blob: b6e21879e7f2df77c1b582844e71eb4da4b88379 [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;
Yuta HIGUCHI412add62014-07-25 13:03:43 -070045
Toshio Koidec87810e2014-02-11 13:03:21 -080046import org.junit.After;
47import org.junit.Before;
48import org.junit.Test;
Nick Karanatsios8abe7172014-02-19 20:31:48 -080049import org.junit.runner.RunWith;
50import org.powermock.api.easymock.PowerMock;
51import org.powermock.core.classloader.annotations.PrepareForTest;
52import org.powermock.modules.junit4.PowerMockRunner;
Yuta HIGUCHI412add62014-07-25 13:03:43 -070053import org.slf4j.Logger;
54import org.slf4j.LoggerFactory;
Toshio Koidec87810e2014-02-11 13:03:21 -080055
56/**
Toshio Koidee04a9df2014-05-01 15:49:28 -070057 * Temporary test cases for the ONS2014 demo.
58 * These test cases should be modified and be moved to appropriate classes
59 * (ex. PathCalcRuntimeModuleTest, PlanInstallModuleTest, etc.)
Toshio Koidec87810e2014-02-11 13:03:21 -080060 */
Nick Karanatsios8abe7172014-02-19 20:31:48 -080061@RunWith(PowerMockRunner.class)
62@PrepareForTest(PathCalcRuntimeModule.class)
Toshio Koidec87810e2014-02-11 13:03:21 -080063public class UseCaseTest {
Yuta HIGUCHI412add62014-07-25 13:03:43 -070064 private static final Logger log = LoggerFactory.getLogger(UseCaseTest.class);
65
Jonathan Harte37e4e22014-05-13 19:12:02 -070066 private Topology topology;
Ray Milkey269ffb92014-04-03 14:43:30 -070067 private FloodlightModuleContext modContext;
68 private IDatagridService datagridService;
Jonathan Harte37e4e22014-05-13 19:12:02 -070069 private ITopologyService topologyService;
Ray Milkey269ffb92014-04-03 14:43:30 -070070 private IControllerRegistryService controllerRegistryService;
71 private PersistIntent persistIntent;
Pavlin Radoslavov13669052014-05-13 10:33:39 -070072 private IRestApiService restApi;
Toshio Koidee04a9df2014-05-01 15:49:28 -070073 private IEventChannel<Long, IntentOperationList> intentOperationChannel;
74 private IEventChannel<Long, IntentStateList> intentStateChannel;
Toshio Koidec87810e2014-02-11 13:03:21 -080075
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070076 private static final Long LOCAL_PORT = 0xFFFEL;
Toshio Koidefe1d5d92014-02-26 20:09:48 -080077
Ray Milkey269ffb92014-04-03 14:43:30 -070078 @SuppressWarnings("unchecked")
79 @Before
80 public void setUp() throws Exception {
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070081 MockTopology mockTopology = new MockTopology();
82 mockTopology.createSampleTopology1();
83 this.topology = mockTopology;
Toshio Koide27ffd412014-02-18 19:15:27 -080084
Ray Milkey269ffb92014-04-03 14:43:30 -070085 datagridService = createMock(IDatagridService.class);
Jonathan Harte37e4e22014-05-13 19:12:02 -070086 topologyService = createMock(ITopologyService.class);
Ray Milkey269ffb92014-04-03 14:43:30 -070087 controllerRegistryService = createMock(IControllerRegistryService.class);
88 modContext = createMock(FloodlightModuleContext.class);
Toshio Koidee04a9df2014-05-01 15:49:28 -070089 intentOperationChannel = createMock(IEventChannel.class);
90 intentStateChannel = createMock(IEventChannel.class);
Ray Milkey269ffb92014-04-03 14:43:30 -070091 persistIntent = PowerMock.createMock(PersistIntent.class);
Pavlin Radoslavov13669052014-05-13 10:33:39 -070092 restApi = createMock(IRestApiService.class);
Toshio Koide798bc1b2014-02-20 14:02:40 -080093
Ray Milkey269ffb92014-04-03 14:43:30 -070094 PowerMock.expectNew(PersistIntent.class,
Pavlin Radoslavov0294e052014-04-10 13:36:45 -070095 anyObject(IControllerRegistryService.class)).andReturn(persistIntent);
Toshio Koide27ffd412014-02-18 19:15:27 -080096
Ray Milkey269ffb92014-04-03 14:43:30 -070097 expect(modContext.getServiceImpl(IDatagridService.class))
98 .andReturn(datagridService).once();
Jonathan Harte37e4e22014-05-13 19:12:02 -070099 expect(modContext.getServiceImpl(ITopologyService.class))
100 .andReturn(topologyService).once();
Ray Milkey269ffb92014-04-03 14:43:30 -0700101 expect(modContext.getServiceImpl(IControllerRegistryService.class))
102 .andReturn(controllerRegistryService).once();
103 expect(persistIntent.getKey()).andReturn(1L).anyTimes();
104 expect(persistIntent.persistIfLeader(eq(1L),
105 anyObject(IntentOperationList.class))).andReturn(true).anyTimes();
Pavlin Radoslavov13669052014-05-13 10:33:39 -0700106 expect(modContext.getServiceImpl(IRestApiService.class))
107 .andReturn(restApi).once();
Toshio Koide0c9106d2014-02-19 15:26:38 -0800108
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700109 expect(topologyService.getTopology()).andReturn(mockTopology).anyTimes();
Jonathan Harte37e4e22014-05-13 19:12:02 -0700110 topologyService.registerTopologyListener(anyObject(ITopologyListener.class));
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);
Pavlin Radoslavovd4f40372014-07-18 16:58:40 -0700140 OnosMetrics.removeMatching(MetricFilter.ALL);
Ray Milkey269ffb92014-04-03 14:43:30 -0700141 }
Toshio Koidec87810e2014-02-11 13:03:21 -0800142
Ray Milkey269ffb92014-04-03 14:43:30 -0700143 private void showResult(PathIntentMap intents) {
144 for (Intent intent : intents.getAllIntents()) {
145 PathIntent pathIntent = (PathIntent) intent;
Yuta HIGUCHI412add62014-07-25 13:03:43 -0700146 log.debug("Path intent:" + pathIntent);
147 log.debug("Parent intent: " + pathIntent.getParentIntent().toString());
Ray Milkey269ffb92014-04-03 14:43:30 -0700148 }
149 }
Toshio Koidec87810e2014-02-11 13:03:21 -0800150
Ray Milkey269ffb92014-04-03 14:43:30 -0700151 @Test
152 public void createShortestPaths() throws FloodlightModuleException {
153 // create shortest path intents
154 IntentOperationList opList = new IntentOperationList();
155 opList.add(Operator.ADD, new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT));
156 opList.add(Operator.ADD, new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT));
157 opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L, LOCAL_PORT));
Toshio Koidec87810e2014-02-11 13:03:21 -0800158
Ray Milkey269ffb92014-04-03 14:43:30 -0700159 // compile high-level intent operations into low-level intent operations (calculate paths)
160 PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule();
161 runtime1.init(modContext);
162 runtime1.startUp(modContext);
163 IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList);
Toshio Koide27ffd412014-02-18 19:15:27 -0800164
Ray Milkey269ffb92014-04-03 14:43:30 -0700165 // compile low-level intents into flow entry installation plan
166 PlanCalcRuntime runtime2 = new PlanCalcRuntime();
167 List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList);
Toshio Koidec87810e2014-02-11 13:03:21 -0800168
Ray Milkey269ffb92014-04-03 14:43:30 -0700169 // show results
170 showResult((PathIntentMap) runtime1.getPathIntents());
Yuta HIGUCHI412add62014-07-25 13:03:43 -0700171 log.debug("{}", plan);
Ray Milkey269ffb92014-04-03 14:43:30 -0700172 }
Toshio Koidec87810e2014-02-11 13:03:21 -0800173
Ray Milkey269ffb92014-04-03 14:43:30 -0700174 @Test
175 public void createConstrainedShortestPaths() throws FloodlightModuleException {
176 // create constrained shortest path intents
177 IntentOperationList opList = new IntentOperationList();
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700178 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("1", 1L, 12L,
179 LOCAL_PORT, 2L, 21L, LOCAL_PORT, 400.0));
180 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("2", 1L, 14L,
181 LOCAL_PORT, 4L, 41L, LOCAL_PORT, 400.0));
182 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("3", 2L, 24L,
183 LOCAL_PORT, 4L, 42L, LOCAL_PORT, 400.0));
184 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("4", 2L, 23L,
185 LOCAL_PORT, 3L, 32L, LOCAL_PORT, 400.0));
186 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("5", 3L, 34L,
187 LOCAL_PORT, 4L, 43L, LOCAL_PORT, 400.0));
Toshio Koidec87810e2014-02-11 13:03:21 -0800188
Ray Milkey269ffb92014-04-03 14:43:30 -0700189 // compile high-level intent operations into low-level intent operations (calculate paths)
190 PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule();
191 runtime1.init(modContext);
192 runtime1.startUp(modContext);
193 IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList);
Toshio Koidec87810e2014-02-11 13:03:21 -0800194
Ray Milkey269ffb92014-04-03 14:43:30 -0700195 // compile low-level intents into flow entry installation plan
196 PlanCalcRuntime runtime2 = new PlanCalcRuntime();
197 List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList);
Brian O'Connor7f8e3012014-02-15 23:59:29 -0800198
Ray Milkey269ffb92014-04-03 14:43:30 -0700199 // show results
200 showResult((PathIntentMap) runtime1.getPathIntents());
Yuta HIGUCHI412add62014-07-25 13:03:43 -0700201 log.debug("{}", plan);
Ray Milkey269ffb92014-04-03 14:43:30 -0700202 }
Toshio Koidec87810e2014-02-11 13:03:21 -0800203
Ray Milkey269ffb92014-04-03 14:43:30 -0700204 @Test
205 public void createMixedShortestPaths() throws FloodlightModuleException {
206 // create constrained & best effort shortest path intents
207 IntentOperationList opList = new IntentOperationList();
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700208 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("1", 1L, 12L,
209 LOCAL_PORT, 2L, 21L, LOCAL_PORT, 400.0));
210 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("2", 1L, 14L,
211 LOCAL_PORT, 4L, 41L, LOCAL_PORT, 400.0));
212 opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 24L, LOCAL_PORT, 4L,
213 42L, LOCAL_PORT));
214 opList.add(Operator.ADD, new ShortestPathIntent("4", 2L, 23L, LOCAL_PORT, 3L,
215 32L, LOCAL_PORT));
216 opList.add(Operator.ADD, new ConstrainedShortestPathIntent("5", 3L, 34L,
217 LOCAL_PORT, 4L, 43L, LOCAL_PORT, 400.0));
Toshio Koidec87810e2014-02-11 13:03:21 -0800218
Ray Milkey269ffb92014-04-03 14:43:30 -0700219 // compile high-level intent operations into low-level intent operations (calculate paths)
220 PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule();
221 runtime1.init(modContext);
222 runtime1.startUp(modContext);
223 IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList);
Toshio Koidec87810e2014-02-11 13:03:21 -0800224
Ray Milkey269ffb92014-04-03 14:43:30 -0700225 // compile low-level intents into flow entry installation plan
226 PlanCalcRuntime runtime2 = new PlanCalcRuntime();
227 List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList);
Brian O'Connor7f8e3012014-02-15 23:59:29 -0800228
Ray Milkey269ffb92014-04-03 14:43:30 -0700229 // show results
230 showResult((PathIntentMap) runtime1.getPathIntents());
Yuta HIGUCHI412add62014-07-25 13:03:43 -0700231 log.debug("{}", plan);
Ray Milkey269ffb92014-04-03 14:43:30 -0700232 }
Toshio Koided9fa2a82014-02-19 17:35:18 -0800233
Ray Milkey269ffb92014-04-03 14:43:30 -0700234 @Test
235 public void rerouteShortestPaths() throws FloodlightModuleException {
236 List<SwitchEvent> addedSwitchEvents = new LinkedList<>();
237 List<SwitchEvent> removedSwitchEvents = new LinkedList<>();
238 List<PortEvent> addedPortEvents = new LinkedList<>();
239 List<PortEvent> removedPortEvents = new LinkedList<>();
240 List<LinkEvent> addedLinkEvents = new LinkedList<>();
241 List<LinkEvent> removedLinkEvents = new LinkedList<>();
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700242 List<HostEvent> addedHostEvents = new LinkedList<>();
243 List<HostEvent> removedHostEvents = new LinkedList<>();
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700244 TopologyEvents topologyEvents;
Pavlin Radoslavov74986ce2014-02-20 13:17:20 -0800245
Ray Milkey269ffb92014-04-03 14:43:30 -0700246 // create shortest path intents
247 IntentOperationList opList = new IntentOperationList();
248 opList.add(Operator.ADD, new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT));
249 opList.add(Operator.ADD, new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT));
250 opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L, LOCAL_PORT));
Toshio Koide0c9106d2014-02-19 15:26:38 -0800251
Ray Milkey269ffb92014-04-03 14:43:30 -0700252 // compile high-level intent operations into low-level intent operations (calculate paths)
253 PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule();
254 runtime1.init(modContext);
255 runtime1.startUp(modContext);
256 IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList);
Toshio Koide0c9106d2014-02-19 15:26:38 -0800257
Ray Milkey269ffb92014-04-03 14:43:30 -0700258 // compile low-level intents into flow entry installation plan
259 PlanCalcRuntime runtime2 = new PlanCalcRuntime();
260 List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList);
Toshio Koide0c9106d2014-02-19 15:26:38 -0800261
Ray Milkey269ffb92014-04-03 14:43:30 -0700262 // show results step1
263 showResult((PathIntentMap) runtime1.getPathIntents());
Yuta HIGUCHI412add62014-07-25 13:03:43 -0700264 log.debug("{}", plan);
Toshio Koide0c9106d2014-02-19 15:26:38 -0800265
Ray Milkey269ffb92014-04-03 14:43:30 -0700266 // TODO this state changes should be triggered by notification of plan module
267 IntentStateList states = new IntentStateList();
268 states.put("1", IntentState.INST_ACK);
269 states.put("2", IntentState.INST_ACK);
270 states.put("3", IntentState.INST_ACK);
271 runtime1.getHighLevelIntents().changeStates(states);
272 states.clear();
273 states.put("1___0", IntentState.INST_ACK);
274 states.put("2___0", IntentState.INST_ACK);
275 states.put("3___0", IntentState.INST_ACK);
276 runtime1.getPathIntents().changeStates(states);
Toshio Koidea10c0372014-02-20 17:28:10 -0800277
Ray Milkey269ffb92014-04-03 14:43:30 -0700278 // link down
Jonathan Harte37e4e22014-05-13 19:12:02 -0700279 ((MockTopology) topology).removeLink(1L, 12L, 2L, 21L); // This link is used by the intent "1"
280 ((MockTopology) topology).removeLink(2L, 21L, 1L, 12L);
Yuta HIGUCHIe2a4e172014-07-03 10:50:39 -0700281 LinkEvent linkEvent1 = new LinkEvent(new SwitchPort(1L, 12L), new SwitchPort(2L, 21L));
282 LinkEvent linkEvent2 = new LinkEvent(new SwitchPort(2L, 21L), new SwitchPort(1L, 12L));
Ray Milkey269ffb92014-04-03 14:43:30 -0700283 removedLinkEvents.clear();
284 removedLinkEvents.add(linkEvent1);
285 removedLinkEvents.add(linkEvent2);
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700286
287 topologyEvents = new TopologyEvents(0,
288 addedSwitchEvents,
289 removedSwitchEvents,
290 addedPortEvents,
291 removedPortEvents,
292 addedLinkEvents,
293 removedLinkEvents,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700294 addedHostEvents,
295 removedHostEvents);
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700296
297 runtime1.topologyEvents(topologyEvents);
Yuta HIGUCHI412add62014-07-25 13:03:43 -0700298 log.debug("*** Link goes down. ***");
Toshio Koide7d3cee02014-06-05 18:56:19 -0700299
300 // send notification
301 IntentStateList isl = new IntentStateList();
302 isl.put("1___0", IntentState.DEL_ACK);
303 isl.put("1___1", IntentState.INST_ACK);
304 isl.domainSwitchDpids.add(1L);
305 isl.domainSwitchDpids.add(2L);
306 isl.domainSwitchDpids.add(4L);
307 runtime1.entryUpdated(isl);
Toshio Koide0c9106d2014-02-19 15:26:38 -0800308
Ray Milkey269ffb92014-04-03 14:43:30 -0700309 // show results step2
310 showResult((PathIntentMap) runtime1.getPathIntents());
Toshio Koide7d3cee02014-06-05 18:56:19 -0700311
312 // link up
313 ((MockTopology) topology).addBidirectionalLinks(1L, 12L, 2L, 21L);
Yuta HIGUCHIe2a4e172014-07-03 10:50:39 -0700314 linkEvent1 = new LinkEvent(new SwitchPort(1L, 12L), new SwitchPort(2L, 21L));
315 linkEvent2 = new LinkEvent(new SwitchPort(2L, 21L), new SwitchPort(1L, 12L));
Toshio Koide7d3cee02014-06-05 18:56:19 -0700316 removedLinkEvents.clear();
317 addedLinkEvents.clear();
318 addedLinkEvents.add(linkEvent1);
319 addedLinkEvents.add(linkEvent2);
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700320
321 topologyEvents = new TopologyEvents(0,
322 addedSwitchEvents,
323 removedSwitchEvents,
324 addedPortEvents,
325 removedPortEvents,
326 addedLinkEvents,
327 removedLinkEvents,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700328 addedHostEvents,
329 removedHostEvents);
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700330
331 runtime1.topologyEvents(topologyEvents);
Yuta HIGUCHI412add62014-07-25 13:03:43 -0700332 log.debug("*** Link goes up. ***");
Toshio Koide7d3cee02014-06-05 18:56:19 -0700333
334 // send notification
335 isl = new IntentStateList();
336 isl.put("1___1", IntentState.DEL_ACK);
337 isl.put("1___2", IntentState.INST_ACK);
338 isl.domainSwitchDpids.add(1L);
339 isl.domainSwitchDpids.add(2L);
340 isl.domainSwitchDpids.add(4L);
341 runtime1.entryUpdated(isl);
342
343 // show results step3
344 showResult((PathIntentMap) runtime1.getPathIntents());
345
Ray Milkey269ffb92014-04-03 14:43:30 -0700346 // TODO: show results of plan computation
347 }
Toshio Koidefa735a12014-03-28 10:49:07 -0700348
349
Ray Milkey269ffb92014-04-03 14:43:30 -0700350 @Test
351 public void createAndRemoveShortestPaths() throws FloodlightModuleException {
352 // create shortest path intents
353 IntentOperationList opList = new IntentOperationList();
354 opList.add(Operator.ADD, new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT));
355 opList.add(Operator.ADD, new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT));
356 opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L, LOCAL_PORT));
Toshio Koidefa735a12014-03-28 10:49:07 -0700357
Ray Milkey269ffb92014-04-03 14:43:30 -0700358 // compile high-level intent operations into low-level intent operations (calculate paths)
359 PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule();
360 runtime1.init(modContext);
361 runtime1.startUp(modContext);
362 IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList);
Toshio Koidefa735a12014-03-28 10:49:07 -0700363
Ray Milkey269ffb92014-04-03 14:43:30 -0700364 // compile low-level intents into flow entry installation plan
365 PlanCalcRuntime runtime2 = new PlanCalcRuntime();
366 List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList);
Toshio Koidefa735a12014-03-28 10:49:07 -0700367
Ray Milkey269ffb92014-04-03 14:43:30 -0700368 // show results
369 showResult((PathIntentMap) runtime1.getPathIntents());
Yuta HIGUCHI412add62014-07-25 13:03:43 -0700370 log.debug("{}", plan);
Toshio Koidefa735a12014-03-28 10:49:07 -0700371
Ray Milkey269ffb92014-04-03 14:43:30 -0700372 // create remove operations
373 opList.clear();
374 opList.add(Operator.REMOVE, new Intent("1"));
375 opList.add(Operator.REMOVE, new Intent("2"));
Toshio Koidefa735a12014-03-28 10:49:07 -0700376
Ray Milkey269ffb92014-04-03 14:43:30 -0700377 // compile
378 runtime1.executeIntentOperations(opList);
Toshio Koidefa735a12014-03-28 10:49:07 -0700379
Ray Milkey269ffb92014-04-03 14:43:30 -0700380 // show results
381 showResult((PathIntentMap) runtime1.getPathIntents());
Yuta HIGUCHI412add62014-07-25 13:03:43 -0700382 log.debug("{}", plan);
Ray Milkey269ffb92014-04-03 14:43:30 -0700383 }
Toshio Koidefa735a12014-03-28 10:49:07 -0700384
Toshio Koidec87810e2014-02-11 13:03:21 -0800385}