blob: e9286ad3a799e75bc3c486bc73ccb834edfb036f [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;
Pavlin Radoslavove2238bc2014-06-09 18:05:23 -07007import static org.hamcrest.Matchers.not;
Jonathan Harta88fd242014-04-03 11:24:54 -07008import static org.hamcrest.Matchers.notNullValue;
9
10import java.util.Collection;
11import java.util.LinkedList;
12import java.util.List;
13
Ray Milkey6688cd82014-03-11 16:40:46 -070014import net.floodlightcontroller.core.module.FloodlightModuleContext;
15import net.floodlightcontroller.core.module.FloodlightModuleException;
Jonathan Hartaa380972014-04-03 10:24:46 -070016import net.onrc.onos.core.intent.Intent;
Jonathan Harta88fd242014-04-03 11:24:54 -070017import net.onrc.onos.core.intent.Intent.IntentState;
Jonathan Hartaa380972014-04-03 10:24:46 -070018import net.onrc.onos.core.intent.IntentMap;
Jonathan Harta88fd242014-04-03 11:24:54 -070019import net.onrc.onos.core.intent.IntentOperation.Operator;
Jonathan Hartaa380972014-04-03 10:24:46 -070020import net.onrc.onos.core.intent.IntentOperationList;
Jonathan Harte37e4e22014-05-13 19:12:02 -070021import net.onrc.onos.core.intent.MockTopology;
Jonathan Hartaa380972014-04-03 10:24:46 -070022import net.onrc.onos.core.intent.ShortestPathIntent;
Jonathan Hart472062d2014-04-03 10:56:48 -070023import net.onrc.onos.core.topology.DeviceEvent;
Jonathan Hart472062d2014-04-03 10:56:48 -070024import net.onrc.onos.core.topology.LinkEvent;
25import net.onrc.onos.core.topology.PortEvent;
26import net.onrc.onos.core.topology.SwitchEvent;
Ray Milkey6688cd82014-03-11 16:40:46 -070027
Jonathan Harta88fd242014-04-03 11:24:54 -070028import org.hamcrest.Description;
29import org.hamcrest.Factory;
30import org.hamcrest.Matcher;
31import org.hamcrest.Matchers;
32import org.hamcrest.TypeSafeMatcher;
Ray Milkey6688cd82014-03-11 16:40:46 -070033import org.junit.After;
34import org.junit.Before;
35import org.junit.Test;
36import org.junit.runner.RunWith;
Ray Milkey6688cd82014-03-11 16:40:46 -070037import org.powermock.core.classloader.annotations.PrepareForTest;
38import org.powermock.modules.junit4.PowerMockRunner;
39
Ray Milkey6688cd82014-03-11 16:40:46 -070040/**
41 * @author Ray Milkey (ray@onlab.us)
Ray Milkey269ffb92014-04-03 14:43:30 -070042 * <p/>
43 * Unit tests for the Path Calculation Runtime module (PathCalcRuntimeModule).
44 * These test cases check the results of creating paths, deleting paths, and
Jonathan Harte37e4e22014-05-13 19:12:02 -070045 * rerouting paths. The topology, controller registry, and data grid are
Ray Milkey269ffb92014-04-03 14:43:30 -070046 * mocked out. The individual tests check the high level intents and the
47 * resulting operation lists to be sure they match the intended APIs.
Ray Milkey6688cd82014-03-11 16:40:46 -070048 */
49@RunWith(PowerMockRunner.class)
50@PrepareForTest(PathCalcRuntimeModule.class)
51public class PathCalcRuntimeModuleTest {
Ray Milkeydc659c42014-03-28 16:30:42 -070052 private static final Long LOCAL_PORT = 0xFFFEL;
53
Ray Milkey9d671002014-05-29 17:24:29 -070054 private IntentTestMocks mocks;
55 private PathCalcRuntimeModule runtime;
Ray Milkey6688cd82014-03-11 16:40:46 -070056
Ray Milkey6688cd82014-03-11 16:40:46 -070057 @Before
58 public void setUp() throws Exception {
Ray Milkey9d671002014-05-29 17:24:29 -070059 mocks = new IntentTestMocks();
60 mocks.setUpIntentMocks();
Ray Milkey6688cd82014-03-11 16:40:46 -070061
Ray Milkey9d671002014-05-29 17:24:29 -070062 runtime = new PathCalcRuntimeModule();
63 final FloodlightModuleContext moduleContext = mocks.getModuleContext();
64 runtime.init(moduleContext);
65 runtime.startUp(moduleContext);
Ray Milkey6688cd82014-03-11 16:40:46 -070066 }
67
Ray Milkeydc659c42014-03-28 16:30:42 -070068
69 /**
70 * Hamcrest matcher to check that a collection of Intents contains an
71 * Intent with the specified Intent Id.
72 */
73 public static class EntryForIntentMatcher extends TypeSafeMatcher<Collection<Intent>> {
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070074 private final String id;
Ray Milkeydc659c42014-03-28 16:30:42 -070075
76 public EntryForIntentMatcher(String idValue) {
77 id = idValue;
78 }
79
80 @Override
81 public boolean matchesSafely(Collection<Intent> intents) {
Pavlin Radoslavove2238bc2014-06-09 18:05:23 -070082 return hasItem(Matchers.<Intent>hasProperty("id", equalTo(id))).matches(intents);
Ray Milkeydc659c42014-03-28 16:30:42 -070083 }
84
85 @Override
86 public void describeTo(Description description) {
87 description.appendText("an intent with id \" ").
88 appendText(id).
89 appendText("\"");
90 }
91 }
92
93
94 /**
95 * Factory method to create an Intent entry Matcher. Returns a matcher
96 * for the Intent with the given id.
Ray Milkey269ffb92014-04-03 14:43:30 -070097 *
Ray Milkeydc659c42014-03-28 16:30:42 -070098 * @param id id of the intent to match
99 * @return Matcher object
100 */
101 @Factory
102 public static Matcher<Collection<Intent>> hasIntentWithId(String id) {
103 return new EntryForIntentMatcher(id);
104 }
105
106
107 /**
108 * Matcher to determine if an IntentMap contains an entry with a given id,
109 * and that entry has a given state.
110 */
111 public static class IntentsHaveIntentWithStateMatcher extends TypeSafeMatcher<IntentMap> {
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700112 private final String id;
113 private final IntentState state;
Ray Milkeydc659c42014-03-28 16:30:42 -0700114 private Intent intent;
115
116 public IntentsHaveIntentWithStateMatcher(String idValue,
117 IntentState stateValue) {
118 id = idValue;
119 state = stateValue;
120 }
121
122 @Override
123 public boolean matchesSafely(IntentMap intents) {
124 intent = intents.getIntent(id);
125
126 return intent != null && intent.getState() == state;
127 }
128
129 @Override
130 public void describeTo(Description description) {
131 if (intent == null) {
132 description.appendText("intent lookup for id \"");
133 description.appendText(id);
134 description.appendText("\"");
135 } else {
136 description.appendText("state ");
137 description.appendText(state.toString());
138 }
139 }
140
141 @Override
142 public void describeMismatchSafely(IntentMap intents,
143 Description mismatchDescription) {
144 if (intent != null) {
145 mismatchDescription.appendText("was ").
Ray Milkey269ffb92014-04-03 14:43:30 -0700146 appendText(intent.getState().toString());
Ray Milkeydc659c42014-03-28 16:30:42 -0700147 } else {
148 mismatchDescription.appendText("that intent was not found");
149 }
150 }
151 }
152
153
154 /**
155 * Factory method to create a Matcher for an IntentMap that looks for an
156 * Intent with a given id and state.
157 *
Ray Milkey269ffb92014-04-03 14:43:30 -0700158 * @param id id of the Intent to match
Ray Milkeydc659c42014-03-28 16:30:42 -0700159 * @param state if the Intent is found, its state must match this
160 * @return Matcher object
161 */
162 @Factory
163 public static Matcher<IntentMap> hasIntentWithIdAndState(String id,
164 IntentState state) {
165 return new IntentsHaveIntentWithStateMatcher(id, state);
166 }
167
168
Ray Milkey6688cd82014-03-11 16:40:46 -0700169 @After
170 public void tearDown() {
Ray Milkey9d671002014-05-29 17:24:29 -0700171 mocks.tearDownIntentMocks();
Ray Milkey6688cd82014-03-11 16:40:46 -0700172 }
173
174 /**
175 * Test the result of executing a path calculation on an
176 * Intent Operation List which contains a path that references a
177 * non-existent switch.
Ray Milkey269ffb92014-04-03 14:43:30 -0700178 * <p/>
Ray Milkey6688cd82014-03-11 16:40:46 -0700179 * A 3 path list is created where one of the paths references a switch
180 * that is not in the topology. The test checks that the resulting
181 * Operation List has entries for the 2 correct paths, and that the
182 * high level intents contain a proper error entry for the bad path.
183 */
184 @Test
185 public void testInvalidSwitchName() throws FloodlightModuleException {
Ray Milkey6688cd82014-03-11 16:40:46 -0700186 final String BAD_SWITCH_INTENT_NAME = "No Such Switch Intent";
187
188 // create shortest path intents
189 final IntentOperationList opList = new IntentOperationList();
190 opList.add(Operator.ADD,
191 new ShortestPathIntent(BAD_SWITCH_INTENT_NAME, 111L, 12L,
192 LOCAL_PORT, 2L, 21L, LOCAL_PORT));
193 opList.add(Operator.ADD,
194 new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L,
195 LOCAL_PORT));
196 opList.add(Operator.ADD,
197 new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L,
198 LOCAL_PORT));
199
200 // compile high-level intent operations into low-level intent
201 // operations (calculate paths)
Ray Milkey6688cd82014-03-11 16:40:46 -0700202 final IntentOperationList pathIntentOpList =
203 runtime.executeIntentOperations(opList);
204 assertThat(pathIntentOpList, notNullValue());
205
206 final IntentMap highLevelIntents = runtime.getHighLevelIntents();
207 assertThat(highLevelIntents, notNullValue());
208
209 final Collection<Intent> allIntents = highLevelIntents.getAllIntents();
210 assertThat(allIntents, notNullValue());
211
212 // One intent had an error and should not create a path list entry
213 assertThat(pathIntentOpList, hasSize(opList.size() - 1));
214
215 // Should be a high level intent for each operation
Ray Milkeydc659c42014-03-28 16:30:42 -0700216 assertThat(allIntents, hasSize(opList.size()));
Ray Milkey6688cd82014-03-11 16:40:46 -0700217
218 // Check that we got a high level intent for each operation
Ray Milkeydc659c42014-03-28 16:30:42 -0700219 assertThat(allIntents, hasIntentWithId("3"));
220 assertThat(allIntents, hasIntentWithId("2"));
221 assertThat(allIntents, hasIntentWithId(BAD_SWITCH_INTENT_NAME));
Ray Milkey6688cd82014-03-11 16:40:46 -0700222
223 // Check that the non existent switch was NACKed
Ray Milkeydc659c42014-03-28 16:30:42 -0700224 assertThat(highLevelIntents, hasIntentWithIdAndState(BAD_SWITCH_INTENT_NAME, IntentState.INST_NACK));
Ray Milkey6688cd82014-03-11 16:40:46 -0700225
226 // Check that switch 2 was correctly processed
Ray Milkeydc659c42014-03-28 16:30:42 -0700227 assertThat(highLevelIntents, hasIntentWithIdAndState("2", IntentState.INST_REQ));
Ray Milkey6688cd82014-03-11 16:40:46 -0700228
229 // Check that switch 3 was correctly processed
Ray Milkeydc659c42014-03-28 16:30:42 -0700230 assertThat(highLevelIntents, hasIntentWithIdAndState("3", IntentState.INST_REQ));
231
232 }
233
234
235 /**
236 * Test the result of executing a path calculation on an
237 * Intent Operation List and then removing one of the switches.
Ray Milkey269ffb92014-04-03 14:43:30 -0700238 * <p/>
Ray Milkeydc659c42014-03-28 16:30:42 -0700239 * A 3 path list is created and then one of the paths is removed.
240 * The test checks that the resulting Operation List is correct,
241 * and that the high level intents contain a proper "delete requested"
242 * entry for the deleted path.
243 */
244 @Test
245 public void testIntentRemoval() throws FloodlightModuleException {
246
247 // create shortest path intents
248 final IntentOperationList opList = new IntentOperationList();
249 opList.add(Operator.ADD,
250 new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L,
Ray Milkey269ffb92014-04-03 14:43:30 -0700251 LOCAL_PORT));
Ray Milkeydc659c42014-03-28 16:30:42 -0700252 opList.add(Operator.ADD,
253 new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L,
Ray Milkey269ffb92014-04-03 14:43:30 -0700254 LOCAL_PORT));
Ray Milkeydc659c42014-03-28 16:30:42 -0700255 opList.add(Operator.ADD,
256 new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L,
Ray Milkey269ffb92014-04-03 14:43:30 -0700257 LOCAL_PORT));
Ray Milkeydc659c42014-03-28 16:30:42 -0700258
259 // compile high-level intent operations into low-level intent
260 // operations (calculate paths)
Ray Milkeydc659c42014-03-28 16:30:42 -0700261 final IntentOperationList pathIntentOpList =
262 runtime.executeIntentOperations(opList);
263 assertThat(pathIntentOpList, notNullValue());
264
265 final IntentMap highLevelIntents = runtime.getHighLevelIntents();
266 assertThat(highLevelIntents, notNullValue());
267
268 final Collection<Intent> allIntents = highLevelIntents.getAllIntents();
269 assertThat(allIntents, notNullValue());
270
271 // Should be one operation per path
272 assertThat(pathIntentOpList, hasSize(opList.size()));
273
274 // Should be a high level intent for each operation
275 assertThat(allIntents, hasSize(opList.size()));
276
277 // Check that we got a high level intent for each operation
278 assertThat(allIntents, hasIntentWithId("3"));
279 assertThat(allIntents, hasIntentWithId("2"));
280 assertThat(allIntents, hasIntentWithId("1"));
281
282 // Check that switch 1 was correctly processed
283 assertThat(highLevelIntents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700284 hasIntentWithIdAndState("1", IntentState.INST_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700285
286 // Check that switch 2 was correctly processed
287 assertThat(highLevelIntents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700288 hasIntentWithIdAndState("2", IntentState.INST_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700289
290 // Check that switch 3 was correctly processed
291 assertThat(highLevelIntents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700292 hasIntentWithIdAndState("3", IntentState.INST_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700293
294 // Now delete one path and check the results
295 final IntentOperationList opListForRemoval = new IntentOperationList();
296 opListForRemoval.add(Operator.REMOVE,
297 new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L,
298 LOCAL_PORT));
299
300 final IntentOperationList pathIntentOpListAfterRemoval =
301 runtime.executeIntentOperations(opListForRemoval);
302 assertThat(pathIntentOpListAfterRemoval, notNullValue());
303 assertThat(pathIntentOpListAfterRemoval, hasSize(1));
304
305 // Check the high level intents.
306 final IntentMap highLevelIntentsAfterRemoval = runtime.getHighLevelIntents();
307 assertThat(highLevelIntentsAfterRemoval, notNullValue());
308
309 final Collection<Intent> allIntentsAfterRemoval = highLevelIntentsAfterRemoval.getAllIntents();
310 assertThat(allIntentsAfterRemoval, notNullValue());
311 assertThat(allIntentsAfterRemoval, hasSize(3));
312
313 // Check that we got a high level intent for each operation
314 assertThat(allIntentsAfterRemoval, hasIntentWithId("3"));
315 assertThat(allIntentsAfterRemoval, hasIntentWithId("2"));
316 assertThat(allIntentsAfterRemoval, hasIntentWithId("1"));
317
318 // Check the states of the high level intents
319 // Check that switch 1 was correctly processed
320 assertThat(highLevelIntents,
321 hasIntentWithIdAndState("1", IntentState.DEL_REQ));
322
323 // Check that switch 2 was correctly processed
324 assertThat(highLevelIntents,
325 hasIntentWithIdAndState("2", IntentState.INST_REQ));
326
327 // Check that switch 3 was correctly processed
328 assertThat(highLevelIntents,
329 hasIntentWithIdAndState("3", IntentState.INST_REQ));
330 }
331
332 /**
333 * Test the result of executing a path calculation on an
334 * Intent Operation List and then forcing a reroute.
Ray Milkey269ffb92014-04-03 14:43:30 -0700335 * <p/>
Ray Milkeydc659c42014-03-28 16:30:42 -0700336 * A 3 path list is created and then one of the links is removed.
337 * The test checks that the resulting Operation List is correct,
338 * and that the high level intents contain a proper "reroute requested"
339 * entry for the deleted link.
340 */
341 @Test
342 public void testIntentReroute() throws FloodlightModuleException {
343
344 // create shortest path intents
345 final IntentOperationList opList = new IntentOperationList();
346 final ShortestPathIntent pathIntent1 =
347 new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L,
Ray Milkey269ffb92014-04-03 14:43:30 -0700348 LOCAL_PORT);
Ray Milkeydc659c42014-03-28 16:30:42 -0700349
350 opList.add(Operator.ADD, pathIntent1);
351 opList.add(Operator.ADD,
352 new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L,
Ray Milkey269ffb92014-04-03 14:43:30 -0700353 LOCAL_PORT));
Ray Milkeydc659c42014-03-28 16:30:42 -0700354 opList.add(Operator.ADD,
355 new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L,
Ray Milkey269ffb92014-04-03 14:43:30 -0700356 LOCAL_PORT));
Ray Milkeydc659c42014-03-28 16:30:42 -0700357
358 // compile high-level intent operations into low-level intent
359 // operations (calculate paths)
Ray Milkeydc659c42014-03-28 16:30:42 -0700360 final IntentOperationList pathIntentOpList =
361 runtime.executeIntentOperations(opList);
362 assertThat(pathIntentOpList, notNullValue());
363
364 final IntentMap highLevelIntents = runtime.getHighLevelIntents();
365 assertThat(highLevelIntents, notNullValue());
366
367 final Collection<Intent> allIntents = highLevelIntents.getAllIntents();
368 assertThat(allIntents, notNullValue());
369
370 // Should be one operation per path
371 assertThat(pathIntentOpList, hasSize(opList.size()));
372
373 // Should be a high level intent for each operation
374 assertThat(allIntents, hasSize(opList.size()));
375
376 // Check that we got a high level intent for each operation
377 assertThat(allIntents, hasIntentWithId("3"));
378 assertThat(allIntents, hasIntentWithId("2"));
379 assertThat(allIntents, hasIntentWithId("1"));
380
Toshio Koidec2112c22014-06-05 19:59:15 -0700381 // Check that the high level intent 1 was correctly processed
Ray Milkeydc659c42014-03-28 16:30:42 -0700382 assertThat(highLevelIntents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700383 hasIntentWithIdAndState("1", IntentState.INST_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700384
Toshio Koidec2112c22014-06-05 19:59:15 -0700385 // Check that the high level intent 2 was correctly processed
Ray Milkeydc659c42014-03-28 16:30:42 -0700386 assertThat(highLevelIntents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700387 hasIntentWithIdAndState("2", IntentState.INST_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700388
Toshio Koidec2112c22014-06-05 19:59:15 -0700389 // Check that the high level intent 3 was correctly processed
Ray Milkeydc659c42014-03-28 16:30:42 -0700390 assertThat(highLevelIntents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700391 hasIntentWithIdAndState("3", IntentState.INST_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700392
Toshio Koidec2112c22014-06-05 19:59:15 -0700393 final IntentMap pathIntents = runtime.getPathIntents();
394 assertThat(pathIntents, notNullValue());
Ray Milkeydc659c42014-03-28 16:30:42 -0700395
Toshio Koidec2112c22014-06-05 19:59:15 -0700396 final Collection<Intent> allPathIntents = pathIntents.getAllIntents();
397 assertThat(allPathIntents, notNullValue());
398
399 // Check that we got a low level intent for each operation
400 assertThat(allPathIntents, hasIntentWithId("3___0"));
401 assertThat(allPathIntents, hasIntentWithId("2___0"));
402 assertThat(allPathIntents, hasIntentWithId("1___0"));
403
404 // Check that the low level intent 1 was correctly processed
405 assertThat(pathIntents,
406 hasIntentWithIdAndState("1___0", IntentState.INST_REQ));
407
408 // Check that the low level intent 2 was correctly processed
409 assertThat(pathIntents,
410 hasIntentWithIdAndState("2___0", IntentState.INST_REQ));
411
412 // Check that the low level intent 3 was correctly processed
413 assertThat(pathIntents,
414 hasIntentWithIdAndState("3___0", IntentState.INST_REQ));
415
416 // Receive notification from south-bound
417 IntentStateList isl = new IntentStateList();
418 isl.put("1___0", IntentState.INST_ACK);
419 isl.put("2___0", IntentState.INST_ACK);
420 isl.put("3___0", IntentState.INST_ACK);
421 isl.domainSwitchDpids.add(1L);
422 isl.domainSwitchDpids.add(2L);
423 isl.domainSwitchDpids.add(3L);
424 isl.domainSwitchDpids.add(4L);
425 runtime.entryUpdated(isl);
426
427 // Now check the results
428 final IntentMap processedHighLevelIntents = runtime.getHighLevelIntents();
429 assertThat(processedHighLevelIntents, notNullValue());
430
431 // Check that the high level intent 1 was correctly processed
432 assertThat(processedHighLevelIntents,
433 hasIntentWithIdAndState("1", IntentState.INST_ACK));
434
435 // Check that the high level intent 2 was correctly processed
436 assertThat(processedHighLevelIntents,
437 hasIntentWithIdAndState("2", IntentState.INST_ACK));
438
439 // Check that the high level intent 3 was correctly processed
440 assertThat(processedHighLevelIntents,
441 hasIntentWithIdAndState("3", IntentState.INST_ACK));
442
443 final IntentMap processedPathIntents = runtime.getPathIntents();
444 assertThat(processedPathIntents, notNullValue());
445
446 // Check that the low level intent 1 was correctly processed
447 assertThat(processedPathIntents,
448 hasIntentWithIdAndState("1___0", IntentState.INST_ACK));
449
450 // Check that the low level intent 2 was correctly processed
451 assertThat(processedPathIntents,
452 hasIntentWithIdAndState("2___0", IntentState.INST_ACK));
453
454 // Check that the low level intent 3 was correctly processed
455 assertThat(processedPathIntents,
456 hasIntentWithIdAndState("3___0", IntentState.INST_ACK));
457
458
459 // Remove one of the links and check results
Ray Milkeydc659c42014-03-28 16:30:42 -0700460 final List<SwitchEvent> emptySwitchEvents = new LinkedList<>();
461 final List<PortEvent> emptyPortEvents = new LinkedList<>();
462 final List<DeviceEvent> emptyDeviceEvents = new LinkedList<>();
463 final List<LinkEvent> addedLinkEvents = new LinkedList<>();
464 final List<LinkEvent> removedLinkEvents = new LinkedList<>();
465
Ray Milkey9d671002014-05-29 17:24:29 -0700466 final MockTopology topology = mocks.getTopology();
Jonathan Harte37e4e22014-05-13 19:12:02 -0700467 topology.removeLink(1L, 12L, 2L, 21L); // This link is used by the intent "1"
468 topology.removeLink(2L, 21L, 1L, 12L);
Ray Milkeydc659c42014-03-28 16:30:42 -0700469 LinkEvent linkEvent1 = new LinkEvent(1L, 12L, 2L, 21L);
470 LinkEvent linkEvent2 = new LinkEvent(2L, 21L, 1L, 12L);
471 removedLinkEvents.add(linkEvent1);
472 removedLinkEvents.add(linkEvent2);
Jonathan Harte37e4e22014-05-13 19:12:02 -0700473 runtime.topologyEvents(
Ray Milkeydc659c42014-03-28 16:30:42 -0700474 emptySwitchEvents,
475 emptySwitchEvents,
476 emptyPortEvents,
477 emptyPortEvents,
478 addedLinkEvents,
479 removedLinkEvents,
480 emptyDeviceEvents,
481 emptyDeviceEvents);
Ray Milkeydc659c42014-03-28 16:30:42 -0700482
483 // Check the high level intents.
484 final IntentMap highLevelIntentsAfterReroute = runtime.getHighLevelIntents();
485 assertThat(highLevelIntentsAfterReroute, notNullValue());
486
Ray Milkeydc659c42014-03-28 16:30:42 -0700487 // Check the states of the high level intents
Toshio Koidec2112c22014-06-05 19:59:15 -0700488 // Check that the high level intent 1 was correctly processed
489 assertThat(highLevelIntentsAfterReroute,
490 hasIntentWithIdAndState("1", IntentState.REROUTE_REQ));
Ray Milkeydc659c42014-03-28 16:30:42 -0700491
Toshio Koidec2112c22014-06-05 19:59:15 -0700492 // Check that the high level intent 2 was not affected
493 assertThat(highLevelIntentsAfterReroute,
Ray Milkeydc659c42014-03-28 16:30:42 -0700494 hasIntentWithIdAndState("2", IntentState.INST_ACK));
495
Toshio Koidec2112c22014-06-05 19:59:15 -0700496 // Check that the high level intent 3 was not affected
497 assertThat(highLevelIntentsAfterReroute,
Ray Milkeydc659c42014-03-28 16:30:42 -0700498 hasIntentWithIdAndState("3", IntentState.INST_ACK));
499
Toshio Koidec2112c22014-06-05 19:59:15 -0700500 final IntentMap pathIntentsAfterReroute = runtime.getPathIntents();
501 assertThat(pathIntentsAfterReroute, notNullValue());
Ray Milkey6688cd82014-03-11 16:40:46 -0700502
Toshio Koidec2112c22014-06-05 19:59:15 -0700503 // Check that the low level intent 1 was correctly processed
504 assertThat(pathIntentsAfterReroute,
505 hasIntentWithIdAndState("1___0", IntentState.DEL_REQ));
506 assertThat(pathIntentsAfterReroute,
507 hasIntentWithIdAndState("1___1", IntentState.INST_REQ));
508
509 // Check that the low level intent 2 was not affected
510 assertThat(pathIntentsAfterReroute,
511 hasIntentWithIdAndState("2___0", IntentState.INST_ACK));
512
513 // Check that the low level intent 3 was not affected
514 assertThat(pathIntentsAfterReroute,
515 hasIntentWithIdAndState("3___0", IntentState.INST_ACK));
516
517 // Receive notification from south-bound
518 isl = new IntentStateList();
519 isl.put("1___0", IntentState.DEL_ACK);
520 isl.put("1___1", IntentState.INST_ACK);
521 isl.domainSwitchDpids.add(1L);
522 isl.domainSwitchDpids.add(2L);
523 isl.domainSwitchDpids.add(4L);
524 runtime.entryUpdated(isl);
525
526 // Now check the results
527 final IntentMap reroutedHighLevelIntents = runtime.getHighLevelIntents();
528 assertThat(reroutedHighLevelIntents, notNullValue());
529
530 // Check that the high level intent 1 was correctly processed
531 assertThat(reroutedHighLevelIntents,
532 hasIntentWithIdAndState("1", IntentState.INST_ACK));
533
534 // Check that the high level intent 2 was not affected
535 assertThat(reroutedHighLevelIntents,
536 hasIntentWithIdAndState("2", IntentState.INST_ACK));
537
538 // Check that the high level intent 3 was not affected
539 assertThat(reroutedHighLevelIntents,
540 hasIntentWithIdAndState("3", IntentState.INST_ACK));
541
542 final IntentMap reroutedPathIntents = runtime.getPathIntents();
543 assertThat(processedPathIntents, notNullValue());
544
545 // Check that the low level intent 1 was correctly processed
Pavlin Radoslavove2238bc2014-06-09 18:05:23 -0700546 assertThat(reroutedPathIntents.getAllIntents(),
547 not(hasIntentWithId("1___0")));
Toshio Koidec2112c22014-06-05 19:59:15 -0700548 assertThat(reroutedPathIntents,
549 hasIntentWithIdAndState("1___1", IntentState.INST_ACK));
550
551 // Check that the low level intent 2 was not affected
552 assertThat(reroutedPathIntents,
553 hasIntentWithIdAndState("2___0", IntentState.INST_ACK));
554
555 // Check that the low level intent 3 was not affected
556 assertThat(reroutedPathIntents,
557 hasIntentWithIdAndState("3___0", IntentState.INST_ACK));
Ray Milkey6688cd82014-03-11 16:40:46 -0700558 }
Ray Milkey6688cd82014-03-11 16:40:46 -0700559}