Commit d9d7f036 authored by Leigh B Stoller's avatar Leigh B Stoller

Initial work on converting the iface1/iface2 column of the wires table

to strings that represent how the ports are actually addressed by the
switch. Eventually card/port will be fully deprecated, but before we can
do that there has to be a way to automatically update existing sites.
Kirk will probably be the one to finish this off since I don't know
enough about the devices to do it correctly.

Also a minor structural change; move the convertPortFormat() constants
from the device files to snmpit_lib so we can call convertPortFormat
from outside the device file.
parent caa73c7b
#
# Copyright (c) 2000-2013, 2016 University of Utah and the Flux Group.
# Copyright (c) 2000-2017 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -32,7 +32,7 @@ include $(OBJDIR)/Makeconf
SUBDIRS =
BIN_STUFF = snmpit portstats
BIN_STUFF = snmpit portstats convertifaces
LIB_STUFF = snmpit_intel.pm \
snmpit_cisco.pm snmpit_lib.pm \
snmpit_cisco_stack.pm snmpit_intel_stack.pm \
......
#!/usr/bin/perl -w
#
# Copyright (c) 2003-2017 University of Utah and the Flux Group.
#
# {{{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/>.
#
# }}}
#
use strict;
use English;
use Getopt::Std;
use Data::Dumper;
#
# Add an interface to the DB. Typically, this is used to add the switch
# side of a wire, but it can be used to add the node side too.a
#
sub usage()
{
print STDERR "Usage: convertifaces [-n] [-v level] switch switch ...\n";
print STDERR " -n - Impotent mode\n";
print STDERR " -v level - snmput verbosity level\n";
exit(-1);
}
my $optlist = "nv:";
my $impotent = 1;
my $debug = 0;
# Protos
sub fatal($);
#
# Configure variables
#
my $TB = "@prefix@";
#
# Testbed Support libraries
#
use lib "@prefix@/lib";
use emdb;
use EmulabConstants;
use emutil;
use Node;
use NodeType;
use Interface;
use lib "@prefix@/lib/snmpit";
use snmpit_lib;
#
# Turn off line buffering on output
#
$| = 1;
#
# Untaint the path
#
$ENV{'PATH'} = "/bin:/sbin:/usr/bin:";
#
# Parse command arguments.
#
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{'n'})) {
$impotent = 1;
}
if (defined($options{'v'})) {
$debug = $options{'v'};
}
usage()
if (!@ARGV);
foreach my $switchid (@ARGV) {
my $switch = Node->Lookup($switchid);
if (!defined($switch)) {
fatal("No such switch in the database: $switchid");
}
if (!$switch->isswitch()) {
fatal("Not a switch: $switchid");
}
#
# Connect to the switch.
#
my $type = getDeviceType($switchid);
my $device;
SWITCH: for ($type) {
/cisco/ && do {
require snmpit_cisco;
$device = new snmpit_cisco($switchid, $debug);
last;
};
/intel/ && do {
require snmpit_intel;
$device = new snmpit_intel($switchid, $debug);
last;
};
/foundry/ && do {
require snmpit_foundry;
$device = new snmpit_foundry($switchid, $debug);
last;
};
/nortel/ && do {
require snmpit_nortel;
$device = new snmpit_nortel($switchid, $debug);
last;
};
/hp/ && do {
require snmpit_hp;
$device = new snmpit_hp($switchid, $debug);
last;
};
/arista/ && do {
require snmpit_arista;
$device = new snmpit_arista($switchid, $debug);
last;
};
/mellanox/ && do {
require snmpit_mellanox;
$device = new snmpit_mellanox($switchid, $debug);
last;
};
/force10/ && do {
require snmpit_force10;
$device = new snmpit_force10($switchid, $debug);
last;
};
/comware/ && do {
require snmpit_h3c;
$device = new snmpit_h3c($switchid, $debug);
last;
};
fatal("Unknown switch type ($type) for $switchid");
}
#
# Grab all the interfaces we have in the DB for this switch. At
# this point, there should be an interface associated with both
# sides of every wire, and a wire associated with every trunk.
#
my $query_result =
DBQueryFatal("select iface from interfaces ".
"where node_id='$switchid'");
if (!$query_result->numrows) {
print STDERR "No interfaces found in the DB for $switchid. ".
"Skipping ...\n";
next;
}
while (my ($iface) = $query_result->fetchrow_array()) {
my ($card,$port);
my $interface = Interface->LookupByIface($switch, $iface);
fatal("Could not lookup interface $switchid:$iface in the DB")
if (!defined($interface));
# It is okay not to have a wire for an interface, but there
# will always be an interface for both sides of a wire.
my $wire = Interface::Wire->LookupAnyByIface($switch, $iface);
if (defined($wire)) {
#
# Need to encapsulate this in the library!
#
if ($wire->node_id1() eq $switchid) {
$card = $wire->card1();
$port = $wire->port1();
}
else {
$card = $wire->card2();
$port = $wire->port2();
}
}
elsif ($interface->card_saved() && $interface->port_saved()) {
# We are keeping the old card,port around for a while.
$card = $interface->card_saved();
$port = $interface->port_saved();
}
else {
print "$switchid:$iface : no wire and no card/port. Skipping ...\n";
next;
}
my $modport = "$card.$port";
my ($ifdesc) = $device->convertPortFormat($PORT_FORMAT_PORTINDEX,
($modport));
if (!defined($ifdesc)) {
print STDERR "Could not convert $switchid:$iface to an ifdescr. ".
"Skipping.\n";
next;
}
next
if ($interface->iface() eq $ifdesc);
print "$switchid:$iface does not match ifdescr: $ifdesc\n";
if ($impotent) {
print "--> Would change $interface to $ifdesc\n";
}
else {
print "--> Changing $interface to $ifdesc\n";
}
}
}
exit(0);
sub fatal($)
{
my ($mesg) = $_[0];
die("*** $0:\n".
" $mesg\n");
}
......@@ -2,7 +2,7 @@
# vim: set et ts=4 sw=4:
#
# Copyright (c) 2000-2012 University of Utah and the Flux Group.
# Copyright (c) 2000-2017 University of Utah and the Flux Group.
#
# {{{EMULAB-LGPL
#
......@@ -74,14 +74,6 @@ my %cmdOIDs =
# Cisco switches (eg. 5.42)
# nodeport: node:port pair, referring to the node that the switch port is
# connected to (eg. "pc42:1")
#
# See the function convertPortFormat below for conversions between these
# formats
#
my $PORT_FORMAT_IFINDEX = 1;
my $PORT_FORMAT_MODPORT = 2;
my $PORT_FORMAT_NODEPORT = 3;
my $PORT_FORMAT_PORT = 4;
#
# used by vlanTrunkUtil()
......@@ -437,6 +429,11 @@ sub convertPortFormat($$@) {
}
if ($input == $PORT_FORMAT_IFINDEX) {
if ($output == $PORT_FORMAT_PORTINDEX) {
my @mps = map $self->{IFDESCR}{$_}, @ports;
$self->debug("Converting ifindex to ifDescr\n",3);
return @mps;
}
my @mps = map $self->{IFINDEX}{$_}, @ports;
if ($output == $PORT_FORMAT_MODPORT) {
$self->debug("Converting ifindex to modport\n",2);
......@@ -456,6 +453,11 @@ sub convertPortFormat($$@) {
$self->debug("Converting modport to ifindex\n",2);
return map $self->{IFINDEX}{$_}, @ports;
}
if ($output == $PORT_FORMAT_PORTINDEX) {
$self->debug("Converting modport to ifDescr\n",3);
my @ifs = map $self->{IFINDEX}{$_}, @ports;
return map $self->{IFDESCR}{$_}, @ifs;
}
my @pos = map Port->LookupByStringForced($self->{NAME}.":".$_), @ports;
......@@ -2074,15 +2076,23 @@ sub readifIndex($) {
foreach my $rowref (@$rows) {
my ($name,$modport,$ifindex) = @$rowref;
my $ifd = $modport;
$ifd =~ s/\./\//g;
$self->debug("portIfIndex: $name, $modport, $ifindex, $ifd\n", 2);
$self->{IFINDEX}{$modport} = $ifindex;
$self->{IFINDEX}{$ifindex} = $modport;
$self->{IFDESCR}{$ifindex} = $ifd;
$self->{IFDESCR}{$ifd} = $ifindex;
}
} elsif ($self->{OSTYPE} eq "IOS" || $self->{OSTYPE} eq 'NX-OS') {
my ($rows) = snmpitBulkwalkFatal($self->{SESS},["ifDescr"]);
foreach my $rowref (@$rows) {
my ($name,$iid,$descr) = @$rowref;
$self->debug("ifdesc: $name, $iid, $descr\n", 2);
if ($descr =~ /(\D*)(\d+)\/(\d+)(\/(\d+))?$/) {
my $hassubmod = defined($4) ? 1 : 0;
my $type = $1;
......@@ -2117,6 +2127,8 @@ sub readifIndex($) {
$self->{IFINDEX}{$modport} = $ifindex;
$self->{IFINDEX}{$ifindex} = $modport;
$self->{IFDESCR}{$ifindex} = $descr;
$self->{IFDESCR}{$descr} = $ifindex;
$self->debug("IFINDEX: $modport,$ifindex\n", 2);
}
......
#!/usr/bin/perl -w
#
# Copyright (c) 2013,2014 University of Utah and the Flux Group.
# Copyright (c) 2013-2017 University of Utah and the Flux Group.
# Copyright (c) 2006-2014 Universiteit Gent/iMinds, Belgium.
# Copyright (c) 2004-2006 Regents, University of California.
#
......@@ -133,12 +133,6 @@ my $OID_AGGPLIST = ".1.3.6.1.4.1.6027.3.2.1.1.1.1.6";
# nodeport: node:port pair, referring to the node that the switch port is
# connected to (eg. "pc42:1")
#
# See the function convertPortFormat below for conversions between these
# formats
#
my $PORT_FORMAT_IFINDEX = 1;
my $PORT_FORMAT_MODPORT = 2;
my $PORT_FORMAT_PORT = 3;
# OpenFlow constants
my $MAX_OF_ID = 8;
......@@ -541,7 +535,11 @@ sub convertPortFormat($$@) {
}
if ($input == $PORT_FORMAT_IFINDEX) {
if ($output == $PORT_FORMAT_MODPORT) {
if ($output == $PORT_FORMAT_PORTINDEX) {
$self->debug("Converting ifindex to ifDescr\n",3);
return map $self->{PORTINDEX}{$_}, @ports;
}
elsif ($output == $PORT_FORMAT_MODPORT) {
$self->debug("Converting ifindex to modport\n",2);
return map $self->{IFINDEX}{$_}, @ports;
} elsif ($output == $PORT_FORMAT_PORT) {
......@@ -555,7 +553,13 @@ sub convertPortFormat($$@) {
if ($output == $PORT_FORMAT_IFINDEX) {
$self->debug("Converting modport to ifindex\n",2);
return map $self->{IFINDEX}{$_}, @ports;
} elsif ($output == $PORT_FORMAT_PORT) {
}
elsif ($output == $PORT_FORMAT_PORTINDEX) {
$self->debug("Converting modport to ifDescr\n",3);
my @ifs = map $self->{IFINDEX}{$_}, @ports;
return map $self->{PORTINDEX}{$_}, @ifs;
}
elsif ($output == $PORT_FORMAT_PORT) {
$self->debug("Converting modport to Port\n",2);
return map {Port->LookupByStringForced(
Port->Tokens2TripleString(
......
#!/usr/bin/perl -w
#
# Copyright (c) 2000-2013 University of Utah and the Flux Group.
# Copyright (c) 2000-2013, 2017 University of Utah and the Flux Group.
# Copyright (c) 2004-2010 Regents, University of California.
#
# {{{EMULAB-LGPL
......@@ -100,10 +100,6 @@ my $ofListenerVarNameMarker = '35.1.1.4';
# See the function convertPortFormat below for conversions between these
# formats
#
my $PORT_FORMAT_IFINDEX = 1;
my $PORT_FORMAT_MODPORT = 2;
my $PORT_FORMAT_NODEPORT = 3;
my $PORT_FORMAT_PORT = 4;
#
# Creates a new object.
......@@ -168,6 +164,7 @@ sub new($$$;$) {
# set up hashes for internal use
#
$self->{IFINDEX} = {};
$self->{IFDESCR} = {};
$self->{TRUNKINDEX} = {};
$self->{TRUNKS} = {};
......@@ -573,6 +570,12 @@ sub convertPortFormat($$@) {
}
if ($input == $PORT_FORMAT_IFINDEX) {
if ($output == $PORT_FORMAT_PORTINDEX) {
my @mps = map $self->{IFDESCR}{$_}, @ports;
$self->debug("Converting ifindex to ifDescr\n",3);
@results = @mps;
goto done;
}
my @mps = map $self->{IFINDEX}{$_}, @ports;
if ($output == $PORT_FORMAT_MODPORT) {
$self->debug("Converting ifindex to modport\n",3);
......@@ -604,6 +607,12 @@ sub convertPortFormat($$@) {
@results = map $self->{IFINDEX}{$_}, @ports;
goto done;
}
if ($output == $PORT_FORMAT_PORTINDEX) {
$self->debug("Converting modport to ifDescr\n",3);
my @ifs = map $self->{IFINDEX}{$_}, @ports;
@results = map $self->{IFDESCR}{$_}, @ifs;
goto done;
}
my @pos = map Port->LookupByStringForced($self->{NAME}.":".$_), @ports;
......@@ -678,6 +687,7 @@ sub convertPortFormat($$@) {
}
return @results;
}
#
# Check to see if the given 802.1Q VLAN tag exists on the switch
#
......@@ -1925,10 +1935,18 @@ sub readifIndex($) {
my $self = shift;
my ($maxport, $maxtrunk, $name, $ifindex, $iidoid, $port, $mod, $j) = (0,0);
$self->debug($self->{NAME} . "::readifIndex:\n", 2);
my %ifdescr = ();
my ($rows) = snmpitBulkwalkFatal($self->{SESS}, ["ifDescr"]);
foreach my $rowref (@$rows) {
my ($name,$ifindex,$descr) = @$rowref;
$self->debug("ifDescr: $name, $ifindex, $descr\n", 2);
$ifdescr{"$ifindex"} = $descr;
}
my $bladesize = $blade_sizes{$self->{HPTYPE}};
my ($rows) = snmpitBulkwalkFatal($self->{SESS}, ["hpSwitchPortTrunkGroup"]);
($rows) = snmpitBulkwalkFatal($self->{SESS}, ["hpSwitchPortTrunkGroup"]);
my $t_off = $self->{TRUNKOFFSET} = 288;
foreach my $rowref (@$rows) {
......@@ -1940,6 +1958,7 @@ sub readifIndex($) {
if ($iidoid > $maxtrunk) { $maxtrunk = $iidoid;}
}
while (($ifindex, $iidoid) = each %{$self->{TRUNKINDEX}}) {
my $ifd = "unknown";
if (defined($bladesize)) {
$j = $ifindex - 1;
$port = 1 + ($j % $bladesize);
......@@ -1948,11 +1967,19 @@ sub readifIndex($) {
{ $mod = 1; $port = $ifindex; }
my $modport = "$mod.$port";
my $portindex = $iidoid ? ($t_off + $iidoid) : $ifindex ;
my $ifdesc = (exists($ifdescr{"$ifindex"}) ?
$ifdescr{"$ifindex"} : "unknown");
$self->{IFINDEX}{$modport} = $portindex;
$self->{IFINDEX}{$ifindex} = $modport;
$self->debug("$ifindex, $modport\n", 2);
if (exists($ifdescr{"$ifindex"})) {
$ifd = $ifdescr{"$ifindex"};
$self->{IFDESCR}{$ifindex} = $ifd;
$self->{IFDESCR}{$ifd} = $ifindex;
}
$self->debug("$ifindex, $modport, $ifd\n", 2);
}
foreach $j (keys %{$self->{TRUNKS}}) {
my $ifd = "unknown";
$ifindex = $j + $t_off;
if (my $lref = $self->{TRUNKS}{$j}) {
$port = $self->{IFINDEX}{@$lref[0]}; #actually modport
......@@ -1960,7 +1987,12 @@ sub readifIndex($) {
$self->{IFINDEX}{$ifindex} = $port;
$self->{IFINDEX}{$port} = $ifindex;
$self->{TRUNKINDEX}{$ifindex} = 0; # simplifies convertPortIndex
$self->debug("$ifindex, $port\n", 2);
if (exists($ifdescr{"$ifindex"})) {
$ifd = $ifdescr{"$ifindex"};
$self->{IFDESCR}{$ifindex} = $ifd;
$self->{IFDESCR}{$ifd} = $ifindex;
}
$self->debug("$ifindex, $port, $ifd\n", 2);
}
$self->{MAXPORT} = $maxport;
$self->{MAXTRUNK} = $maxtrunk;
......
......@@ -30,6 +30,16 @@ package snmpit_lib;
use Exporter;
@ISA = ("Exporter");
use vars qw($PORT_FORMAT_IFINDEX $PORT_FORMAT_MODPORT
$PORT_FORMAT_NODEPORT $PORT_FORMAT_PORT $PORT_FORMAT_PORTINDEX);
# For convertPortFormat in the device libraries.
$PORT_FORMAT_IFINDEX = 1;
$PORT_FORMAT_MODPORT = 2;
$PORT_FORMAT_NODEPORT = 3;
$PORT_FORMAT_PORT = 4;
$PORT_FORMAT_PORTINDEX= 5;
@EXPORT = qw( macport portnum portiface Dev vlanmemb vlanid
getTestSwitches getControlSwitches getSwitchesInStack
getSwitchesInStacks
......@@ -56,6 +66,8 @@ use Exporter;
mapVlansToSwitches mapStaleVlansToSwitches
getTrunksForVlan getExperimentTrunksForVlan
setSwitchTrunkPath mapPortsToSwitches findAndDumpLan
$PORT_FORMAT_IFINDEX $PORT_FORMAT_MODPORT
$PORT_FORMAT_NODEPORT $PORT_FORMAT_PORT $PORT_FORMAT_PORTINDEX
);
use English;
......
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