Open Kilda Java Documentation
DiscoveryManagerTest.java
Go to the documentation of this file.
1 /* Copyright 2018 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.wfm.isl;
17 
18 import static org.hamcrest.Matchers.everyItem;
19 import static org.hamcrest.Matchers.hasProperty;
20 import static org.hamcrest.Matchers.is;
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertFalse;
23 import static org.junit.Assert.assertThat;
24 import static org.junit.Assert.assertTrue;
25 
29 
30 import org.junit.Before;
31 import org.junit.Test;
32 
33 import java.util.HashMap;
34 import java.util.List;
35 import java.util.Optional;
36 import java.util.Set;
37 
38 
47 public class DiscoveryManagerTest {
48 
49  private DiscoveryManager dm;
50  private NetworkEndpoint srcNode1;
51  private NetworkEndpoint dstNode1;
52  private NetworkEndpoint srcNode2;
53  private NetworkEndpoint dstNode2;
54  private NetworkEndpoint srcNode3;
55  private NetworkEndpoint dstNode3;
56  private int islHealthCheckInterval;
57  private int islHealthFailureLimit;
58  // Determines how many attempts to discover isl will be made
59  private int maxAttemptsLimit;
60  private int minutesKeepRemovedIsl;
61 
65  @Before
66  public void setUp() throws Exception {
67  islHealthCheckInterval = 0; // means check ever tick
68  islHealthFailureLimit = 1; // for testing, failure after 1 tick;
69  maxAttemptsLimit = 2;
70  minutesKeepRemovedIsl = 10;
71 
72  dm = new DiscoveryManager(new HashMap<>(), islHealthCheckInterval,
73  islHealthFailureLimit, maxAttemptsLimit, minutesKeepRemovedIsl);
74  }
75 
79  private void setupThreeLinks() {
80  srcNode1 = new NetworkEndpoint(new SwitchId("ff:01"), 1);
81  dstNode1 = new NetworkEndpoint(new SwitchId("ff:03"), 1);
82  srcNode2 = new NetworkEndpoint(new SwitchId("ff:01"), 2);
83  dstNode2 = new NetworkEndpoint(new SwitchId("ff:03"), 2);
84  srcNode3 = new NetworkEndpoint(new SwitchId("ff:02"), 1);
85  dstNode3 = new NetworkEndpoint(new SwitchId("ff:03"), 3);
86 
87  dm.handlePortUp(srcNode1.getDatapath(), srcNode1.getPortNumber());
88  dm.handlePortUp(srcNode2.getDatapath(), srcNode2.getPortNumber());
89  dm.handlePortUp(srcNode3.getDatapath(), srcNode3.getPortNumber());
90  }
91 
92  @Test
94  setupThreeLinks();
95 
96  // Initially, given 0 tick interval, everything should be in discoveryPlan and no failures
97  DiscoveryManager.Plan discoveryPlan = dm.makeDiscoveryPlan();
98  assertEquals(3, discoveryPlan.needDiscovery.size());
99  assertEquals(0, discoveryPlan.discoveryFailure.size());
100  }
101 
102  @Test
104  setupThreeLinks();
105 
106  for (int attempt = 0; attempt <= maxAttemptsLimit + islHealthFailureLimit + 1; attempt++) {
107 
108  DiscoveryManager.Plan discoveryPlan;
109  discoveryPlan = dm.makeDiscoveryPlan();
110  // number of attempts is always cleared up after receiving the response
111  assertEquals(1, dm.findBySourceEndpoint(srcNode1).get().getAttempts());
112  assertEquals(1, dm.findBySourceEndpoint(srcNode2).get().getAttempts());
113  assertEquals(1, dm.findBySourceEndpoint(srcNode3).get().getAttempts());
114 
115  discoveryPlan.needDiscovery.forEach(endpoint -> dm.handleSentDiscoPacket(endpoint));
116  // we should receive acknowledge for every sent disco packet
117  assertEquals(1, dm.findBySourceEndpoint(srcNode1).get().getAckAttempts());
118  assertEquals(1, dm.findBySourceEndpoint(srcNode2).get().getAckAttempts());
119  assertEquals(1, dm.findBySourceEndpoint(srcNode3).get().getAckAttempts());
120 
121  assertEquals(3, discoveryPlan.needDiscovery.size());
122  assertEquals(0, discoveryPlan.discoveryFailure.size());
123 
124  dm.handleDiscovered(srcNode1.getDatapath(), srcNode1.getPortNumber(),
125  dstNode1.getDatapath(), dstNode1.getPortNumber());
126  dm.handleDiscovered(srcNode2.getDatapath(), srcNode2.getPortNumber(),
127  dstNode2.getDatapath(), dstNode2.getPortNumber());
128  dm.handleDiscovered(srcNode3.getDatapath(), srcNode3.getPortNumber(),
129  dstNode3.getDatapath(), dstNode3.getPortNumber());
130 
131  verifyAllLinks();
132  }
133  }
134 
135  @Test
137  DiscoveryLink link = new DiscoveryLink(new SwitchId("ff:01"), 1, new SwitchId("ff:02"), 2,
138  islHealthCheckInterval, islHealthFailureLimit, false);
139  NetworkEndpoint srcNode = link.getSource();
140  dm.handlePortUp(srcNode.getDatapath(), srcNode.getPortNumber());
141 
142  DiscoveryManager.Plan discoveryPlan = dm.makeDiscoveryPlan();
143  discoveryPlan.needDiscovery.forEach(endpoint -> dm.handleSentDiscoPacket(endpoint));
144  dm.handleDiscovered(srcNode.getDatapath(), srcNode.getPortNumber(),
145  link.getDestination().getDatapath(), link.getDestination().getPortNumber());
146 
147  assertTrue(dm.findBySourceEndpoint(srcNode).get().isActive());
148 
149  // 1st attempt
150  discoveryPlan = dm.makeDiscoveryPlan();
151  assertEquals(1, discoveryPlan.needDiscovery.size());
152  assertEquals(0, discoveryPlan.discoveryFailure.size());
153  discoveryPlan.needDiscovery.forEach(endpoint -> dm.handleSentDiscoPacket(endpoint));
154  assertTrue(dm.findBySourceEndpoint(srcNode).get().isActive());
155 
156  // 2nd attempt and we have only one acknowledged dispatch of disco packet
157  discoveryPlan = dm.makeDiscoveryPlan();
158  assertEquals(1, discoveryPlan.needDiscovery.size());
159  assertEquals(0, discoveryPlan.discoveryFailure.size());
160  discoveryPlan.needDiscovery.forEach(endpoint -> dm.handleSentDiscoPacket(endpoint));
161  assertTrue(dm.findBySourceEndpoint(srcNode).get().isActive());
162 
163  // 3rd attempt and 1st failure
164  // link should be marked as inactive because 2 ackAttempts > current islHealthFailureLimit
165  discoveryPlan = dm.makeDiscoveryPlan();
166  assertEquals(1, discoveryPlan.needDiscovery.size());
167  assertEquals(1, discoveryPlan.discoveryFailure.size());
168  discoveryPlan.needDiscovery.forEach(endpoint -> dm.handleSentDiscoPacket(endpoint));
169  assertFalse(dm.findBySourceEndpoint(srcNode).get().isActive());
170 
171  // 4th attempt, 1st consecutive failure
172  discoveryPlan = dm.makeDiscoveryPlan();
173  assertEquals(1, discoveryPlan.needDiscovery.size());
174  assertEquals(0, discoveryPlan.discoveryFailure.size());
175  discoveryPlan.needDiscovery.forEach(endpoint -> dm.handleSentDiscoPacket(endpoint));
176  assertFalse(dm.findBySourceEndpoint(srcNode).get().isActive());
177 
178  // 5th attempt, 2nd consecutive failure
179  // should be removed from discovery because consecutiveFailure > consecutiveFailureLimit
180  discoveryPlan = dm.makeDiscoveryPlan();
181  assertEquals(0, discoveryPlan.needDiscovery.size());
182  assertEquals(0, discoveryPlan.discoveryFailure.size());
183  assertFalse(dm.findBySourceEndpoint(srcNode).get().isActive());
184  }
185 
186  @Test
188  setupThreeLinks();
189 
190  DiscoveryManager.Plan discoveryPlan;
191  for (int attempt = 0; attempt <= maxAttemptsLimit + islHealthFailureLimit; attempt++) {
192  discoveryPlan = dm.makeDiscoveryPlan();
193  discoveryPlan.needDiscovery.forEach(endpoint -> dm.handleSentDiscoPacket(endpoint));
194  assertEquals(3, discoveryPlan.needDiscovery.size());
195  assertEquals(0, discoveryPlan.discoveryFailure.size());
196  }
197 
198  // 5th attempt to send disco packet. 3rd failure and it is bigger than islConsecutiveFailureLimit (2).
199  discoveryPlan = dm.makeDiscoveryPlan();
200  // we should stop sending disco packets from these endpoints.
201  assertEquals(0, discoveryPlan.needDiscovery.size());
202  assertEquals(0, discoveryPlan.discoveryFailure.size());
203 
204  // all links are discovered - we need to add them to discovery plan again.
205  dm.handleDiscovered(srcNode1.getDatapath(), srcNode1.getPortNumber(),
206  dstNode1.getDatapath(), dstNode1.getPortNumber());
207  dm.handleDiscovered(srcNode2.getDatapath(),
208  srcNode2.getPortNumber(), dstNode2.getDatapath(), dstNode2.getPortNumber());
209  dm.handleDiscovered(srcNode3.getDatapath(), srcNode3.getPortNumber(),
210  dstNode3.getDatapath(), dstNode3.getPortNumber());
211  discoveryPlan = dm.makeDiscoveryPlan();
212  assertEquals(3, discoveryPlan.needDiscovery.size());
213  assertEquals(0, discoveryPlan.discoveryFailure.size());
214  }
215 
216  @Test
218  setupThreeLinks();
219 
220  // if we don't receive confirmation of sending discovery packet we should not mark ISL as inactive
221  for (int attempt = 0; attempt <= maxAttemptsLimit + islHealthFailureLimit + 1; attempt++) {
222  DiscoveryManager.Plan discoveryPlan;
223  discoveryPlan = dm.makeDiscoveryPlan();
224  assertEquals(3, discoveryPlan.needDiscovery.size());
225  assertEquals(0, discoveryPlan.discoveryFailure.size());
226  }
227  }
228 
229  @Test
231  setupThreeLinks();
232  DiscoveryManager.Plan discoveryPlan = dm.makeDiscoveryPlan();
233  discoveryPlan.needDiscovery.forEach(endpoint -> dm.handleSentDiscoPacket(endpoint));
234 
235  dm.handleDiscovered(srcNode1.getDatapath(), srcNode1.getPortNumber(),
236  dstNode1.getDatapath(), dstNode1.getPortNumber());
237  dm.handleDiscovered(srcNode2.getDatapath(), srcNode2.getPortNumber(),
238  dstNode2.getDatapath(), dstNode2.getPortNumber());
239  dm.handleDiscovered(srcNode3.getDatapath(), srcNode3.getPortNumber(),
240  dstNode3.getDatapath(), dstNode3.getPortNumber());
241 
242  // if we don't receive confirmation of sending discovery packet we should not mark ISL as inactive
243  for (int attempt = 0; attempt <= maxAttemptsLimit + islHealthFailureLimit + 1; attempt++) {
244  discoveryPlan = dm.makeDiscoveryPlan();
245  assertEquals(3, discoveryPlan.needDiscovery.size());
246  assertEquals(0, discoveryPlan.discoveryFailure.size());
247  }
248 
249  verifyAllLinks();
250  }
251 
252  @Test
254  // verify Health Check Interval is working properly.
255  islHealthCheckInterval = 2;
256  islHealthFailureLimit = 4; // for testing, failure after 1 tick;
257  maxAttemptsLimit = 8;
258 
259  dm = new DiscoveryManager(new HashMap<>(), islHealthCheckInterval,
260  islHealthFailureLimit, maxAttemptsLimit, minutesKeepRemovedIsl);
261  setupThreeLinks();
262  // Initially, given 2 tick interval, nothing should be in the lists
263  DiscoveryManager.Plan discoveryPlan = dm.makeDiscoveryPlan();
264  assertEquals(0, discoveryPlan.needDiscovery.size());
265  assertEquals(0, discoveryPlan.discoveryFailure.size());
266 
267  // Still nothing
268  discoveryPlan = dm.makeDiscoveryPlan();
269  assertEquals(0, discoveryPlan.needDiscovery.size());
270  assertEquals(0, discoveryPlan.discoveryFailure.size());
271 
272  // Now we discover
273  discoveryPlan = dm.makeDiscoveryPlan();
274  assertEquals(3, discoveryPlan.needDiscovery.size());
275  assertEquals(0, discoveryPlan.discoveryFailure.size());
276 
277  // But not now
278  discoveryPlan = dm.makeDiscoveryPlan();
279  assertEquals(0, discoveryPlan.needDiscovery.size());
280  assertEquals(0, discoveryPlan.discoveryFailure.size());
281  }
282 
283  @Test
284  public void handleDiscovered() {
285  // Test whether it handle the state change properly .. ie is this a new failure ore not.
286  // - if !discovered, then we've just found an ISL
287  // - if discovered, but found failures (and now we have success), that is a change
288  // - state information .. consecutive failures is zero, tick/attempts is zero, success++
289 
290  setupThreeLinks();
291  NetworkEndpoint dstNode = dstNode2;
292 
293  // An initial success is state change
294  assertEquals(true, dm.handleDiscovered(srcNode2.getSwitchDpId(), srcNode2.getPortId(),
295  dstNode.getSwitchDpId(), dstNode.getPortId()));
296  // A repeated success is not
297  assertEquals(false, dm.handleDiscovered(srcNode2.getSwitchDpId(), srcNode2.getPortId(),
298  dstNode.getSwitchDpId(), dstNode.getPortId()));
299 
300  // Let it fail, then succeed .. both are state changes
301  assertEquals(true, dm.handleFailed(srcNode2.getSwitchDpId(), srcNode2.getPortId()));
302  assertEquals(true, dm.handleDiscovered(srcNode2.getSwitchDpId(), srcNode2.getPortId(),
303  dstNode.getSwitchDpId(), dstNode.getPortId()));
304  assertEquals(false, dm.handleDiscovered(srcNode2.getSwitchDpId(), srcNode2.getPortId(),
305  dstNode.getSwitchDpId(), dstNode.getPortId()));
306  }
307 
308  @Test
309  public void handleFailed() {
310  // Test whether it handle the state change properly .. ie is this a new failure or not.
311  // NB: handleFailed is called when an ISL failure is received from FL; the other kind of
312  // failure is if there is no response, and that is handled by makeDiscoveryPlan().
313  List<DiscoveryLink> nodes;
314  setupThreeLinks();
315 
316  // After a PortUP, a failure isn't a state change, the default is to assume it isn't an ISL
317  assertEquals(false, dm.handleFailed(srcNode2.getSwitchDpId(), srcNode2.getPortId()));
318  // A success after a failure is state change
319  assertEquals(true, dm.handleDiscovered(srcNode2.getSwitchDpId(), srcNode2.getPortId(),
320  dstNode2.getSwitchDpId(), dstNode2.getPortId()));
321  // A failure after a success is state change
322  assertEquals(true, dm.handleFailed(srcNode2.getSwitchDpId(), srcNode2.getPortId()));
323  // Repeated failures isn't a state change.
324  assertEquals(false, dm.handleFailed(srcNode2.getSwitchDpId(), srcNode2.getPortId()));
325  }
326 
327  @Test
328  public void handleSwitchUp() {
329  // Verify that all switch/ports on this switch of the ISL flag cleared
330 
331  // Generally speaking, nothing interesting happens on a SwitchUp, since all of the action is
332  // in PortUp. However, this one area, when pre-existing ISLs are already in the DM, should
333  // be tested. We need to create some ISLs, then send the SwitchUp, and confirm isFoundIsl
334  // is cleared.
335  setupThreeLinks();
336 
337  // discover them and confirm all discovered
338  dm.handleDiscovered(srcNode1.getDatapath(), srcNode1.getPortNumber(),
339  dstNode1.getDatapath(), dstNode1.getPortNumber());
340  dm.handleDiscovered(srcNode2.getDatapath(), srcNode2.getPortNumber(),
341  dstNode2.getDatapath(), dstNode2.getPortNumber());
342  dm.handleDiscovered(srcNode3.getDatapath(), srcNode3.getPortNumber(),
343  dstNode3.getDatapath(), dstNode3.getPortNumber());
344 
345  Set<DiscoveryLink> links = dm.findAllBySwitch(srcNode1.getDatapath());
346  assertThat(links, everyItem(hasProperty("active", is(true))));
347  links = dm.findAllBySwitch(srcNode3.getDatapath());
348  assertThat(links, everyItem(hasProperty("active", is(true))));
349 
350  // now send SwitchUp and confirm sw1 all go back to not found, sw2 unchanged
351  dm.handleSwitchUp(srcNode1.getDatapath());
352  links = dm.findAllBySwitch(srcNode1.getDatapath());
353  assertThat(links, everyItem(hasProperty("active", is(false))));
354  links = dm.findAllBySwitch(srcNode3.getDatapath());
355  assertThat(links, everyItem(hasProperty("active", is(true))));
356 
357  // now confirm they go back to found upon next Discovery.
358  dm.handleDiscovered(srcNode1.getDatapath(), srcNode1.getPortNumber(),
359  dstNode1.getDatapath(), dstNode1.getPortNumber());
360  dm.handleDiscovered(srcNode2.getDatapath(), srcNode2.getPortNumber(),
361  dstNode2.getDatapath(), dstNode2.getPortNumber());
362  links = dm.findAllBySwitch(srcNode1.getDatapath());
363  assertThat(links, everyItem(hasProperty("active", is(true))));
364  links = dm.findAllBySwitch(srcNode3.getDatapath());
365  assertThat(links, everyItem(hasProperty("active", is(true))));
366  }
367 
368  @Test
369  public void handleSwitchDown() {
370  // verify all the ISL switch/ports are deleted
371 
372  setupThreeLinks();
373  // 3 nodes - 2 in sw1, one in sw2; verify dropping sw1 drops 2 nodes (1 remaining)
374  Set<DiscoveryLink> links = dm.findAllBySwitch(srcNode1.getDatapath());
375  assertEquals(2, links.size());
376  links = dm.findAllBySwitch(srcNode3.getDatapath());
377  assertEquals(1, links.size());
378 
379  // Drop the switch, and then the same 4 lines of code, except 0 size for sw1 nodes.
380  dm.handleSwitchDown(srcNode1.getDatapath());
381  links = dm.findAllBySwitch(srcNode1.getDatapath());
382  assertEquals(0, links.size());
383  links = dm.findAllBySwitch((srcNode3.getDatapath()));
384  assertEquals(1, links.size());
385  }
386 
387  @Test
388  public void handlePortUp() {
389  // verify the switch/port is added
390  // verify that adding an existing one doesn't crash it.
391 
392  // Put in 1 node and verify it is there.
393  DiscoveryLink link = new DiscoveryLink(new SwitchId("ff:01"), 1, islHealthCheckInterval, islHealthFailureLimit);
394  NetworkEndpoint srcNode = link.getSource();
395  dm.handlePortUp(srcNode.getSwitchDpId(), srcNode.getPortId());
396  Optional<DiscoveryLink> discoveryLink =
397  dm.findBySourceEndpoint(new NetworkEndpoint(srcNode.getSwitchDpId(), srcNode.getPortId()));
398  assertTrue(discoveryLink.isPresent());
399  assertEquals(link, discoveryLink.get());
400 
401  // try to add it back in .. should still be present
402  dm.handlePortUp(srcNode.getSwitchDpId(), srcNode.getPortId());
403  discoveryLink = dm.findBySourceEndpoint(new NetworkEndpoint(srcNode.getSwitchDpId(), srcNode.getPortId()));
404  assertTrue(discoveryLink.isPresent());
405  assertEquals(link, discoveryLink.get());
406  }
407 
408  @Test
409  public void handlePortDown() {
410  // verify the switch/port is deleted.
411  // verify remove one that doesn't exist doesn't crash it
412 
413  // Put in 1 node and then remove it. The handlePortUp test ensures the Port Up works.
414  DiscoveryLink link = new DiscoveryLink(new SwitchId("ff:01"), 1, islHealthCheckInterval, islHealthFailureLimit);
415  NetworkEndpoint srcNode = link.getSource();
416  dm.handlePortUp(srcNode.getSwitchDpId(), srcNode.getPortId());
417  dm.handlePortDown(srcNode.getSwitchDpId(), srcNode.getPortId());
418  Optional<DiscoveryLink> discoveryLink =
419  dm.findBySourceEndpoint(new NetworkEndpoint(srcNode.getSwitchDpId(), srcNode.getPortId()));
420  assertFalse(discoveryLink.isPresent());
421 
422  // call PortDown again .. verify nothing bad happens.
423  dm.handlePortDown(srcNode.getSwitchDpId(), srcNode.getPortId());
424  discoveryLink = dm.findBySourceEndpoint(new NetworkEndpoint(srcNode.getSwitchDpId(), srcNode.getPortId()));
425  assertFalse(discoveryLink.isPresent());
426  }
427 
428  @Test
430  setupThreeLinks();
431 
432  boolean stateChanged = dm.handleDiscovered(srcNode1.getSwitchDpId(), srcNode1.getPortId(),
433  dstNode1.getSwitchDpId(), dstNode1.getPortId());
434  assertTrue(stateChanged);
435 
436  stateChanged = dm.handleDiscovered(srcNode1.getSwitchDpId(), srcNode1.getPortId(),
437  dstNode1.getSwitchDpId(), dstNode1.getPortId());
438  assertFalse(stateChanged);
439 
440  stateChanged = dm.handleDiscovered(srcNode1.getSwitchDpId(), srcNode1.getPortId(),
441  dstNode2.getSwitchDpId(), dstNode2.getPortId());
442  assertTrue(stateChanged);
443  }
444 
445  @Test
447  NetworkEndpoint source = new NetworkEndpoint(new SwitchId("ff:01"), 1);
448  assertFalse(dm.isInDiscoveryPlan(source.getDatapath(), source.getPortNumber()));
449  }
450 
451  @Test
453  NetworkEndpoint source = new NetworkEndpoint(new SwitchId("ff:01"), 1);
454  dm.handlePortUp(source.getDatapath(), source.getPortNumber());
455 
456  // 1st attempt to discover
457  dm.makeDiscoveryPlan();
459 
460  // 2nd attempt to discover
461  dm.makeDiscoveryPlan();
463 
464  // 3rd attempt to send disco packet. 1st failure because ISL still not discovered.
465  dm.makeDiscoveryPlan();
467 
468  // 4th attempt to send disco packet. 2nd failure because ISL still not discovered.
469  dm.makeDiscoveryPlan();
470 
471  // 5th attempt to send disco packet. 3rd failure and it is bigger than islConsecutiveFailureLimit (2).
472  dm.makeDiscoveryPlan();
473 
474  assertFalse(dm.isInDiscoveryPlan(source.getDatapath(), source.getPortNumber()));
475  }
476 
477  @Test
479  NetworkEndpoint source = new NetworkEndpoint(new SwitchId("ff:01"), 1);
480  dm.handlePortUp(source.getDatapath(), source.getPortNumber());
481  assertTrue(dm.isInDiscoveryPlan(source.getDatapath(), source.getPortNumber()));
482  }
483 
484  @Test
486  NetworkEndpoint source = new NetworkEndpoint(new SwitchId("ff:01"), 1);
487  dm.handlePortUp(source.getDatapath(), source.getPortNumber());
488 
489  // originally all counters should be 0.
490  Optional<DiscoveryLink> links = dm.findBySourceEndpoint(source);
491  assertTrue(links.isPresent());
492  assertEquals(0, links.get().getAckAttempts());
493  assertEquals(0, links.get().getAttempts());
494 
495  // simulate receiving the confirmation abound sending disco packet
497  links = dm.findBySourceEndpoint(source);
498  assertTrue(links.isPresent());
499  assertEquals(1, links.get().getAckAttempts());
500  assertEquals(0, links.get().getAttempts());
501  }
502 
503  private void verifyAllLinks() {
504  assertTrue(dm.findBySourceEndpoint(srcNode1).isPresent()
505  && dm.findBySourceEndpoint(srcNode1).get().isActive());
506  assertTrue(dm.findBySourceEndpoint(srcNode2).isPresent()
507  && dm.findBySourceEndpoint(srcNode2).get().isActive());
508  assertTrue(dm.findBySourceEndpoint(srcNode3).isPresent()
509  && dm.findBySourceEndpoint(srcNode3).get().isActive());
510  }
511 
512  @Test
514  // given
515  setupThreeLinks();
516 
517  Optional<DiscoveryLink> foundAsLink1Before = dm.findBySourceEndpoint(srcNode1);
518  assertTrue(foundAsLink1Before.isPresent());
519  foundAsLink1Before.get().activate(dstNode1);
520 
521  // when
522  DiscoveryLink affectedLink = dm.registerPort(srcNode1.getDatapath(), srcNode1.getPortNumber());
523  assertEquals(affectedLink.getSource(), srcNode1);
524  assertTrue("The link must be active.", affectedLink.isActive());
525 
526  // then
527  Optional<DiscoveryLink> foundAsLink1After = dm.findBySourceEndpoint(srcNode1);
528  assertTrue(foundAsLink1After.isPresent());
529  assertTrue("The link must be active.", foundAsLink1After.get().isActive());
530  }
531 
532  @Test
534  // given
535  setupThreeLinks();
536 
537  NetworkEndpoint srcNode4 = new NetworkEndpoint(new SwitchId("ff:02"), 2);
538 
539  Optional<DiscoveryLink> foundAsLink4Before = dm.findBySourceEndpoint(srcNode4);
540  assertFalse(foundAsLink4Before.isPresent());
541 
542  // when
543  DiscoveryLink addedLink = dm.registerPort(srcNode4.getDatapath(), srcNode4.getPortNumber());
544  assertEquals(addedLink.getSource(), srcNode4);
545  assertFalse("The link must be inactive.", addedLink.isActive());
546 
547  // then
548  Optional<DiscoveryLink> foundAsLink4After = dm.findBySourceEndpoint(srcNode4);
549  assertTrue(foundAsLink4After.isPresent());
550  }
551 }
nodes
Definition: nodes.py:41
boolean isInDiscoveryPlan(SwitchId switchId, int portId)
void handlePortUp(SwitchId switchId, int portId)
void handlePortDown(SwitchId switchId, int portId)
DiscoveryLink registerPort(SwitchId switchId, int portId)
void handleSentDiscoPacket(NetworkEndpoint endpoint)
boolean handleFailed(SwitchId switchId, int portId)
source
Definition: nodes.py:53
final List< NetworkEndpoint > needDiscovery
boolean handleDiscovered(SwitchId srcSwitch, int srcPort, SwitchId dstSwitch, int dstPort)