Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.intent; |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 2 | |
Jonathan Hart | a88fd24 | 2014-04-03 11:24:54 -0700 | [diff] [blame] | 3 | import static org.junit.Assert.assertEquals; |
| 4 | import static org.junit.Assert.assertNotNull; |
| 5 | import static org.junit.Assert.assertNull; |
Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 6 | import net.onrc.onos.core.intent.IntentOperation.Operator; |
Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 7 | import net.onrc.onos.core.topology.LinkEvent; |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame] | 8 | import net.onrc.onos.core.topology.MockTopology; |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 9 | |
| 10 | import org.junit.After; |
| 11 | import org.junit.Before; |
| 12 | import org.junit.Test; |
| 13 | |
| 14 | /** |
Yuta HIGUCHI | d4acc80 | 2014-06-19 22:30:31 -0700 | [diff] [blame] | 15 | * Unit tests for ConstrainedBFSTree class. |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 16 | */ |
| 17 | public class ConstrainedBFSTreeTest { |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 18 | static final long LOCAL_PORT = 0xFFFEL; |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 19 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 20 | @Before |
| 21 | public void setUp() throws Exception { |
| 22 | } |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 23 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 24 | @After |
| 25 | public void tearDown() throws Exception { |
| 26 | } |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 27 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 28 | @Test |
| 29 | public void testCreate() { |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 30 | MockTopology topology = new MockTopology(); |
| 31 | topology.createSampleTopology1(); |
| 32 | ConstrainedBFSTree tree = new ConstrainedBFSTree(topology.getSwitch(1L)); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 33 | assertNotNull(tree); |
| 34 | } |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 35 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 36 | @Test |
| 37 | public void testCreateConstrained() { |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 38 | MockTopology topology = new MockTopology(); |
| 39 | topology.createSampleTopology1(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 40 | PathIntentMap intents = new PathIntentMap(); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 41 | ConstrainedBFSTree tree = new ConstrainedBFSTree(topology.getSwitch(1L), intents, 1000.0); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 42 | assertNotNull(tree); |
| 43 | } |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 44 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 45 | @Test |
| 46 | public void testGetPath() { |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 47 | MockTopology topology = new MockTopology(); |
| 48 | topology.createSampleTopology1(); |
| 49 | ConstrainedBFSTree tree = new ConstrainedBFSTree(topology.getSwitch(1L)); |
| 50 | Path path11 = tree.getPath(topology.getSwitch(1L)); |
| 51 | Path path12 = tree.getPath(topology.getSwitch(2L)); |
| 52 | Path path13 = tree.getPath(topology.getSwitch(3L)); |
| 53 | Path path14 = tree.getPath(topology.getSwitch(4L)); |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 54 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 55 | assertNotNull(path11); |
| 56 | assertEquals(0, path11.size()); |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 57 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 58 | assertNotNull(path12); |
| 59 | assertEquals(1, path12.size()); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 60 | assertEquals(new LinkEvent(topology.getOutgoingLink(1L, 12L)), path12.get(0)); |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 61 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 62 | assertNotNull(path13); |
| 63 | assertEquals(2, path13.size()); |
| 64 | if (path13.get(0).getDst().getDpid() == 2L) { |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 65 | assertEquals(new LinkEvent(topology.getOutgoingLink(1L, 12L)), path13.get(0)); |
| 66 | assertEquals(new LinkEvent(topology.getOutgoingLink(2L, 23L)), path13.get(1)); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 67 | } else { |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 68 | assertEquals(new LinkEvent(topology.getOutgoingLink(1L, 14L)), path13.get(0)); |
| 69 | assertEquals(new LinkEvent(topology.getOutgoingLink(4L, 43L)), path13.get(1)); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 70 | } |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 71 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 72 | assertNotNull(path14); |
| 73 | assertEquals(1, path14.size()); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 74 | assertEquals(new LinkEvent(topology.getOutgoingLink(1L, 14L)), path14.get(0)); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 75 | } |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 76 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 77 | @Test |
| 78 | public void testGetPathNull() { |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 79 | MockTopology topology = new MockTopology(); |
| 80 | topology.createSampleTopology1(); |
| 81 | topology.removeLink(1L, 12L, 2L, 21L); |
| 82 | topology.removeLink(1L, 14L, 4L, 41L); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 83 | // now, there is no path from switch 1, but to switch1 |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 84 | |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 85 | ConstrainedBFSTree tree1 = new ConstrainedBFSTree(topology.getSwitch(1L)); |
| 86 | Path path12 = tree1.getPath(topology.getSwitch(2L)); |
| 87 | Path path13 = tree1.getPath(topology.getSwitch(3L)); |
| 88 | Path path14 = tree1.getPath(topology.getSwitch(4L)); |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 89 | |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 90 | ConstrainedBFSTree tree2 = new ConstrainedBFSTree(topology.getSwitch(2L)); |
| 91 | Path path21 = tree2.getPath(topology.getSwitch(1L)); |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 92 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 93 | assertNull(path12); |
| 94 | assertNull(path13); |
| 95 | assertNull(path14); |
| 96 | assertNotNull(path21); |
| 97 | assertEquals(1, path21.size()); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 98 | assertEquals(new LinkEvent(topology.getOutgoingLink(2L, 21L)), path21.get(0)); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 99 | } |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 100 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 101 | @Test |
| 102 | public void testGetConstrainedPath() { |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 103 | MockTopology topology = new MockTopology(); |
| 104 | topology.createSampleTopology1(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 105 | PathIntentMap intents = new PathIntentMap(); |
| 106 | IntentOperationList intentOps = new IntentOperationList(); |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 107 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 108 | // create constrained shortest path intents that have the same source destination ports |
| 109 | ConstrainedShortestPathIntent intent1 = new ConstrainedShortestPathIntent( |
| 110 | "1", 1L, LOCAL_PORT, 0x111L, 2L, LOCAL_PORT, 0x222L, 600.0); |
| 111 | ConstrainedShortestPathIntent intent2 = new ConstrainedShortestPathIntent( |
| 112 | "2", 1L, LOCAL_PORT, 0x333L, 2L, LOCAL_PORT, 0x444L, 600.0); |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 113 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 114 | // calculate path of the intent1 |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 115 | ConstrainedBFSTree tree = new ConstrainedBFSTree(topology.getSwitch(1L), intents, 600.0); |
| 116 | Path path1 = tree.getPath(topology.getSwitch(2L)); |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 117 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 118 | assertNotNull(path1); |
| 119 | assertEquals(1, path1.size()); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 120 | assertEquals(new LinkEvent(topology.getOutgoingLink(1L, 12L)), path1.get(0)); |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 121 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 122 | PathIntent pathIntent1 = new PathIntent("pi1", path1, 600.0, intent1); |
| 123 | intentOps.add(Operator.ADD, pathIntent1); |
| 124 | intents.executeOperations(intentOps); |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 125 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 126 | // calculate path of the intent2 |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 127 | tree = new ConstrainedBFSTree(topology.getSwitch(1L), intents, 600.0); |
| 128 | Path path2 = tree.getPath(topology.getSwitch(2L)); |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 129 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 130 | assertNotNull(path2); |
| 131 | assertEquals(2, path2.size()); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 132 | assertEquals(new LinkEvent(topology.getOutgoingLink(1L, 14L)), path2.get(0)); |
| 133 | assertEquals(new LinkEvent(topology.getOutgoingLink(4L, 42L)), path2.get(1)); |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 134 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 135 | PathIntent pathIntent2 = new PathIntent("pi2", path2, 600.0, intent2); |
| 136 | intentOps.add(Operator.ADD, pathIntent2); |
| 137 | intents.executeOperations(intentOps); |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 138 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 139 | // calculate path of the intent3 |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 140 | tree = new ConstrainedBFSTree(topology.getSwitch(1L), intents, 600.0); |
| 141 | Path path3 = tree.getPath(topology.getSwitch(2L)); |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 142 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 143 | assertNull(path3); |
| 144 | } |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 145 | } |