Commit 603d3489 authored by Jonathon Duerig's avatar Jonathon Duerig

Fix up stitching to allow available vlans in rspec as a restriction range.

parent 02ad17db
......@@ -3941,6 +3941,7 @@ use libdb;
use libtestbed;
use English;
use Lan;
use String::Util 'trim';
use overload ('""' => 'Stringify');
#
......@@ -4040,22 +4041,66 @@ sub VlanTagOkay($$)
}
}
sub VlanToSet($$)
{
my ($self, $vlanString) = @_;
my %result = ();
if ($vlanString =~ /(([0-9]+)(-[0-9]+)?)+/) {
# vlans is a comma-delimited list
my @vlans = split(",", $vlanString);
foreach my $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) {
%result{$i} = 1;
}
}
}
return %result;
}
sub CalculateVlans($)
{
my ($self) = @_;
$self->{'VLANSET'} = $($self->VlanToSet($self->vlans()));
# vlans is a comma-delimited list
my @vlans = split(",", $self->vlans());
foreach my $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;
# my @vlans = split(",", $self->vlans());
# foreach my $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;
# }
# }
}
# Return a list of vlans from the VLANSET, but only those which are
# also included in the restrictionString
sub GetRestrictedVlans($$)
{
my ($self, $restrictionString) = @_;
$restrictionString = trim($restrictionString);
my %result = ();
if ($restrictionString eq "" || $restrictionString eq "any") {
%result = %{ $self->{'VLANSET'} };
} else {
my %restriction = $self->VlanToSet($restrictionString);
foreach my $candidate (keys(%{ $self->{'VLANSET'} })) {
if (%restriction{$candidate}) {
$result{$candidate} = 1;
}
}
}
return %result;
}
# Return the list calculated above.
......
......@@ -114,7 +114,8 @@ sub vlan_list($)
my $first = 1;
foreach my $point (@{ $self->points() }) {
if ($first) {
@candidates = keys(%{ $point->{'network'}->{'VLANSET'} });
my $available = GeniXML::GetAvailableVlanFromHop($point->{'internal_hop'});
@candidates = keys($point->{'network'}->GetRestrictedVlans(available));
$first = 0;
} else {
my @newlist = ();
......
......@@ -43,7 +43,7 @@ GetVirtualizationType SetVirtualizationSubtype GetVirtualizationSubtype
GetExclusive SetExclusive GetLinkManager SetText GetText Serialize
CreateDocument AddElement RemoveChild PolicyExists GetMask
GetDiskImage IsUntaggedLan IsTaggedLan GetHopLinkID GetCapabilitySection
GetSuggestedVlanFromHop SetVlanTagInHop);
GetSuggestedVlanFromHop GetAvailableVlanFromHop SetVlanTagInHop);
use English;
use Data::Dumper;
......@@ -1196,6 +1196,17 @@ sub GetSuggestedVlanFromHop($)
return $tag;
}
sub GetAvailableVlanFromHop($)
{
my ($hopref) = @_;
my $capref = GetHopCapabilitySection($hopref);
return undef
if (!defined($capref));
my $tag = GeniXML::GetText("vlanRangeAvailability", $capref);
return $tag;
}
sub SetVlanTagInHop($$)
{
my ($hopref, $tag) = @_;
......
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