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