blob: cdae6d8e44f85a3b790f70d3a026930633b8cc54 [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 Harte37e4e22014-05-13 19:12:02 -070027import net.onrc.onos.core.intent.MockTopology;
Jonathan Hartaa380972014-04-03 10:24:46 -070028import net.onrc.onos.core.intent.PathIntent;
29import net.onrc.onos.core.intent.PathIntentMap;
30import net.onrc.onos.core.intent.ShortestPathIntent;
Pavlin Radoslavov13669052014-05-13 10:33:39 -070031import net.onrc.onos.core.intent.runtime.web.IntentWebRoutable;
Jonathan Hartdeda0ba2014-04-03 11:14:12 -070032import net.onrc.onos.core.registry.IControllerRegistryService;
Jonathan Hart472062d2014-04-03 10:56:48 -070033import net.onrc.onos.core.topology.DeviceEvent;
Jonathan Harte37e4e22014-05-13 19:12:02 -070034import net.onrc.onos.core.topology.ITopologyListener;
35import net.onrc.onos.core.topology.ITopologyService;
Jonathan Hart472062d2014-04-03 10:56:48 -070036import net.onrc.onos.core.topology.LinkEvent;
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;
Toshio Koidec87810e2014-02-11 13:03:21 -080040
41import org.junit.After;
42import org.junit.Before;
43import org.junit.Test;
Nick Karanatsios8abe7172014-02-19 20:31:48 -080044import org.junit.runner.RunWith;
45import org.powermock.api.easymock.PowerMock;
46import org.powermock.core.classloader.annotations.PrepareForTest;
47import org.powermock.modules.junit4.PowerMockRunner;
Toshio Koidec87810e2014-02-11 13:03:21 -080048
49/**
Toshio Koidee04a9df2014-05-01 15:49:28 -070050 * 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.)
53 *
Toshio Koidec87810e2014-02-11 13:03:21 -080054 * @author Toshio Koide (t-koide@onlab.us)
55 */
Nick Karanatsios8abe7172014-02-19 20:31:48 -080056@RunWith(PowerMockRunner.class)
57@PrepareForTest(PathCalcRuntimeModule.class)
Toshio Koidec87810e2014-02-11 13:03:21 -080058public class UseCaseTest {
Jonathan Harte37e4e22014-05-13 19:12:02 -070059 private Topology topology;
Ray Milkey269ffb92014-04-03 14:43:30 -070060 private FloodlightModuleContext modContext;
61 private IDatagridService datagridService;
Jonathan Harte37e4e22014-05-13 19:12:02 -070062 private ITopologyService topologyService;
Ray Milkey269ffb92014-04-03 14:43:30 -070063 private IControllerRegistryService controllerRegistryService;
64 private PersistIntent persistIntent;
Pavlin Radoslavov13669052014-05-13 10:33:39 -070065 private IRestApiService restApi;
Toshio Koidee04a9df2014-05-01 15:49:28 -070066 private IEventChannel<Long, IntentOperationList> intentOperationChannel;
67 private IEventChannel<Long, IntentStateList> intentStateChannel;
Toshio Koidec87810e2014-02-11 13:03:21 -080068
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070069 private static final Long LOCAL_PORT = 0xFFFEL;
Toshio Koidefe1d5d92014-02-26 20:09:48 -080070
Ray Milkey269ffb92014-04-03 14:43:30 -070071 @SuppressWarnings("unchecked")
72 @Before
73 public void setUp() throws Exception {
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070074 MockTopology mockTopology = new MockTopology();
75 mockTopology.createSampleTopology1();
76 this.topology = mockTopology;
Toshio Koide27ffd412014-02-18 19:15:27 -080077
Ray Milkey269ffb92014-04-03 14:43:30 -070078 datagridService = createMock(IDatagridService.class);
Jonathan Harte37e4e22014-05-13 19:12:02 -070079 topologyService = createMock(ITopologyService.class);
Ray Milkey269ffb92014-04-03 14:43:30 -070080 controllerRegistryService = createMock(IControllerRegistryService.class);
81 modContext = createMock(FloodlightModuleContext.class);
Toshio Koidee04a9df2014-05-01 15:49:28 -070082 intentOperationChannel = createMock(IEventChannel.class);
83 intentStateChannel = createMock(IEventChannel.class);
Ray Milkey269ffb92014-04-03 14:43:30 -070084 persistIntent = PowerMock.createMock(PersistIntent.class);
Pavlin Radoslavov13669052014-05-13 10:33:39 -070085 restApi = createMock(IRestApiService.class);
Toshio Koide798bc1b2014-02-20 14:02:40 -080086
Ray Milkey269ffb92014-04-03 14:43:30 -070087 PowerMock.expectNew(PersistIntent.class,
Pavlin Radoslavov0294e052014-04-10 13:36:45 -070088 anyObject(IControllerRegistryService.class)).andReturn(persistIntent);
Toshio Koide27ffd412014-02-18 19:15:27 -080089
Ray Milkey269ffb92014-04-03 14:43:30 -070090 expect(modContext.getServiceImpl(IDatagridService.class))
91 .andReturn(datagridService).once();
Jonathan Harte37e4e22014-05-13 19:12:02 -070092 expect(modContext.getServiceImpl(ITopologyService.class))
93 .andReturn(topologyService).once();
Ray Milkey269ffb92014-04-03 14:43:30 -070094 expect(modContext.getServiceImpl(IControllerRegistryService.class))
95 .andReturn(controllerRegistryService).once();
96 expect(persistIntent.getKey()).andReturn(1L).anyTimes();
97 expect(persistIntent.persistIfLeader(eq(1L),
98 anyObject(IntentOperationList.class))).andReturn(true).anyTimes();
Pavlin Radoslavov13669052014-05-13 10:33:39 -070099 expect(modContext.getServiceImpl(IRestApiService.class))
100 .andReturn(restApi).once();
Toshio Koide0c9106d2014-02-19 15:26:38 -0800101
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700102 expect(topologyService.getTopology()).andReturn(mockTopology).anyTimes();
Jonathan Harte37e4e22014-05-13 19:12:02 -0700103 topologyService.registerTopologyListener(anyObject(ITopologyListener.class));
Ray Milkey269ffb92014-04-03 14:43:30 -0700104 expectLastCall();
Toshio Koide0c9106d2014-02-19 15:26:38 -0800105
Ray Milkey269ffb92014-04-03 14:43:30 -0700106 expect(datagridService.createChannel("onos.pathintent", Long.class, IntentOperationList.class))
Toshio Koidee04a9df2014-05-01 15:49:28 -0700107 .andReturn(intentOperationChannel).once();
Toshio Koide27ffd412014-02-18 19:15:27 -0800108
Ray Milkey269ffb92014-04-03 14:43:30 -0700109 expect(datagridService.addListener(
110 eq("onos.pathintent_state"),
111 anyObject(IEventChannelListener.class),
112 eq(Long.class),
113 eq(IntentStateList.class)))
Toshio Koidee04a9df2014-05-01 15:49:28 -0700114 .andReturn(intentStateChannel).once();
Pavlin Radoslavov13669052014-05-13 10:33:39 -0700115 restApi.addRestletRoutable(anyObject(IntentWebRoutable.class));
Toshio Koide066506e2014-02-20 19:52:09 -0800116
Ray Milkey269ffb92014-04-03 14:43:30 -0700117 replay(datagridService);
Jonathan Harte37e4e22014-05-13 19:12:02 -0700118 replay(topologyService);
Ray Milkey269ffb92014-04-03 14:43:30 -0700119 replay(modContext);
120 replay(controllerRegistryService);
121 PowerMock.replay(persistIntent, PersistIntent.class);
Pavlin Radoslavov13669052014-05-13 10:33:39 -0700122 replay(restApi);
Ray Milkey269ffb92014-04-03 14:43:30 -0700123 }
Toshio Koidec87810e2014-02-11 13:03:21 -0800124
Ray Milkey269ffb92014-04-03 14:43:30 -0700125 @After
126 public void tearDown() {
127 verify(datagridService);
Jonathan Harte37e4e22014-05-13 19:12:02 -0700128 verify(topologyService);
Ray Milkey269ffb92014-04-03 14:43:30 -0700129 verify(modContext);
130 verify(controllerRegistryService);
131 PowerMock.verify(persistIntent, PersistIntent.class);
Pavlin Radoslavov13669052014-05-13 10:33:39 -0700132 verify(restApi);
Ray Milkey269ffb92014-04-03 14:43:30 -0700133 }
Toshio Koidec87810e2014-02-11 13:03:21 -0800134
Ray Milkey269ffb92014-04-03 14:43:30 -0700135 private void showResult(PathIntentMap intents) {
136 for (Intent intent : intents.getAllIntents()) {
137 PathIntent pathIntent = (PathIntent) intent;
138 System.out.println("Path intent:" + pathIntent);
139 System.out.println("Parent intent: " + pathIntent.getParentIntent().toString());
140 }
141 }
Toshio Koidec87810e2014-02-11 13:03:21 -0800142
Ray Milkey269ffb92014-04-03 14:43:30 -0700143 @Test
144 public void createShortestPaths() throws FloodlightModuleException {
145 // create shortest path intents
146 IntentOperationList opList = new IntentOperationList();
147 opList.add(Operator.ADD, new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT));
148 opList.add(Operator.ADD, new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT));
149 opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L, LOCAL_PORT));
Toshio Koidec87810e2014-02-11 13:03:21 -0800150
Ray Milkey269ffb92014-04-03 14:43:30 -0700151 // compile high-level intent operations into low-level intent operations (calculate paths)
152 PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule();
153 runtime1.init(modContext);
154 runtime1.startUp(modContext);
155 IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList);
Toshio Koide27ffd412014-02-18 19:15:27 -0800156
Ray Milkey269ffb92014-04-03 14:43:30 -0700157 // compile low-level intents into flow entry installation plan
158 PlanCalcRuntime runtime2 = new PlanCalcRuntime();
159 List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList);
Toshio Koidec87810e2014-02-11 13:03:21 -0800160
Ray Milkey269ffb92014-04-03 14:43:30 -0700161 // show results
162 showResult((PathIntentMap) runtime1.getPathIntents());
163 System.out.println(plan);
164 }
Toshio Koidec87810e2014-02-11 13:03:21 -0800165
Ray Milkey269ffb92014-04-03 14:43:30 -0700166 @Test
167 public void createConstrainedShortestPaths() throws FloodlightModuleException {
168 // create constrained shortest path intents
169 IntentOperationList opList = new IntentOperationList();
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700170 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("1", 1L, 12L,
171 LOCAL_PORT, 2L, 21L, LOCAL_PORT, 400.0));
172 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("2", 1L, 14L,
173 LOCAL_PORT, 4L, 41L, LOCAL_PORT, 400.0));
174 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("3", 2L, 24L,
175 LOCAL_PORT, 4L, 42L, LOCAL_PORT, 400.0));
176 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("4", 2L, 23L,
177 LOCAL_PORT, 3L, 32L, LOCAL_PORT, 400.0));
178 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("5", 3L, 34L,
179 LOCAL_PORT, 4L, 43L, LOCAL_PORT, 400.0));
Toshio Koidec87810e2014-02-11 13:03:21 -0800180
Ray Milkey269ffb92014-04-03 14:43:30 -0700181 // compile high-level intent operations into low-level intent operations (calculate paths)
182 PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule();
183 runtime1.init(modContext);
184 runtime1.startUp(modContext);
185 IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList);
Toshio Koidec87810e2014-02-11 13:03:21 -0800186
Ray Milkey269ffb92014-04-03 14:43:30 -0700187 // compile low-level intents into flow entry installation plan
188 PlanCalcRuntime runtime2 = new PlanCalcRuntime();
189 List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList);
Brian O'Connor7f8e3012014-02-15 23:59:29 -0800190
Ray Milkey269ffb92014-04-03 14:43:30 -0700191 // show results
192 showResult((PathIntentMap) runtime1.getPathIntents());
193 System.out.println(plan);
194 }
Toshio Koidec87810e2014-02-11 13:03:21 -0800195
Ray Milkey269ffb92014-04-03 14:43:30 -0700196 @Test
197 public void createMixedShortestPaths() throws FloodlightModuleException {
198 // create constrained & best effort shortest path intents
199 IntentOperationList opList = new IntentOperationList();
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700200 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("1", 1L, 12L,
201 LOCAL_PORT, 2L, 21L, LOCAL_PORT, 400.0));
202 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("2", 1L, 14L,
203 LOCAL_PORT, 4L, 41L, LOCAL_PORT, 400.0));
204 opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 24L, LOCAL_PORT, 4L,
205 42L, LOCAL_PORT));
206 opList.add(Operator.ADD, new ShortestPathIntent("4", 2L, 23L, LOCAL_PORT, 3L,
207 32L, LOCAL_PORT));
208 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("5", 3L, 34L,
209 LOCAL_PORT, 4L, 43L, LOCAL_PORT, 400.0));
Toshio Koidec87810e2014-02-11 13:03:21 -0800210
Ray Milkey269ffb92014-04-03 14:43:30 -0700211 // compile high-level intent operations into low-level intent operations (calculate paths)
212 PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule();
213 runtime1.init(modContext);
214 runtime1.startUp(modContext);
215 IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList);
Toshio Koidec87810e2014-02-11 13:03:21 -0800216
Ray Milkey269ffb92014-04-03 14:43:30 -0700217 // compile low-level intents into flow entry installation plan
218 PlanCalcRuntime runtime2 = new PlanCalcRuntime();
219 List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList);
Brian O'Connor7f8e3012014-02-15 23:59:29 -0800220
Ray Milkey269ffb92014-04-03 14:43:30 -0700221 // show results
222 showResult((PathIntentMap) runtime1.getPathIntents());
223 System.out.println(plan);
224 }
Toshio Koided9fa2a82014-02-19 17:35:18 -0800225
Ray Milkey269ffb92014-04-03 14:43:30 -0700226 @Test
227 public void rerouteShortestPaths() throws FloodlightModuleException {
228 List<SwitchEvent> addedSwitchEvents = new LinkedList<>();
229 List<SwitchEvent> removedSwitchEvents = new LinkedList<>();
230 List<PortEvent> addedPortEvents = new LinkedList<>();
231 List<PortEvent> removedPortEvents = new LinkedList<>();
232 List<LinkEvent> addedLinkEvents = new LinkedList<>();
233 List<LinkEvent> removedLinkEvents = new LinkedList<>();
234 List<DeviceEvent> addedDeviceEvents = new LinkedList<>();
235 List<DeviceEvent> removedDeviceEvents = new LinkedList<>();
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);
Jonathan Harte37e4e22014-05-13 19:12:02 -0700277 runtime1.topologyEvents(
Ray Milkey269ffb92014-04-03 14:43:30 -0700278 addedSwitchEvents,
279 removedSwitchEvents,
280 addedPortEvents,
281 removedPortEvents,
282 addedLinkEvents,
283 removedLinkEvents,
284 addedDeviceEvents,
285 removedDeviceEvents);
Toshio Koide7d3cee02014-06-05 18:56:19 -0700286 System.out.println("*** Link goes down. ***");
287
288 // send notification
289 IntentStateList isl = new IntentStateList();
290 isl.put("1___0", IntentState.DEL_ACK);
291 isl.put("1___1", IntentState.INST_ACK);
292 isl.domainSwitchDpids.add(1L);
293 isl.domainSwitchDpids.add(2L);
294 isl.domainSwitchDpids.add(4L);
295 runtime1.entryUpdated(isl);
Toshio Koide0c9106d2014-02-19 15:26:38 -0800296
Ray Milkey269ffb92014-04-03 14:43:30 -0700297 // show results step2
298 showResult((PathIntentMap) runtime1.getPathIntents());
Toshio Koide7d3cee02014-06-05 18:56:19 -0700299
300 // link up
301 ((MockTopology) topology).addBidirectionalLinks(1L, 12L, 2L, 21L);
302 linkEvent1 = new LinkEvent(1L, 12L, 2L, 21L);
303 linkEvent2 = new LinkEvent(2L, 21L, 1L, 12L);
304 removedLinkEvents.clear();
305 addedLinkEvents.clear();
306 addedLinkEvents.add(linkEvent1);
307 addedLinkEvents.add(linkEvent2);
308 runtime1.topologyEvents(
309 addedSwitchEvents,
310 removedSwitchEvents,
311 addedPortEvents,
312 removedPortEvents,
313 addedLinkEvents,
314 removedLinkEvents,
315 addedDeviceEvents,
316 removedDeviceEvents);
317 System.out.println("*** Link goes up. ***");
318
319 // send notification
320 isl = new IntentStateList();
321 isl.put("1___1", IntentState.DEL_ACK);
322 isl.put("1___2", IntentState.INST_ACK);
323 isl.domainSwitchDpids.add(1L);
324 isl.domainSwitchDpids.add(2L);
325 isl.domainSwitchDpids.add(4L);
326 runtime1.entryUpdated(isl);
327
328 // show results step3
329 showResult((PathIntentMap) runtime1.getPathIntents());
330
Ray Milkey269ffb92014-04-03 14:43:30 -0700331 // TODO: show results of plan computation
332 }
Toshio Koidefa735a12014-03-28 10:49:07 -0700333
334
Ray Milkey269ffb92014-04-03 14:43:30 -0700335 @Test
336 public void createAndRemoveShortestPaths() throws FloodlightModuleException {
337 // create shortest path intents
338 IntentOperationList opList = new IntentOperationList();
339 opList.add(Operator.ADD, new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT));
340 opList.add(Operator.ADD, new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT));
341 opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L, LOCAL_PORT));
Toshio Koidefa735a12014-03-28 10:49:07 -0700342
Ray Milkey269ffb92014-04-03 14:43:30 -0700343 // compile high-level intent operations into low-level intent operations (calculate paths)
344 PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule();
345 runtime1.init(modContext);
346 runtime1.startUp(modContext);
347 IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList);
Toshio Koidefa735a12014-03-28 10:49:07 -0700348
Ray Milkey269ffb92014-04-03 14:43:30 -0700349 // compile low-level intents into flow entry installation plan
350 PlanCalcRuntime runtime2 = new PlanCalcRuntime();
351 List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList);
Toshio Koidefa735a12014-03-28 10:49:07 -0700352
Ray Milkey269ffb92014-04-03 14:43:30 -0700353 // show results
354 showResult((PathIntentMap) runtime1.getPathIntents());
355 System.out.println(plan);
Toshio Koidefa735a12014-03-28 10:49:07 -0700356
Ray Milkey269ffb92014-04-03 14:43:30 -0700357 // create remove operations
358 opList.clear();
359 opList.add(Operator.REMOVE, new Intent("1"));
360 opList.add(Operator.REMOVE, new Intent("2"));
Toshio Koidefa735a12014-03-28 10:49:07 -0700361
Ray Milkey269ffb92014-04-03 14:43:30 -0700362 // compile
363 runtime1.executeIntentOperations(opList);
Toshio Koidefa735a12014-03-28 10:49:07 -0700364
Ray Milkey269ffb92014-04-03 14:43:30 -0700365 // show results
366 showResult((PathIntentMap) runtime1.getPathIntents());
367 System.out.println(plan);
368 }
Toshio Koidefa735a12014-03-28 10:49:07 -0700369
Toshio Koidec87810e2014-02-11 13:03:21 -0800370}