widearea_nodeinfo.php3 9.77 KB
Newer Older
1
2
3
<?php
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2004, 2006, 2007 University of Utah and the Flux Group.
5
6
7
8
9
10
11
# All rights reserved.
#
include("defs.php3");

#
# Only known and logged in users can see this information
#
12
13
14
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
15

16
17
18
19
20
21
22
23
24
#
# Verify page arguments.
#
$optargs = OptionalPageArguments("node",       PAGEARG_NODE,
				 "formfields", PAGEARG_ARRAY);

if (isset($node)) {
    $node_id = $node->node_id();
    
25
26
27
28
29
30
31
32
33
34
35
    PAGEHEADER("Wide Area Link Characteristics For $node_id");
} else {
    PAGEHEADER("Wide Area Link Characteristics");
}

#
#
#
function SPITDATA($table, $title, $formfields)
{
    #
36
    # Grab a couple of the formfields that we are gonna use a lot
37
    #
38
39
40
    $node_id     = $formfields["node_id"];
    $dst_node_id = $formfields["dst_node_id"];
    $sortby      = $formfields["sortby"];
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

    #
    # 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";
    }
71
72
    if ($dst_node_id) {
	$whereclause .= " and t.node_id2='$dst_node_id'";
73
74
75
76
77
    }

    #
    # Handle constraints on the bandwidth, latency, and PLR
    #
78
79
80
    if ($formfields["min_bw"]) {
	$min_bw = $formfields["min_bw"];
	$whereclause .= " and t.bandwidth >= $min_bw";
81
    }
82
83
84
    if ($formfields["max_bw"]) {
	$max_bw = $formfields["max_bw"];
	$whereclause .= " and t.bandwidth <= $max_bw";
85
86
87
    }

    # Convert from percent to fractional
88
89
    if ($formfields["min_plr"]) {
	$min_plr = $formfields["min_plr"] / 100.0;
90
91
	$whereclause .= " and t.lossrate >= $min_plr";
    }
92
93
    if ($formfields["max_plr"]) {
	$max_plr = $formfields["max_plr"] / 100.0;
94
95
96
97
	$whereclause .= " and t.lossrate <= $max_plr";
    }

    # Convert from ms to seconds
98
99
    if ($formfields["min_latency"]) {
	$min_latency = $formfields["min_latency"] / 1000.0;
100
101
	$whereclause .= " and t.time >= $min_latency";
    }
102
103
    if ($formfields["max_latency"]) {
	$max_latency = $formfields["max_latency"] / 1000.0;
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
	$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>";

    #
125
    # Make the column headers links to change the sort order, unless we are
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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
    # 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)) {
175
176
177
178
179
180
181
182
	$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"];
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
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
246
247
248
249
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
    
	#
	# 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) {

    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>
278
279
            <input type=hidden name='formfields[sortby]'
                      value='$formfields[sortby]'>
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
	    <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) {
298
	$fieldcopy["node_id"] = $node_id;
299
300
    }
    if ($sortby) {
301
	$fieldcopy["sortby"] = $sortby;
302
303
304
    }
    $fieldstrings = array();
    foreach ($fieldcopy as $field => $value) {
305
	array_push($fieldstrings, "formfields[$field]=$value");
306
307
308
309
310
    }
    $args = implode("&",$fieldstrings);
    return "<a href=\"widearea_nodeinfo.php3?$args\">$text</a>";
}

311
$err = false;
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
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"])) {
330
	$err = true;
331
332
333
334
	USERERROR("Invalid characters in node_id");
    }
    if ($formfields["dst_node_id"] &&
	!TBvalid_node_id($formfields["dst_node_id"])) {
335
	$err = true;
336
337
338
339
	USERERROR("Invalid characters in dst_node_id");
    }
    if ($formfields["min_bw"] &&
	!TBvalid_integer($formfields["min_bw"])) {
340
	$err = true;
341
342
343
344
	USERERROR("Invalid characters in min_bw");
    }
    if ($formfields["max_bw"] &&
	!TBvalid_integer($formfields["max_bw"])) {
345
	$err = true;
346
347
348
349
	USERERROR("Invalid characters in max_bw");
    }
    if ($formfields["min_latency"] &&
	!TBvalid_integer($formfields["min_latency"])) {
350
	$err = true;
351
352
353
354
	USERERROR("Invalid characters in min_latency");
    }
    if ($formfields["max_latency"] &&
	!TBvalid_integer($formfields["max_latency"])) {
355
	$err = true;
356
357
358
359
	USERERROR("Invalid characters in max_latency");
    }
    if ($formfields["min_plr"] &&
	!TBvalid_float($formfields["min_plr"])) {
360
	$err = true;
361
362
363
364
	USERERROR("Invalid characters in min_plr");
    }
    if ($formfields["max_plr"] &&
	!TBvalid_float($formfields["max_plr"])) {
365
	$err = true;
366
367
368
369
	USERERROR("Invalid characters in max_plr");
    }
    
    SPITFORM($formfields);
370
371
372
373
    if (! $err) {
	SPITDATA("widearea_recent", "Most Recent Data", $formfields);
	SPITDATA("widearea_delays", "Aged Data", $formfields);
    }
374
375
376
377
378
379
380
}

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