Commit 558dc84b authored by Leigh B Stoller's avatar Leigh B Stoller
Browse files

Add new routine called mapVlansToSwitches() which is used before

creating the stack object, to ensure that the only devices used are
the one that are needed (ports plus trunks). This will prevent the
stack module from accessing switches it does not need.
parent 6e006b3f
......@@ -35,6 +35,7 @@ use Exporter;
getExperimentVlanPorts
uniq isSwitchPort getPathVlanIfaces
reserveVlanTag getReservedVlanTag clearReservedVlanTag
mapVlansToSwitches
);
use English;
......@@ -1124,6 +1125,50 @@ sub getTrunkPath($$$$) {
}
}
#
# Given a set of vlans, determine *exactly* what devices are needed
# for the ports and any trunks that need to be crossed. This is done
# in the stack module, but really want to do this before the stack
# is created so that we do not add extra devices if not needed.
#
sub mapVlansToSwitches(@)
{
my @vlan_ids = @_;
my %switches = ();
my %trunks = getTrunks();
#
# This code is lifted from setPortVlan() in snmpit_stack.pm
#
foreach my $vlan_id (@vlan_ids) {
my %devices = ();
my @ports = getVlanPorts($vlan_id);
my %map = mapPortsToDevices(@ports);
foreach my $device (keys %map) {
$devices{$device} = 1;
}
#
# Find out every switch which might have to transit this VLAN through
# its trunks.
#
my @trunks = getTrunksFromSwitches(\%trunks, keys %devices);
foreach my $trunk (@trunks) {
my ($src,$dst) = @$trunk;
$devices{$src} = $devices{$dst} = 1;
}
# And update the total set of switches.
foreach my $device (keys(%devices)) {
$switches{$device} = 1;
}
}
my @sorted = sort {tbsort($a,$b)} keys %switches;
print "mapVlansToSwitches: @sorted\n";
return @sorted;
}
#
# Returns a list of trunks, in the form [src, dest], from a path (as returned
# by getTrunkPath() ). For example, if the input is:
......
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