blob: 69f8e01761b1a42ccd49bae17a5852d3e147fdbd [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;
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -070032import net.onrc.onos.core.topology.HostEvent;
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;
Pavlin Radoslavovcac157d2014-07-31 13:54:08 -070036import net.onrc.onos.core.topology.MastershipEvent;
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
Ray Milkey38301352014-07-28 08:51:54 -070044import net.onrc.onos.core.util.UnitTest;
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;
Yuta HIGUCHI412add62014-07-25 13:03:43 -070052import org.slf4j.Logger;
53import org.slf4j.LoggerFactory;
Toshio Koidec87810e2014-02-11 13:03:21 -080054
55/**
Toshio Koidee04a9df2014-05-01 15:49:28 -070056 * Temporary test cases for the ONS2014 demo.
57 * These test cases should be modified and be moved to appropriate classes
58 * (ex. PathCalcRuntimeModuleTest, PlanInstallModuleTest, etc.)
Toshio Koidec87810e2014-02-11 13:03:21 -080059 */
Nick Karanatsios8abe7172014-02-19 20:31:48 -080060@RunWith(PowerMockRunner.class)
61@PrepareForTest(PathCalcRuntimeModule.class)
Ray Milkey38301352014-07-28 08:51:54 -070062public class UseCaseTest extends UnitTest {
Yuta HIGUCHI412add62014-07-25 13:03:43 -070063 private static final Logger log = LoggerFactory.getLogger(UseCaseTest.class);
64
Jonathan Harte37e4e22014-05-13 19:12:02 -070065 private Topology topology;
Ray Milkey269ffb92014-04-03 14:43:30 -070066 private FloodlightModuleContext modContext;
67 private IDatagridService datagridService;
Jonathan Harte37e4e22014-05-13 19:12:02 -070068 private ITopologyService topologyService;
Ray Milkey269ffb92014-04-03 14:43:30 -070069 private IControllerRegistryService controllerRegistryService;
70 private PersistIntent persistIntent;
Pavlin Radoslavov13669052014-05-13 10:33:39 -070071 private IRestApiService restApi;
Toshio Koidee04a9df2014-05-01 15:49:28 -070072 private IEventChannel<Long, IntentOperationList> intentOperationChannel;
73 private IEventChannel<Long, IntentStateList> intentStateChannel;
Toshio Koidec87810e2014-02-11 13:03:21 -080074
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070075 private static final Long LOCAL_PORT = 0xFFFEL;
Toshio Koidefe1d5d92014-02-26 20:09:48 -080076
Ray Milkey269ffb92014-04-03 14:43:30 -070077 @SuppressWarnings("unchecked")
78 @Before
79 public void setUp() throws Exception {
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070080 MockTopology mockTopology = new MockTopology();
81 mockTopology.createSampleTopology1();
82 this.topology = mockTopology;
Toshio Koide27ffd412014-02-18 19:15:27 -080083
Ray Milkey269ffb92014-04-03 14:43:30 -070084 datagridService = createMock(IDatagridService.class);
Jonathan Harte37e4e22014-05-13 19:12:02 -070085 topologyService = createMock(ITopologyService.class);
Ray Milkey269ffb92014-04-03 14:43:30 -070086 controllerRegistryService = createMock(IControllerRegistryService.class);
87 modContext = createMock(FloodlightModuleContext.class);
Toshio Koidee04a9df2014-05-01 15:49:28 -070088 intentOperationChannel = createMock(IEventChannel.class);
89 intentStateChannel = createMock(IEventChannel.class);
Ray Milkey269ffb92014-04-03 14:43:30 -070090 persistIntent = PowerMock.createMock(PersistIntent.class);
Pavlin Radoslavov13669052014-05-13 10:33:39 -070091 restApi = createMock(IRestApiService.class);
Toshio Koide798bc1b2014-02-20 14:02:40 -080092
Ray Milkey269ffb92014-04-03 14:43:30 -070093 PowerMock.expectNew(PersistIntent.class,
Pavlin Radoslavov0294e052014-04-10 13:36:45 -070094 anyObject(IControllerRegistryService.class)).andReturn(persistIntent);
Toshio Koide27ffd412014-02-18 19:15:27 -080095
Ray Milkey269ffb92014-04-03 14:43:30 -070096 expect(modContext.getServiceImpl(IDatagridService.class))
97 .andReturn(datagridService).once();
Jonathan Harte37e4e22014-05-13 19:12:02 -070098 expect(modContext.getServiceImpl(ITopologyService.class))
99 .andReturn(topologyService).once();
Ray Milkey269ffb92014-04-03 14:43:30 -0700100 expect(modContext.getServiceImpl(IControllerRegistryService.class))
101 .andReturn(controllerRegistryService).once();
102 expect(persistIntent.getKey()).andReturn(1L).anyTimes();
103 expect(persistIntent.persistIfLeader(eq(1L),
104 anyObject(IntentOperationList.class))).andReturn(true).anyTimes();
Pavlin Radoslavov13669052014-05-13 10:33:39 -0700105 expect(modContext.getServiceImpl(IRestApiService.class))
106 .andReturn(restApi).once();
Toshio Koide0c9106d2014-02-19 15:26:38 -0800107
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700108 expect(topologyService.getTopology()).andReturn(mockTopology).anyTimes();
Pavlin Radoslavov054cd592014-08-07 20:57:16 -0700109 topologyService.addListener(anyObject(ITopologyListener.class),
110 eq(false));
Ray Milkey269ffb92014-04-03 14:43:30 -0700111 expectLastCall();
Toshio Koide0c9106d2014-02-19 15:26:38 -0800112
Ray Milkey269ffb92014-04-03 14:43:30 -0700113 expect(datagridService.createChannel("onos.pathintent", Long.class, IntentOperationList.class))
Toshio Koidee04a9df2014-05-01 15:49:28 -0700114 .andReturn(intentOperationChannel).once();
Toshio Koide27ffd412014-02-18 19:15:27 -0800115
Ray Milkey269ffb92014-04-03 14:43:30 -0700116 expect(datagridService.addListener(
117 eq("onos.pathintent_state"),
118 anyObject(IEventChannelListener.class),
119 eq(Long.class),
120 eq(IntentStateList.class)))
Toshio Koidee04a9df2014-05-01 15:49:28 -0700121 .andReturn(intentStateChannel).once();
Pavlin Radoslavov13669052014-05-13 10:33:39 -0700122 restApi.addRestletRoutable(anyObject(IntentWebRoutable.class));
Toshio Koide066506e2014-02-20 19:52:09 -0800123
Ray Milkey269ffb92014-04-03 14:43:30 -0700124 replay(datagridService);
Jonathan Harte37e4e22014-05-13 19:12:02 -0700125 replay(topologyService);
Ray Milkey269ffb92014-04-03 14:43:30 -0700126 replay(modContext);
127 replay(controllerRegistryService);
128 PowerMock.replay(persistIntent, PersistIntent.class);
Pavlin Radoslavov13669052014-05-13 10:33:39 -0700129 replay(restApi);
Ray Milkey269ffb92014-04-03 14:43:30 -0700130 }
Toshio Koidec87810e2014-02-11 13:03:21 -0800131
Ray Milkey269ffb92014-04-03 14:43:30 -0700132 @After
133 public void tearDown() {
134 verify(datagridService);
Jonathan Harte37e4e22014-05-13 19:12:02 -0700135 verify(topologyService);
Ray Milkey269ffb92014-04-03 14:43:30 -0700136 verify(modContext);
137 verify(controllerRegistryService);
138 PowerMock.verify(persistIntent, PersistIntent.class);
Pavlin Radoslavov13669052014-05-13 10:33:39 -0700139 verify(restApi);
Ray Milkey269ffb92014-04-03 14:43:30 -0700140 }
Toshio Koidec87810e2014-02-11 13:03:21 -0800141
Ray Milkey269ffb92014-04-03 14:43:30 -0700142 private void showResult(PathIntentMap intents) {
143 for (Intent intent : intents.getAllIntents()) {
144 PathIntent pathIntent = (PathIntent) intent;
Yuta HIGUCHI412add62014-07-25 13:03:43 -0700145 log.debug("Path intent:" + pathIntent);
146 log.debug("Parent intent: " + pathIntent.getParentIntent().toString());
Ray Milkey269ffb92014-04-03 14:43:30 -0700147 }
148 }
Toshio Koidec87810e2014-02-11 13:03:21 -0800149
Ray Milkey269ffb92014-04-03 14:43:30 -0700150 @Test
151 public void createShortestPaths() throws FloodlightModuleException {
152 // create shortest path intents
153 IntentOperationList opList = new IntentOperationList();
154 opList.add(Operator.ADD, new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT));
155 opList.add(Operator.ADD, new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT));
156 opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L, LOCAL_PORT));
Toshio Koidec87810e2014-02-11 13:03:21 -0800157
Ray Milkey269ffb92014-04-03 14:43:30 -0700158 // compile high-level intent operations into low-level intent operations (calculate paths)
159 PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule();
160 runtime1.init(modContext);
161 runtime1.startUp(modContext);
162 IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList);
Toshio Koide27ffd412014-02-18 19:15:27 -0800163
Ray Milkey269ffb92014-04-03 14:43:30 -0700164 // compile low-level intents into flow entry installation plan
165 PlanCalcRuntime runtime2 = new PlanCalcRuntime();
166 List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList);
Toshio Koidec87810e2014-02-11 13:03:21 -0800167
Ray Milkey269ffb92014-04-03 14:43:30 -0700168 // show results
169 showResult((PathIntentMap) runtime1.getPathIntents());
Yuta HIGUCHI412add62014-07-25 13:03:43 -0700170 log.debug("{}", plan);
Ray Milkey269ffb92014-04-03 14:43:30 -0700171 }
Toshio Koidec87810e2014-02-11 13:03:21 -0800172
Ray Milkey269ffb92014-04-03 14:43:30 -0700173 @Test
174 public void createConstrainedShortestPaths() throws FloodlightModuleException {
175 // create constrained shortest path intents
176 IntentOperationList opList = new IntentOperationList();
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700177 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("1", 1L, 12L,
178 LOCAL_PORT, 2L, 21L, LOCAL_PORT, 400.0));
179 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("2", 1L, 14L,
180 LOCAL_PORT, 4L, 41L, LOCAL_PORT, 400.0));
181 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("3", 2L, 24L,
182 LOCAL_PORT, 4L, 42L, LOCAL_PORT, 400.0));
183 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("4", 2L, 23L,
184 LOCAL_PORT, 3L, 32L, LOCAL_PORT, 400.0));
185 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("5", 3L, 34L,
186 LOCAL_PORT, 4L, 43L, LOCAL_PORT, 400.0));
Toshio Koidec87810e2014-02-11 13:03:21 -0800187
Ray Milkey269ffb92014-04-03 14:43:30 -0700188 // compile high-level intent operations into low-level intent operations (calculate paths)
189 PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule();
190 runtime1.init(modContext);
191 runtime1.startUp(modContext);
192 IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList);
Toshio Koidec87810e2014-02-11 13:03:21 -0800193
Ray Milkey269ffb92014-04-03 14:43:30 -0700194 // compile low-level intents into flow entry installation plan
195 PlanCalcRuntime runtime2 = new PlanCalcRuntime();
196 List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList);
Brian O'Connor7f8e3012014-02-15 23:59:29 -0800197
Ray Milkey269ffb92014-04-03 14:43:30 -0700198 // show results
199 showResult((PathIntentMap) runtime1.getPathIntents());
Yuta HIGUCHI412add62014-07-25 13:03:43 -0700200 log.debug("{}", plan);
Ray Milkey269ffb92014-04-03 14:43:30 -0700201 }
Toshio Koidec87810e2014-02-11 13:03:21 -0800202
Ray Milkey269ffb92014-04-03 14:43:30 -0700203 @Test
204 public void createMixedShortestPaths() throws FloodlightModuleException {
205 // create constrained & best effort shortest path intents
206 IntentOperationList opList = new IntentOperationList();
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700207 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("1", 1L, 12L,
208 LOCAL_PORT, 2L, 21L, LOCAL_PORT, 400.0));
209 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("2", 1L, 14L,
210 LOCAL_PORT, 4L, 41L, LOCAL_PORT, 400.0));
211 opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 24L, LOCAL_PORT, 4L,
212 42L, LOCAL_PORT));
213 opList.add(Operator.ADD, new ShortestPathIntent("4", 2L, 23L, LOCAL_PORT, 3L,
214 32L, LOCAL_PORT));
215 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("5", 3L, 34L,
216 LOCAL_PORT, 4L, 43L, LOCAL_PORT, 400.0));
Toshio Koidec87810e2014-02-11 13:03:21 -0800217
Ray Milkey269ffb92014-04-03 14:43:30 -0700218 // compile high-level intent operations into low-level intent operations (calculate paths)
219 PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule();
220 runtime1.init(modContext);
221 runtime1.startUp(modContext);
222 IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList);
Toshio Koidec87810e2014-02-11 13:03:21 -0800223
Ray Milkey269ffb92014-04-03 14:43:30 -0700224 // compile low-level intents into flow entry installation plan
225 PlanCalcRuntime runtime2 = new PlanCalcRuntime();
226 List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList);
Brian O'Connor7f8e3012014-02-15 23:59:29 -0800227
Ray Milkey269ffb92014-04-03 14:43:30 -0700228 // show results
229 showResult((PathIntentMap) runtime1.getPathIntents());
Yuta HIGUCHI412add62014-07-25 13:03:43 -0700230 log.debug("{}", plan);
Ray Milkey269ffb92014-04-03 14:43:30 -0700231 }
Toshio Koided9fa2a82014-02-19 17:35:18 -0800232
Ray Milkey269ffb92014-04-03 14:43:30 -0700233 @Test
234 public void rerouteShortestPaths() throws FloodlightModuleException {
Pavlin Radoslavovcac157d2014-07-31 13:54:08 -0700235 List<MastershipEvent> addedMastershipEvents = new LinkedList<>();
236 List<MastershipEvent> removedMastershipEvents = new LinkedList<>();
Ray Milkey269ffb92014-04-03 14:43:30 -0700237 List<SwitchEvent> addedSwitchEvents = new LinkedList<>();
238 List<SwitchEvent> removedSwitchEvents = new LinkedList<>();
239 List<PortEvent> addedPortEvents = new LinkedList<>();
240 List<PortEvent> removedPortEvents = new LinkedList<>();
241 List<LinkEvent> addedLinkEvents = new LinkedList<>();
242 List<LinkEvent> removedLinkEvents = new LinkedList<>();
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700243 List<HostEvent> addedHostEvents = new LinkedList<>();
244 List<HostEvent> removedHostEvents = new LinkedList<>();
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700245 TopologyEvents topologyEvents;
Pavlin Radoslavov74986ce2014-02-20 13:17:20 -0800246
Ray Milkey269ffb92014-04-03 14:43:30 -0700247 // create shortest path intents
248 IntentOperationList opList = new IntentOperationList();
249 opList.add(Operator.ADD, new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT));
250 opList.add(Operator.ADD, new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT));
251 opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L, LOCAL_PORT));
Toshio Koide0c9106d2014-02-19 15:26:38 -0800252
Ray Milkey269ffb92014-04-03 14:43:30 -0700253 // compile high-level intent operations into low-level intent operations (calculate paths)
254 PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule();
255 runtime1.init(modContext);
256 runtime1.startUp(modContext);
257 IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList);
Toshio Koide0c9106d2014-02-19 15:26:38 -0800258
Ray Milkey269ffb92014-04-03 14:43:30 -0700259 // compile low-level intents into flow entry installation plan
260 PlanCalcRuntime runtime2 = new PlanCalcRuntime();
261 List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList);
Toshio Koide0c9106d2014-02-19 15:26:38 -0800262
Ray Milkey269ffb92014-04-03 14:43:30 -0700263 // show results step1
264 showResult((PathIntentMap) runtime1.getPathIntents());
Yuta HIGUCHI412add62014-07-25 13:03:43 -0700265 log.debug("{}", plan);
Toshio Koide0c9106d2014-02-19 15:26:38 -0800266
Ray Milkey269ffb92014-04-03 14:43:30 -0700267 // TODO this state changes should be triggered by notification of plan module
268 IntentStateList states = new IntentStateList();
269 states.put("1", IntentState.INST_ACK);
270 states.put("2", IntentState.INST_ACK);
271 states.put("3", IntentState.INST_ACK);
272 runtime1.getHighLevelIntents().changeStates(states);
273 states.clear();
274 states.put("1___0", IntentState.INST_ACK);
275 states.put("2___0", IntentState.INST_ACK);
276 states.put("3___0", IntentState.INST_ACK);
277 runtime1.getPathIntents().changeStates(states);
Toshio Koidea10c0372014-02-20 17:28:10 -0800278
Ray Milkey269ffb92014-04-03 14:43:30 -0700279 // link down
Jonathan Harte37e4e22014-05-13 19:12:02 -0700280 ((MockTopology) topology).removeLink(1L, 12L, 2L, 21L); // This link is used by the intent "1"
281 ((MockTopology) topology).removeLink(2L, 21L, 1L, 12L);
Yuta HIGUCHIe2a4e172014-07-03 10:50:39 -0700282 LinkEvent linkEvent1 = new LinkEvent(new SwitchPort(1L, 12L), new SwitchPort(2L, 21L));
283 LinkEvent linkEvent2 = new LinkEvent(new SwitchPort(2L, 21L), new SwitchPort(1L, 12L));
Ray Milkey269ffb92014-04-03 14:43:30 -0700284 removedLinkEvents.clear();
285 removedLinkEvents.add(linkEvent1);
286 removedLinkEvents.add(linkEvent2);
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700287
Pavlin Radoslavovcac157d2014-07-31 13:54:08 -0700288 topologyEvents = new TopologyEvents(addedMastershipEvents,
289 removedMastershipEvents,
290 addedSwitchEvents,
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700291 removedSwitchEvents,
292 addedPortEvents,
293 removedPortEvents,
294 addedLinkEvents,
295 removedLinkEvents,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700296 addedHostEvents,
297 removedHostEvents);
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700298
299 runtime1.topologyEvents(topologyEvents);
Yuta HIGUCHI412add62014-07-25 13:03:43 -0700300 log.debug("*** Link goes down. ***");
Toshio Koide7d3cee02014-06-05 18:56:19 -0700301
302 // send notification
303 IntentStateList isl = new IntentStateList();
304 isl.put("1___0", IntentState.DEL_ACK);
305 isl.put("1___1", IntentState.INST_ACK);
306 isl.domainSwitchDpids.add(1L);
307 isl.domainSwitchDpids.add(2L);
308 isl.domainSwitchDpids.add(4L);
309 runtime1.entryUpdated(isl);
Toshio Koide0c9106d2014-02-19 15:26:38 -0800310
Ray Milkey269ffb92014-04-03 14:43:30 -0700311 // show results step2
312 showResult((PathIntentMap) runtime1.getPathIntents());
Toshio Koide7d3cee02014-06-05 18:56:19 -0700313
314 // link up
315 ((MockTopology) topology).addBidirectionalLinks(1L, 12L, 2L, 21L);
Yuta HIGUCHIe2a4e172014-07-03 10:50:39 -0700316 linkEvent1 = new LinkEvent(new SwitchPort(1L, 12L), new SwitchPort(2L, 21L));
317 linkEvent2 = new LinkEvent(new SwitchPort(2L, 21L), new SwitchPort(1L, 12L));
Toshio Koide7d3cee02014-06-05 18:56:19 -0700318 removedLinkEvents.clear();
319 addedLinkEvents.clear();
320 addedLinkEvents.add(linkEvent1);
321 addedLinkEvents.add(linkEvent2);
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700322
Pavlin Radoslavovcac157d2014-07-31 13:54:08 -0700323 topologyEvents = new TopologyEvents(addedMastershipEvents,
324 removedMastershipEvents,
325 addedSwitchEvents,
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700326 removedSwitchEvents,
327 addedPortEvents,
328 removedPortEvents,
329 addedLinkEvents,
330 removedLinkEvents,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700331 addedHostEvents,
332 removedHostEvents);
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700333
334 runtime1.topologyEvents(topologyEvents);
Yuta HIGUCHI412add62014-07-25 13:03:43 -0700335 log.debug("*** Link goes up. ***");
Toshio Koide7d3cee02014-06-05 18:56:19 -0700336
337 // send notification
338 isl = new IntentStateList();
339 isl.put("1___1", IntentState.DEL_ACK);
340 isl.put("1___2", IntentState.INST_ACK);
341 isl.domainSwitchDpids.add(1L);
342 isl.domainSwitchDpids.add(2L);
343 isl.domainSwitchDpids.add(4L);
344 runtime1.entryUpdated(isl);
345
346 // show results step3
347 showResult((PathIntentMap) runtime1.getPathIntents());
348
Ray Milkey269ffb92014-04-03 14:43:30 -0700349 // TODO: show results of plan computation
350 }
Toshio Koidefa735a12014-03-28 10:49:07 -0700351
352
Ray Milkey269ffb92014-04-03 14:43:30 -0700353 @Test
354 public void createAndRemoveShortestPaths() throws FloodlightModuleException {
355 // create shortest path intents
356 IntentOperationList opList = new IntentOperationList();
357 opList.add(Operator.ADD, new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT));
358 opList.add(Operator.ADD, new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT));
359 opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L, LOCAL_PORT));
Toshio Koidefa735a12014-03-28 10:49:07 -0700360
Ray Milkey269ffb92014-04-03 14:43:30 -0700361 // compile high-level intent operations into low-level intent operations (calculate paths)
362 PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule();
363 runtime1.init(modContext);
364 runtime1.startUp(modContext);
365 IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList);
Toshio Koidefa735a12014-03-28 10:49:07 -0700366
Ray Milkey269ffb92014-04-03 14:43:30 -0700367 // compile low-level intents into flow entry installation plan
368 PlanCalcRuntime runtime2 = new PlanCalcRuntime();
369 List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList);
Toshio Koidefa735a12014-03-28 10:49:07 -0700370
Ray Milkey269ffb92014-04-03 14:43:30 -0700371 // show results
372 showResult((PathIntentMap) runtime1.getPathIntents());
Yuta HIGUCHI412add62014-07-25 13:03:43 -0700373 log.debug("{}", plan);
Toshio Koidefa735a12014-03-28 10:49:07 -0700374
Ray Milkey269ffb92014-04-03 14:43:30 -0700375 // create remove operations
376 opList.clear();
377 opList.add(Operator.REMOVE, new Intent("1"));
378 opList.add(Operator.REMOVE, new Intent("2"));
Toshio Koidefa735a12014-03-28 10:49:07 -0700379
Ray Milkey269ffb92014-04-03 14:43:30 -0700380 // compile
381 runtime1.executeIntentOperations(opList);
Toshio Koidefa735a12014-03-28 10:49:07 -0700382
Ray Milkey269ffb92014-04-03 14:43:30 -0700383 // show results
384 showResult((PathIntentMap) runtime1.getPathIntents());
Yuta HIGUCHI412add62014-07-25 13:03:43 -0700385 log.debug("{}", plan);
Ray Milkey269ffb92014-04-03 14:43:30 -0700386 }
Toshio Koidefa735a12014-03-28 10:49:07 -0700387
Toshio Koidec87810e2014-02-11 13:03:21 -0800388}