Commit c1bb91ff authored by Robert Ricci's avatar Robert Ricci
Browse files

Make the process of getting ifIndexes for EhterChannels more robust.

This seems to be necesary because of what I can only describe as a
bug in CatOS in which not ll ports in a trunk return the proper channel
grou number.
parent 01d47132
......@@ -1368,18 +1368,60 @@ sub getStats ($) {
}
#
# Get the ifindex for an EtherChannel (trunk given as a list of ports)
#
# usage: getChannelIfIndex(self, ports)
# Returns: undef if more than one port is given, and no channel is found
# an ifindex if a channel is found and/or only one port is given
#
#
sub getChannelIfIndex($@) {
my $self = shift;
my @ports = @_;
my @ifIndexes = $self->convertPortFormat($PORT_FORMAT_IFINDEX,@ports);
my $ifindex = undef;
#
# Try to get a channel number for each one of the ports in turn - we'll
# take the first one we get
#
foreach my $port (@ifIndexes) {
my $channel = snmpitGetFatal($self->{SESS},["pagpGroupIfIndex",$port]);
if (($channel =~ /^\d+$/) && ($channel != 0)) {
$ifindex = $channel;
last;
}
}
#
# If we didn't get a channel number, and we were only given a single port,
# we can return the ifIndex for that port. Note that we tried to get a
# channel number first, in case someone did something silly like give us a
# single port channel.
#
if (!$ifindex) {
if (@ifIndexes == 1) {
$ifindex = $ifIndexes[0];
}
}
return $ifindex;
}
#
# Enable, or disable, port on a trunk
#
# usage: setVlansOnTrunk(self, modport, value, vlan_numbers)
# modport: module.port of the trunk to operate on
# usage: setVlansOnTrunk(self, ifindex, value, vlan_numbers)
# ifindex: ifindex of the trunk to operate on
# value: 0 to disallow the VLAN on the trunk, 1 to allow it
# vlan_numbers: An array of cisco-native VLAN numbers operate on
# Returns 1 on success, 0 otherwise
#
sub setVlansOnTrunk($$$$) {
my $self = shift;
my ($modport, $value, @vlan_numbers) = @_;
my ($port, $value, @vlan_numbers) = @_;
#
# Some error checking
......@@ -1391,23 +1433,7 @@ sub setVlansOnTrunk($$$$) {
die "VLAN 1 passed to setVlanOnTrunk\n"
}
my ($ifIndex) = $self->convertPortFormat($PORT_FORMAT_IFINDEX,$modport);
#
# If this is part of an EtherChannel, we have to find the ifIndex for the
# channel.
# TODO: Perhaps this should be general - ie. $self{IFINDEX} should have
# the channel ifIndex the the port is in a channel. Not sure that
# this is _always_ beneficial, though
#
my $channel = snmpitGetFatal($self->{SESS},["pagpGroupIfIndex",$ifIndex]);
if (!($channel =~ /^\d+$/) || ($channel == 0)) {
print "WARNING: setVlansOnTrunk got zero channel for $self->{NAME}.$modport\n";
return 0;
}
if (($channel =~ /^\d+$/) && ($channel != 0)) {
$ifIndex = $channel;
}
my ($ifIndex) = $self->convertPortFormat($PORT_FORMAT_IFINDEX,$port);
#
# Get the exisisting bitfield for allowed VLANs on the trunk
......
......@@ -835,42 +835,40 @@ sub setVlanOnTrunks($$$;@) {
warn "ERROR - Bad device $src found in setVlanOnTrunks!\n";
$errors++;
} else {
my $found = 0;
#
# On ciscos, we can use any port in the trunk, so we'll use the
# first
# Trunks might be EtherChannels, find the ifIndex
#
foreach my $modport (@{ $trunks{$src}{$dst} }) {
if ($self->{DEVICES}{$src}->
setVlansOnTrunk($modport,$value,$vlan_number)) {
$found = 1;
last;
}
}
if (!$found) {
$errors += 1;
my $trunkIndex = $self->{DEVICES}{$src}->
getChannelIfIndex(@{ $trunks{$src}{$dst} });
if (!defined($trunkIndex)) {
warn "ERROR - unable to find channel information for $src\n";
$errors += 1;
} else {
if (!$self->{DEVICES}{$src}->
setVlansOnTrunk($trunkIndex,$value,$vlan_number)) {
warn "ERROR - unable to set trunk on swich $src\n";
$errors += 1;
}
}
}
if (!$self->{DEVICES}{$dst}) {
warn "ERROR - Bad device $dst found in setVlanOnTrunks!\n";
$errors++;
} else {
my $found = 0;
#
# On ciscos, we can use any port in the trunk, so we'll use the
# first
# Trunks might be EtherChannels, find the ifIndex
#
foreach my $modport (@{ $trunks{$dst}{$src} }) {
if ($self->{DEVICES}{$dst}->
setVlansOnTrunk($modport,$value,$vlan_number)) {
$found = 1;
last;
}
}
if (!$found) {
$errors += 1;
my $trunkIndex = $self->{DEVICES}{$dst}->
getChannelIfIndex(@{ $trunks{$dst}{$src} });
if (!defined($trunkIndex)) {
warn "ERROR - unable to find channel information for $dst\n";
$errors += 1;
} else {
if (!$self->{DEVICES}{$dst}->
setVlansOnTrunk($trunkIndex,$value,$vlan_number)) {
warn "ERROR - unable to set trunk on swich $dst\n";
$errors += 1;
}
}
}
}
......
Supports Markdown
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