Commit 72c9008f authored by Leigh B Stoller's avatar Leigh B Stoller
Browse files

Rework the vlan tag reservation code quite a bit.

parent 259c9475
......@@ -497,7 +497,8 @@ sub CompareVlansWithSwitches($$$)
# This is bad; if one of these updates fails, we are screwed.
#
foreach my $table ("lans", "lan_attributes", "lan_members",
"lan_member_attributes", "ifaces") {
"lan_member_attributes", "ifaces",
"reserved_vlantags") {
DBQueryWarn("update $table set lanid=$oldid ".
"where lanid='$newid'")
or return -1;
......@@ -557,7 +558,8 @@ sub CompareVlansWithSwitches2($$)
# This is bad; if one of these updates fails, we are screwed.
#
foreach my $table ("lans", "lan_attributes", "lan_members",
"lan_member_attributes", "ifaces") {
"lan_member_attributes", "ifaces",
"reserved_vlantags") {
DBQueryWarn("update $table set lanid=$oldid ".
"where lanid='$newid'")
or return -1;
......@@ -1786,6 +1788,27 @@ sub Instantiate($)
}
}
#
# Check to see if there is an entry in reserved_vlantags table.
# If so, use that lanid instead of generating a new one. This is
# mostly for the benefit of ProtoGeni stitching, but is also handy
# for swapmod so we can reuse existing vlan tags and lanids.
#
if (!defined($idx)) {
my $exptidx = $experiment->idx();
my $query_result =
DBQueryWarn("select lanid from reserved_vlantags ".
"where exptidx='$exptidx' and vname='$vname'");
return -1
if (!defined($query_result));
if ($query_result->numrows) {
($idx) = $query_result->fetchrow_array();
}
}
# The new lan has the 'ready' bit set to zero.
my $lan = Lan->Create($experiment, $vname, $type, $idx, $link);
return -1
......@@ -2489,48 +2512,136 @@ sub GetClass($)
return "Experimental";
}
# VLan reservation.
sub ReserveVlanTag($$)
# VLan reservation for a specific lan in an experiment.
sub ReserveVlanTag($$;$)
{
my ($self, $tag) = @_;
my ($self, $tag, $checkonly) = @_;
my $lanid = $self->lanid();
my $vname = $self->vname();
my $pid = $self->pid();
my $eid = $self->eid();
my $exptidx = $self->exptidx();
$checkonly = 0 if (!defined($checkonly));
DBQueryWarn("lock tables lans write, lan_attributes write")
DBQueryWarn("lock tables lan_attributes write, lans write, ".
" reserved_vlantags write, vlans read")
or return undef;
#
# Use global table for all reservations.
#
my $query_result =
DBQueryWarn("select attrvalue from lan_attributes ".
"where attrkey='reservedvlantag' and attrvalue='$tag'");
DBQueryWarn("select lanid from reserved_vlantags where tag='$tag'");
$tag = undef
if (!$query_result || $query_result->numrows ||
$self->SetAttribute("reservedvlantag", $tag) != 0);
goto inuse
if (!$query_result || $query_result->numrows);
#
# But because of swapmod and syncvlansfromtables, must also check
# the vlans table since that is what is currently on the switches.
#
$query_result =
DBQueryWarn("select id from vlans where tag='$tag'");
goto inuse
if (!$query_result || $query_result->numrows);
# Just checking ...
goto isfree
if ($checkonly);
goto inuse
if (!DBQueryWarn("insert into reserved_vlantags set ".
" lanid='$lanid', tag='$tag', vname='$vname', ".
" pid='$pid', eid='$eid', exptidx='$exptidx', ".
" reserve_time=now()"));
isfree:
DBQueryWarn("unlock tables");
return $tag;
inuse:
DBQueryWarn("unlock tables");
return undef;
}
sub ClearReservedVlanTag($)
# Both a class and an instance method.
sub ClearReservedVlanTag($;$)
{
my ($self) = @_;
my $lanid = $self->lanid();
my ($arg, $tag) = @_;
my $lanid = (ref($arg) ? $arg->lanid() : $arg);
my $clause = (defined($tag) ? "and tag='$tag'" : "");
DBQueryWarn("delete from lan_attributes ".
"where attrkey='reservedvlantag' and lanid='$lanid'")
DBQueryWarn("delete from reserved_vlantags where lanid='$lanid' $clause")
or return -1;
return 0;
}
sub GetReservedVlanTags($)
{
my ($self) = @_;
my $lanid = $self->lanid();
my @result = ();
my $query_result =
DBQueryWarn("select tag from reserved_vlantags ".
"where lanid='$lanid'");
return ()
if (!$query_result || !$query_result->numrows);
while (my ($tag) = $query_result->fetchrow_array()) {
push(@result, $tag);
}
return @result;
}
sub GetReservedVlanTag($)
{
my ($self) = @_;
my $tag;
my $lanid = $self->lanid();
return undef
if ($self->GetAttribute("reservedvlantag",\$tag) != 0);
my $query_result =
DBQueryWarn("select tag from reserved_vlantags ".
"where lanid='$lanid'");
return undef
if (!$query_result || !$query_result->numrows);
my ($tag) = $query_result->fetchrow_array();
return $tag;
}
sub HasVlanTagReserved($$)
{
my ($arg, $tag) = @_;
my $lanid = (ref($arg) ? $arg->lanid() : $arg);
my $query_result =
DBQueryWarn("select tag from reserved_vlantags ".
"where lanid='$lanid' and tag='$tag'");
return 0
if (!$query_result);
return $query_result->numrows;
}
sub VlanTagAvailable($$)
{
my ($class, $tag) = @_;
my $query_result =
DBQueryWarn("select tag from reserved_vlantags where tag='$tag'");
return 0
if (!$query_result || $query_result->numrows);
$query_result =
DBQueryWarn("select id from vlans where tag='$tag'");
return 0
if (!$query_result || $query_result->numrows);
return 1;
}
# Find out which stack a VLAN resides on
......@@ -2590,7 +2701,7 @@ sub IsManual($)
#
# Check to see if we think the VLAN actually exists on any switches at the
# moment (ie. has a vlans table entry)
# moment (ie. has a vlans table entry).
#
sub CreatedOnSwitches() {
my ($self) = @_;
......
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