use of org.onosproject.net.link.LinkEvent in project onos by opennetworkinglab.
the class EdgeManagerTest method testBasics.
@Test
public void testBasics() {
// Setup
int numDevices = 20;
int numPorts = 4;
defaultPopulator(numDevices, numPorts);
assertEquals("Unexpected number of ports", numDevices * numPorts, infrastructurePorts.size());
assertFalse("Expected isEdge to return false", mgr.isEdgePoint(NetTestTools.connectPoint(Integer.toString(1), 1)));
removeInfraPort(NetTestTools.connectPoint(Integer.toString(1), 1));
postTopologyEvent(new LinkEvent(LINK_REMOVED, NetTestTools.link(Integer.toString(1), 1, "b", 2)));
assertTrue("Expected isEdge to return true", mgr.isEdgePoint(NetTestTools.connectPoint(Integer.toString(1), 1)));
}
use of org.onosproject.net.link.LinkEvent in project onos by opennetworkinglab.
the class EdgeManagerTest method testLinkUpdates.
@Test
public void testLinkUpdates() {
// Setup
ConnectPoint testPoint, referencePoint;
// Testing link removal
devices.put(NetTestTools.did("a"), NetTestTools.device("a"));
devices.put(NetTestTools.did("b"), NetTestTools.device("b"));
postTopologyEvent(new LinkEvent(LINK_REMOVED, NetTestTools.link("a", 1, "b", 2)));
assertEquals("The list contained an unexpected number of events", 2, events.size());
assertTrue("The first element is of the wrong type.", events.get(0).type() == EDGE_PORT_ADDED);
testPoint = events.get(0).subject();
referencePoint = NetTestTools.connectPoint("a", 1);
assertTrue("The port numbers of the first element are incorrect", testPoint.port().toLong() == referencePoint.port().toLong());
assertTrue("The device id of the first element is incorrect.", testPoint.deviceId().equals(referencePoint.deviceId()));
testPoint = events.get(1).subject();
referencePoint = NetTestTools.connectPoint("b", 2);
assertTrue("The port numbers of the second element are incorrect", testPoint.port().toLong() == referencePoint.port().toLong());
assertTrue("The device id of the second element is incorrect.", testPoint.deviceId().equals(referencePoint.deviceId()));
// Rebroadcast event to ensure it results in no additional events
postTopologyEvent(new LinkEvent(LINK_REMOVED, NetTestTools.link("a", 1, "b", 2)));
assertTrue("The list contained an unexpected number of events", events.size() == 2);
// Testing link adding when links to remove exist
events.clear();
postTopologyEvent(new LinkEvent(LINK_ADDED, NetTestTools.link("a", 1, "b", 2)));
assertTrue("The list contained an unexpected number of events", events.size() == 2);
assertTrue("The first element is of the wrong type.", events.get(0).type() == EDGE_PORT_REMOVED);
assertTrue("The second element is of the wrong type.", events.get(1).type() == EDGE_PORT_REMOVED);
testPoint = events.get(0).subject();
referencePoint = NetTestTools.connectPoint("a", 1);
assertTrue("The port numbers of the first element are incorrect", testPoint.port().toLong() == referencePoint.port().toLong());
assertTrue("The device id of the first element is incorrect.", testPoint.deviceId().equals(referencePoint.deviceId()));
testPoint = events.get(1).subject();
referencePoint = NetTestTools.connectPoint("b", 2);
assertTrue("The port numbers of the second element are incorrect", testPoint.port().toLong() == referencePoint.port().toLong());
assertTrue("The device id of the second element is incorrect.", testPoint.deviceId().equals(referencePoint.deviceId()));
// Apparent duplicate of previous method tests removal when the elements have already been removed
events.clear();
postTopologyEvent(new LinkEvent(LINK_ADDED, NetTestTools.link("a", 1, "b", 2)));
assertTrue("The list should contain no events, the removed elements don't exist.", events.size() == 0);
}
use of org.onosproject.net.link.LinkEvent in project onos by opennetworkinglab.
the class EdgeManagerTest method defaultPopulator.
/**
* @param numDevices the number of devices to populate.
* @param numInfraPorts the number of ports to be set as infrastructure on each device, numbered base 0, ports 0
* through numInfraPorts - 1
*/
private void defaultPopulator(int numDevices, int numInfraPorts) {
for (int device = 0; device < numDevices; device++) {
String str = Integer.toString(device);
Device deviceToAdd = NetTestTools.device(str);
devices.put(deviceToAdd.id(), deviceToAdd);
testDeviceManager.listener.event(new DeviceEvent(DEVICE_ADDED, deviceToAdd));
for (int port = 1; port <= numInfraPorts; port++) {
testLinkService.listener.event(new LinkEvent(LINK_ADDED, NetTestTools.link(str, port, "other", 1)));
infrastructurePorts.add(NetTestTools.connectPoint(str, port));
}
}
}
use of org.onosproject.net.link.LinkEvent in project onos by opennetworkinglab.
the class LinkManager method removeLinks.
// Removes all links in the specified set and emits appropriate events.
private void removeLinks(Set<Link> links, boolean isSoftRemove) {
for (Link link : links) {
LinkEvent event = isSoftRemove ? store.removeOrDownLink(link.src(), link.dst()) : store.removeLink(link.src(), link.dst());
if (event != null) {
log.info("Link {} removed/vanished", event.subject());
post(event);
}
}
}
use of org.onosproject.net.link.LinkEvent in project onos by opennetworkinglab.
the class SimpleLinkStore method removeLink.
@Override
public LinkEvent removeLink(ConnectPoint src, ConnectPoint dst) {
final LinkKey key = linkKey(src, dst);
Map<ProviderId, LinkDescription> descs = getOrCreateLinkDescriptions(key);
synchronized (descs) {
Link link = links.remove(key);
descs.clear();
if (link != null) {
srcLinks.remove(link.src().deviceId(), key);
dstLinks.remove(link.dst().deviceId(), key);
return new LinkEvent(LINK_REMOVED, link);
}
return null;
}
}
Aggregations