Java Code Examples for org.onosproject.net.Link#type()

The following examples show how to use org.onosproject.net.Link#type() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OplinkSwitchProtection.java    From onos with Apache License 2.0 5 votes vote down vote up
private DeviceId getPeerId() {
    ConnectPoint dstCp = new ConnectPoint(data().deviceId(), PortNumber.portNumber(VIRTUAL_PORT));
    Set<Link> links = handler().get(LinkService.class).getIngressLinks(dstCp);

    for (Link l : links) {
        if (l.type() == Link.Type.VIRTUAL) {
            // this device is the destination and peer is the source.
            return l.src().deviceId();
        }
    }

    return data().deviceId();
}
 
Example 2
Source File: OplinkOpticalProtectionSwitchConfig.java    From onos with Apache License 2.0 5 votes vote down vote up
private DeviceId getPeerId() {
    ConnectPoint dstCp = new ConnectPoint(data().deviceId(), PORT_VIRTUAL);
    Set<Link> links = handler().get(LinkService.class).getIngressLinks(dstCp);
    for (Link l : links) {
        if (l.type() == Link.Type.VIRTUAL) {
            // This device is the destination and peer is the source.
            return l.src().deviceId();
        }
    }
    // None of link found, return itself.
    return data().deviceId();
}
 
Example 3
Source File: AnnotateLinkCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
private LinkDescription description(Link link, String key, String value) {
    checkNotNull(key, "Key cannot be null");
    DefaultAnnotations.Builder builder = DefaultAnnotations.builder();
    if (value != null) {
        builder.set(key, value);
    } else {
        builder.remove(key);
    }
    return new DefaultLinkDescription(link.src(),
                                      link.dst(),
                                      link.type(),
                                      link.isExpected(),
                                      builder.build());
}
 
Example 4
Source File: OpticalPathProvisioner.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies if given link forms a cross-connection between packet and optical layer.
 *
 * @param link the link
 * @return true if the link is a cross-connect link, false otherwise
 */
private boolean isCrossConnectLink(Link link) {
    if (link.type() != Link.Type.OPTICAL) {
        return false;
    }

    Device.Type src = deviceService.getDevice(link.src().deviceId()).type();
    Device.Type dst = deviceService.getDevice(link.dst().deviceId()).type();

    return src != dst &&
            ((isPacketLayer(src) && isTransportLayer(dst)) || (isPacketLayer(dst) && isTransportLayer(src)));
}
 
Example 5
Source File: DefaultGroupHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
private void populateNeighborMaps() {
    Set<Link> outgoingLinks = linkService.getDeviceEgressLinks(deviceId);
    for (Link link : outgoingLinks) {
        if (link.type() != Link.Type.DIRECT) {
            continue;
        }
        addNeighborAtPort(link.dst().deviceId(), link.src().port());
    }
}
 
Example 6
Source File: LatencyConstraint.java    From onos with Apache License 2.0 5 votes vote down vote up
private double cost(Link link) {
    //Check only links, not EdgeLinks
    if (link.type() != Link.Type.EDGE) {
        return link.annotations().value(LATENCY) != null ? getAnnotatedValue(link, LATENCY) : 0;
    } else {
        return 0;
    }
}
 
Example 7
Source File: BasicLinkOperator.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Generates a link description from a link description entity. The endpoints
 * must be specified to indicate directionality.
 *
 * @param src the source ConnectPoint
 * @param dst the destination ConnectPoint
 * @param link the link config entity
 * @return a linkDescription based on the config
 */
public static LinkDescription descriptionOf(
            ConnectPoint src, ConnectPoint dst, Link link) {
    checkNotNull(src, "Must supply a source endpoint");
    checkNotNull(dst, "Must supply a destination endpoint");
    checkNotNull(link, "Must supply a link");
    return new DefaultLinkDescription(
            src, dst, link.type(),
            link.isExpected(),
            (SparseAnnotations) link.annotations());
}
 
Example 8
Source File: FlowRuleIntentInstaller.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Create a list of devices ordered from the ingress to the egress of a path.
 * @param resources the resources of the intent
 * @return a list of devices
 */
private List<DeviceId> createIngressToEgressDeviceList(Collection<NetworkResource> resources) {
    List<DeviceId> deviceIds = Lists.newArrayList();
    List<Link> links = Lists.newArrayList();

    for (NetworkResource resource : resources) {
        if (resource instanceof Link) {
            Link linkToAdd = (Link) resource;
            if (linkToAdd.type() != Link.Type.EDGE) {
                links.add(linkToAdd);
            }
        }
    }

    Collections.sort(links, LINK_COMPARATOR);

    int i = 0;
    for (Link orderedLink : links) {
        deviceIds.add(orderedLink.src().deviceId());
        if (i == resources.size() - 1) {
            deviceIds.add(orderedLink.dst().deviceId());
        }
        i++;
    }

    return deviceIds;
}
 
Example 9
Source File: SimpleLinkStore.java    From onos with Apache License 2.0 5 votes vote down vote up
private LinkEvent updateLink(LinkKey key, Link oldLink, Link newLink) {
    if (oldLink.state() != newLink.state() ||
            (oldLink.type() == INDIRECT && newLink.type() == DIRECT) ||
            !AnnotationsUtil.isEqual(oldLink.annotations(), newLink.annotations())) {

        links.put(key, newLink);
        // strictly speaking following can be omitted
        srcLinks.put(oldLink.src().deviceId(), key);
        dstLinks.put(oldLink.dst().deviceId(), key);
        return new LinkEvent(LINK_UPDATED, newLink);
    }
    return null;
}
 
Example 10
Source File: ECLinkStore.java    From onos with Apache License 2.0 5 votes vote down vote up
private LinkEvent updateLink(LinkKey key, Link oldLink, Link newLink) {
    // Note: INDIRECT -> DIRECT transition only
    // so that BDDP discovered Link will not overwrite LDDP Link
    if (oldLink.state() != newLink.state() ||
            (oldLink.type() == INDIRECT && newLink.type() == DIRECT) ||
            !AnnotationsUtil.isEqual(oldLink.annotations(), newLink.annotations())) {

        links.put(key, newLink);
        return new LinkEvent(LINK_UPDATED, newLink);
    }
    return null;
}
 
Example 11
Source File: LinkHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Checks validity of link. Examples of invalid links include
 * indirect-links, links between ports on the same switch, and more.
 *
 * @param link the link to be processed
 * @return true if valid link
 */
 boolean isLinkValid(Link link) {
    if (link.type() != Link.Type.DIRECT) {
        // NOTE: A DIRECT link might be transiently marked as INDIRECT
        // if BDDP is received before LLDP. We can safely ignore that
        // until the LLDP is received and the link is marked as DIRECT.
        log.info("Ignore link {}->{}. Link type is {} instead of DIRECT.",
                 link.src(), link.dst(), link.type());
        return false;
    }
    DeviceId srcId = link.src().deviceId();
    DeviceId dstId = link.dst().deviceId();
    if (srcId.equals(dstId)) {
        log.warn("Links between ports on the same switch are not "
                + "allowed .. ignoring link {}", link);
        return false;
    }
    DeviceConfiguration devConfig = srManager.deviceConfiguration;
    if (devConfig == null) {
        log.warn("Cannot check validity of link without device config");
        return true;
    }
    try {
        /*if (!devConfig.isEdgeDevice(srcId)
                && !devConfig.isEdgeDevice(dstId)) {
            // ignore links between spines
            // XXX revisit when handling multi-stage fabrics
            log.warn("Links between spines not allowed...ignoring "
                    + "link {}", link);
            return false;
        }*/
        if (devConfig.isEdgeDevice(srcId)
                && devConfig.isEdgeDevice(dstId)) {
            // ignore links between leaves if they are not pair-links
            // XXX revisit if removing pair-link config or allowing more than
            // one pair-link
            if (devConfig.getPairDeviceId(srcId).equals(dstId)
                    && devConfig.getPairLocalPort(srcId)
                            .equals(link.src().port())
                    && devConfig.getPairLocalPort(dstId)
                            .equals(link.dst().port())) {
                // found pair link - allow it
                return true;
            } else {
                log.warn("Links between leaves other than pair-links are "
                        + "not allowed...ignoring link {}", link);
                return false;
            }
        }
    } catch (DeviceConfigNotFoundException e) {
        // We still want to count the links in seenLinks even though there
        // is no config. So we let it return true
        log.warn("Could not check validity of link {} as subtending devices "
                + "are not yet configured", link);
    }
    return true;
}
 
Example 12
Source File: TopologySimulator.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Produces a link description from the given link.
 *
 * @param link link to copy
 * @return link description
 */
static DefaultLinkDescription description(Link link) {
    return new DefaultLinkDescription(link.src(), link.dst(), link.type());
}