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