Implement rerouting feature in PathCalcRuntimeModule

Change-Id: Ie37ebd1fa6910e999d457481d7082adb0d1d9a3a
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/LinkEvent.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/LinkEvent.java
index c8cf71e..83af786 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/LinkEvent.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/LinkEvent.java
@@ -24,18 +24,23 @@
 
     public LinkEvent(Long src_dpid, Long src_port_no, Long dst_dpid,
 	    Long dst_port_no) {
-
 	src = new SwitchPort(src_dpid, src_port_no);
 	dst = new SwitchPort(dst_dpid, dst_port_no);
+    }
 
+    public LinkEvent(Link link) {
+	src = new SwitchPort(link.getSourceSwitch().getDpid(),
+		link.getSourcePort().getNumber());
+	dst = new SwitchPort(link.getDestinationSwitch().getDpid(),
+		link.getDestinationPort().getNumber());
     }
 
     public SwitchPort getSrc() {
-        return src;
+	return src;
     }
 
     public SwitchPort getDst() {
-        return dst;
+	return dst;
     }
 
     @Override
@@ -54,6 +59,47 @@
 
     public byte[] getID() {
 	return getLinkID(src.getDpid(), src.getNumber(),
-			 dst.getDpid(), dst.getNumber());
+		dst.getDpid(), dst.getNumber());
     }
-}
+
+    public Link getLink(NetworkGraph graph) {
+	Port srcPort = graph.getPort(getSrc().getDpid(), getSrc().getNumber());
+	if (srcPort == null) return null;
+	Link link = srcPort.getOutgoingLink();
+	if (link == null) return null;
+	if (link.getDestinationSwitch().getDpid() != getDst().getDpid()) return null;
+	if (link.getDestinationPort().getNumber() != getDst().getNumber()) return null;
+	return link;
+    }
+
+    @Override
+    public int hashCode() {
+	final int prime = 31;
+	int result = 1;
+	result = prime * result + ((dst == null) ? 0 : dst.hashCode());
+	result = prime * result + ((src == null) ? 0 : src.hashCode());
+	return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+	if (this == obj)
+	    return true;
+	if (obj == null)
+	    return false;
+	if (getClass() != obj.getClass())
+	    return false;
+	LinkEvent other = (LinkEvent) obj;
+	if (dst == null) {
+	    if (other.dst != null)
+		return false;
+	} else if (!dst.equals(other.dst))
+	    return false;
+	if (src == null) {
+	    if (other.src != null)
+		return false;
+	} else if (!src.equals(other.src))
+	    return false;
+	return true;
+    }
+}
\ No newline at end of file