Commit 9fa67d71 authored by Weibin Sun's avatar Weibin Sun

Modify: db/Lan.pm.in, tbsetup/snmpit.in - Add Lan arrtibutes: ofenabled,...

Modify: db/Lan.pm.in, tbsetup/snmpit.in - Add Lan arrtibutes: ofenabled, ofcontroller and oflistener for Openflow settings. Call Openflow enable/controller/listener functions in snmpit.in when creating vlan for an experiment swapin. doEnableOpenflowListener in snmpit.in also updates the VLan oflistener attribute
parent 4bdc56bc
......@@ -188,6 +188,53 @@ 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);
......
......@@ -1545,6 +1545,36 @@ sub doVlansFromTables($$@) {
}
delete($trunkedPorts{$port});
}
#
# Set openflow
#
# A much more right place for the openflow settings is CreateOneVlan,
# however, it is called by sync vlan function and others, which don't destroy
# the existing vlan_arrtibutes rows.
#
# TODO: Move this part to CreateOneVlan and Make sure the existed
# vlan_attributes rows are deleted
#
my $ofenabled;
$vlan->GetAttribute("ofenabled", \$ofenabled);
if (defined($ofenabled) && $ofenabled == 1) {
$errors += doOpenflowEnable($stacks, $vlanid);
my $ofcontroller;
$vlan->GetAttribute("ofcontroller", \$ofcontroller);
if (defined($ofcontroller) && $ofcontroller ne "") {
$errors += doSetOpenflowController($stacks, $vlanid, $ofcontroller);
}
$errors += doEnableOpenflowListener($stacks, $vlanid);
# doEnableOpenflowListener updates the lan_arrtibutes table, so vlan
# should refresh itself. But here vlan will not be used any more, so
# maybe we can comment this refresh.
$vlan->Refresh();
}
# Delete this vlan from the list that will be created below.
delete($vlans{"$vlanid"});
}
......@@ -1584,6 +1614,35 @@ sub doVlansFromTables($$@) {
my @ports = getVlanPorts($vlanid);
$errors += CreateOneVlan($stack, $vlanid, @ports);
#
# Set openflow
#
# A much more right place for the openflow settings is CreateOneVlan,
# however, it is called by sync vlan function and others, which don't destroy
# the existing vlan_arrtibutes rows.
#
# TODO: Move this part to CreateOneVlan and Make sure the existed
# vlan_attributes rows are deleted
#
my $ofenabled;
$vlan->GetAttribute("ofenabled", \$ofenabled);
if (defined($ofenabled) && $ofenabled == 1) {
$errors += doOpenflowEnable($stacks, $vlanid);
my $ofcontroller;
$vlan->GetAttribute("ofcontroller", \$ofcontroller);
if (defined($ofcontroller) && $ofcontroller ne "") {
$errors += doSetOpenflowController($stacks, $vlanid, $ofcontroller);
}
$errors += doEnableOpenflowListener($stacks, $vlanid);
# doEnableOpenflowListener updates the lan_arrtibutes table, so vlan
# should refresh itself. But here vlan will not be used any more, so
# maybe we can comment this refresh.
$vlan->Refresh();
}
}
return $errors;
}
......@@ -2686,6 +2745,13 @@ sub doEnableOpenflowListener($$) {
}
ofunlock();
#
# update the vlan object with the new listener string
# other openflow functions may also need this, especially doOpenflowEnable/doOpenflowDisable
#
my $vlan = VLan->Lookup($vlan);
$vlan->SetAttribute('oflistener', $listenerConnStr, 'string');
return $errors;
}
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