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