Commit 5674e476 authored by Jonathon Duerig's avatar Jonathon Duerig
Browse files

Merge branch 'master' of git-public.flux.utah.edu:/flux/git/emulab-devel

parents 8a508bfd 9e0021d3
......@@ -876,7 +876,13 @@ sub getOtherEndIfaceString($) {
# get the other side of a port instance, according to 'wires' DB table
#
sub getOtherEndPort($) {
return Port->LookupByTriple($_[0]->getOtherEndTripleString());
my $self = $_[0];
my $pt = Port->LookupByTriple($self->getOtherEndTripleString());
if (defined($pt)) {
return $pt;
} else {
return $self;
}
}
#
......
......@@ -337,7 +337,7 @@ DEVICE: foreach my $name (keys %portMap) {
# Figure out which port on which switch this corresponds to
#
my $switchport = $port->getSwitchPort()?
$port->getSwitchPort()->toString():undef;
$port->getSwitchPort():undef;
if (!$switchport) {
warn "WARNING: No switch port found for ".$port->toString()."\n";
......
......@@ -405,7 +405,7 @@ sub convertPortFormat($$@) {
if ($output == $PORT_FORMAT_NODEPORT) {
$self->debug("Converting ifindex to nodeport\n",2);
return map $_->getPCPort()->toTripleString(), @pos;
return map $_->getOtherEndPort()->toTripleString(), @pos;
} elsif ($output == $PORT_FORMAT_PORT) {
return @pos;
}
......@@ -419,7 +419,7 @@ sub convertPortFormat($$@) {
if ($output == $PORT_FORMAT_NODEPORT) {
$self->debug("Converting modport to nodeport\n",3);
return map $_->getPCPort()->toTripleString(), @pos;
return map $_->getOtherEndPort()->toTripleString(), @pos;
} elsif ($output == $PORT_FORMAT_PORT) {
return @pos;
}
......@@ -452,7 +452,7 @@ sub convertPortFormat($$@) {
)[1] } @ports;
} elsif ($output == $PORT_FORMAT_NODEPORT) {
$self->debug("Converting port to nodeport\n",3);
return map $_->getPCPort()->toTripleString(), @ports;
return map $_->getOtherEndPort()->toTripleString(), @ports;
}
}
......@@ -1656,7 +1656,7 @@ sub walkTableIfIndex($$$;$) {
my $po = convertPortFromString("$self->{NAME}:$index")
|| convertPortFromString("$self->{NAME}:".$self->{IFINDEX}{$index});
if (! defined $po) { next; } # Skip if we don't know about it
my $port = $po->getPCPort()->toTripleString();
my $port = $po->getOtherEndPort()->toTripleString();
#
# Apply the user's processing function
......
......@@ -18,6 +18,7 @@ $| = 1; # Turn off line buffering on output
use English;
use SNMP;
use snmpit_lib;
use Port;
#
# These are the commands that can be passed to the portControl function
......@@ -50,6 +51,7 @@ my %cmdOIDs =
my $PORT_FORMAT_IFINDEX = 1;
my $PORT_FORMAT_MODPORT = 2;
my $PORT_FORMAT_NODEPORT = 3;
my $PORT_FORMAT_PORT = 4;
#
# Creates a new object.
......@@ -272,6 +274,7 @@ sub convertPortFormat($$@) {
my $input;
SWITCH: for ($sample) {
(Port->isPort($sample)) && do { $input = $PORT_FORMAT_PORT; last; };
(/^\d+$/) && do { $input = $PORT_FORMAT_IFINDEX; last; };
(/^\d+\.\d+$/) && do { $input = $PORT_FORMAT_MODPORT; last; };
(/^$self->{NAME}\.\d+\/\d+$/) && do { $input = $PORT_FORMAT_MODPORT;
......@@ -288,29 +291,68 @@ sub convertPortFormat($$@) {
}
if ($input == $PORT_FORMAT_IFINDEX) {
my @mps = map $self->{IFINDEX}{$_}, @ports;
if ($output == $PORT_FORMAT_MODPORT) {
$self->debug("Converting ifindex to modport\n",2);
return map $self->{IFINDEX}{$_}, @ports;
} elsif ($output == $PORT_FORMAT_NODEPORT) {
$self->debug("Converting ifindex to nodeport\n",2);
return map portnum($self->{NAME}.":".$self->{IFINDEX}{$_}), @ports;
$self->debug("Converting ifindex to modport\n",3);
return @mps;
}
my @pos = map Port->LookupByStringForced($self->{NAME}.":".$_), @mps;
if ($output == $PORT_FORMAT_NODEPORT) {
$self->debug("Converting ifindex to nodeport\n",3);
return map $_->getPCPort()->toTripleString(), @pos;
} elsif ($output == $PORT_FORMAT_PORT) {
return @pos;
}
} elsif ($input == $PORT_FORMAT_MODPORT) {
if ($output == $PORT_FORMAT_IFINDEX) {
$self->debug("Converting modport to ifindex\n",2);
$self->debug("Converting modport to ifindex\n",3);
return map $self->{IFINDEX}{$_}, @ports;
} elsif ($output == $PORT_FORMAT_NODEPORT) {
$self->debug("Converting modport to nodeport\n",2);
return map portnum($self->{NAME} . ":$_"), @ports;
}
my @pos = map Port->LookupByStringForced($self->{NAME}.":".$_), @ports;
if ($output == $PORT_FORMAT_NODEPORT) {
$self->debug("Converting modport to nodeport\n",3);
return map $_->getPCPort()->toTripleString(), @pos;
} elsif ($output == $PORT_FORMAT_PORT) {
return @pos;
}
} elsif ($input == $PORT_FORMAT_NODEPORT) {
my @pos = map Port->LookupByStringForced($_)->getSwitchPort(), @ports;
if ($output == $PORT_FORMAT_IFINDEX) {
$self->debug("Converting nodeport to ifindex\n",2);
return map $self->{IFINDEX}{(split /:/,portnum($_))[1]}, @ports;
$self->debug("Converting nodeport to ifindex\n",3);
return map $self->{IFINDEX}{(split /:/, $_->toTripleString())[1]}, @pos;
} elsif ($output == $PORT_FORMAT_MODPORT) {
$self->debug("Converting nodeport to modport\n",2);
return map { (split /:/,portnum($_))[1] } @ports;
}
$self->debug("Converting nodeport to modport\n",3);
return map { (split /:/, $_->toTripleString())[1] } @pos;
} elsif ($output == $PORT_FORMAT_PORT) {
return @pos;
}
} elsif ($input == $PORT_FORMAT_PORT) {
if ($output == $PORT_FORMAT_IFINDEX) {
$self->debug("Converting port to ifindex\n",3);
return map $self->{IFINDEX}{(split /:/,
($_->node_id() eq $self->{NAME})?
$_->toTripleString():
$_->getOtherEndTripleString()
)[1]}, @ports;
} elsif ($output == $PORT_FORMAT_MODPORT) {
$self->debug("Converting port to modport\n",3);
return map { (split /:/,
($_->node_id() eq $self->{NAME})?
$_->toTripleString():
$_->getOtherEndTripleString()
)[1] } @ports;
} elsif ($output == $PORT_FORMAT_NODEPORT) {
$self->debug("Converting port to nodeport\n",3);
return map $_->getPCPort()->toTripleString(), @ports;
}
}
#
......@@ -501,7 +543,7 @@ sub setPortVlan($$@) {
#
my @portlist = $self->convertPortFormat($PORT_FORMAT_IFINDEX, @ports);
$self->debug("foundry::setPortVLan ports: " . join(",",@ports) . "\n");
$self->debug("foundry::setPortVLan ports: " . Port->toStrings(@ports) . "\n");
$self->debug("as ifIndexes: " . join(",",@portlist) . "\n");
foreach my $port (@portlist) {
......@@ -542,7 +584,7 @@ sub setPortVlan($$@) {
# We need to make sure the ports get enabled.
#
$self->debug("Enabling " . join(',',@ports) . "...\n");
$self->debug("Enabling " . Port->toStrings(@ports) . "...\n");
if ( my $rv = $self->portControl("enable",@ports) ) {
print STDERR "Port enable had $rv failures.\n";
$errors += $rv;
......@@ -662,7 +704,7 @@ sub removeSomePortsFromVlan($$@) {
my ($self, $vlan_number, @ports) = @_;
my ($errors, $id, %hports) = (0,$self->{NAME}."::removeSomePortsFromVlan");
$self->debug("$id $vlan_number @ports\n");
$self->debug("$id $vlan_number ".Port->toStrings(@ports)."\n");
@ports = $self->convertPortFormat($PORT_FORMAT_IFINDEX,@ports);
@hports{@ports} = @ports;
......
......@@ -493,7 +493,7 @@ sub convertPortFormat($$@) {
if ($output == $PORT_FORMAT_NODEPORT) {
$self->debug("Converting ifindex to nodeport\n",3);
return map $_->getPCPort()->toTripleString(), @pos;
return map $_->getOtherEndPort()->toTripleString(), @pos;
} elsif ($output == $PORT_FORMAT_PORT) {
return @pos;
}
......@@ -507,7 +507,7 @@ sub convertPortFormat($$@) {
if ($output == $PORT_FORMAT_NODEPORT) {
$self->debug("Converting modport to nodeport\n",3);
return map $_->getPCPort()->toTripleString(), @pos;
return map $_->getOtherEndPort()->toTripleString(), @pos;
} elsif ($output == $PORT_FORMAT_PORT) {
return @pos;
}
......@@ -540,7 +540,7 @@ sub convertPortFormat($$@) {
)[1] } @ports;
} elsif ($output == $PORT_FORMAT_NODEPORT) {
$self->debug("Converting port to nodeport\n",3);
return map $_->getPCPort()->toTripleString(), @ports;
return map $_->getOtherEndPort()->toTripleString(), @ports;
}
}
......@@ -1364,7 +1364,7 @@ sub listPorts($) {
$portname = $self->{NAME} . ":$modport";
my $port = Port->LookupByTriple($portname);
if (defined($port)) {
$port = $port->getPCPort();
$port = $port->getOtherEndPort();
}
#
......@@ -1422,7 +1422,7 @@ sub getStats() {
my $po = convertPortFromString("$self->{NAME}:$ifindex")
|| convertPortFromString("$self->{NAME}:".$self->{IFINDEX}{$ifindex});
if (! defined $po) { next; } # Skip if we don't know about it
my $port = $po->getPCPort()->toTripleString();
my $port = $po->getOtherEndPort()->toTripleString();
${$stats{$port}}[$i] = $value;
}
......
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