Commit 62ebf329 authored by Leigh Stoller's avatar Leigh Stoller

Some minor updates to Interface::Vinterface, to look up by the virtual

node info. Not sure this will survive. Add routines to update as well.
Also add Update and Refresh routines.

Export VMAC for virtual interfaces as for cooked mode.
parent e0234031
......@@ -553,7 +553,7 @@ my $nextfake = 0;
#
# Lookup by node_id,unit
#
sub Lookup($$$$)
sub Lookup($$$)
{
my ($class, $nodeid, $unit) = @_;
......@@ -593,6 +593,30 @@ sub bandwidth($) { return field($_[0], 'bandwidth'); }
# The virtual iface name is $type$unit
sub viface($) { return $_[0]->type() . $_[0]->unit(); }
#
# Lookup by the experiment/virtlan/vnode
#
sub LookupByVirtLan($$$$)
{
my ($class, $experiment, $virtlan, $vnode) = @_;
my $exptidx = $experiment->idx();
$virtlan = DBQuoteSpecial($virtlan);
$vnode = DBQuoteSpecial($vnode);
my $query_result =
DBQueryWarn("select node_id,unit from vinterfaces as vif ".
"left join virt_lans as vl on vl.exptidx=vif.exptidx and ".
" vl.ip=vif.IP ".
"where vif.exptidx='$exptidx' and ".
" vl.vname=$virtlan and vl.vnode=$vnode");
return undef
if (!defined($query_result) || !$query_result->numrows);
my ($node_id,$unit) = $query_result->fetchrow_array();
return Interface::VInterface->Lookup($node_id, $unit);
}
#
# Create a new vinterface
#
......@@ -682,6 +706,62 @@ sub ReserveSharedBandwidth($$)
return 0;
}
#
# Refresh instance by reloading from the DB.
#
sub Refresh($)
{
my ($self) = @_;
return -1
if (! ref($self));
my $nodeid = $self->node_id();
my $unit = $self->unit();
my $query_result =
DBQueryWarn("select * from vinterfaces ".
"where node_id='$nodeid' and unit='$unit'");
return undef
if (!$query_result || !$query_result->numrows);
$self->{"DBROW"} = $query_result->fetchrow_hashref();
return 0;
}
#
# Perform some updates ...
#
sub Update($$)
{
my ($self, $argref) = @_;
# Must be a real reference.
return -1
if (! ref($self));
my $nodeid = $self->node_id();
my $unit = $self->unit();
my @sets = ();
foreach my $key (keys(%{$argref})) {
my $val = $argref->{$key};
# Treat NULL special.
push (@sets, "${key}=" . ($val eq "NULL" ?
"NULL" : DBQuoteSpecial($val)));
}
my $query = "update vinterfaces set " . join(",", @sets) .
" where node_id='$nodeid' and unit='$unit'";
return -1
if (! DBQueryWarn($query));
return Refresh($self);
}
# _Always_ make sure that this 1 is at the end of the file...
1;
......@@ -2095,6 +2095,7 @@ sub SliverWorkAux($$$$$$$)
$ifaceref);
my $node_id = GeniXML::GetText("virtual_node_id",
$ifaceref);
my ($vnode,$vinterface);
#
# Look for links that are really lans; one of the interfaces
......@@ -2111,11 +2112,28 @@ sub SliverWorkAux($$$$$$$)
$message = "Link $linkname specifies a non-existent node";
goto bad;
}
my $nodeobject= GeniUtil::LookupNode($nodesliver->resource_uuid());
if (!defined($nodeobject)) {
my $node = GeniUtil::LookupNode($nodesliver->resource_id());
if (!defined($node)) {
$message = "Could not find node object for $nodesliver";
goto bad;
}
#
# Not quite sure how to deal with links into virtual containers
# yet. For now, the link section will hold the physical info,
# but we have to return the VMAC so the caller knows which
# virtual interface inside the container.
#
if ($node->isvirtnode()) {
$vnode = $node;
$node = GeniUtil::LookupNode($nodesliver->resource_uuid());
if (!defined($node)) {
$message = "Could not find node object for $nodesliver";
goto bad;
}
$vinterface =
Interface::VInterface->LookupByVirtLan($experiment,
$linkname, $node_id);
}
#
# The interface was set above.
......@@ -2133,16 +2151,15 @@ sub SliverWorkAux($$$$$$$)
GeniHRN::ParseInterface($iface_name);
$iface_name = $short_iface;
}
$interface = Interface->LookupByIface($nodeobject,$iface_name);
$interface = Interface->LookupByIface($node, $iface_name);
if (!defined($interface)) {
$message = "No such interface ".
"$iface_name on node $nodeobject";
$message = "No such interface $iface_name on $node";
goto bad;
}
}
my $sliver = GeniSliver::Interface->Create($slice,
$owner,
$nodeobject->node_id(),
$node->node_id(),
$iface_name,
$linkname,
$ifaceref);
......@@ -2155,6 +2172,8 @@ sub SliverWorkAux($$$$$$$)
GeniXML::SetText("sliver_urn", $ifaceref, $sliver->sliver_urn());
GeniXML::SetText("MAC", $ifaceref, $interface->mac())
if (defined($interface));
GeniXML::SetText("VMAC", $ifaceref, $vinterface->mac())
if (defined($vinterface));
GeniXML::SetText("IP", $ifaceref, $interface->IP())
if (defined($interface) &&
defined($interface->IP()) && $interface->IP() ne "");
......
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