alshabib

stoppign starting works nicely

1 package org.onlab.onos.of.drivers.impl; 1 package org.onlab.onos.of.drivers.impl;
2 2
3 +import java.util.Collections;
3 import java.util.List; 4 import java.util.List;
4 import java.util.concurrent.atomic.AtomicBoolean; 5 import java.util.concurrent.atomic.AtomicBoolean;
5 6
...@@ -135,7 +136,7 @@ public class OFSwitchImplOVS13 extends AbstractOpenFlowSwitch { ...@@ -135,7 +136,7 @@ public class OFSwitchImplOVS13 extends AbstractOpenFlowSwitch {
135 136
136 @Override 137 @Override
137 public void write(OFMessage msg) { 138 public void write(OFMessage msg) {
138 - channel.write(msg); 139 + channel.write(Collections.singletonList(msg));
139 140
140 } 141 }
141 142
......
...@@ -14,6 +14,7 @@ import org.apache.felix.scr.annotations.Deactivate; ...@@ -14,6 +14,7 @@ import org.apache.felix.scr.annotations.Deactivate;
14 import org.apache.felix.scr.annotations.Reference; 14 import org.apache.felix.scr.annotations.Reference;
15 import org.apache.felix.scr.annotations.ReferenceCardinality; 15 import org.apache.felix.scr.annotations.ReferenceCardinality;
16 import org.onlab.onos.net.Device; 16 import org.onlab.onos.net.Device;
17 +import org.onlab.onos.net.DeviceId;
17 import org.onlab.onos.net.MastershipRole; 18 import org.onlab.onos.net.MastershipRole;
18 import org.onlab.onos.net.PortNumber; 19 import org.onlab.onos.net.PortNumber;
19 import org.onlab.onos.net.device.DefaultDeviceDescription; 20 import org.onlab.onos.net.device.DefaultDeviceDescription;
...@@ -66,14 +67,22 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr ...@@ -66,14 +67,22 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
66 public void activate() { 67 public void activate() {
67 providerService = providerRegistry.register(this); 68 providerService = providerRegistry.register(this);
68 controller.addListener(listener); 69 controller.addListener(listener);
70 + for (OpenFlowSwitch sw : controller.getSwitches()) {
71 + listener.switchAdded(new Dpid(sw.getId()));
72 + }
69 LOG.info("Started"); 73 LOG.info("Started");
70 } 74 }
71 75
72 @Deactivate 76 @Deactivate
73 public void deactivate() { 77 public void deactivate() {
78 + for (OpenFlowSwitch sw : controller.getSwitches()) {
79 + providerService.deviceDisconnected(DeviceId.deviceId("of:"
80 + + Long.toHexString(sw.getId())));
81 + }
74 providerRegistry.unregister(this); 82 providerRegistry.unregister(this);
75 controller.removeListener(listener); 83 controller.removeListener(listener);
76 providerService = null; 84 providerService = null;
85 +
77 LOG.info("Stopped"); 86 LOG.info("Stopped");
78 } 87 }
79 88
......
...@@ -86,6 +86,7 @@ public class LinkDiscovery implements TimerTask { ...@@ -86,6 +86,7 @@ public class LinkDiscovery implements TimerTask {
86 private final OpenFlowController ctrl; 86 private final OpenFlowController ctrl;
87 private final LinkProviderService linkProvider; 87 private final LinkProviderService linkProvider;
88 private final Map<Integer, OFPortDesc> ports; 88 private final Map<Integer, OFPortDesc> ports;
89 + private Timeout timeout;
89 90
90 /** 91 /**
91 * Instantiates discovery manager for the given physical switch. Creates a 92 * Instantiates discovery manager for the given physical switch. Creates a
...@@ -127,7 +128,7 @@ public class LinkDiscovery implements TimerTask { ...@@ -127,7 +128,7 @@ public class LinkDiscovery implements TimerTask {
127 addPort(port); 128 addPort(port);
128 } 129 }
129 } 130 }
130 - Timer.getTimer().newTimeout(this, this.probeRate, 131 + timeout = Timer.getTimer().newTimeout(this, this.probeRate,
131 TimeUnit.MILLISECONDS); 132 TimeUnit.MILLISECONDS);
132 this.log.debug("Started discovery manager for switch {}", 133 this.log.debug("Started discovery manager for switch {}",
133 sw.getId()); 134 sw.getId());
...@@ -186,6 +187,10 @@ public class LinkDiscovery implements TimerTask { ...@@ -186,6 +187,10 @@ public class LinkDiscovery implements TimerTask {
186 portnum); 187 portnum);
187 } 188 }
188 } 189 }
190 + ConnectPoint cp = new ConnectPoint(
191 + DeviceId.deviceId("of:" + Long.toHexString(sw.getId())),
192 + PortNumber.portNumber(port.getPortNo().getPortNumber()));
193 + linkProvider.linksVanished(cp);
189 194
190 } 195 }
191 196
...@@ -380,14 +385,19 @@ public class LinkDiscovery implements TimerTask { ...@@ -380,14 +385,19 @@ public class LinkDiscovery implements TimerTask {
380 } 385 }
381 386
382 // reschedule timer 387 // reschedule timer
383 - Timer.getTimer().newTimeout(this, this.probeRate, 388 + timeout = Timer.getTimer().newTimeout(this, this.probeRate,
384 TimeUnit.MILLISECONDS); 389 TimeUnit.MILLISECONDS);
385 } 390 }
386 391
387 public void removeAllPorts() { 392 public void removeAllPorts() {
388 - for (OFPortDesc port : sw.getPorts()) { 393 + for (OFPortDesc port : ports.values()) {
389 removePort(port); 394 removePort(port);
390 } 395 }
391 } 396 }
392 397
398 + public void stop() {
399 + removeAllPorts();
400 + timeout.cancel();
401 + }
402 +
393 } 403 }
......
...@@ -10,9 +10,7 @@ import org.apache.felix.scr.annotations.Component; ...@@ -10,9 +10,7 @@ import org.apache.felix.scr.annotations.Component;
10 import org.apache.felix.scr.annotations.Deactivate; 10 import org.apache.felix.scr.annotations.Deactivate;
11 import org.apache.felix.scr.annotations.Reference; 11 import org.apache.felix.scr.annotations.Reference;
12 import org.apache.felix.scr.annotations.ReferenceCardinality; 12 import org.apache.felix.scr.annotations.ReferenceCardinality;
13 -import org.onlab.onos.net.ConnectPoint;
14 import org.onlab.onos.net.DeviceId; 13 import org.onlab.onos.net.DeviceId;
15 -import org.onlab.onos.net.PortNumber;
16 import org.onlab.onos.net.link.LinkProvider; 14 import org.onlab.onos.net.link.LinkProvider;
17 import org.onlab.onos.net.link.LinkProviderRegistry; 15 import org.onlab.onos.net.link.LinkProviderRegistry;
18 import org.onlab.onos.net.link.LinkProviderService; 16 import org.onlab.onos.net.link.LinkProviderService;
...@@ -20,10 +18,10 @@ import org.onlab.onos.net.provider.AbstractProvider; ...@@ -20,10 +18,10 @@ import org.onlab.onos.net.provider.AbstractProvider;
20 import org.onlab.onos.net.provider.ProviderId; 18 import org.onlab.onos.net.provider.ProviderId;
21 import org.onlab.onos.of.controller.Dpid; 19 import org.onlab.onos.of.controller.Dpid;
22 import org.onlab.onos.of.controller.OpenFlowController; 20 import org.onlab.onos.of.controller.OpenFlowController;
21 +import org.onlab.onos.of.controller.OpenFlowSwitch;
23 import org.onlab.onos.of.controller.OpenFlowSwitchListener; 22 import org.onlab.onos.of.controller.OpenFlowSwitchListener;
24 import org.onlab.onos.of.controller.PacketContext; 23 import org.onlab.onos.of.controller.PacketContext;
25 import org.onlab.onos.of.controller.PacketListener; 24 import org.onlab.onos.of.controller.PacketListener;
26 -import org.onlab.timer.Timer;
27 import org.projectfloodlight.openflow.protocol.OFPortConfig; 25 import org.projectfloodlight.openflow.protocol.OFPortConfig;
28 import org.projectfloodlight.openflow.protocol.OFPortDesc; 26 import org.projectfloodlight.openflow.protocol.OFPortDesc;
29 import org.projectfloodlight.openflow.protocol.OFPortState; 27 import org.projectfloodlight.openflow.protocol.OFPortState;
...@@ -51,6 +49,8 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid ...@@ -51,6 +49,8 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid
51 49
52 private final InternalLinkProvider listener = new InternalLinkProvider(); 50 private final InternalLinkProvider listener = new InternalLinkProvider();
53 51
52 + private final Map<Dpid, LinkDiscovery> discoverers = new ConcurrentHashMap<>();
53 +
54 /** 54 /**
55 * Creates an OpenFlow link provider. 55 * Creates an OpenFlow link provider.
56 */ 56 */
...@@ -63,23 +63,28 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid ...@@ -63,23 +63,28 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid
63 providerService = providerRegistry.register(this); 63 providerService = providerRegistry.register(this);
64 controller.addListener(listener); 64 controller.addListener(listener);
65 controller.addPacketListener(0, listener); 65 controller.addPacketListener(0, listener);
66 + for (OpenFlowSwitch sw : controller.getSwitches()) {
67 + listener.switchAdded(new Dpid(sw.getId()));
68 + }
66 log.info("Started"); 69 log.info("Started");
67 } 70 }
68 71
69 @Deactivate 72 @Deactivate
70 public void deactivate() { 73 public void deactivate() {
74 + for (LinkDiscovery ld : discoverers.values()) {
75 + ld.stop();
76 + }
71 providerRegistry.unregister(this); 77 providerRegistry.unregister(this);
72 controller.removeListener(listener); 78 controller.removeListener(listener);
73 controller.removePacketListener(listener); 79 controller.removePacketListener(listener);
74 providerService = null; 80 providerService = null;
75 - Timer.getTimer().stop(); 81 +
76 log.info("Stopped"); 82 log.info("Stopped");
77 } 83 }
78 84
79 85
80 private class InternalLinkProvider implements PacketListener, OpenFlowSwitchListener { 86 private class InternalLinkProvider implements PacketListener, OpenFlowSwitchListener {
81 87
82 - private final Map<Dpid, LinkDiscovery> discoverers = new ConcurrentHashMap<>();
83 88
84 @Override 89 @Override
85 public void handlePacket(PacketContext pktCtx) { 90 public void handlePacket(PacketContext pktCtx) {
...@@ -102,7 +107,7 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid ...@@ -102,7 +107,7 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid
102 107
103 @Override 108 @Override
104 public void switchRemoved(Dpid dpid) { 109 public void switchRemoved(Dpid dpid) {
105 - LinkDiscovery ld = this.discoverers.remove(dpid); 110 + LinkDiscovery ld = discoverers.remove(dpid);
106 if (ld != null) { 111 if (ld != null) {
107 ld.removeAllPorts(); 112 ld.removeAllPorts();
108 } 113 }
...@@ -122,10 +127,9 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid ...@@ -122,10 +127,9 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid
122 if (enabled) { 127 if (enabled) {
123 ld.addPort(port); 128 ld.addPort(port);
124 } else { 129 } else {
125 - ConnectPoint cp = new ConnectPoint( 130 + /*
126 - DeviceId.deviceId("of:" + Long.toHexString(dpid.value())), 131 + * remove port calls linkVanished
127 - PortNumber.portNumber(port.getPortNo().getPortNumber())); 132 + */
128 - providerService.linksVanished(cp);
129 ld.removePort(port); 133 ld.removePort(port);
130 } 134 }
131 135
......