Change Intent classes to self contained
Change-Id: I0def86a280646983efb98dbe5937b93b4c9a4885
diff --git a/src/test/java/net/onrc/onos/intent/ConstrainedShortestPathIntentTest.java b/src/test/java/net/onrc/onos/intent/ConstrainedShortestPathIntentTest.java
index 8160ca8..354e053 100644
--- a/src/test/java/net/onrc/onos/intent/ConstrainedShortestPathIntentTest.java
+++ b/src/test/java/net/onrc/onos/intent/ConstrainedShortestPathIntentTest.java
@@ -2,10 +2,15 @@
import static org.junit.Assert.*;
import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
public class ConstrainedShortestPathIntentTest {
NetworkGraph g;
@@ -22,21 +27,27 @@
@Test
public void test() {
+ Kryo kryo = new Kryo();
+ Output output = new Output(1024);
+
ConstrainedShortestPathIntent intent1 =
- new ConstrainedShortestPathIntent(g, "1", 1L, 20L, 1L, 4L, 20L, 4L, 1000.0);
+ new ConstrainedShortestPathIntent("1", 2L, 3L, 4L, 5L, 6L, 7L, 1000.0);
- byte b[] = intent1.toBytes();
+ kryo.writeObject(output, intent1);
+ output.close();
+ Input input = new Input(output.toBytes());
ConstrainedShortestPathIntent intent2 =
- ConstrainedShortestPathIntent.fromBytes(g, b);
+ kryo.readObject(input, ConstrainedShortestPathIntent.class);
+ input.close();
assertEquals("1", intent2.getId());
- assertEquals(Long.valueOf(1), intent2.getSourcePort().getSwitch().getDpid());
- assertEquals(Long.valueOf(20), intent2.getSourcePort().getNumber());
- assertEquals(1L, intent2.getSourceMac().toLong());
- assertEquals(Long.valueOf(4), intent2.getDestinationPort().getSwitch().getDpid());
- assertEquals(Long.valueOf(20), intent2.getDestinationPort().getNumber());
- assertEquals(4L, intent2.getDestinationMac().toLong());
- assertEquals(Double.valueOf(1000.0), intent2.getBandwidth());
+ assertEquals(2L, intent2.getSrcSwitchDpid());
+ assertEquals(3L, intent2.getSrcPortNumber());
+ assertEquals(4L, intent2.getSrcMac());
+ assertEquals(5L, intent2.getDstSwitchDpid());
+ assertEquals(6L, intent2.getDstPortNumber());
+ assertEquals(7L, intent2.getDstMac());
+ assertEquals(1000.0, intent2.getBandwidth(), 0.0);
}
}
diff --git a/src/test/java/net/onrc/onos/intent/ShortestPathIntentTest.java b/src/test/java/net/onrc/onos/intent/ShortestPathIntentTest.java
index a0da341..e325be8 100644
--- a/src/test/java/net/onrc/onos/intent/ShortestPathIntentTest.java
+++ b/src/test/java/net/onrc/onos/intent/ShortestPathIntentTest.java
@@ -2,10 +2,15 @@
import static org.junit.Assert.*;
import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
public class ShortestPathIntentTest {
NetworkGraph g;
@@ -22,21 +27,26 @@
@Test
public void test() {
+ Kryo kryo = new Kryo();
+ Output output = new Output(1024);
+
ShortestPathIntent intent1 =
- new ShortestPathIntent(g, "1", 1L, 20L, 1L, 4L, 20L, 4L);
+ new ShortestPathIntent("1", 2L, 3L, 4L, 5L, 6L, 7L);
- byte b[] = intent1.toBytes();
+ kryo.writeObject(output, intent1);
+ output.close();
+ Input input = new Input(output.toBytes());
ShortestPathIntent intent2 =
- ShortestPathIntent.fromBytes(g, b);
+ kryo.readObject(input, ShortestPathIntent.class);
+ input.close();
assertEquals("1", intent2.getId());
- assertEquals(Long.valueOf(1), intent2.getSourcePort().getSwitch().getDpid());
- assertEquals(Long.valueOf(20), intent2.getSourcePort().getNumber());
- assertEquals(1L, intent2.getSourceMac().toLong());
- assertEquals(Long.valueOf(4), intent2.getDestinationPort().getSwitch().getDpid());
- assertEquals(Long.valueOf(20), intent2.getDestinationPort().getNumber());
- assertEquals(4L, intent2.getDestinationMac().toLong());
+ assertEquals(2L, intent2.getSrcSwitchDpid());
+ assertEquals(3L, intent2.getSrcPortNumber());
+ assertEquals(4L, intent2.getSrcMac());
+ assertEquals(5L, intent2.getDstSwitchDpid());
+ assertEquals(6L, intent2.getDstPortNumber());
+ assertEquals(7L, intent2.getDstMac());
}
-
}
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 73eee6b..554aece 100644
--- a/src/test/java/net/onrc/onos/intent/runtime/UseCaseTest.java
+++ b/src/test/java/net/onrc/onos/intent/runtime/UseCaseTest.java
@@ -49,9 +49,9 @@
public void useCase1() {
// create shortest path intents
LinkedList<Intent> intents = new LinkedList<Intent>();
- 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));
+ intents.add(new ShortestPathIntent("1", 1L, 20L, 1L, 4L, 20L, 4L));
+ intents.add(new ShortestPathIntent("2", 2L, 20L, 2L, 6L, 20L, 5L));
+ intents.add(new ShortestPathIntent("3", 4L, 20L, 3L, 8L, 20L, 6L));
// compile high-level intents into low-level intents (calculate paths)
PathCalcRuntime runtime1 = new PathCalcRuntime(g);
@@ -65,11 +65,11 @@
public void useCase2() {
// create constrained shortest path intents
LinkedList<Intent> intents = new LinkedList<Intent>();
- 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));
+ intents.add(new ConstrainedShortestPathIntent("1", 1L, 20L, 1L, 4L, 20L, 17L, 400.0));
+ intents.add(new ConstrainedShortestPathIntent("2", 2L, 20L, 2L, 6L, 20L, 18L, 400.0));
+ intents.add(new ConstrainedShortestPathIntent("3", 4L, 20L, 3L, 8L, 20L, 19L, 400.0));
+ intents.add(new ConstrainedShortestPathIntent("4", 3L, 20L, 4L, 8L, 20L, 20L, 400.0));
+ intents.add(new ConstrainedShortestPathIntent("5", 4L, 20L, 5L, 8L, 20L, 21L, 400.0));
// compile high-level intents into low-level intents (calculate paths)
PathCalcRuntime runtime1 = new PathCalcRuntime(g);
@@ -83,11 +83,11 @@
public void useCase3() {
// create constrained & not best effort shortest path intents
LinkedList<Intent> intents = new LinkedList<Intent>();
- 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));
+ intents.add(new ConstrainedShortestPathIntent("1", 1L, 20L, 1L, 4L, 20L, 6L, 600.0));
+ intents.add(new ConstrainedShortestPathIntent("2", 2L, 20L, 2L, 6L, 20L, 7L, 600.0));
+ intents.add(new ShortestPathIntent("3", 4L, 20L, 3L, 8L, 20L, 8L));
+ intents.add(new ShortestPathIntent("4", 4L, 20L, 4L, 8L, 20L, 9L));
+ intents.add(new ConstrainedShortestPathIntent("5", 4L, 20L, 5L, 8L, 20L, 10L, 600.0));
// compile high-level intents into low-level intents (calculate paths)
PathCalcRuntime runtime1 = new PathCalcRuntime(g);