Added a wipe-out command; we need to revisit how to either make the devices come back or the links not come back.
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/WipeOutCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/WipeOutCommand.java
new file mode 100644
index 0000000..51a0fce
--- /dev/null
+++ b/cli/src/main/java/org/onlab/onos/cli/net/WipeOutCommand.java
@@ -0,0 +1,35 @@
+package org.onlab.onos.cli.net;
+
+import org.apache.karaf.shell.commands.Command;
+import org.onlab.onos.net.Device;
+import org.onlab.onos.net.Host;
+import org.onlab.onos.net.device.DeviceAdminService;
+import org.onlab.onos.net.device.DeviceService;
+import org.onlab.onos.net.host.HostAdminService;
+import org.onlab.onos.net.host.HostService;
+
+/**
+ * Wipes-out the entire network information base, i.e. devices, links, hosts.
+ */
+@Command(scope = "onos", name = "wipe-out",
+ description = "Wipes-out the entire network information base, i.e. devices, links, hosts")
+public class WipeOutCommand extends ClustersListCommand {
+
+ @Override
+ protected Object doExecute() throws Exception {
+ DeviceAdminService deviceAdminService = get(DeviceAdminService.class);
+ DeviceService deviceService = get(DeviceService.class);
+ for (Device device : deviceService.getDevices()) {
+ deviceAdminService.removeDevice(device.id());
+ }
+
+ HostAdminService hostAdminService = get(HostAdminService.class);
+ HostService hostService = get(HostService.class);
+ for (Host host : hostService.getHosts()) {
+ hostAdminService.removeHost(host.id());
+ }
+ return null;
+ }
+
+
+}
diff --git a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
index 55fec58..4494709 100644
--- a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
+++ b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -58,11 +58,11 @@
<command>
<action class="org.onlab.onos.cli.net.HostsListCommand"/>
- <completers>
- <ref component-id="hostIdCompleter"/>
- </completers>
</command>
+ <command>
+ <action class="org.onlab.onos.cli.net.WipeOutCommand"/>
+ </command>
</command-bundle>
<bean id="deviceIdCompleter" class="org.onlab.onos.cli.net.DeviceIdCompleter"/>
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/Instruction.java b/core/api/src/main/java/org/onlab/onos/net/flow/Instruction.java
index 0888d9b..cc72880 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/Instruction.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/Instruction.java
@@ -2,7 +2,6 @@
/**
* Abstraction of a single traffic treatment step.
- * @param <T> the type parameter for the instruction
*/
public interface Instruction {
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/Instructions.java b/core/api/src/main/java/org/onlab/onos/net/flow/Instructions.java
index 9681076..cfe1440 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/Instructions.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/Instructions.java
@@ -23,6 +23,7 @@
return new OutputInstruction(number);
}
+ // TODO: Move these out into separate classes and to flow.instruction package
public static DropInstruction createDrop() {
return new DropInstruction();
}
@@ -30,7 +31,6 @@
// TODO: add create methods
public static final class DropInstruction implements Instruction {
-
@Override
public Type type() {
return Type.DROP;
@@ -39,7 +39,6 @@
public static final class OutputInstruction implements Instruction {
-
private final PortNumber port;
private OutputInstruction(PortNumber port) {
@@ -54,8 +53,6 @@
public Type type() {
return Type.OUTPUT;
}
-
-
}
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/host/HostAdminService.java b/core/api/src/main/java/org/onlab/onos/net/host/HostAdminService.java
new file mode 100644
index 0000000..d94449a
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/host/HostAdminService.java
@@ -0,0 +1,17 @@
+package org.onlab.onos.net.host;
+
+import org.onlab.onos.net.HostId;
+
+/**
+ * Service for administering the inventory of end-station hosts.
+ */
+public interface HostAdminService {
+
+ /**
+ * Removes the end-station host with the specified identifier.
+ *
+ * @param hostId host identifier
+ */
+ void removeHost(HostId hostId);
+
+}
diff --git a/core/api/src/main/java/org/onlab/onos/net/packet/PacketContext.java b/core/api/src/main/java/org/onlab/onos/net/packet/PacketContext.java
index 48cb084..73fe102 100644
--- a/core/api/src/main/java/org/onlab/onos/net/packet/PacketContext.java
+++ b/core/api/src/main/java/org/onlab/onos/net/packet/PacketContext.java
@@ -43,13 +43,15 @@
/**
* Blocks the outbound packet from being sent from this point onward.
+ *
* @return whether the outbound packet is blocked.
*/
boolean block();
/**
- * Check whether the outbound packet is blocked.
- * @return
+ * Indicates whether the outbound packet is handled, i.e. sent or blocked.
+ *
+ * @return true uf the packed is handled
*/
boolean isHandled();
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/device/impl/SimpleDeviceStore.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/device/impl/SimpleDeviceStore.java
index 6317b14..ece82e1 100644
--- a/core/trivial/src/main/java/org/onlab/onos/net/trivial/device/impl/SimpleDeviceStore.java
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/device/impl/SimpleDeviceStore.java
@@ -139,8 +139,7 @@
DeviceEvent markOffline(DeviceId deviceId) {
synchronized (this) {
Device device = devices.get(deviceId);
- checkArgument(device != null, DEVICE_NOT_FOUND, deviceId);
- boolean removed = availableDevices.remove(deviceId);
+ boolean removed = device != null && availableDevices.remove(deviceId);
return !removed ? null :
new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device, null);
}
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/host/impl/SimpleHostManager.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/host/impl/SimpleHostManager.java
index b42f1af..3e43dfd 100644
--- a/core/trivial/src/main/java/org/onlab/onos/net/trivial/host/impl/SimpleHostManager.java
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/host/impl/SimpleHostManager.java
@@ -12,6 +12,7 @@
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Host;
import org.onlab.onos.net.HostId;
+import org.onlab.onos.net.host.HostAdminService;
import org.onlab.onos.net.host.HostDescription;
import org.onlab.onos.net.host.HostEvent;
import org.onlab.onos.net.host.HostListener;
@@ -38,7 +39,7 @@
@Service
public class SimpleHostManager
extends AbstractProviderRegistry<HostProvider, HostProviderService>
- implements HostService, HostProviderRegistry {
+ implements HostService, HostAdminService, HostProviderRegistry {
public static final String HOST_ID_NULL = "Host ID cannot be null";
private final Logger log = getLogger(getClass());
@@ -124,6 +125,16 @@
listenerRegistry.removeListener(listener);
}
+ @Override
+ public void removeHost(HostId hostId) {
+ checkNotNull(hostId, HOST_ID_NULL);
+ HostEvent event = store.removeHost(hostId);
+ if (event != null) {
+ log.info("Host {} administratively removed", hostId);
+ post(event);
+ }
+ }
+
// Personalized host provider service issued to the supplied provider.
private class InternalHostProviderService
extends AbstractProviderService<HostProvider>
diff --git a/core/trivial/src/main/java/org/onlab/onos/net/trivial/link/impl/SimpleLinkManager.java b/core/trivial/src/main/java/org/onlab/onos/net/trivial/link/impl/SimpleLinkManager.java
index 4ea1753..7242642 100644
--- a/core/trivial/src/main/java/org/onlab/onos/net/trivial/link/impl/SimpleLinkManager.java
+++ b/core/trivial/src/main/java/org/onlab/onos/net/trivial/link/impl/SimpleLinkManager.java
@@ -16,6 +16,9 @@
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Link;
+import org.onlab.onos.net.device.DeviceEvent;
+import org.onlab.onos.net.device.DeviceListener;
+import org.onlab.onos.net.device.DeviceService;
import org.onlab.onos.net.link.LinkAdminService;
import org.onlab.onos.net.link.LinkDescription;
import org.onlab.onos.net.link.LinkEvent;
@@ -49,6 +52,10 @@
listenerRegistry = new AbstractListenerRegistry<>();
private final SimpleLinkStore store = new SimpleLinkStore();
+ private final DeviceListener deviceListener = new InnerDeviceListener();
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DeviceService deviceService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected EventDeliveryService eventDispatcher;
@@ -56,12 +63,14 @@
@Activate
public void activate() {
eventDispatcher.addSink(LinkEvent.class, listenerRegistry);
+ deviceService.addListener(deviceListener);
log.info("Started");
}
@Deactivate
public void deactivate() {
eventDispatcher.removeSink(LinkEvent.class);
+ deviceService.removeListener(deviceListener);
log.info("Stopped");
}
@@ -140,6 +149,20 @@
listenerRegistry.removeListener(listener);
}
+ // Auxiliary interceptor for device remove events to prune links that
+ // are associated with the removed device or its port.
+ private class InnerDeviceListener implements DeviceListener {
+ @Override
+ public void event(DeviceEvent event) {
+ if (event.type() == DeviceEvent.Type.DEVICE_REMOVED) {
+ removeLinks(event.subject().id());
+ } else if (event.type() == DeviceEvent.Type.PORT_REMOVED) {
+ removeLinks(new ConnectPoint(event.subject().id(),
+ event.port().number()));
+ }
+ }
+ }
+
@Override
protected LinkProviderService createProviderService(LinkProvider provider) {
return new InternalLinkProviderService(provider);
diff --git a/core/trivial/src/test/java/org/onlab/onos/net/trivial/link/impl/SimpleLinkManagerTest.java b/core/trivial/src/test/java/org/onlab/onos/net/trivial/link/impl/SimpleLinkManagerTest.java
index 6eace8f..3702b0a 100644
--- a/core/trivial/src/test/java/org/onlab/onos/net/trivial/link/impl/SimpleLinkManagerTest.java
+++ b/core/trivial/src/test/java/org/onlab/onos/net/trivial/link/impl/SimpleLinkManagerTest.java
@@ -22,6 +22,7 @@
import org.onlab.onos.net.provider.AbstractProvider;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.event.impl.TestEventDispatcher;
+import org.onlab.onos.net.trivial.device.impl.SimpleDeviceManager;
import java.util.ArrayList;
import java.util.Iterator;
@@ -65,6 +66,7 @@
admin = mgr;
registry = mgr;
mgr.eventDispatcher = new TestEventDispatcher();
+ mgr.deviceService = new SimpleDeviceManager();
mgr.activate();
service.addListener(listener);