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