tbreport.in 21.5 KB
Newer Older
1
#!/usr/bin/perl -wT
2

Leigh Stoller's avatar
Leigh Stoller committed
3 4
#
# EMULAB-COPYRIGHT
5
# Copyright (c) 2000-2004 University of Utah and the Flux Group.
Leigh Stoller's avatar
Leigh Stoller committed
6 7 8 9
# All rights reserved.
#


10 11 12 13 14 15 16
#
# tbreport - given a pid and eid, print out useful information, including
# a list of nodes and links, about the experiment. Only useful when the
# experiment is in the active, swapped, or testing states
#

sub usage {
17
    print "Usage: $0 [-h] [-n] [-l] [-m] [-e] [-d] [-r] [-v] pid eid\n";
18
    print "-h		Shows this message\n";
19 20 21 22 23
    print "-n		Show node info\n";
    print "-m		Show node mapping\n";
    print "-l		Show link info\n";
    print "-d		Show traffic shapping info\n";
    print "-e		Show event listing\n";
24
    print "-r		Show routes\n";
25 26
    print "-b		Show most things\n";
    print "-v		Show everything!\n";
27 28
    return 1;
}
29

30
my $TBROOT = "@prefix@";
31 32
my $DOMAIN = "@OURDOMAIN@";

33
use lib '@prefix@/lib';
34
use libtestbed;
35
use libdb;
36
require exitonwarn;
37
use Getopt::Std;
38

Leigh Stoller's avatar
Leigh Stoller committed
39 40 41 42
#
# Turn off line buffering on output
#
$| = 1;
43

44 45 46 47
#
# Get options
#
my %opt = ();
48 49 50 51 52 53
my $verbose    = 0;
my $shownodes  = 0;
my $showmap    = 0;
my $showlinks  = 0;
my $showdelays = 0;
my $showevents = 0;
54
my $showroutes = 0;
55 56 57
my %v2pmap;
my %p2type;
my %p2osid;
58
my %vv2pmap;
59 60
my $hasremote  = 0;
my $hasplab    = 0;
61 62 63
my %ipmap;
my %macmap;
my %membermap;
64

65
getopts('hnmdlevbr',\%opt);
66

67 68 69 70
if ($opt{h}) {
    exit &usage;
}
if ($opt{v}) {
Leigh Stoller's avatar
Leigh Stoller committed
71
    $verbose = 1;
72 73 74 75 76
    $shownodes = 1;
    $showmap = 1;
    $showdelays = 1;
    $showlinks = 1;
    $showevents = 1;
77
    $showroutes = 1;
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
}
if ($opt{b}) {
    $shownodes = 1;
    $showmap = 1;
    $showdelays = 1;
    $showlinks = 1;
}
if ($opt{n}) {
    $shownodes = 1;
}
if ($opt{m}) {
    $showmap = 1;
}
if ($opt{d}) {
    $showdelays = 1;
}
if ($opt{l}) {
    $showlinks = 1;
}
if ($opt{e}) {
    $showevents = 1;
99
}
100 101 102
if ($opt{r}) {
    $showroutes = 1;
}
103 104 105 106 107
if (@ARGV != 2) {
    exit &usage;
}

my ($pid,$eid) = @ARGV;
Leigh Stoller's avatar
Leigh Stoller committed
108
my $state;
109

110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
#
# Untaint the arguments.
#
if ($pid =~ /^([-\w\.]+)$/) {
    $pid = $1;
}
else {
    die("Tainted argument $pid!\n");
}
if ($eid =~ /^([-\w\.]+)$/) {
    $eid = $1;
}
else {
    die("Tainted argument $eid!\n");
}

126
#
Leigh Stoller's avatar
Leigh Stoller committed
127
# Experiment must exist.
128
#
Leigh Stoller's avatar
Leigh Stoller committed
129 130
if (!($state = ExpState($pid,$eid))) {
    die("There is no experiment $eid in project $pid\n");
131 132
}

Leigh Stoller's avatar
Leigh Stoller committed
133 134 135 136 137 138 139
#
# User must have permission to view the experiment.
#
if ($UID) {
    if (!TBExptAccessCheck($UID, $pid, $eid, TB_EXPT_READINFO)) {
        die("*** You not have permission to view this experiment!\n");
    }
140
}
141

142
if (($state ne EXPTSTATE_SWAPPED) &&
143
    ($state ne EXPTSTATE_ACTIVE)) {
Leigh Stoller's avatar
Leigh Stoller committed
144
    # nothing to do
145
    print "No information available.\n";
Leigh Stoller's avatar
Leigh Stoller committed
146
    exit(0);
147 148
}

149 150 151 152
print "Experiment: $pid/$eid\n";
print "State: $state\n";
print "\n";

153
# Read nodemap if applicable
154
if ($state eq EXPTSTATE_ACTIVE) {
155
    my $query_result =
156
	DBQueryFatal("select r.vname,r.node_id,n.type,n.phys_nodeid,o.osname,".
157 158
		     "       n.sshdport,n.jailflag,nt.isremotenode,".
		     "       nt.isplabdslice ".
159
		     "  from reserved as r ".
160 161
		     "left join nodes as n on r.node_id=n.node_id ".
		     "left join os_info as o on o.osid=n.def_boot_osid ".
162
		     "left join node_types as nt on nt.type=n.type ".
163
		     "where r.pid='$pid' and r.eid='$eid' order by vname");
164

165
    while (($v,$p,$t,$m,$o,$s,$j,$r,$d) = $query_result->fetchrow_array()) {
166
	if (!$v) {
167
	    $v = $p;
168
	}
169 170 171 172 173 174 175 176
	$v2pmap{$v} = {
	    PNODE	=> $p,
	    TYPE	=> $t,
	    OSID	=> $o,
	    VVP		=> $m,
	    SSHDPORT	=> $s,
	    JAILED	=> $j,
	    ISREMOTE    => $r,
177
	    PLAB	=> $d,
178
	};
179 180 181 182 183 184
	if ($r) {
	    $hasremote = 1;
	}
	if ($d) {
	    $hasplab = 1;
	}
185
    }
186 187 188 189 190 191 192
}

#
# Display virtual info. We might need the ips for below, so we always do
# this.
#
my $virtnodes_result =
193
    DBQueryFatal("SELECT vname,osname,cmd_line,rpms," .
194
		 "startupcmd,tarfiles,type,fixed from virt_nodes ".
195
		 "where pid='$pid' and eid='$eid' order by vname");
196 197 198

if ($shownodes) {
    print "Virtual Node Info:\n";
199 200 201
    printf "%-15s %-12s %-15s %s\n", "ID", "Type", "OS", "Qualified Name";
    print "--------------- ------------ --------------- ".
	  "--------------------\n";
202

203
    while (($vname,$osname,$cmd_line,$rpms,$startupcmd,
204
	    $tarfiles,$type,$fixed) = $virtnodes_result->fetchrow_array()) {
205
	my $qualname = "$vname.$eid.$pid.$DOMAIN";
206 207 208 209

	if ($fixed) {
	    $vname = "$vname ($fixed)";
	}
210

211
	printf "%-15s %-12s %-15s %s\n", $vname, $type, $osname, $qualname;
Leigh Stoller's avatar
Leigh Stoller committed
212 213 214 215 216 217 218 219 220 221 222 223 224 225
	if ($cmd_line ne "") {
	    printf "   %-17s %s\n", "Command Line:", $cmd_line;
	}
	if ($startupcmd ne "") {
	    printf "   %-17s %s\n", "Startup Command:", $startupcmd;
	}
	if ($rpms ne "") {
	    printf "   %-17s %s\n", "RPMS:", $rpms;
	}
	if ($tarfiles ne "") {
	    printf "   %-17s %s\n", "Tarfiles:", $tarfiles;
	}
    }
    print "\n";
226
}
Leigh Stoller's avatar
Leigh Stoller committed
227

228 229
#
# Physical mapping of virtual topology
230
#
231
if ($showmap && $state eq EXPTSTATE_ACTIVE) {
232
    print  "Physical Node Mapping:\n";
233 234
    printf "%-15s %-12s %-15s %-12s\n", "ID", "Type", "OS", "Physical";
    print  "--------------- ------------ --------------- ------------\n";
235

236
    foreach $v (sort keys(%v2pmap)) {
237 238 239 240
	my $p = $v2pmap{$v}->{PNODE};
	my $t = $v2pmap{$v}->{TYPE};
	my $o = $v2pmap{$v}->{OSID};
	my $m = $v2pmap{$v}->{VVP};
241 242 243 244 245
	printf "%-15s %-12s %-15s %s", $v, $t, $o, $p;
	if ($m ne $p) {
	    printf " ($m)";
	}
	printf "\n";
Leigh Stoller's avatar
Leigh Stoller committed
246 247
    }
    print "\n";
248

249
    if ($hasremote || $hasplab) {
250 251 252 253 254 255 256 257 258 259
	# Have to do this query twice, once to get the number of distinct
	# sites
	my $wai_query = "from reserved as r ".
			 "left join nodes as n on r.node_id=n.node_id ".
			 "left join widearea_nodeinfo as w on ".
			 "    w.node_id=n.phys_nodeid " .
			 "where pid='$pid' and eid='$eid' order by vname";
	my $distinct_sites_results =
	    DBQueryFatal("select count(distinct site) $wai_query");
        my ($sites) = $distinct_sites_results->fetchrow_array();
260
	my $widearea_info_result =
261 262 263 264 265 266
	    DBQueryFatal("select vname, site, hostname $wai_query");
	print  "Wide-Area Node Hostnames and Sites: $sites distinct sites\n";
	printf "%-15s %-20s %-40s \n", "ID", "Site", "Hostname";
	print  "--------------- -------------------- --------------------\n";
	while (($vname,$site,$hostname)
		= $widearea_info_result->fetchrow_array()) {
267 268 269 270 271 272
	    next unless
		($v2pmap{$vname}->{ISREMOTE} || $v2pmap{$vname}->{PLAB});
	    my $pnode = $v2pmap{$vname}->{VVP};
	    if (!defined($hostname)) {
		$hostname = "--";
	    }
273 274 275 276
	    if (!defined($site)) {
		$site = "--";
	    }
	    printf "%-15s %-20s %-40s\n", $vname, $site, $hostname;
277 278 279 280 281
	}
	print "\n";
    }


282 283 284 285 286
    my $range_result =
	DBQueryFatal("select low,high from ipport_ranges ".
		     "where pid='$pid' and eid='$eid'");
    if ($range_result->numrows) {
	my ($low,$high) = $range_result->fetchrow_array();
287

288
	print  "IP Port allocation:\n";
289 290 291
	printf "%-15s %-12s \n", "Low", "High";
	print  "--------------- ------------\n";
	printf "%-15s %-12s\n", $low, $high;
292
	print  "\n";
293 294 295 296

	print  "SSHD Port allocation ('ssh -p portnum'):\n";
	printf "%-15s %-10s %-20s\n", "ID", "Port", "SSH command";
	print  "--------------- ---------- ----------------------\n";
297
	foreach $v (sort keys(%v2pmap)) {
298 299 300
	    my $p = $v2pmap{$v}->{PNODE};
	    my $s = $v2pmap{$v}->{SSHDPORT};
	    my $m = $v2pmap{$v}->{VVP};
301
	    my $q = "$v.$eid.$pid.$DOMAIN";
302 303
	    if (($v2pmap{$v}->{JAILED} || $v2pmap{$v}->{PLAB}) &&
		$v2pmap{$v}->{ISREMOTE}) {
304 305 306 307 308
		printf "%-15s %-10s %-20s", $v, $s, "ssh -p $s $q";
		print  "\n";
	    }
	}
	print "\n";
309
    }
310 311 312 313 314 315
}

#
# Links and Lans
#
if ($showlinks) {
316 317 318 319 320 321 322
    $result =
	DBQueryFatal("select vname,vnode,vport,ip,member,mask,delay, ".
		     "       bandwidth,lossrate, ".
		     "       rdelay,rbandwidth,rlossrate,protocol ".
		     "  from virt_lans as v ".
		     "where pid='$pid' and eid='$eid' ".
		     "order by vname,member");
Leigh Stoller's avatar
Leigh Stoller committed
323

324 325 326
    while (my ($vname,$vnode,$vport,$ip) = $result->fetchrow_array()) {
	$ipmap{"$vnode:$vport"} = $ip;
	$macmap{$ip}->{"MEMBER"} = "$vnode:$vport";
327
    }
328
    $result->dataseek(0);
329

330
    my $iface_result =
331 332 333 334 335
	DBQueryFatal("select i.ip,i.mac,i.iface from reserved as r ".
		     "left join interfaces as i on r.node_id=i.node_id ".
		     "where r.pid='$pid' and r.eid='$eid' and ".
		     "      i.ip is not NULL and i.ip!=''");

336
    while (($ip,$mac,$iface) = $iface_result->fetchrow_array()) {
337 338 339 340 341 342 343
	if ($mac =~ /^(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})$/) {
	    $mac = "$1:$2:$3:$4:$5:$6";
	}
	$macmap{$ip}->{"MAC"}   = $mac;
	$macmap{$ip}->{"IFACE"} = $iface;
    }

344
    if ($result->numrows) {
345
	print  "Virtual Lan/Link Info:\n";
346
	printf "%-15s %-15s %-15s %-9s %-9s %-9s\n",
347
	       "ID", "Member/Proto", "IP/Mask", "Delay", "BW (Kbs)", "Loss Rate";
348 349
	print  "--------------- --------------- --------------- --------- ".
	       "--------- ---------\n";
350

351 352
	while (($vname,$vnode,$vport,$ip,$member,$mask,$delay,$bandwidth,
		$lossrate,$rdelay,$rbandwidth,$rlossrate,$protocol)
353
	       = $result->fetchrow_array()) {
354
	    printf "%-15s %-15s %-15s %-9s %-9s %-9s\n", $vname,
355 356
	           $member, $ipmap{$member}, $delay, $bandwidth, $lossrate;
	    printf "%-15s %-15s %-15s %-9s %-9s %-9s\n", "",
357
	           $protocol, $mask, $rdelay, $rbandwidth, $rlossrate;
358 359 360 361
	}
	print "\n";
    }

362 363 364 365 366 367 368 369 370
    if ($state eq EXPTSTATE_ACTIVE && $result->numrows) {
	$result->dataseek(0);

	print  "Physical Lan/Link Mapping:\n";
	printf "%-15s %-15s %-15s %-20s %-9s\n",
	       "ID", "Member", "IP", "MAC", "NodeID";
	print  "--------------- --------------- --------------- ".
	       "-------------------- ---------\n";

371 372
	while (($vname,$vnode,$vport,$ip,$member) =
	       $result->fetchrow_array()) {
373 374 375
	    my ($vname,$port) = split(":", $member);
	    
	    printf "%-15s %-15s %-15s %-20s %-9s\n", $vname,
376 377 378 379
	            $member, $ipmap{$member},
	            (defined($macmap{$ipmap{$member}}->{"MAC"}) ?
		     $macmap{$ipmap{$member}}->{"MAC"} : ""),
		    $v2pmap{$vname}->{PNODE};
380 381 382 383
	}
	print "\n";
    }

384 385 386 387 388
    # Queue info.
    $result =
	DBQueryFatal("select vname,member,q_limit,q_maxthresh,q_minthresh, ".
		     "q_weight,q_linterm,q_qinbytes,q_red,q_gentle ".
		     "  from virt_lans ".
389
		     "where pid='$pid' and eid='$eid' ".
390
		     "order by vname,member");
391 392 393

    if ($result->numrows) {
	print  "Virtual Queue Info:\n";
394
	printf "%-15s %-15s %-10s %-7s %s\n",
395 396 397 398
	       "ID", "Member", "Q Limit", "Type",
	       "weight/min_th/max_th/linterm";
	print  "--------------- --------------- ---------- ".
	       "------- ----------------------------\n";
399

400 401 402 403
	while (($vname,$member,$q_limit,$q_maxthresh,$q_minthresh,
		$q_weight,$q_linterm,$q_qinbytes,$q_red,$q_gentle)
	       = $result->fetchrow_array()) {

404
	    printf("%-15s %-15s %-10s %-7s %s\n", $vname, $member,
405
		   $q_limit . ($q_qinbytes ? " bytes" : " slots"),
406 407 408
		   ($q_red ? ($q_gentle ? "GRED" : "RED") : "Tail"),
		   ($q_red ? "$q_weight/$q_minthresh/$q_maxthresh/$q_linterm" :
		    "0/0/0/0"));
409 410 411
	}
	print "\n";
    }
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
    #
    # Settings.
    #
    my $result1 =
	DBQueryFatal("select vname,capkey,capval from virt_lan_settings ".
		     "where pid='$pid' and eid='$eid' ".
		     "order by vname");

    my $result2 =
	DBQueryFatal("select vname,member,capkey,capval ".
		     "  from virt_lan_member_settings ".
		     "where pid='$pid' and eid='$eid' ".
		     "order by vname,member");

    if ($result1->numrows || $result2->numrows) {
	print  "Virtual Lan Settings:\n";
	printf "%-15s %-15s %-20s %-20s\n", "ID", "Member", "Key", "Value";
	print  "--------------- --------------- -------------------- ".
	       "--------------------\n";

	while (my ($vname,$capkey,$capval) = $result1->fetchrow_array()) {
	    printf("%-15s %-15s %-20s %-20s\n", $vname, "", $capkey, $capval);
	}
	while (my ($vname,$member,$capkey,$capval) =
	       $result2->fetchrow_array()) {
	    printf("%-15s %-15s %-20s %-20s\n", $vname, $member,
		   $capkey, $capval);
	}
	print "\n";
    }

444 445 446
    #
    # Actual mapped information for widearea links
    #
447
    if ($state eq EXPTSTATE_ACTIVE) {
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
	#
	# Grab actual interface settings.
	#
	$result =
	    DBQueryFatal("select s.* from reserved as r ".
			 "left join interface_settings as s on ".
			 "     s.node_id=r.node_id ".
			 "where r.pid='$pid' and r.eid='$eid' ".
			 "     and s.iface is not null ".
			 "order by s.node_id,s.iface");

	if ($result->numrows) {
	    print  "Physical Lan Settings:\n";
	    printf "%-15s %-15s %-20s %-20s\n", "ID", "Iface", "Key", "Value";
	    print  "--------------- --------------- -------------------- ".
		"--------------------\n";

	    while (my ($pnode,$iface,$capkey,$capval) =
		   $result->fetchrow_array()) {
		printf("%-15s %-15s %-20s %-20s\n", $pnode, $iface,
		       $capkey, $capval);
	    }
	    print "\n";
	}
	
473
	#
474
	# Grab all widearea links from the database
475
	#
476 477 478 479
	my %links = ();
	$result =
	    DBQueryFatal("select vname,member,delay,bandwidth,lossrate ".
			 "from virt_lans where pid='$pid' and eid='$eid' and ".
480
			 "widearea!=0 order by vname,member");
481
	if ($result->numrows) {
482
	    while (($vname,$member,$delay,$bandwidth,$lossrate)
483 484
		       = $result->fetchrow_array()) {
		$member =~ /(.+):(\d+)/;
485
		my ($pname,$card) = ($v2pmap{$1}->{PNODE}, $2);
486 487 488 489 490 491 492 493 494 495 496 497

		#
		# Check to see if the 'physical' node name is just a
		# virtual (multiplexed) name for a _real_ physical name
		#
		my $realpname;
		if (TBPhysNodeID($pname,\$realpname)) {
		    push @{$links{$vname}}, [$member,$realpname,$card];
		} else {
		    push @{$links{$vname}}, [$member,$pname,$card];
		}
	    }
498 499
	}

500
	if (keys %links) {
501

502
	    #
503
	    # Grab all data from widearea_recent
504
	    #
505 506 507 508 509
	    my $result = DBQueryFatal("select node_id1, node_id2, time, " .
		"bandwidth, lossrate from widearea_recent");
	    my %delaymap = ();
	    while (my ($node_id1, $node_id2, $time, $bandwidth,
		    $lossrate) = $result->fetchrow) {
510
		$delaymap{"$node_id1 $node_id2"} =
511
		    [$time * 1000 / 2, $bandwidth, $lossrate];
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544
	    }

	    print  "Wide-Area Lan/Link Info: Recent Data\n";
	    printf "%-15s %-15s %-15s %-9s %-9s %-9s\n",
		    "ID", "Source", "Destination", "Delay/2", "BW (Kbs)",
		    "Loss Rate";
	    print  "--------------- --------------- --------------- --------- ".
		    "--------- ---------\n";

	    foreach my $link (sort keys %links) {
		my ($node1, $node2) = @{$links{$link}};
		my ($virt1,$pname1,$card1) = @$node1;
		my ($virt2,$pname2,$card2) = @$node2;

		my ($wname1, $wname2);
		if (!TBWideareaNodeID($pname1,\$wname1)) {
		    $wname1 = $pname1;
		}
		if (!TBWideareaNodeID($pname2,\$wname2)) {
		    $wname2 = $pname2;
		}

		#
		# Have to get both orders (node1,node2) and (node2,node1)
		#
		printf "%-15s %-15s %-15s ", $link, $virt1, $virt2;
		my $delay1 = $delaymap{"$wname1 $wname2"};
		if (!$delay1) {
		    if ($wname1 eq $wname2) {
			print "Local or loopback connection\n";
		    } else {
			print "No data available\n";
		    }
545
		} else {
546 547 548
		    my ($time, $bandwidth, $lossrate) =  @$delay1;
		    printf "%-9.2f %-9.2f %-9.4f\n", $time, $bandwidth,
			    $lossrate;
549
		}
550

551 552 553 554 555 556 557 558
		printf "%-15s %-15s %-15s ", $link, $virt2, $virt1;
		my $delay2 = $delaymap{"$wname2 $wname1"};
		if (!$delay2) {
		    if ($wname1 eq $wname2) {
			print "Local or loopback connection\n";
		    } else {
			print "No data available\n";
		    }
559
		} else {
560 561 562
		    my ($time, $bandwidth, $lossrate) =  @$delay2;
		    printf "%-9.2f %-9.2f %-9.4f\n", $time, $bandwidth,
			    $lossrate;
563
		}
564
	    }
Robert Ricci's avatar
Robert Ricci committed
565

566 567
	    print "\n";
	}
568
    }
569 570
}

571

572 573 574
#
# Delay node info.
#
575
if ($showdelays && $state eq EXPTSTATE_ACTIVE) {
576 577
    $result_delays =
	DBQueryFatal("select d.*,r.vname as delayvname from delays as d ".
578
		     "left join reserved as r on d.node_id=r.node_id ".
579 580
		     "where d.pid='$pid' and d.eid='$eid' ".
		     "order by vname,vnode0");
581

582 583
    $result_linkdelays =
	DBQueryFatal("select * from linkdelays ".
584 585 586
		     "where pid='$pid' and eid='$eid' ".
		     "order by vlan,vnode,node_id");

587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
    if ($result_delays->numrows || $result_linkdelays->numrows) {
	print  "Physical Lan/Link Info:\n";
	printf "%-15s %-15s %-12s %-8s %-8s %-6s %-9s\n",
	       "ID", "Member", "Delay Node", "Delay", "BW (Kbs)", "PLR",
	       "Pipe";
	print  "--------------- --------------- ------------ -------- ".
	       "-------- ------ ---------\n";
    }

    if ($result_delays->numrows) {
	while (my %row = $result_delays->fetchhash()) {
	    printf("%-15s %-15s %-12s %-8s %-8s %-6s %-9s\n",
		   $row{vname}, $row{vnode0}, $row{delayvname},
		   $row{delay0}, $row{bandwidth0}, $row{lossrate0},
		   $row{pipe0});

	    # If vnode0 eq vnode1, its a lan node. Print differently.
	    printf("%-15s %-15s %-12s %-8s %-8s %-6s %-9s\n",
		   ($row{vnode0} eq $row{vnode1} ? "" : $row{vname}),
		   ($row{vnode0} eq $row{vnode1} ? "" : $row{vnode1}),
		   ($row{vnode0} eq $row{vnode1} ? "" : $row{delayvname}),
		   $row{delay1}, $row{bandwidth1}, $row{lossrate1},
		   $row{pipe1});
	}
	print "\n";
    }
613

614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
    if ($result_linkdelays->numrows) {
	while (my %row = $result_linkdelays->fetchhash()) {
	    printf("%-15s %-15s %-12s %-8s %-8s %-6s %-9s\n",
		   $row{vlan}, $row{vnode}, $row{node_id},
		   $row{delay}, $row{bandwidth}, $row{lossrate},
		   $row{pipe});


	    # Lan node, from the switch
	    if ($row{type} eq "duplex") {
		printf("%-15s %-15s %-12s %-8s %-8s %-6s %-9s\n", "", "", "",
		       $row{rdelay}, $row{rbandwidth}, $row{rlossrate},
		       $row{rpipe});
	    }
	}
	print "\n";
    }
631

632 633 634 635 636
    $result_delays->dataseek(0);
    $result_linkdelays->dataseek(0);

    if ($result_delays->numrows || $result_linkdelays->numrows) {
	print  "Physical Queue Info:\n";
637
	printf "%-15s %-15s %-15s %-7s %s\n",
638 639 640 641 642
	       "ID", "Member", "Q Limit", "Type",
	       "weight/min_th/max_th/linterm";
	print  "--------------- --------------- ---------- ".
	       "------- ----------------------------\n";
    }
643

644 645
    if ($result_delays->numrows) {
	while (my %row = $result_delays->fetchhash()) {
646
	    printf("%-15s %-15s %-15s %-7s %s\n", $row{vname},
647
		   $row{vnode0},
648
		   $row{q0_limit} . ($row{q0_qinbytes} ? " bytes" : " slots"),
649 650 651 652 653 654 655 656 657
		   ($row{q0_red} ?
		    ($row{q0_gentle} ? "GRED" : "RED") : "Tail"),
		   ($row{q0_red} ?
		    "$row{q0_weight}/$row{q0_minthresh}/".
		    "$row{q0_maxthresh}/$row{q0_linterm}" :
		    "0/0/0/0"));

	    # If equal, its a lan, and so only one queue towards the switch
	    if ($row{vnode0} ne $row{vnode1}) {
658
		printf("%-15s %-15s %-15s %-7s %s\n", $row{vname},
659
		       $row{vnode1},
660
		       $row{q1_limit} . ($row{q1_qinbytes} ? " bytes" : " slots"),
661 662 663 664 665 666 667 668 669 670 671 672 673
		       ($row{q1_red} ?
			($row{q1_gentle} ? "GRED" : "RED") : "Tail"),
		       ($row{q1_red} ?
			"$row{q1_weight}/$row{q1_minthresh}/".
			"$row{q1_maxthresh}/$row{q1_linterm}" :
			"0/0/0/0"));
	    }
	}
	print "\n";
    }

    if ($result_linkdelays->numrows) {
	while (my %row = $result_linkdelays->fetchhash()) {
674
	    printf("%-15s %-15s %-15s %-7s %s\n", $row{vlan},
675
		   $row{vnode},
676
		   $row{q_limit} . ($row{q_qinbytes} ? " bytes" : " slots"),
677 678 679
		   ($row{q_red} ?
		    ($row{q_gentle} ? "GRED" : "RED") : "Tail"),
		   ($row{q_red} ?
Leigh Stoller's avatar
Leigh Stoller committed
680 681
		    "$row{q_weight}/$row{q_minthresh}/".
		    "$row{q_maxthresh}/$row{q_linterm}" :
682
		    "0/0/0/0"));
683
	}
684
	print "\n";
685
    }
686 687
}

688 689 690 691 692
#
# Print route list.
#
if ($showroutes) {
    my $result =
693
	DBQueryFatal("select vname,src,dst,dst_type,dst_mask,nexthop,cost ".
694
		     " from virt_routes where ".
695
		     "pid='$pid' and eid='$eid' order by vname,src,dst");
696 697 698

    if ($result->numrows) {
	print  "Route List:\n";
699 700
	printf "%-15s %-15s %-15s %-15s %-5s %-4s \n",
	       "Node", "Interface", "Dest", "Nexthop", "Type", "Cost";
701
	print  "--------------- --------------- --------------- ".
702
	       "--------------- ----- ----\n";
703

704
	while (($vname,$src,$dst,$dst_type,$dst_mask,$nexthop,$cost) =
705 706 707 708 709
	       $result->fetchrow_array()) {

	    if ($dst_type eq "host") {
		$dst_mask = "host";
	    }
710 711
	    printf "%-15s %-15s %-15s %-15s %-5s %-4s \n",
	           $vname, $src, $dst, $nexthop, $dst_type, $cost;
712 713 714 715 716
	}
	print "\n";
    }
}

717
#
718 719 720 721
# Print event list or summary
#
if ($showevents) {
    my $result =
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750
	DBQueryFatal("select group_name,agent_name from event_groups ".
		     "where pid='$pid' and eid='$eid' ".
		     "order by group_name");

    if ($result->numrows) {
	my %egroups = ();

	while (($group_name,$agent_name) = $result->fetchrow_array()) {
	    if (!exists($egroups{$group_name})) {
		$egroups{$group_name} = [];
	    }
	    push(@{ $egroups{$group_name} }, $agent_name);
	}
	print  "Event Groups:\n";

	printf("%-15s %s\n",
	       "Group Name", "Members");
	print("--------------- --------------------------------".
	      "-------------------------------\n");

	foreach my $group (keys(%egroups)) {
	    my @agents = @{ $egroups{$group} };
	    
	    printf("%-15s %s\n", $group, join(",", @agents));
	}
	print "\n";
    }
    
    $result =
751 752 753 754 755
	DBQueryFatal("select time,vnode,vname,ot.type,et.type,arguments ".
		" from eventlist as ex ".
		"left join event_eventtypes as et on ex.eventtype=et.idx ".
		"left join event_objecttypes as ot on ex.objecttype=ot.idx ".
		"where ex.pid='$pid' and ex.eid='$eid' ".
756
		"order by time,vnode,vname,ex.idx");
757 758 759 760 761 762 763 764

    if ($result->numrows) {
	if ($verbose) {
	    print  "Event List:\n";
	    printf "%-12s %-12s %-10s %-10s %-10s %s\n",
	           "Time", "Node", "Agent", "Type", "Event", "Arguments";
	    print  "------------ ------------ ---------- ---------- ".
		   "---------- ------------ \n";
765

766 767 768 769
	    while (($time,$vnode,$vname,$obj,$type,$args) =
		   $result->fetchrow_array()){
		printf("%-12s %-12s %-10s %-10s %-10s ",
		       $time, $vnode, $vname, $obj, $type);
770

771 772
		my @arglist = split(" ", $args);
		my $arg     = shift(@arglist);
773

774 775 776 777 778 779 780 781
		if (defined($arg)) {
		    printf("$arg");
		}
		printf("\n");
		foreach my $arg (@arglist) {
		    printf("%-58s %s\n", "", $arg);
		}
	    }
782
	}
783 784 785 786
	else {
	    my $min;
	    my $max;
	    my $count = $result->numrows;
787

788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
	    while (($time,$vnode,$vname,$obj,$type,$args) =
		   $result->fetchrow_array()) {

		if (!defined($min)) {
		    $min = $time;
		    $max = $time;
		}
		if ($time > $max) {
		    $max = $time;
		}
	    }

	    print "Event Summary:\n";
	    print "--------------\n";
	    print "Event count:    $count\n";
	    print "First event:    $min seconds\n";
	    print "Last event:     $max seconds\n";
805 806 807
	}
    }
}
808

809
exit(0);