Commit 13c58c2e authored by Leigh B. Stoller's avatar Leigh B. Stoller
Browse files

Various changes to support changes to snmpit that record manually

created vlans (-m option to snmpit) in the DB, both for the
experimental and control stacks.
parent 3da9ec35
#!/usr/bin/perl -wT
#
# EMULAB-COPYRIGHT
# Copyright (c) 2007, 2008 University of Utah and the Flux Group.
# Copyright (c) 2007-2009 University of Utah and the Flux Group.
# All rights reserved.
#
package Lan;
......@@ -629,21 +629,54 @@ sub IsMember($$$)
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.
DBQueryWarn("select lma1.memberid from lan_member_attributes as lma1 ".
"left join lan_member_attributes as lma2 on ".
" lma1.lanid=lma2.lanid and ".
" lma1.memberid=lma2.memberid ".
"where lma1.lanid='$lanid' and ".
" ((lma1.attrkey='node_id' and ".
" lma1.attrvalue='$nodeid') and ".
" (lma2.attrkey='iface' and ".
" lma2.attrvalue='$iface'))");
return 0
if ($query_result->numrows != 2);
my ($memberid1) = $query_result->fetchrow_array();
my ($memberid2) = $query_result->fetchrow_array();
if (!$query_result || $query_result->numrows != 1);
return 1;
}
#
# Check membership.
#
sub FindMember($$$)
{
my ($self, $node, $iface) = @_;
if (!ref($node)) {
$node = Node->Lookup($node);
return undef
if (!defined($node));
}
my $nodeid = $node->node_id();
my $lanid = $self->lanid();
my $query_result =
DBQueryWarn("select lma1.memberid from lan_member_attributes as lma1 ".
"left join lan_member_attributes as lma2 on ".
" lma1.lanid=lma2.lanid and ".
" lma1.memberid=lma2.memberid ".
"where lma1.lanid='$lanid' and ".
" ((lma1.attrkey='node_id' and ".
" lma1.attrvalue='$nodeid') and ".
" (lma2.attrkey='iface' and ".
" lma2.attrvalue='$iface'))");
return undef
if (!$query_result || $query_result->numrows != 1);
my ($memberid) = $query_result->fetchrow_array();
return ($memberid1 == $memberid2 ? 1 : 0);
return Lan::Member->Lookup($self, $memberid);
}
#
......@@ -1854,6 +1887,7 @@ use libdb;
use libtestbed;
use English;
use Lan;
use Interface;
use overload ('""' => 'Stringify');
my $SNMPIT = "$TB/bin/snmpit";
......@@ -1941,7 +1975,14 @@ sub Create($$$;$)
return undef
if (!defined($lan));
return VLan->Lookup($lan->lanid());
my $vlan = VLan->Lookup($lan->lanid());
return undef
if (!defined($vlan));
$vlan->SetStack("Experimental") == 0
or return undef;
return $vlan;
}
#
......@@ -1954,6 +1995,16 @@ sub Destroy($)
return $self->GetLan()->Destroy();
}
#
# Equality
#
sub SameVlan($$)
{
my ($self, $other) = @_;
return $self->id() == $other->id();
}
#
# Refresh underyling object.
#
......@@ -2005,6 +2056,54 @@ sub DelMember($$)
return $self->GetLan()->DelMember($member);
}
#
# Find a member
#
sub FindMember($$$)
{
my ($self, $node, $iface) = @_;
return $self->GetLan()->FindMember($node, $iface);
}
#
# Add a member in snmpit port form (node:card).
#
sub AddPort($$)
{
my ($self, $port) = @_;
my ($node_id, $card) = split(":", $port);
my $interface = Interface->Lookup($node_id, $card, 1);
return undef
if (!defined($interface));
my $member = $self->FindMember($node_id, $interface->iface());
return $member
if (defined($member));
return $self->GetLan()->AddMember($node_id, $interface->iface());
}
#
# Delete a member in snmpit port form (node:card).
#
sub DelPort($$)
{
my ($self, $port) = @_;
my ($node_id, $card) = split(":", $port);
my $interface = Interface->Lookup($node_id, $card, 1);
return -1
if (!defined($interface));
my $member = $self->FindMember($node_id, $interface->iface());
return 0
if (!defined($member));
return $self->DelMember($member);
}
#
# Does member already exists in protolan.
#
......@@ -2117,8 +2216,52 @@ sub SetTag($$)
sub GetTag($$)
{
my ($self, $ptag) = @_;
my $tag;
return -1
if ($self->GetAttribute("vlantag", \$tag) != 0);
if (defined($ptag)) {
$$ptag = $tag;
return 0;
}
return $tag;
}
sub SetStack($$)
{
my ($self, $stack) = @_;
return $self->GetLan()->SetAttribute("stack", $stack);
}
sub GetStack($)
{
my ($self) = @_;
my $stack;
return $stack
if ($self->GetAttribute("stack", \$stack) == 0);
# Assume experimental stack.
return "Experimental";
}
#
# Mark/Get the "manually created" (command line) bit on a vlan.
#
sub MarkManual($)
{
my ($self) = @_;
return $self->GetAttribute("vlantag", $ptag);
return $self->GetLan()->SetAttribute("cmdline_created", "1");
}
sub IsManual($)
{
my ($self) = @_;
my $flag;
return $flag
if ($self->GetAttribute("cmdline_created", \$flag) == 0);
return 0;
}
#
......@@ -2161,7 +2304,11 @@ sub ExperimentVLans($$$)
my $query_result =
DBQueryWarn("select l.lanid from lans as l ".
"where l.type='vlan' and l.exptidx='$exptidx'");
"left join lan_attributes as la on ".
" la.lanid=l.lanid and la.attrkey='stack' ".
"where l.type='vlan' and l.exptidx='$exptidx' and ".
" (la.attrvalue='Experimental' or ".
" la.attrvalue is null)");
return -1
if (!defined($query_result));
......@@ -2197,6 +2344,7 @@ sub Instantiate($;$)
my $vname = $self->vname();
my $lanid = $self->lanid();
my $opt = ($quiet ? "-q" : "");
my $stack = $self->GetStack();
#print "Setting up VLAN $vname ($lanid) in $pid/$eid\n";
system("$SNMPIT $opt -t $pid $eid $lanid");
......@@ -2226,6 +2374,7 @@ sub UnInstantiate($;$)
my $vname = $self->vname();
my $lanid = $self->lanid();
my $opt = ($quiet ? "-q" : "");
my $stack = $self->GetStack();
#print "Removing VLAN $vname ($lanid) from $pid/$eid\n";
system("$SNMPIT $opt -r $pid $eid $lanid");
......@@ -2236,11 +2385,11 @@ sub UnInstantiate($;$)
#
# Class methods to maintain the backup vlans table, which records what
# is on the switches. This is used to optimize swapmod, nothing else.
# is on the switches.
#
sub RecordVlanInsertion($$$$)
sub RecordVlanInsertion($$$)
{
my ($class, $experiment, $lanid, $tag) = @_;
my ($class, $experiment, $lanid) = @_;
my $pid = $experiment->pid();
my $eid = $experiment->eid();
......@@ -2249,7 +2398,12 @@ sub RecordVlanInsertion($$$$)
return -1
if (!defined($vlan));
my $stack = $vlan->GetStack();
my $vname = $vlan->vname();
my $tag = $vlan->GetTag(undef);
return -1
if ($tag <= 0);
my @portlist;
$vlan->PortList(\@portlist) == 0
or return -1;
......@@ -2257,7 +2411,8 @@ sub RecordVlanInsertion($$$$)
DBQueryWarn("replace into vlans set ".
" id='$lanid', pid='$pid', eid='$eid', exptidx='$exptidx', ".
" virtual='$vname', members='$members', tag='$tag'")
" virtual='$vname', members='$members', tag='$tag', ".
" stack='$stack'")
or return -1;
return 0;
......@@ -2273,6 +2428,49 @@ sub RecordVLanDeletion($$)
return 0;
}
#
# Is a node within a vlan, any vlan. Used for sanity checking nfree.
#
sub IsNodeInAVlan($$)
{
my ($class, $nodeid) = @_;
if (ref($nodeid)) {
$nodeid = $nodeid->node_id();
}
my $query_result =
DBQueryWarn("select id from vlans where members like '%${nodeid}:%'");
return -1
if (!$query_result);
return $query_result->numrows;
}
sub FindVlanByPort($$$)
{
my ($class, $experiment, $port) = @_;
my ($node_id, $card) = split(":", $port);
my $interface = Interface->Lookup($node_id, $card, 1);
return undef
if (!defined($interface));
my $iface = $interface->iface();
my $exptidx = $experiment->idx();
my $query_result =
DBQueryWarn("select id from vlans ".
"where exptidx='$exptidx' and ".
" members like '%${node_id}:${iface}%'");
return undef
if (!$query_result || !$query_result->numrows);
my ($lanid) = $query_result->fetchrow_array();
return VLan->Lookup($lanid);
}
#
# Return a list of stale vlans for an experiment; vlans in the vlans
# table that need to be removed from the switches. This happens when a
......@@ -2290,7 +2488,8 @@ sub StaleVlanList($$$)
my @result = ();
my $query_result =
DBQueryWarn("select id from vlans where exptidx=$exptidx");
DBQueryWarn("select id from vlans ".
"where exptidx=$exptidx and stack='Experimental'");
return -1
if (!$query_result);
......
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