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