delaycontrol.php3 14.3 KB
Newer Older
1 2 3
<?php
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2005 University of Utah and the Flux Group.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# All rights reserved.
#
include("defs.php3");

#
# Standard Testbed Header
#
PAGEHEADER("Delay Control");

#
# Only known and logged in users can do this.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
$isadmin = ISADMIN($uid);
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

#
# Must provide the PID/EID!
# 
if (!isset($pid) ||
    strcmp($pid, "") == 0) {
    USERERROR("The project ID was not provided!", 1);
}

if (!isset($eid) ||
    strcmp($eid, "") == 0) {
    USERERROR("The experiment ID was not provided!", 1);
}

if (!TBValidExperiment($pid, $eid)) {
    USERERROR("No such experiment $eid in project $eid!", 1);
}
$query_result =
38
    DBQueryFatal("SELECT gid,state FROM experiments WHERE ".
39 40 41
		 "eid='$eid' and pid='$pid'");
$row = mysql_fetch_array($query_result);
$gid         = $row[gid];
42
$state       = $row[state];
43 44

#
45
# Look for transition and exit with error.
46
#
47 48 49
if ($state != $TB_EXPTSTATE_ACTIVE &&
    $state != $TB_EXPTSTATE_SWAPPED) {
    USERERROR("Experiment $eid is not ACTIVE or SWAPPED.<br>".
50 51 52 53 54 55 56 57 58
	      "You must wait until the experiment is no longer in transition.".
	      "<br>", 1);
}

#
# Must be active. The backend can deal with changing the base experiment
# when the experiment is swapped out, but we need to generate a form based
# on virt_lans instead of delays/linkdelays. Thats harder to do. 
#
59
if (strcmp($state, $TB_EXPTSTATE_ACTIVE)) {
60 61 62 63 64 65 66 67 68
    USERERROR("Experiment $eid must be active to change its traffic ".
	      "shaping configuration!", 1);
}

#
# Verify permission.
#
if (! TBExptAccessCheck($uid, $pid, $eid, $TB_EXPT_MODIFY)) {
    USERERROR("You do not have permission to modify experiment $eid!", 1);
69 70
}

71
if ($dochange == "1") {
72 73 74 75
    #
    # Array of changes, indexed by [lan:node]
    # 
    $changes = array();
76

77 78 79 80 81 82
    #
    # modbase 
    #
    $modbasearg = "";
    if (isset($modbase) && $modbase) {
	$modbasearg = "-m";
83
    }
84
    
85 86 87 88 89
    #
    # Grab the unix GID for running scripts.
    #
    TBGroupUnixInfo($pid, $gid, $unix_gid, $unix_name);
    
90 91 92 93 94
    while (list ($header, $value) = each ($HTTP_POST_VARS)) {
	$changestring = strstr($header, "DC::");
	if (! $changestring) {
	    continue;
	}
95 96 97 98
	if (!isset($value) || !strcmp($value, "") ||
	    !ereg("^[0-9\.bs]*$", "$value")) {
	    continue;
	}
99 100 101 102 103 104 105 106

	# Too bad sscanf is broken ...
	$temp      = substr($header, 4);
	$param     = substr($temp, 0, strpos($temp, "::"));
	$temp      = substr($temp, strpos($temp, "::") + 2);
	$lan       = substr($temp, 0, strpos($temp, "::"));
	$vnode     = substr($temp, strpos($temp, "::") + 2);

107
	#echo "$param $lan $vnode $value<br>\n";
108 109 110 111

	#
	# Must taint check! This stuff is going to a shell program. 
	# 
112 113 114
	if (!preg_match("/^[-\w]*$/", $param) ||
	    !preg_match("/^[-\w]*$/", $lan) ||
	    !preg_match("/^[-\w]*$/", $vnode)) {
115 116 117
	    continue;
	}

118 119 120 121 122 123 124 125 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
	#
	# Queue limit is special. Need to parse for "b" or "s" extension.
	#
	$qlimitarg = "";
	if (! strcmp($param, "limit")) {
	    $lastchr = $value{strlen($value)-1};

	    if (ctype_alpha($lastchr)) {
		if ($lastchr == "s") {
		    $qlimitarg = "QUEUE-IN-BYTES=0";
		}
		elseif ($lastchr == "b") {
		    $qlimitarg = "QUEUE-IN-BYTES=1";
		}
		$value = substr($value, 0, strlen($value) - 1);
	    }
	}

	if (!isset($vnode) || !strcmp($vnode, "")) {
	    $changes["$lan"]["allnodes"] .= "${param}=${value} $qlimitarg ";
	}
	else {
	    $changes["$lan"]["$vnode"] .= "${param}=${value} $qlimitarg ";
	}
    }
    foreach ($changes as $lan => $foo) {
	foreach ($foo as $vnode => $string) {
	    if (strcmp($vnode, "allnodes")) {
		$vnode = "-s $vnode";
	    }
	    else {
		$vnode = "";
	    }
151 152
	    	
	    $cmd = "webdelay_config $modbasearg $vnode $pid $eid $lan $string";
153
	    #echo "$cmd<br>\n";
154

155 156 157 158 159
	    #
	    # Need proper auditing or logging. For now, run as normal and
	    # if something breaks we get the mail from the web interface.
	    # This might change depending on how often we get email!
	    #
160 161
	    $retval = SUEXEC($uid, "$pid,$unix_gid", $cmd,
			     SUEXEC_ACTION_IGNORE);
162 163 164 165 166 167 168 169 170 171 172
	    if ($retval) {
		# Ug, I know this hardwired return value is bad! 
		if ($retval == 2) {
		    # A usage error, reported to user. At some point the
		    # approach is to do all the argument checking first.
		    SUEXECERROR(SUEXEC_ACTION_USERERROR);
		}
		else {
		    # All other errors reported to tbops since they are bad!
		    SUEXECERROR(SUEXEC_ACTION_DIE);
		}
173
	    }
174
	}
175 176
    }
}
177

178 179 180
#
# Okay, even if changes were made, keep going and report again.
# 
181
$result_delays =
182 183
    DBQueryFatal("select * from delays ".
		 "where eid='$eid' and pid='$pid' and noshaping=0 " .
184
		 "order by vname,vnode0,vnode1");
185
$result_linkdelays =
186 187
    DBQueryFatal("select * from linkdelays ".
		 "where eid='$eid' and pid='$pid' " .
188
		 "order by vlan,vnode");
189 190 191

if (mysql_num_rows($result_delays) == 0 &&
    mysql_num_rows($result_linkdelays) == 0) {
192 193 194
    USERERROR("No running delay nodes with eid='$eid' and pid='$pid'!", 1);
}

195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
echo "<font size=+1>Experiment <b>".
     "<a href='showproject.php3?pid=$pid'>$pid</a>/".
     "<a href='showexp.php3?pid=$pid&eid=$eid'>$eid</a></b></font>\n";
echo "<br><br>\n";

echo "Use this page to alter the traffic shaping parameters of your
      <em>swapped in</em> experiment. You can change as many values as you
      like at a time. The first line in each link or lan
      (labeled <font color=red>All Nodes</font>) allows you to set
      the parameters for the <em>entire</em> link or lan. If you want to
      change the values for indvidual nodes, then enter new values on the
      proper line instead. Anything you leave blank will be unaffected.<br> 
      When you are ready, click on the Execute button at the bottom of the
      form. If you want these changes to be saved across swapout, then
      check the Save box.<br><br>\n";

211
print "<form action='delaycontrol.php3' method=post>\n" .
212
      "<input type=hidden name=dochange value=1 />\n" .
213 214 215 216
      "<input type=hidden name=eid value='$eid' />\n" .
      "<input type=hidden name=pid value='$pid' />\n" .
      "<table>\n" .
      "<tr>" .
217 218 219 220 221 222
      " <th rowspan=2>Link Name</th>".
      " <th rowspan=2>Node</th>".
      " <th rowspan=2>Delay (msec)</th>".
      " <th rowspan=2>Bandwidth<br>(kb/s)</th>".
      " <th rowspan=2>Loss (ratio)</th>".
      " <th rowspan=2>Queue Size</th>".
223 224
      " <td align=center colspan=4>
            RED/GRED<br>(only if link specified as RED)</td>".
225 226 227 228 229 230
      "</tr>".
      "<tr>".
      " <th>q_weight</th>".
      " <th>minthresh</th>".
      " <th>maxthresh</th>".
      " <th>linterm</th>".
231
      "</tr>";
232
           
233 234
$num  = mysql_num_rows( $result_delays );
$last = "";
235 236
for ($i = 0; $i < $num; $i++) {
    $row = mysql_fetch_array($result_delays);
237

238 239 240
    $vlan   = $row["vname"];
    $vnode0 = $row["vnode0"];
    $vnode1 = $row["vnode1"];
241

242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
    if (strcmp($last, $vlan)) {
	$last = $vlan;
	echo "<tr>\n";
	echo "  <td><font color=blue>$vlan</font></td>\n";
	echo "  <td><font color=red>All Nodes</font></td>\n";
	echo "  <td> " .
	    "<input type=text name=\"DC::delay::$vlan::allnodes\" size=6/>" .
	    "</td>\n";
	echo "  <td> " .
	    "<input type=text name=DC::bandwidth::$vlan::allnodes size=6/>" .
	    "</td>\n";
	echo "  <td> " .
	    "<input type=text name=DC::plr::$vlan::allnodes size=6/>" .
	    "</td>\n";
	echo "  <td> " . 
	    "<input type=text name=DC::limit::$vlan::allnodes size=6/>" .
	    "</td>\n";
259

260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
	if ($row["q0_red"]) {
	    echo "  <td> " .
		"<input type=text name=DC::q_weight::$vlan::allnodes size=6/>".
		"</td>\n";
	    echo "  <td> " .
	       "<input type=text name=DC::minthresh::$vlan::allnodes size=6/>".
		"</td>\n";
	    echo "  <td> " .
		"<input type=text name=DC::thresh::$vlan::allnodes size=6/>" .
		"</td>\n";
	    echo "  <td> " .
		"<input type=text name=DC::linterm::$vlan::allnodes size=6/>" .
		"</td>\n";
	}
	else {
	    echo "<td>n/a</td>\n";
	    echo "<td>n/a</td>\n";
	    echo "<td>n/a</td>\n";
	    echo "<td>n/a</td>\n";
	}
	echo "</tr>\n";
    }
282

283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
    echo "<tr>\n";
    echo "  <td>&nbsp</td>\n";
    echo "  <td>$vnode0</td>\n";
    echo "  <td> " . $row["delay0"] . 
	"<br><input type=text name=\"DC::delay::$vlan::$vnode0\" size=6/>" .
	"</td>\n";
    echo "  <td> " . $row["bandwidth0"] . 
	"<br><input type=text name=DC::bandwidth::$vlan::$vnode0 size=6/>" .
	"</td>\n";
    echo "  <td> " . $row["lossrate0"] . 
	"<br><input type=text name=DC::plr::$vlan::$vnode0 size=6/>" .
	"</td>\n";
    echo "  <td> " . $row["q0_limit"] .
	($row["q0_qinbytes"] ? "b" : "s") . 
	"<br><input type=text name=DC::limit::$vlan::$vnode0 size=6/>" .
	"</td>\n";
    if ($row["q0_red"]) {
	echo "  <td> " . $row["q0_weight"] . 
	    "<br><input type=text name=DC::q_weight::$vlan::$vnode0 size=6/>".
	    "</td>\n";
	echo "  <td> " . $row["q0_minthresh"] . 
            "<br><input type=text name=DC::minthresh::$vlan::$vnode0 size=6/>".
	    "</td>\n";
	echo "  <td> " . $row["q0_maxthresh"] . 
	    "<br><input type=text name=DC::thresh::$vlan::$vnode0 size=6/>" .
	    "</td>\n";
	echo "  <td> " . $row["q0_linterm"] . 
	    "<br><input type=text name=DC::linterm::$vlan::$vnode0 size=6/>" .
	    "</td>\n";
    }
    else {
	echo "<td>n/a</td>\n";
	echo "<td>n/a</td>\n";
	echo "<td>n/a</td>\n";
	echo "<td>n/a</td>\n";
    }
    echo "</tr>\n";
320

321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
    #
    # If vnode0 and vnode1 are different, its a plain duplex link.
    # Otherwise its a lan node. At some point we will allow asymmetric
    # changes to lan nodes, but the backend script does not support that
    # so do not give them the option.
    #
    echo "<tr>\n";
    if (strcmp($row["vnode0"], $row["vnode1"])) {
	echo "  <td>&nbsp</td>\n";
	echo "  <td>$vnode1</td>\n";
	echo "  <td> " . $row["delay1"] . 
	    "<br><input type=text name=DC::delay::$vlan::$vnode1 size=6/>" .
	    "</td>\n";
	echo "  <td> " . $row["bandwidth1"] . 
	    "<br><input type=text name=DC::bandwidth::$vlan::$vnode1 size=6/>".
	    "</td>\n";
	echo "  <td> " . $row["lossrate1"] . 
	    "<br><input type=text name=DC::plr::$vlan::$vnode1 size=6/>" .
	    "</td>\n";
	echo "  <td> " . $row["q1_limit"] .
	    ($row["q1_qinbytes"] ? "b" : "s") . 
	    "<br><input type=text name=DC::limit::$vlan::$vnode1 size=6/>" .
	    "</td>\n";
	if ($row["q0_red"]) {
	    echo "  <td> " . $row["q1_weight"] . 
	    "<br><input type=text name=DC::q_weight::$vlan::$vnode1 size=6/>" .
		"</td>\n";
	    echo "  <td> " . $row["q1_minthresh"] . 
	    "<br><input type=text name=DC::minthresh::$vlan::$vnode1 size=6/>".
		"</td>\n";
	    echo "  <td> " . $row["q1_maxthresh"] . 
	    "<br><input type=text name=DC::thresh::$vlan::$vnode1 size=6/>" .
		"</td>\n";
	    echo "  <td> " . $row["q1_linterm"] . 
	    "<br><input type=text name=DC::linterm::$vlan::$vnode1 size=6/>" .
		"</td>\n";
	}
	else {
	    echo "<td>n/a</td>\n";
	    echo "<td>n/a</td>\n";
	    echo "<td>n/a</td>\n";
	    echo "<td>n/a</td>\n";
	}
    }
    else {
	if (0) {
	    echo "  <td>&nbsp</td>\n";
	    echo "  <td>&nbsp</td>\n";
	    echo "  <td> " . $row["delay1"] . "</td>\n";
	    echo "  <td> " . $row["bandwidth1"] . "</td>\n";
	    echo "  <td> " . $row["lossrate1"] . "</td>\n";
	    echo "  <td> " . $row["q1_limit"] . "</td>\n";
	}
    }
    echo "</tr>\n";
}
377

378 379 380
$num = mysql_num_rows( $result_linkdelays );
for ($i = 0; $i < $num; $i++) {
    $row = mysql_fetch_array( $result_linkdelays );
381

382 383
    $vlan  = $row["vlan"];
    $vnode = $row["vnode"];
384

385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
    if (strcmp($last, $vlan)) {
	$last = $vlan;
	echo "<tr>\n";
	echo "  <td><font color=blue>$vlan</font></td>\n";
	echo "  <td><font color=red>All Nodes</font></td>\n";
	echo "  <td> " .
	    "<input type=text name=\"DC::delay::$vlan::allnodes\" size=6/>" .
	    "</td>\n";
	echo "  <td> " .
	    "<input type=text name=DC::bandwidth::$vlan::allnodes size=6/>" .
	    "</td>\n";
	echo "  <td> " .
	    "<input type=text name=DC::plr::$vlan::allnodes size=6/>" .
	    "</td>\n";
	echo "  <td> " . 
	    "<input type=text name=DC::limit::$vlan::allnodes size=6/>" .
	    "</td>\n";
	if ($row["q_red"]) {
	    echo "  <td> " .
		"<input type=text name=DC::q_weight::$vlan::allnodes size=6/>".
		"</td>\n";
	    echo "  <td> " .
	       "<input type=text name=DC::minthresh::$vlan::allnodes size=6/>".
		"</td>\n";
	    echo "  <td> " .
		"<input type=text name=DC::thresh::$vlan::allnodes size=6/>" .
		"</td>\n";
	    echo "  <td> " .
		"<input type=text name=DC::linterm::$vlan::allnodes size=6/>" .
		"</td>\n";
	}
	else {
	    echo "<td>n/a</td>\n";
	    echo "<td>n/a</td>\n";
	    echo "<td>n/a</td>\n";
	    echo "<td>n/a</td>\n";
	}
	echo "</tr>\n";
    }
    echo "<tr>\n";
    echo "  <td>&nbsp</td>\n";
    echo "  <td>$vnode</td>\n";
    echo "  <td> " . $row["delay"] . 
	"<br><input type=text name=DC::delay::$vlan::$vnode size=6/>" .
	"</td>\n";
    echo "  <td> " . $row["bandwidth"] . 
	"<br><input type=text name=DC::bandwidth::$vlan::$vnode size=6/>" .
	"</td>\n";
    echo "  <td> " . $row["lossrate"] . 
	"<br><input type=text name=DC::plr::$vlan::$vnode size=6/>" .
	"</td>\n";
    echo "  <td> " . $row["q_limit"] .
	($row["q_qinbytes"] ? "b" : "s") . 
	"<br><input type=text name=DC::limit::$vlan::$vnode size=6/>" .
	"</td>\n";
    if ($row["q_red"]) {
	echo "  <td> " . $row["q_weight"] . 
	    "<br><input type=text name=DC::q_weight::$vlan::$vnode size=6/>" .
	    "</td>\n";
	echo "  <td> " . $row["q_minthresh"] . 
	    "<br><input type=text name=DC::minthresh::$vlan::$vnode size=6/>" .
	    "</td>\n";
	echo "  <td> " . $row["q_maxthresh"] . 
	    "<br><input type=text name=DC::thresh::$vlan::$vnode size=6/>" .
	    "</td>\n";
	echo "  <td> " . $row["q_linterm"] . 
	    "<br><input type=text name=DC::linterm::$vlan::$vnode size=6/>" .
	    "</td>\n";
    }
    else {
	    echo "<td>n/a</td>\n";
	    echo "<td>n/a</td>\n";
	    echo "<td>n/a</td>\n";
	    echo "<td>n/a</td>\n";
    }
    echo "</tr>\n";
461 462 463

   #
   # If duplex, its a lan node. Print reverse params.
464 465
   # Note, we do not allow them to change lan nodes asymmetrically yet
   # since the backend script cannot handle that.
466
   #
467
   if (0 && !strcmp($row{"type"}, "duplex")) {
468 469 470
       echo "<tr>\n";
       echo "  <td>&nbsp</td>\n";
       echo "  <td>&nbsp</td>\n";
471 472 473 474
       echo "  <td> " . $row["rdelay"] . "</td>\n";
       echo "  <td> " . $row["rbandwidth"] . "</td>\n";
       echo "  <td> " . $row["rlossrate"] . "</td>\n";
       echo "  <td> " . $row["q_limit"] . "</td>\n";
475 476
       echo "</tr>\n";
   }
477
   
478 479 480
}

print "</table>\n" .
481 482 483 484
      "<input type=checkbox value=\"1\" name=modbase>
              &nbsp Save? (Check this box if you want to modify the base
	            experiment configuration)<br><br>\n".
      "<input type=submit value='Execute'>\n" .
485 486 487 488 489
      "</form>\n";

PAGEFOOTER();
?>