widearea_info.php3 5.2 KB
Newer Older
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2 3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
5 6
# All rights reserved.
#
7 8 9 10 11 12 13 14 15 16 17 18 19 20
include("defs.php3");
include("showstuff.php3");

#
# Only known and logged in users can end experiments.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);

#
# Show argument.
#
if (! isset($showtype))
    $showtype="delay";
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
if (! isset($plain))
    $plain=0;

if (! $plain) {
    PAGEHEADER("Wide Area Link Characteristics");

    echo "<b>Show:
           <a href='widearea_info.php3?showtype=delay&plain=$plain'>Delay</a>,
           <a href='widearea_info.php3?showtype=bw&plain=$plain'>Bandwidth</a>,
           <a href='widearea_info.php3?showtype=plr&plain=$plain'>Lossrate</a>,
           <a href='widearea_info.php3?showtype=dates&plain=$plain'>Dates</a>,
           <a href='widearea_info.php3?showtype=all&plain=$plain'>All</a>. ";
    echo "Format:
           <a href='widearea_info.php3?showtype=$showtype&plain=1'>Text</a>.";
    echo "</b><br><br>\n";
}
else {
    header("Content-Type: text/plain");
    echo "\n";
}
41 42 43 44 45 46 47 48 49 50 51 52

#
# Convert showtype to quicker compare
#
if (!strcmp($showtype, "all"))
    $showtype = 1;
elseif (!strcmp($showtype, "delay"))
    $showtype = 2;
elseif (!strcmp($showtype, "bw"))
    $showtype = 3;
elseif (!strcmp($showtype, "plr"))
    $showtype = 4;
53 54
elseif (!strcmp($showtype, "dates"))
    $showtype = 5;
55 56 57
else
    $showtype = 1;

58
function SPITDATA($table, $title, $showtype, $plain)
59 60
{
    $query_result1 =
61 62 63
	DBQueryFatal("select t.*,n.priority from $table as t ".
		     "left join nodes as n on n.node_id=t.node_id1 ".
		     "order by n.priority");
64 65 66 67 68 69 70 71 72 73 74 75 76
    
    # PHP arrays are strange wrt "each" function. Need two copies.
    $nodenamesrow = array();
    $nodenamescol = array();

    while ($row = mysql_fetch_array($query_result1)) {
	$node_id1 = $row[node_id1];
	$iface1   = $row[iface1];
	$node_id2 = $row[node_id2];
	$iface2   = $row[iface2];
	$time     = $row[time];
	$bw       = $row[bandwidth];
	$plr      = $row[lossrate];
77 78
	$start    = $row[start_time];
	$end      = $row[end_time];
79
	$pri      = $row[priority];
80 81 82 83
    
	$glom1    = $node_id1;
	$glom2    = $node_id2;

84
        #echo "Got $glom1 to $glom2 $pri<br>\n";
85
	
86 87 88 89 90
	$nodenamesrow[$glom1] = $pri;
	$nodenamescol[$glom1] = $pri;

#	$nodenamesrow[$glom2] = 1;
#	$nodenamescol[$glom2] = 1;
91

92
	$speeds[ $glom1 . "+" . $glom2 ] = $time * 1000;
93
	$bws[ $glom1 . "+" . $glom2 ] = $bw;
94
	$plrs[ $glom1 . "+" . $glom2 ] = $plr * 100.0;
95 96 97 98 99
	$dates[ $glom1 . "+" . $glom2 ] =
	    strftime("%m/%d-%H:%M", $start) . "<br>" .
	    strftime("%m/%d-%H:%M", $end);
	
	
100
    }
101 102 103 104
    asort($nodenamesrow, SORT_NUMERIC);
    reset($nodenamesrow);
    asort($nodenamescol, SORT_NUMERIC);
    reset($nodenamescol);
105

106 107 108
    if (! $plain) {
	echo "<center>
               <b>$title</b><br>\n";
109
    
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
	if ($showtype == 1)
	    echo "(Delay,BW,PLR)\n";
	elseif ($showtype == 2)
	    echo "(Delay)\n";
	elseif ($showtype == 3)
	    echo "(BW)\n";
	elseif ($showtype == 4)
	    echo "(PLR)\n";
	elseif ($showtype == 5)
	    echo "(Time Span of Data)\n";

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

	echo "<table border=2 
                     cellpadding=1 cellspacing=2 align=center>
               <tr>";
	echo "   <td>&nbsp</td>\n";

	while (list($n1, $ignore1) = each($nodenamescol)) {
	    echo "<td>$n1</td>\n";
	}
	reset($nodenamescol);
	echo " </tr>\n";
    }
    else {
	printf("$title:\n");
	printf("%10s ", " ");
	while (list($n1, $ignore1) = each($nodenamescol)) {
	    printf("%10s ", $n1);
	}
	echo "\n";
	reset($nodenamescol);
142 143 144
    }

    while (list($n1, $ignore1) = each($nodenamesrow)) {
145 146 147 148 149 150 151
	if (! $plain) {
	    echo "<tr>";
	    echo "  <td>$n1</td>";
	}
	else {
	    printf("%10s ", "$n1");
	}
152 153 154
    
	while (list($n2, $ignore2) = each($nodenamescol)) {
	    if (strcmp($n1, $n2)) {
155 156 157
		$s = -1;
		$b = -1;
		$p = -1;
158
		$d = (($plain) ? "" : "&nbsp");
159 160 161 162 163 164 165
		$glom = $n1 . "+" . $n2;

		if (isset($speeds[$glom])) {
		    $s = (int) $speeds[$glom];
		    $b = (int) $bws[$glom];
		    $p = sprintf("%.2f", $plrs[$glom]);
		    $d = $dates[$glom];
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
		if ($plain) {
		    if ($showtype == 1)
			printf("%10s ", "$s,$b,$p");
		    elseif ($showtype == 2)
			printf("%10s ", "$s");
		    elseif ($showtype == 3)
			printf("%10s ", "$b");
		    elseif ($showtype == 4)
			printf("%10s ", "$p");
		    elseif ($showtype == 5)
			printf("%10s ", "$d");
		}
		else {
		    if ($showtype == 1)
			echo "<td>$s,$b,$p</td>";
		    elseif ($showtype == 2)
			echo "<td align=center>$s</td>";
		    elseif ($showtype == 3)
			echo "<td align=center>$b</td>";
		    elseif ($showtype == 4)
			echo "<td align=center>$p</td>";
		    elseif ($showtype == 5)
			echo "<td align=center nowrap=1>$d</td>";
		}
191 192
	    }
	    else {
193 194 195 196
		if ($plain)
		    printf("%10s ", "*");
		else
		    echo "<td align=center><img src=blueball.gif alt=0</td>";
197 198 199
	    }
	}
	reset($nodenamescol);
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
	if (!$plain) {
	    echo "</tr>";
	}
	echo "  \n";
    }
    if ($plain) {
	echo "\n\n";
    }
    else {
	echo "</table>\n";
	echo "<center>
              Delay in milliseconds, Bandwidth in KB/s, PLR rounded to two
	      decimal places (0-100%).
              </center>\n";
	echo "<br>\n";
215 216 217
    }
}

218 219
SPITDATA("widearea_recent", "Most Recent Data", $showtype, $plain);
SPITDATA("widearea_delays", "Aged Data", $showtype, $plain);
220 221 222

#
# Standard Testbed Footer
223 224 225 226
#
if (! $plain) {
    PAGEFOOTER();
} 
227
?>