portStatusChanged implemented
diff --git a/of/api/src/main/java/org/onlab/onos/of/controller/OpenFlowSwitchListener.java b/of/api/src/main/java/org/onlab/onos/of/controller/OpenFlowSwitchListener.java
index 7ccba6d..ae5e3a8 100644
--- a/of/api/src/main/java/org/onlab/onos/of/controller/OpenFlowSwitchListener.java
+++ b/of/api/src/main/java/org/onlab/onos/of/controller/OpenFlowSwitchListener.java
@@ -1,5 +1,7 @@
package org.onlab.onos.of.controller;
+import org.projectfloodlight.openflow.protocol.OFPortStatus;
+
/**
* Allows for providers interested in Switch events to be notified.
*/
@@ -17,4 +19,10 @@
*/
public void switchRemoved(Dpid dpid);
+ /**
+ * Notify that a port has changed.
+ * @param dpid the switch on which the change happened.
+ * @param status the new state of the port.
+ */
+ public void portChanged(Dpid dpid, OFPortStatus status);
}
diff --git a/providers/of/device/src/main/java/org/onlab/onos/provider/of/device/impl/OpenFlowDeviceProvider.java b/providers/of/device/src/main/java/org/onlab/onos/provider/of/device/impl/OpenFlowDeviceProvider.java
index 1740f4b..2309de4 100644
--- a/providers/of/device/src/main/java/org/onlab/onos/provider/of/device/impl/OpenFlowDeviceProvider.java
+++ b/providers/of/device/src/main/java/org/onlab/onos/provider/of/device/impl/OpenFlowDeviceProvider.java
@@ -33,6 +33,7 @@
import org.projectfloodlight.openflow.protocol.OFPortConfig;
import org.projectfloodlight.openflow.protocol.OFPortDesc;
import org.projectfloodlight.openflow.protocol.OFPortState;
+import org.projectfloodlight.openflow.protocol.OFPortStatus;
import org.slf4j.Logger;
/**
@@ -130,6 +131,18 @@
providerService.deviceDisconnected(deviceId(uri));
}
+ @Override
+ public void portChanged(Dpid dpid, OFPortStatus status) {
+ final PortDescription portDescription = buildPortDescription(status.getDesc());
+ final URI uri = buildURI(dpid);
+ providerService.portStatusChanged(deviceId(uri), portDescription);
+ }
+
+ /**
+ * Given a dpid builds a URI for the device.
+ * @param dpid the dpid to build the uri from
+ * @return returns a uri of the form of:<dpidHexForm>
+ */
private URI buildURI(Dpid dpid) {
URI uri = null;
try {
@@ -140,21 +153,31 @@
return uri;
}
+ /**
+ * Builds a list of port descriptions for a given list of ports.
+ * @param ports the list of ports
+ * @return list of portdescriptions
+ */
private List<PortDescription> buildPortDescriptions(
List<OFPortDesc> ports) {
final List<PortDescription> portDescs = new ArrayList<PortDescription>();
- PortNumber portNo;
- boolean enabled;
for (OFPortDesc port : ports) {
- portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
- enabled = !port.getState().contains(OFPortState.LINK_DOWN) &&
- !port.getConfig().contains(OFPortConfig.PORT_DOWN);
- portDescs.add(new DefaultPortDescription(portNo,
- enabled));
+ portDescs.add(buildPortDescription(port));
}
return portDescs;
}
+ /**
+ * Build a portDescription from a given port.
+ * @param port the port to build from.
+ * @return portDescription for the port.
+ */
+ private PortDescription buildPortDescription(OFPortDesc port) {
+ final PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
+ final boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) &&
+ !port.getConfig().contains(OFPortConfig.PORT_DOWN);
+ return new DefaultPortDescription(portNo, enabled);
+ }
}
}