Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 1 | package net.onrc.onos.intent; |
| 2 | |
| 3 | import static org.junit.Assert.*; |
| 4 | import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph; |
| 5 | import net.onrc.onos.ofcontroller.networkgraph.Path; |
| 6 | |
| 7 | import org.junit.After; |
| 8 | import org.junit.Before; |
| 9 | import org.junit.Test; |
| 10 | |
| 11 | import com.esotericsoftware.kryo.Kryo; |
| 12 | import com.esotericsoftware.kryo.io.Input; |
| 13 | import com.esotericsoftware.kryo.io.Output; |
| 14 | |
| 15 | public class PathIntentTest { |
| 16 | NetworkGraph g; |
| 17 | |
| 18 | @Before |
| 19 | public void setUp() throws Exception { |
| 20 | MockNetworkGraph graph = new MockNetworkGraph(); |
| 21 | graph.createSampleTopology(); |
| 22 | g = graph; |
| 23 | } |
| 24 | |
| 25 | @After |
| 26 | public void tearDown() throws Exception { |
| 27 | } |
| 28 | |
| 29 | @Test |
| 30 | public void test() { |
| 31 | Kryo kryo = new Kryo(); |
| 32 | Output output = new Output(1024); |
| 33 | |
| 34 | ConstrainedShortestPathIntent cspIntent1 = |
| 35 | new ConstrainedShortestPathIntent("1", 2L, 3L, 4L, 5L, 6L, 7L, 1000.0); |
| 36 | |
| 37 | Path path = new Path(); |
| 38 | path.add(g.getSwitch(1L).getPort(1L).getOutgoingLink()); |
| 39 | path.add(g.getSwitch(2L).getPort(1L).getOutgoingLink()); |
| 40 | path.add(g.getSwitch(3L).getPort(1L).getOutgoingLink()); |
| 41 | |
| 42 | PathIntent pathIntent1 = new PathIntent("11", path, 123.45, cspIntent1); |
| 43 | |
| 44 | kryo.writeObject(output, pathIntent1); |
| 45 | output.close(); |
| 46 | |
| 47 | Input input = new Input(output.toBytes()); |
| 48 | |
| 49 | // create pathIntent from bytes |
| 50 | |
| 51 | PathIntent pathIntent2 = |
| 52 | kryo.readObject(input, PathIntent.class); |
| 53 | input.close(); |
| 54 | |
| 55 | // check |
| 56 | |
| 57 | assertEquals("11", pathIntent2.getId()); |
| 58 | Path path2 = pathIntent2.getPath(g); |
| 59 | |
| 60 | assertEquals(Long.valueOf(1L), path2.get(0).getSourceSwitch().getDpid()); |
| 61 | assertEquals(Long.valueOf(1L), path2.get(0).getSourcePort().getNumber()); |
| 62 | assertEquals(Long.valueOf(2L), path2.get(0).getDestinationSwitch().getDpid()); |
| 63 | assertEquals(Long.valueOf(2L), path2.get(0).getDestinationPort().getNumber()); |
| 64 | |
| 65 | assertEquals(Long.valueOf(2L), path2.get(1).getSourceSwitch().getDpid()); |
| 66 | assertEquals(Long.valueOf(1L), path2.get(1).getSourcePort().getNumber()); |
| 67 | assertEquals(Long.valueOf(3L), path2.get(1).getDestinationSwitch().getDpid()); |
| 68 | assertEquals(Long.valueOf(2L), path2.get(1).getDestinationPort().getNumber()); |
| 69 | |
| 70 | assertEquals(Long.valueOf(3L), path2.get(2).getSourceSwitch().getDpid()); |
| 71 | assertEquals(Long.valueOf(1L), path2.get(2).getSourcePort().getNumber()); |
| 72 | assertEquals(Long.valueOf(4L), path2.get(2).getDestinationSwitch().getDpid()); |
| 73 | assertEquals(Long.valueOf(2L), path2.get(2).getDestinationPort().getNumber()); |
| 74 | |
| 75 | assertEquals(123.45, pathIntent2.getBandwidth(), 0.0); |
| 76 | |
| 77 | ConstrainedShortestPathIntent cspIntent2 = |
| 78 | (ConstrainedShortestPathIntent) pathIntent2.getParentIntent(); |
| 79 | |
| 80 | assertEquals("1", cspIntent2.getId()); |
| 81 | assertEquals(2L, cspIntent2.getSrcSwitchDpid()); |
| 82 | assertEquals(3L, cspIntent2.getSrcPortNumber()); |
| 83 | assertEquals(4L, cspIntent2.getSrcMac()); |
| 84 | assertEquals(5L, cspIntent2.getDstSwitchDpid()); |
| 85 | assertEquals(6L, cspIntent2.getDstPortNumber()); |
| 86 | assertEquals(7L, cspIntent2.getDstMac()); |
| 87 | assertEquals(1000.0, cspIntent2.getBandwidth(), 0.0); |
| 88 | } |
| 89 | } |