Commit cb02a386 authored by Leigh Stoller's avatar Leigh Stoller

More changes/fixes for setting up vlans from within an elabinelab. I was

not really able to test this stuff until it was running in the main tree.
parent 7acd041f
......@@ -344,13 +344,21 @@ sub Refresh($)
return -1
if (! ref($self));
my $newref = Lan->Lookup($self->lanid());
my $lanid = $self->lanid();
# Delete from the cache to force lookup.
delete($lans{"$lanid"});
my $newref = Lan->Lookup($lanid);
return -1
if (!defined($newref));
$self->{'LAN'} = $newref->{'LAN'};
$self->{"ATTRS"} = $newref->{'ATTRS'};
# Add back to cache.
$lans{"$lanid"} = $self;
return 0;
}
......@@ -457,9 +465,11 @@ sub AddInterface($$$$;$$)
{
my ($self, $node, $vnode, $vport, $iface, $member) = @_;
return undef
if (! (ref($self) && ref($node)));
if (!ref($node)) {
$node = Node->Lookup($node);
return undef
if (!defined($node));
}
my $interface = Lan::Interface->Create($self, $node,
$vnode, $vport, $member);
return undef
......@@ -503,9 +513,11 @@ sub AddMember($$;$)
return undef
if (!ref($self));
return undef
if (defined($node) && !ref($node));
if (!ref($node)) {
$node = Node->Lookup($node);
return undef
if (!defined($node));
}
my $member = Lan::Member->Create($self);
if (defined($node)) {
......@@ -536,6 +548,39 @@ sub AddMember($$;$)
return $member;
}
#
# Check membership.
#
sub IsMember($$$)
{
my ($self, $node, $iface) = @_;
if (!ref($node)) {
$node = Node->Lookup($node);
return 0
if (!defined($node));
}
my $nodeid = $node->node_id();
my $lanid = $self->lanid();
my $query_result =
DBQueryWarn("select memberid from ".
" lan_member_attributes as lma ".
"where lma.lanid='$lanid' and ".
" ((lma.attrkey='node_id' and ".
" lma.attrvalue='$nodeid') or ".
" (lma.attrkey='iface' and ".
" lma.attrvalue='$iface'))");
# Must be two rows and those must be the same memberid.
return 0
if ($query_result->numrows != 2);
my ($memberid1) = $query_result->fetchrow_array();
my ($memberid2) = $query_result->fetchrow_array();
return ($memberid1 == $memberid2 ? 1 : 0);
}
#
# Remove a member from a lan.
#
......@@ -1814,6 +1859,16 @@ sub DelMember($$)
return $self->GetLan()->DelMember($member);
}
#
# Does member already exists in protolan.
#
sub IsMember($$$)
{
my ($self, $node, $iface) = @_;
return $self->GetLan()->IsMember($node, $iface);
}
#
# Return a list of interfaces for a vlan.
#
......
......@@ -313,15 +313,6 @@ sub SetupVlans()
$errors++;
next;
}
foreach my $port (@members) {
my ($nodeid, $iface) = split(":", $port);
if (!$vlan->IsMember($nodeid, $iface) &&
$vlan->AddMember($nodeid, $iface) != 0) {
print STDERR "*** $0:\n".
" Could not $port to $vlan\n";
$errors++;
}
}
}
else {
$vlan = VLan->Create($experiment, $vtag);
......@@ -354,6 +345,15 @@ sub SetupVlans()
print STDERR "Mapping inner id $id to outer id $outer_id\n";
print STDERR " $mstring\n";
}
foreach my $port (@members) {
my ($nodeid, $iface) = split(":", $port);
if (!$vlan->IsMember($nodeid, $iface) &&
!$vlan->AddMember($nodeid, $iface)) {
print STDERR "*** $0:\n".
" Could not $port to $vlan\n";
$errors++;
}
}
$vmaptable{$id} = $outer_id;
# Okay, save outer_id up for passing to snmpit below.
push(@outer_ids, $outer_id);
......@@ -390,7 +390,7 @@ sub SetupVlans()
next;
}
my $tagnum;
if (!$outer_vlan->GetTag(\$tagnum) != 0) {
if ($outer_vlan->GetTag(\$tagnum) != 0) {
print STDERR "*** Could not get vlan tag for $outer_vlan\n";
$errors++;
next;
......
......@@ -313,15 +313,6 @@ sub SetupVlans()
$errors++;
next;
}
foreach my $port (@members) {
my ($nodeid, $iface) = split(":", $port);
if (!$vlan->IsMember($nodeid, $iface) &&
$vlan->AddMember($nodeid, $iface) != 0) {
print STDERR "*** $0:\n".
" Could not $port to $vlan\n";
$errors++;
}
}
}
else {
$vlan = VLan->Create($experiment, $vtag);
......@@ -354,6 +345,15 @@ sub SetupVlans()
print STDERR "Mapping inner id $id to outer id $outer_id\n";
print STDERR " $mstring\n";
}
foreach my $port (@members) {
my ($nodeid, $iface) = split(":", $port);
if (!$vlan->IsMember($nodeid, $iface) &&
!$vlan->AddMember($nodeid, $iface)) {
print STDERR "*** $0:\n".
" Could not $port to $vlan\n";
$errors++;
}
}
$vmaptable{$id} = $outer_id;
# Okay, save outer_id up for passing to snmpit below.
push(@outer_ids, $outer_id);
......@@ -390,7 +390,7 @@ sub SetupVlans()
next;
}
my $tagnum;
if (!$outer_vlan->GetTag(\$tagnum) != 0) {
if ($outer_vlan->GetTag(\$tagnum) != 0) {
print STDERR "*** Could not get vlan tag for $outer_vlan\n";
$errors++;
next;
......
......@@ -156,7 +156,7 @@ sub RemoteDoVlansFromTables(@)
my ($vlanid, $tag) = split '#', $vlres;
if (!exists($vlans{$vlanid})) {
print STDERR "Ban vlanid $vlanid in returned vlan map\n";
print STDERR "Bad vlanid $vlanid in returned vlan map\n";
$errors++;
}
my $vlan = $vlans{$vlanid};
......
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