Commit afb28fde authored by Robert Ricci's avatar Robert Ricci

Actually call the code to pick which VLANs are allowed on which trunk.

When dealing with trunks, since they may be EtherChannels, we have to
make another lookup on the switch to get the ifIndex for the whole
channel - can't just use the ifIndex of one of the ports like you
can from the Cisco CLI.

These changes make snmpit slightly slower - it now has to get more information
from the switches when it's going to create or delete VLANs. However, this
is on the order of fractions of seconds, so it shouldn't be too noticable.
parent 2fe293d2
......@@ -89,7 +89,8 @@ sub new($$;$) {
&SNMP::addMibDirs($mibpath);
&SNMP::addMibFiles("$mibpath/CISCO-STACK-MIB.txt",
"$mibpath/CISCO-VTP-MIB.txt",
"$mibpath/CISCO-VLAN-MEMBERSHIP-MIB.txt");
"$mibpath/CISCO-VLAN-MEMBERSHIP-MIB.txt",
"$mibpath/CISCO-PAGP-MIB.txt");
$SNMP::save_descriptions = 1; # must be set prior to mib initialization
SNMP::initMib(); # parses default list of Mib modules
......@@ -948,6 +949,18 @@ sub setVlanOnTrunk($$$$) {
my $ifIndex = $self->{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 = $self->{SESS}->get(["pagpGroupIfIndex",$ifIndex]);
if (($channel =~ /^\d+$/) && ($channel != 0)) {
$ifIndex = $channel;
}
#
# Get the exisisting bitfield for allowed VLANs on the trunk
#
......@@ -962,11 +975,13 @@ sub setVlanOnTrunk($$$$) {
# Pack it back up...
$unpacked = join('',@bits);
$bitfield = pack("B*",$unpacked);
# And save it back...
if (!$self->{SESS}->set(["vlanTrunkPortVlansEnabled",$ifIndex,$bitfield,
"OCTETSTR"])) {
my $rv = $self->{SESS}->set(["vlanTrunkPortVlansEnabled",$ifIndex,$bitfield,
"OCTETSTR"]);
if ($rv) {
return 1;
} else {
return 0;
......
......@@ -226,6 +226,11 @@ sub setPortVlan($$@) {
$errors += $device->setPortVlan($vlan_id,@{$map{$devicename}});
}
if ($vlan_id ne 'default') {
my $vlan_number = $self->{LEADER}->findVlan($vlan_id);
$errors += (!$self->setVlanOnTrunks($vlan_number,1));
}
return $errors;
}
......@@ -335,6 +340,16 @@ sub removeVlan($$) {
return 0;
}
#
# Prevent the VLAN from being sent across trunks.
#
if (!$self->setVlanOnTrunks($vlan_number,0)) {
warn "ERROR: Unable to set up VLANs on trunks!\n";
#
# We can keep going, 'cause we can still remove the VLAN
#
}
#
# Now, we go through each device and remove all ports from the VLAN
# on that device
......@@ -402,7 +417,7 @@ sub getStats($) {
# this file, not external functions.
#
# Enables or disables (depending on $value) a VLAN on all appropriate
# switches in a stack
# switches in a stack. Returns 1 on sucess, 0 on failure.
#
# ONLY pass in @ports if you're SURE that they are the only ports in the
# VLAN - basically, only if you just created it. This is a shortcut, so
......@@ -487,7 +502,7 @@ sub setVlanOnTrunks($$$;@) {
}
}
return $errors;
return (!$errors);
}
# End with true
......
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