Search in sources :

Example 21 with LinkDescription

use of org.onosproject.net.link.LinkDescription in project onos by opennetworkinglab.

the class TopologyMutationDriver method severLink.

// Picks a random active link and severs it.
private LinkDescription severLink() {
    LinkDescription link = getRandomLink(activeLinks);
    linkProviderService.linkVanished(link);
    linkProviderService.linkVanished(reverse(link));
    return link;
}
Also used : DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription)

Example 22 with LinkDescription

use of org.onosproject.net.link.LinkDescription in project onos by opennetworkinglab.

the class TopologyMutationDriver method repairLink.

/**
 * Repairs the link between the specified end-points in both directions.
 *
 * @param one link endpoint
 * @param two link endpoint
 */
void repairLink(ConnectPoint one, ConnectPoint two) {
    LinkDescription link = new DefaultLinkDescription(one, two, DIRECT);
    linkProviderService.linkDetected(link);
    linkProviderService.linkDetected(reverse(link));
}
Also used : DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription)

Example 23 with LinkDescription

use of org.onosproject.net.link.LinkDescription in project onos by opennetworkinglab.

the class LinkDiscoveryAristaImpl method createLinksDescs.

private Set<LinkDescription> createLinksDescs(Optional<JsonNode> response) {
    DriverHandler handler = checkNotNull(handler());
    DeviceId localDeviceId = checkNotNull(handler.data().deviceId());
    DeviceService deviceService = handler.get(DeviceService.class);
    Set<LinkDescription> linkDescriptions = Sets.newHashSet();
    List<Port> ports = deviceService.getPorts(localDeviceId);
    if (ports.isEmpty() || Objects.isNull(response)) {
        return linkDescriptions;
    }
    if (!response.isPresent()) {
        return linkDescriptions;
    }
    log.debug("response: {}, {}", response, localDeviceId.toString());
    JsonNode res = response.get();
    if (res == null) {
        log.warn("result is null");
        return linkDescriptions;
    }
    JsonNode lldpNeighbors = res.findValue(LLDP_NEIGHBORS);
    if (lldpNeighbors == null) {
        log.warn("{} is null", LLDP_NEIGHBORS);
        return linkDescriptions;
    }
    Iterator<Map.Entry<String, JsonNode>> lldpNeighborsIter = lldpNeighbors.fields();
    while (lldpNeighborsIter.hasNext()) {
        Map.Entry<String, JsonNode> neighbor = lldpNeighborsIter.next();
        String lldpLocalPort = neighbor.getKey();
        JsonNode neighborValue = neighbor.getValue();
        log.debug("lldpLocalPort: {}", lldpLocalPort);
        log.debug("neighborValue: {}", neighborValue.toString());
        if (lldpLocalPort.isEmpty()) {
            continue;
        }
        JsonNode neighborInfo = neighborValue.findValue(LLDP_NEIGHBOR_INFO);
        if (neighborInfo == null) {
            log.warn("{} is null", LLDP_NEIGHBOR_INFO);
            continue;
        }
        Iterator<JsonNode> neighborInfoIter = neighborInfo.elements();
        while (neighborInfoIter.hasNext()) {
            JsonNode info = neighborInfoIter.next();
            String chassisIdType = info.get(CHASSIS_ID_TYPE).asText("");
            if (chassisIdType == null) {
                log.warn("{} is null", CHASSIS_ID_TYPE);
                continue;
            }
            if (!chassisIdType.equals(CHASSIS_ID_TYPE_MAC)) {
                log.warn("{} is not mac: {}", CHASSIS_ID_TYPE_MAC, chassisIdType);
                continue;
            }
            JsonNode remotePortNameNode = info.findValue(PORT_ID);
            if (remotePortNameNode == null) {
                continue;
            }
            String remoteChassisId = info.get(CHASSIS_ID).asText("");
            String remotePortName = remotePortNameNode.asText("");
            log.debug("{}: {}, {}: {}", CHASSIS_ID, remoteChassisId, PORT_ID, remotePortName);
            Optional<Port> localPort = findLocalPortByName(ports, lldpLocalPort);
            if (!localPort.isPresent()) {
                log.warn("local port not found. lldpLocalPort value: {}", lldpLocalPort);
                continue;
            }
            Optional<Device> remoteDevice = findRemoteDeviceByChassisId(deviceService, remoteChassisId);
            if (!remoteDevice.isPresent()) {
                log.warn("remote device not found. remoteChassisId value: {}", remoteChassisId);
                continue;
            }
            Optional<Port> remotePort = findDestinationPortByName(remotePortName, deviceService, remoteDevice.get());
            if (!remotePort.isPresent()) {
                log.warn("remote port not found. remotePortName value: {}", remotePortName);
                continue;
            }
            if (!localPort.get().isEnabled() || !remotePort.get().isEnabled()) {
                log.debug("Ports are disabled. Cannot create a link between {}/{} and {}/{}", localDeviceId, localPort.get(), remoteDevice.get().id(), remotePort.get());
                continue;
            }
            linkDescriptions.addAll(buildLinkPair(localDeviceId, localPort.get(), remoteDevice.get().id(), remotePort.get()));
        }
    }
    log.debug("returning linkDescriptions: {}", linkDescriptions);
    return linkDescriptions;
}
Also used : DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) DeviceService(org.onosproject.net.device.DeviceService) JsonNode(com.fasterxml.jackson.databind.JsonNode) DriverHandler(org.onosproject.net.driver.DriverHandler) Map(java.util.Map)

Example 24 with LinkDescription

use of org.onosproject.net.link.LinkDescription in project onos by opennetworkinglab.

the class DeviceDiscoveryTest method getLinksTest.

@Test
public void getLinksTest() {
    Ciena5162DeviceDescription targetUnderTest1 = new Ciena5162DeviceDescription();
    Ciena5162DeviceDescription targetUnderTest2 = new Ciena5162DeviceDescription();
    Ciena5162DeviceDescription.TEMPLATE_MANAGER.setRequestDriver(mockRequestDriver);
    DeviceId mId = DeviceId.deviceId("netconf:1.2.3.4:830");
    targetUnderTest1.setHandler(mockDriverHandlers.get(mId));
    deviceService.addDevice(new MockDevice(mId, targetUnderTest1.discoverDeviceDetails()));
    mId = DeviceId.deviceId("netconf:5.6.7.8:830");
    targetUnderTest2.setHandler(mockDriverHandlers.get(mId));
    deviceService.addDevice(new MockDevice(mId, targetUnderTest2.discoverDeviceDetails()));
    Set<LinkDescription> links1 = targetUnderTest1.getLinks();
    Set<LinkDescription> links2 = targetUnderTest2.getLinks();
    assertEquals("A to B link count", 1, links1.size());
    assertEquals("B to A link count", 1, links2.size());
    LinkDescription a2b = links1.toArray(new LinkDescription[0])[0];
    LinkDescription b2a = links2.toArray(new LinkDescription[0])[0];
    assertEquals("A to B src and dest", a2b.src(), b2a.dst());
    assertEquals("B to A src and dest", b2a.src(), a2b.dst());
}
Also used : MockDevice(org.onosproject.drivers.netconf.MockDevice) LinkDescription(org.onosproject.net.link.LinkDescription) DeviceId(org.onosproject.net.DeviceId) Test(org.junit.Test)

Example 25 with LinkDescription

use of org.onosproject.net.link.LinkDescription in project onos by opennetworkinglab.

the class ECLinkStore method injectLink.

private LinkEvent injectLink(Provided<LinkDescription> linkInjectRequest) {
    log.trace("Received request to inject link {}", linkInjectRequest);
    ProviderId providerId = linkInjectRequest.providerId();
    LinkDescription linkDescription = linkInjectRequest.key();
    final DeviceId deviceId = linkDescription.dst().deviceId();
    if (!deviceClockService.isTimestampAvailable(deviceId)) {
        // workaround for ONOS-1208
        log.warn("Not ready to accept update. Dropping {}", linkInjectRequest);
        return null;
    }
    return createOrUpdateLink(providerId, linkDescription);
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) DeviceId(org.onosproject.net.DeviceId)

Aggregations

LinkDescription (org.onosproject.net.link.LinkDescription)29 DefaultLinkDescription (org.onosproject.net.link.DefaultLinkDescription)24 DeviceId (org.onosproject.net.DeviceId)17 ConnectPoint (org.onosproject.net.ConnectPoint)11 Device (org.onosproject.net.Device)9 DeviceService (org.onosproject.net.device.DeviceService)9 ProviderId (org.onosproject.net.provider.ProviderId)7 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)6 Type (org.onosproject.net.Link.Type)6 LinkKey (org.onosproject.net.LinkKey)6 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 Port (org.onosproject.net.Port)5 NetconfController (org.onosproject.netconf.NetconfController)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Set (java.util.Set)3 NetconfException (org.onosproject.netconf.NetconfException)3 NetconfSession (org.onosproject.netconf.NetconfSession)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2