Commit a8231a6a authored by Leigh B Stoller's avatar Leigh B Stoller
Browse files

Fixes to deal with stale vlans in syncVlansFromTables(); need to look

at the current experiment vlans/ports.
parent 4d242822
......@@ -35,7 +35,7 @@ use Exporter;
getExperimentVlanPorts
uniq isSwitchPort getPathVlanIfaces
reserveVlanTag getReservedVlanTag clearReservedVlanTag
mapVlansToSwitches
mapVlansToSwitches mapStaleVlansToSwitches
);
use English;
......@@ -1120,49 +1120,85 @@ 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);
my @ports = uniq(getVlanPorts($vlan_id),
getExperimentVlanPorts($vlan_id));
my @devices = mapPortsToSwitches(@ports);
foreach my $device (keys %map) {
$devices{$device} = 1;
# And update the total set of switches.
foreach my $device (@devices) {
$switches{$device} = 1;
}
}
my @sorted = sort {tbsort($a,$b)} keys %switches;
print "mapVlansToSwitches: @sorted\n";
return @sorted;
}
#
# An alternate version for a "stale" vlan; one that is destroyed cause of
# a swapmod (syncVlansFromTables).
#
sub mapStaleVlansToSwitches(@)
{
my @vlan_ids = @_;
my %switches = ();
foreach my $vlan_id (@vlan_ids) {
#
# Add in the ports that we think are already in the vlan, since
# Get the ports that we think are already in the vlan, since
# this might be a remove/modify operation. Can probably optimize
# this.
#
@ports = getExperimentVlanPorts($vlan_id);
%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;
}
my @ports = getExperimentVlanPorts($vlan_id);
my @devices = mapPortsToSwitches(@ports);
# And update the total set of switches.
foreach my $device (keys(%devices)) {
foreach my $device (@devices) {
$switches{$device} = 1;
}
}
my @sorted = sort {tbsort($a,$b)} keys %switches;
print "mapVlansToSwitches: @sorted\n";
print "mapStaleVlansToSwitches: @sorted\n";
return @sorted;
}
#
# Map a set of ports to the devices they are on plus the trunks.
# See above.
#
sub mapPortsToSwitches(@)
{
my @ports = @_;
my %switches = ();
my %trunks = getTrunks();
my %map = mapPortsToDevices(@ports);
my %devices = ();
foreach my $device (keys %map) {
$devices{$device} = 1;
}
#
# This code is lifted from setPortVlan() in snmpit_stack.pm
#
# Find 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;
return @sorted;
}
......
......@@ -814,20 +814,13 @@ COMMAND: foreach my $command (@commands) {
my @newvlans = getExperimentVlans($pid,$eid,@optvlanids);
my @oldvlans;
VLan->StaleVlanList($experiment,\@oldvlans);
@vlans = uniq(@newvlans, @oldvlans);
if ($supplied_switches) {
debug("Sync: using supplied switches\n");
@devicenames = @supplied_switches;
@vlans = filterVlansBySwitches(\@supplied_switches, @vlans);
if (!@vlans) {
print "snmpit: $pid/$eid has no VLANs to sync ".
"on supplied devices, skipping\n"
if (!$quiet);
next COMMAND;
}
} else {
@devicenames = mapVlansToSwitches(@vlans);
die("-X and -i cannot be used together\n");
}
else {
@devicenames = uniq(mapVlansToSwitches(@newvlans),
mapStaleVlansToSwitches(@oldvlans));
debug("Sync: list from database: " . join(",",@devicenames) .
"\n");
}
......
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