Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.intent; |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 2 | |
Toshio Koide | d9fa2a8 | 2014-02-19 17:35:18 -0800 | [diff] [blame] | 3 | import static org.junit.Assert.assertEquals; |
Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 4 | import net.onrc.onos.core.topology.LinkEvent; |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 5 | import net.onrc.onos.core.util.Dpid; |
| 6 | import net.onrc.onos.core.util.PortNumber; |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 7 | import net.onrc.onos.core.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 | |
Toshio Koide | 066506e | 2014-02-20 19:52:09 -0800 | [diff] [blame] | 17 | /** |
Yuta HIGUCHI | d4acc80 | 2014-06-19 22:30:31 -0700 | [diff] [blame] | 18 | * Unit tests for PathIntent. |
Toshio Koide | 066506e | 2014-02-20 19:52:09 -0800 | [diff] [blame] | 19 | */ |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 20 | public class PathIntentTest { |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 21 | |
| 22 | private static final Dpid DPID_1 = new Dpid(1L); |
| 23 | private static final Dpid DPID_2 = new Dpid(2L); |
| 24 | private static final Dpid DPID_3 = new Dpid(3L); |
| 25 | private static final Dpid DPID_4 = new Dpid(4L); |
| 26 | |
| 27 | private static final PortNumber PORT_NUMBER_1 = new PortNumber((short) 1); |
| 28 | private static final PortNumber PORT_NUMBER_2 = new PortNumber((short) 2); |
| 29 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 30 | @Before |
| 31 | public void setUp() throws Exception { |
| 32 | } |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 33 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 34 | @After |
| 35 | public void tearDown() throws Exception { |
| 36 | } |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 37 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 38 | @Test |
| 39 | public void testCreateFirstId() { |
| 40 | String id = PathIntent.createFirstId("100"); |
| 41 | assertEquals("100___0", id); |
| 42 | } |
Toshio Koide | a10c037 | 2014-02-20 17:28:10 -0800 | [diff] [blame] | 43 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 44 | @Test |
| 45 | public void testCreateNextId() { |
| 46 | String id = PathIntent.createNextId("100___999"); |
| 47 | assertEquals("100___1000", id); |
| 48 | } |
Toshio Koide | a10c037 | 2014-02-20 17:28:10 -0800 | [diff] [blame] | 49 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 50 | @Test |
| 51 | public void test() { |
| 52 | KryoFactory factory = new KryoFactory(); |
| 53 | Kryo kryo = factory.newKryo(); |
| 54 | Output output = new Output(1024); |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 55 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 56 | ConstrainedShortestPathIntent cspIntent1 = |
| 57 | new ConstrainedShortestPathIntent("1", 2L, 3L, 4L, 5L, 6L, 7L, 1000.0); |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 58 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 59 | Path path = new Path(); |
| 60 | path.add(new LinkEvent(1L, 1L, 2L, 2L)); |
| 61 | path.add(new LinkEvent(2L, 1L, 3L, 2L)); |
| 62 | path.add(new LinkEvent(3L, 1L, 4L, 2L)); |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 63 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 64 | PathIntent pathIntent1 = new PathIntent("11", path, 123.45, cspIntent1); |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 65 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 66 | kryo.writeObject(output, pathIntent1); |
| 67 | output.close(); |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 68 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 69 | Input input = new Input(output.toBytes()); |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 70 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 71 | // create pathIntent from bytes |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 72 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 73 | PathIntent pathIntent2 = |
| 74 | kryo.readObject(input, PathIntent.class); |
| 75 | input.close(); |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 76 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 77 | // check |
Toshio Koide | d9fa2a8 | 2014-02-19 17:35:18 -0800 | [diff] [blame] | 78 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 79 | assertEquals("11", pathIntent2.getId()); |
| 80 | Path path2 = pathIntent2.getPath(); |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 81 | |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 82 | assertEquals(DPID_1, path2.get(0).getSrc().getDpid()); |
Yuta HIGUCHI | b1e2ab7 | 2014-06-30 11:01:31 -0700 | [diff] [blame] | 83 | assertEquals(PORT_NUMBER_1, path2.get(0).getSrc().getPortNumber()); |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 84 | assertEquals(DPID_2, path2.get(0).getDst().getDpid()); |
Yuta HIGUCHI | b1e2ab7 | 2014-06-30 11:01:31 -0700 | [diff] [blame] | 85 | assertEquals(PORT_NUMBER_2, path2.get(0).getDst().getPortNumber()); |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 86 | |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 87 | assertEquals(DPID_2, path2.get(1).getSrc().getDpid()); |
Yuta HIGUCHI | b1e2ab7 | 2014-06-30 11:01:31 -0700 | [diff] [blame] | 88 | assertEquals(PORT_NUMBER_1, path2.get(1).getSrc().getPortNumber()); |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 89 | assertEquals(DPID_3, path2.get(1).getDst().getDpid()); |
Yuta HIGUCHI | b1e2ab7 | 2014-06-30 11:01:31 -0700 | [diff] [blame] | 90 | assertEquals(PORT_NUMBER_2, path2.get(1).getDst().getPortNumber()); |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 91 | |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 92 | assertEquals(DPID_3, path2.get(2).getSrc().getDpid()); |
Yuta HIGUCHI | b1e2ab7 | 2014-06-30 11:01:31 -0700 | [diff] [blame] | 93 | assertEquals(PORT_NUMBER_1, path2.get(2).getSrc().getPortNumber()); |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 94 | assertEquals(DPID_4, path2.get(2).getDst().getDpid()); |
Yuta HIGUCHI | b1e2ab7 | 2014-06-30 11:01:31 -0700 | [diff] [blame] | 95 | assertEquals(PORT_NUMBER_2, path2.get(2).getDst().getPortNumber()); |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 96 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 97 | assertEquals(123.45, pathIntent2.getBandwidth(), 0.0); |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 98 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 99 | ConstrainedShortestPathIntent cspIntent2 = |
| 100 | (ConstrainedShortestPathIntent) pathIntent2.getParentIntent(); |
Toshio Koide | d9fa2a8 | 2014-02-19 17:35:18 -0800 | [diff] [blame] | 101 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 102 | assertEquals("1", cspIntent2.getId()); |
| 103 | assertEquals(2L, cspIntent2.getSrcSwitchDpid()); |
| 104 | assertEquals(3L, cspIntent2.getSrcPortNumber()); |
| 105 | assertEquals(4L, cspIntent2.getSrcMac()); |
| 106 | assertEquals(5L, cspIntent2.getDstSwitchDpid()); |
| 107 | assertEquals(6L, cspIntent2.getDstPortNumber()); |
| 108 | assertEquals(7L, cspIntent2.getDstMac()); |
| 109 | assertEquals(1000.0, cspIntent2.getBandwidth(), 0.0); |
| 110 | } |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 111 | } |