widearea_nodeinfo.php3 10.6 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2004-2012 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
23 24 25 26 27 28
#
include("defs.php3");

#
# Only known and logged in users can see this information
#
29 30 31
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
32

33 34 35 36 37 38 39 40 41
#
# Verify page arguments.
#
$optargs = OptionalPageArguments("node",       PAGEARG_NODE,
				 "formfields", PAGEARG_ARRAY);

if (isset($node)) {
    $node_id = $node->node_id();
    
42 43 44 45 46 47 48 49 50 51 52
    PAGEHEADER("Wide Area Link Characteristics For $node_id");
} else {
    PAGEHEADER("Wide Area Link Characteristics");
}

#
#
#
function SPITDATA($table, $title, $formfields)
{
    #
53
    # Grab a couple of the formfields that we are gonna use a lot
54
    #
55 56 57
    $node_id     = $formfields["node_id"];
    $dst_node_id = $formfields["dst_node_id"];
    $sortby      = $formfields["sortby"];
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

    #
    # Provide a default sort order
    #
    if (!$sortby) {
	$sortby = "node";
    }

    #
    # Figure out what order to sort in
    #
    if (!strcmp($sortby,"bw")) {
	$sortclause = "t.bandwidth desc";
    } elseif (!strcmp($sortby,"delay")) {
	$sortclause = "t.time";
    } elseif (!strcmp($sortby,"plr")) {
	$sortclause = "t.lossrate";
    } else {
	$sortclause = "n.priority";
    }

    #
    # Do we have a destination node, or are we grabbing all destinations for
    # the source node?
    #
    if ($node_id) {
	$whereclause = "t.node_id1='$node_id'";
    } else {
	$whereclause = "1";
    }
88 89
    if ($dst_node_id) {
	$whereclause .= " and t.node_id2='$dst_node_id'";
90 91 92 93 94
    }

    #
    # Handle constraints on the bandwidth, latency, and PLR
    #
95 96 97
    if ($formfields["min_bw"]) {
	$min_bw = $formfields["min_bw"];
	$whereclause .= " and t.bandwidth >= $min_bw";
98
    }
99 100 101
    if ($formfields["max_bw"]) {
	$max_bw = $formfields["max_bw"];
	$whereclause .= " and t.bandwidth <= $max_bw";
102 103 104
    }

    # Convert from percent to fractional
105 106
    if ($formfields["min_plr"]) {
	$min_plr = $formfields["min_plr"] / 100.0;
107 108
	$whereclause .= " and t.lossrate >= $min_plr";
    }
109 110
    if ($formfields["max_plr"]) {
	$max_plr = $formfields["max_plr"] / 100.0;
111 112 113 114
	$whereclause .= " and t.lossrate <= $max_plr";
    }

    # Convert from ms to seconds
115 116
    if ($formfields["min_latency"]) {
	$min_latency = $formfields["min_latency"] / 1000.0;
117 118
	$whereclause .= " and t.time >= $min_latency";
    }
119 120
    if ($formfields["max_latency"]) {
	$max_latency = $formfields["max_latency"] / 1000.0;
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
	$whereclause .= " and t.time <= $max_latency";
    }

    #
    # Start the table and explain its contents
    #
    echo "<center>
	   <b>$title</b><br>\n";

    echo "</center><br>\n";

    echo "<center>
    Delay in milliseconds, Bandwidth in KB/s, PLR rounded to two
    decimal places (0-100%).
    </center>\n";

    echo "<table border=2 
		 cellpadding=1 cellspacing=2 align=center>
	   <tr>";

    #
142
    # Make the column headers links to change the sort order, unless we are
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
    # aready sorting by the column - also, if we have a desitnation node (and
    # thus are only displaying one row), sorting is pointless,
    #
    if ($dst_node_id || !strcmp($sortby,"node")) {
	echo "   <th>Node</th>\n";
    } else {
	echo "   <th>" . makeURL("Node",$formfields,$node_id,"node")
	     . "</th>\n";
    }
    if (!$node_id) {
	if ($dst_node_id || !strcmp($sortby,"node")) {
	    echo "   <th>Node</th>\n";
	} else {
	    echo "   <th>" . makeURL("Node",$formfields,$node_id,"node")
	         . "</th>\n";
	}
    }
    if ($dst_node_id || !strcmp($sortby,"delay")) {
	echo "   <th>Delay</th>\n";
    } else {
	echo "   <th>" . makeURL("Delay",$formfields,$node_id,"delay")
	     . "</th>\n";
    }
    if ($dst_node_id || !strcmp($sortby,"bw")) {
	echo "   <th>BW</th>\n";
    } else {
	echo "   <th>" . makeURL("BW",$formfields,$node_id,"bw") . "</th>\n";
    }
    if ($dst_node_id || !strcmp($sortby,"plr")) {
	echo "   <th>PLR</th>\n";
    } else {
	echo "   <th>" . makeURL("PLR",$formfields,$node_id,"plr")
	     . "</th>\n";
    }
    echo "   <th>Time Span</th>\n";
    if ($node_id) {
	echo "   <th>Hostname</th>\n";
    }
    echo " </tr>\n";

    $query_result =
	DBQueryFatal("select t.node_id1, t.node_id2, t.time, t.bandwidth, " .
	             "   t.lossrate, t.start_time, t.end_time, i.hostname " .
		     "from $table as t ".
		     "left join nodes as n on n.node_id=t.node_id1 ".
		     "left join widearea_nodeinfo as i on t.node_id2=i.node_id".
		     " where $whereclause order by $sortclause");

    while ($row = mysql_fetch_array($query_result)) {
192 193 194 195 196 197 198 199
	$node_id1 = $row["node_id1"];
	$node_id2 = $row["node_id2"];
	$time     = $row["time"];
	$bw       = $row["bandwidth"];
	$plr      = $row["lossrate"];
	$start    = $row["start_time"];
	$end      = $row["end_time"];
	$hostname = $row["hostname"];
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
    
	#
	# Convert a few columns to the right formats
	#
	$speed = $time * 1000;
	$bws   = $bw;
	$plrs  = $plr * 100.0;
	$dates = strftime("%m/%d-%H:%M", $start) . " to " .
		 strftime("%m/%d-%H:%M", $end);
	
	if (strcmp($node_id1, $node_id2)) {
	    echo "<tr>\n";
	    #
	    # Provide a link the equivalent page for each node
	    #
	    if (!$node_id) {
		echo "<td> " . makeURL($node_id1,$formfields,$node_id1,$sortby)
		           . "</td>\n";
	    }
	    echo "<td> " . makeURL($node_id2,$formfields,$node_id2,$sortby)
	                 . "</td>\n";

	    echo "<td>$speed</td>\n";
	    echo "<td>$bws</td>\n";
	    echo "<td>$plrs</td>\n";
	    echo "<td><nobr>$dates</nobr></td>\n";
	    if ($node_id) {
		echo "<td><code>$hostname</code></td>\n";
	    }
	    echo "</tr>\n";
	} else {
	    #
	    # Skip any data from a node to itself
	    #
	    continue;
	}
    }
    echo "</table>\n";
    echo "<br>\n";
}

#
# Form to let the user specify which node(s) and link characteristics they are
# interested in
#
function SPITFORM($formfields) {
246 247 248 249
    # XSS prevention.
    while (list ($key, $val) = each ($formfields)) {
	$formfields[$key] = CleanString($val);
    }
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298

    echo "<form action='widearea_nodeinfo.php3' method='get'>
	  <table align='center'>
	    <tr>
		<td colspan=2>
		<b>Search for link characteristics</b><br>
		All search terms are optional, but you must supply at least one
		</td>
	    </tr>
	    <tr>
		<td>Source Node:</td>
		<td><input name='formfields[node_id]'
		     value='$formfields[node_id]' size=10></td>
	    </tr>
	    <tr>
		<td>Destination Node: <i>(requires source node)<i></td>
		<td><input name='formfields[dst_node_id]'
		     value='$formfields[dst_node_id]' size=10></td>
	    </tr>
	    <tr>
		<td>Min bandwidth: <i>(KBps)</i></td>
		<td><input name='formfields[min_bw]'
		     value='$formfields[min_bw]' size=4></td>
	    </tr>
	    <tr>
		<td>Max bandwidth:</td>
		<td><input name='formfields[max_bw]'
		     value='$formfields[max_bw]' size=4></td>
	    </tr>
	    <tr>
		<td>Min latency: <i>(ms)</i></td>
		<td><input name='formfields[min_latency]'
		     value='$formfields[min_latency]' size=4></td>
	    </tr>
	    <tr>
		<td>Max latency:</td>
		<td><input name='formfields[max_latency]'
		     value='$formfields[max_latency]' size=4></td>
	    </tr>
	    <tr>
		<td>Min packet loss: <i>(%)</i></td>
		<td><input name='formfields[min_plr]'
		     value='$formfields[min_plr]' size=4></td>
	    </tr>
	    <tr>
		<td>Max packet loss:</td>
		<td><input name='formfields[max_plr]'
		     value='$formfields[max_plr]' size=4></td>
	    </tr>
299 300
            <input type=hidden name='formfields[sortby]'
                      value='$formfields[sortby]'>
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
	    <tr>
		<td colspan=2 align='center'>
		    <input type='submit' name='Submit' value='Submit'>
		</td>
	    </tr>
	  </table>
	  </form>
	  <br>\n";
}

#
# Make a URL for this page, going to the given node_id and using the given
# sorting scheme (either of which can be empty, to avoid overriding the current
# value), with $text as the anchor text
#
function makeURL($text,$formfields,$node_id,$sortby) {
    $fieldcopy = $formfields;
    if ($node_id) {
319
	$fieldcopy["node_id"] = $node_id;
320 321
    }
    if ($sortby) {
322
	$fieldcopy["sortby"] = $sortby;
323 324 325
    }
    $fieldstrings = array();
    foreach ($fieldcopy as $field => $value) {
326
	array_push($fieldstrings, "formfields[$field]=$value");
327 328 329 330 331
    }
    $args = implode("&",$fieldstrings);
    return "<a href=\"widearea_nodeinfo.php3?$args\">$text</a>";
}

332
$err = false;
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
if (!isset($formfields)) {
    $formfields = array();
    
    $formfields["node_id"]	= "";
    $formfields["dst_node_id"]	= "";
    $formfields["min_bw"]	= "";
    $formfields["max_bw"]	= "";
    $formfields["min_latency"]	= "";
    $formfields["max_latency"]	= "";
    $formfields["min_plr"]	= "";
    $formfields["max_plr"]	= "";
    $formfields["sortby"]	= "node";
    
    SPITFORM($formfields);
}
else {
    if ($formfields["node_id"] &&
	!TBvalid_node_id($formfields["node_id"])) {
351
	$err = true;
352 353 354 355
	USERERROR("Invalid characters in node_id");
    }
    if ($formfields["dst_node_id"] &&
	!TBvalid_node_id($formfields["dst_node_id"])) {
356
	$err = true;
357 358 359 360
	USERERROR("Invalid characters in dst_node_id");
    }
    if ($formfields["min_bw"] &&
	!TBvalid_integer($formfields["min_bw"])) {
361
	$err = true;
362 363 364 365
	USERERROR("Invalid characters in min_bw");
    }
    if ($formfields["max_bw"] &&
	!TBvalid_integer($formfields["max_bw"])) {
366
	$err = true;
367 368 369 370
	USERERROR("Invalid characters in max_bw");
    }
    if ($formfields["min_latency"] &&
	!TBvalid_integer($formfields["min_latency"])) {
371
	$err = true;
372 373 374 375
	USERERROR("Invalid characters in min_latency");
    }
    if ($formfields["max_latency"] &&
	!TBvalid_integer($formfields["max_latency"])) {
376
	$err = true;
377 378 379 380
	USERERROR("Invalid characters in max_latency");
    }
    if ($formfields["min_plr"] &&
	!TBvalid_float($formfields["min_plr"])) {
381
	$err = true;
382 383 384 385
	USERERROR("Invalid characters in min_plr");
    }
    if ($formfields["max_plr"] &&
	!TBvalid_float($formfields["max_plr"])) {
386
	$err = true;
387 388 389 390
	USERERROR("Invalid characters in max_plr");
    }
    
    SPITFORM($formfields);
391 392 393 394
    if (! $err) {
	SPITDATA("widearea_recent", "Most Recent Data", $formfields);
	SPITDATA("widearea_delays", "Aged Data", $formfields);
    }
395 396 397 398 399 400 401
}

#
# Standard Testbed Footer
#
PAGEFOOTER();
?>