blob: a5b881607012fb96757068e80533144a3ae5db2c [file] [log] [blame]
Jonathan Hartaa380972014-04-03 10:24:46 -07001package net.onrc.onos.core.intent.runtime;
Toshio Koidec87810e2014-02-11 13:03:21 -08002
Jonathan Harta88fd242014-04-03 11:24:54 -07003import static org.easymock.EasyMock.anyObject;
4import static org.easymock.EasyMock.createMock;
5import static org.easymock.EasyMock.eq;
6import static org.easymock.EasyMock.expect;
7import static org.easymock.EasyMock.expectLastCall;
8import static org.easymock.EasyMock.replay;
9import static org.easymock.EasyMock.verify;
Toshio Koide066506e2014-02-20 19:52:09 -080010
Pavlin Radoslavov74986ce2014-02-20 13:17:20 -080011import java.util.LinkedList;
Brian O'Connor12861f72014-02-19 20:40:32 -080012import java.util.List;
13import java.util.Set;
14
Toshio Koide27ffd412014-02-18 19:15:27 -080015import net.floodlightcontroller.core.module.FloodlightModuleContext;
16import net.floodlightcontroller.core.module.FloodlightModuleException;
Pavlin Radoslavov13669052014-05-13 10:33:39 -070017import net.floodlightcontroller.restserver.IRestApiService;
Jonathan Hart6df90172014-04-03 10:13:11 -070018import net.onrc.onos.core.datagrid.IDatagridService;
19import net.onrc.onos.core.datagrid.IEventChannel;
20import net.onrc.onos.core.datagrid.IEventChannelListener;
Jonathan Hartaa380972014-04-03 10:24:46 -070021import net.onrc.onos.core.intent.ConstrainedShortestPathIntent;
22import net.onrc.onos.core.intent.FlowEntry;
23import net.onrc.onos.core.intent.Intent;
Jonathan Harta88fd242014-04-03 11:24:54 -070024import net.onrc.onos.core.intent.Intent.IntentState;
25import net.onrc.onos.core.intent.IntentOperation.Operator;
Jonathan Hartaa380972014-04-03 10:24:46 -070026import net.onrc.onos.core.intent.IntentOperationList;
Jonathan Hartaa380972014-04-03 10:24:46 -070027import net.onrc.onos.core.intent.PathIntent;
28import net.onrc.onos.core.intent.PathIntentMap;
29import net.onrc.onos.core.intent.ShortestPathIntent;
Pavlin Radoslavov13669052014-05-13 10:33:39 -070030import net.onrc.onos.core.intent.runtime.web.IntentWebRoutable;
Jonathan Hartdeda0ba2014-04-03 11:14:12 -070031import net.onrc.onos.core.registry.IControllerRegistryService;
Jonathan Hart472062d2014-04-03 10:56:48 -070032import net.onrc.onos.core.topology.DeviceEvent;
Jonathan Harte37e4e22014-05-13 19:12:02 -070033import net.onrc.onos.core.topology.ITopologyListener;
34import net.onrc.onos.core.topology.ITopologyService;
Jonathan Hart472062d2014-04-03 10:56:48 -070035import net.onrc.onos.core.topology.LinkEvent;
TeruU5d2c9392014-06-09 20:02:02 -070036import net.onrc.onos.core.topology.MockTopology;
Jonathan Hart472062d2014-04-03 10:56:48 -070037import net.onrc.onos.core.topology.PortEvent;
38import net.onrc.onos.core.topology.SwitchEvent;
Jonathan Harte37e4e22014-05-13 19:12:02 -070039import net.onrc.onos.core.topology.Topology;
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -070040import net.onrc.onos.core.topology.TopologyEvents;
Toshio Koidec87810e2014-02-11 13:03:21 -080041
42import org.junit.After;
43import org.junit.Before;
44import org.junit.Test;
Nick Karanatsios8abe7172014-02-19 20:31:48 -080045import org.junit.runner.RunWith;
46import org.powermock.api.easymock.PowerMock;
47import org.powermock.core.classloader.annotations.PrepareForTest;
48import org.powermock.modules.junit4.PowerMockRunner;
Toshio Koidec87810e2014-02-11 13:03:21 -080049
50/**
Toshio Koidee04a9df2014-05-01 15:49:28 -070051 * Temporary test cases for the ONS2014 demo.
52 * These test cases should be modified and be moved to appropriate classes
53 * (ex. PathCalcRuntimeModuleTest, PlanInstallModuleTest, etc.)
Toshio Koidec87810e2014-02-11 13:03:21 -080054 */
Nick Karanatsios8abe7172014-02-19 20:31:48 -080055@RunWith(PowerMockRunner.class)
56@PrepareForTest(PathCalcRuntimeModule.class)
Toshio Koidec87810e2014-02-11 13:03:21 -080057public class UseCaseTest {
Jonathan Harte37e4e22014-05-13 19:12:02 -070058 private Topology topology;
Ray Milkey269ffb92014-04-03 14:43:30 -070059 private FloodlightModuleContext modContext;
60 private IDatagridService datagridService;
Jonathan Harte37e4e22014-05-13 19:12:02 -070061 private ITopologyService topologyService;
Ray Milkey269ffb92014-04-03 14:43:30 -070062 private IControllerRegistryService controllerRegistryService;
63 private PersistIntent persistIntent;
Pavlin Radoslavov13669052014-05-13 10:33:39 -070064 private IRestApiService restApi;
Toshio Koidee04a9df2014-05-01 15:49:28 -070065 private IEventChannel<Long, IntentOperationList> intentOperationChannel;
66 private IEventChannel<Long, IntentStateList> intentStateChannel;
Toshio Koidec87810e2014-02-11 13:03:21 -080067
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070068 private static final Long LOCAL_PORT = 0xFFFEL;
Toshio Koidefe1d5d92014-02-26 20:09:48 -080069
Ray Milkey269ffb92014-04-03 14:43:30 -070070 @SuppressWarnings("unchecked")
71 @Before
72 public void setUp() throws Exception {
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070073 MockTopology mockTopology = new MockTopology();
74 mockTopology.createSampleTopology1();
75 this.topology = mockTopology;
Toshio Koide27ffd412014-02-18 19:15:27 -080076
Ray Milkey269ffb92014-04-03 14:43:30 -070077 datagridService = createMock(IDatagridService.class);
Jonathan Harte37e4e22014-05-13 19:12:02 -070078 topologyService = createMock(ITopologyService.class);
Ray Milkey269ffb92014-04-03 14:43:30 -070079 controllerRegistryService = createMock(IControllerRegistryService.class);
80 modContext = createMock(FloodlightModuleContext.class);
Toshio Koidee04a9df2014-05-01 15:49:28 -070081 intentOperationChannel = createMock(IEventChannel.class);
82 intentStateChannel = createMock(IEventChannel.class);
Ray Milkey269ffb92014-04-03 14:43:30 -070083 persistIntent = PowerMock.createMock(PersistIntent.class);
Pavlin Radoslavov13669052014-05-13 10:33:39 -070084 restApi = createMock(IRestApiService.class);
Toshio Koide798bc1b2014-02-20 14:02:40 -080085
Ray Milkey269ffb92014-04-03 14:43:30 -070086 PowerMock.expectNew(PersistIntent.class,
Pavlin Radoslavov0294e052014-04-10 13:36:45 -070087 anyObject(IControllerRegistryService.class)).andReturn(persistIntent);
Toshio Koide27ffd412014-02-18 19:15:27 -080088
Ray Milkey269ffb92014-04-03 14:43:30 -070089 expect(modContext.getServiceImpl(IDatagridService.class))
90 .andReturn(datagridService).once();
Jonathan Harte37e4e22014-05-13 19:12:02 -070091 expect(modContext.getServiceImpl(ITopologyService.class))
92 .andReturn(topologyService).once();
Ray Milkey269ffb92014-04-03 14:43:30 -070093 expect(modContext.getServiceImpl(IControllerRegistryService.class))
94 .andReturn(controllerRegistryService).once();
95 expect(persistIntent.getKey()).andReturn(1L).anyTimes();
96 expect(persistIntent.persistIfLeader(eq(1L),
97 anyObject(IntentOperationList.class))).andReturn(true).anyTimes();
Pavlin Radoslavov13669052014-05-13 10:33:39 -070098 expect(modContext.getServiceImpl(IRestApiService.class))
99 .andReturn(restApi).once();
Toshio Koide0c9106d2014-02-19 15:26:38 -0800100
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700101 expect(topologyService.getTopology()).andReturn(mockTopology).anyTimes();
Jonathan Harte37e4e22014-05-13 19:12:02 -0700102 topologyService.registerTopologyListener(anyObject(ITopologyListener.class));
Ray Milkey269ffb92014-04-03 14:43:30 -0700103 expectLastCall();
Toshio Koide0c9106d2014-02-19 15:26:38 -0800104
Ray Milkey269ffb92014-04-03 14:43:30 -0700105 expect(datagridService.createChannel("onos.pathintent", Long.class, IntentOperationList.class))
Toshio Koidee04a9df2014-05-01 15:49:28 -0700106 .andReturn(intentOperationChannel).once();
Toshio Koide27ffd412014-02-18 19:15:27 -0800107
Ray Milkey269ffb92014-04-03 14:43:30 -0700108 expect(datagridService.addListener(
109 eq("onos.pathintent_state"),
110 anyObject(IEventChannelListener.class),
111 eq(Long.class),
112 eq(IntentStateList.class)))
Toshio Koidee04a9df2014-05-01 15:49:28 -0700113 .andReturn(intentStateChannel).once();
Pavlin Radoslavov13669052014-05-13 10:33:39 -0700114 restApi.addRestletRoutable(anyObject(IntentWebRoutable.class));
Toshio Koide066506e2014-02-20 19:52:09 -0800115
Ray Milkey269ffb92014-04-03 14:43:30 -0700116 replay(datagridService);
Jonathan Harte37e4e22014-05-13 19:12:02 -0700117 replay(topologyService);
Ray Milkey269ffb92014-04-03 14:43:30 -0700118 replay(modContext);
119 replay(controllerRegistryService);
120 PowerMock.replay(persistIntent, PersistIntent.class);
Pavlin Radoslavov13669052014-05-13 10:33:39 -0700121 replay(restApi);
Ray Milkey269ffb92014-04-03 14:43:30 -0700122 }
Toshio Koidec87810e2014-02-11 13:03:21 -0800123
Ray Milkey269ffb92014-04-03 14:43:30 -0700124 @After
125 public void tearDown() {
126 verify(datagridService);
Jonathan Harte37e4e22014-05-13 19:12:02 -0700127 verify(topologyService);
Ray Milkey269ffb92014-04-03 14:43:30 -0700128 verify(modContext);
129 verify(controllerRegistryService);
130 PowerMock.verify(persistIntent, PersistIntent.class);
Pavlin Radoslavov13669052014-05-13 10:33:39 -0700131 verify(restApi);
Ray Milkey269ffb92014-04-03 14:43:30 -0700132 }
Toshio Koidec87810e2014-02-11 13:03:21 -0800133
Ray Milkey269ffb92014-04-03 14:43:30 -0700134 private void showResult(PathIntentMap intents) {
135 for (Intent intent : intents.getAllIntents()) {
136 PathIntent pathIntent = (PathIntent) intent;
137 System.out.println("Path intent:" + pathIntent);
138 System.out.println("Parent intent: " + pathIntent.getParentIntent().toString());
139 }
140 }
Toshio Koidec87810e2014-02-11 13:03:21 -0800141
Ray Milkey269ffb92014-04-03 14:43:30 -0700142 @Test
143 public void createShortestPaths() throws FloodlightModuleException {
144 // create shortest path intents
145 IntentOperationList opList = new IntentOperationList();
146 opList.add(Operator.ADD, new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT));
147 opList.add(Operator.ADD, new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT));
148 opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L, LOCAL_PORT));
Toshio Koidec87810e2014-02-11 13:03:21 -0800149
Ray Milkey269ffb92014-04-03 14:43:30 -0700150 // compile high-level intent operations into low-level intent operations (calculate paths)
151 PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule();
152 runtime1.init(modContext);
153 runtime1.startUp(modContext);
154 IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList);
Toshio Koide27ffd412014-02-18 19:15:27 -0800155
Ray Milkey269ffb92014-04-03 14:43:30 -0700156 // compile low-level intents into flow entry installation plan
157 PlanCalcRuntime runtime2 = new PlanCalcRuntime();
158 List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList);
Toshio Koidec87810e2014-02-11 13:03:21 -0800159
Ray Milkey269ffb92014-04-03 14:43:30 -0700160 // show results
161 showResult((PathIntentMap) runtime1.getPathIntents());
162 System.out.println(plan);
163 }
Toshio Koidec87810e2014-02-11 13:03:21 -0800164
Ray Milkey269ffb92014-04-03 14:43:30 -0700165 @Test
166 public void createConstrainedShortestPaths() throws FloodlightModuleException {
167 // create constrained shortest path intents
168 IntentOperationList opList = new IntentOperationList();
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700169 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("1", 1L, 12L,
170 LOCAL_PORT, 2L, 21L, LOCAL_PORT, 400.0));
171 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("2", 1L, 14L,
172 LOCAL_PORT, 4L, 41L, LOCAL_PORT, 400.0));
173 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("3", 2L, 24L,
174 LOCAL_PORT, 4L, 42L, LOCAL_PORT, 400.0));
175 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("4", 2L, 23L,
176 LOCAL_PORT, 3L, 32L, LOCAL_PORT, 400.0));
177 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("5", 3L, 34L,
178 LOCAL_PORT, 4L, 43L, LOCAL_PORT, 400.0));
Toshio Koidec87810e2014-02-11 13:03:21 -0800179
Ray Milkey269ffb92014-04-03 14:43:30 -0700180 // compile high-level intent operations into low-level intent operations (calculate paths)
181 PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule();
182 runtime1.init(modContext);
183 runtime1.startUp(modContext);
184 IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList);
Toshio Koidec87810e2014-02-11 13:03:21 -0800185
Ray Milkey269ffb92014-04-03 14:43:30 -0700186 // compile low-level intents into flow entry installation plan
187 PlanCalcRuntime runtime2 = new PlanCalcRuntime();
188 List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList);
Brian O'Connor7f8e3012014-02-15 23:59:29 -0800189
Ray Milkey269ffb92014-04-03 14:43:30 -0700190 // show results
191 showResult((PathIntentMap) runtime1.getPathIntents());
192 System.out.println(plan);
193 }
Toshio Koidec87810e2014-02-11 13:03:21 -0800194
Ray Milkey269ffb92014-04-03 14:43:30 -0700195 @Test
196 public void createMixedShortestPaths() throws FloodlightModuleException {
197 // create constrained & best effort shortest path intents
198 IntentOperationList opList = new IntentOperationList();
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700199 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("1", 1L, 12L,
200 LOCAL_PORT, 2L, 21L, LOCAL_PORT, 400.0));
201 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("2", 1L, 14L,
202 LOCAL_PORT, 4L, 41L, LOCAL_PORT, 400.0));
203 opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 24L, LOCAL_PORT, 4L,
204 42L, LOCAL_PORT));
205 opList.add(Operator.ADD, new ShortestPathIntent("4", 2L, 23L, LOCAL_PORT, 3L,
206 32L, LOCAL_PORT));
207 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("5", 3L, 34L,
208 LOCAL_PORT, 4L, 43L, LOCAL_PORT, 400.0));
Toshio Koidec87810e2014-02-11 13:03:21 -0800209
Ray Milkey269ffb92014-04-03 14:43:30 -0700210 // compile high-level intent operations into low-level intent operations (calculate paths)
211 PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule();
212 runtime1.init(modContext);
213 runtime1.startUp(modContext);
214 IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList);
Toshio Koidec87810e2014-02-11 13:03:21 -0800215
Ray Milkey269ffb92014-04-03 14:43:30 -0700216 // compile low-level intents into flow entry installation plan
217 PlanCalcRuntime runtime2 = new PlanCalcRuntime();
218 List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList);
Brian O'Connor7f8e3012014-02-15 23:59:29 -0800219
Ray Milkey269ffb92014-04-03 14:43:30 -0700220 // show results
221 showResult((PathIntentMap) runtime1.getPathIntents());
222 System.out.println(plan);
223 }
Toshio Koided9fa2a82014-02-19 17:35:18 -0800224
Ray Milkey269ffb92014-04-03 14:43:30 -0700225 @Test
226 public void rerouteShortestPaths() throws FloodlightModuleException {
227 List<SwitchEvent> addedSwitchEvents = new LinkedList<>();
228 List<SwitchEvent> removedSwitchEvents = new LinkedList<>();
229 List<PortEvent> addedPortEvents = new LinkedList<>();
230 List<PortEvent> removedPortEvents = new LinkedList<>();
231 List<LinkEvent> addedLinkEvents = new LinkedList<>();
232 List<LinkEvent> removedLinkEvents = new LinkedList<>();
233 List<DeviceEvent> addedDeviceEvents = new LinkedList<>();
234 List<DeviceEvent> removedDeviceEvents = new LinkedList<>();
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700235 TopologyEvents topologyEvents;
Pavlin Radoslavov74986ce2014-02-20 13:17:20 -0800236
Ray Milkey269ffb92014-04-03 14:43:30 -0700237 // create shortest path intents
238 IntentOperationList opList = new IntentOperationList();
239 opList.add(Operator.ADD, new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT));
240 opList.add(Operator.ADD, new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT));
241 opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L, LOCAL_PORT));
Toshio Koide0c9106d2014-02-19 15:26:38 -0800242
Ray Milkey269ffb92014-04-03 14:43:30 -0700243 // compile high-level intent operations into low-level intent operations (calculate paths)
244 PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule();
245 runtime1.init(modContext);
246 runtime1.startUp(modContext);
247 IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList);
Toshio Koide0c9106d2014-02-19 15:26:38 -0800248
Ray Milkey269ffb92014-04-03 14:43:30 -0700249 // compile low-level intents into flow entry installation plan
250 PlanCalcRuntime runtime2 = new PlanCalcRuntime();
251 List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList);
Toshio Koide0c9106d2014-02-19 15:26:38 -0800252
Ray Milkey269ffb92014-04-03 14:43:30 -0700253 // show results step1
254 showResult((PathIntentMap) runtime1.getPathIntents());
255 System.out.println(plan);
Toshio Koide0c9106d2014-02-19 15:26:38 -0800256
Ray Milkey269ffb92014-04-03 14:43:30 -0700257 // TODO this state changes should be triggered by notification of plan module
258 IntentStateList states = new IntentStateList();
259 states.put("1", IntentState.INST_ACK);
260 states.put("2", IntentState.INST_ACK);
261 states.put("3", IntentState.INST_ACK);
262 runtime1.getHighLevelIntents().changeStates(states);
263 states.clear();
264 states.put("1___0", IntentState.INST_ACK);
265 states.put("2___0", IntentState.INST_ACK);
266 states.put("3___0", IntentState.INST_ACK);
267 runtime1.getPathIntents().changeStates(states);
Toshio Koidea10c0372014-02-20 17:28:10 -0800268
Ray Milkey269ffb92014-04-03 14:43:30 -0700269 // link down
Jonathan Harte37e4e22014-05-13 19:12:02 -0700270 ((MockTopology) topology).removeLink(1L, 12L, 2L, 21L); // This link is used by the intent "1"
271 ((MockTopology) topology).removeLink(2L, 21L, 1L, 12L);
Ray Milkey269ffb92014-04-03 14:43:30 -0700272 LinkEvent linkEvent1 = new LinkEvent(1L, 12L, 2L, 21L);
273 LinkEvent linkEvent2 = new LinkEvent(2L, 21L, 1L, 12L);
274 removedLinkEvents.clear();
275 removedLinkEvents.add(linkEvent1);
276 removedLinkEvents.add(linkEvent2);
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700277
278 topologyEvents = new TopologyEvents(0,
279 addedSwitchEvents,
280 removedSwitchEvents,
281 addedPortEvents,
282 removedPortEvents,
283 addedLinkEvents,
284 removedLinkEvents,
285 addedDeviceEvents,
286 removedDeviceEvents);
287
288 runtime1.topologyEvents(topologyEvents);
Toshio Koide7d3cee02014-06-05 18:56:19 -0700289 System.out.println("*** Link goes down. ***");
290
291 // send notification
292 IntentStateList isl = new IntentStateList();
293 isl.put("1___0", IntentState.DEL_ACK);
294 isl.put("1___1", IntentState.INST_ACK);
295 isl.domainSwitchDpids.add(1L);
296 isl.domainSwitchDpids.add(2L);
297 isl.domainSwitchDpids.add(4L);
298 runtime1.entryUpdated(isl);
Toshio Koide0c9106d2014-02-19 15:26:38 -0800299
Ray Milkey269ffb92014-04-03 14:43:30 -0700300 // show results step2
301 showResult((PathIntentMap) runtime1.getPathIntents());
Toshio Koide7d3cee02014-06-05 18:56:19 -0700302
303 // link up
304 ((MockTopology) topology).addBidirectionalLinks(1L, 12L, 2L, 21L);
305 linkEvent1 = new LinkEvent(1L, 12L, 2L, 21L);
306 linkEvent2 = new LinkEvent(2L, 21L, 1L, 12L);
307 removedLinkEvents.clear();
308 addedLinkEvents.clear();
309 addedLinkEvents.add(linkEvent1);
310 addedLinkEvents.add(linkEvent2);
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700311
312 topologyEvents = new TopologyEvents(0,
313 addedSwitchEvents,
314 removedSwitchEvents,
315 addedPortEvents,
316 removedPortEvents,
317 addedLinkEvents,
318 removedLinkEvents,
319 addedDeviceEvents,
320 removedDeviceEvents);
321
322 runtime1.topologyEvents(topologyEvents);
Toshio Koide7d3cee02014-06-05 18:56:19 -0700323 System.out.println("*** Link goes up. ***");
324
325 // send notification
326 isl = new IntentStateList();
327 isl.put("1___1", IntentState.DEL_ACK);
328 isl.put("1___2", IntentState.INST_ACK);
329 isl.domainSwitchDpids.add(1L);
330 isl.domainSwitchDpids.add(2L);
331 isl.domainSwitchDpids.add(4L);
332 runtime1.entryUpdated(isl);
333
334 // show results step3
335 showResult((PathIntentMap) runtime1.getPathIntents());
336
Ray Milkey269ffb92014-04-03 14:43:30 -0700337 // TODO: show results of plan computation
338 }
Toshio Koidefa735a12014-03-28 10:49:07 -0700339
340
Ray Milkey269ffb92014-04-03 14:43:30 -0700341 @Test
342 public void createAndRemoveShortestPaths() throws FloodlightModuleException {
343 // create shortest path intents
344 IntentOperationList opList = new IntentOperationList();
345 opList.add(Operator.ADD, new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT));
346 opList.add(Operator.ADD, new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT));
347 opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L, LOCAL_PORT));
Toshio Koidefa735a12014-03-28 10:49:07 -0700348
Ray Milkey269ffb92014-04-03 14:43:30 -0700349 // compile high-level intent operations into low-level intent operations (calculate paths)
350 PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule();
351 runtime1.init(modContext);
352 runtime1.startUp(modContext);
353 IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList);
Toshio Koidefa735a12014-03-28 10:49:07 -0700354
Ray Milkey269ffb92014-04-03 14:43:30 -0700355 // compile low-level intents into flow entry installation plan
356 PlanCalcRuntime runtime2 = new PlanCalcRuntime();
357 List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList);
Toshio Koidefa735a12014-03-28 10:49:07 -0700358
Ray Milkey269ffb92014-04-03 14:43:30 -0700359 // show results
360 showResult((PathIntentMap) runtime1.getPathIntents());
361 System.out.println(plan);
Toshio Koidefa735a12014-03-28 10:49:07 -0700362
Ray Milkey269ffb92014-04-03 14:43:30 -0700363 // create remove operations
364 opList.clear();
365 opList.add(Operator.REMOVE, new Intent("1"));
366 opList.add(Operator.REMOVE, new Intent("2"));
Toshio Koidefa735a12014-03-28 10:49:07 -0700367
Ray Milkey269ffb92014-04-03 14:43:30 -0700368 // compile
369 runtime1.executeIntentOperations(opList);
Toshio Koidefa735a12014-03-28 10:49:07 -0700370
Ray Milkey269ffb92014-04-03 14:43:30 -0700371 // show results
372 showResult((PathIntentMap) runtime1.getPathIntents());
373 System.out.println(plan);
374 }
Toshio Koidefa735a12014-03-28 10:49:07 -0700375
Toshio Koidec87810e2014-02-11 13:03:21 -0800376}