widearea_info.php3 6.04 KB
Newer Older
1
<?php
Leigh Stoller's avatar
Leigh Stoller committed
2
#
3
# Copyright (c) 2000-2003, 2006, 2007 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/>.
# 
# }}}
Leigh Stoller's avatar
Leigh Stoller committed
23
#
24 25 26
include("defs.php3");

#
27
# Only known and logged in users.
28
#
29 30 31
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
32

33 34 35 36 37 38
#
# Verify page arguments.
#
$optargs = OptionalPageArguments("showtype", PAGEARG_STRING,
				 "plain",    PAGEARG_BOOLEAN);

39 40 41 42 43
#
# Show argument.
#
if (! isset($showtype))
    $showtype="delay";
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
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";
}
64 65 66 67 68 69 70 71 72 73 74 75

#
# 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;
76 77
elseif (!strcmp($showtype, "dates"))
    $showtype = 5;
78 79 80
else
    $showtype = 1;

81
function SPITDATA($table, $title, $showtype, $plain)
82 83
{
    $query_result1 =
84 85 86
	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");
87 88 89 90 91 92
    
    # PHP arrays are strange wrt "each" function. Need two copies.
    $nodenamesrow = array();
    $nodenamescol = array();

    while ($row = mysql_fetch_array($query_result1)) {
93 94 95 96 97 98 99 100 101 102
	$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"];
	$start    = $row["start_time"];
	$end      = $row["end_time"];
	$pri      = $row["priority"];
103 104 105 106
    
	$glom1    = $node_id1;
	$glom2    = $node_id2;

107
        #echo "Got $glom1 to $glom2 $pri<br>\n";
108
	
109 110
	$nodenamesrow["$glom1"] = $pri;
	$nodenamescol["$glom1"] = $pri;
111 112 113

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

115
	$speeds[ $glom1 . "+" . $glom2 ] = $time * 1000;
116
	$bws[ $glom1 . "+" . $glom2 ] = $bw;
117
	$plrs[ $glom1 . "+" . $glom2 ] = $plr * 100.0;
118 119 120 121 122
	$dates[ $glom1 . "+" . $glom2 ] =
	    strftime("%m/%d-%H:%M", $start) . "<br>" .
	    strftime("%m/%d-%H:%M", $end);
	
	
123
    }
124 125 126 127
    asort($nodenamesrow, SORT_NUMERIC);
    reset($nodenamesrow);
    asort($nodenamescol, SORT_NUMERIC);
    reset($nodenamescol);
128

129 130 131
    if (! $plain) {
	echo "<center>
               <b>$title</b><br>\n";
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
	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);
165 166 167
    }

    while (list($n1, $ignore1) = each($nodenamesrow)) {
168 169 170 171 172 173 174
	if (! $plain) {
	    echo "<tr>";
	    echo "  <td>$n1</td>";
	}
	else {
	    printf("%10s ", "$n1");
	}
175 176 177
    
	while (list($n2, $ignore2) = each($nodenamescol)) {
	    if (strcmp($n1, $n2)) {
178 179 180
		$s = -1;
		$b = -1;
		$p = -1;
181
		$d = (($plain) ? "" : "&nbsp");
182 183 184 185 186 187 188
		$glom = $n1 . "+" . $n2;

		if (isset($speeds[$glom])) {
		    $s = (int) $speeds[$glom];
		    $b = (int) $bws[$glom];
		    $p = sprintf("%.2f", $plrs[$glom]);
		    $d = $dates[$glom];
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
		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>";
		}
214 215
	    }
	    else {
216 217 218 219
		if ($plain)
		    printf("%10s ", "*");
		else
		    echo "<td align=center><img src=blueball.gif alt=0</td>";
220 221 222
	    }
	}
	reset($nodenamescol);
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
	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";
238 239 240
    }
}

241 242
SPITDATA("widearea_recent", "Most Recent Data", $showtype, $plain);
SPITDATA("widearea_delays", "Aged Data", $showtype, $plain);
243 244 245

#
# Standard Testbed Footer
246 247 248 249
#
if (! $plain) {
    PAGEFOOTER();
} 
250
?>