Commit beb947af authored by Leigh B Stoller's avatar Leigh B 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($) ...@@ -494,14 +494,14 @@ sub getnodeinfo($)
if ($debug && 0); if ($debug && 0);
$query_result = $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". " from wires as w,nodes as n".
" left join reserved as r on n.node_id=r.node_id". " left join reserved as r on n.node_id=r.node_id".
" where w.node_id1=n.node_id". " where w.node_id1=n.node_id".
" $sclause". " $sclause".
" and w.type='Control'". " and w.type='Control'".
" and n.role='testnode' $nclause". " and n.role='testnode' $nclause".
" order by node_id2,card2,port2"); " order by node_id2,iface1");
if (! $query_result || $query_result->numrows == 0) { if (! $query_result || $query_result->numrows == 0) {
print STDERR "Node(s) not found.\n"; print STDERR "Node(s) not found.\n";
exit(0); exit(0);
...@@ -515,24 +515,16 @@ sub getnodeinfo($) ...@@ -515,24 +515,16 @@ sub getnodeinfo($)
while (my %row = $query_result->fetchhash()) { while (my %row = $query_result->fetchhash()) {
my $switch = $row{'node_id2'}; my $switch = $row{'node_id2'};
my $pc = $row{'node_id1'}; my $pc = $row{'node_id1'};
my $pceth = $row{'card1'}; my $pciface = $row{'iface1'};
my $pcport = $row{'port1'};
my $exp; my $exp;
if (defined($row{'pid'})) { if (defined($row{'pid'})) {
$exp = $row{'pid'} . "/" . $row{'eid'}; $exp = $row{'pid'} . "/" . $row{'eid'};
} else { } else {
$exp = "<NONE>"; $exp = "<NONE>";
} }
# portstats now accepts node:iface, and spits out in that format (-i).
#
# 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 my $cnet = "$pc:$pciface";
if ($pcport != 1);
my $cnet = "$pc:$pceth";
push(@{$switches{$switch}}, $cnet); push(@{$switches{$switch}}, $cnet);
$newpcs{$cnet}{'exp'} = $exp; $newpcs{$cnet}{'exp'} = $exp;
...@@ -585,7 +577,7 @@ sub gather($) ...@@ -585,7 +577,7 @@ sub gather($)
foreach my $switch (keys %switches) { foreach my $switch (keys %switches) {
my $slist = join(' ', @{$switches{$switch}}); 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"; print STDERR "*** $switch: portstats failed, ignored\n";
next; next;
} }
...@@ -593,7 +585,7 @@ sub gather($) ...@@ -593,7 +585,7 @@ sub gather($)
chomp; chomp;
# XXX ignore warnings from snmpit # XXX ignore warnings from snmpit
next if ($_ =~ /^WARNING:/); next if ($_ =~ /^WARNING:/);
next if ($_ !~ /^[-\w]+:\d/); next if ($_ !~ /^[-\w]+:\w*/);
my ($node, @counts) = split ','; my ($node, @counts) = split ',';
if (@counts != 8) { if (@counts != 8) {
print STDERR "*** $node: invalid portstats!?\n"; print STDERR "*** $node: invalid portstats!?\n";
...@@ -601,13 +593,8 @@ sub gather($) ...@@ -601,13 +593,8 @@ sub gather($)
} }
# #
# XXX portstats returns nodes in the format: pcXXX:N.N, # XXX portstats returns nodes in the format: pcXXX:ethN
# even though it won't accept that format on the command line!
# #
if ($node =~ /^(.*:\d+)\.\d$/) {
$node = $1;
}
if (!exists($pcs{$node})) { if (!exists($pcs{$node})) {
print STDERR "*** $node: no stats returned!?\n"; print STDERR "*** $node: no stats returned!?\n";
next; next;
......
#!/usr/bin/perl -wT #!/usr/bin/perl -w
# #
# Copyright (c) 2008-2017 University of Utah and the Flux Group. # Copyright (c) 2008-2017 University of Utah and the Flux Group.
# #
...@@ -62,8 +62,7 @@ my $controlnet = 1; ...@@ -62,8 +62,7 @@ my $controlnet = 1;
# #
# Configure variables # Configure variables
# #
#my $TB = "@prefix@"; my $TB = "@prefix@";
my $TB = "/usr/testbed";
# #
# Testbed Support libraries # Testbed Support libraries
...@@ -171,23 +170,23 @@ print STDERR "Switches: ", join(" ", @switches), "\n" ...@@ -171,23 +170,23 @@ print STDERR "Switches: ", join(" ", @switches), "\n"
if ($doall == 2) { if ($doall == 2) {
$query_result = $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". " from wires as w,nodes as n".
" left join reserved as r on n.node_id=r.node_id". " left join reserved as r on n.node_id=r.node_id".
" where w.node_id1=n.node_id". " where w.node_id1=n.node_id".
" $sclause". " $sclause".
" and w.type='Control'". " and w.type='Control'".
" and n.role='testnode' $nclause". " and n.role='testnode' $nclause".
" order by node_id2,card2,port2"); " order by node_id2,iface1");
} else { } else {
$query_result = $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". " from wires as w,nodes as n,reserved as r".
" where w.node_id1=n.node_id and w.node_id1=r.node_id". " where w.node_id1=n.node_id and w.node_id1=r.node_id".
" $sclause". " $sclause".
" and w.type='Control'". " and w.type='Control'".
" and n.role='testnode' $nclause". " and n.role='testnode' $nclause".
" order by node_id2,card2,port2"); " order by node_id2,iface1");
} }
if (! $query_result || $query_result->numrows == 0) { if (! $query_result || $query_result->numrows == 0) {
print STDERR "Node(s) not found.\n"; print STDERR "Node(s) not found.\n";
...@@ -200,8 +199,7 @@ print STDERR "Nodes: " ...@@ -200,8 +199,7 @@ print STDERR "Nodes: "
while (my %row = $query_result->fetchhash()) { while (my %row = $query_result->fetchhash()) {
my $switch = $row{'node_id2'}; my $switch = $row{'node_id2'};
my $pc = $row{'node_id1'}; my $pc = $row{'node_id1'};
my $pceth = $row{'card1'}; my $pciface = $row{'iface1'};
my $pcport = $row{'port1'};
my $exp; my $exp;
if (defined($row{'pid'})) { if (defined($row{'pid'})) {
$exp = $row{'pid'} . "/" . $row{'eid'}; $exp = $row{'pid'} . "/" . $row{'eid'};
...@@ -209,15 +207,7 @@ while (my %row = $query_result->fetchhash()) { ...@@ -209,15 +207,7 @@ while (my %row = $query_result->fetchhash()) {
$exp = "<NONE>"; $exp = "<NONE>";
} }
# my $cnet = "$pc:$pciface";
# 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";
push(@{$switches{$switch}}, $cnet); push(@{$switches{$switch}}, $cnet);
$pcs{$cnet}{'exp'} = $exp; $pcs{$cnet}{'exp'} = $exp;
...@@ -375,13 +365,13 @@ sub gather($$) ...@@ -375,13 +365,13 @@ sub gather($$)
foreach my $switch (keys %switches) { foreach my $switch (keys %switches) {
my $slist = join(' ', @{$switches{$switch}}); my $slist = join(' ', @{$switches{$switch}});
my $arg = $byexpt ? "" : "-c"; 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"; die "Could not get portstats\n";
while (<PS>) { while (<PS>) {
chomp; chomp;
# XXX ignore warnings from snmpit # XXX ignore warnings from snmpit
next if ($_ =~ /^WARNING:/); next if ($_ =~ /^WARNING:/);
next if ($_ !~ /^[-\w]+:\d/); next if ($_ !~ /^[-\w]+:\w+/);
my ($node, @counts) = split ','; my ($node, @counts) = split ',';
if (@counts != 6) { if (@counts != 6) {
print STDERR "*** $node: invalid portstats!?\n"; print STDERR "*** $node: invalid portstats!?\n";
...@@ -389,13 +379,8 @@ sub gather($$) ...@@ -389,13 +379,8 @@ sub gather($$)
} }
# #
# XXX portstats returns nodes in the format: pcXXX:N.N, # XXX portstats returns nodes in the format: pcXXX:ethN
# even though it won't accept that format on the command line!
# #
if ($node =~ /^(.*:\d+)\.\d$/) {
$node = $1;
}
if (!exists($pcref->{$node})) { if (!exists($pcref->{$node})) {
print STDERR "*** $node: no stats returned!?\n"; print STDERR "*** $node: no stats returned!?\n";
next; next;
......
#!/usr/bin/perl -w #!/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 # {{{EMULAB-LICENSE
# #
...@@ -226,12 +226,16 @@ foreach my $node (@interconnects) { ...@@ -226,12 +226,16 @@ foreach my $node (@interconnects) {
foreach my $iface (@interfaces) { foreach my $iface (@interfaces) {
next next
if ($iface->current_speed() == 0); 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. # To be consistent use a Port object since getTrunks() does too.
my $port = Port->LookupByIface($node->node_id, $iface->iface()); my $port = Port->LookupByIface($node->node_id, $iface->iface());
if (!defined($port)) { if (!defined($port)) {
fatal("Could not get Port for $iface"); fatal("Could not get Port for $iface");
} }
$connects{$node->node_id()}->{$port->switch_node_id()} = $port; $connects{$node->node_id()}->{$port->switch_node_id()} = $port;
} }
} }
...@@ -274,8 +278,7 @@ sub Gather($) ...@@ -274,8 +278,7 @@ sub Gather($)
my @ports = @{ $trunks{$sw1}->{$sw2} }; my @ports = @{ $trunks{$sw1}->{$sw2} };
foreach my $port (@ports) { foreach my $port (@ports) {
$portstr .= " ${sw1}:" . $portstr .= " ${sw1}:" . $port->switch_iface();
$port->switch_card() . "." . $port->switch_port();
} }
} }
} }
...@@ -286,23 +289,23 @@ sub Gather($) ...@@ -286,23 +289,23 @@ sub Gather($)
foreach my $id (keys(%connects)) { foreach my $id (keys(%connects)) {
foreach my $switch (keys(%{ $connects{$id} })) { foreach my $switch (keys(%{ $connects{$id} })) {
my $port = $connects{$id}->{$switch}; my $port = $connects{$id}->{$switch};
my $str = " ${switch}:" . my $str = " ${switch}:" . $port->switch_iface();
$port->switch_card() . "." . $port->switch_port();
$portstr .= $str; $portstr .= $str;
} }
} }
if ($debug) { if ($debug) {
print $portstr . "\n"; 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"); fatal("Could not get portstats");
while (<PS>) { while (<PS>) {
if ($_ !~ /^[-\w]+:\d/) { if ($_ !~ /^[-\w]+:\w+/) {
print $_ print $_
if ($debug); if ($debug);
next; next;
} }
chomp($_); chomp($_);
my ($swport, @counts) = split(",", $_); my ($swport, @counts) = split(",", $_);
if (@counts != 6) { if (@counts != 6) {
print STDERR "*** $swport: invalid portstats!?\n"; print STDERR "*** $swport: invalid portstats!?\n";
...@@ -314,7 +317,7 @@ sub Gather($) ...@@ -314,7 +317,7 @@ sub Gather($)
# #
my ($switch,$port); my ($switch,$port);
if ($swport =~ /^(.*):(\d+\.\d+)$/) { if ($swport =~ /^(.*):([\/\.\w]+)$/) {
$switch = $1; $switch = $1;
$port = $2; $port = $2;
} }
...@@ -348,8 +351,8 @@ sub Aggregate($$) ...@@ -348,8 +351,8 @@ sub Aggregate($$)
my %sum = (); my %sum = ();
foreach my $swport (@ports) { foreach my $swport (@ports) {
my (undef,$port) = split(":", $swport); my $iface = $swport->switch_iface();
my $counts = $results->{$sw1}->{"$port"}; my $counts = $results->{$sw1}->{$iface};
foreach my $key (keys(%{$counts})) { foreach my $key (keys(%{$counts})) {
if (!exists($sum{$key})) { if (!exists($sum{$key})) {
...@@ -375,7 +378,7 @@ sub Aggregate($$) ...@@ -375,7 +378,7 @@ sub Aggregate($$)
# These ports objects refer to the node side, not the switch side, # 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. # 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"}; my $counts = $results->{$switch}->{"$port"};
$aggref->{$switch}->{$id} = $counts; $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