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

Leigh Stoller's avatar
Leigh Stoller committed
3 4
#
# EMULAB-COPYRIGHT
5
# Copyright (c) 2000-2008 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 {
Mike Hibler's avatar
Mike Hibler committed
17
    print "Usage: $0 [-h] [-n] [-l] [-m] [-e] [-f] [-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";
Mike Hibler's avatar
Mike Hibler committed
24
    print "-f		Show firewall rules\n";
25
    print "-r		Show routes\n";
26 27
    print "-b		Show most things\n";
    print "-v		Show everything!\n";
28 29
    return 1;
}
30

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

34
use lib '@prefix@/lib';
35
use libtestbed;
36
use libdb;
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;
Mike Hibler's avatar
Mike Hibler committed
55
my $showfwinfo = 0;
56 57 58
my %v2pmap;
my %p2type;
my %p2osid;
59
my %vv2pmap;
60 61
my $hasremote  = 0;
my $hasplab    = 0;
62 63
my %ipmap;
my %membermap;
64

65
getopts('hnmdlevbrfa',\%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;
Mike Hibler's avatar
Mike Hibler committed
78
    $showfwinfo = 1;
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
}
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;
100 101 102
    if ($opt{a}) {
	$verbose = 1;
    }
103
}
104 105 106
if ($opt{r}) {
    $showroutes = 1;
}
Mike Hibler's avatar
Mike Hibler committed
107 108 109
if ($opt{f}) {
    $showfwinfo = 1;
}
110 111 112 113 114
if (@ARGV != 2) {
    exit &usage;
}

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

117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
#
# 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");
}

133
#
Leigh Stoller's avatar
Leigh Stoller committed
134
# Experiment must exist.
135
#
Leigh Stoller's avatar
Leigh Stoller committed
136 137
if (!($state = ExpState($pid,$eid))) {
    die("There is no experiment $eid in project $pid\n");
138 139
}

Leigh Stoller's avatar
Leigh Stoller committed
140 141 142 143 144 145 146
#
# 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");
    }
147
}
148

149
if (($state ne EXPTSTATE_SWAPPED) &&
150
    ($state ne EXPTSTATE_ACTIVE)) {
Leigh Stoller's avatar
Leigh Stoller committed
151
    # nothing to do
152
    print "No information available.\n";
Leigh Stoller's avatar
Leigh Stoller committed
153
    exit(0);
154 155
}

156 157 158 159
print "Experiment: $pid/$eid\n";
print "State: $state\n";
print "\n";

160
# Read nodemap if applicable
161
if ($state eq EXPTSTATE_ACTIVE) {
162
    my $query_result =
163
	DBQueryFatal("select r.vname,r.node_id,n.type,n.phys_nodeid,o.osname,".
164
		     "       n.sshdport,n.jailflag,nt.isremotenode,".
165
		     "       nt.isplabdslice ".
166
		     "  from reserved as r ".
167 168
		     "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 ".
169
		     "left join node_types as nt on nt.type=n.type ".
170
		     "where r.pid='$pid' and r.eid='$eid' order by vname");
171

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

#
# Display virtual info. We might need the ips for below, so we always do
# this.
#
my $virtnodes_result =
200
    DBQueryFatal("SELECT vname,osname,cmd_line,rpms," .
201
		 "startupcmd,tarfiles,type,fixed from virt_nodes ".
202
		 "where pid='$pid' and eid='$eid' order by vname");
203 204 205

if ($shownodes) {
    print "Virtual Node Info:\n";
206 207 208
    printf "%-15s %-12s %-15s %s\n", "ID", "Type", "OS", "Qualified Name";
    print "--------------- ------------ --------------- ".
	  "--------------------\n";
209

210
    while (($vname,$osname,$cmd_line,$rpms,$startupcmd,
211
	    $tarfiles,$type,$fixed) = $virtnodes_result->fetchrow_array()) {
212
	my $qualname = "$vname.$eid.$pid.$DOMAIN";
213 214 215 216

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

218
	printf "%-15s %-12s %-15s %s\n", $vname, $type, $osname, $qualname;
219
	if (defined($cmd_line) && $cmd_line ne "") {
Leigh Stoller's avatar
Leigh Stoller committed
220 221
	    printf "   %-17s %s\n", "Command Line:", $cmd_line;
	}
222
	if (defined($startupcmd) && $startupcmd ne "") {
Leigh Stoller's avatar
Leigh Stoller committed
223 224
	    printf "   %-17s %s\n", "Startup Command:", $startupcmd;
	}
225
	if (defined($rpms) && $rpms ne "") {
Leigh Stoller's avatar
Leigh Stoller committed
226 227
	    printf "   %-17s %s\n", "RPMS:", $rpms;
	}
228
	if (defined($tarfiles) && $tarfiles ne "") {
Leigh Stoller's avatar
Leigh Stoller committed
229 230 231 232
	    printf "   %-17s %s\n", "Tarfiles:", $tarfiles;
	}
    }
    print "\n";
233
}
Leigh Stoller's avatar
Leigh Stoller committed
234

235 236
#
# Physical mapping of virtual topology
237
#
238
if ($showmap && $state eq EXPTSTATE_ACTIVE) {
239
    print  "Physical Node Mapping:\n";
240 241
    printf "%-15s %-12s %-15s %-12s\n", "ID", "Type", "OS", "Physical";
    print  "--------------- ------------ --------------- ------------\n";
242

243
    foreach $v (sort keys(%v2pmap)) {
244 245 246 247
	my $p = $v2pmap{$v}->{PNODE};
	my $t = $v2pmap{$v}->{TYPE};
	my $o = $v2pmap{$v}->{OSID};
	my $m = $v2pmap{$v}->{VVP};
248 249 250 251 252
	printf "%-15s %-12s %-15s %s", $v, $t, $o, $p;
	if ($m ne $p) {
	    printf " ($m)";
	}
	printf "\n";
Leigh Stoller's avatar
Leigh Stoller committed
253 254
    }
    print "\n";
255

256
    if ($hasremote || $hasplab) {
257 258 259 260 261 262 263 264 265 266
	# 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();
267
	my $widearea_info_result =
268 269 270 271 272 273
	    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()) {
274 275 276 277 278 279
	    next unless
		($v2pmap{$vname}->{ISREMOTE} || $v2pmap{$vname}->{PLAB});
	    my $pnode = $v2pmap{$vname}->{VVP};
	    if (!defined($hostname)) {
		$hostname = "--";
	    }
280 281 282 283
	    if (!defined($site)) {
		$site = "--";
	    }
	    printf "%-15s %-20s %-40s\n", $vname, $site, $hostname;
284 285 286 287 288
	}
	print "\n";
    }


289 290 291 292 293
    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();
294

295
	print  "IP Port allocation:\n";
296 297 298
	printf "%-15s %-12s \n", "Low", "High";
	print  "--------------- ------------\n";
	printf "%-15s %-12s\n", $low, $high;
299
	print  "\n";
300 301 302 303

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

#
# Links and Lans
#
if ($showlinks) {
323 324
    my %portmap = ();
    my %macmap  = ();
Leigh Stoller's avatar
Leigh Stoller committed
325

326 327 328 329
    my $vlan_result =
	DBQueryFatal("select v.* from virt_lans as v ".
		     "where v.pid='$pid' and v.eid='$eid' ".
		     "order by v.vname,v.member");
330

331 332 333 334 335
    while (my %row = $vlan_result->fetchhash()) {
	my $ip          = $row{"ip"};
	my $vnode       = $row{"vnode"};
	my $vport       = $row{"vport"};
	my $member      = "$vnode:$vport";
336

337 338 339 340 341 342 343 344 345 346 347 348 349 350
	$ipmap{$member} = $ip;
    }
    $vlan_result->dataseek(0);

    #
    # If swapped in, get a bunch of physical link info.
    #
    if ($state eq EXPTSTATE_ACTIVE && $vlan_result->numrows) {
	$link_result =
	    DBQueryFatal("select v.vname,v.vnode,v.vport, ".
			 "       i.ip,i.mac,i.iface,w.* from virt_lans as v ".
			 "left join reserved as r on r.vname=v.vnode and ".
			 "     r.pid=v.pid and r.eid=v.eid ".
			 "left join interfaces as i on r.node_id=i.node_id ".
351
			 "     and i.ip=v.ip ".
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
			 "left join wires as w on i.node_id=w.node_id1 ".
			 "     and i.card=w.card1 and i.port=w.port1 ".
			 "where v.pid='$pid' and v.eid='$eid' and ".
			 "      i.ip is not NULL and i.ip!='' ".
			 "order by v.vname,v.member");

	while (my %row = $link_result->fetchhash()) {
	    my $ip          = $row{"ip"};
	    my $mac         = $row{"mac"};
	    my $lan         = $row{"vname"};
	    my $vnode       = $row{"vnode"};
	    my $vport       = $row{"vport"};
	    my $iface       = $row{"iface"};
	    my $member      = "$vnode:$vport";

	    if ($mac =~ /^(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})$/) {
		$mac = "$1:$2:$3:$4:$5:$6";
	    }
	    $portmap{$member}->{"NODEMAC"}     = $mac;
	    $portmap{$member}->{"IFACE"}      = $iface;
	    $portmap{$member}->{"NODECARD"}   = $row{"card1"};
	    $portmap{$member}->{"NODEPORT"}   = $row{"port1"};
	    $portmap{$member}->{"SWITCH"}     = $row{"node_id2"};
	    $portmap{$member}->{"SWITCHCARD"} = $row{"card2"};
	    $portmap{$member}->{"SWITCHPORT"} = $row{"port2"};
377 378 379
	}
    }

380
    if ($vlan_result->numrows) {
381
	print  "Virtual Lan/Link Info:\n";
382
	printf "%-15s %-15s %-15s %-9s %-9s %-9s\n",
383
	       "ID", "Member/Proto", "IP/Mask", "Delay","BW (Kbs)","Loss Rate";
384 385
	print  "--------------- --------------- --------------- --------- ".
	       "--------- ---------\n";
386

387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
	while (my %row = $vlan_result->fetchhash()) {
	    my $vname       = $row{"vname"};
	    my $vnode       = $row{"vnode"};
	    my $vport       = $row{"vport"};
	    my $ip          = $row{"ip"};
	    my $member      = "$vnode:$vport";
	    my $mask        = $row{"mask"};
	    my $delay       = $row{"delay"};
	    my $bandwidth   = $row{"bandwidth"};
	    my $lossrate    = $row{"lossrate"};
	    my $rdelay      = $row{"rdelay"};
	    my $rbandwidth  = $row{"rbandwidth"};
	    my $rlossrate   = $row{"rlossrate"};
	    my $protocol    = $row{"protocol"};
	    
402
	    printf "%-15s %-15s %-15s %-9s %-9s %-9s\n", $vname,
403 404
	           $member, $ipmap{$member}, $delay, $bandwidth, $lossrate;
	    printf "%-15s %-15s %-15s %-9s %-9s %-9s\n", "",
405
	           $protocol, $mask, $rdelay, $rbandwidth, $rlossrate;
406 407
	}
	print "\n";
408
	$vlan_result->dataseek(0);
409 410
    }

411
    if ($state eq EXPTSTATE_ACTIVE && $vlan_result->numrows) {
412 413 414 415 416 417
	print  "Physical Lan/Link Mapping:\n";
	printf "%-15s %-15s %-15s %-20s %-9s\n",
	       "ID", "Member", "IP", "MAC", "NodeID";
	print  "--------------- --------------- --------------- ".
	       "-------------------- ---------\n";

418 419 420 421 422 423 424 425 426 427
	while (my %row = $vlan_result->fetchhash()) {
	    my $vname       = $row{"vname"};
	    my $vnode       = $row{"vnode"};
	    my $vport       = $row{"vport"};
	    my $ip          = $row{"ip"};
	    my $member      = "$vnode:$vport";
	    my $mac         = (exists($portmap{$member}) ?
			       $portmap{$member}->{"NODEMAC"} : "");
	    my $pnode       = $v2pmap{$vnode}->{PNODE};

428
	    printf "%-15s %-15s %-15s %-20s %-9s\n", $vname,
429 430
		   $member, $ipmap{$member}, $mac, $pnode;

431 432
	    if (exists($portmap{$member}) &&
		defined($portmap{$member}->{"SWITCH"})) {
433 434 435 436 437 438 439 440 441 442
		my $node_card   = $portmap{$member}->{"NODECARD"};
		my $node_port   = $portmap{$member}->{"NODEPORT"};
		my $switch      = $portmap{$member}->{"SWITCH"};
		my $switch_card = $portmap{$member}->{"SWITCHCARD"};
		my $switch_port = $portmap{$member}->{"SWITCHPORT"};
		
		printf "%-15s %-15s %-15s %-20s %-9s\n", "", "", "",
		    "$node_card/$node_port <-> $switch_card/$switch_port",
		    $switch;
	    }
443 444
	}
	print "\n";
445
	$vlan_result->dataseek(0);
446 447
    }

448 449 450 451 452
    # 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 ".
453
		     "where pid='$pid' and eid='$eid' ".
454
		     "order by vname,member");
455

456
    if ($vlan_result->numrows) {
457
	print  "Virtual Queue Info:\n";
458
	printf "%-15s %-15s %-10s %-7s %s\n",
459 460 461 462
	       "ID", "Member", "Q Limit", "Type",
	       "weight/min_th/max_th/linterm";
	print  "--------------- --------------- ---------- ".
	       "------- ----------------------------\n";
463

464 465 466 467 468 469 470 471 472 473 474 475 476 477
	while (my %row = $vlan_result->fetchhash()) {
	    my $vname       = $row{"vname"};
	    my $vnode       = $row{"vnode"};
	    my $vport       = $row{"vport"};
	    my $member      = "$vnode:$vport";
	    my $q_limit     = $row{"q_limit"};
	    my $q_maxthresh = $row{"q_maxthresh"};
	    my $q_minthresh = $row{"q_minthresh"};
	    my $q_weight    = $row{"q_weight"};
	    my $q_linterm   = $row{"q_linterm"};
	    my $q_qinbytes  = $row{"q_qinbytes"};
	    my $q_red       = $row{"q_red"};
	    my $q_gentle    = $row{"q_gentle"};
	    
478
	    printf("%-15s %-15s %-10s %-7s %s\n", $vname, $member,
479
		   $q_limit . ($q_qinbytes ? " bytes" : " slots"),
480 481 482
		   ($q_red ? ($q_gentle ? "GRED" : "RED") : "Tail"),
		   ($q_red ? "$q_weight/$q_minthresh/$q_maxthresh/$q_linterm" :
		    "0/0/0/0"));
483 484
	}
	print "\n";
485
	$vlan_result->dataseek(0);
486
    }
487

488 489 490 491 492 493 494 495 496 497 498
    # Trace info. See if any traced links
    my $got_traced = 0;
    while (my %row = $vlan_result->fetchhash()) {
	if ($row{'traced'}) {
	    $got_traced++;
	    last;
	}
    }
    $vlan_result->dataseek(0);
    
    if ($got_traced) {
499 500 501 502 503 504
	print  "Trace/Monitoring Info:\n";
	printf "%-15s %-15s %-10s %-7s %s\n",
	       "ID", "Member", "Type", "Snap", "Expression";
	print  "--------------- --------------- ---------- ".
	       "------- ----------------------------\n";

505 506 507 508 509 510 511 512
	while (my %row = $vlan_result->fetchhash()) {
	    my $vname       = $row{"vname"};
	    my $vnode       = $row{"vnode"};
	    my $vport       = $row{"vport"};
	    my $member      = "$vnode:$vport";
	    my $trace_type  = $row{"trace_type"};
	    my $trace_snap  = $row{"trace_snaplen"};
	    my $trace_expr  = $row{"trace_expr"};
513 514

	    printf("%-15s %-15s %-10s %-7s %s\n", $vname, $member,
515
		   $trace_type, $trace_snap,
516 517 518
		   (defined($trace_expr) ? $trace_expr : ""));
	}
	print "\n";
519
	$vlan_result->dataseek(0);
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 545 546 547 548 549 550 551 552
    #
    # 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";
    }

553 554 555
    #
    # Actual mapped information for widearea links
    #
556
    if ($state eq EXPTSTATE_ACTIVE) {
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581
	#
	# 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";
	}
	
582
	#
583
	# Grab all widearea links from the database
584
	#
585 586
	my %links = ();
	$result =
587
	    DBQueryFatal("select vname,member ".
588
			 "from virt_lans where pid='$pid' and eid='$eid' and ".
589
			 "widearea!=0 order by vname,member");
590
	if ($result->numrows) {
591
	    while (($vname,$member) = $result->fetchrow_array()) {
592
		$member =~ /(.+):(\d+)/;
593
		my ($pname,$card) = ($v2pmap{$1}->{PNODE}, $2);
594 595 596 597 598 599 600 601 602 603 604 605

		#
		# 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];
		}
	    }
606 607
	}

608
	if (keys %links) {
609

610
	    #
611
	    # Grab all data from widearea_recent
612
	    #
613 614 615 616 617
	    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) {
618
		$delaymap{"$node_id1 $node_id2"} =
619
		    [$time * 1000 / 2, $bandwidth, $lossrate];
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652
	    }

	    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";
		    }
653
		} else {
654 655 656
		    my ($time, $bandwidth, $lossrate) =  @$delay1;
		    printf "%-9.2f %-9.2f %-9.4f\n", $time, $bandwidth,
			    $lossrate;
657
		}
658

659 660 661 662 663 664 665 666
		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";
		    }
667
		} else {
668 669 670
		    my ($time, $bandwidth, $lossrate) =  @$delay2;
		    printf "%-9.2f %-9.2f %-9.4f\n", $time, $bandwidth,
			    $lossrate;
671
		}
672
	    }
Robert Ricci's avatar
Robert Ricci committed
673

674 675
	    print "\n";
	}
676
    }
677 678
}

679

680 681 682
#
# Delay node info.
#
683
if ($showdelays && $state eq EXPTSTATE_ACTIVE) {
684
    $result_delays =
685 686
	DBQueryFatal("select d.*,w.*,i.iface,r.vname as delayvname ".
		     "   from delays as d ".
687
		     "left join reserved as r on d.node_id=r.node_id ".
688 689 690 691
		     "left join interfaces as i on i.node_id=d.node_id and ".
		     "     (i.iface=d.iface0 or i.iface=d.iface1) ".
 		     "left join wires as w on w.node_id1=i.node_id ".
		     "     and i.card=w.card1 and i.port=w.port1 ".
692
		     "where d.pid='$pid' and d.eid='$eid' ".
693
		     "order by d.vname,d.vnode0");
694

695 696
    $result_linkdelays =
	DBQueryFatal("select * from linkdelays ".
697 698 699
		     "where pid='$pid' and eid='$eid' ".
		     "order by vlan,vnode,node_id");

700
    if ($result_delays->numrows || $result_linkdelays->numrows) {
701
	print  "Physical Delay Info:\n";
702 703 704 705 706 707 708 709 710
	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()) {
711 712 713 714
	    # Skip dups.
	    next
		if ($row{'iface'} eq $row{'iface1'});
	    
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729
	    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";
    }
730

731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747
    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";
    }
748

749 750 751 752 753
    $result_delays->dataseek(0);
    $result_linkdelays->dataseek(0);

    if ($result_delays->numrows || $result_linkdelays->numrows) {
	print  "Physical Queue Info:\n";
754
	printf "%-15s %-15s %-15s %-7s %s\n",
755 756 757 758 759
	       "ID", "Member", "Q Limit", "Type",
	       "weight/min_th/max_th/linterm";
	print  "--------------- --------------- ---------- ".
	       "------- ----------------------------\n";
    }
760

761 762
    if ($result_delays->numrows) {
	while (my %row = $result_delays->fetchhash()) {
763
	    printf("%-15s %-15s %-15s %-7s %s\n", $row{vname},
764
		   $row{vnode0},
765
		   $row{q0_limit} . ($row{q0_qinbytes} ? " bytes" : " slots"),
766 767 768 769 770 771 772 773 774
		   ($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}) {
775
		printf("%-15s %-15s %-15s %-7s %s\n", $row{vname},
776
		       $row{vnode1},
777
		       $row{q1_limit} . ($row{q1_qinbytes} ? " bytes" : " slots"),
778 779 780 781 782 783 784 785 786 787 788 789 790
		       ($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()) {
791
	    printf("%-15s %-15s %-15s %-7s %s\n", $row{vlan},
792
		   $row{vnode},
793
		   $row{q_limit} . ($row{q_qinbytes} ? " bytes" : " slots"),
794 795 796
		   ($row{q_red} ?
		    ($row{q_gentle} ? "GRED" : "RED") : "Tail"),
		   ($row{q_red} ?
Leigh Stoller's avatar
Leigh Stoller committed
797 798
		    "$row{q_weight}/$row{q_minthresh}/".
		    "$row{q_maxthresh}/$row{q_linterm}" :
799
		    "0/0/0/0"));
800
	}
801
	print "\n";
802
    }
803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830

    $result_delays->dataseek(0);

    if ($result_delays->numrows) {
	print  "Delay Node Switch Info:\n";
	printf "%-15s %-15s %-12s %-9s %-9s %-9s\n",
	       "ID", "Member", "Delay Node", "Card/Port", "Switch",
	       "Card/Port";
	print  "--------------- --------------- ------------ --------- ".
	       "--------- --------\n";

	while (my %row = $result_delays->fetchhash()) {
	    my $vname       = $row{"vname"};
	    my $dname       = $row{"delayvname"};
	    my $iface       = $row{"iface"};
	    my $iface0      = $row{"iface0"};
	    my $iface1      = $row{"iface1"};
	    my $vnode0      = $row{"vnode0"};
	    my $vnode1      = $row{"vnode1"};
	    my $vnode       = ($iface eq $iface0 ? $vnode0 : $vnode1);
	    my $node_card   = $row{"card1"};
	    my $node_port   = $row{"port1"};
	    my $switch      = $row{"node_id2"};
	    my $switch_card = $row{"card2"};
	    my $switch_port = $row{"port2"};

	    printf("%-15s %-15s %-12s %-9s %-9s %-9s\n", $vname, $vnode,
		   $dname,
831
		   "$node_card/$node_port $iface", $switch,
832 833 834 835
		   "$switch_card/$switch_port");
	}
	print "\n";
    }
836 837
}

838 839 840 841 842
#
# Print route list.
#
if ($showroutes) {
    my $result =
843
	DBQueryFatal("select vname,src,dst,dst_type,dst_mask,nexthop,cost ".
844
		     " from virt_routes where ".
845
		     "pid='$pid' and eid='$eid' order by vname,src,dst");
846 847 848

    if ($result->numrows) {
	print  "Route List:\n";
849 850
	printf "%-15s %-15s %-15s %-15s %-5s %-4s \n",
	       "Node", "Interface", "Dest", "Nexthop", "Type", "Cost";
851
	print  "--------------- --------------- --------------- ".
852
	       "--------------- ----- ----\n";
853

854
	while (($vname,$src,$dst,$dst_type,$dst_mask,$nexthop,$cost) =
855 856 857 858 859
	       $result->fetchrow_array()) {

	    if ($dst_type eq "host") {
		$dst_mask = "host";
	    }
860 861
	    printf "%-15s %-15s %-15s %-15s %-5s %-4s \n",
	           $vname, $src, $dst, $nexthop, $dst_type, $cost;
862 863 864 865 866
	}
	print "\n";
    }
}

867
#
868 869 870 871
# Print event list or summary
#
if ($showevents) {
    my $result =
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899
	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 =
900
	DBQueryFatal("select time,vnode,vname,ot.type,et.type,arguments,parent ".
901 902 903 904
		" 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' ".
905
		"order by time,ex.idx,vnode,vname");
906 907 908 909

    if ($result->numrows) {
	if ($verbose) {
	    print  "Event List:\n";
910 911 912
	    printf "%-12s %-12s %-10s %-10s %-10s %-10s %s\n",
	           "Time", "Node", "Agent", "Type", "Event", "Parent",
	           "Arguments";
913
	    print  "------------ ------------ ---------- ---------- ".
914
		   "---------- ---------- ------------ \n";
915

916
	    while (($time,$vnode,$vname,$obj,$type,$args,$parent) =
917
		   $result->fetchrow_array()){
918 919
		printf("%-12s %-12s %-10s %-10s %-10s %-10s ",
		       $time, $vnode, $vname, $obj, $type, $parent);
920

921 922
		my @arglist = split(" ", $args);
		my $arg     = shift(@arglist);
923

924 925 926 927 928
		if (defined($arg)) {
		    printf("$arg");
		}
		printf("\n");
		foreach my $arg (@arglist) {
929
		    printf("%-69s %s\n", "", $arg);
930 931
		}
	    }
932
	}
933 934 935 936
	else {
	    my $min;
	    my $max;
	    my $count = $result->numrows;
937

938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954
	    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";
955 956 957
	}
    }
}
958

Mike Hibler's avatar
Mike Hibler committed
959 960 961 962 963
#
# Print firewall information
#
if ($showfwinfo) {
    my $result_fw =
964
	DBQueryFatal("select fwname,type,style from virt_firewalls ".
Mike Hibler's avatar
Mike Hibler committed
965 966 967
		     "where pid='$pid' and eid='$eid' ");
    if ($result_fw->numrows) {
	print "Firewall information:\n";
968
	printf("%-15s %-10s %-8s %-5s %s\n",
969
	       "ID", "Type", "Style", "Rule#", "Rule");
970
	print("--------------- ---------- -------- ----- ".
Mike Hibler's avatar
Mike Hibler committed
971 972
	      "-----------------------------------\n");
	while (my ($fwname,$fwtype,$fwstyle) = $result_fw->fetchrow_array()) {
973
	    printf("%-15s %-10s %-8s", $fwname, $fwtype, $fwstyle);
Mike Hibler's avatar
Mike Hibler committed
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993
	    my $result =
		DBQueryFatal("select ruleno,rule from firewall_rules ".
			     "where pid='$pid' and eid='$eid' ".
			     "and fwname='$fwname'");
	    my %rules = ();
	    if ($result->numrows) {
		while ((my $ruleno,$rule) = $result->fetchrow_array()) {
		    $rules{$ruleno} = $rule;
		}
	    }
	    $result =
		DBQueryFatal("select ruleno,rule from default_firewall_rules ".
			     "where type='$fwtype' and style='$fwstyle' ".
			     "and enabled!=0");
	    if ($result->numrows) {
		while ((my $ruleno,$rule) = $result->fetchrow_array()) {
		    $rules{$ruleno} = $rule;
		}
	    }
	    my $leader=" ";
994
	    foreach my $ruleno (sort { $a <=> $b } keys(%rules)) {
Mike Hibler's avatar
Mike Hibler committed
995
		printf("%s%5d %s\n", $leader, $ruleno, $rules{$ruleno});
996
		$leader="                                    ";
Mike Hibler's avatar
Mike Hibler committed
997 998 999 1000 1001
	    }
	    print "\n";
	}
    }
}
1002
exit(0);