Commit c4f7546e authored by Jonathon Duerig's avatar Jonathon Duerig

Update database to allow more flexible vlans on external networks

parent 88e36f79
......@@ -3922,6 +3922,8 @@ sub Lookup($$)
}
my $self = {};
$self->{'DBROW'} = $query_result->fetchrow_hashref();
$self->{'VLANSET'} = {};
$self->CalculateVlans();
bless($self, $class);
return $self;
......@@ -3932,8 +3934,7 @@ sub field($$) { return ((! ref($_[0])) ? -1 : $_[0]->{'DBROW'}->{$_[1]}); }
sub node_id($) { return field($_[0], 'node_id'); }
sub node_type($) { return field($_[0], 'node_type'); }
sub network_id($) { return field($_[0], 'network_id'); }
sub min_vlan($) { return field($_[0], 'min_vlan'); }
sub max_vlan($) { return field($_[0], 'max_vlan'); }
sub vlans($) { return field($_[0], 'vlans'); }
sub mode($) { return field($_[0], 'mode'); }
#
......@@ -3955,8 +3956,29 @@ sub Stringify($)
sub VlanTagOkay($$)
{
my ($self, $tag) = @_;
if (exists($self->{'VLANSET'}->{$tag})) {
return 1;
} else {
return 0;
}
}
return ($tag >= $self->min_vlan() && $tag <= $self->max_vlan() ? 1 : 0);
sub CalculateVlans($)
{
my ($self) = @_;
# vlans is a comma-delimited list
my @vlans = split(",", $self->vlans());
foreach $range (@vlans) {
# Each range is either a single vlan number or min-max inclusive.
my ($min, $max) = split("-", $range);
if (! defined($max)) {
$max = $min;
}
my $i = $min;
for ($i = $min; $i <= $max; $i += 1) {
$self->{'VLANSET'}->{$i} = 1;
}
}
}
# _Always_ make sure that this 1 is at the end of the file...
......
......@@ -2299,11 +2299,11 @@ sub GetTicketAuxAux($$$$$$$$$$)
# Look in the network object to get the limits. This is not an
# efficient way to do this; should put some of this into snmpit.
#
my $mintag = $stitchpath->min_vlan();
my $maxtag = $stitchpath->max_vlan();
my @tags = ();
while (scalar(@tags) < 20 && $mintag < $maxtag) {
my $t = $mintag++;
my @candidates = $stitchpath->vlan_list();
my @tags = ();
my $i = 0;
for ($i = 0; $i < scalar(@candidates) && $i < 20; $i++) {
my $t = $candidates[$i];
push(@tags, $t)
if (VLan->VlanTagAvailable($t));
}
......
......@@ -2042,11 +2042,7 @@ sub ReserveVlanTags($)
#
# Return a list of okay tags.
#
my @okaytags = ();
for (my $i = $stitchpath->min_vlan();
$i < $stitchpath->max_vlan(); $i++) {
push(@okaytags, $i);
}
my @okaytags = $stitchpath->vlan_list();
$response = GeniResponse->Create(GENIRESPONSE_SEARCHFAILED,
\@okaytags,
"Could not find a suitable tag");
......
......@@ -107,30 +107,26 @@ sub hoplist($) { return field($_[0], 'hoplist'); }
sub points($) { return field($_[0], 'points'); }
sub error($) { return field($_[0], 'error'); }
sub min_vlan($)
sub vlan_list($)
{
my ($self) = @_;
my $result = undef;
foreach my $point (@{ $self->points() }) {
my $network = $point->{'network'};
if (! defined($result) || $network->min_vlan() > $result) {
$result = $network->min_vlan();
}
}
return $result;
}
sub max_vlan($)
{
my ($self) = @_;
my $result = undef;
my @candidates = ();
my $first = 1;
foreach my $point (@{ $self->points() }) {
my $network = $point->{'network'};
if (! defined($result) || $network->max_vlan() < $result) {
$result = $network->max_vlan();
if ($first) {
@candidates = keys(%{ $point->{'network'}->{'VLANSET'} });
$first = 0;
} else {
my @newlist = ();
foreach my $can (@candidates) {
if ($point->{'network'}->VlanTagOkay($can)) {
push($can, @newlist);
}
}
@candidates = @newlist;
}
}
return $result;
return @candidates;
}
sub vlan_ok($$)
......
......@@ -1474,13 +1474,12 @@ CREATE TABLE `external_networks` (
`network_id` varchar(32) NOT NULL default '',
`node_id` varchar(32) NOT NULL default '',
`node_type` varchar(30) NOT NULL default '',
`min_vlan` int(11) NOT NULL default '256',
`max_vlan` int(11) NOT NULL default '1000',
`external_manager` tinytext,
`external_interface` tinytext,
`external_wire` tinytext,
`external_subport` tinytext,
`mode` enum('chain','tree') NOT NULL default 'tree',
`vlans` tinytext,
PRIMARY KEY (`network_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
......
#
# Add feature/desire marker flags to blockstore virt and physical type tables.
#
use strict;
use libdb;
my $impotent = 0;
sub DoUpdate($$$)
{
my ($dbhandle, $dbname, $version) = @_;
if (!DBSlotExists("external_networks", "vlans")) {
DBQueryFatal("alter table external_networks add ".
" `vlans` tinytext");
DBQueryFatal("UPDATE external_networks SET vlans=".
"CONCAT(CAST(min_vlan as CHAR), \"-\", ".
"CAST(max_vlan as CHAR))");
DBQueryFatal("alter table external_networks drop `min_vlan`");
DBQueryFatal("alter table external_networks drop `max_vlan`");
}
return 0;
}
# Local Variables:
# mode:perl
# End:
......@@ -388,7 +388,7 @@ my %stitch_points;
$result = DBQueryFatal("select w.node_id1, w.card1, w.port1, i1.iface, ".
"w.node_id2, w.card2, w.port2, i2.iface, ".
"w.external_interface, w.external_wire, ".
"e.node_id, e.min_vlan, e.max_vlan, ".
"e.node_id, ".
"e.external_manager, e.network_id, e.external_interface, e.external_wire ".
"from wires as w ".
"left join external_networks as e ".
......@@ -397,8 +397,8 @@ $result = DBQueryFatal("select w.node_id1, w.card1, w.port1, i1.iface, ".
"left join interfaces as i2 on w.node_id2=i2.node_id and w.card2=i2.card and w.port2=i2.port ".
"where e.node_id is not null");
while (my ($cnode, $ccard, $cport, $ciface, $enode, $ecard, $eport, $eiface,
$external_iface_urn, $external_link_urn, $external, $minLan,
$maxLan, $external_manager_urn,
$external_iface_urn, $external_link_urn, $external, $vlanList,
$external_manager_urn,
$external_network_id, $external_network_iface_urn,
$external_network_link_urn) = $result->fetchrow_array) {
if ($external eq $cnode) {
......@@ -422,7 +422,7 @@ while (my ($cnode, $ccard, $cport, $ciface, $enode, $ecard, $eport, $eiface,
if (! defined($external_link_urn)) {
$external_link_urn = $external_network_link_urn;
}
$external_nodes{$enode} = "$minLan-$maxLan";
$external_nodes{$enode} = $vlanList;
$external_managers{"$cnode:$enode"} = $external_manager_urn;
$external_ifaces{"$cnode:$enode"} = $external_iface_urn;
$external_links{"$cnode:$enode"} = $external_link_urn;
......
......@@ -31,7 +31,7 @@ use File::Temp qw(tempfile);
#
sub usage()
{
print STDERR "Usage: addexternalnetwork [-d] [-n] [-w external_wire_urn] [-i external_interface_urn] [-t vm-type] <network_id> <node_id> <external_manager> <minvlan>-<maxvlan>\n";
print STDERR "Usage: addexternalnetwork [-d] [-n] [-w external_wire_urn] [-i external_interface_urn] [-t vm-type] <network_id> <node_id> <external_manager> <vlan-vlan[,vlan-vlan]*>\n";
print STDERR "Options:\n";
print STDERR " -d - Turn on debugging\n";
print STDERR " -n - Dry run mode\n";
......@@ -44,8 +44,6 @@ my $network;
my $node_id;
my $external;
my $vlans;
my $minvlan;
my $maxvlan;
my $wire;
my $iface;
my $vmtype;
......@@ -110,9 +108,7 @@ usage()
($network, $node_id, $external, $vlans) = @ARGV;
if ($vlans =~ /([0-9]+)-([0-9]+)/) {
$minvlan = $1;
$maxvlan = $2;
if ($vlans =~ /([0-9,\-]+)/) {
} else {
usage();
}
......@@ -153,11 +149,10 @@ $network = DBQuoteSpecial($network);
$node_id = DBQuoteSpecial($node_id);
$type = DBQuoteSpecial($type);
$external = DBQuoteSpecial($external);
$minvlan = DBQuoteSpecial($minvlan);
$maxvlan = DBQuoteSpecial($maxvlan);
$vlans = DBQuoteSpecial($vlans);
my $query = "REPLACE INTO external_networks SET node_id=$node_id, ".
"node_type=$type, min_vlan=$minvlan, max_vlan=$maxvlan, ".
"node_type=$type, vlans=$vlans, ".
"external_manager=$external, network_id=$network";
if (defined($wire)) {
$wire = DBQuoteSpecial($wire);
......
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