Add id field to Intent classes
Change-Id: If3938446de9b65f84e7bbe1a9f5adb8b26de475a
diff --git a/src/main/java/net/onrc/onos/intent/ConstrainedShortestPathIntent.java b/src/main/java/net/onrc/onos/intent/ConstrainedShortestPathIntent.java
index c5db590..b659179 100644
--- a/src/main/java/net/onrc/onos/intent/ConstrainedShortestPathIntent.java
+++ b/src/main/java/net/onrc/onos/intent/ConstrainedShortestPathIntent.java
@@ -10,19 +10,19 @@
public class ConstrainedShortestPathIntent extends ShortestPathIntent {
protected Double bandwidth;
- public ConstrainedShortestPathIntent(
+ public ConstrainedShortestPathIntent(String id,
Port srcPort, MACAddress srcMac,
Port dstPort, MACAddress dstMac,
Double bandwidth) {
- super(srcPort, srcMac, dstPort, dstMac);
+ super(id, srcPort, srcMac, dstPort, dstMac);
this.bandwidth = bandwidth;
}
- public ConstrainedShortestPathIntent(NetworkGraph graph,
- Long srcSwitch, Long srcPort, long srcMac,
- Long dstSwitch, Long dstPort, long dstMac,
+ public ConstrainedShortestPathIntent(NetworkGraph graph, String id,
+ long srcSwitch, long srcPort, long srcMac,
+ long dstSwitch, long dstPort, long dstMac,
Double bandwidth) {
- super(graph, srcSwitch, srcPort, srcMac, dstSwitch, dstPort, dstMac);
+ super(graph, id, srcSwitch, srcPort, srcMac, dstSwitch, dstPort, dstMac);
this.bandwidth = bandwidth;
}
diff --git a/src/main/java/net/onrc/onos/intent/Intent.java b/src/main/java/net/onrc/onos/intent/Intent.java
index 33888ae..823b106 100644
--- a/src/main/java/net/onrc/onos/intent/Intent.java
+++ b/src/main/java/net/onrc/onos/intent/Intent.java
@@ -4,4 +4,18 @@
* @author Toshio Koide (t-koide@onlab.us)
*/
public abstract class Intent {
+ protected String id;
+
+ public Intent(String id) {
+ this.id = id;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ @Override
+ public int hashCode() {
+ return id.hashCode();
+ }
}
diff --git a/src/main/java/net/onrc/onos/intent/PathIntent.java b/src/main/java/net/onrc/onos/intent/PathIntent.java
index 22948b9..07f53e1 100644
--- a/src/main/java/net/onrc/onos/intent/PathIntent.java
+++ b/src/main/java/net/onrc/onos/intent/PathIntent.java
@@ -9,6 +9,7 @@
protected Path path;
protected Double bandwidth;
protected Intent parentIntent;
+ protected int id;
/**
*
@@ -17,8 +18,10 @@
* @param bandwidth bandwidth which should be allocated for the path.
* If null, it means no intent for bandwidth allocation (best effort).
* @param parentIntent parent intent. If null, it means this is root intent.
+ * @param id
*/
- public PathIntent(Path path, Double bandwidth, Intent parentIntent) {
+ public PathIntent(String id, Path path, Double bandwidth, Intent parentIntent) {
+ super(id);
this.path = path;
this.bandwidth = bandwidth;
this.parentIntent = parentIntent;
diff --git a/src/main/java/net/onrc/onos/intent/ShortestPathIntent.java b/src/main/java/net/onrc/onos/intent/ShortestPathIntent.java
index e7f1a13..b1f58f5 100644
--- a/src/main/java/net/onrc/onos/intent/ShortestPathIntent.java
+++ b/src/main/java/net/onrc/onos/intent/ShortestPathIntent.java
@@ -13,18 +13,20 @@
protected MACAddress srcMac = null;
protected MACAddress dstMac = null;
- public ShortestPathIntent(
+ public ShortestPathIntent(String id,
Port srcPort, MACAddress srcMac,
Port dstPort, MACAddress dstMac) {
+ super(id);
this.srcPort = srcPort;
this.dstPort = dstPort;
this.srcMac = srcMac;
this.dstMac = dstMac;
}
- public ShortestPathIntent(NetworkGraph graph,
- Long srcSwitch, Long srcPort, long srcMac,
- Long dstSwitch, Long dstPort, long dstMac) {
+ public ShortestPathIntent(NetworkGraph graph, String id,
+ long srcSwitch, long srcPort, long srcMac,
+ long dstSwitch, long dstPort, long dstMac) {
+ super(id);
this.srcPort = graph.getSwitch(srcSwitch).getPort(srcPort);
this.dstPort = graph.getSwitch(dstSwitch).getPort(srcPort);
this.srcMac = MACAddress.valueOf(srcMac);
diff --git a/src/main/java/net/onrc/onos/intent/runtime/PathCalcRuntime.java b/src/main/java/net/onrc/onos/intent/runtime/PathCalcRuntime.java
index 3e09f8c..60cf10d 100644
--- a/src/main/java/net/onrc/onos/intent/runtime/PathCalcRuntime.java
+++ b/src/main/java/net/onrc/onos/intent/runtime/PathCalcRuntime.java
@@ -73,7 +73,7 @@
continue;
}
- pathIntents.addIntent(new PathIntent(path, bandwidth, intent));
+ pathIntents.addIntent(new PathIntent("pi" + intent.getId(), path, bandwidth, intent));
}
return pathIntents;
}
diff --git a/src/test/java/net/onrc/onos/intent/runtime/UseCaseTest.java b/src/test/java/net/onrc/onos/intent/runtime/UseCaseTest.java
index 8f7b02f..93aa8ab 100644
--- a/src/test/java/net/onrc/onos/intent/runtime/UseCaseTest.java
+++ b/src/test/java/net/onrc/onos/intent/runtime/UseCaseTest.java
@@ -114,9 +114,9 @@
public void useCase1() {
// create shortest path intents
LinkedList<Intent> intents = new LinkedList<Intent>();
- intents.add(new ShortestPathIntent(g, 1L, 20L, 1L, 4L, 20L, 4L));
- intents.add(new ShortestPathIntent(g, 2L, 20L, 2L, 6L, 20L, 5L));
- intents.add(new ShortestPathIntent(g, 4L, 20L, 3L, 8L, 20L, 6L));
+ intents.add(new ShortestPathIntent(g, "1", 1L, 20L, 1L, 4L, 20L, 4L));
+ intents.add(new ShortestPathIntent(g, "2", 2L, 20L, 2L, 6L, 20L, 5L));
+ intents.add(new ShortestPathIntent(g, "3", 4L, 20L, 3L, 8L, 20L, 6L));
// compile high-level intents into low-level intents (calculate paths)
PathCalcRuntime runtime1 = new PathCalcRuntime(g);
@@ -130,11 +130,11 @@
public void useCase2() {
// create constrained shortest path intents
LinkedList<Intent> intents = new LinkedList<Intent>();
- intents.add(new ConstrainedShortestPathIntent(g, 1L, 20L, 1L, 4L, 20L, 17L, 400.0));
- intents.add(new ConstrainedShortestPathIntent(g, 2L, 20L, 2L, 6L, 20L, 18L, 400.0));
- intents.add(new ConstrainedShortestPathIntent(g, 4L, 20L, 3L, 8L, 20L, 19L, 400.0));
- intents.add(new ConstrainedShortestPathIntent(g, 3L, 20L, 4L, 8L, 20L, 20L, 400.0));
- intents.add(new ConstrainedShortestPathIntent(g, 4L, 20L, 5L, 8L, 20L, 21L, 400.0));
+ intents.add(new ConstrainedShortestPathIntent(g, "1", 1L, 20L, 1L, 4L, 20L, 17L, 400.0));
+ intents.add(new ConstrainedShortestPathIntent(g, "2", 2L, 20L, 2L, 6L, 20L, 18L, 400.0));
+ intents.add(new ConstrainedShortestPathIntent(g, "3", 4L, 20L, 3L, 8L, 20L, 19L, 400.0));
+ intents.add(new ConstrainedShortestPathIntent(g, "4", 3L, 20L, 4L, 8L, 20L, 20L, 400.0));
+ intents.add(new ConstrainedShortestPathIntent(g, "5", 4L, 20L, 5L, 8L, 20L, 21L, 400.0));
// compile high-level intents into low-level intents (calculate paths)
PathCalcRuntime runtime1 = new PathCalcRuntime(g);
@@ -148,11 +148,11 @@
public void useCase3() {
// create constrained & not best effort shortest path intents
LinkedList<Intent> intents = new LinkedList<Intent>();
- intents.add(new ConstrainedShortestPathIntent(g, 1L, 20L, 1L, 4L, 20L, 6L, 600.0));
- intents.add(new ConstrainedShortestPathIntent(g, 2L, 20L, 2L, 6L, 20L, 7L, 600.0));
- intents.add(new ShortestPathIntent(g, 4L, 20L, 3L, 8L, 20L, 8L));
- intents.add(new ShortestPathIntent(g, 4L, 20L, 4L, 8L, 20L, 9L));
- intents.add(new ConstrainedShortestPathIntent(g, 4L, 20L, 5L, 8L, 20L, 10L, 600.0));
+ intents.add(new ConstrainedShortestPathIntent(g, "1", 1L, 20L, 1L, 4L, 20L, 6L, 600.0));
+ intents.add(new ConstrainedShortestPathIntent(g, "2", 2L, 20L, 2L, 6L, 20L, 7L, 600.0));
+ intents.add(new ShortestPathIntent(g, "3", 4L, 20L, 3L, 8L, 20L, 8L));
+ intents.add(new ShortestPathIntent(g, "4", 4L, 20L, 4L, 8L, 20L, 9L));
+ intents.add(new ConstrainedShortestPathIntent(g, "5", 4L, 20L, 5L, 8L, 20L, 10L, 600.0));
// compile high-level intents into low-level intents (calculate paths)
PathCalcRuntime runtime1 = new PathCalcRuntime(g);