Commit a289bdf9 authored by Mike Hibler's avatar Mike Hibler

Add -s option which says to interpret arguments in switch.module/port

syntax.  This allows us to query interswitch link counters.  Only root
or the admin can use this option.
parent 909b034a
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# #
# EMULAB-COPYRIGHT # EMULAB-COPYRIGHT
# Copyright (c) 2000-2004 University of Utah and the Flux Group. # Copyright (c) 2000-2004, 2006 University of Utah and the Flux Group.
# All rights reserved. # All rights reserved.
# #
...@@ -41,6 +41,7 @@ Usage: $0 [-h] <-p | <pid> <eid> > [vname ...] [vname:port ...] ...@@ -41,6 +41,7 @@ Usage: $0 [-h] <-p | <pid> <eid> > [vname ...] [vname:port ...]
-c Print absolute, rather than relative, counts -c Print absolute, rather than relative, counts
-p The machines given are physical, not virtual, node IDs. No pid and -p The machines given are physical, not virtual, node IDs. No pid and
eid should be given when using this option. eid should be given when using this option.
-s Ports are specified in switch.port syntax
If only pid and eid are given, prints out information about all ports in the If only pid and eid are given, prints out information about all ports in the
experiment. Otherwise, output is limited to the nodes and/or ports given. experiment. Otherwise, output is limited to the nodes and/or ports given.
...@@ -60,7 +61,7 @@ END ...@@ -60,7 +61,7 @@ END
# Process command-line arguments # Process command-line arguments
# #
my %opt = (); my %opt = ();
GetOptions(\%opt,'h','a','e','p','b','z','q','c'); GetOptions(\%opt,'h','a','e','p','b','z','q','c','s');
if ($opt{h}) { if ($opt{h}) {
exit &usage; exit &usage;
...@@ -81,7 +82,7 @@ if ($opt{a}) { ...@@ -81,7 +82,7 @@ if ($opt{a}) {
} }
my ($pid, $eid); my ($pid, $eid);
if (!$opt{p}) { if (!$opt{p} && !$opt{s}) {
if (@ARGV < 2) { if (@ARGV < 2) {
exit &usage; exit &usage;
} }
...@@ -91,7 +92,7 @@ if (!$opt{p}) { ...@@ -91,7 +92,7 @@ if (!$opt{p}) {
# Untaint args. # Untaint args.
# #
if ($pid =~ /^([-\w]+)$/) { if ($pid =~ /^([-\w]+)$/) {
$pid = $1; $pid = $1;
} }
else { else {
tbdie("Bad data in pid: $pid."); tbdie("Bad data in pid: $pid.");
...@@ -110,11 +111,20 @@ if (!$opt{p}) { ...@@ -110,11 +111,20 @@ if (!$opt{p}) {
# #
my @passedPorts = (); my @passedPorts = ();
foreach my $arg (@ARGV) { foreach my $arg (@ARGV) {
if ($arg =~ /^([-\w\.:]+)$/) { if ($opt{s}) {
$arg = $1; if ($arg =~ /^([-\w\.\/]+)$/) {
} $arg = $1;
else { }
tbdie("Bad data in arg: $arg."); else {
tbdie("Bad data in arg: $arg.");
}
} else {
if ($arg =~ /^([-\w\.:]+)$/) {
$arg = $1;
}
else {
tbdie("Bad data in arg: $arg.");
}
} }
push(@passedPorts, $arg); push(@passedPorts, $arg);
} }
...@@ -140,7 +150,7 @@ my %oids = ( ...@@ -140,7 +150,7 @@ my %oids = (
# #
# First, make sure the experiment exists # First, make sure the experiment exists
# #
if (!$opt{p}) { if (!$opt{p} && !$opt{s}) {
if (!ExpState($pid,$eid)) { if (!ExpState($pid,$eid)) {
die "There is no experiment $eid in project $pid\n"; die "There is no experiment $eid in project $pid\n";
} }
...@@ -149,7 +159,11 @@ if (!$opt{p}) { ...@@ -149,7 +159,11 @@ if (!$opt{p}) {
# #
# Make sure they have access to it # Make sure they have access to it
# #
if ($opt{p}) { if ($opt{s}) {
if ($UID && !TBAdmin($UID)) {
die("Only root or TB admins can use -s.");
}
} elsif ($opt{p}) {
my @nodes = map { /^([^:]+)(:(\d+))?$/; $1; } @passedPorts; my @nodes = map { /^([^:]+)(:(\d+))?$/; $1; } @passedPorts;
if (!TBNodeAccessCheck($UID,TB_NODEACCESS_READINFO,@nodes)) { if (!TBNodeAccessCheck($UID,TB_NODEACCESS_READINFO,@nodes)) {
die "You do not have permission to view one or more of @nodes\n"; die "You do not have permission to view one or more of @nodes\n";
...@@ -170,12 +184,25 @@ if ($ELABINELAB) { ...@@ -170,12 +184,25 @@ if ($ELABINELAB) {
snmpit_lib::init(0); snmpit_lib::init(0);
my @ports;
#
# If using "switch" syntax, make sure all names are in the correct format
#
if ($opt{s}) {
foreach my $port (@passedPorts) {
if ($port =~ /^[^.]+\.\d+\/\d+$/) {
push @ports, $port;
} else {
print "'$port' not in correct switch.port syntax, ignoring\n";
}
}
}
# #
# If using physical port IDs, just use the list passed on the command line - # If using physical port IDs, just use the list passed on the command line -
# For an experiment, figure out which one(s) they wanted. # For an experiment, figure out which one(s) they wanted.
# #
my @ports; elsif ($opt{p}) {
if ($opt{p}) {
# #
# If they gave a node:port form, use just that port. Otherwise, try to find # If they gave a node:port form, use just that port. Otherwise, try to find
# all the node's ports # all the node's ports
...@@ -275,7 +302,14 @@ foreach my $name (keys %portMap) { ...@@ -275,7 +302,14 @@ foreach my $name (keys %portMap) {
# #
# Figure out which port on which switch this corresponds to # Figure out which port on which switch this corresponds to
# #
my $switchport = portnum($port); my $switchport;
if ($opt{s}) {
if ($port =~ /^([^.]+)\.(\d+)\/(\d+)$/) {
$switchport = "$1:$2.$3";
}
} else {
$switchport = portnum($port);
}
if (!($switchport && ($switchport =~ /(.+):(\d+)\.(\d+)/))) { if (!($switchport && ($switchport =~ /(.+):(\d+)\.(\d+)/))) {
warn "WARNING: No switch port found for $port\n"; warn "WARNING: No switch port found for $port\n";
} else { } else {
...@@ -344,7 +378,7 @@ foreach my $name (keys %portMap) { ...@@ -344,7 +378,7 @@ foreach my $name (keys %portMap) {
} }
} }
if (!$opt{p}) { if (!$opt{p} && !$opt{s}) {
# #
# Try to translate the port name to the node's vname # Try to translate the port name to the node's vname
# #
......
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