Commit beb947af authored by Leigh Stoller's avatar Leigh Stoller

Rework to to avoid card,port and use iface, since portstats now accepts

iface syntax and prints out in iface syntax (-i option).
parent a6cd8ee2
......@@ -494,14 +494,14 @@ sub getnodeinfo($)
if ($debug && 0);
$query_result =
DBQueryWarn("select r.pid,r.eid,node_id1,eventstate,card1,port1,node_id2".
DBQueryWarn("select r.pid,r.eid,node_id1,eventstate,iface1,node_id2".
" from wires as w,nodes as n".
" left join reserved as r on n.node_id=r.node_id".
" where w.node_id1=n.node_id".
" $sclause".
" and w.type='Control'".
" and n.role='testnode' $nclause".
" order by node_id2,card2,port2");
" order by node_id2,iface1");
if (! $query_result || $query_result->numrows == 0) {
print STDERR "Node(s) not found.\n";
exit(0);
......@@ -515,24 +515,16 @@ sub getnodeinfo($)
while (my %row = $query_result->fetchhash()) {
my $switch = $row{'node_id2'};
my $pc = $row{'node_id1'};
my $pceth = $row{'card1'};
my $pcport = $row{'port1'};
my $pciface = $row{'iface1'};
my $exp;
if (defined($row{'pid'})) {
$exp = $row{'pid'} . "/" . $row{'eid'};
} else {
$exp = "<NONE>";
}
#
# XXX ugh, portstats only takes node:card and not node:card.port,
# so if the port is anything other than 1 (e.g., an allocable switch)
# we cannot look it up.
# portstats now accepts node:iface, and spits out in that format (-i).
#
next
if ($pcport != 1);
my $cnet = "$pc:$pceth";
my $cnet = "$pc:$pciface";
push(@{$switches{$switch}}, $cnet);
$newpcs{$cnet}{'exp'} = $exp;
......@@ -585,7 +577,7 @@ sub gather($)
foreach my $switch (keys %switches) {
my $slist = join(' ', @{$switches{$switch}});
if (!open(PS, "$portstats -H -r -l -c -p $slist 2>&1 |")) {
if (!open(PS, "$portstats -i -H -r -l -c -p $slist 2>&1 |")) {
print STDERR "*** $switch: portstats failed, ignored\n";
next;
}
......@@ -593,7 +585,7 @@ sub gather($)
chomp;
# XXX ignore warnings from snmpit
next if ($_ =~ /^WARNING:/);
next if ($_ !~ /^[-\w]+:\d/);
next if ($_ !~ /^[-\w]+:\w*/);
my ($node, @counts) = split ',';
if (@counts != 8) {
print STDERR "*** $node: invalid portstats!?\n";
......@@ -601,13 +593,8 @@ sub gather($)
}
#
# XXX portstats returns nodes in the format: pcXXX:N.N,
# even though it won't accept that format on the command line!
# XXX portstats returns nodes in the format: pcXXX:ethN
#
if ($node =~ /^(.*:\d+)\.\d$/) {
$node = $1;
}
if (!exists($pcs{$node})) {
print STDERR "*** $node: no stats returned!?\n";
next;
......
#!/usr/bin/perl -wT
#!/usr/bin/perl -w
#
# Copyright (c) 2008-2017 University of Utah and the Flux Group.
#
......@@ -62,8 +62,7 @@ my $controlnet = 1;
#
# Configure variables
#
#my $TB = "@prefix@";
my $TB = "/usr/testbed";
my $TB = "@prefix@";
#
# Testbed Support libraries
......@@ -171,23 +170,23 @@ print STDERR "Switches: ", join(" ", @switches), "\n"
if ($doall == 2) {
$query_result =
DBQueryWarn("select r.pid,r.eid,node_id1,eventstate,card1,port1,node_id2".
DBQueryWarn("select r.pid,r.eid,node_id1,eventstate,iface1,node_id2".
" from wires as w,nodes as n".
" left join reserved as r on n.node_id=r.node_id".
" where w.node_id1=n.node_id".
" $sclause".
" and w.type='Control'".
" and n.role='testnode' $nclause".
" order by node_id2,card2,port2");
" order by node_id2,iface1");
} else {
$query_result =
DBQueryWarn("select r.pid,r.eid,node_id1,eventstate,card1,port1,node_id2".
DBQueryWarn("select r.pid,r.eid,node_id1,eventstate,iface1,node_id2".
" from wires as w,nodes as n,reserved as r".
" where w.node_id1=n.node_id and w.node_id1=r.node_id".
" $sclause".
" and w.type='Control'".
" and n.role='testnode' $nclause".
" order by node_id2,card2,port2");
" order by node_id2,iface1");
}
if (! $query_result || $query_result->numrows == 0) {
print STDERR "Node(s) not found.\n";
......@@ -200,8 +199,7 @@ print STDERR "Nodes: "
while (my %row = $query_result->fetchhash()) {
my $switch = $row{'node_id2'};
my $pc = $row{'node_id1'};
my $pceth = $row{'card1'};
my $pcport = $row{'port1'};
my $pciface = $row{'iface1'};
my $exp;
if (defined($row{'pid'})) {
$exp = $row{'pid'} . "/" . $row{'eid'};
......@@ -209,15 +207,7 @@ while (my %row = $query_result->fetchhash()) {
$exp = "<NONE>";
}
#
# XXX ugh, portstats only takes node:card and not node:card.port,
# so if the port is anything other than 1 (e.g., an allocable switch)
# we cannot look it up.
#
next
if ($pcport != 1);
my $cnet = "$pc:$pceth";
my $cnet = "$pc:$pciface";
push(@{$switches{$switch}}, $cnet);
$pcs{$cnet}{'exp'} = $exp;
......@@ -375,13 +365,13 @@ sub gather($$)
foreach my $switch (keys %switches) {
my $slist = join(' ', @{$switches{$switch}});
my $arg = $byexpt ? "" : "-c";
open(PS, "$portstats $arg -r -l -p $slist 2>&1 |") or
open(PS, "$portstats -i $arg -r -l -p $slist 2>&1 |") or
die "Could not get portstats\n";
while (<PS>) {
chomp;
# XXX ignore warnings from snmpit
next if ($_ =~ /^WARNING:/);
next if ($_ !~ /^[-\w]+:\d/);
next if ($_ !~ /^[-\w]+:\w+/);
my ($node, @counts) = split ',';
if (@counts != 6) {
print STDERR "*** $node: invalid portstats!?\n";
......@@ -389,13 +379,8 @@ sub gather($$)
}
#
# XXX portstats returns nodes in the format: pcXXX:N.N,
# even though it won't accept that format on the command line!
# XXX portstats returns nodes in the format: pcXXX:ethN
#
if ($node =~ /^(.*:\d+)\.\d$/) {
$node = $1;
}
if (!exists($pcref->{$node})) {
print STDERR "*** $node: no stats returned!?\n";
next;
......
#!/usr/bin/perl -w
#
# Copyright (c) 2008-2014, 2016 University of Utah and the Flux Group.
# Copyright (c) 2008-2017 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -226,12 +226,16 @@ foreach my $node (@interconnects) {
foreach my $iface (@interfaces) {
next
if ($iface->current_speed() == 0);
next
if (!$iface->wiredup() || $iface->wire_type() eq "Unused");
# To be consistent use a Port object since getTrunks() does too.
my $port = Port->LookupByIface($node->node_id, $iface->iface());
if (!defined($port)) {
fatal("Could not get Port for $iface");
}
$connects{$node->node_id()}->{$port->switch_node_id()} = $port;
}
}
......@@ -274,8 +278,7 @@ sub Gather($)
my @ports = @{ $trunks{$sw1}->{$sw2} };
foreach my $port (@ports) {
$portstr .= " ${sw1}:" .
$port->switch_card() . "." . $port->switch_port();
$portstr .= " ${sw1}:" . $port->switch_iface();
}
}
}
......@@ -286,23 +289,23 @@ sub Gather($)
foreach my $id (keys(%connects)) {
foreach my $switch (keys(%{ $connects{$id} })) {
my $port = $connects{$id}->{$switch};
my $str = " ${switch}:" .
$port->switch_card() . "." . $port->switch_port();
my $str = " ${switch}:" . $port->switch_iface();
$portstr .= $str;
}
}
if ($debug) {
print $portstr . "\n";
}
open(PS, "$PORTSTATS -r -s -c $portstr 2>&1 |") or
open(PS, "$PORTSTATS -i -r -s -c $portstr 2>&1 |") or
fatal("Could not get portstats");
while (<PS>) {
if ($_ !~ /^[-\w]+:\d/) {
if ($_ !~ /^[-\w]+:\w+/) {
print $_
if ($debug);
next;
}
chomp($_);
my ($swport, @counts) = split(",", $_);
if (@counts != 6) {
print STDERR "*** $swport: invalid portstats!?\n";
......@@ -314,7 +317,7 @@ sub Gather($)
#
my ($switch,$port);
if ($swport =~ /^(.*):(\d+\.\d+)$/) {
if ($swport =~ /^(.*):([\/\.\w]+)$/) {
$switch = $1;
$port = $2;
}
......@@ -348,8 +351,8 @@ sub Aggregate($$)
my %sum = ();
foreach my $swport (@ports) {
my (undef,$port) = split(":", $swport);
my $counts = $results->{$sw1}->{"$port"};
my $iface = $swport->switch_iface();
my $counts = $results->{$sw1}->{$iface};
foreach my $key (keys(%{$counts})) {
if (!exists($sum{$key})) {
......@@ -375,7 +378,7 @@ sub Aggregate($$)
# These ports objects refer to the node side, not the switch side,
# so we have to explicity get the switch side in index the array.
#
my $port = $swport->switch_card() . "." . $swport->switch_port();
my $port = $swport->switch_iface();
my $counts = $results->{$switch}->{"$port"};
$aggref->{$switch}->{$id} = $counts;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment