Commit 4d9b797a authored by Weibin Sun's avatar Weibin Sun

db/Lan.pm.in: move the Openflow settings from Lan:Create to a seperate...

db/Lan.pm.in: move the Openflow settings from Lan:Create to a seperate function and called from Lan:Lookup.
parent 58b67c15
......@@ -48,6 +48,93 @@ my %LanTables = ("lans" => ["lanid"],
"lan_member_attributes" => ["lanid", "memberid", "attrkey"],
"ifaces" => ["lanid", "ifaceid"]);
#
# Initialize Openflow attributes in lan_attributes table.
#
sub InitOpenflowAttributes($$$)
{
my ($exptidx, $vname, $lanid) = @_;
my $ofenabled = 0;
my $ofcontroller = "";
my $safe_val;
# Add openflow arrtibutes:
my $query_result =
DBQueryWarn("select ofenabled, ofcontroller from virt_lans ".
"where exptidx=$exptidx and vname='$vname'");
return 0
if (!$query_result);
($ofenabled, $ofcontroller) = $query_result->fetchrow_array()
if ($query_result->numrows);
#
# Firstly check if the attribuets are there, if no values,
# insert them. This is because the vlan may be created
# by Lookup many times. The values can be overwritten by
# the later creation.
#
# Process 'ofenabled':
$query_result =
DBQueryWarn("select attrvalue from lan_attributes ".
"where lanid=$lanid and attrkey='ofenabled'");
return 0
if (!$query_result);
if (!$query_result->numrows)
{
$safe_val = DBQuoteSpecial($ofenabled);
$query_result =
DBQueryWarn("replace into lan_attributes set ".
" lanid=$lanid, ".
" attrkey='ofenabled', ".
" attrvalue=$safe_val, ".
" attrtype='integer'");
return 0
if (!defined($query_result));
}
# Process 'ofcontroller':
$query_result =
DBQueryWarn("select attrvalue from lan_attributes ".
"where lanid=$lanid and attrkey='ofcontroller'");
return 0
if (!$query_result);
if (!$query_result->numrows)
{
$safe_val = DBQuoteSpecial($ofcontroller);
$query_result =
DBQueryWarn("replace into lan_attributes set ".
" lanid=$lanid, ".
" attrkey='ofcontroller', ".
" attrvalue=$safe_val, ".
" attrtype='string'");
return 0
if (!defined($query_result));
}
# Process 'oflistener':
$query_result =
DBQueryWarn("select attrvalue from lan_attributes ".
"where lanid=$lanid and attrkey='oflistener'");
return 0
if (!$query_result);
if (!$query_result->numrows)
{
$safe_val = DBQuoteSpecial("");
$query_result =
DBQueryWarn("replace into lan_attributes set ".
" lanid=$lanid, ".
" attrkey='oflistener', ".
" attrvalue=$safe_val, ".
" attrtype='string'");
return 0
if (!defined($query_result));
}
return 1;
}
#
# Lookup and create a class instance to return.
#
......@@ -107,6 +194,9 @@ sub Lookup($$;$$)
$self->{"ATTRS"} = {};
$self->{"EXPT"} = $experiment;
if (!Lan->InitOpenflowAttributes($arg1, $arg2, $lanid))
return undef;
#
# Grab the attributes for this lan now.
#
......@@ -188,54 +278,7 @@ sub Create($$$;$$$)
# Need the newly minted ID
my $lanid = $query_result->insertid();
my $lan = Lan->Lookup($lanid);
# Add openflow arrtibutes:
#
# Still not sure if it is the right place to add such
# attributes. Will take a look at where other attributes
# are added.
#
$query_result =
DBQueryWarn("select ofenabled, ofcontroller from virt_lans ".
"where exptidx=$exptidx and vname='$vname'");
return undef
if (!$query_result);
my($ofenabled, $ofcontroller) = $query_result->fetchrow_array()
if ($query_result->numrows);
my $safe_val = DBQuoteSpecial($ofenabled);
$query_result =
DBQueryWarn("insert into lan_attributes set ".
" lanid=$lanid, ".
" attrkey='ofenabled', ".
" attrvalue=$safe_val, ".
" attrtype='integer'"));
return undef
if (!defined($query_result));
$safe_val = DBQuoteSpecial($ofcontroller);
$query_result =
DBQueryWarn("insert into lan_attributes set ".
" lanid=$lanid, ".
" attrkey='ofcontroller', ".
" attrvalue=$safe_val, ".
" attrtype='string'"));
return undef
if (!defined($query_result));
$safe_val = DBQuoteSpecial("");
$query_result =
DBQueryWarn("insert into lan_attributes set ".
" lanid=$lanid, ".
" attrkey='oflistener', ".
" attrvalue=$safe_val, ".
" attrtype='string'"));
return undef
if (!defined($query_result));
# An extra refresh for loading the openflow attributes.
$lan->Refresh();
print "Created lan: $lan\n"
if ($debug && $lan);
return $lan;
......
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