alshabib

stoppign starting works nicely

package org.onlab.onos.of.drivers.impl;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
......@@ -135,7 +136,7 @@ public class OFSwitchImplOVS13 extends AbstractOpenFlowSwitch {
@Override
public void write(OFMessage msg) {
channel.write(msg);
channel.write(Collections.singletonList(msg));
}
......
......@@ -14,6 +14,7 @@ import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.onos.net.Device;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.MastershipRole;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.device.DefaultDeviceDescription;
......@@ -66,14 +67,22 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
public void activate() {
providerService = providerRegistry.register(this);
controller.addListener(listener);
for (OpenFlowSwitch sw : controller.getSwitches()) {
listener.switchAdded(new Dpid(sw.getId()));
}
LOG.info("Started");
}
@Deactivate
public void deactivate() {
for (OpenFlowSwitch sw : controller.getSwitches()) {
providerService.deviceDisconnected(DeviceId.deviceId("of:"
+ Long.toHexString(sw.getId())));
}
providerRegistry.unregister(this);
controller.removeListener(listener);
providerService = null;
LOG.info("Stopped");
}
......
......@@ -86,6 +86,7 @@ public class LinkDiscovery implements TimerTask {
private final OpenFlowController ctrl;
private final LinkProviderService linkProvider;
private final Map<Integer, OFPortDesc> ports;
private Timeout timeout;
/**
* Instantiates discovery manager for the given physical switch. Creates a
......@@ -127,7 +128,7 @@ public class LinkDiscovery implements TimerTask {
addPort(port);
}
}
Timer.getTimer().newTimeout(this, this.probeRate,
timeout = Timer.getTimer().newTimeout(this, this.probeRate,
TimeUnit.MILLISECONDS);
this.log.debug("Started discovery manager for switch {}",
sw.getId());
......@@ -186,6 +187,10 @@ public class LinkDiscovery implements TimerTask {
portnum);
}
}
ConnectPoint cp = new ConnectPoint(
DeviceId.deviceId("of:" + Long.toHexString(sw.getId())),
PortNumber.portNumber(port.getPortNo().getPortNumber()));
linkProvider.linksVanished(cp);
}
......@@ -380,14 +385,19 @@ public class LinkDiscovery implements TimerTask {
}
// reschedule timer
Timer.getTimer().newTimeout(this, this.probeRate,
timeout = Timer.getTimer().newTimeout(this, this.probeRate,
TimeUnit.MILLISECONDS);
}
public void removeAllPorts() {
for (OFPortDesc port : sw.getPorts()) {
for (OFPortDesc port : ports.values()) {
removePort(port);
}
}
public void stop() {
removeAllPorts();
timeout.cancel();
}
}
......
......@@ -10,9 +10,7 @@ import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.link.LinkProvider;
import org.onlab.onos.net.link.LinkProviderRegistry;
import org.onlab.onos.net.link.LinkProviderService;
......@@ -20,10 +18,10 @@ import org.onlab.onos.net.provider.AbstractProvider;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.of.controller.Dpid;
import org.onlab.onos.of.controller.OpenFlowController;
import org.onlab.onos.of.controller.OpenFlowSwitch;
import org.onlab.onos.of.controller.OpenFlowSwitchListener;
import org.onlab.onos.of.controller.PacketContext;
import org.onlab.onos.of.controller.PacketListener;
import org.onlab.timer.Timer;
import org.projectfloodlight.openflow.protocol.OFPortConfig;
import org.projectfloodlight.openflow.protocol.OFPortDesc;
import org.projectfloodlight.openflow.protocol.OFPortState;
......@@ -51,6 +49,8 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid
private final InternalLinkProvider listener = new InternalLinkProvider();
private final Map<Dpid, LinkDiscovery> discoverers = new ConcurrentHashMap<>();
/**
* Creates an OpenFlow link provider.
*/
......@@ -63,23 +63,28 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid
providerService = providerRegistry.register(this);
controller.addListener(listener);
controller.addPacketListener(0, listener);
for (OpenFlowSwitch sw : controller.getSwitches()) {
listener.switchAdded(new Dpid(sw.getId()));
}
log.info("Started");
}
@Deactivate
public void deactivate() {
for (LinkDiscovery ld : discoverers.values()) {
ld.stop();
}
providerRegistry.unregister(this);
controller.removeListener(listener);
controller.removePacketListener(listener);
providerService = null;
Timer.getTimer().stop();
log.info("Stopped");
}
private class InternalLinkProvider implements PacketListener, OpenFlowSwitchListener {
private final Map<Dpid, LinkDiscovery> discoverers = new ConcurrentHashMap<>();
@Override
public void handlePacket(PacketContext pktCtx) {
......@@ -102,7 +107,7 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid
@Override
public void switchRemoved(Dpid dpid) {
LinkDiscovery ld = this.discoverers.remove(dpid);
LinkDiscovery ld = discoverers.remove(dpid);
if (ld != null) {
ld.removeAllPorts();
}
......@@ -122,10 +127,9 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid
if (enabled) {
ld.addPort(port);
} else {
ConnectPoint cp = new ConnectPoint(
DeviceId.deviceId("of:" + Long.toHexString(dpid.value())),
PortNumber.portNumber(port.getPortNo().getPortNumber()));
providerService.linksVanished(cp);
/*
* remove port calls linkVanished
*/
ld.removePort(port);
}
......