alshabib
Committed by Gerrit Code Review

when a switch vapourizes so must its ports

Change-Id: Ibcbcc47f691c24897985978a39da9dba6411ba2a

disable a port which is deleted

Change-Id: Ic6e0cb0a9901a6589b587aeb89bfc1b302d17516
......@@ -25,6 +25,8 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import com.google.common.collect.Lists;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
......@@ -46,6 +48,7 @@ import org.onlab.onos.net.MastershipRole;
import org.onlab.onos.net.Port;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.device.DefaultDeviceDescription;
import org.onlab.onos.net.device.DefaultPortDescription;
import org.onlab.onos.net.device.DeviceAdminService;
import org.onlab.onos.net.device.DeviceClockProviderService;
import org.onlab.onos.net.device.DeviceDescription;
......@@ -330,6 +333,13 @@ public class DeviceManager
log.info("Device {} disconnected from this node", deviceId);
DeviceEvent event = null;
List<Port> ports = store.getPorts(deviceId);
List<PortDescription> descs = Lists.newArrayList();
ports.forEach(port ->
descs.add(new DefaultPortDescription(port.number(),
false, port.type(),
port.portSpeed())));
store.updatePorts(this.provider().id(), deviceId, descs);
try {
event = store.markOffline(deviceId);
} catch (IllegalStateException e) {
......
......@@ -46,6 +46,7 @@ import org.projectfloodlight.openflow.protocol.OFFactory;
import org.projectfloodlight.openflow.protocol.OFPortConfig;
import org.projectfloodlight.openflow.protocol.OFPortDesc;
import org.projectfloodlight.openflow.protocol.OFPortFeatures;
import org.projectfloodlight.openflow.protocol.OFPortReason;
import org.projectfloodlight.openflow.protocol.OFPortState;
import org.projectfloodlight.openflow.protocol.OFPortStatus;
import org.projectfloodlight.openflow.protocol.OFVersion;
......@@ -242,7 +243,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
@Override
public void portChanged(Dpid dpid, OFPortStatus status) {
PortDescription portDescription = buildPortDescription(status.getDesc());
PortDescription portDescription = buildPortDescription(status);
providerService.portStatusChanged(deviceId(uri(dpid)), portDescription);
}
......@@ -303,6 +304,17 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
return new DefaultPortDescription(portNo, enabled, type, portSpeed(port));
}
private PortDescription buildPortDescription(OFPortStatus status) {
OFPortDesc port = status.getDesc();
if (status.getReason() != OFPortReason.DELETE) {
return buildPortDescription(port);
} else {
PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER;
return new DefaultPortDescription(portNo, false, type, portSpeed(port));
}
}
private long portSpeed(OFPortDesc port) {
if (port.getVersion() == OFVersion.OF_13) {
return port.getCurrSpeed() / MBPS;
......