* Added new method LinkStorageImpl.getReverseLinks(Long dpid, short port)
* Fixed a bug inside method LinkStorageImpl.getLinks(Long dpid, short port) :
add an explicit "null" pointer check.
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/ILinkStorage.java b/src/main/java/net/onrc/onos/ofcontroller/core/ILinkStorage.java
index c8312d4..8889092 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/ILinkStorage.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/ILinkStorage.java
@@ -44,6 +44,14 @@
*/
public List<Link> getLinks(Long dpid, short port);
+ /**
+ * Get list of all reverse links connected to the port specified by given DPID and port number.
+ * @param dpid DPID of desired port.
+ * @param port Port number of desired port.
+ * @return List of reverse links. Empty list if no port was found.
+ */
+ public List<Link> getReverseLinks(Long dpid, short port);
+
public List<Link> getLinks(String dpid);
/**
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java b/src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java
index 09e87ca..cd8f9ad 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java
@@ -235,12 +235,42 @@
if(srcSw != null && srcPort != null) {
for(IPortObject dstPort : srcPort.getLinkedPorts()) {
ISwitchObject dstSw = dstPort.getSwitch();
- Link link = new Link(HexString.toLong(srcSw.getDPID()),
- srcPort.getNumber(),
- HexString.toLong(dstSw.getDPID()),
- dstPort.getNumber());
-
- links.add(link);
+ if (dstSw != null) {
+ Link link = new Link(HexString.toLong(srcSw.getDPID()),
+ srcPort.getNumber(),
+ HexString.toLong(dstSw.getDPID()),
+ dstPort.getNumber());
+ links.add(link);
+ }
+ }
+ }
+
+ return links;
+ }
+
+ /**
+ * Get list of all reverse links connected to the port specified by given DPID and port number.
+ * @param dpid DPID of desired port.
+ * @param port Port number of desired port.
+ * @return List of reverse links. Empty list if no port was found.
+ */
+ @Override
+ public List<Link> getReverseLinks(Long dpid, short port) {
+ List<Link> links = new ArrayList<Link>();
+
+ IPortObject srcPort = op.searchPort(HexString.toHexString(dpid), port);
+ ISwitchObject srcSw = srcPort.getSwitch();
+
+ if(srcSw != null && srcPort != null) {
+ for(IPortObject dstPort : srcPort.getReverseLinkedPorts()) {
+ ISwitchObject dstSw = dstPort.getSwitch();
+ if (dstSw != null) {
+ Link link = new Link(HexString.toLong(dstSw.getDPID()),
+ dstPort.getNumber(),
+ HexString.toLong(srcSw.getDPID()),
+ srcPort.getNumber());
+ links.add(link);
+ }
}
}