Implement rerouting feature in PathCalcRuntimeModule
Change-Id: Ie37ebd1fa6910e999d457481d7082adb0d1d9a3a
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/Link.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/Link.java
index ef74f73..4fd53af 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/Link.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/Link.java
@@ -12,7 +12,7 @@
public Port getDestinationPort();
public Switch getSourceSwitch();
public Switch getDestinationSwitch();
-
+
public long getLastSeenTime();
public int getCost();
@@ -21,8 +21,12 @@
// Not sure if we want to expose these northbound
// Toshi: I think these are unnecessary because we can get them
// Toshi: like "this.getSourcePort().getSwitch()" etc.
+ @Deprecated
public Long getSourceSwitchDpid();
+ @Deprecated
public Long getSourcePortNumber();
+ @Deprecated
public Long getDestinationSwitchDpid();
+ @Deprecated
public Long getDestinationPortNumber();
}
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
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/LinkImpl.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/LinkImpl.java
index c8954a9..801e780 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/LinkImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/LinkImpl.java
@@ -76,39 +76,43 @@
}
@Override
+ public Double getCapacity() {
+ return capacity;
+ }
+
+ public void setCapacity(Double capacity) {
+ this.capacity = capacity;
+ }
+
+ @Deprecated
+ @Override
public Long getSourceSwitchDpid() {
return srcPort.getSwitch().getDpid();
}
+ @Deprecated
@Override
public Long getSourcePortNumber() {
return srcPort.getNumber();
}
+ @Deprecated
@Override
public Long getDestinationSwitchDpid() {
return dstPort.getSwitch().getDpid();
}
+ @Deprecated
@Override
public Long getDestinationPortNumber() {
return dstPort.getNumber();
}
@Override
- public Double getCapacity() {
- return capacity;
- }
-
- @Override
public String toString() {
return String.format("%s --(cap:%f Mbps)--> %s",
getSourcePort().toString(),
getCapacity(),
getDestinationPort().toString());
}
-
- public void setCapacity(Double capacity) {
- this.capacity = capacity;
- }
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/PortEvent.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/PortEvent.java
index b42bf1e..8172f29 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/PortEvent.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/PortEvent.java
@@ -10,8 +10,8 @@
*/
public class PortEvent {
public static class SwitchPort {
- public final Long dpid;
- public final Long number;
+ public final Long dpid;
+ public final Long number;
/**
* Default constructor.
@@ -39,6 +39,37 @@
return "(" + Long.toHexString(dpid) + "@" + number + ")";
}
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((dpid == null) ? 0 : dpid.hashCode());
+ result = prime * result
+ + ((number == null) ? 0 : number.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;
+ SwitchPort other = (SwitchPort) obj;
+ if (dpid == null) {
+ if (other.dpid != null)
+ return false;
+ } else if (!dpid.equals(other.dpid))
+ return false;
+ if (number == null) {
+ if (other.number != null)
+ return false;
+ } else if (!number.equals(other.number))
+ return false;
+ return true;
+ }
}
private final SwitchPort id;