blob: b56b3e1db627afd876178eb7a243e285668355ab [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;
Pavlin Radoslavovd4f40372014-07-18 16:58:40 -070031import net.onrc.onos.core.metrics.OnosMetrics;
Jonathan Hartdeda0ba2014-04-03 11:14:12 -070032import net.onrc.onos.core.registry.IControllerRegistryService;
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -070033import net.onrc.onos.core.topology.HostEvent;
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;
TeruU5d2c9392014-06-09 20:02:02 -070037import net.onrc.onos.core.topology.MockTopology;
Jonathan Hart472062d2014-04-03 10:56:48 -070038import net.onrc.onos.core.topology.PortEvent;
39import net.onrc.onos.core.topology.SwitchEvent;
Jonathan Harte37e4e22014-05-13 19:12:02 -070040import net.onrc.onos.core.topology.Topology;
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -070041import net.onrc.onos.core.topology.TopologyEvents;
Yuta HIGUCHIe2a4e172014-07-03 10:50:39 -070042import net.onrc.onos.core.util.SwitchPort;
Toshio Koidec87810e2014-02-11 13:03:21 -080043
Pavlin Radoslavovd4f40372014-07-18 16:58:40 -070044import com.codahale.metrics.MetricFilter;
Toshio Koidec87810e2014-02-11 13:03:21 -080045import org.junit.After;
46import org.junit.Before;
47import org.junit.Test;
Nick Karanatsios8abe7172014-02-19 20:31:48 -080048import org.junit.runner.RunWith;
49import org.powermock.api.easymock.PowerMock;
50import org.powermock.core.classloader.annotations.PrepareForTest;
51import org.powermock.modules.junit4.PowerMockRunner;
Toshio Koidec87810e2014-02-11 13:03:21 -080052
53/**
Toshio Koidee04a9df2014-05-01 15:49:28 -070054 * Temporary test cases for the ONS2014 demo.
55 * These test cases should be modified and be moved to appropriate classes
56 * (ex. PathCalcRuntimeModuleTest, PlanInstallModuleTest, etc.)
Toshio Koidec87810e2014-02-11 13:03:21 -080057 */
Nick Karanatsios8abe7172014-02-19 20:31:48 -080058@RunWith(PowerMockRunner.class)
59@PrepareForTest(PathCalcRuntimeModule.class)
Toshio Koidec87810e2014-02-11 13:03:21 -080060public class UseCaseTest {
Jonathan Harte37e4e22014-05-13 19:12:02 -070061 private Topology topology;
Ray Milkey269ffb92014-04-03 14:43:30 -070062 private FloodlightModuleContext modContext;
63 private IDatagridService datagridService;
Jonathan Harte37e4e22014-05-13 19:12:02 -070064 private ITopologyService topologyService;
Ray Milkey269ffb92014-04-03 14:43:30 -070065 private IControllerRegistryService controllerRegistryService;
66 private PersistIntent persistIntent;
Pavlin Radoslavov13669052014-05-13 10:33:39 -070067 private IRestApiService restApi;
Toshio Koidee04a9df2014-05-01 15:49:28 -070068 private IEventChannel<Long, IntentOperationList> intentOperationChannel;
69 private IEventChannel<Long, IntentStateList> intentStateChannel;
Toshio Koidec87810e2014-02-11 13:03:21 -080070
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070071 private static final Long LOCAL_PORT = 0xFFFEL;
Toshio Koidefe1d5d92014-02-26 20:09:48 -080072
Ray Milkey269ffb92014-04-03 14:43:30 -070073 @SuppressWarnings("unchecked")
74 @Before
75 public void setUp() throws Exception {
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070076 MockTopology mockTopology = new MockTopology();
77 mockTopology.createSampleTopology1();
78 this.topology = mockTopology;
Toshio Koide27ffd412014-02-18 19:15:27 -080079
Ray Milkey269ffb92014-04-03 14:43:30 -070080 datagridService = createMock(IDatagridService.class);
Jonathan Harte37e4e22014-05-13 19:12:02 -070081 topologyService = createMock(ITopologyService.class);
Ray Milkey269ffb92014-04-03 14:43:30 -070082 controllerRegistryService = createMock(IControllerRegistryService.class);
83 modContext = createMock(FloodlightModuleContext.class);
Toshio Koidee04a9df2014-05-01 15:49:28 -070084 intentOperationChannel = createMock(IEventChannel.class);
85 intentStateChannel = createMock(IEventChannel.class);
Ray Milkey269ffb92014-04-03 14:43:30 -070086 persistIntent = PowerMock.createMock(PersistIntent.class);
Pavlin Radoslavov13669052014-05-13 10:33:39 -070087 restApi = createMock(IRestApiService.class);
Toshio Koide798bc1b2014-02-20 14:02:40 -080088
Ray Milkey269ffb92014-04-03 14:43:30 -070089 PowerMock.expectNew(PersistIntent.class,
Pavlin Radoslavov0294e052014-04-10 13:36:45 -070090 anyObject(IControllerRegistryService.class)).andReturn(persistIntent);
Toshio Koide27ffd412014-02-18 19:15:27 -080091
Ray Milkey269ffb92014-04-03 14:43:30 -070092 expect(modContext.getServiceImpl(IDatagridService.class))
93 .andReturn(datagridService).once();
Jonathan Harte37e4e22014-05-13 19:12:02 -070094 expect(modContext.getServiceImpl(ITopologyService.class))
95 .andReturn(topologyService).once();
Ray Milkey269ffb92014-04-03 14:43:30 -070096 expect(modContext.getServiceImpl(IControllerRegistryService.class))
97 .andReturn(controllerRegistryService).once();
98 expect(persistIntent.getKey()).andReturn(1L).anyTimes();
99 expect(persistIntent.persistIfLeader(eq(1L),
100 anyObject(IntentOperationList.class))).andReturn(true).anyTimes();
Pavlin Radoslavov13669052014-05-13 10:33:39 -0700101 expect(modContext.getServiceImpl(IRestApiService.class))
102 .andReturn(restApi).once();
Toshio Koide0c9106d2014-02-19 15:26:38 -0800103
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700104 expect(topologyService.getTopology()).andReturn(mockTopology).anyTimes();
Jonathan Harte37e4e22014-05-13 19:12:02 -0700105 topologyService.registerTopologyListener(anyObject(ITopologyListener.class));
Ray Milkey269ffb92014-04-03 14:43:30 -0700106 expectLastCall();
Toshio Koide0c9106d2014-02-19 15:26:38 -0800107
Ray Milkey269ffb92014-04-03 14:43:30 -0700108 expect(datagridService.createChannel("onos.pathintent", Long.class, IntentOperationList.class))
Toshio Koidee04a9df2014-05-01 15:49:28 -0700109 .andReturn(intentOperationChannel).once();
Toshio Koide27ffd412014-02-18 19:15:27 -0800110
Ray Milkey269ffb92014-04-03 14:43:30 -0700111 expect(datagridService.addListener(
112 eq("onos.pathintent_state"),
113 anyObject(IEventChannelListener.class),
114 eq(Long.class),
115 eq(IntentStateList.class)))
Toshio Koidee04a9df2014-05-01 15:49:28 -0700116 .andReturn(intentStateChannel).once();
Pavlin Radoslavov13669052014-05-13 10:33:39 -0700117 restApi.addRestletRoutable(anyObject(IntentWebRoutable.class));
Toshio Koide066506e2014-02-20 19:52:09 -0800118
Ray Milkey269ffb92014-04-03 14:43:30 -0700119 replay(datagridService);
Jonathan Harte37e4e22014-05-13 19:12:02 -0700120 replay(topologyService);
Ray Milkey269ffb92014-04-03 14:43:30 -0700121 replay(modContext);
122 replay(controllerRegistryService);
123 PowerMock.replay(persistIntent, PersistIntent.class);
Pavlin Radoslavov13669052014-05-13 10:33:39 -0700124 replay(restApi);
Ray Milkey269ffb92014-04-03 14:43:30 -0700125 }
Toshio Koidec87810e2014-02-11 13:03:21 -0800126
Ray Milkey269ffb92014-04-03 14:43:30 -0700127 @After
128 public void tearDown() {
129 verify(datagridService);
Jonathan Harte37e4e22014-05-13 19:12:02 -0700130 verify(topologyService);
Ray Milkey269ffb92014-04-03 14:43:30 -0700131 verify(modContext);
132 verify(controllerRegistryService);
133 PowerMock.verify(persistIntent, PersistIntent.class);
Pavlin Radoslavov13669052014-05-13 10:33:39 -0700134 verify(restApi);
Pavlin Radoslavovd4f40372014-07-18 16:58:40 -0700135 OnosMetrics.removeMatching(MetricFilter.ALL);
Ray Milkey269ffb92014-04-03 14:43:30 -0700136 }
Toshio Koidec87810e2014-02-11 13:03:21 -0800137
Ray Milkey269ffb92014-04-03 14:43:30 -0700138 private void showResult(PathIntentMap intents) {
139 for (Intent intent : intents.getAllIntents()) {
140 PathIntent pathIntent = (PathIntent) intent;
141 System.out.println("Path intent:" + pathIntent);
142 System.out.println("Parent intent: " + pathIntent.getParentIntent().toString());
143 }
144 }
Toshio Koidec87810e2014-02-11 13:03:21 -0800145
Ray Milkey269ffb92014-04-03 14:43:30 -0700146 @Test
147 public void createShortestPaths() throws FloodlightModuleException {
148 // create shortest path intents
149 IntentOperationList opList = new IntentOperationList();
150 opList.add(Operator.ADD, new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT));
151 opList.add(Operator.ADD, new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT));
152 opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L, LOCAL_PORT));
Toshio Koidec87810e2014-02-11 13:03:21 -0800153
Ray Milkey269ffb92014-04-03 14:43:30 -0700154 // compile high-level intent operations into low-level intent operations (calculate paths)
155 PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule();
156 runtime1.init(modContext);
157 runtime1.startUp(modContext);
158 IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList);
Toshio Koide27ffd412014-02-18 19:15:27 -0800159
Ray Milkey269ffb92014-04-03 14:43:30 -0700160 // compile low-level intents into flow entry installation plan
161 PlanCalcRuntime runtime2 = new PlanCalcRuntime();
162 List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList);
Toshio Koidec87810e2014-02-11 13:03:21 -0800163
Ray Milkey269ffb92014-04-03 14:43:30 -0700164 // show results
165 showResult((PathIntentMap) runtime1.getPathIntents());
166 System.out.println(plan);
167 }
Toshio Koidec87810e2014-02-11 13:03:21 -0800168
Ray Milkey269ffb92014-04-03 14:43:30 -0700169 @Test
170 public void createConstrainedShortestPaths() throws FloodlightModuleException {
171 // create constrained shortest path intents
172 IntentOperationList opList = new IntentOperationList();
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700173 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("1", 1L, 12L,
174 LOCAL_PORT, 2L, 21L, LOCAL_PORT, 400.0));
175 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("2", 1L, 14L,
176 LOCAL_PORT, 4L, 41L, LOCAL_PORT, 400.0));
177 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("3", 2L, 24L,
178 LOCAL_PORT, 4L, 42L, LOCAL_PORT, 400.0));
179 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("4", 2L, 23L,
180 LOCAL_PORT, 3L, 32L, LOCAL_PORT, 400.0));
181 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("5", 3L, 34L,
182 LOCAL_PORT, 4L, 43L, LOCAL_PORT, 400.0));
Toshio Koidec87810e2014-02-11 13:03:21 -0800183
Ray Milkey269ffb92014-04-03 14:43:30 -0700184 // compile high-level intent operations into low-level intent operations (calculate paths)
185 PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule();
186 runtime1.init(modContext);
187 runtime1.startUp(modContext);
188 IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList);
Toshio Koidec87810e2014-02-11 13:03:21 -0800189
Ray Milkey269ffb92014-04-03 14:43:30 -0700190 // compile low-level intents into flow entry installation plan
191 PlanCalcRuntime runtime2 = new PlanCalcRuntime();
192 List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList);
Brian O'Connor7f8e3012014-02-15 23:59:29 -0800193
Ray Milkey269ffb92014-04-03 14:43:30 -0700194 // show results
195 showResult((PathIntentMap) runtime1.getPathIntents());
196 System.out.println(plan);
197 }
Toshio Koidec87810e2014-02-11 13:03:21 -0800198
Ray Milkey269ffb92014-04-03 14:43:30 -0700199 @Test
200 public void createMixedShortestPaths() throws FloodlightModuleException {
201 // create constrained & best effort shortest path intents
202 IntentOperationList opList = new IntentOperationList();
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700203 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("1", 1L, 12L,
204 LOCAL_PORT, 2L, 21L, LOCAL_PORT, 400.0));
205 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("2", 1L, 14L,
206 LOCAL_PORT, 4L, 41L, LOCAL_PORT, 400.0));
207 opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 24L, LOCAL_PORT, 4L,
208 42L, LOCAL_PORT));
209 opList.add(Operator.ADD, new ShortestPathIntent("4", 2L, 23L, LOCAL_PORT, 3L,
210 32L, LOCAL_PORT));
211 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("5", 3L, 34L,
212 LOCAL_PORT, 4L, 43L, LOCAL_PORT, 400.0));
Toshio Koidec87810e2014-02-11 13:03:21 -0800213
Ray Milkey269ffb92014-04-03 14:43:30 -0700214 // compile high-level intent operations into low-level intent operations (calculate paths)
215 PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule();
216 runtime1.init(modContext);
217 runtime1.startUp(modContext);
218 IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList);
Toshio Koidec87810e2014-02-11 13:03:21 -0800219
Ray Milkey269ffb92014-04-03 14:43:30 -0700220 // compile low-level intents into flow entry installation plan
221 PlanCalcRuntime runtime2 = new PlanCalcRuntime();
222 List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList);
Brian O'Connor7f8e3012014-02-15 23:59:29 -0800223
Ray Milkey269ffb92014-04-03 14:43:30 -0700224 // show results
225 showResult((PathIntentMap) runtime1.getPathIntents());
226 System.out.println(plan);
227 }
Toshio Koided9fa2a82014-02-19 17:35:18 -0800228
Ray Milkey269ffb92014-04-03 14:43:30 -0700229 @Test
230 public void rerouteShortestPaths() throws FloodlightModuleException {
231 List<SwitchEvent> addedSwitchEvents = new LinkedList<>();
232 List<SwitchEvent> removedSwitchEvents = new LinkedList<>();
233 List<PortEvent> addedPortEvents = new LinkedList<>();
234 List<PortEvent> removedPortEvents = new LinkedList<>();
235 List<LinkEvent> addedLinkEvents = new LinkedList<>();
236 List<LinkEvent> removedLinkEvents = new LinkedList<>();
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700237 List<HostEvent> addedHostEvents = new LinkedList<>();
238 List<HostEvent> removedHostEvents = new LinkedList<>();
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700239 TopologyEvents topologyEvents;
Pavlin Radoslavov74986ce2014-02-20 13:17:20 -0800240
Ray Milkey269ffb92014-04-03 14:43:30 -0700241 // create shortest path intents
242 IntentOperationList opList = new IntentOperationList();
243 opList.add(Operator.ADD, new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT));
244 opList.add(Operator.ADD, new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT));
245 opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L, LOCAL_PORT));
Toshio Koide0c9106d2014-02-19 15:26:38 -0800246
Ray Milkey269ffb92014-04-03 14:43:30 -0700247 // compile high-level intent operations into low-level intent operations (calculate paths)
248 PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule();
249 runtime1.init(modContext);
250 runtime1.startUp(modContext);
251 IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList);
Toshio Koide0c9106d2014-02-19 15:26:38 -0800252
Ray Milkey269ffb92014-04-03 14:43:30 -0700253 // compile low-level intents into flow entry installation plan
254 PlanCalcRuntime runtime2 = new PlanCalcRuntime();
255 List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList);
Toshio Koide0c9106d2014-02-19 15:26:38 -0800256
Ray Milkey269ffb92014-04-03 14:43:30 -0700257 // show results step1
258 showResult((PathIntentMap) runtime1.getPathIntents());
259 System.out.println(plan);
Toshio Koide0c9106d2014-02-19 15:26:38 -0800260
Ray Milkey269ffb92014-04-03 14:43:30 -0700261 // TODO this state changes should be triggered by notification of plan module
262 IntentStateList states = new IntentStateList();
263 states.put("1", IntentState.INST_ACK);
264 states.put("2", IntentState.INST_ACK);
265 states.put("3", IntentState.INST_ACK);
266 runtime1.getHighLevelIntents().changeStates(states);
267 states.clear();
268 states.put("1___0", IntentState.INST_ACK);
269 states.put("2___0", IntentState.INST_ACK);
270 states.put("3___0", IntentState.INST_ACK);
271 runtime1.getPathIntents().changeStates(states);
Toshio Koidea10c0372014-02-20 17:28:10 -0800272
Ray Milkey269ffb92014-04-03 14:43:30 -0700273 // link down
Jonathan Harte37e4e22014-05-13 19:12:02 -0700274 ((MockTopology) topology).removeLink(1L, 12L, 2L, 21L); // This link is used by the intent "1"
275 ((MockTopology) topology).removeLink(2L, 21L, 1L, 12L);
Yuta HIGUCHIe2a4e172014-07-03 10:50:39 -0700276 LinkEvent linkEvent1 = new LinkEvent(new SwitchPort(1L, 12L), new SwitchPort(2L, 21L));
277 LinkEvent linkEvent2 = new LinkEvent(new SwitchPort(2L, 21L), new SwitchPort(1L, 12L));
Ray Milkey269ffb92014-04-03 14:43:30 -0700278 removedLinkEvents.clear();
279 removedLinkEvents.add(linkEvent1);
280 removedLinkEvents.add(linkEvent2);
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700281
282 topologyEvents = new TopologyEvents(0,
283 addedSwitchEvents,
284 removedSwitchEvents,
285 addedPortEvents,
286 removedPortEvents,
287 addedLinkEvents,
288 removedLinkEvents,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700289 addedHostEvents,
290 removedHostEvents);
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700291
292 runtime1.topologyEvents(topologyEvents);
Toshio Koide7d3cee02014-06-05 18:56:19 -0700293 System.out.println("*** Link goes down. ***");
294
295 // send notification
296 IntentStateList isl = new IntentStateList();
297 isl.put("1___0", IntentState.DEL_ACK);
298 isl.put("1___1", IntentState.INST_ACK);
299 isl.domainSwitchDpids.add(1L);
300 isl.domainSwitchDpids.add(2L);
301 isl.domainSwitchDpids.add(4L);
302 runtime1.entryUpdated(isl);
Toshio Koide0c9106d2014-02-19 15:26:38 -0800303
Ray Milkey269ffb92014-04-03 14:43:30 -0700304 // show results step2
305 showResult((PathIntentMap) runtime1.getPathIntents());
Toshio Koide7d3cee02014-06-05 18:56:19 -0700306
307 // link up
308 ((MockTopology) topology).addBidirectionalLinks(1L, 12L, 2L, 21L);
Yuta HIGUCHIe2a4e172014-07-03 10:50:39 -0700309 linkEvent1 = new LinkEvent(new SwitchPort(1L, 12L), new SwitchPort(2L, 21L));
310 linkEvent2 = new LinkEvent(new SwitchPort(2L, 21L), new SwitchPort(1L, 12L));
Toshio Koide7d3cee02014-06-05 18:56:19 -0700311 removedLinkEvents.clear();
312 addedLinkEvents.clear();
313 addedLinkEvents.add(linkEvent1);
314 addedLinkEvents.add(linkEvent2);
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700315
316 topologyEvents = new TopologyEvents(0,
317 addedSwitchEvents,
318 removedSwitchEvents,
319 addedPortEvents,
320 removedPortEvents,
321 addedLinkEvents,
322 removedLinkEvents,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700323 addedHostEvents,
324 removedHostEvents);
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700325
326 runtime1.topologyEvents(topologyEvents);
Toshio Koide7d3cee02014-06-05 18:56:19 -0700327 System.out.println("*** Link goes up. ***");
328
329 // send notification
330 isl = new IntentStateList();
331 isl.put("1___1", IntentState.DEL_ACK);
332 isl.put("1___2", IntentState.INST_ACK);
333 isl.domainSwitchDpids.add(1L);
334 isl.domainSwitchDpids.add(2L);
335 isl.domainSwitchDpids.add(4L);
336 runtime1.entryUpdated(isl);
337
338 // show results step3
339 showResult((PathIntentMap) runtime1.getPathIntents());
340
Ray Milkey269ffb92014-04-03 14:43:30 -0700341 // TODO: show results of plan computation
342 }
Toshio Koidefa735a12014-03-28 10:49:07 -0700343
344
Ray Milkey269ffb92014-04-03 14:43:30 -0700345 @Test
346 public void createAndRemoveShortestPaths() throws FloodlightModuleException {
347 // create shortest path intents
348 IntentOperationList opList = new IntentOperationList();
349 opList.add(Operator.ADD, new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT));
350 opList.add(Operator.ADD, new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT));
351 opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L, LOCAL_PORT));
Toshio Koidefa735a12014-03-28 10:49:07 -0700352
Ray Milkey269ffb92014-04-03 14:43:30 -0700353 // compile high-level intent operations into low-level intent operations (calculate paths)
354 PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule();
355 runtime1.init(modContext);
356 runtime1.startUp(modContext);
357 IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList);
Toshio Koidefa735a12014-03-28 10:49:07 -0700358
Ray Milkey269ffb92014-04-03 14:43:30 -0700359 // compile low-level intents into flow entry installation plan
360 PlanCalcRuntime runtime2 = new PlanCalcRuntime();
361 List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList);
Toshio Koidefa735a12014-03-28 10:49:07 -0700362
Ray Milkey269ffb92014-04-03 14:43:30 -0700363 // show results
364 showResult((PathIntentMap) runtime1.getPathIntents());
365 System.out.println(plan);
Toshio Koidefa735a12014-03-28 10:49:07 -0700366
Ray Milkey269ffb92014-04-03 14:43:30 -0700367 // create remove operations
368 opList.clear();
369 opList.add(Operator.REMOVE, new Intent("1"));
370 opList.add(Operator.REMOVE, new Intent("2"));
Toshio Koidefa735a12014-03-28 10:49:07 -0700371
Ray Milkey269ffb92014-04-03 14:43:30 -0700372 // compile
373 runtime1.executeIntentOperations(opList);
Toshio Koidefa735a12014-03-28 10:49:07 -0700374
Ray Milkey269ffb92014-04-03 14:43:30 -0700375 // show results
376 showResult((PathIntentMap) runtime1.getPathIntents());
377 System.out.println(plan);
378 }
Toshio Koidefa735a12014-03-28 10:49:07 -0700379
Toshio Koidec87810e2014-02-11 13:03:21 -0800380}