Commit 64c78cae authored by Robert Ricci's avatar Robert Ricci

New script: checkports

Checks to make sure that all ports for an experiment are in the
correct switch state. If they are enabled, they should have
carrier.

Note that enough code is shared between checkports and portstats
that some of it could probably be moved to a library at this
point.
parent 2195929c
......@@ -1225,6 +1225,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
tbsetup/webmkproj tbsetup/mkproj tbsetup/libtestbed.pm \
tbsetup/portstats tbsetup/vnode_setup tbsetup/staticroutes \
tbsetup/console_setup.proxy tbsetup/exports_setup.proxy \
tbsetup/checkports \
tip/GNUmakefile \
tmcd/GNUmakefile tmcd/freebsd/GNUmakefile tmcd/linux/GNUmakefile \
tmcd/ron/GNUmakefile \
......
......@@ -297,6 +297,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
tbsetup/webmkproj tbsetup/mkproj tbsetup/libtestbed.pm \
tbsetup/portstats tbsetup/vnode_setup tbsetup/staticroutes \
tbsetup/console_setup.proxy tbsetup/exports_setup.proxy \
tbsetup/checkports \
tip/GNUmakefile \
tmcd/GNUmakefile tmcd/freebsd/GNUmakefile tmcd/linux/GNUmakefile \
tmcd/ron/GNUmakefile \
......
......@@ -13,7 +13,7 @@ SUBDIRS = checkpass ns2ir
BIN_STUFF = power snmpit tbend tbswapin tbswapout tbprerun tbreport \
os_load startexp endexp batchexp swapexp \
node_reboot nscheck node_update savelogs node_control \
portstats
portstats checkports
# Stuff that mere users get on plastic.
USERBINS = os_load node_reboot nscheck node_update savelogs \
......
#!/usr/bin/perl -w
#
# checkports - Check to make sure that all ports for an experiment are
# up
#
# TODO: Add duplex checking
# TODO: Add the ability to check all ports at once
#
#
# Configure variables
#
use lib '@prefix@/lib';
use libdb;
use snmpit_lib;
use English;
use Getopt::Long;
use strict;
sub usage {
print << "END";
Usage: $0 [-h] <pid> <eid>
-h This message
Checks all ports in pid/eid to make sure that the operational status (whether
or not the port has carrier) matches the administrative status (whether or not
the port is enabled.)
END
return 1;
}
#
# Process command-line arguments
#
my %opt = ();
GetOptions(\%opt,'h');
if ($opt{h}) {
exit &usage;
}
my @oids = ('ifAdminStatus','ifOperStatus'); # The set of OIDs we care about
if (@ARGV != 2) {
exit &usage;
}
snmpit_lib::init(0);
my($pid,$eid) = (shift,shift);
#
# First, make sure the experiment exists
#
if (!ExpState($pid,$eid)) {
die "There is no experiment $eid in project $pid\n";
}
#
# Make sure they have access to it
#
if (!TBExptAccessCheck($UID,$pid,$eid,TB_EXPT_READINFO)) {
die "You do not have permission to view experiment $pid/$eid\n";
}
#
# Get a list of all ports in the experiment
#
my @ports = getExperimentPorts($pid,$eid);
#
# Just exit now if there are no ports for this experiment
#
if (!@ports) {
print "There are no switch ports for $pid/$eid\n";
exit(0);
}
#
# Find out which devices these ports are on
#
my %portMap = mapPortsToDevices(@ports);
my @portinfo;
foreach my $name (keys %portMap) {
my @ports = @{$portMap{$name}};
#
# Connect to the switch and get the data we want off of it
#
my $type = getDeviceType($name);
my $device;
SWITCH: for ($type) {
/cisco/ && do {
require snmpit_cisco;
$device = new snmpit_cisco($name);
last;
};
/intel/ && do {
require snmpit_intel;
$device = new snmpit_intel($name);
last;
};
# 'default' case
die "Unknown switch type ($type) for $name\n";
}
my @results = $device->getFields(\@ports,\@oids);
foreach my $result (@results) {
my $port = shift @ports;
#
# Try to translate the port name to the node's vname
#
$port =~ /^(.+):(\d+)/;
my $nickname;
if ($1) {
my $portnum = $2;
my ($junk, $vname);
NodeidToExp($1,\$junk,\$junk,\$vname);
$nickname = "$vname:$portnum";
}
#
# Throw this onto a list, so that we can sort it
#
push @portinfo, [$nickname,$port,@$result];
}
}
#
# Finally, print out the results
#
my $errors = 0;
foreach my $line (sort {$$a[0] cmp $$b[0]} @portinfo) {
my ($nickname,$port,$adminStatus,$operStatus) = @$line;
if ($adminStatus ne $operStatus) {
print "Switch port for $nickname ($port) should be $adminStatus, " .
"but is $operStatus\n";
$errors++;
}
}
if ($errors) {
print "There were no errors found\n";
exit(1);
} else {
print "There were $errors errors found\n";
exit(0);
}
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