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

Bug Fix: Fix up the code that removes individual ports from vlans

when doing syncVlansFromTables(). I was not looking to see which ports
existed on which devices, and so was calling the device specific
remove for ports that did not exist on the device. Ditto for removing
ports from trunks.

Also a bunch of debugging bits in case there are more problems.
parent e8a7fa5b
......@@ -1049,7 +1049,9 @@ sub opPortVlan($$$@) {
# Make sure the port didn't get mangled in conversion
#
if (!defined $index) {
print STDERR "Port not found, skipping\n";
my $name = $self->{NAME};
print STDERR "Port ($port) not found on $name, skipping\n";
$errors++;
next;
}
......
......@@ -1662,6 +1662,10 @@ sub doVlansFromTables($$@) {
}
my ($stack) = @$stacks;
# $debug = 1;
# $stack->FlipDebug(1);
my @trunkedPorts = getExperimentTrunks($experiment->pid(),
$experiment->eid());
my %trunkedPorts = map { $_ => $_ } @trunkedPorts;
......@@ -1901,11 +1905,15 @@ sub doReset($@) {
# In case of error, do not clear the DB state.
my %notdeleted = ();
$debug = 1;
#
# Just remove the VLAN from every stack on which it exists. We keep a
# list and do them all at once for efficiency.
#
foreach my $stack (@$stacks) {
# $stack->FlipDebug(1);
my @existant_vlans = $stack->existantVlans(@vlans);
if (!$stack->removeVlan(@existant_vlans)) {
#
......@@ -1944,13 +1952,15 @@ sub syncVlansFromTables($$) {
my $errors = 0;
my $vlan_number;
$debug = 1;
if (@$stacks > 1) {
die "VLAN creation across multiple stacks is not yet supported\n" .
"Stacks are " . join(", ",map {$_->{STACKID}} @$stacks) . "\n";
}
my ($stack) = @$stacks;
$debug = 1;
$stack->FlipDebug(1);
my @needTrunking = getExperimentTrunks($pid,$eid);
my %needTrunking = map { $_ => $_ } @needTrunking;
......
......@@ -15,6 +15,7 @@ $| = 1; # Turn off line buffering on output
use English;
use SNMP;
use snmpit_lib;
use Data::Dumper;
use libdb;
use libtestbed;
......@@ -165,6 +166,25 @@ sub Stringify($)
return "[Stack ${stack_id}]";
}
sub FlipDebug($$)
{
my $self = shift;
my $debug = shift;
$self->{'DEBUG'} = $debug;
$snmpit_stack_child::child_debug = $debug;
foreach my $devicename (keys %{$self->{DEVICES}}) {
my $device = $self->{DEVICES}{$devicename};
$device->{'DEBUG'} = $debug;
}
foreach my $device (values(%devices)) {
$device->{'DEBUG'} = $debug;
# print Dumper($device);
}
return 0;
}
#
# List all VLANs on all switches in the stack
#
......@@ -846,6 +866,7 @@ sub removeSomePortsFromVlan($$@) {
warn "ERROR: VLAN $vlan_id not found on switch!";
return 0;
}
my %map = mapPortsToDevices(@ports);
#
# Now, we go through each device and remove all ports from the VLAN
......@@ -855,7 +876,7 @@ sub removeSomePortsFromVlan($$@) {
# first, so the other snmpit will not see it free until it's been
# removed from all switches)
#
foreach my $devicename (sort {tbsort($b,$a)} keys %{$self->{DEVICES}}) {
foreach my $devicename (sort {tbsort($b,$a)} keys %map) {
my $device = $self->{DEVICES}{$devicename};
my %vlan_numbers = $device->findVlans($vlan_id);
......@@ -870,9 +891,9 @@ sub removeSomePortsFromVlan($$@) {
print "Removing ports on $devicename from VLAN $vlan_id ($vlan_number)\n"
if $self->{DEBUG};
$errors += $device->removeSomePortsFromVlan($vlan_number, @ports);
$errors += $device->removeSomePortsFromVlan($vlan_number,
@{$map{$devicename}});
}
return ($errors == 0);
}
......@@ -899,6 +920,7 @@ sub removeSomePortsFromTrunk($$@) {
warn "ERROR: VLAN $vlan_id not found on switch!";
return 0;
}
my %map = mapPortsToDevices(@ports);
#
# Now, we go through each device and remove all ports from the trunk
......@@ -908,7 +930,7 @@ sub removeSomePortsFromTrunk($$@) {
# first, so the other snmpit will not see it free until it's been
# removed from all switches)
#
foreach my $devicename (sort {tbsort($b,$a)} keys %{$self->{DEVICES}}) {
foreach my $devicename (sort {tbsort($b,$a)} keys %map) {
my $device = $self->{DEVICES}{$devicename};
my %vlan_numbers = $device->findVlans($vlan_id);
......@@ -920,10 +942,11 @@ sub removeSomePortsFromTrunk($$@) {
my $vlan_number = $vlan_numbers{$vlan_id};
print "Removing ports on $devicename from VLAN $vlan_id ($vlan_number)\n"
print "Removing trunk ports on $devicename from VLAN ".
"$vlan_id ($vlan_number)\n"
if $self->{DEBUG};
foreach my $port (@ports) {
foreach my $port (@{$map{$devicename}}) {
return 0
if (! $device->setVlansOnTrunk($port, 0, $vlan_number));
}
......
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