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