Commit 30b32bb7 authored by Leigh B Stoller's avatar Leigh B Stoller

More changes to support deleting nodes from a layer 1 link.

parent 7ed1fcf3
...@@ -3673,7 +3673,7 @@ sub RemovePhysicalState($;$) ...@@ -3673,7 +3673,7 @@ sub RemovePhysicalState($;$)
if (Lan->DestroyExperimentLans($self, $purge) != 0); if (Lan->DestroyExperimentLans($self, $purge) != 0);
return -1 return -1
if (Interface::LogicalWire->DeleteLogicalWires($self) != 0); if (Interface::LogicalWire->RemoveLogicalWires($self) != 0);
if (@pnodenames || @vnodenames) { if (@pnodenames || @vnodenames) {
my $clause1 = join(" or ", map("node_id='$_'", @pnodenames)) my $clause1 = join(" or ", map("node_id='$_'", @pnodenames))
...@@ -3845,7 +3845,7 @@ sub RestorePhysicalState($) ...@@ -3845,7 +3845,7 @@ sub RestorePhysicalState($)
return -1 return -1
if (Lan->RestoreExperimentLans($self, $pstateDir) != 0); if (Lan->RestoreExperimentLans($self, $pstateDir) != 0);
return -1 return -1
if (Interface::LogicalWire->RestoreLogicalWires($self, $pstateDir)); if (Interface::LogicalWire->RestoreLogicalWires($self, $pstateDir));
......
...@@ -2062,11 +2062,12 @@ sub ExperimentLogicalWires($$$) ...@@ -2062,11 +2062,12 @@ sub ExperimentLogicalWires($$$)
# #
# Delete all logical wires for an experiment, as for swapout. # Delete all logical wires for an experiment, as for swapout.
# #
sub DeleteLogicalWires($$) sub DeleteLogicalWires($$;$)
{ {
my ($class, $experiment) = @_; my ($class, $experiment, $force) = @_;
my @wires = (); my @wires = ();
my $errors = 0; my $errors = 0;
$force = 0 if (!defined($force));
return -1 return -1
if (! ref($experiment)); if (! ref($experiment));
...@@ -2079,9 +2080,10 @@ sub DeleteLogicalWires($$) ...@@ -2079,9 +2080,10 @@ sub DeleteLogicalWires($$)
foreach my $wire (@wires) { foreach my $wire (@wires) {
print STDERR "Deleting $wire\n"; print STDERR "Deleting $wire\n";
if ($wire->IsActive()) { if ($wire->IsActive() && !$force) {
print STDERR "$wire is still active; cannot delete!\n"; print STDERR "$wire is still active; cannot delete!\n";
$errors++; $errors++;
next;
} }
my ($interface1, $interface2) = $wire->Interfaces(); my ($interface1, $interface2) = $wire->Interfaces();
...@@ -2145,6 +2147,17 @@ sub RestoreLogicalWires($$$) ...@@ -2145,6 +2147,17 @@ sub RestoreLogicalWires($$$)
return 0; return 0;
} }
#
# Remove all logical wires for an experiment, as for modify.
#
sub RemoveLogicalWires($$)
{
my ($class, $experiment) = @_;
# Force deletion of active logical wires for swapmod.
return DeleteLogicalWires($class, $experiment, 1);
}
############################################################################## ##############################################################################
# #
# A trivial wrapper class for interface_types. # A trivial wrapper class for interface_types.
......
...@@ -587,7 +587,8 @@ sub CompareVlansWithSwitches2($$) ...@@ -587,7 +587,8 @@ sub CompareVlansWithSwitches2($$)
$query_result->fetchrow_array()) { $query_result->fetchrow_array()) {
my $vlan = VLan->Lookup($experiment, $vname); my $vlan = VLan->Lookup($experiment, $vname);
if (!defined($vlan) || $vlan->type ne "vlan") { if (!defined($vlan) ||
($vlan->type ne "vlan" && $vlan->type ne "wire")) {
# #
# The vlan was deleted. # The vlan was deleted.
# #
......
...@@ -2348,12 +2348,23 @@ sub DeleteNodes($) ...@@ -2348,12 +2348,23 @@ sub DeleteNodes($)
print STDERR "No virtual node for $noderef\n"; print STDERR "No virtual node for $noderef\n";
return GeniResponse->Create(GENIRESPONSE_ERROR()); return GeniResponse->Create(GENIRESPONSE_ERROR());
} }
$allnodes{$id} = $id; my $vnode_id = GeniXML::GetVnodeId($noderef);
my $pnode = GeniUtil::LookupNode($vnode_id);
if (!defined($pnode)) {
return GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"Bad resource $vnode_id in manifest");
}
$allnodes{$id} = $pnode;
} }
foreach my $nodeid (keys(%nodelist)) { foreach my $nodeid (keys(%nodelist)) {
if (!exists($allnodes{$nodeid})) { if (!exists($allnodes{$nodeid})) {
return GeniResponse->Create(GENIRESPONSE_BADARGS(), undef, return GeniResponse->Create(GENIRESPONSE_BADARGS(), undef,
"No such node $nodeid in the topology!"); "No such node $nodeid in the topology!");
}
my $pnode = $allnodes{$nodeid};
if ($pnode->isswitch()) {
return GeniResponse->Create(GENIRESPONSE_BADARGS(), undef,
"Not allowed to delete switches from topology!");
} }
} }
main::AddLogfileMetaDataFromSlice($slice); main::AddLogfileMetaDataFromSlice($slice);
...@@ -2382,6 +2393,8 @@ sub DeleteNodes($) ...@@ -2382,6 +2393,8 @@ sub DeleteNodes($)
if (keys(%ifacestoremovefromlans)) { if (keys(%ifacestoremovefromlans)) {
foreach my $linkref (GeniXML::FindNodes("n:link", foreach my $linkref (GeniXML::FindNodes("n:link",
$manifest)->get_nodelist()) { $manifest)->get_nodelist()) {
my $link_id = GeniXML::GetVirtualId($linkref);
foreach my $iref (GeniXML::FindNodes("n:interface_ref", foreach my $iref (GeniXML::FindNodes("n:interface_ref",
$linkref)->get_nodelist()) { $linkref)->get_nodelist()) {
my $client_id = GeniXML::GetInterfaceId($iref); my $client_id = GeniXML::GetInterfaceId($iref);
...@@ -2392,6 +2405,15 @@ sub DeleteNodes($) ...@@ -2392,6 +2405,15 @@ sub DeleteNodes($)
} }
} }
} }
# Purge links if we reduced the number of interfaces to <= 1.
foreach my $linkref (GeniXML::FindNodes("n:link",
$manifest)->get_nodelist()) {
my @ifaces = GeniXML::FindNodes("n:interface_ref",
$linkref)->get_nodelist();
if (@ifaces <= 1) {
$manifest->removeChild($linkref);
}
}
my $rspecstr = GeniXML::Serialize($manifest); my $rspecstr = GeniXML::Serialize($manifest);
print STDERR "$rspecstr\n"; print STDERR "$rspecstr\n";
......
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