delaycontrol.php3 14.3 KB
Newer Older
1 2 3
<?php
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2003 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 38 39 40 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

#
# 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 =
    DBQueryFatal("SELECT * FROM experiments WHERE ".
		 "eid='$eid' and pid='$pid'");
$row = mysql_fetch_array($query_result);
$gid         = $row[gid];
$expt_locked = $row[expt_locked];
$estate      = $row[state];

#
# Look for transition progress and exit with error.
#
if ($expt_locked) {
    USERERROR("Experiment $eid went into transition at $expt_locked.<br>".
	      "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. 
#
if (strcmp($estate, $TB_EXPTSTATE_ACTIVE)) {
    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 160 161 162 163 164 165 166 167 168 169 170 171
	    #
	    # 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!
	    #
	    $retval = SUEXEC($uid, $unix_gid, $cmd, SUEXEC_ACTION_IGNORE);
	    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);
		}
172
	    }
173
	}
174 175
    }
}
176

177 178 179
#
# Okay, even if changes were made, keep going and report again.
# 
180
$result_delays =
181 182
    DBQueryFatal("SELECT * FROM delays WHERE eid='$eid' AND pid='$pid' " .
		 "order by vname,vnode0,vnode1");
183
$result_linkdelays =
184 185
    DBQueryFatal("SELECT * FROM linkdelays WHERE eid='$eid' AND pid='$pid' ".
		 "order by vlan,vnode");
186 187 188

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

192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
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";

208
print "<form action='delaycontrol.php3' method=post>\n" .
209
      "<input type=hidden name=dochange value=1 />\n" .
210 211 212 213
      "<input type=hidden name=eid value='$eid' />\n" .
      "<input type=hidden name=pid value='$pid' />\n" .
      "<table>\n" .
      "<tr>" .
214 215 216 217 218 219
      " <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>".
220 221
      " <td align=center colspan=4>
            RED/GRED<br>(only if link specified as RED)</td>".
222 223 224 225 226 227
      "</tr>".
      "<tr>".
      " <th>q_weight</th>".
      " <th>minthresh</th>".
      " <th>maxthresh</th>".
      " <th>linterm</th>".
228
      "</tr>";
229
           
230 231
$num  = mysql_num_rows( $result_delays );
$last = "";
232 233
for ($i = 0; $i < $num; $i++) {
    $row = mysql_fetch_array($result_delays);
234

235 236 237
    $vlan   = $row["vname"];
    $vnode0 = $row["vnode0"];
    $vnode1 = $row["vnode1"];
238

239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
    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";
256

257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
	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";
    }
279

280 281 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
    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";
317

318 319 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
    #
    # 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";
}
374

375 376 377
$num = mysql_num_rows( $result_linkdelays );
for ($i = 0; $i < $num; $i++) {
    $row = mysql_fetch_array( $result_linkdelays );
378

379 380
    $vlan  = $row["vlan"];
    $vnode = $row["vnode"];
381

382 383 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
    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";
458 459 460

   #
   # If duplex, its a lan node. Print reverse params.
461 462
   # Note, we do not allow them to change lan nodes asymmetrically yet
   # since the backend script cannot handle that.
463
   #
464
   if (0 && !strcmp($row{"type"}, "duplex")) {
465 466 467
       echo "<tr>\n";
       echo "  <td>&nbsp</td>\n";
       echo "  <td>&nbsp</td>\n";
468 469 470 471
       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";
472 473
       echo "</tr>\n";
   }
474
   
475 476 477
}

print "</table>\n" .
478 479 480 481
      "<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" .
482 483 484 485 486
      "</form>\n";

PAGEFOOTER();
?>