blob: 17f578818730249a85c8d9abce05c67e4ad9d69f [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;
Toshio Koidee04a9df2014-05-01 15:49:28 -070073 private IEventChannel<Long, IntentOperationList> intentOperationChannel;
74 private IEventChannel<Long, IntentStateList> intentStateChannel;
Ray Milkey6688cd82014-03-11 16:40:46 -070075
76 @SuppressWarnings("unchecked")
77 @Before
78 public void setUp() throws Exception {
Ray Milkeydc659c42014-03-28 16:30:42 -070079 graph = new MockNetworkGraph();
Ray Milkey6688cd82014-03-11 16:40:46 -070080 graph.createSampleTopology1();
81
82 datagridService = createMock(IDatagridService.class);
83 networkGraphService = createMock(INetworkGraphService.class);
84 controllerRegistryService = createMock(IControllerRegistryService.class);
85 modContext = createMock(FloodlightModuleContext.class);
Toshio Koidee04a9df2014-05-01 15:49:28 -070086 intentOperationChannel = createMock(IEventChannel.class);
87 intentStateChannel = createMock(IEventChannel.class);
Ray Milkey6688cd82014-03-11 16:40:46 -070088 persistIntent = PowerMock.createMock(PersistIntent.class);
89
90 PowerMock.expectNew(PersistIntent.class,
Pavlin Radoslavov0294e052014-04-10 13:36:45 -070091 anyObject(IControllerRegistryService.class)).andReturn(persistIntent);
Ray Milkey6688cd82014-03-11 16:40:46 -070092
93 expect(modContext.getServiceImpl(IDatagridService.class))
94 .andReturn(datagridService).once();
95 expect(modContext.getServiceImpl(INetworkGraphService.class))
96 .andReturn(networkGraphService).once();
97 expect(modContext.getServiceImpl(IControllerRegistryService.class))
98 .andReturn(controllerRegistryService).once();
99 expect(persistIntent.getKey()).andReturn(1L).anyTimes();
100 expect(persistIntent.persistIfLeader(eq(1L),
101 anyObject(IntentOperationList.class))).andReturn(true)
102 .anyTimes();
103
104 expect(networkGraphService.getNetworkGraph()).andReturn(graph)
105 .anyTimes();
106 networkGraphService.registerNetworkGraphListener(
107 anyObject(INetworkGraphListener.class));
108 expectLastCall();
109
110 expect(datagridService.createChannel("onos.pathintent",
111 Long.class, IntentOperationList.class))
Toshio Koidee04a9df2014-05-01 15:49:28 -0700112 .andReturn(intentOperationChannel).once();
Ray Milkey6688cd82014-03-11 16:40:46 -0700113
114 expect(datagridService.addListener(
115 eq("onos.pathintent_state"),
116 anyObject(IEventChannelListener.class),
117 eq(Long.class),
118 eq(IntentStateList.class)))
Toshio Koidee04a9df2014-05-01 15:49:28 -0700119 .andReturn(intentStateChannel).once();
Ray Milkey6688cd82014-03-11 16:40:46 -0700120
121 replay(datagridService);
122 replay(networkGraphService);
123 replay(modContext);
124 replay(controllerRegistryService);
125 PowerMock.replay(persistIntent, PersistIntent.class);
126 }
127
Ray Milkeydc659c42014-03-28 16:30:42 -0700128
129 /**
130 * Hamcrest matcher to check that a collection of Intents contains an
131 * Intent with the specified Intent Id.
132 */
133 public static class EntryForIntentMatcher extends TypeSafeMatcher<Collection<Intent>> {
134 final private String id;
135
136 public EntryForIntentMatcher(String idValue) {
137 id = idValue;
138 }
139
140 @Override
141 public boolean matchesSafely(Collection<Intent> intents) {
142 assertThat(intents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700143 hasItem(Matchers.<Intent>hasProperty("id", equalTo(id))));
Ray Milkeydc659c42014-03-28 16:30:42 -0700144 return true;
145 }
146
147 @Override
148 public void describeTo(Description description) {
149 description.appendText("an intent with id \" ").
150 appendText(id).
151 appendText("\"");
152 }
153 }
154
155
156 /**
157 * Factory method to create an Intent entry Matcher. Returns a matcher
158 * for the Intent with the given id.
Ray Milkey269ffb92014-04-03 14:43:30 -0700159 *
Ray Milkeydc659c42014-03-28 16:30:42 -0700160 * @param id id of the intent to match
161 * @return Matcher object
162 */
163 @Factory
164 public static Matcher<Collection<Intent>> hasIntentWithId(String id) {
165 return new EntryForIntentMatcher(id);
166 }
167
168
169 /**
170 * Matcher to determine if an IntentMap contains an entry with a given id,
171 * and that entry has a given state.
172 */
173 public static class IntentsHaveIntentWithStateMatcher extends TypeSafeMatcher<IntentMap> {
174 final private String id;
175 final private IntentState state;
176 private Intent intent;
177
178 public IntentsHaveIntentWithStateMatcher(String idValue,
179 IntentState stateValue) {
180 id = idValue;
181 state = stateValue;
182 }
183
184 @Override
185 public boolean matchesSafely(IntentMap intents) {
186 intent = intents.getIntent(id);
187
188 return intent != null && intent.getState() == state;
189 }
190
191 @Override
192 public void describeTo(Description description) {
193 if (intent == null) {
194 description.appendText("intent lookup for id \"");
195 description.appendText(id);
196 description.appendText("\"");
197 } else {
198 description.appendText("state ");
199 description.appendText(state.toString());
200 }
201 }
202
203 @Override
204 public void describeMismatchSafely(IntentMap intents,
205 Description mismatchDescription) {
206 if (intent != null) {
207 mismatchDescription.appendText("was ").
Ray Milkey269ffb92014-04-03 14:43:30 -0700208 appendText(intent.getState().toString());
Ray Milkeydc659c42014-03-28 16:30:42 -0700209 } else {
210 mismatchDescription.appendText("that intent was not found");
211 }
212 }
213 }
214
215
216 /**
217 * Factory method to create a Matcher for an IntentMap that looks for an
218 * Intent with a given id and state.
219 *
Ray Milkey269ffb92014-04-03 14:43:30 -0700220 * @param id id of the Intent to match
Ray Milkeydc659c42014-03-28 16:30:42 -0700221 * @param state if the Intent is found, its state must match this
222 * @return Matcher object
223 */
224 @Factory
225 public static Matcher<IntentMap> hasIntentWithIdAndState(String id,
226 IntentState state) {
227 return new IntentsHaveIntentWithStateMatcher(id, state);
228 }
229
230
Ray Milkey6688cd82014-03-11 16:40:46 -0700231 @After
232 public void tearDown() {
233 verify(datagridService);
234 verify(networkGraphService);
235 verify(modContext);
236 verify(controllerRegistryService);
237 PowerMock.verify(persistIntent, PersistIntent.class);
238 }
239
240 /**
241 * Test the result of executing a path calculation on an
242 * Intent Operation List which contains a path that references a
243 * non-existent switch.
Ray Milkey269ffb92014-04-03 14:43:30 -0700244 * <p/>
Ray Milkey6688cd82014-03-11 16:40:46 -0700245 * A 3 path list is created where one of the paths references a switch
246 * that is not in the topology. The test checks that the resulting
247 * Operation List has entries for the 2 correct paths, and that the
248 * high level intents contain a proper error entry for the bad path.
249 */
250 @Test
251 public void testInvalidSwitchName() throws FloodlightModuleException {
Ray Milkey6688cd82014-03-11 16:40:46 -0700252 final String BAD_SWITCH_INTENT_NAME = "No Such Switch Intent";
253
254 // create shortest path intents
255 final IntentOperationList opList = new IntentOperationList();
256 opList.add(Operator.ADD,
257 new ShortestPathIntent(BAD_SWITCH_INTENT_NAME, 111L, 12L,
258 LOCAL_PORT, 2L, 21L, LOCAL_PORT));
259 opList.add(Operator.ADD,
260 new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L,
261 LOCAL_PORT));
262 opList.add(Operator.ADD,
263 new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L,
264 LOCAL_PORT));
265
266 // compile high-level intent operations into low-level intent
267 // operations (calculate paths)
268 final PathCalcRuntimeModule runtime = new PathCalcRuntimeModule();
269 runtime.init(modContext);
270 runtime.startUp(modContext);
271 final IntentOperationList pathIntentOpList =
272 runtime.executeIntentOperations(opList);
273 assertThat(pathIntentOpList, notNullValue());
274
275 final IntentMap highLevelIntents = runtime.getHighLevelIntents();
276 assertThat(highLevelIntents, notNullValue());
277
278 final Collection<Intent> allIntents = highLevelIntents.getAllIntents();
279 assertThat(allIntents, notNullValue());
280
281 // One intent had an error and should not create a path list entry
282 assertThat(pathIntentOpList, hasSize(opList.size() - 1));
283
284 // Should be a high level intent for each operation
Ray Milkeydc659c42014-03-28 16:30:42 -0700285 assertThat(allIntents, hasSize(opList.size()));
Ray Milkey6688cd82014-03-11 16:40:46 -0700286
287 // Check that we got a high level intent for each operation
Ray Milkeydc659c42014-03-28 16:30:42 -0700288 assertThat(allIntents, hasIntentWithId("3"));
289 assertThat(allIntents, hasIntentWithId("2"));
290 assertThat(allIntents, hasIntentWithId(BAD_SWITCH_INTENT_NAME));
Ray Milkey6688cd82014-03-11 16:40:46 -0700291
292 // Check that the non existent switch was NACKed
Ray Milkeydc659c42014-03-28 16:30:42 -0700293 assertThat(highLevelIntents, hasIntentWithIdAndState(BAD_SWITCH_INTENT_NAME, IntentState.INST_NACK));
Ray Milkey6688cd82014-03-11 16:40:46 -0700294
295 // Check that switch 2 was correctly processed
Ray Milkeydc659c42014-03-28 16:30:42 -0700296 assertThat(highLevelIntents, hasIntentWithIdAndState("2", IntentState.INST_REQ));
Ray Milkey6688cd82014-03-11 16:40:46 -0700297
298 // Check that switch 3 was correctly processed
Ray Milkeydc659c42014-03-28 16:30:42 -0700299 assertThat(highLevelIntents, hasIntentWithIdAndState("3", IntentState.INST_REQ));
300
301 }
302
303
304 /**
305 * Test the result of executing a path calculation on an
306 * Intent Operation List and then removing one of the switches.
Ray Milkey269ffb92014-04-03 14:43:30 -0700307 * <p/>
Ray Milkeydc659c42014-03-28 16:30:42 -0700308 * A 3 path list is created and then one of the paths is removed.
309 * The test checks that the resulting Operation List is correct,
310 * and that the high level intents contain a proper "delete requested"
311 * entry for the deleted path.
312 */
313 @Test
314 public void testIntentRemoval() throws FloodlightModuleException {
315
316 // create shortest path intents
317 final IntentOperationList opList = new IntentOperationList();
318 opList.add(Operator.ADD,
319 new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L,
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("2", 1L, 14L, LOCAL_PORT, 4L, 41L,
Ray Milkey269ffb92014-04-03 14:43:30 -0700323 LOCAL_PORT));
Ray Milkeydc659c42014-03-28 16:30:42 -0700324 opList.add(Operator.ADD,
325 new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L,
Ray Milkey269ffb92014-04-03 14:43:30 -0700326 LOCAL_PORT));
Ray Milkeydc659c42014-03-28 16:30:42 -0700327
328 // compile high-level intent operations into low-level intent
329 // operations (calculate paths)
330 final PathCalcRuntimeModule runtime = new PathCalcRuntimeModule();
331 runtime.init(modContext);
332 runtime.startUp(modContext);
333 final IntentOperationList pathIntentOpList =
334 runtime.executeIntentOperations(opList);
335 assertThat(pathIntentOpList, notNullValue());
336
337 final IntentMap highLevelIntents = runtime.getHighLevelIntents();
338 assertThat(highLevelIntents, notNullValue());
339
340 final Collection<Intent> allIntents = highLevelIntents.getAllIntents();
341 assertThat(allIntents, notNullValue());
342
343 // Should be one operation per path
344 assertThat(pathIntentOpList, hasSize(opList.size()));
345
346 // Should be a high level intent for each operation
347 assertThat(allIntents, hasSize(opList.size()));
348
349 // Check that we got a high level intent for each operation
350 assertThat(allIntents, hasIntentWithId("3"));
351 assertThat(allIntents, hasIntentWithId("2"));
352 assertThat(allIntents, hasIntentWithId("1"));
353
354 // Check that switch 1 was correctly processed
355 assertThat(highLevelIntents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700356 hasIntentWithIdAndState("1", IntentState.INST_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700357
358 // Check that switch 2 was correctly processed
359 assertThat(highLevelIntents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700360 hasIntentWithIdAndState("2", IntentState.INST_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700361
362 // Check that switch 3 was correctly processed
363 assertThat(highLevelIntents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700364 hasIntentWithIdAndState("3", IntentState.INST_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700365
366 // Now delete one path and check the results
367 final IntentOperationList opListForRemoval = new IntentOperationList();
368 opListForRemoval.add(Operator.REMOVE,
369 new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L,
370 LOCAL_PORT));
371
372 final IntentOperationList pathIntentOpListAfterRemoval =
373 runtime.executeIntentOperations(opListForRemoval);
374 assertThat(pathIntentOpListAfterRemoval, notNullValue());
375 assertThat(pathIntentOpListAfterRemoval, hasSize(1));
376
377 // Check the high level intents.
378 final IntentMap highLevelIntentsAfterRemoval = runtime.getHighLevelIntents();
379 assertThat(highLevelIntentsAfterRemoval, notNullValue());
380
381 final Collection<Intent> allIntentsAfterRemoval = highLevelIntentsAfterRemoval.getAllIntents();
382 assertThat(allIntentsAfterRemoval, notNullValue());
383 assertThat(allIntentsAfterRemoval, hasSize(3));
384
385 // Check that we got a high level intent for each operation
386 assertThat(allIntentsAfterRemoval, hasIntentWithId("3"));
387 assertThat(allIntentsAfterRemoval, hasIntentWithId("2"));
388 assertThat(allIntentsAfterRemoval, hasIntentWithId("1"));
389
390 // Check the states of the high level intents
391 // Check that switch 1 was correctly processed
392 assertThat(highLevelIntents,
393 hasIntentWithIdAndState("1", IntentState.DEL_REQ));
394
395 // Check that switch 2 was correctly processed
396 assertThat(highLevelIntents,
397 hasIntentWithIdAndState("2", IntentState.INST_REQ));
398
399 // Check that switch 3 was correctly processed
400 assertThat(highLevelIntents,
401 hasIntentWithIdAndState("3", IntentState.INST_REQ));
402 }
403
404 /**
405 * Test the result of executing a path calculation on an
406 * Intent Operation List and then forcing a reroute.
Ray Milkey269ffb92014-04-03 14:43:30 -0700407 * <p/>
Ray Milkeydc659c42014-03-28 16:30:42 -0700408 * A 3 path list is created and then one of the links is removed.
409 * The test checks that the resulting Operation List is correct,
410 * and that the high level intents contain a proper "reroute requested"
411 * entry for the deleted link.
412 */
413 @Test
414 public void testIntentReroute() throws FloodlightModuleException {
415
416 // create shortest path intents
417 final IntentOperationList opList = new IntentOperationList();
418 final ShortestPathIntent pathIntent1 =
419 new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L,
Ray Milkey269ffb92014-04-03 14:43:30 -0700420 LOCAL_PORT);
Ray Milkeydc659c42014-03-28 16:30:42 -0700421
422 opList.add(Operator.ADD, pathIntent1);
423 opList.add(Operator.ADD,
424 new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L,
Ray Milkey269ffb92014-04-03 14:43:30 -0700425 LOCAL_PORT));
Ray Milkeydc659c42014-03-28 16:30:42 -0700426 opList.add(Operator.ADD,
427 new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L,
Ray Milkey269ffb92014-04-03 14:43:30 -0700428 LOCAL_PORT));
Ray Milkeydc659c42014-03-28 16:30:42 -0700429
430 // compile high-level intent operations into low-level intent
431 // operations (calculate paths)
432 final PathCalcRuntimeModule runtime = new PathCalcRuntimeModule();
433 runtime.init(modContext);
434 runtime.startUp(modContext);
435 final IntentOperationList pathIntentOpList =
436 runtime.executeIntentOperations(opList);
437 assertThat(pathIntentOpList, notNullValue());
438
439 final IntentMap highLevelIntents = runtime.getHighLevelIntents();
440 assertThat(highLevelIntents, notNullValue());
441
442 final Collection<Intent> allIntents = highLevelIntents.getAllIntents();
443 assertThat(allIntents, notNullValue());
444
445 // Should be one operation per path
446 assertThat(pathIntentOpList, hasSize(opList.size()));
447
448 // Should be a high level intent for each operation
449 assertThat(allIntents, hasSize(opList.size()));
450
451 // Check that we got a high level intent for each operation
452 assertThat(allIntents, hasIntentWithId("3"));
453 assertThat(allIntents, hasIntentWithId("2"));
454 assertThat(allIntents, hasIntentWithId("1"));
455
456 // Check that switch 1 was correctly processed
457 assertThat(highLevelIntents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700458 hasIntentWithIdAndState("1", IntentState.INST_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700459
460 // Check that switch 2 was correctly processed
461 assertThat(highLevelIntents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700462 hasIntentWithIdAndState("2", IntentState.INST_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700463
464 // Check that switch 3 was correctly processed
465 assertThat(highLevelIntents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700466 hasIntentWithIdAndState("3", IntentState.INST_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700467
468 // Now add a different path to one of the switches path and check
469 // the results
470 IntentStateList states = new IntentStateList();
471 states.put("1", IntentState.INST_ACK);
472 states.put("2", IntentState.INST_ACK);
473 states.put("3", IntentState.INST_ACK);
474 runtime.getHighLevelIntents().changeStates(states);
475 states.clear();
476 states.put("1___0", IntentState.INST_ACK);
477 states.put("2___0", IntentState.INST_ACK);
478 states.put("3___0", IntentState.INST_ACK);
479 runtime.getPathIntents().changeStates(states);
480
481 final List<SwitchEvent> emptySwitchEvents = new LinkedList<>();
482 final List<PortEvent> emptyPortEvents = new LinkedList<>();
483 final List<DeviceEvent> emptyDeviceEvents = new LinkedList<>();
484 final List<LinkEvent> addedLinkEvents = new LinkedList<>();
485 final List<LinkEvent> removedLinkEvents = new LinkedList<>();
486
487 graph.removeLink(1L, 12L, 2L, 21L); // This link is used by the intent "1"
488 graph.removeLink(2L, 21L, 1L, 12L);
489 LinkEvent linkEvent1 = new LinkEvent(1L, 12L, 2L, 21L);
490 LinkEvent linkEvent2 = new LinkEvent(2L, 21L, 1L, 12L);
491 removedLinkEvents.add(linkEvent1);
492 removedLinkEvents.add(linkEvent2);
493 runtime.networkGraphEvents(
494 emptySwitchEvents,
495 emptySwitchEvents,
496 emptyPortEvents,
497 emptyPortEvents,
498 addedLinkEvents,
499 removedLinkEvents,
500 emptyDeviceEvents,
501 emptyDeviceEvents);
502 final IntentOperationList opListForReroute = new IntentOperationList();
503 opListForReroute.add(Operator.ADD, pathIntent1);
504
505 final IntentOperationList pathIntentOpListAfterReroute =
506 runtime.executeIntentOperations(opListForReroute);
507 assertThat(pathIntentOpListAfterReroute, notNullValue());
508 assertThat(pathIntentOpListAfterReroute, hasSize(2));
509
510 // Check the high level intents.
511 final IntentMap highLevelIntentsAfterReroute = runtime.getHighLevelIntents();
512 assertThat(highLevelIntentsAfterReroute, notNullValue());
513
514 final Collection<Intent> allIntentsAfterReroute = highLevelIntentsAfterReroute.getAllIntents();
515 assertThat(allIntentsAfterReroute, notNullValue());
516 assertThat(allIntentsAfterReroute, hasSize(3));
517
518 // Check that we got a high level intent for each operation
519 assertThat(allIntentsAfterReroute, hasIntentWithId("3"));
520 assertThat(allIntentsAfterReroute, hasIntentWithId("2"));
521 assertThat(allIntentsAfterReroute, hasIntentWithId("1"));
522
523 // Check the states of the high level intents
524 // Check that switch 1 was correctly processed
525 assertThat(highLevelIntents,
526 hasIntentWithIdAndState("1", IntentState.REROUTE_REQ));
527
528 // Check that switch 2 was correctly processed
529 assertThat(highLevelIntents,
530 hasIntentWithIdAndState("2", IntentState.INST_ACK));
531
532 // Check that switch 3 was correctly processed
533 assertThat(highLevelIntents,
534 hasIntentWithIdAndState("3", IntentState.INST_ACK));
535
Ray Milkey6688cd82014-03-11 16:40:46 -0700536
537 }
538
539
540}