tom

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

… back or the links not come back.
1 +package org.onlab.onos.cli.net;
2 +
3 +import org.apache.karaf.shell.commands.Command;
4 +import org.onlab.onos.net.Device;
5 +import org.onlab.onos.net.Host;
6 +import org.onlab.onos.net.device.DeviceAdminService;
7 +import org.onlab.onos.net.device.DeviceService;
8 +import org.onlab.onos.net.host.HostAdminService;
9 +import org.onlab.onos.net.host.HostService;
10 +
11 +/**
12 + * Wipes-out the entire network information base, i.e. devices, links, hosts.
13 + */
14 +@Command(scope = "onos", name = "wipe-out",
15 + description = "Wipes-out the entire network information base, i.e. devices, links, hosts")
16 +public class WipeOutCommand extends ClustersListCommand {
17 +
18 + @Override
19 + protected Object doExecute() throws Exception {
20 + DeviceAdminService deviceAdminService = get(DeviceAdminService.class);
21 + DeviceService deviceService = get(DeviceService.class);
22 + for (Device device : deviceService.getDevices()) {
23 + deviceAdminService.removeDevice(device.id());
24 + }
25 +
26 + HostAdminService hostAdminService = get(HostAdminService.class);
27 + HostService hostService = get(HostService.class);
28 + for (Host host : hostService.getHosts()) {
29 + hostAdminService.removeHost(host.id());
30 + }
31 + return null;
32 + }
33 +
34 +
35 +}
...@@ -58,11 +58,11 @@ ...@@ -58,11 +58,11 @@
58 58
59 <command> 59 <command>
60 <action class="org.onlab.onos.cli.net.HostsListCommand"/> 60 <action class="org.onlab.onos.cli.net.HostsListCommand"/>
61 - <completers>
62 - <ref component-id="hostIdCompleter"/>
63 - </completers>
64 </command> 61 </command>
65 62
63 + <command>
64 + <action class="org.onlab.onos.cli.net.WipeOutCommand"/>
65 + </command>
66 </command-bundle> 66 </command-bundle>
67 67
68 <bean id="deviceIdCompleter" class="org.onlab.onos.cli.net.DeviceIdCompleter"/> 68 <bean id="deviceIdCompleter" class="org.onlab.onos.cli.net.DeviceIdCompleter"/>
......
...@@ -2,7 +2,6 @@ package org.onlab.onos.net.flow; ...@@ -2,7 +2,6 @@ package org.onlab.onos.net.flow;
2 2
3 /** 3 /**
4 * Abstraction of a single traffic treatment step. 4 * Abstraction of a single traffic treatment step.
5 - * @param <T> the type parameter for the instruction
6 */ 5 */
7 public interface Instruction { 6 public interface Instruction {
8 7
......
...@@ -23,6 +23,7 @@ public final class Instructions { ...@@ -23,6 +23,7 @@ public final class Instructions {
23 return new OutputInstruction(number); 23 return new OutputInstruction(number);
24 } 24 }
25 25
26 + // TODO: Move these out into separate classes and to flow.instruction package
26 public static DropInstruction createDrop() { 27 public static DropInstruction createDrop() {
27 return new DropInstruction(); 28 return new DropInstruction();
28 } 29 }
...@@ -30,7 +31,6 @@ public final class Instructions { ...@@ -30,7 +31,6 @@ public final class Instructions {
30 // TODO: add create methods 31 // TODO: add create methods
31 32
32 public static final class DropInstruction implements Instruction { 33 public static final class DropInstruction implements Instruction {
33 -
34 @Override 34 @Override
35 public Type type() { 35 public Type type() {
36 return Type.DROP; 36 return Type.DROP;
...@@ -39,7 +39,6 @@ public final class Instructions { ...@@ -39,7 +39,6 @@ public final class Instructions {
39 39
40 40
41 public static final class OutputInstruction implements Instruction { 41 public static final class OutputInstruction implements Instruction {
42 -
43 private final PortNumber port; 42 private final PortNumber port;
44 43
45 private OutputInstruction(PortNumber port) { 44 private OutputInstruction(PortNumber port) {
...@@ -54,8 +53,6 @@ public final class Instructions { ...@@ -54,8 +53,6 @@ public final class Instructions {
54 public Type type() { 53 public Type type() {
55 return Type.OUTPUT; 54 return Type.OUTPUT;
56 } 55 }
57 -
58 -
59 } 56 }
60 57
61 } 58 }
......
1 +package org.onlab.onos.net.host;
2 +
3 +import org.onlab.onos.net.HostId;
4 +
5 +/**
6 + * Service for administering the inventory of end-station hosts.
7 + */
8 +public interface HostAdminService {
9 +
10 + /**
11 + * Removes the end-station host with the specified identifier.
12 + *
13 + * @param hostId host identifier
14 + */
15 + void removeHost(HostId hostId);
16 +
17 +}
...@@ -43,13 +43,15 @@ public interface PacketContext { ...@@ -43,13 +43,15 @@ public interface PacketContext {
43 43
44 /** 44 /**
45 * Blocks the outbound packet from being sent from this point onward. 45 * Blocks the outbound packet from being sent from this point onward.
46 + *
46 * @return whether the outbound packet is blocked. 47 * @return whether the outbound packet is blocked.
47 */ 48 */
48 boolean block(); 49 boolean block();
49 50
50 /** 51 /**
51 - * Check whether the outbound packet is blocked. 52 + * Indicates whether the outbound packet is handled, i.e. sent or blocked.
52 - * @return 53 + *
54 + * @return true uf the packed is handled
53 */ 55 */
54 boolean isHandled(); 56 boolean isHandled();
55 57
......
...@@ -139,8 +139,7 @@ class SimpleDeviceStore { ...@@ -139,8 +139,7 @@ class SimpleDeviceStore {
139 DeviceEvent markOffline(DeviceId deviceId) { 139 DeviceEvent markOffline(DeviceId deviceId) {
140 synchronized (this) { 140 synchronized (this) {
141 Device device = devices.get(deviceId); 141 Device device = devices.get(deviceId);
142 - checkArgument(device != null, DEVICE_NOT_FOUND, deviceId); 142 + boolean removed = device != null && availableDevices.remove(deviceId);
143 - boolean removed = availableDevices.remove(deviceId);
144 return !removed ? null : 143 return !removed ? null :
145 new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device, null); 144 new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device, null);
146 } 145 }
......
...@@ -12,6 +12,7 @@ import org.onlab.onos.net.ConnectPoint; ...@@ -12,6 +12,7 @@ import org.onlab.onos.net.ConnectPoint;
12 import org.onlab.onos.net.DeviceId; 12 import org.onlab.onos.net.DeviceId;
13 import org.onlab.onos.net.Host; 13 import org.onlab.onos.net.Host;
14 import org.onlab.onos.net.HostId; 14 import org.onlab.onos.net.HostId;
15 +import org.onlab.onos.net.host.HostAdminService;
15 import org.onlab.onos.net.host.HostDescription; 16 import org.onlab.onos.net.host.HostDescription;
16 import org.onlab.onos.net.host.HostEvent; 17 import org.onlab.onos.net.host.HostEvent;
17 import org.onlab.onos.net.host.HostListener; 18 import org.onlab.onos.net.host.HostListener;
...@@ -38,7 +39,7 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -38,7 +39,7 @@ import static org.slf4j.LoggerFactory.getLogger;
38 @Service 39 @Service
39 public class SimpleHostManager 40 public class SimpleHostManager
40 extends AbstractProviderRegistry<HostProvider, HostProviderService> 41 extends AbstractProviderRegistry<HostProvider, HostProviderService>
41 - implements HostService, HostProviderRegistry { 42 + implements HostService, HostAdminService, HostProviderRegistry {
42 43
43 public static final String HOST_ID_NULL = "Host ID cannot be null"; 44 public static final String HOST_ID_NULL = "Host ID cannot be null";
44 private final Logger log = getLogger(getClass()); 45 private final Logger log = getLogger(getClass());
...@@ -124,6 +125,16 @@ public class SimpleHostManager ...@@ -124,6 +125,16 @@ public class SimpleHostManager
124 listenerRegistry.removeListener(listener); 125 listenerRegistry.removeListener(listener);
125 } 126 }
126 127
128 + @Override
129 + public void removeHost(HostId hostId) {
130 + checkNotNull(hostId, HOST_ID_NULL);
131 + HostEvent event = store.removeHost(hostId);
132 + if (event != null) {
133 + log.info("Host {} administratively removed", hostId);
134 + post(event);
135 + }
136 + }
137 +
127 // Personalized host provider service issued to the supplied provider. 138 // Personalized host provider service issued to the supplied provider.
128 private class InternalHostProviderService 139 private class InternalHostProviderService
129 extends AbstractProviderService<HostProvider> 140 extends AbstractProviderService<HostProvider>
......
...@@ -16,6 +16,9 @@ import org.onlab.onos.event.EventDeliveryService; ...@@ -16,6 +16,9 @@ import org.onlab.onos.event.EventDeliveryService;
16 import org.onlab.onos.net.ConnectPoint; 16 import org.onlab.onos.net.ConnectPoint;
17 import org.onlab.onos.net.DeviceId; 17 import org.onlab.onos.net.DeviceId;
18 import org.onlab.onos.net.Link; 18 import org.onlab.onos.net.Link;
19 +import org.onlab.onos.net.device.DeviceEvent;
20 +import org.onlab.onos.net.device.DeviceListener;
21 +import org.onlab.onos.net.device.DeviceService;
19 import org.onlab.onos.net.link.LinkAdminService; 22 import org.onlab.onos.net.link.LinkAdminService;
20 import org.onlab.onos.net.link.LinkDescription; 23 import org.onlab.onos.net.link.LinkDescription;
21 import org.onlab.onos.net.link.LinkEvent; 24 import org.onlab.onos.net.link.LinkEvent;
...@@ -49,6 +52,10 @@ public class SimpleLinkManager ...@@ -49,6 +52,10 @@ public class SimpleLinkManager
49 listenerRegistry = new AbstractListenerRegistry<>(); 52 listenerRegistry = new AbstractListenerRegistry<>();
50 53
51 private final SimpleLinkStore store = new SimpleLinkStore(); 54 private final SimpleLinkStore store = new SimpleLinkStore();
55 + private final DeviceListener deviceListener = new InnerDeviceListener();
56 +
57 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
58 + protected DeviceService deviceService;
52 59
53 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 60 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
54 protected EventDeliveryService eventDispatcher; 61 protected EventDeliveryService eventDispatcher;
...@@ -56,12 +63,14 @@ public class SimpleLinkManager ...@@ -56,12 +63,14 @@ public class SimpleLinkManager
56 @Activate 63 @Activate
57 public void activate() { 64 public void activate() {
58 eventDispatcher.addSink(LinkEvent.class, listenerRegistry); 65 eventDispatcher.addSink(LinkEvent.class, listenerRegistry);
66 + deviceService.addListener(deviceListener);
59 log.info("Started"); 67 log.info("Started");
60 } 68 }
61 69
62 @Deactivate 70 @Deactivate
63 public void deactivate() { 71 public void deactivate() {
64 eventDispatcher.removeSink(LinkEvent.class); 72 eventDispatcher.removeSink(LinkEvent.class);
73 + deviceService.removeListener(deviceListener);
65 log.info("Stopped"); 74 log.info("Stopped");
66 } 75 }
67 76
...@@ -140,6 +149,20 @@ public class SimpleLinkManager ...@@ -140,6 +149,20 @@ public class SimpleLinkManager
140 listenerRegistry.removeListener(listener); 149 listenerRegistry.removeListener(listener);
141 } 150 }
142 151
152 + // Auxiliary interceptor for device remove events to prune links that
153 + // are associated with the removed device or its port.
154 + private class InnerDeviceListener implements DeviceListener {
155 + @Override
156 + public void event(DeviceEvent event) {
157 + if (event.type() == DeviceEvent.Type.DEVICE_REMOVED) {
158 + removeLinks(event.subject().id());
159 + } else if (event.type() == DeviceEvent.Type.PORT_REMOVED) {
160 + removeLinks(new ConnectPoint(event.subject().id(),
161 + event.port().number()));
162 + }
163 + }
164 + }
165 +
143 @Override 166 @Override
144 protected LinkProviderService createProviderService(LinkProvider provider) { 167 protected LinkProviderService createProviderService(LinkProvider provider) {
145 return new InternalLinkProviderService(provider); 168 return new InternalLinkProviderService(provider);
......
...@@ -22,6 +22,7 @@ import org.onlab.onos.net.link.LinkService; ...@@ -22,6 +22,7 @@ import org.onlab.onos.net.link.LinkService;
22 import org.onlab.onos.net.provider.AbstractProvider; 22 import org.onlab.onos.net.provider.AbstractProvider;
23 import org.onlab.onos.net.provider.ProviderId; 23 import org.onlab.onos.net.provider.ProviderId;
24 import org.onlab.onos.event.impl.TestEventDispatcher; 24 import org.onlab.onos.event.impl.TestEventDispatcher;
25 +import org.onlab.onos.net.trivial.device.impl.SimpleDeviceManager;
25 26
26 import java.util.ArrayList; 27 import java.util.ArrayList;
27 import java.util.Iterator; 28 import java.util.Iterator;
...@@ -65,6 +66,7 @@ public class SimpleLinkManagerTest { ...@@ -65,6 +66,7 @@ public class SimpleLinkManagerTest {
65 admin = mgr; 66 admin = mgr;
66 registry = mgr; 67 registry = mgr;
67 mgr.eventDispatcher = new TestEventDispatcher(); 68 mgr.eventDispatcher = new TestEventDispatcher();
69 + mgr.deviceService = new SimpleDeviceManager();
68 mgr.activate(); 70 mgr.activate();
69 71
70 service.addListener(listener); 72 service.addListener(listener);
......