Search in sources :

Example 11 with LinkEvent

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)));
}
Also used : LinkEvent(org.onosproject.net.link.LinkEvent) ConnectPoint(org.onosproject.net.ConnectPoint) Test(org.junit.Test)

Example 12 with LinkEvent

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);
}
Also used : LinkEvent(org.onosproject.net.link.LinkEvent) ConnectPoint(org.onosproject.net.ConnectPoint) Test(org.junit.Test)

Example 13 with LinkEvent

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));
        }
    }
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) LinkEvent(org.onosproject.net.link.LinkEvent) Device(org.onosproject.net.Device) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 14 with LinkEvent

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);
        }
    }
}
Also used : LinkEvent(org.onosproject.net.link.LinkEvent) Link(org.onosproject.net.Link)

Example 15 with LinkEvent

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;
    }
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) LinkKey(org.onosproject.net.LinkKey) LinkEvent(org.onosproject.net.link.LinkEvent) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink)

Aggregations

LinkEvent (org.onosproject.net.link.LinkEvent)25 Test (org.junit.Test)16 Link (org.onosproject.net.Link)13 ConnectPoint (org.onosproject.net.ConnectPoint)10 DefaultLink (org.onosproject.net.DefaultLink)6 TopologyEvent (org.onosproject.net.topology.TopologyEvent)6 DeviceEvent (org.onosproject.net.device.DeviceEvent)5 DefaultLinkDescription (org.onosproject.net.link.DefaultLinkDescription)5 LinkKey (org.onosproject.net.LinkKey)4 AbstractEventTest (org.onosproject.event.AbstractEventTest)3 Event (org.onosproject.event.Event)3 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)3 ClusterEvent (org.onosproject.cluster.ClusterEvent)2 MastershipEvent (org.onosproject.mastership.MastershipEvent)2 HostEvent (org.onosproject.net.host.HostEvent)2 IntentEvent (org.onosproject.net.intent.IntentEvent)2 Topology (org.onosproject.net.topology.Topology)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1