blob: 421d2fa6b6dc48964b022a60fbeb7693bc69da76 [file] [log] [blame]
Jonathan Hartaa380972014-04-03 10:24:46 -07001package net.onrc.onos.core.intent.runtime;
Ray Milkey6688cd82014-03-11 16:40:46 -07002
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;
10import static org.hamcrest.MatcherAssert.assertThat;
11import static org.hamcrest.Matchers.equalTo;
12import static org.hamcrest.Matchers.hasItem;
13import static org.hamcrest.Matchers.hasSize;
14import static org.hamcrest.Matchers.notNullValue;
15
16import java.util.Collection;
17import java.util.LinkedList;
18import java.util.List;
19
Ray Milkey6688cd82014-03-11 16:40:46 -070020import net.floodlightcontroller.core.module.FloodlightModuleContext;
21import net.floodlightcontroller.core.module.FloodlightModuleException;
Jonathan Hart6df90172014-04-03 10:13:11 -070022import net.onrc.onos.core.datagrid.IDatagridService;
23import net.onrc.onos.core.datagrid.IEventChannel;
24import net.onrc.onos.core.datagrid.IEventChannelListener;
Jonathan Hartaa380972014-04-03 10:24:46 -070025import net.onrc.onos.core.intent.Intent;
Jonathan Harta88fd242014-04-03 11:24:54 -070026import net.onrc.onos.core.intent.Intent.IntentState;
Jonathan Hartaa380972014-04-03 10:24:46 -070027import net.onrc.onos.core.intent.IntentMap;
Jonathan Harta88fd242014-04-03 11:24:54 -070028import net.onrc.onos.core.intent.IntentOperation.Operator;
Jonathan Hartaa380972014-04-03 10:24:46 -070029import net.onrc.onos.core.intent.IntentOperationList;
30import net.onrc.onos.core.intent.MockNetworkGraph;
31import net.onrc.onos.core.intent.ShortestPathIntent;
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;
34import net.onrc.onos.core.topology.INetworkGraphListener;
35import net.onrc.onos.core.topology.INetworkGraphService;
36import net.onrc.onos.core.topology.LinkEvent;
37import net.onrc.onos.core.topology.PortEvent;
38import net.onrc.onos.core.topology.SwitchEvent;
Ray Milkey6688cd82014-03-11 16:40:46 -070039
Jonathan Harta88fd242014-04-03 11:24:54 -070040import org.hamcrest.Description;
41import org.hamcrest.Factory;
42import org.hamcrest.Matcher;
43import org.hamcrest.Matchers;
44import org.hamcrest.TypeSafeMatcher;
Ray Milkey6688cd82014-03-11 16:40:46 -070045import org.junit.After;
46import org.junit.Before;
47import org.junit.Test;
48import org.junit.runner.RunWith;
49import org.powermock.api.easymock.PowerMock;
50import org.powermock.core.classloader.annotations.PrepareForTest;
51import org.powermock.modules.junit4.PowerMockRunner;
52
Ray Milkey6688cd82014-03-11 16:40:46 -070053/**
54 * @author Ray Milkey (ray@onlab.us)
Ray Milkey269ffb92014-04-03 14:43:30 -070055 * <p/>
56 * Unit tests for the Path Calculation Runtime module (PathCalcRuntimeModule).
57 * These test cases check the results of creating paths, deleting paths, and
58 * rerouting paths. The network graph, controller registry, and data grid are
59 * mocked out. The individual tests check the high level intents and the
60 * resulting operation lists to be sure they match the intended APIs.
Ray Milkey6688cd82014-03-11 16:40:46 -070061 */
62@RunWith(PowerMockRunner.class)
63@PrepareForTest(PathCalcRuntimeModule.class)
64public class PathCalcRuntimeModuleTest {
Ray Milkeydc659c42014-03-28 16:30:42 -070065 private static final Long LOCAL_PORT = 0xFFFEL;
66
Ray Milkey6688cd82014-03-11 16:40:46 -070067 private FloodlightModuleContext modContext;
68 private IDatagridService datagridService;
69 private INetworkGraphService networkGraphService;
70 private IControllerRegistryService controllerRegistryService;
71 private PersistIntent persistIntent;
Ray Milkeydc659c42014-03-28 16:30:42 -070072 private MockNetworkGraph graph;
Ray Milkey6688cd82014-03-11 16:40:46 -070073
74 @SuppressWarnings("unchecked")
75 @Before
76 public void setUp() throws Exception {
Ray Milkeydc659c42014-03-28 16:30:42 -070077 graph = new MockNetworkGraph();
Ray Milkey6688cd82014-03-11 16:40:46 -070078 graph.createSampleTopology1();
79
80 datagridService = createMock(IDatagridService.class);
81 networkGraphService = createMock(INetworkGraphService.class);
82 controllerRegistryService = createMock(IControllerRegistryService.class);
83 modContext = createMock(FloodlightModuleContext.class);
84 final IEventChannel eventChannel = createMock(IEventChannel.class);
85 persistIntent = PowerMock.createMock(PersistIntent.class);
86
87 PowerMock.expectNew(PersistIntent.class,
Pavlin Radoslavov0294e052014-04-10 13:36:45 -070088 anyObject(IControllerRegistryService.class)).andReturn(persistIntent);
Ray Milkey6688cd82014-03-11 16:40:46 -070089
90 expect(modContext.getServiceImpl(IDatagridService.class))
91 .andReturn(datagridService).once();
92 expect(modContext.getServiceImpl(INetworkGraphService.class))
93 .andReturn(networkGraphService).once();
94 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)
99 .anyTimes();
100
101 expect(networkGraphService.getNetworkGraph()).andReturn(graph)
102 .anyTimes();
103 networkGraphService.registerNetworkGraphListener(
104 anyObject(INetworkGraphListener.class));
105 expectLastCall();
106
107 expect(datagridService.createChannel("onos.pathintent",
108 Long.class, IntentOperationList.class))
109 .andReturn(eventChannel).once();
110
111 expect(datagridService.addListener(
112 eq("onos.pathintent_state"),
113 anyObject(IEventChannelListener.class),
114 eq(Long.class),
115 eq(IntentStateList.class)))
116 .andReturn(eventChannel).once();
117
118 replay(datagridService);
119 replay(networkGraphService);
120 replay(modContext);
121 replay(controllerRegistryService);
122 PowerMock.replay(persistIntent, PersistIntent.class);
123 }
124
Ray Milkeydc659c42014-03-28 16:30:42 -0700125
126 /**
127 * Hamcrest matcher to check that a collection of Intents contains an
128 * Intent with the specified Intent Id.
129 */
130 public static class EntryForIntentMatcher extends TypeSafeMatcher<Collection<Intent>> {
131 final private String id;
132
133 public EntryForIntentMatcher(String idValue) {
134 id = idValue;
135 }
136
137 @Override
138 public boolean matchesSafely(Collection<Intent> intents) {
139 assertThat(intents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700140 hasItem(Matchers.<Intent>hasProperty("id", equalTo(id))));
Ray Milkeydc659c42014-03-28 16:30:42 -0700141 return true;
142 }
143
144 @Override
145 public void describeTo(Description description) {
146 description.appendText("an intent with id \" ").
147 appendText(id).
148 appendText("\"");
149 }
150 }
151
152
153 /**
154 * Factory method to create an Intent entry Matcher. Returns a matcher
155 * for the Intent with the given id.
Ray Milkey269ffb92014-04-03 14:43:30 -0700156 *
Ray Milkeydc659c42014-03-28 16:30:42 -0700157 * @param id id of the intent to match
158 * @return Matcher object
159 */
160 @Factory
161 public static Matcher<Collection<Intent>> hasIntentWithId(String id) {
162 return new EntryForIntentMatcher(id);
163 }
164
165
166 /**
167 * Matcher to determine if an IntentMap contains an entry with a given id,
168 * and that entry has a given state.
169 */
170 public static class IntentsHaveIntentWithStateMatcher extends TypeSafeMatcher<IntentMap> {
171 final private String id;
172 final private IntentState state;
173 private Intent intent;
174
175 public IntentsHaveIntentWithStateMatcher(String idValue,
176 IntentState stateValue) {
177 id = idValue;
178 state = stateValue;
179 }
180
181 @Override
182 public boolean matchesSafely(IntentMap intents) {
183 intent = intents.getIntent(id);
184
185 return intent != null && intent.getState() == state;
186 }
187
188 @Override
189 public void describeTo(Description description) {
190 if (intent == null) {
191 description.appendText("intent lookup for id \"");
192 description.appendText(id);
193 description.appendText("\"");
194 } else {
195 description.appendText("state ");
196 description.appendText(state.toString());
197 }
198 }
199
200 @Override
201 public void describeMismatchSafely(IntentMap intents,
202 Description mismatchDescription) {
203 if (intent != null) {
204 mismatchDescription.appendText("was ").
Ray Milkey269ffb92014-04-03 14:43:30 -0700205 appendText(intent.getState().toString());
Ray Milkeydc659c42014-03-28 16:30:42 -0700206 } else {
207 mismatchDescription.appendText("that intent was not found");
208 }
209 }
210 }
211
212
213 /**
214 * Factory method to create a Matcher for an IntentMap that looks for an
215 * Intent with a given id and state.
216 *
Ray Milkey269ffb92014-04-03 14:43:30 -0700217 * @param id id of the Intent to match
Ray Milkeydc659c42014-03-28 16:30:42 -0700218 * @param state if the Intent is found, its state must match this
219 * @return Matcher object
220 */
221 @Factory
222 public static Matcher<IntentMap> hasIntentWithIdAndState(String id,
223 IntentState state) {
224 return new IntentsHaveIntentWithStateMatcher(id, state);
225 }
226
227
Ray Milkey6688cd82014-03-11 16:40:46 -0700228 @After
229 public void tearDown() {
230 verify(datagridService);
231 verify(networkGraphService);
232 verify(modContext);
233 verify(controllerRegistryService);
234 PowerMock.verify(persistIntent, PersistIntent.class);
235 }
236
237 /**
238 * Test the result of executing a path calculation on an
239 * Intent Operation List which contains a path that references a
240 * non-existent switch.
Ray Milkey269ffb92014-04-03 14:43:30 -0700241 * <p/>
Ray Milkey6688cd82014-03-11 16:40:46 -0700242 * A 3 path list is created where one of the paths references a switch
243 * that is not in the topology. The test checks that the resulting
244 * Operation List has entries for the 2 correct paths, and that the
245 * high level intents contain a proper error entry for the bad path.
246 */
247 @Test
248 public void testInvalidSwitchName() throws FloodlightModuleException {
Ray Milkey6688cd82014-03-11 16:40:46 -0700249 final String BAD_SWITCH_INTENT_NAME = "No Such Switch Intent";
250
251 // create shortest path intents
252 final IntentOperationList opList = new IntentOperationList();
253 opList.add(Operator.ADD,
254 new ShortestPathIntent(BAD_SWITCH_INTENT_NAME, 111L, 12L,
255 LOCAL_PORT, 2L, 21L, LOCAL_PORT));
256 opList.add(Operator.ADD,
257 new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L,
258 LOCAL_PORT));
259 opList.add(Operator.ADD,
260 new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L,
261 LOCAL_PORT));
262
263 // compile high-level intent operations into low-level intent
264 // operations (calculate paths)
265 final PathCalcRuntimeModule runtime = new PathCalcRuntimeModule();
266 runtime.init(modContext);
267 runtime.startUp(modContext);
268 final IntentOperationList pathIntentOpList =
269 runtime.executeIntentOperations(opList);
270 assertThat(pathIntentOpList, notNullValue());
271
272 final IntentMap highLevelIntents = runtime.getHighLevelIntents();
273 assertThat(highLevelIntents, notNullValue());
274
275 final Collection<Intent> allIntents = highLevelIntents.getAllIntents();
276 assertThat(allIntents, notNullValue());
277
278 // One intent had an error and should not create a path list entry
279 assertThat(pathIntentOpList, hasSize(opList.size() - 1));
280
281 // Should be a high level intent for each operation
Ray Milkeydc659c42014-03-28 16:30:42 -0700282 assertThat(allIntents, hasSize(opList.size()));
Ray Milkey6688cd82014-03-11 16:40:46 -0700283
284 // Check that we got a high level intent for each operation
Ray Milkeydc659c42014-03-28 16:30:42 -0700285 assertThat(allIntents, hasIntentWithId("3"));
286 assertThat(allIntents, hasIntentWithId("2"));
287 assertThat(allIntents, hasIntentWithId(BAD_SWITCH_INTENT_NAME));
Ray Milkey6688cd82014-03-11 16:40:46 -0700288
289 // Check that the non existent switch was NACKed
Ray Milkeydc659c42014-03-28 16:30:42 -0700290 assertThat(highLevelIntents, hasIntentWithIdAndState(BAD_SWITCH_INTENT_NAME, IntentState.INST_NACK));
Ray Milkey6688cd82014-03-11 16:40:46 -0700291
292 // Check that switch 2 was correctly processed
Ray Milkeydc659c42014-03-28 16:30:42 -0700293 assertThat(highLevelIntents, hasIntentWithIdAndState("2", IntentState.INST_REQ));
Ray Milkey6688cd82014-03-11 16:40:46 -0700294
295 // Check that switch 3 was correctly processed
Ray Milkeydc659c42014-03-28 16:30:42 -0700296 assertThat(highLevelIntents, hasIntentWithIdAndState("3", IntentState.INST_REQ));
297
298 }
299
300
301 /**
302 * Test the result of executing a path calculation on an
303 * Intent Operation List and then removing one of the switches.
Ray Milkey269ffb92014-04-03 14:43:30 -0700304 * <p/>
Ray Milkeydc659c42014-03-28 16:30:42 -0700305 * A 3 path list is created and then one of the paths is removed.
306 * The test checks that the resulting Operation List is correct,
307 * and that the high level intents contain a proper "delete requested"
308 * entry for the deleted path.
309 */
310 @Test
311 public void testIntentRemoval() throws FloodlightModuleException {
312
313 // create shortest path intents
314 final IntentOperationList opList = new IntentOperationList();
315 opList.add(Operator.ADD,
316 new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L,
Ray Milkey269ffb92014-04-03 14:43:30 -0700317 LOCAL_PORT));
Ray Milkeydc659c42014-03-28 16:30:42 -0700318 opList.add(Operator.ADD,
319 new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L,
Ray Milkey269ffb92014-04-03 14:43:30 -0700320 LOCAL_PORT));
Ray Milkeydc659c42014-03-28 16:30:42 -0700321 opList.add(Operator.ADD,
322 new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L,
Ray Milkey269ffb92014-04-03 14:43:30 -0700323 LOCAL_PORT));
Ray Milkeydc659c42014-03-28 16:30:42 -0700324
325 // compile high-level intent operations into low-level intent
326 // operations (calculate paths)
327 final PathCalcRuntimeModule runtime = new PathCalcRuntimeModule();
328 runtime.init(modContext);
329 runtime.startUp(modContext);
330 final IntentOperationList pathIntentOpList =
331 runtime.executeIntentOperations(opList);
332 assertThat(pathIntentOpList, notNullValue());
333
334 final IntentMap highLevelIntents = runtime.getHighLevelIntents();
335 assertThat(highLevelIntents, notNullValue());
336
337 final Collection<Intent> allIntents = highLevelIntents.getAllIntents();
338 assertThat(allIntents, notNullValue());
339
340 // Should be one operation per path
341 assertThat(pathIntentOpList, hasSize(opList.size()));
342
343 // Should be a high level intent for each operation
344 assertThat(allIntents, hasSize(opList.size()));
345
346 // Check that we got a high level intent for each operation
347 assertThat(allIntents, hasIntentWithId("3"));
348 assertThat(allIntents, hasIntentWithId("2"));
349 assertThat(allIntents, hasIntentWithId("1"));
350
351 // Check that switch 1 was correctly processed
352 assertThat(highLevelIntents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700353 hasIntentWithIdAndState("1", IntentState.INST_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700354
355 // Check that switch 2 was correctly processed
356 assertThat(highLevelIntents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700357 hasIntentWithIdAndState("2", IntentState.INST_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700358
359 // Check that switch 3 was correctly processed
360 assertThat(highLevelIntents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700361 hasIntentWithIdAndState("3", IntentState.INST_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700362
363 // Now delete one path and check the results
364 final IntentOperationList opListForRemoval = new IntentOperationList();
365 opListForRemoval.add(Operator.REMOVE,
366 new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L,
367 LOCAL_PORT));
368
369 final IntentOperationList pathIntentOpListAfterRemoval =
370 runtime.executeIntentOperations(opListForRemoval);
371 assertThat(pathIntentOpListAfterRemoval, notNullValue());
372 assertThat(pathIntentOpListAfterRemoval, hasSize(1));
373
374 // Check the high level intents.
375 final IntentMap highLevelIntentsAfterRemoval = runtime.getHighLevelIntents();
376 assertThat(highLevelIntentsAfterRemoval, notNullValue());
377
378 final Collection<Intent> allIntentsAfterRemoval = highLevelIntentsAfterRemoval.getAllIntents();
379 assertThat(allIntentsAfterRemoval, notNullValue());
380 assertThat(allIntentsAfterRemoval, hasSize(3));
381
382 // Check that we got a high level intent for each operation
383 assertThat(allIntentsAfterRemoval, hasIntentWithId("3"));
384 assertThat(allIntentsAfterRemoval, hasIntentWithId("2"));
385 assertThat(allIntentsAfterRemoval, hasIntentWithId("1"));
386
387 // Check the states of the high level intents
388 // Check that switch 1 was correctly processed
389 assertThat(highLevelIntents,
390 hasIntentWithIdAndState("1", IntentState.DEL_REQ));
391
392 // Check that switch 2 was correctly processed
393 assertThat(highLevelIntents,
394 hasIntentWithIdAndState("2", IntentState.INST_REQ));
395
396 // Check that switch 3 was correctly processed
397 assertThat(highLevelIntents,
398 hasIntentWithIdAndState("3", IntentState.INST_REQ));
399 }
400
401 /**
402 * Test the result of executing a path calculation on an
403 * Intent Operation List and then forcing a reroute.
Ray Milkey269ffb92014-04-03 14:43:30 -0700404 * <p/>
Ray Milkeydc659c42014-03-28 16:30:42 -0700405 * A 3 path list is created and then one of the links is removed.
406 * The test checks that the resulting Operation List is correct,
407 * and that the high level intents contain a proper "reroute requested"
408 * entry for the deleted link.
409 */
410 @Test
411 public void testIntentReroute() throws FloodlightModuleException {
412
413 // create shortest path intents
414 final IntentOperationList opList = new IntentOperationList();
415 final ShortestPathIntent pathIntent1 =
416 new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L,
Ray Milkey269ffb92014-04-03 14:43:30 -0700417 LOCAL_PORT);
Ray Milkeydc659c42014-03-28 16:30:42 -0700418
419 opList.add(Operator.ADD, pathIntent1);
420 opList.add(Operator.ADD,
421 new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L,
Ray Milkey269ffb92014-04-03 14:43:30 -0700422 LOCAL_PORT));
Ray Milkeydc659c42014-03-28 16:30:42 -0700423 opList.add(Operator.ADD,
424 new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L,
Ray Milkey269ffb92014-04-03 14:43:30 -0700425 LOCAL_PORT));
Ray Milkeydc659c42014-03-28 16:30:42 -0700426
427 // compile high-level intent operations into low-level intent
428 // operations (calculate paths)
429 final PathCalcRuntimeModule runtime = new PathCalcRuntimeModule();
430 runtime.init(modContext);
431 runtime.startUp(modContext);
432 final IntentOperationList pathIntentOpList =
433 runtime.executeIntentOperations(opList);
434 assertThat(pathIntentOpList, notNullValue());
435
436 final IntentMap highLevelIntents = runtime.getHighLevelIntents();
437 assertThat(highLevelIntents, notNullValue());
438
439 final Collection<Intent> allIntents = highLevelIntents.getAllIntents();
440 assertThat(allIntents, notNullValue());
441
442 // Should be one operation per path
443 assertThat(pathIntentOpList, hasSize(opList.size()));
444
445 // Should be a high level intent for each operation
446 assertThat(allIntents, hasSize(opList.size()));
447
448 // Check that we got a high level intent for each operation
449 assertThat(allIntents, hasIntentWithId("3"));
450 assertThat(allIntents, hasIntentWithId("2"));
451 assertThat(allIntents, hasIntentWithId("1"));
452
453 // Check that switch 1 was correctly processed
454 assertThat(highLevelIntents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700455 hasIntentWithIdAndState("1", IntentState.INST_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700456
457 // Check that switch 2 was correctly processed
458 assertThat(highLevelIntents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700459 hasIntentWithIdAndState("2", IntentState.INST_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700460
461 // Check that switch 3 was correctly processed
462 assertThat(highLevelIntents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700463 hasIntentWithIdAndState("3", IntentState.INST_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700464
465 // Now add a different path to one of the switches path and check
466 // the results
467 IntentStateList states = new IntentStateList();
468 states.put("1", IntentState.INST_ACK);
469 states.put("2", IntentState.INST_ACK);
470 states.put("3", IntentState.INST_ACK);
471 runtime.getHighLevelIntents().changeStates(states);
472 states.clear();
473 states.put("1___0", IntentState.INST_ACK);
474 states.put("2___0", IntentState.INST_ACK);
475 states.put("3___0", IntentState.INST_ACK);
476 runtime.getPathIntents().changeStates(states);
477
478 final List<SwitchEvent> emptySwitchEvents = new LinkedList<>();
479 final List<PortEvent> emptyPortEvents = new LinkedList<>();
480 final List<DeviceEvent> emptyDeviceEvents = new LinkedList<>();
481 final List<LinkEvent> addedLinkEvents = new LinkedList<>();
482 final List<LinkEvent> removedLinkEvents = new LinkedList<>();
483
484 graph.removeLink(1L, 12L, 2L, 21L); // This link is used by the intent "1"
485 graph.removeLink(2L, 21L, 1L, 12L);
486 LinkEvent linkEvent1 = new LinkEvent(1L, 12L, 2L, 21L);
487 LinkEvent linkEvent2 = new LinkEvent(2L, 21L, 1L, 12L);
488 removedLinkEvents.add(linkEvent1);
489 removedLinkEvents.add(linkEvent2);
490 runtime.networkGraphEvents(
491 emptySwitchEvents,
492 emptySwitchEvents,
493 emptyPortEvents,
494 emptyPortEvents,
495 addedLinkEvents,
496 removedLinkEvents,
497 emptyDeviceEvents,
498 emptyDeviceEvents);
499 final IntentOperationList opListForReroute = new IntentOperationList();
500 opListForReroute.add(Operator.ADD, pathIntent1);
501
502 final IntentOperationList pathIntentOpListAfterReroute =
503 runtime.executeIntentOperations(opListForReroute);
504 assertThat(pathIntentOpListAfterReroute, notNullValue());
505 assertThat(pathIntentOpListAfterReroute, hasSize(2));
506
507 // Check the high level intents.
508 final IntentMap highLevelIntentsAfterReroute = runtime.getHighLevelIntents();
509 assertThat(highLevelIntentsAfterReroute, notNullValue());
510
511 final Collection<Intent> allIntentsAfterReroute = highLevelIntentsAfterReroute.getAllIntents();
512 assertThat(allIntentsAfterReroute, notNullValue());
513 assertThat(allIntentsAfterReroute, hasSize(3));
514
515 // Check that we got a high level intent for each operation
516 assertThat(allIntentsAfterReroute, hasIntentWithId("3"));
517 assertThat(allIntentsAfterReroute, hasIntentWithId("2"));
518 assertThat(allIntentsAfterReroute, hasIntentWithId("1"));
519
520 // Check the states of the high level intents
521 // Check that switch 1 was correctly processed
522 assertThat(highLevelIntents,
523 hasIntentWithIdAndState("1", IntentState.REROUTE_REQ));
524
525 // Check that switch 2 was correctly processed
526 assertThat(highLevelIntents,
527 hasIntentWithIdAndState("2", IntentState.INST_ACK));
528
529 // Check that switch 3 was correctly processed
530 assertThat(highLevelIntents,
531 hasIntentWithIdAndState("3", IntentState.INST_ACK));
532
Ray Milkey6688cd82014-03-11 16:40:46 -0700533
534 }
535
536
537}