Link lt = new Link(1L, 1, 2L, 1);
NodePortTuple srcNpt = new NodePortTuple(1L, 1);
NodePortTuple dstNpt = new NodePortTuple(2L, 1);
LinkInfo info;
info = new LinkInfo(System.currentTimeMillis() - 40000,
System.currentTimeMillis() - 40000, null);
linkDiscovery.addOrUpdateLink(lt, info);
// check invariants hold
assertNotNull(linkDiscovery.switchLinks.get(lt.getSrc()));
assertTrue(linkDiscovery.switchLinks.get(lt.getSrc()).contains(lt));
assertNotNull(linkDiscovery.portLinks.get(srcNpt));
assertTrue(linkDiscovery.portLinks.get(srcNpt).contains(lt));
assertNotNull(linkDiscovery.portLinks.get(dstNpt));
assertTrue(linkDiscovery.portLinks.get(dstNpt).contains(lt));
assertTrue(linkDiscovery.links.containsKey(lt));
linkDiscovery.timeoutLinks();
info = new LinkInfo(System.currentTimeMillis(),/* firstseen */
null,/* unicast */
System.currentTimeMillis());
linkDiscovery.addOrUpdateLink(lt, info);
assertTrue(linkDiscovery.links.get(lt).getUnicastValidTime() == null);
assertTrue(linkDiscovery.links.get(lt).getMulticastValidTime() != null);
// Add a link info based on info that woudld be obtained from unicast LLDP
// Setting the unicast LLDP reception time to be 40 seconds old, so we can use
// this to test timeout after this test. Although the info is initialized
// with LT_OPENFLOW_LINK, the link property should be changed to LT_NON_OPENFLOW
// by the addOrUpdateLink method.
info = new LinkInfo(System.currentTimeMillis() - 40000,
System.currentTimeMillis() - 40000, null);
linkDiscovery.addOrUpdateLink(lt, info);
// Expect to timeout the unicast Valid Time, but not the multicast Valid time
// So the link type should go back to non-openflow link.
linkDiscovery.timeoutLinks();
assertTrue(linkDiscovery.links.get(lt).getUnicastValidTime() == null);
assertTrue(linkDiscovery.links.get(lt).getMulticastValidTime() != null);
// Set the multicastValidTime to be old and see if that also times out.
info = new LinkInfo(System.currentTimeMillis() - 40000,
null, System.currentTimeMillis() - 40000);
linkDiscovery.addOrUpdateLink(lt, info);
linkDiscovery.timeoutLinks();
assertTrue(linkDiscovery.links.get(lt) == null);
// Test again only with multicast LLDP
info = new LinkInfo(System.currentTimeMillis() - 40000,
null, System.currentTimeMillis() - 40000);
linkDiscovery.addOrUpdateLink(lt, info);
assertTrue(linkDiscovery.links.get(lt).getUnicastValidTime() == null);
assertTrue(linkDiscovery.links.get(lt).getMulticastValidTime() != null);
// Call timeout and check if link is no longer present.
linkDiscovery.timeoutLinks();
assertTrue(linkDiscovery.links.get(lt) == null);
// Start clean and see if loops are also added.
lt = new Link(1L, 1, 1L, 2);
srcNpt = new NodePortTuple(1L, 1);
dstNpt = new NodePortTuple(1L, 2);
info = new LinkInfo(System.currentTimeMillis() - 40000,
null, System.currentTimeMillis() - 40000);
linkDiscovery.addOrUpdateLink(lt, info);
// Start clean and see if loops are also added.
lt = new Link(1L, 1, 1L, 3);
srcNpt = new NodePortTuple(1L, 1);
dstNpt = new NodePortTuple(1L, 3);
info = new LinkInfo(System.currentTimeMillis() - 40000,
null, System.currentTimeMillis() - 40000);
linkDiscovery.addOrUpdateLink(lt, info);
// Start clean and see if loops are also added.
lt = new Link(1L, 4, 1L, 5);
srcNpt = new NodePortTuple(1L, 4);
dstNpt = new NodePortTuple(1L, 5);
info = new LinkInfo(System.currentTimeMillis() - 40000,
null, System.currentTimeMillis() - 40000);
linkDiscovery.addOrUpdateLink(lt, info);
// Start clean and see if loops are also added.
lt = new Link(1L, 3, 1L, 5);
srcNpt = new NodePortTuple(1L, 3);
dstNpt = new NodePortTuple(1L, 5);
info = new LinkInfo(System.currentTimeMillis() - 40000,
null, System.currentTimeMillis() - 40000);
linkDiscovery.addOrUpdateLink(lt, info);
}