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

Fix a bug I introduced a couple of months ago that was causing

swapmod to leave behind vlans on the switch. As a side effect,
add a "class" field to the vlans table so that we can determine if a
stale vlan is a control or experimental vlan (since we now support
building experimental vlans on the control stack, so the stack no
longer tells us what kind of vlan it is).
parent 3825b20d
...@@ -2047,8 +2047,12 @@ sub Instantiate($) ...@@ -2047,8 +2047,12 @@ sub Instantiate($)
return -1; return -1;
} }
} }
# These are always class=Experiment. #
if (exists($self->{"ATTRS"}->{'class'})) { # These are always class=Experimental if not specified. Note that
# we support experimental vlans on the control network via trunk
# links. Thus the stack and the class can actually be different.
#
if (! exists($self->{"ATTRS"}->{'class'})) {
if ($lan->SetAttribute("class", "Experimental")) { if ($lan->SetAttribute("class", "Experimental")) {
$lan->Destroy(); $lan->Destroy();
return -1; return -1;
...@@ -3361,7 +3365,6 @@ sub UnInstantiate($;$) ...@@ -3361,7 +3365,6 @@ sub UnInstantiate($;$)
my $vname = $self->vname(); my $vname = $self->vname();
my $lanid = $self->lanid(); my $lanid = $self->lanid();
my $opt = ($quiet ? "-q" : ""); my $opt = ($quiet ? "-q" : "");
my $class = $self->GetClass();
#print "Removing VLAN $vname ($lanid) from $pid/$eid\n"; #print "Removing VLAN $vname ($lanid) from $pid/$eid\n";
system("$SNMPIT $opt -r $pid $eid $lanid"); system("$SNMPIT $opt -r $pid $eid $lanid");
...@@ -3389,6 +3392,7 @@ sub RecordVlanInsertion($$$) ...@@ -3389,6 +3392,7 @@ sub RecordVlanInsertion($$$)
my $exptidx = $vlan->exptidx(); my $exptidx = $vlan->exptidx();
my $lanid = $vlan->lanid(); my $lanid = $vlan->lanid();
my $vname = $vlan->vname(); my $vname = $vlan->vname();
my $vclass = $vlan->GetClass();
my $tag = $vlan->GetReservedVlanTag(); my $tag = $vlan->GetReservedVlanTag();
return -1 return -1
if (!defined($tag)); if (!defined($tag));
...@@ -3408,7 +3412,7 @@ sub RecordVlanInsertion($$$) ...@@ -3408,7 +3412,7 @@ sub RecordVlanInsertion($$$)
DBQueryWarn("replace into vlans set ". DBQueryWarn("replace into vlans set ".
" id='$lanid', pid='$pid', eid='$eid', exptidx='$exptidx', ". " id='$lanid', pid='$pid', eid='$eid', exptidx='$exptidx', ".
" virtual='$vname', members='$members', tag='$tag', ". " virtual='$vname', members='$members', tag='$tag', ".
" stack='$stack' $path") " stack='$stack', class='$vclass' $path")
or return -1; or return -1;
return 0; return 0;
...@@ -3569,10 +3573,7 @@ sub StaleVlanList($$$) ...@@ -3569,10 +3573,7 @@ sub StaleVlanList($$$)
# tells, we need to look at the "class" of the lan. # tells, we need to look at the "class" of the lan.
# #
my $query_result = my $query_result =
DBQueryWarn("select v.id,a.attrvalue from vlans as v ". DBQueryWarn("select id,class from vlans where exptidx=$exptidx");
"left join lan_attributes as a on a.lanid=v.id and ".
" a.attrkey='class' ".
"where v.exptidx=$exptidx");
return -1 return -1
if (!$query_result); if (!$query_result);
...@@ -3580,7 +3581,7 @@ sub StaleVlanList($$$) ...@@ -3580,7 +3581,7 @@ sub StaleVlanList($$$)
# No class means Experimental; we were not setting this properly # No class means Experimental; we were not setting this properly
# for a long time. # for a long time.
push(@result, $id) push(@result, $id)
if (!defined($class) || $class eq "Experimental"); if (!defined($class) || $class eq "" || $class eq "Experimental");
} }
@$pref = @result; @$pref = @result;
return 0; return 0;
......
...@@ -4940,6 +4940,7 @@ CREATE TABLE `vlans` ( ...@@ -4940,6 +4940,7 @@ CREATE TABLE `vlans` (
`id` int(11) NOT NULL auto_increment, `id` int(11) NOT NULL auto_increment,
`tag` smallint(5) NOT NULL default '0', `tag` smallint(5) NOT NULL default '0',
`stack` varchar(32) default NULL, `stack` varchar(32) default NULL,
`class` varchar(32) default NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `pid` (`pid`,`eid`,`virtual`), KEY `pid` (`pid`,`eid`,`virtual`),
KEY `exptidx` (`exptidx`,`virtual`) KEY `exptidx` (`exptidx`,`virtual`)
......
#
# Add class to vlans. Note that we now support experimental vlans on
# the control network via trunk links. Thus the stack and the class
# can actually be different. But we need to store this in the vlans
# table cause of swapmod and syncvlansfromtables, since there might
# not be a lans table entry if the lan is stale and needs to be
# destroyed. We can probably get by without this, but I like having
# it be explicit when looking at the vlans table, and since the table
# is not tha big, the extra slot is no big deal.
#
use strict;
use libdb;
sub DoUpdate($$$)
{
my ($dbhandle, $dbname, $version) = @_;
if (!DBSlotExists("vlans", "class")) {
DBQueryFatal("alter table vlans add ".
" `class` varchar(32) default NULL");
}
return 0;
}
1;
# Local Variables:
# mode:perl
# End:
...@@ -2306,9 +2306,15 @@ sub syncVlansFromTables($$@) { ...@@ -2306,9 +2306,15 @@ sub syncVlansFromTables($$@) {
VLan->StaleVlanList($experiment, \@tmp) == 0 or VLan->StaleVlanList($experiment, \@tmp) == 0 or
die("Could not get stale vlans for $experiment\n"); die("Could not get stale vlans for $experiment\n");
foreach my $vlanid (@tmp) { foreach my $vlanid (@tmp) {
# Narrow to provided vlanids. #
# Narrow to vlans that came in on the command line, not
# the ones sent to this function. When a specific vlan is
# provided on the command line, we consider only that one as
# potentially stale. If no vlans on the command line, then all
# vlans in the experiment are potentially stale.
#
next next
if (@vlanids && ! grep {$_ == $vlanid} @vlanids); if (@optvlanids && ! grep {$_ == $vlanid} @optvlanids);
$curvlans{$vlanid} = 1; $curvlans{$vlanid} = 1;
......
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