blob: c20291091a56e1b692476953c7b733f19ea2053c [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.hamcrest.MatcherAssert.assertThat;
4import static org.hamcrest.Matchers.equalTo;
5import static org.hamcrest.Matchers.hasItem;
6import static org.hamcrest.Matchers.hasSize;
7import static org.hamcrest.Matchers.notNullValue;
8
9import java.util.Collection;
10import java.util.LinkedList;
11import java.util.List;
12
Ray Milkey6688cd82014-03-11 16:40:46 -070013import net.floodlightcontroller.core.module.FloodlightModuleContext;
14import net.floodlightcontroller.core.module.FloodlightModuleException;
Jonathan Hartaa380972014-04-03 10:24:46 -070015import net.onrc.onos.core.intent.Intent;
Jonathan Harta88fd242014-04-03 11:24:54 -070016import net.onrc.onos.core.intent.Intent.IntentState;
Jonathan Hartaa380972014-04-03 10:24:46 -070017import net.onrc.onos.core.intent.IntentMap;
Jonathan Harta88fd242014-04-03 11:24:54 -070018import net.onrc.onos.core.intent.IntentOperation.Operator;
Jonathan Hartaa380972014-04-03 10:24:46 -070019import net.onrc.onos.core.intent.IntentOperationList;
Jonathan Harte37e4e22014-05-13 19:12:02 -070020import net.onrc.onos.core.intent.MockTopology;
Jonathan Hartaa380972014-04-03 10:24:46 -070021import net.onrc.onos.core.intent.ShortestPathIntent;
Jonathan Hart472062d2014-04-03 10:56:48 -070022import net.onrc.onos.core.topology.DeviceEvent;
Jonathan Hart472062d2014-04-03 10:56:48 -070023import net.onrc.onos.core.topology.LinkEvent;
24import net.onrc.onos.core.topology.PortEvent;
25import net.onrc.onos.core.topology.SwitchEvent;
Ray Milkey6688cd82014-03-11 16:40:46 -070026
Jonathan Harta88fd242014-04-03 11:24:54 -070027import org.hamcrest.Description;
28import org.hamcrest.Factory;
29import org.hamcrest.Matcher;
30import org.hamcrest.Matchers;
31import org.hamcrest.TypeSafeMatcher;
Ray Milkey6688cd82014-03-11 16:40:46 -070032import org.junit.After;
33import org.junit.Before;
34import org.junit.Test;
35import org.junit.runner.RunWith;
Ray Milkey6688cd82014-03-11 16:40:46 -070036import org.powermock.core.classloader.annotations.PrepareForTest;
37import org.powermock.modules.junit4.PowerMockRunner;
38
Ray Milkey6688cd82014-03-11 16:40:46 -070039/**
40 * @author Ray Milkey (ray@onlab.us)
Ray Milkey269ffb92014-04-03 14:43:30 -070041 * <p/>
42 * Unit tests for the Path Calculation Runtime module (PathCalcRuntimeModule).
43 * These test cases check the results of creating paths, deleting paths, and
Jonathan Harte37e4e22014-05-13 19:12:02 -070044 * rerouting paths. The topology, controller registry, and data grid are
Ray Milkey269ffb92014-04-03 14:43:30 -070045 * mocked out. The individual tests check the high level intents and the
46 * resulting operation lists to be sure they match the intended APIs.
Ray Milkey6688cd82014-03-11 16:40:46 -070047 */
48@RunWith(PowerMockRunner.class)
49@PrepareForTest(PathCalcRuntimeModule.class)
50public class PathCalcRuntimeModuleTest {
Ray Milkeydc659c42014-03-28 16:30:42 -070051 private static final Long LOCAL_PORT = 0xFFFEL;
52
Ray Milkey9d671002014-05-29 17:24:29 -070053 private IntentTestMocks mocks;
54 private PathCalcRuntimeModule runtime;
Ray Milkey6688cd82014-03-11 16:40:46 -070055
Ray Milkey6688cd82014-03-11 16:40:46 -070056 @Before
57 public void setUp() throws Exception {
Ray Milkey9d671002014-05-29 17:24:29 -070058 mocks = new IntentTestMocks();
59 mocks.setUpIntentMocks();
Ray Milkey6688cd82014-03-11 16:40:46 -070060
Ray Milkey9d671002014-05-29 17:24:29 -070061 runtime = new PathCalcRuntimeModule();
62 final FloodlightModuleContext moduleContext = mocks.getModuleContext();
63 runtime.init(moduleContext);
64 runtime.startUp(moduleContext);
Ray Milkey6688cd82014-03-11 16:40:46 -070065 }
66
Ray Milkeydc659c42014-03-28 16:30:42 -070067
68 /**
69 * Hamcrest matcher to check that a collection of Intents contains an
70 * Intent with the specified Intent Id.
71 */
72 public static class EntryForIntentMatcher extends TypeSafeMatcher<Collection<Intent>> {
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070073 private final String id;
Ray Milkeydc659c42014-03-28 16:30:42 -070074
75 public EntryForIntentMatcher(String idValue) {
76 id = idValue;
77 }
78
79 @Override
80 public boolean matchesSafely(Collection<Intent> intents) {
81 assertThat(intents,
Ray Milkey269ffb92014-04-03 14:43:30 -070082 hasItem(Matchers.<Intent>hasProperty("id", equalTo(id))));
Ray Milkeydc659c42014-03-28 16:30:42 -070083 return true;
84 }
85
86 @Override
87 public void describeTo(Description description) {
88 description.appendText("an intent with id \" ").
89 appendText(id).
90 appendText("\"");
91 }
92 }
93
94
95 /**
96 * Factory method to create an Intent entry Matcher. Returns a matcher
97 * for the Intent with the given id.
Ray Milkey269ffb92014-04-03 14:43:30 -070098 *
Ray Milkeydc659c42014-03-28 16:30:42 -070099 * @param id id of the intent to match
100 * @return Matcher object
101 */
102 @Factory
103 public static Matcher<Collection<Intent>> hasIntentWithId(String id) {
104 return new EntryForIntentMatcher(id);
105 }
106
107
108 /**
109 * Matcher to determine if an IntentMap contains an entry with a given id,
110 * and that entry has a given state.
111 */
112 public static class IntentsHaveIntentWithStateMatcher extends TypeSafeMatcher<IntentMap> {
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700113 private final String id;
114 private final IntentState state;
Ray Milkeydc659c42014-03-28 16:30:42 -0700115 private Intent intent;
116
117 public IntentsHaveIntentWithStateMatcher(String idValue,
118 IntentState stateValue) {
119 id = idValue;
120 state = stateValue;
121 }
122
123 @Override
124 public boolean matchesSafely(IntentMap intents) {
125 intent = intents.getIntent(id);
126
127 return intent != null && intent.getState() == state;
128 }
129
130 @Override
131 public void describeTo(Description description) {
132 if (intent == null) {
133 description.appendText("intent lookup for id \"");
134 description.appendText(id);
135 description.appendText("\"");
136 } else {
137 description.appendText("state ");
138 description.appendText(state.toString());
139 }
140 }
141
142 @Override
143 public void describeMismatchSafely(IntentMap intents,
144 Description mismatchDescription) {
145 if (intent != null) {
146 mismatchDescription.appendText("was ").
Ray Milkey269ffb92014-04-03 14:43:30 -0700147 appendText(intent.getState().toString());
Ray Milkeydc659c42014-03-28 16:30:42 -0700148 } else {
149 mismatchDescription.appendText("that intent was not found");
150 }
151 }
152 }
153
154
155 /**
156 * Factory method to create a Matcher for an IntentMap that looks for an
157 * Intent with a given id and state.
158 *
Ray Milkey269ffb92014-04-03 14:43:30 -0700159 * @param id id of the Intent to match
Ray Milkeydc659c42014-03-28 16:30:42 -0700160 * @param state if the Intent is found, its state must match this
161 * @return Matcher object
162 */
163 @Factory
164 public static Matcher<IntentMap> hasIntentWithIdAndState(String id,
165 IntentState state) {
166 return new IntentsHaveIntentWithStateMatcher(id, state);
167 }
168
169
Ray Milkey6688cd82014-03-11 16:40:46 -0700170 @After
171 public void tearDown() {
Ray Milkey9d671002014-05-29 17:24:29 -0700172 mocks.tearDownIntentMocks();
Ray Milkey6688cd82014-03-11 16:40:46 -0700173 }
174
175 /**
176 * Test the result of executing a path calculation on an
177 * Intent Operation List which contains a path that references a
178 * non-existent switch.
Ray Milkey269ffb92014-04-03 14:43:30 -0700179 * <p/>
Ray Milkey6688cd82014-03-11 16:40:46 -0700180 * A 3 path list is created where one of the paths references a switch
181 * that is not in the topology. The test checks that the resulting
182 * Operation List has entries for the 2 correct paths, and that the
183 * high level intents contain a proper error entry for the bad path.
184 */
185 @Test
186 public void testInvalidSwitchName() throws FloodlightModuleException {
Ray Milkey6688cd82014-03-11 16:40:46 -0700187 final String BAD_SWITCH_INTENT_NAME = "No Such Switch Intent";
188
189 // create shortest path intents
190 final IntentOperationList opList = new IntentOperationList();
191 opList.add(Operator.ADD,
192 new ShortestPathIntent(BAD_SWITCH_INTENT_NAME, 111L, 12L,
193 LOCAL_PORT, 2L, 21L, LOCAL_PORT));
194 opList.add(Operator.ADD,
195 new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L,
196 LOCAL_PORT));
197 opList.add(Operator.ADD,
198 new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L,
199 LOCAL_PORT));
200
201 // compile high-level intent operations into low-level intent
202 // operations (calculate paths)
Ray Milkey6688cd82014-03-11 16:40:46 -0700203 final IntentOperationList pathIntentOpList =
204 runtime.executeIntentOperations(opList);
205 assertThat(pathIntentOpList, notNullValue());
206
207 final IntentMap highLevelIntents = runtime.getHighLevelIntents();
208 assertThat(highLevelIntents, notNullValue());
209
210 final Collection<Intent> allIntents = highLevelIntents.getAllIntents();
211 assertThat(allIntents, notNullValue());
212
213 // One intent had an error and should not create a path list entry
214 assertThat(pathIntentOpList, hasSize(opList.size() - 1));
215
216 // Should be a high level intent for each operation
Ray Milkeydc659c42014-03-28 16:30:42 -0700217 assertThat(allIntents, hasSize(opList.size()));
Ray Milkey6688cd82014-03-11 16:40:46 -0700218
219 // Check that we got a high level intent for each operation
Ray Milkeydc659c42014-03-28 16:30:42 -0700220 assertThat(allIntents, hasIntentWithId("3"));
221 assertThat(allIntents, hasIntentWithId("2"));
222 assertThat(allIntents, hasIntentWithId(BAD_SWITCH_INTENT_NAME));
Ray Milkey6688cd82014-03-11 16:40:46 -0700223
224 // Check that the non existent switch was NACKed
Ray Milkeydc659c42014-03-28 16:30:42 -0700225 assertThat(highLevelIntents, hasIntentWithIdAndState(BAD_SWITCH_INTENT_NAME, IntentState.INST_NACK));
Ray Milkey6688cd82014-03-11 16:40:46 -0700226
227 // Check that switch 2 was correctly processed
Ray Milkeydc659c42014-03-28 16:30:42 -0700228 assertThat(highLevelIntents, hasIntentWithIdAndState("2", IntentState.INST_REQ));
Ray Milkey6688cd82014-03-11 16:40:46 -0700229
230 // Check that switch 3 was correctly processed
Ray Milkeydc659c42014-03-28 16:30:42 -0700231 assertThat(highLevelIntents, hasIntentWithIdAndState("3", IntentState.INST_REQ));
232
233 }
234
235
236 /**
237 * Test the result of executing a path calculation on an
238 * Intent Operation List and then removing one of the switches.
Ray Milkey269ffb92014-04-03 14:43:30 -0700239 * <p/>
Ray Milkeydc659c42014-03-28 16:30:42 -0700240 * A 3 path list is created and then one of the paths is removed.
241 * The test checks that the resulting Operation List is correct,
242 * and that the high level intents contain a proper "delete requested"
243 * entry for the deleted path.
244 */
245 @Test
246 public void testIntentRemoval() throws FloodlightModuleException {
247
248 // create shortest path intents
249 final IntentOperationList opList = new IntentOperationList();
250 opList.add(Operator.ADD,
251 new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L,
Ray Milkey269ffb92014-04-03 14:43:30 -0700252 LOCAL_PORT));
Ray Milkeydc659c42014-03-28 16:30:42 -0700253 opList.add(Operator.ADD,
254 new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L,
Ray Milkey269ffb92014-04-03 14:43:30 -0700255 LOCAL_PORT));
Ray Milkeydc659c42014-03-28 16:30:42 -0700256 opList.add(Operator.ADD,
257 new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L,
Ray Milkey269ffb92014-04-03 14:43:30 -0700258 LOCAL_PORT));
Ray Milkeydc659c42014-03-28 16:30:42 -0700259
260 // compile high-level intent operations into low-level intent
261 // operations (calculate paths)
Ray Milkeydc659c42014-03-28 16:30:42 -0700262 final IntentOperationList pathIntentOpList =
263 runtime.executeIntentOperations(opList);
264 assertThat(pathIntentOpList, notNullValue());
265
266 final IntentMap highLevelIntents = runtime.getHighLevelIntents();
267 assertThat(highLevelIntents, notNullValue());
268
269 final Collection<Intent> allIntents = highLevelIntents.getAllIntents();
270 assertThat(allIntents, notNullValue());
271
272 // Should be one operation per path
273 assertThat(pathIntentOpList, hasSize(opList.size()));
274
275 // Should be a high level intent for each operation
276 assertThat(allIntents, hasSize(opList.size()));
277
278 // Check that we got a high level intent for each operation
279 assertThat(allIntents, hasIntentWithId("3"));
280 assertThat(allIntents, hasIntentWithId("2"));
281 assertThat(allIntents, hasIntentWithId("1"));
282
283 // Check that switch 1 was correctly processed
284 assertThat(highLevelIntents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700285 hasIntentWithIdAndState("1", IntentState.INST_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700286
287 // Check that switch 2 was correctly processed
288 assertThat(highLevelIntents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700289 hasIntentWithIdAndState("2", IntentState.INST_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700290
291 // Check that switch 3 was correctly processed
292 assertThat(highLevelIntents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700293 hasIntentWithIdAndState("3", IntentState.INST_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700294
295 // Now delete one path and check the results
296 final IntentOperationList opListForRemoval = new IntentOperationList();
297 opListForRemoval.add(Operator.REMOVE,
298 new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L,
299 LOCAL_PORT));
300
301 final IntentOperationList pathIntentOpListAfterRemoval =
302 runtime.executeIntentOperations(opListForRemoval);
303 assertThat(pathIntentOpListAfterRemoval, notNullValue());
304 assertThat(pathIntentOpListAfterRemoval, hasSize(1));
305
306 // Check the high level intents.
307 final IntentMap highLevelIntentsAfterRemoval = runtime.getHighLevelIntents();
308 assertThat(highLevelIntentsAfterRemoval, notNullValue());
309
310 final Collection<Intent> allIntentsAfterRemoval = highLevelIntentsAfterRemoval.getAllIntents();
311 assertThat(allIntentsAfterRemoval, notNullValue());
312 assertThat(allIntentsAfterRemoval, hasSize(3));
313
314 // Check that we got a high level intent for each operation
315 assertThat(allIntentsAfterRemoval, hasIntentWithId("3"));
316 assertThat(allIntentsAfterRemoval, hasIntentWithId("2"));
317 assertThat(allIntentsAfterRemoval, hasIntentWithId("1"));
318
319 // Check the states of the high level intents
320 // Check that switch 1 was correctly processed
321 assertThat(highLevelIntents,
322 hasIntentWithIdAndState("1", IntentState.DEL_REQ));
323
324 // Check that switch 2 was correctly processed
325 assertThat(highLevelIntents,
326 hasIntentWithIdAndState("2", IntentState.INST_REQ));
327
328 // Check that switch 3 was correctly processed
329 assertThat(highLevelIntents,
330 hasIntentWithIdAndState("3", IntentState.INST_REQ));
331 }
332
333 /**
334 * Test the result of executing a path calculation on an
335 * Intent Operation List and then forcing a reroute.
Ray Milkey269ffb92014-04-03 14:43:30 -0700336 * <p/>
Ray Milkeydc659c42014-03-28 16:30:42 -0700337 * A 3 path list is created and then one of the links is removed.
338 * The test checks that the resulting Operation List is correct,
339 * and that the high level intents contain a proper "reroute requested"
340 * entry for the deleted link.
341 */
342 @Test
343 public void testIntentReroute() throws FloodlightModuleException {
344
345 // create shortest path intents
346 final IntentOperationList opList = new IntentOperationList();
347 final ShortestPathIntent pathIntent1 =
348 new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L,
Ray Milkey269ffb92014-04-03 14:43:30 -0700349 LOCAL_PORT);
Ray Milkeydc659c42014-03-28 16:30:42 -0700350
351 opList.add(Operator.ADD, pathIntent1);
352 opList.add(Operator.ADD,
353 new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L,
Ray Milkey269ffb92014-04-03 14:43:30 -0700354 LOCAL_PORT));
Ray Milkeydc659c42014-03-28 16:30:42 -0700355 opList.add(Operator.ADD,
356 new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L,
Ray Milkey269ffb92014-04-03 14:43:30 -0700357 LOCAL_PORT));
Ray Milkeydc659c42014-03-28 16:30:42 -0700358
359 // compile high-level intent operations into low-level intent
360 // operations (calculate paths)
Ray Milkeydc659c42014-03-28 16:30:42 -0700361 final IntentOperationList pathIntentOpList =
362 runtime.executeIntentOperations(opList);
363 assertThat(pathIntentOpList, notNullValue());
364
365 final IntentMap highLevelIntents = runtime.getHighLevelIntents();
366 assertThat(highLevelIntents, notNullValue());
367
368 final Collection<Intent> allIntents = highLevelIntents.getAllIntents();
369 assertThat(allIntents, notNullValue());
370
371 // Should be one operation per path
372 assertThat(pathIntentOpList, hasSize(opList.size()));
373
374 // Should be a high level intent for each operation
375 assertThat(allIntents, hasSize(opList.size()));
376
377 // Check that we got a high level intent for each operation
378 assertThat(allIntents, hasIntentWithId("3"));
379 assertThat(allIntents, hasIntentWithId("2"));
380 assertThat(allIntents, hasIntentWithId("1"));
381
Toshio Koidec2112c22014-06-05 19:59:15 -0700382 // Check that the high level intent 1 was correctly processed
Ray Milkeydc659c42014-03-28 16:30:42 -0700383 assertThat(highLevelIntents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700384 hasIntentWithIdAndState("1", IntentState.INST_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700385
Toshio Koidec2112c22014-06-05 19:59:15 -0700386 // Check that the high level intent 2 was correctly processed
Ray Milkeydc659c42014-03-28 16:30:42 -0700387 assertThat(highLevelIntents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700388 hasIntentWithIdAndState("2", IntentState.INST_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700389
Toshio Koidec2112c22014-06-05 19:59:15 -0700390 // Check that the high level intent 3 was correctly processed
Ray Milkeydc659c42014-03-28 16:30:42 -0700391 assertThat(highLevelIntents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700392 hasIntentWithIdAndState("3", IntentState.INST_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700393
Toshio Koidec2112c22014-06-05 19:59:15 -0700394 final IntentMap pathIntents = runtime.getPathIntents();
395 assertThat(pathIntents, notNullValue());
Ray Milkeydc659c42014-03-28 16:30:42 -0700396
Toshio Koidec2112c22014-06-05 19:59:15 -0700397 final Collection<Intent> allPathIntents = pathIntents.getAllIntents();
398 assertThat(allPathIntents, notNullValue());
399
400 // Check that we got a low level intent for each operation
401 assertThat(allPathIntents, hasIntentWithId("3___0"));
402 assertThat(allPathIntents, hasIntentWithId("2___0"));
403 assertThat(allPathIntents, hasIntentWithId("1___0"));
404
405 // Check that the low level intent 1 was correctly processed
406 assertThat(pathIntents,
407 hasIntentWithIdAndState("1___0", IntentState.INST_REQ));
408
409 // Check that the low level intent 2 was correctly processed
410 assertThat(pathIntents,
411 hasIntentWithIdAndState("2___0", IntentState.INST_REQ));
412
413 // Check that the low level intent 3 was correctly processed
414 assertThat(pathIntents,
415 hasIntentWithIdAndState("3___0", IntentState.INST_REQ));
416
417 // Receive notification from south-bound
418 IntentStateList isl = new IntentStateList();
419 isl.put("1___0", IntentState.INST_ACK);
420 isl.put("2___0", IntentState.INST_ACK);
421 isl.put("3___0", IntentState.INST_ACK);
422 isl.domainSwitchDpids.add(1L);
423 isl.domainSwitchDpids.add(2L);
424 isl.domainSwitchDpids.add(3L);
425 isl.domainSwitchDpids.add(4L);
426 runtime.entryUpdated(isl);
427
428 // Now check the results
429 final IntentMap processedHighLevelIntents = runtime.getHighLevelIntents();
430 assertThat(processedHighLevelIntents, notNullValue());
431
432 // Check that the high level intent 1 was correctly processed
433 assertThat(processedHighLevelIntents,
434 hasIntentWithIdAndState("1", IntentState.INST_ACK));
435
436 // Check that the high level intent 2 was correctly processed
437 assertThat(processedHighLevelIntents,
438 hasIntentWithIdAndState("2", IntentState.INST_ACK));
439
440 // Check that the high level intent 3 was correctly processed
441 assertThat(processedHighLevelIntents,
442 hasIntentWithIdAndState("3", IntentState.INST_ACK));
443
444 final IntentMap processedPathIntents = runtime.getPathIntents();
445 assertThat(processedPathIntents, notNullValue());
446
447 // Check that the low level intent 1 was correctly processed
448 assertThat(processedPathIntents,
449 hasIntentWithIdAndState("1___0", IntentState.INST_ACK));
450
451 // Check that the low level intent 2 was correctly processed
452 assertThat(processedPathIntents,
453 hasIntentWithIdAndState("2___0", IntentState.INST_ACK));
454
455 // Check that the low level intent 3 was correctly processed
456 assertThat(processedPathIntents,
457 hasIntentWithIdAndState("3___0", IntentState.INST_ACK));
458
459
460 // Remove one of the links and check results
Ray Milkeydc659c42014-03-28 16:30:42 -0700461 final List<SwitchEvent> emptySwitchEvents = new LinkedList<>();
462 final List<PortEvent> emptyPortEvents = new LinkedList<>();
463 final List<DeviceEvent> emptyDeviceEvents = new LinkedList<>();
464 final List<LinkEvent> addedLinkEvents = new LinkedList<>();
465 final List<LinkEvent> removedLinkEvents = new LinkedList<>();
466
Ray Milkey9d671002014-05-29 17:24:29 -0700467 final MockTopology topology = mocks.getTopology();
Jonathan Harte37e4e22014-05-13 19:12:02 -0700468 topology.removeLink(1L, 12L, 2L, 21L); // This link is used by the intent "1"
469 topology.removeLink(2L, 21L, 1L, 12L);
Ray Milkeydc659c42014-03-28 16:30:42 -0700470 LinkEvent linkEvent1 = new LinkEvent(1L, 12L, 2L, 21L);
471 LinkEvent linkEvent2 = new LinkEvent(2L, 21L, 1L, 12L);
472 removedLinkEvents.add(linkEvent1);
473 removedLinkEvents.add(linkEvent2);
Jonathan Harte37e4e22014-05-13 19:12:02 -0700474 runtime.topologyEvents(
Ray Milkeydc659c42014-03-28 16:30:42 -0700475 emptySwitchEvents,
476 emptySwitchEvents,
477 emptyPortEvents,
478 emptyPortEvents,
479 addedLinkEvents,
480 removedLinkEvents,
481 emptyDeviceEvents,
482 emptyDeviceEvents);
Ray Milkeydc659c42014-03-28 16:30:42 -0700483
484 // Check the high level intents.
485 final IntentMap highLevelIntentsAfterReroute = runtime.getHighLevelIntents();
486 assertThat(highLevelIntentsAfterReroute, notNullValue());
487
Ray Milkeydc659c42014-03-28 16:30:42 -0700488 // Check the states of the high level intents
Toshio Koidec2112c22014-06-05 19:59:15 -0700489 // Check that the high level intent 1 was correctly processed
490 assertThat(highLevelIntentsAfterReroute,
491 hasIntentWithIdAndState("1", IntentState.REROUTE_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700492
Toshio Koidec2112c22014-06-05 19:59:15 -0700493 // Check that the high level intent 2 was not affected
494 assertThat(highLevelIntentsAfterReroute,
Ray Milkeydc659c42014-03-28 16:30:42 -0700495 hasIntentWithIdAndState("2", IntentState.INST_ACK));
496
Toshio Koidec2112c22014-06-05 19:59:15 -0700497 // Check that the high level intent 3 was not affected
498 assertThat(highLevelIntentsAfterReroute,
Ray Milkeydc659c42014-03-28 16:30:42 -0700499 hasIntentWithIdAndState("3", IntentState.INST_ACK));
500
Toshio Koidec2112c22014-06-05 19:59:15 -0700501 final IntentMap pathIntentsAfterReroute = runtime.getPathIntents();
502 assertThat(pathIntentsAfterReroute, notNullValue());
Ray Milkey6688cd82014-03-11 16:40:46 -0700503
Toshio Koidec2112c22014-06-05 19:59:15 -0700504 // Check that the low level intent 1 was correctly processed
505 assertThat(pathIntentsAfterReroute,
506 hasIntentWithIdAndState("1___0", IntentState.DEL_REQ));
507 assertThat(pathIntentsAfterReroute,
508 hasIntentWithIdAndState("1___1", IntentState.INST_REQ));
509
510 // Check that the low level intent 2 was not affected
511 assertThat(pathIntentsAfterReroute,
512 hasIntentWithIdAndState("2___0", IntentState.INST_ACK));
513
514 // Check that the low level intent 3 was not affected
515 assertThat(pathIntentsAfterReroute,
516 hasIntentWithIdAndState("3___0", IntentState.INST_ACK));
517
518 // Receive notification from south-bound
519 isl = new IntentStateList();
520 isl.put("1___0", IntentState.DEL_ACK);
521 isl.put("1___1", IntentState.INST_ACK);
522 isl.domainSwitchDpids.add(1L);
523 isl.domainSwitchDpids.add(2L);
524 isl.domainSwitchDpids.add(4L);
525 runtime.entryUpdated(isl);
526
527 // Now check the results
528 final IntentMap reroutedHighLevelIntents = runtime.getHighLevelIntents();
529 assertThat(reroutedHighLevelIntents, notNullValue());
530
531 // Check that the high level intent 1 was correctly processed
532 assertThat(reroutedHighLevelIntents,
533 hasIntentWithIdAndState("1", IntentState.INST_ACK));
534
535 // Check that the high level intent 2 was not affected
536 assertThat(reroutedHighLevelIntents,
537 hasIntentWithIdAndState("2", IntentState.INST_ACK));
538
539 // Check that the high level intent 3 was not affected
540 assertThat(reroutedHighLevelIntents,
541 hasIntentWithIdAndState("3", IntentState.INST_ACK));
542
543 final IntentMap reroutedPathIntents = runtime.getPathIntents();
544 assertThat(processedPathIntents, notNullValue());
545
546 // Check that the low level intent 1 was correctly processed
547 assertThat(reroutedPathIntents,
548 hasIntentWithIdAndState("1___0", IntentState.DEL_ACK));
549 assertThat(reroutedPathIntents,
550 hasIntentWithIdAndState("1___1", IntentState.INST_ACK));
551
552 // Check that the low level intent 2 was not affected
553 assertThat(reroutedPathIntents,
554 hasIntentWithIdAndState("2___0", IntentState.INST_ACK));
555
556 // Check that the low level intent 3 was not affected
557 assertThat(reroutedPathIntents,
558 hasIntentWithIdAndState("3___0", IntentState.INST_ACK));
Ray Milkey6688cd82014-03-11 16:40:46 -0700559 }
Ray Milkey6688cd82014-03-11 16:40:46 -0700560}