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

Bug fix for handling shared vlans and trunked ports.

The code to determine what ports need to be trunked or untrunked was
blindly picking all ports for the experiment, instead of restricting
them to those in the vlans being operated on. The result was a missing
device from the stack.
parent fd839f77
......@@ -315,13 +315,16 @@ sub getVlanPorts (@) {
}
my @ports = ();
foreach my $vlanid (@vlans) {
my $vlan = VLan->Lookup($vlanid);
if (!defined($vlan)) {
foreach my $vlanid (@vlans) {
my $vlan = $vlanid;
if (!ref($vlan)) {
$vlan = VLan->Lookup($vlanid);
if (!defined($vlan)) {
die("*** $0:\n".
" No vlanid $vlanid in the DB!\n");
}
}
}
my @members;
if ($vlan->MemberList(\@members) != 0) {
die("*** $0:\n".
......@@ -351,19 +354,22 @@ sub getVlanPorts (@) {
# Returns an an array of trunked ports (in node:card form) used by an
# experiment
#
sub getExperimentTrunks($$) {
my ($pid, $eid) = @_;
my @ports;
my $query_result =
DBQueryFatal("select distinct r.node_id,i.iface from reserved as r " .
"left join interfaces as i on i.node_id=r.node_id " .
"where r.pid='$pid' and r.eid='$eid' and " .
" i.trunk!=0");
sub getExperimentTrunks($$@) {
my ($pid, $eid, @vlans) = @_;
my @ports = ();
while (my ($node, $iface) = $query_result->fetchrow()) {
$node = Port->LookupByIface($node, $iface);
push @ports, $node;
#
# We want to restrict the set of ports to just those in the
# provided vlans, lest we get into a problem with a missing
# device from the stack. This became necessary after adding
# shared vlans, since those ports technically belong to the
# current experiment, but are setup in the context of a
# different experiment. Needs more thought though.
#
my @vlanports = getVlanPorts(@vlans);
foreach my $port (@vlanports) {
push(@ports, $port)
if ($port->trunk());
}
return @ports;
}
......@@ -373,9 +379,23 @@ sub getExperimentTrunks($$) {
# experiment. These are the ports that are actually in trunk mode,
# rather then the ports we want to be in trunk mode (above function).
#
sub getExperimentCurrentTrunks($$) {
my ($pid, $eid) = @_;
my @ports;
sub getExperimentCurrentTrunks($$@) {
my ($pid, $eid, @vlans) = @_;
my @ports = ();
#
# We want to restrict the set of ports to just those in the
# provided vlans, lest we get into a problem with a missing
# device from the stack. This became necessary after adding
# shared vlans, since those ports technically belong to the
# current experiment, but are setup in the context of a
# different experiment. Needs more thought though.
#
my @vlanports = getVlanPorts(@vlans);
my %vlanports = ();
foreach my $port (@vlanports) {
$vlanports{$port->toIfaceString()} = $port;
}
my $query_result =
DBQueryFatal("select distinct r.node_id,i.iface from reserved as r " .
......@@ -384,8 +404,9 @@ sub getExperimentCurrentTrunks($$) {
" i.tagged!=0");
while (my ($node, $iface) = $query_result->fetchrow()) {
$node = Port->LookupByIface($node, $iface);
push @ports, $node;
if (exists($vlanports{"$node:$iface"})) {
push(@ports, $vlanports{"$node:$iface"});
}
}
return @ports;
}
......
......@@ -1833,7 +1833,7 @@ sub doVlansFromTables($$@) {
# $stack->FlipDebug(1);
my @trunkedPorts = getExperimentTrunks($experiment->pid(),
$experiment->eid());
$experiment->eid(), @vlanids);
my %trunkedPorts = map { $_->toString() => $_ } @trunkedPorts;
#
......@@ -2084,7 +2084,7 @@ sub doReset($@) {
}
my $errors = 0;
my @trunkedPorts = getExperimentTrunks($pid,$eid);
my @trunkedPorts = getExperimentTrunks($pid, $eid, @vlans);
foreach my $port (@trunkedPorts) {
$errors += doTrunkDisable($stacks,$port);
}
......@@ -2193,11 +2193,6 @@ sub syncVlansFromTables($$) {
$debug = 1;
$stack->FlipDebug(1);
my @needTrunking = getExperimentTrunks($pid,$eid);
my %needTrunking = map { $_->toString() => $_ } @needTrunking;
debug("Trunk Ports: ".Port->toStrings(@needTrunking)."\n");
#
# Get list of vlans that should exist.
#
......@@ -2209,6 +2204,13 @@ sub syncVlansFromTables($$) {
}
debug("Experiment vlans: " . join(" ", keys(%expvlans)) . "\n");;
#
# List of trunks for the above set of vlans.
#
my @needTrunking = getExperimentTrunks($pid, $eid, @tmp);
my %needTrunking = map { $_->toString() => $_ } @needTrunking;
debug("Trunk Ports: ".Port->toStrings(@needTrunking)."\n");
#
# Get list of vlans that we think are on the switch (vlans table).
#
......@@ -2228,7 +2230,7 @@ sub syncVlansFromTables($$) {
#
# Get a list of interfaces that are currently trunked.
#
my @currentTrunks = getExperimentCurrentTrunks($pid,$eid);
my @currentTrunks = getExperimentCurrentTrunks($pid, $eid, @tmp);
my %currentTrunks = map { $_->toString() => $_ } @currentTrunks;
#
......
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