tom

Added a wipe-out command; we need to revisit how to either make the devices come…

… back or the links not come back.
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;
}
}
......@@ -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"/>
......
......@@ -2,7 +2,6 @@ package org.onlab.onos.net.flow;
/**
* Abstraction of a single traffic treatment step.
* @param <T> the type parameter for the instruction
*/
public interface Instruction {
......
......@@ -23,6 +23,7 @@ public final class Instructions {
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 @@ public final class Instructions {
// TODO: add create methods
public static final class DropInstruction implements Instruction {
@Override
public Type type() {
return Type.DROP;
......@@ -39,7 +39,6 @@ public final class Instructions {
public static final class OutputInstruction implements Instruction {
private final PortNumber port;
private OutputInstruction(PortNumber port) {
......@@ -54,8 +53,6 @@ public final class Instructions {
public Type type() {
return Type.OUTPUT;
}
}
}
......
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);
}
......@@ -43,13 +43,15 @@ public interface PacketContext {
/**
* 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();
......
......@@ -139,8 +139,7 @@ class SimpleDeviceStore {
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);
}
......
......@@ -12,6 +12,7 @@ import org.onlab.onos.net.ConnectPoint;
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 @@ import static org.slf4j.LoggerFactory.getLogger;
@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 @@ public class SimpleHostManager
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>
......
......@@ -16,6 +16,9 @@ import org.onlab.onos.event.EventDeliveryService;
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 @@ public class SimpleLinkManager
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 @@ public class SimpleLinkManager
@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 @@ public class SimpleLinkManager
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);
......
......@@ -22,6 +22,7 @@ import org.onlab.onos.net.link.LinkService;
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 @@ public class SimpleLinkManagerTest {
admin = mgr;
registry = mgr;
mgr.eventDispatcher = new TestEventDispatcher();
mgr.deviceService = new SimpleDeviceManager();
mgr.activate();
service.addListener(listener);
......