tbreport.in 32.6 KB
Newer Older
1
#!/usr/bin/perl -w
2

Leigh Stoller's avatar
Leigh Stoller committed
3
#
4
# Copyright (c) 2000-2017 University of Utah and the Flux Group.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# 
# {{{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
24 25 26
#


27 28 29 30 31 32 33
#
# 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
34
    print "Usage: $0 [-h] [-n] [-l] [-m] [-e] [-f] [-d] [-r] [-v] pid eid\n";
35
    print "-h		Shows this message\n";
36 37 38 39 40
    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
41
    print "-f		Show firewall rules\n";
42
    print "-r		Show routes\n";
43 44
    print "-b		Show most things\n";
    print "-v		Show everything!\n";
45 46
    return 1;
}
47

48 49
sub dump_table($$$$);

50
my $TBROOT = "@prefix@";
51 52
my $DOMAIN = "@OURDOMAIN@";

53
use lib '@prefix@/lib';
54
use libtestbed;
55
use libdb;
56
use Getopt::Std;
57

Leigh Stoller's avatar
Leigh Stoller committed
58 59 60 61
#
# Turn off line buffering on output
#
$| = 1;
62

63 64 65 66
#
# Get options
#
my %opt = ();
67 68 69 70 71 72
my $verbose    = 0;
my $shownodes  = 0;
my $showmap    = 0;
my $showlinks  = 0;
my $showdelays = 0;
my $showevents = 0;
73
my $showroutes = 0;
Mike Hibler's avatar
Mike Hibler committed
74
my $showfwinfo = 0;
75
my %v2pmap;
76
my %p2vmap;
77 78
my %p2type;
my %p2osid;
79
my %vv2pmap;
80 81
my $hasremote  = 0;
my $hasplab    = 0;
82 83
my %ipmap;
my %membermap;
84

85
getopts('hnmdlevbrfa',\%opt);
86

87 88 89 90
if ($opt{h}) {
    exit &usage;
}
if ($opt{v}) {
Leigh Stoller's avatar
Leigh Stoller committed
91
    $verbose = 1;
92 93 94 95 96
    $shownodes = 1;
    $showmap = 1;
    $showdelays = 1;
    $showlinks = 1;
    $showevents = 1;
97
    $showroutes = 1;
Mike Hibler's avatar
Mike Hibler committed
98
    $showfwinfo = 1;
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
}
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;
120 121 122
    if ($opt{a}) {
	$verbose = 1;
    }
123
}
124 125 126
if ($opt{r}) {
    $showroutes = 1;
}
Mike Hibler's avatar
Mike Hibler committed
127 128 129
if ($opt{f}) {
    $showfwinfo = 1;
}
130 131 132 133 134
if (@ARGV != 2) {
    exit &usage;
}

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

137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
#
# 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");
}

153
#
Leigh Stoller's avatar
Leigh Stoller committed
154
# Experiment must exist.
155
#
Leigh Stoller's avatar
Leigh Stoller committed
156 157
if (!($state = ExpState($pid,$eid))) {
    die("There is no experiment $eid in project $pid\n");
158 159
}

Leigh Stoller's avatar
Leigh Stoller committed
160 161 162 163 164 165 166
#
# 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");
    }
167
}
168

169
if (($state ne EXPTSTATE_SWAPPED) &&
170
    ($state ne EXPTSTATE_ACTIVE)) {
Leigh Stoller's avatar
Leigh Stoller committed
171
    # nothing to do
172
    print "No information available.\n";
Leigh Stoller's avatar
Leigh Stoller committed
173
    exit(0);
174 175
}

176 177 178 179
print "Experiment: $pid/$eid\n";
print "State: $state\n";
print "\n";

180
# Read nodemap if applicable
181
if ($state eq EXPTSTATE_ACTIVE) {
182
    my $query_result =
183
	DBQueryFatal("select r.vname,r.node_id,n.type,n.phys_nodeid,o.osname,".
184
		     "       n.sshdport,n.jailflag,nt.isremotenode,".
185
		     "       nt.isplabdslice ".
186
		     "  from reserved as r ".
187 188
		     "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 ".
189
		     "left join node_types as nt on nt.type=n.type ".
190
		     "where r.pid='$pid' and r.eid='$eid' order by vname");
191

192
    while (($v,$p,$t,$m,$o,$s,$j,$r,$d) = $query_result->fetchrow_array()) {
193
	if (!$v) {
194
	    $v = $p;
195
	}
196 197 198 199 200 201 202 203
	$v2pmap{$v} = {
	    PNODE	=> $p,
	    TYPE	=> $t,
	    OSID	=> $o,
	    VVP		=> $m,
	    SSHDPORT	=> $s,
	    JAILED	=> $j,
	    ISREMOTE    => $r,
204
	    PLAB	=> $d,
205
	};
206
	$p2vmap{$p} = $v;
207 208 209 210 211 212
	if ($r) {
	    $hasremote = 1;
	}
	if ($d) {
	    $hasplab = 1;
	}
213
    }
214 215 216 217 218 219 220
}

#
# Display virtual info. We might need the ips for below, so we always do
# this.
#
my $virtnodes_result =
221
    DBQueryFatal("SELECT vname,osname,parent_osname,cmd_line,rpms," .
222
		 "startupcmd,tarfiles,type,fixed from virt_nodes ".
223
		 "where pid='$pid' and eid='$eid' order by vname");
224 225 226

if ($shownodes) {
    print "Virtual Node Info:\n";
227 228 229
    printf "%-15s %-12s %-15s %s\n", "ID", "Type", "OS", "Qualified Name";
    print "--------------- ------------ --------------- ".
	  "--------------------\n";
230

231
    while (($vname,$osname,$parent_osname,$cmd_line,$rpms,$startupcmd,
232
	    $tarfiles,$type,$fixed) = $virtnodes_result->fetchrow_array()) {
233
	my $qualname = "$vname.$eid.$pid.$DOMAIN";
234 235 236 237

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

239
	printf "%-15s %-12s %-15s %s\n", $vname, $type, $osname, $qualname;
240 241 242
	if (defined($parent_osname) && $parent_osname ne "") {
	    printf "   %-17s %s\n", "Parent Osname:", $parent_osname;
	}
243
	if (defined($cmd_line) && $cmd_line ne "") {
Leigh Stoller's avatar
Leigh Stoller committed
244 245
	    printf "   %-17s %s\n", "Command Line:", $cmd_line;
	}
246
	if (defined($startupcmd) && $startupcmd ne "") {
Leigh Stoller's avatar
Leigh Stoller committed
247 248
	    printf "   %-17s %s\n", "Startup Command:", $startupcmd;
	}
249
	if (defined($rpms) && $rpms ne "") {
Leigh Stoller's avatar
Leigh Stoller committed
250 251
	    printf "   %-17s %s\n", "RPMS:", $rpms;
	}
252
	if (defined($tarfiles) && $tarfiles ne "") {
Leigh Stoller's avatar
Leigh Stoller committed
253 254 255 256
	    printf "   %-17s %s\n", "Tarfiles:", $tarfiles;
	}
    }
    print "\n";
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297

    my $attributes_result =
        DBQueryFatal("SELECT vname,attrkey,attrvalue ".
		     "  from virt_node_attributes ".
		     "where pid='$pid' and eid='$eid' ".
		     "order by vname,attrkey");

    if ($attributes_result->numrows) {
	print "\n";
	print "Virtual Node Attributes:\n";
	printf "%-15s %-20s Value\n", "ID", "Key";
	print "--------------- -----------------------------".
	    "--------------------\n";

	my $lastvname = "";
	while (my ($vname,$key,$value) = $attributes_result->fetchrow_array()) {
	    if ($vname ne $lastvname) {
		printf "%-15s %-20s %s\n", $vname, $key, $value;
		$lastvname = $vname;
		next;
	    }
	    printf "%-15s %-20s %s\n", "", $key, $value;
	}
	print "\n";
    }

    $attributes_result =
        DBQueryFatal("SELECT role,attrkey,attrvalue ".
		     "  from elabinelab_attributes ".
		     "where pid='$pid' and eid='$eid' ".
		     "order by role,ordering,attrkey");

    if ($attributes_result->numrows) {
	print "\n";
	print "ElabInElab Attributes:\n";
	printf "%-15s %-20s Value\n", "Role", "Key";
	print "--------------- -----------------------------".
	    "--------------------\n";

	my $lastrole = "";
	while (my ($role,$key,$value) = $attributes_result->fetchrow_array()) {
298 299 300 301 302
	    # Do not print anything that looks like a password.
	    if ($key =~ /password/i ||
		$key =~ /community/i) {
		$value = "**********"
	    }
303 304 305 306 307 308 309 310 311
	    if ($role ne $lastrole) {
		printf "%-15s %-20s %s\n", $role, $key, $value;
		$lastrole = $role;
		next;
	    }
	    printf "%-15s %-20s %s\n", "", $key, $value;
	}
	print "\n";
    }
312
}
Leigh Stoller's avatar
Leigh Stoller committed
313

314 315
#
# Physical mapping of virtual topology
316
#
317
if ($showmap && $state eq EXPTSTATE_ACTIVE) {
318
    print  "Physical Node Mapping:\n";
319 320
    printf "%-15s %-12s %-15s %-12s\n", "ID", "Type", "OS", "Physical";
    print  "--------------- ------------ --------------- ------------\n";
321

322
    foreach $v (sort keys(%v2pmap)) {
323 324
	my $p = $v2pmap{$v}->{PNODE};
	my $t = $v2pmap{$v}->{TYPE};
325
	my $o = $v2pmap{$v}->{OSID} ? $v2pmap{$v}->{OSID} : "<NONE>";
326
	my $m = $v2pmap{$v}->{VVP};
327 328 329 330 331
	printf "%-15s %-12s %-15s %s", $v, $t, $o, $p;
	if ($m ne $p) {
	    printf " ($m)";
	}
	printf "\n";
Leigh Stoller's avatar
Leigh Stoller committed
332 333
    }
    print "\n";
334

335
    if ($hasremote || $hasplab) {
336 337 338 339 340 341 342 343 344 345
	# 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();
346
	my $widearea_info_result =
347 348 349 350 351 352
	    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()) {
353 354 355 356 357 358
	    next unless
		($v2pmap{$vname}->{ISREMOTE} || $v2pmap{$vname}->{PLAB});
	    my $pnode = $v2pmap{$vname}->{VVP};
	    if (!defined($hostname)) {
		$hostname = "--";
	    }
359 360 361 362
	    if (!defined($site)) {
		$site = "--";
	    }
	    printf "%-15s %-20s %-40s\n", $vname, $site, $hostname;
363 364 365 366 367
	}
	print "\n";
    }


368 369 370 371 372
    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();
373

374
	print  "IP Port allocation:\n";
375 376 377
	printf "%-15s %-12s \n", "Low", "High";
	print  "--------------- ------------\n";
	printf "%-15s %-12s\n", $low, $high;
378
	print  "\n";
379 380 381 382

	print  "SSHD Port allocation ('ssh -p portnum'):\n";
	printf "%-15s %-10s %-20s\n", "ID", "Port", "SSH command";
	print  "--------------- ---------- ----------------------\n";
383
	foreach $v (sort keys(%v2pmap)) {
384 385
	    my $p = $v2pmap{$v}->{PNODE};
	    my $s = $v2pmap{$v}->{SSHDPORT};
386 387
	    my $m = $v2pmap{$v}->{VVP};
	    my $q = "$m.$DOMAIN";
388
	    if ($v2pmap{$v}->{JAILED}) {
389 390 391 392 393
		printf "%-15s %-10s %-20s", $v, $s, "ssh -p $s $q";
		print  "\n";
	    }
	}
	print "\n";
394
    }
395 396 397 398 399 400
}

#
# Links and Lans
#
if ($showlinks) {
401 402
    my %portmap = ();
    my %macmap  = ();
Leigh Stoller's avatar
Leigh Stoller committed
403

404 405 406 407
    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");
408 409
    # Need to do this when we want to seek around inside the results.
    $vlan_result = $vlan_result->WrapForSeek();
410

411 412 413 414 415
    while (my %row = $vlan_result->fetchhash()) {
	my $ip          = $row{"ip"};
	my $vnode       = $row{"vnode"};
	my $vport       = $row{"vport"};
	my $member      = "$vnode:$vport";
416

417 418 419 420 421 422 423 424 425 426 427 428 429 430
	$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 ".
431
			 "     and i.ip=v.ip ".
432
			 "left join wires as w on i.node_id=w.node_id1 ".
433
			 "     and i.iface=w.iface1 ".
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
			 "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"};
457
	}
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472

	#
	# Now find vinterfaces
	#
	$link_result =
	    DBQueryFatal("select v.vname,v.vnode,v.vport, ".
			 "       i.IP,i.mac,i.iface 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 vinterfaces as i on r.node_id=i.vnode_id ".
			 "     and i.IP=v.ip ".
			 "where v.pid='$pid' and v.eid='$eid' ".
			 "order by v.vname,v.member");

	while (my %row = $link_result->fetchhash()) {
473
	    my $ip          = $row{"IP"};
474 475 476 477 478 479 480 481 482
	    my $mac         = $row{"mac"};
	    my $lan         = $row{"vname"};
	    my $vnode       = $row{"vnode"};
	    my $vport       = $row{"vport"};
	    my $iface       = $row{"iface"};
	    my $member      = "$vnode:$vport";

	    # Do not bother if no info.
	    next
483 484
		if (!defined($ip));

485 486 487 488 489 490
	    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;
	}
491 492
    }

493
    if ($vlan_result->numrows) {
494
	my @data;
495 496 497 498 499 500 501 502 503
	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"};
504
	    my $backfill    = $row{"backfill"};
505 506 507
	    my $lossrate    = $row{"lossrate"};
	    my $rdelay      = $row{"rdelay"};
	    my $rbandwidth  = $row{"rbandwidth"};
508
	    my $rbackfill   = $row{"rbackfill"};
509 510
	    my $rlossrate   = $row{"rlossrate"};
	    my $protocol    = $row{"protocol"};
511
	    my $encap_style = $row{"encap_style"};
512 513 514
	    my $fixed_iface = $row{"fixed_iface"};
	    $protocol .= " ($fixed_iface)"
		if (defined($fixed_iface) && $fixed_iface ne "");
515 516 517
	    $protocol .= " ($encap_style)"
		if (defined($encap_style) &&
		    $encap_style ne "" && $encap_style ne "default");
518 519 520
	    push @data, [$vname, $member, $ipmap{$member}, 
		        $delay, $bandwidth, $backfill, $lossrate];
	    push @data, ["", $protocol, $mask, $rdelay, $rbandwidth, $rbackfill, $rlossrate];
521
	}
522 523 524 525 526 527 528

	print  "Virtual Lan/Link Info:\n";
	dump_table(["ID", "Member/Proto", "IP/Mask", 
		    "Delay","BW (Kbs)","Backfill", "Loss Rate"],
		   ["Backfill"],
		   [15,15,15,9,9,9,9],
		   \@data);
529
	print "\n";
530
		   
531
	$vlan_result->dataseek(0);
532 533
    }

534
    if ($state eq EXPTSTATE_ACTIVE && $vlan_result->numrows) {
535 536 537 538 539 540
	print  "Physical Lan/Link Mapping:\n";
	printf "%-15s %-15s %-15s %-20s %-9s\n",
	       "ID", "Member", "IP", "MAC", "NodeID";
	print  "--------------- --------------- --------------- ".
	       "-------------------- ---------\n";

541 542 543 544 545 546 547 548 549 550
	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};

551
	    printf "%-15s %-15s %-15s %-20s %-9s\n", $vname,
552 553
		   $member, $ipmap{$member}, $mac, $pnode;

554 555
	    if (exists($portmap{$member}) &&
		defined($portmap{$member}->{"SWITCH"})) {
556 557 558 559 560 561 562 563 564 565
		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;
	    }
566 567
	}
	print "\n";
568
	$vlan_result->dataseek(0);
569 570
    }

571 572 573 574 575
    # 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 ".
576
		     "where pid='$pid' and eid='$eid' ".
577
		     "order by vname,member");
578

579
    if ($vlan_result->numrows) {
580
	print  "Virtual Queue Info:\n";
581
	printf "%-15s %-15s %-10s %-7s %s\n",
582 583 584 585
	       "ID", "Member", "Q Limit", "Type",
	       "weight/min_th/max_th/linterm";
	print  "--------------- --------------- ---------- ".
	       "------- ----------------------------\n";
586

587 588 589 590 591 592 593 594 595 596 597 598 599 600
	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"};
	    
601
	    printf("%-15s %-15s %-10s %-7s %s\n", $vname, $member,
602
		   $q_limit . ($q_qinbytes ? " bytes" : " slots"),
603 604 605
		   ($q_red ? ($q_gentle ? "GRED" : "RED") : "Tail"),
		   ($q_red ? "$q_weight/$q_minthresh/$q_maxthresh/$q_linterm" :
		    "0/0/0/0"));
606 607
	}
	print "\n";
608
	$vlan_result->dataseek(0);
609
    }
610

611 612 613 614 615 616 617 618 619 620 621
    # 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) {
622 623 624 625 626 627
	print  "Trace/Monitoring Info:\n";
	printf "%-15s %-15s %-10s %-7s %s\n",
	       "ID", "Member", "Type", "Snap", "Expression";
	print  "--------------- --------------- ---------- ".
	       "------- ----------------------------\n";

628 629 630 631 632 633 634 635
	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"};
636 637

	    printf("%-15s %-15s %-10s %-7s %s\n", $vname, $member,
638
		   $trace_type, $trace_snap,
639 640 641
		   (defined($trace_expr) ? $trace_expr : ""));
	}
	print "\n";
642
	$vlan_result->dataseek(0);
643 644
    }

645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675
    #
    # 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";
    }

676 677 678
    #
    # Actual mapped information for widearea links
    #
679
    if ($state eq EXPTSTATE_ACTIVE) {
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704
	#
	# 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";
	}
	
705
	#
706
	# Grab all widearea links from the database
707
	#
708 709
	my %links = ();
	$result =
710
	    DBQueryFatal("select vname,member ".
711
			 "from virt_lans where pid='$pid' and eid='$eid' and ".
712
			 "widearea!=0 order by vname,member");
713
	if ($result->numrows) {
714
	    while (($vname,$member) = $result->fetchrow_array()) {
715
		$member =~ /(.+):(\d+)/;
716
		my ($pname,$card) = ($v2pmap{$1}->{PNODE}, $2);
717 718 719 720 721 722 723 724 725 726 727 728

		#
		# 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];
		}
	    }
729 730
	}

731
	if (keys %links) {
732

733
	    #
734
	    # Grab all data from widearea_recent
735
	    #
736 737 738 739 740
	    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) {
741
		$delaymap{"$node_id1 $node_id2"} =
742
		    [$time * 1000 / 2, $bandwidth, $lossrate];
743 744 745 746 747 748 749 750 751 752 753
	    }

	    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}};
Leigh Stoller's avatar
Leigh Stoller committed
754 755
		my ($virt1,$pname1) = @$node1;
		my ($virt2,$pname2) = @$node2;
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775

		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";
		    }
776
		} else {
777 778 779
		    my ($time, $bandwidth, $lossrate) =  @$delay1;
		    printf "%-9.2f %-9.2f %-9.4f\n", $time, $bandwidth,
			    $lossrate;
780
		}
781

782 783 784 785 786 787 788 789
		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";
		    }
790
		} else {
791 792 793
		    my ($time, $bandwidth, $lossrate) =  @$delay2;
		    printf "%-9.2f %-9.2f %-9.4f\n", $time, $bandwidth,
			    $lossrate;
794
		}
795
	    }
Robert Ricci's avatar
Robert Ricci committed
796

797 798
	    print "\n";
	}
799
    }
800 801
}

802

803 804 805
#
# Delay node info.
#
806
if ($showdelays && $state eq EXPTSTATE_ACTIVE) {
807
    $result_delays =
808 809
	DBQueryFatal("select d.*,w.*,i.iface,r.vname as delayvname ".
		     "   from delays as d ".
810
		     "left join reserved as r on d.node_id=r.node_id ".
811 812 813
		     "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 ".
814
		     "     and i.iface=w.iface1 ".
815
		     "where d.pid='$pid' and d.eid='$eid' ".
816
		     "order by d.vname,d.vnode0");
817

818 819
    $result_linkdelays =
	DBQueryFatal("select * from linkdelays ".
820 821 822
		     "where pid='$pid' and eid='$eid' ".
		     "order by vlan,vnode,node_id");

823 824 825 826
    # Need to do this when we want to seek around inside the results.
    $result_delays = $result_delays->WrapForSeek();
    $result_linkdelays = $result_linkdelays->WrapForSeek();

827
    my @data;
828 829 830

    if ($result_delays->numrows) {
	while (my %row = $result_delays->fetchhash()) {
831 832 833 834
	    # Skip dups.
	    next
		if ($row{'iface'} eq $row{'iface1'});
	    
835 836 837
	    push @data, [$row{vname}, $row{vnode0}, $row{delayvname},
			 $row{delay0}, $row{bandwidth0}, $row{backfill0}, $row{lossrate0},
			 $row{pipe0}];
838 839

	    # If vnode0 eq vnode1, its a lan node. Print differently.
840 841 842 843 844
	    push @data, [($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{backfill1}, $row{lossrate1},
			 $row{pipe1}];
845
	}
846
	push @data, [];
847
    }
848

849 850
    if ($result_linkdelays->numrows) {
	while (my %row = $result_linkdelays->fetchhash()) {
851
	    push @data, [$row{vlan}, $row{vnode}, $row{node_id},
852
			 $row{delay}, $row{bandwidth}, undef, $row{lossrate},
853
			 $row{pipe}];
854 855 856 857


	    # Lan node, from the switch
	    if ($row{type} eq "duplex") {
858
		push @data, ["", "", "",
859 860
			     $row{rdelay}, $row{rbandwidth}, undef,
			     $row{rlossrate}, $row{rpipe}];
861 862
	    }
	}
863 864 865 866 867 868 869 870 871 872
	push @data, [];
    }

    if (@data) {
	print  "Physical Delay Info:\n";
	dump_table(["ID", "Member", "Delay Node", "Delay", "BW (Kbs)", 
		    "Backfill", "PLR", "Pipe"],
		   ["Backfill"],
		   [15, 15, 12, 8, 8, 8, 6, 9],
		   \@data);
873
    }
874

875 876 877 878 879
    $result_delays->dataseek(0);
    $result_linkdelays->dataseek(0);

    if ($result_delays->numrows || $result_linkdelays->numrows) {
	print  "Physical Queue Info:\n";
880
	printf "%-15s %-15s %-15s %-7s %s\n",
881 882 883 884 885
	       "ID", "Member", "Q Limit", "Type",
	       "weight/min_th/max_th/linterm";
	print  "--------------- --------------- ---------- ".
	       "------- ----------------------------\n";
    }
886

887 888
    if ($result_delays->numrows) {
	while (my %row = $result_delays->fetchhash()) {
889
	    printf("%-15s %-15s %-15s %-7s %s\n", $row{vname},
890
		   $row{vnode0},
891
		   $row{q0_limit} . ($row{q0_qinbytes} ? " bytes" : " slots"),
892 893 894 895 896 897 898 899 900
		   ($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}) {
901
		printf("%-15s %-15s %-15s %-7s %s\n", $row{vname},
902
		       $row{vnode1},
903
		       $row{q1_limit} . ($row{q1_qinbytes} ? " bytes" : " slots"),
904 905 906 907 908 909 910 911 912 913 914 915 916
		       ($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()) {
917
	    printf("%-15s %-15s %-15s %-7s %s\n", $row{vlan},
918
		   $row{vnode},
919
		   $row{q_limit} . ($row{q_qinbytes} ? " bytes" : " slots"),
920 921 922
		   ($row{q_red} ?
		    ($row{q_gentle} ? "GRED" : "RED") : "Tail"),
		   ($row{q_red} ?
Leigh Stoller's avatar
Leigh Stoller committed
923 924
		    "$row{q_weight}/$row{q_minthresh}/".
		    "$row{q_maxthresh}/$row{q_linterm}" :
925
		    "0/0/0/0"));
926
	}
927
	print "\n";
928
    }
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956

    $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,
957
		   "$node_card/$node_port $iface", $switch,
958 959 960 961
		   "$switch_card/$switch_port");
	}
	print "\n";
    }
962 963
}

964 965 966 967 968
#
# Print route list.
#
if ($showroutes) {
    my $result =
969
	DBQueryFatal("select vname,src,dst,dst_type,dst_mask,nexthop,cost ".
970
		     " from virt_routes where ".
971
		     "pid='$pid' and eid='$eid' order by vname,src,dst");
972 973 974

    if ($result->numrows) {
	print  "Route List:\n";
975 976
	printf "%-15s %-15s %-15s %-15s %-5s %-4s \n",
	       "Node", "Interface", "Dest", "Nexthop", "Type", "Cost";
977
	print  "--------------- --------------- --------------- ".
978
	       "--------------- ----- ----\n";
979

980
	while (($vname,$src,$dst,$dst_type,$dst_mask,$nexthop,$cost) =
981 982 983 984 985
	       $result->fetchrow_array()) {

	    if ($dst_type eq "host") {
		$dst_mask = "host";
	    }
986 987
	    printf "%-15s %-15s %-15s %-15s %-5s %-4s \n",
	           $vname, $src, $dst, $nexthop, $dst_type, $cost;
988 989 990 991 992
	}
	print "\n";
    }
}

993
#
994 995 996 997
# Print event list or summary
#
if ($showevents) {
    my $result =
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025
	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 =
1026
	DBQueryFatal("select time,vnode,vname,ot.type,et.type,arguments,parent ".
1027 1028 1029 1030
		" 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' ".
1031
		"order by time,ex.idx,vnode,vname");
1032 1033 1034 1035

    if ($result->numrows) {
	if ($verbose) {
	    print  "Event List:\n";
1036 1037 1038
	    printf "%-12s %-12s %-10s %-10s %-10s %-10s %s\n",
	           "Time", "Node", "Agent", "Type", "Event", "Parent",
	           "Arguments";
1039
	    print  "------------ ------------ ---------- ---------- ".
1040
		   "---------- ---------- ------------ \n";
1041

1042
	    while (($time,$vnode,$vname,$obj,$type,$args,$parent) =
1043
		   $result->fetchrow_array()){
1044 1045
		printf("%-12s %-12s %-10s %-10s %-10s %-10s ",
		       $time, $vnode, $vname, $obj, $type, $parent);
1046

1047 1048
		my @arglist = split(" ", $args);
		my $arg     = shift(@arglist);
1049

1050 1051 1052 1053 1054
		if (defined($arg)) {
		    printf("$arg");
		}
		printf("\n");
		foreach my $arg (@arglist) {
1055
		    printf("%-69s %s\n", "", $arg);
1056 1057
		}
	    }
1058
	}
1059 1060 1061 1062
	else {
	    my $min;
	    my $max;
	    my $count = $result->numrows;
1063

1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080
	    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";
1081 1082 1083
	}
    }
}
1084

Mike Hibler's avatar
Mike Hibler committed
1085 1086 1087 1088 1089
#
# Print firewall information
#
if ($showfwinfo) {
    my $result_fw =
1090
	DBQueryFatal("select fwname,type,style from virt_firewalls ".
Mike Hibler's avatar
Mike Hibler committed
1091 1092 1093
		     "where pid='$pid' and eid='$eid' ");
    if ($result_fw->numrows) {
	print "Firewall information:\n";
1094
	printf("%-15s %-10s %-8s %-5s %s\n",
1095
	       "ID", "Type", "Style", "Rule#", "Rule");
1096
	print("--------------- ---------- -------- ----- ".
Mike Hibler's avatar
Mike Hibler committed
1097 1098
	      "-----------------------------------\n");
	while (my ($fwname,$fwtype,$fwstyle) = $result_fw->fetchrow_array()) {
1099
	    printf("%-15s %-10s %-8s", $fwname, $fwtype, $fwstyle);
Mike Hibler's avatar
Mike Hibler committed
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119
	    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=" ";
1120
	    foreach my $ruleno (sort { $a <=> $b } keys(%rules)) {
Mike Hibler's avatar
Mike Hibler committed
1121
		printf("%s%5d %s\n", $leader, $ruleno, $rules{$ruleno});
1122
		$leader="                                    ";
Mike Hibler's avatar
Mike Hibler committed
1123 1124 1125 1126 1127
	    }
	    print "\n";
	}
    }
}
1128
exit(0);
1129 1130 1131 1132


#
# dump_table: Dumps a formated table, skipping over any column that
1133
#   does not have a value if they are listed in the optional array;
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179
#
sub skip_over ($$);
sub dump_table($$$$) { # all parameters are expected to be array references
    my ($names, $optional, $widths, $data) = @_;
    my %names_map;
    my $last = @$names - 1;
    foreach (0 .. $last) {
	$names_map{$$names[$_]} = $_;
    }
    
    my @optional;
    foreach (@$optional) {
	$optional[$names_map{$_}] = 1;
    }
    
    my @keep;
    foreach (@$data) {
	my @d = @$_;
	for (0..$last) {
	    $keep[$_]++ if ($d[$_]);
	}
    }
    foreach (0 .. $last) {
	$keep[$_] = 1 unless $optional[$_];
    }

    my $format = join(' ', map {"%-${_}s"} skip_over($widths,\@keep))."\n";

    printf($format,skip_over($names,\@keep));
    print join(' ', map {'-'x$_} skip_over($widths,\@keep))."\n";
    foreach (@$data) {
	if (@$_ > 0) {
	    printf($format, skip_over($_,\@keep));
	} else {
	    print "\n";
	}
    }
}
sub skip_over ($$) {
    my ($data, $keep) = @_;
    my @res;
    foreach (0..$#$data) {
	push @res, $$data[$_] if $$keep[$_];
    }
    return @res;
}