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