Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.intent.runtime; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 2 | |
Jonathan Hart | a88fd24 | 2014-04-03 11:24:54 -0700 | [diff] [blame] | 3 | import static org.easymock.EasyMock.anyObject; |
| 4 | import static org.easymock.EasyMock.createMock; |
| 5 | import static org.easymock.EasyMock.eq; |
| 6 | import static org.easymock.EasyMock.expect; |
| 7 | import static org.easymock.EasyMock.expectLastCall; |
| 8 | import static org.easymock.EasyMock.replay; |
| 9 | import static org.easymock.EasyMock.verify; |
Toshio Koide | 066506e | 2014-02-20 19:52:09 -0800 | [diff] [blame] | 10 | |
Pavlin Radoslavov | 74986ce | 2014-02-20 13:17:20 -0800 | [diff] [blame] | 11 | import java.util.LinkedList; |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 12 | import java.util.List; |
| 13 | import java.util.Set; |
| 14 | |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 15 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 16 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
Pavlin Radoslavov | 1366905 | 2014-05-13 10:33:39 -0700 | [diff] [blame] | 17 | import net.floodlightcontroller.restserver.IRestApiService; |
Jonathan Hart | 6df9017 | 2014-04-03 10:13:11 -0700 | [diff] [blame] | 18 | import net.onrc.onos.core.datagrid.IDatagridService; |
| 19 | import net.onrc.onos.core.datagrid.IEventChannel; |
| 20 | import net.onrc.onos.core.datagrid.IEventChannelListener; |
Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 21 | import net.onrc.onos.core.intent.ConstrainedShortestPathIntent; |
| 22 | import net.onrc.onos.core.intent.FlowEntry; |
| 23 | import net.onrc.onos.core.intent.Intent; |
Jonathan Hart | a88fd24 | 2014-04-03 11:24:54 -0700 | [diff] [blame] | 24 | import net.onrc.onos.core.intent.Intent.IntentState; |
| 25 | import net.onrc.onos.core.intent.IntentOperation.Operator; |
Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 26 | import net.onrc.onos.core.intent.IntentOperationList; |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 27 | import net.onrc.onos.core.intent.MockTopology; |
Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 28 | import net.onrc.onos.core.intent.PathIntent; |
| 29 | import net.onrc.onos.core.intent.PathIntentMap; |
| 30 | import net.onrc.onos.core.intent.ShortestPathIntent; |
Pavlin Radoslavov | 1366905 | 2014-05-13 10:33:39 -0700 | [diff] [blame] | 31 | import net.onrc.onos.core.intent.runtime.web.IntentWebRoutable; |
Jonathan Hart | deda0ba | 2014-04-03 11:14:12 -0700 | [diff] [blame] | 32 | import net.onrc.onos.core.registry.IControllerRegistryService; |
Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 33 | import net.onrc.onos.core.topology.DeviceEvent; |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 34 | import net.onrc.onos.core.topology.ITopologyListener; |
| 35 | import net.onrc.onos.core.topology.ITopologyService; |
Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 36 | import net.onrc.onos.core.topology.LinkEvent; |
Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 37 | import net.onrc.onos.core.topology.PortEvent; |
| 38 | import net.onrc.onos.core.topology.SwitchEvent; |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 39 | import net.onrc.onos.core.topology.Topology; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 40 | |
| 41 | import org.junit.After; |
| 42 | import org.junit.Before; |
| 43 | import org.junit.Test; |
Nick Karanatsios | 8abe717 | 2014-02-19 20:31:48 -0800 | [diff] [blame] | 44 | import org.junit.runner.RunWith; |
| 45 | import org.powermock.api.easymock.PowerMock; |
| 46 | import org.powermock.core.classloader.annotations.PrepareForTest; |
| 47 | import org.powermock.modules.junit4.PowerMockRunner; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 48 | |
| 49 | /** |
Toshio Koide | e04a9df | 2014-05-01 15:49:28 -0700 | [diff] [blame] | 50 | * Temporary test cases for the ONS2014 demo. |
| 51 | * These test cases should be modified and be moved to appropriate classes |
| 52 | * (ex. PathCalcRuntimeModuleTest, PlanInstallModuleTest, etc.) |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 53 | */ |
Nick Karanatsios | 8abe717 | 2014-02-19 20:31:48 -0800 | [diff] [blame] | 54 | @RunWith(PowerMockRunner.class) |
| 55 | @PrepareForTest(PathCalcRuntimeModule.class) |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 56 | public class UseCaseTest { |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 57 | private Topology topology; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 58 | private FloodlightModuleContext modContext; |
| 59 | private IDatagridService datagridService; |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 60 | private ITopologyService topologyService; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 61 | private IControllerRegistryService controllerRegistryService; |
| 62 | private PersistIntent persistIntent; |
Pavlin Radoslavov | 1366905 | 2014-05-13 10:33:39 -0700 | [diff] [blame] | 63 | private IRestApiService restApi; |
Toshio Koide | e04a9df | 2014-05-01 15:49:28 -0700 | [diff] [blame] | 64 | private IEventChannel<Long, IntentOperationList> intentOperationChannel; |
| 65 | private IEventChannel<Long, IntentStateList> intentStateChannel; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 66 | |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 67 | private static final Long LOCAL_PORT = 0xFFFEL; |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 68 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 69 | @SuppressWarnings("unchecked") |
| 70 | @Before |
| 71 | public void setUp() throws Exception { |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 72 | MockTopology mockTopology = new MockTopology(); |
| 73 | mockTopology.createSampleTopology1(); |
| 74 | this.topology = mockTopology; |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 75 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 76 | datagridService = createMock(IDatagridService.class); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 77 | topologyService = createMock(ITopologyService.class); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 78 | controllerRegistryService = createMock(IControllerRegistryService.class); |
| 79 | modContext = createMock(FloodlightModuleContext.class); |
Toshio Koide | e04a9df | 2014-05-01 15:49:28 -0700 | [diff] [blame] | 80 | intentOperationChannel = createMock(IEventChannel.class); |
| 81 | intentStateChannel = createMock(IEventChannel.class); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 82 | persistIntent = PowerMock.createMock(PersistIntent.class); |
Pavlin Radoslavov | 1366905 | 2014-05-13 10:33:39 -0700 | [diff] [blame] | 83 | restApi = createMock(IRestApiService.class); |
Toshio Koide | 798bc1b | 2014-02-20 14:02:40 -0800 | [diff] [blame] | 84 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 85 | PowerMock.expectNew(PersistIntent.class, |
Pavlin Radoslavov | 0294e05 | 2014-04-10 13:36:45 -0700 | [diff] [blame] | 86 | anyObject(IControllerRegistryService.class)).andReturn(persistIntent); |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 87 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 88 | expect(modContext.getServiceImpl(IDatagridService.class)) |
| 89 | .andReturn(datagridService).once(); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 90 | expect(modContext.getServiceImpl(ITopologyService.class)) |
| 91 | .andReturn(topologyService).once(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 92 | expect(modContext.getServiceImpl(IControllerRegistryService.class)) |
| 93 | .andReturn(controllerRegistryService).once(); |
| 94 | expect(persistIntent.getKey()).andReturn(1L).anyTimes(); |
| 95 | expect(persistIntent.persistIfLeader(eq(1L), |
| 96 | anyObject(IntentOperationList.class))).andReturn(true).anyTimes(); |
Pavlin Radoslavov | 1366905 | 2014-05-13 10:33:39 -0700 | [diff] [blame] | 97 | expect(modContext.getServiceImpl(IRestApiService.class)) |
| 98 | .andReturn(restApi).once(); |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 99 | |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 100 | expect(topologyService.getTopology()).andReturn(mockTopology).anyTimes(); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 101 | topologyService.registerTopologyListener(anyObject(ITopologyListener.class)); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 102 | expectLastCall(); |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 103 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 104 | expect(datagridService.createChannel("onos.pathintent", Long.class, IntentOperationList.class)) |
Toshio Koide | e04a9df | 2014-05-01 15:49:28 -0700 | [diff] [blame] | 105 | .andReturn(intentOperationChannel).once(); |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 106 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 107 | expect(datagridService.addListener( |
| 108 | eq("onos.pathintent_state"), |
| 109 | anyObject(IEventChannelListener.class), |
| 110 | eq(Long.class), |
| 111 | eq(IntentStateList.class))) |
Toshio Koide | e04a9df | 2014-05-01 15:49:28 -0700 | [diff] [blame] | 112 | .andReturn(intentStateChannel).once(); |
Pavlin Radoslavov | 1366905 | 2014-05-13 10:33:39 -0700 | [diff] [blame] | 113 | restApi.addRestletRoutable(anyObject(IntentWebRoutable.class)); |
Toshio Koide | 066506e | 2014-02-20 19:52:09 -0800 | [diff] [blame] | 114 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 115 | replay(datagridService); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 116 | replay(topologyService); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 117 | replay(modContext); |
| 118 | replay(controllerRegistryService); |
| 119 | PowerMock.replay(persistIntent, PersistIntent.class); |
Pavlin Radoslavov | 1366905 | 2014-05-13 10:33:39 -0700 | [diff] [blame] | 120 | replay(restApi); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 121 | } |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 122 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 123 | @After |
| 124 | public void tearDown() { |
| 125 | verify(datagridService); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 126 | verify(topologyService); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 127 | verify(modContext); |
| 128 | verify(controllerRegistryService); |
| 129 | PowerMock.verify(persistIntent, PersistIntent.class); |
Pavlin Radoslavov | 1366905 | 2014-05-13 10:33:39 -0700 | [diff] [blame] | 130 | verify(restApi); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 131 | } |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 132 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 133 | private void showResult(PathIntentMap intents) { |
| 134 | for (Intent intent : intents.getAllIntents()) { |
| 135 | PathIntent pathIntent = (PathIntent) intent; |
| 136 | System.out.println("Path intent:" + pathIntent); |
| 137 | System.out.println("Parent intent: " + pathIntent.getParentIntent().toString()); |
| 138 | } |
| 139 | } |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 140 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 141 | @Test |
| 142 | public void createShortestPaths() throws FloodlightModuleException { |
| 143 | // create shortest path intents |
| 144 | IntentOperationList opList = new IntentOperationList(); |
| 145 | opList.add(Operator.ADD, new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT)); |
| 146 | opList.add(Operator.ADD, new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT)); |
| 147 | opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L, LOCAL_PORT)); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 148 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 149 | // compile high-level intent operations into low-level intent operations (calculate paths) |
| 150 | PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule(); |
| 151 | runtime1.init(modContext); |
| 152 | runtime1.startUp(modContext); |
| 153 | IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList); |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 154 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 155 | // compile low-level intents into flow entry installation plan |
| 156 | PlanCalcRuntime runtime2 = new PlanCalcRuntime(); |
| 157 | List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 158 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 159 | // show results |
| 160 | showResult((PathIntentMap) runtime1.getPathIntents()); |
| 161 | System.out.println(plan); |
| 162 | } |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 163 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 164 | @Test |
| 165 | public void createConstrainedShortestPaths() throws FloodlightModuleException { |
| 166 | // create constrained shortest path intents |
| 167 | IntentOperationList opList = new IntentOperationList(); |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 168 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("1", 1L, 12L, |
| 169 | LOCAL_PORT, 2L, 21L, LOCAL_PORT, 400.0)); |
| 170 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("2", 1L, 14L, |
| 171 | LOCAL_PORT, 4L, 41L, LOCAL_PORT, 400.0)); |
| 172 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("3", 2L, 24L, |
| 173 | LOCAL_PORT, 4L, 42L, LOCAL_PORT, 400.0)); |
| 174 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("4", 2L, 23L, |
| 175 | LOCAL_PORT, 3L, 32L, LOCAL_PORT, 400.0)); |
| 176 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("5", 3L, 34L, |
| 177 | LOCAL_PORT, 4L, 43L, LOCAL_PORT, 400.0)); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 178 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 179 | // compile high-level intent operations into low-level intent operations (calculate paths) |
| 180 | PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule(); |
| 181 | runtime1.init(modContext); |
| 182 | runtime1.startUp(modContext); |
| 183 | IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 184 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 185 | // compile low-level intents into flow entry installation plan |
| 186 | PlanCalcRuntime runtime2 = new PlanCalcRuntime(); |
| 187 | List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList); |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 188 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 189 | // show results |
| 190 | showResult((PathIntentMap) runtime1.getPathIntents()); |
| 191 | System.out.println(plan); |
| 192 | } |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 193 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 194 | @Test |
| 195 | public void createMixedShortestPaths() throws FloodlightModuleException { |
| 196 | // create constrained & best effort shortest path intents |
| 197 | IntentOperationList opList = new IntentOperationList(); |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 198 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("1", 1L, 12L, |
| 199 | LOCAL_PORT, 2L, 21L, LOCAL_PORT, 400.0)); |
| 200 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("2", 1L, 14L, |
| 201 | LOCAL_PORT, 4L, 41L, LOCAL_PORT, 400.0)); |
| 202 | opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 24L, LOCAL_PORT, 4L, |
| 203 | 42L, LOCAL_PORT)); |
| 204 | opList.add(Operator.ADD, new ShortestPathIntent("4", 2L, 23L, LOCAL_PORT, 3L, |
| 205 | 32L, LOCAL_PORT)); |
| 206 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("5", 3L, 34L, |
| 207 | LOCAL_PORT, 4L, 43L, LOCAL_PORT, 400.0)); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 208 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 209 | // compile high-level intent operations into low-level intent operations (calculate paths) |
| 210 | PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule(); |
| 211 | runtime1.init(modContext); |
| 212 | runtime1.startUp(modContext); |
| 213 | IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 214 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 215 | // compile low-level intents into flow entry installation plan |
| 216 | PlanCalcRuntime runtime2 = new PlanCalcRuntime(); |
| 217 | List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList); |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 218 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 219 | // show results |
| 220 | showResult((PathIntentMap) runtime1.getPathIntents()); |
| 221 | System.out.println(plan); |
| 222 | } |
Toshio Koide | d9fa2a8 | 2014-02-19 17:35:18 -0800 | [diff] [blame] | 223 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 224 | @Test |
| 225 | public void rerouteShortestPaths() throws FloodlightModuleException { |
| 226 | List<SwitchEvent> addedSwitchEvents = new LinkedList<>(); |
| 227 | List<SwitchEvent> removedSwitchEvents = new LinkedList<>(); |
| 228 | List<PortEvent> addedPortEvents = new LinkedList<>(); |
| 229 | List<PortEvent> removedPortEvents = new LinkedList<>(); |
| 230 | List<LinkEvent> addedLinkEvents = new LinkedList<>(); |
| 231 | List<LinkEvent> removedLinkEvents = new LinkedList<>(); |
| 232 | List<DeviceEvent> addedDeviceEvents = new LinkedList<>(); |
| 233 | List<DeviceEvent> removedDeviceEvents = new LinkedList<>(); |
Pavlin Radoslavov | 74986ce | 2014-02-20 13:17:20 -0800 | [diff] [blame] | 234 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 235 | // create shortest path intents |
| 236 | IntentOperationList opList = new IntentOperationList(); |
| 237 | opList.add(Operator.ADD, new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT)); |
| 238 | opList.add(Operator.ADD, new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT)); |
| 239 | opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L, LOCAL_PORT)); |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 240 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 241 | // compile high-level intent operations into low-level intent operations (calculate paths) |
| 242 | PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule(); |
| 243 | runtime1.init(modContext); |
| 244 | runtime1.startUp(modContext); |
| 245 | IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList); |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 246 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 247 | // compile low-level intents into flow entry installation plan |
| 248 | PlanCalcRuntime runtime2 = new PlanCalcRuntime(); |
| 249 | List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList); |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 250 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 251 | // show results step1 |
| 252 | showResult((PathIntentMap) runtime1.getPathIntents()); |
| 253 | System.out.println(plan); |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 254 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 255 | // TODO this state changes should be triggered by notification of plan module |
| 256 | IntentStateList states = new IntentStateList(); |
| 257 | states.put("1", IntentState.INST_ACK); |
| 258 | states.put("2", IntentState.INST_ACK); |
| 259 | states.put("3", IntentState.INST_ACK); |
| 260 | runtime1.getHighLevelIntents().changeStates(states); |
| 261 | states.clear(); |
| 262 | states.put("1___0", IntentState.INST_ACK); |
| 263 | states.put("2___0", IntentState.INST_ACK); |
| 264 | states.put("3___0", IntentState.INST_ACK); |
| 265 | runtime1.getPathIntents().changeStates(states); |
Toshio Koide | a10c037 | 2014-02-20 17:28:10 -0800 | [diff] [blame] | 266 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 267 | // link down |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 268 | ((MockTopology) topology).removeLink(1L, 12L, 2L, 21L); // This link is used by the intent "1" |
| 269 | ((MockTopology) topology).removeLink(2L, 21L, 1L, 12L); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 270 | LinkEvent linkEvent1 = new LinkEvent(1L, 12L, 2L, 21L); |
| 271 | LinkEvent linkEvent2 = new LinkEvent(2L, 21L, 1L, 12L); |
| 272 | removedLinkEvents.clear(); |
| 273 | removedLinkEvents.add(linkEvent1); |
| 274 | removedLinkEvents.add(linkEvent2); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 275 | runtime1.topologyEvents( |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 276 | addedSwitchEvents, |
| 277 | removedSwitchEvents, |
| 278 | addedPortEvents, |
| 279 | removedPortEvents, |
| 280 | addedLinkEvents, |
| 281 | removedLinkEvents, |
| 282 | addedDeviceEvents, |
| 283 | removedDeviceEvents); |
Toshio Koide | 7d3cee0 | 2014-06-05 18:56:19 -0700 | [diff] [blame] | 284 | System.out.println("*** Link goes down. ***"); |
| 285 | |
| 286 | // send notification |
| 287 | IntentStateList isl = new IntentStateList(); |
| 288 | isl.put("1___0", IntentState.DEL_ACK); |
| 289 | isl.put("1___1", IntentState.INST_ACK); |
| 290 | isl.domainSwitchDpids.add(1L); |
| 291 | isl.domainSwitchDpids.add(2L); |
| 292 | isl.domainSwitchDpids.add(4L); |
| 293 | runtime1.entryUpdated(isl); |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 294 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 295 | // show results step2 |
| 296 | showResult((PathIntentMap) runtime1.getPathIntents()); |
Toshio Koide | 7d3cee0 | 2014-06-05 18:56:19 -0700 | [diff] [blame] | 297 | |
| 298 | // link up |
| 299 | ((MockTopology) topology).addBidirectionalLinks(1L, 12L, 2L, 21L); |
| 300 | linkEvent1 = new LinkEvent(1L, 12L, 2L, 21L); |
| 301 | linkEvent2 = new LinkEvent(2L, 21L, 1L, 12L); |
| 302 | removedLinkEvents.clear(); |
| 303 | addedLinkEvents.clear(); |
| 304 | addedLinkEvents.add(linkEvent1); |
| 305 | addedLinkEvents.add(linkEvent2); |
| 306 | runtime1.topologyEvents( |
| 307 | addedSwitchEvents, |
| 308 | removedSwitchEvents, |
| 309 | addedPortEvents, |
| 310 | removedPortEvents, |
| 311 | addedLinkEvents, |
| 312 | removedLinkEvents, |
| 313 | addedDeviceEvents, |
| 314 | removedDeviceEvents); |
| 315 | System.out.println("*** Link goes up. ***"); |
| 316 | |
| 317 | // send notification |
| 318 | isl = new IntentStateList(); |
| 319 | isl.put("1___1", IntentState.DEL_ACK); |
| 320 | isl.put("1___2", IntentState.INST_ACK); |
| 321 | isl.domainSwitchDpids.add(1L); |
| 322 | isl.domainSwitchDpids.add(2L); |
| 323 | isl.domainSwitchDpids.add(4L); |
| 324 | runtime1.entryUpdated(isl); |
| 325 | |
| 326 | // show results step3 |
| 327 | showResult((PathIntentMap) runtime1.getPathIntents()); |
| 328 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 329 | // TODO: show results of plan computation |
| 330 | } |
Toshio Koide | fa735a1 | 2014-03-28 10:49:07 -0700 | [diff] [blame] | 331 | |
| 332 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 333 | @Test |
| 334 | public void createAndRemoveShortestPaths() throws FloodlightModuleException { |
| 335 | // create shortest path intents |
| 336 | IntentOperationList opList = new IntentOperationList(); |
| 337 | opList.add(Operator.ADD, new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT)); |
| 338 | opList.add(Operator.ADD, new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT)); |
| 339 | opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L, LOCAL_PORT)); |
Toshio Koide | fa735a1 | 2014-03-28 10:49:07 -0700 | [diff] [blame] | 340 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 341 | // compile high-level intent operations into low-level intent operations (calculate paths) |
| 342 | PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule(); |
| 343 | runtime1.init(modContext); |
| 344 | runtime1.startUp(modContext); |
| 345 | IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList); |
Toshio Koide | fa735a1 | 2014-03-28 10:49:07 -0700 | [diff] [blame] | 346 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 347 | // compile low-level intents into flow entry installation plan |
| 348 | PlanCalcRuntime runtime2 = new PlanCalcRuntime(); |
| 349 | List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList); |
Toshio Koide | fa735a1 | 2014-03-28 10:49:07 -0700 | [diff] [blame] | 350 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 351 | // show results |
| 352 | showResult((PathIntentMap) runtime1.getPathIntents()); |
| 353 | System.out.println(plan); |
Toshio Koide | fa735a1 | 2014-03-28 10:49:07 -0700 | [diff] [blame] | 354 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 355 | // create remove operations |
| 356 | opList.clear(); |
| 357 | opList.add(Operator.REMOVE, new Intent("1")); |
| 358 | opList.add(Operator.REMOVE, new Intent("2")); |
Toshio Koide | fa735a1 | 2014-03-28 10:49:07 -0700 | [diff] [blame] | 359 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 360 | // compile |
| 361 | runtime1.executeIntentOperations(opList); |
Toshio Koide | fa735a1 | 2014-03-28 10:49:07 -0700 | [diff] [blame] | 362 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 363 | // show results |
| 364 | showResult((PathIntentMap) runtime1.getPathIntents()); |
| 365 | System.out.println(plan); |
| 366 | } |
Toshio Koide | fa735a1 | 2014-03-28 10:49:07 -0700 | [diff] [blame] | 367 | |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 368 | } |