Added new method SwitchStorageImpl.getPorts(String dpid) to get the
ports for a switch.
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java b/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
index b7825f9..1c243c0 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
@@ -1,5 +1,7 @@
package net.onrc.onos.ofcontroller.core;
+import java.util.List;
+
import net.floodlightcontroller.core.IOFSwitch;
import org.openflow.protocol.OFPhysicalPort;
@@ -43,4 +45,12 @@
* Delete a port on a switch by num
*/
public boolean deletePort(String dpid, short port);
+
+ /**
+ * Get list of all ports on the switch specified by given DPID.
+ *
+ * @param dpid DPID of desired switch.
+ * @return List of port IDs. Empty list if no port was found.
+ */
+ public List<Short> getPorts(String dpid);
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java b/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java
index a6277cf..65c7ec5 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java
@@ -1,5 +1,8 @@
package net.onrc.onos.ofcontroller.core.internal;
+import java.util.ArrayList;
+import java.util.List;
+
import net.floodlightcontroller.core.IOFSwitch;
import net.onrc.onos.graph.GraphDBConnection;
import net.onrc.onos.graph.GraphDBOperation;
@@ -316,6 +319,26 @@
return success;
}
+ /**
+ * Get list of all ports on the switch specified by given DPID.
+ *
+ * @param dpid DPID of desired switch.
+ * @return List of port IDs. Empty list if no port was found.
+ */
+ @Override
+ public List<Short> getPorts(String dpid) {
+ List<Short> ports = new ArrayList<Short>();
+
+ ISwitchObject srcSw = op.searchSwitch(dpid);
+ if (srcSw != null) {
+ for (IPortObject srcPort : srcSw.getPorts()) {
+ ports.add(srcPort.getNumber());
+ }
+ }
+
+ return ports;
+ }
+
private ISwitchObject addSwitchImpl(String dpid) {
if (dpid != null) {
ISwitchObject sw = op.newSwitch(dpid);