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

The following examples show how to use org.onosproject.net.Link#dst() . 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: DeviceViewMessageHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
private ObjectNode portData(Port p, DeviceId id) {
    ObjectNode port = objectNode();
    LinkService ls = get(LinkService.class);
    String name = p.annotations().value(AnnotationKeys.PORT_NAME);

    port.put(ID, capitalizeFully(p.number().toString()));
    port.put(TYPE, capitalizeFully(p.type().toString()));
    port.put(SPEED, p.portSpeed());
    port.put(ENABLED, p.isEnabled());
    port.put(NAME, name != null ? name : "");

    ConnectPoint connectPoint = new ConnectPoint(id, p.number());
    Set<Link> links = ls.getEgressLinks(connectPoint);
    if (!links.isEmpty()) {
        StringBuilder egressLinks = new StringBuilder();
        for (Link l : links) {
            ConnectPoint dest = l.dst();
            egressLinks.append(dest.elementId()).append("/")
                    .append(dest.port()).append(" ");
        }
        port.put(LINK_DEST, egressLinks.toString());
    } else {
        HostService hs = get(HostService.class);
        Set<Host> hosts = hs.getConnectedHosts(connectPoint);
        if (hosts != null && !hosts.isEmpty()) {
            port.put(LINK_DEST, hosts.iterator().next().id().toString());
        }
    }

    return port;
}
 
Example 2
Source File: BasicPceccHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
private LinkedList<PcepValueType> createEroSubObj(Path path) {
    LinkedList<PcepValueType> subObjects = new LinkedList<>();
    List<Link> links = path.links();
    ConnectPoint source = null;
    ConnectPoint destination = null;
    IpAddress ipDstAddress = null;
    IpAddress ipSrcAddress = null;
    PcepValueType subObj = null;
    long portNo;

    for (Link link : links) {
        source = link.src();
        if (!(source.equals(destination))) {
            //set IPv4SubObject for ERO object
            portNo = source.port().toLong();
            portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo;
            ipSrcAddress = Ip4Address.valueOf((int) portNo);
            subObj = new IPv4SubObject(ipSrcAddress.getIp4Address().toInt());
            subObjects.add(subObj);
        }

        destination = link.dst();
        portNo = destination.port().toLong();
        portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo;
        ipDstAddress = Ip4Address.valueOf((int) portNo);
        subObj = new IPv4SubObject(ipDstAddress.getIp4Address().toInt());
        subObjects.add(subObj);
    }
    return subObjects;
}
 
Example 3
Source File: PcepTunnelProvider.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates list of hops for ERO object from Path.
 *
 * @param path network path
 * @return list of ERO subobjects
 */
private LinkedList<PcepValueType> createPcepPath(Path path) {
    LinkedList<PcepValueType> llSubObjects = new LinkedList<>();
    List<Link> listLink = path.links();
    ConnectPoint source = null;
    ConnectPoint destination = null;
    IpAddress ipDstAddress = null;
    IpAddress ipSrcAddress = null;
    PcepValueType subObj = null;
    long portNo;

    for (Link link : listLink) {
        source = link.src();
        if (!(source.equals(destination))) {
            //set IPv4SubObject for ERO object
            portNo = source.port().toLong();
            portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo;
            ipSrcAddress = Ip4Address.valueOf((int) portNo);
            subObj = new IPv4SubObject(ipSrcAddress.getIp4Address().toInt());
            llSubObjects.add(subObj);
        }

        destination = link.dst();
        portNo = destination.port().toLong();
        portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo;
        ipDstAddress = Ip4Address.valueOf((int) portNo);
        subObj = new IPv4SubObject(ipDstAddress.getIp4Address().toInt());
        llSubObjects.add(subObj);
    }

    return llSubObjects;
}
 
Example 4
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 5
Source File: HostToHostIntentCompiler.java    From onos with Apache License 2.0 5 votes vote down vote up
private FilteredConnectPoint getFilteredPointFromLink(Link link) {
    FilteredConnectPoint filteredConnectPoint;
    if (link.src().elementId() instanceof DeviceId) {
        filteredConnectPoint = new FilteredConnectPoint(link.src());
    } else if (link.dst().elementId() instanceof DeviceId) {
        filteredConnectPoint = new FilteredConnectPoint(link.dst());
    } else {
        throw new IntentCompilationException(DEVICE_ID_NOT_FOUND);
    }
    return filteredConnectPoint;
}
 
Example 6
Source File: OpticalPathProvisioner.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public OpticalConnectivityId setupPath(Path path, Bandwidth bandwidth, Duration latency) {
    checkNotNull(path);
    log.debug("setupPath({}, {}, {})", path, bandwidth, latency);

    // map of cross connect points (optical port -> packet port)
    Map<ConnectPoint, ConnectPoint> crossConnectPointMap = new HashMap<>();

    // list of (src, dst) pair of optical ports between which optical path should be installed
    List<Pair<ConnectPoint, ConnectPoint>> crossConnectPoints = new ArrayList<>();

    // Scan path to find pairs of connect points between which optical intent is installed
    // opticalSrcPort works as a flag parameter to show scanning status
    ConnectPoint opticalSrcPort = null;
    for (Link link : path.links()) {
        if (!isCrossConnectLink(link)) {
            continue;
        }

        if (opticalSrcPort != null) {
            // opticalSrcPort!=null means src port was already found
            // in this case link.src() is optical layer, and link.dst() is packet layer

            // Check if types of src port and dst port matches
            Device srcDevice = checkNotNull(deviceService.getDevice(opticalSrcPort.deviceId()),
                    "Unknown device ID");
            Device dstDevice = checkNotNull(deviceService.getDevice(link.src().deviceId()),
                    "Unknown device ID");
            if (srcDevice.type() != dstDevice.type()) {
                log.error("Unsupported mix of cross connect points : {}, {}",
                        srcDevice.type(), dstDevice.type());
                return null;
            }

            // Update cross connect points map
            crossConnectPointMap.put(link.src(), link.dst());

            // Add optical ports pair to list
            crossConnectPoints.add(Pair.of(opticalSrcPort, link.src()));

            // Reset flag parameter
            opticalSrcPort = null;
        } else {
            // opticalSrcPort==null means src port was not found yet
            // in this case link.src() is packet layer, and link.dst() is optical layer

            // Update cross connect points map
            crossConnectPointMap.put(link.dst(), link.src());
            // Set opticalSrcPort to src of link (optical port)
            opticalSrcPort = link.dst();
        }
    }

    // create intents from cross connect points
    List<Intent> intents = createIntents(crossConnectPoints);
    if (intents.isEmpty()) {
        log.error("No intents produced from {}", crossConnectPoints);
        return null;
    }

    // create set of PacketLinkRealizedByOptical
    Set<PacketLinkRealizedByOptical> packetLinks = createPacketLinkSet(crossConnectPoints,
            intents, crossConnectPointMap);

    // create OpticalConnectivity object and store information to distributed store
    OpticalConnectivity connectivity = createConnectivity(path, bandwidth, latency, packetLinks);

    // store cross connect port usage
    path.links().stream().filter(this::isCrossConnectLink)
            .forEach(usedCrossConnectLinkSet::add);

    // Submit the intents
    for (Intent i : intents) {
        intentService.submit(i);
        log.debug("Submitted an intent: {}", i);
    }

    return connectivity.id();
}
 
Example 7
Source File: PceWebTopovMessageHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Handles the event of topology listeners.
 */
private void findTunnelAndHighlights() {
    Collection<Tunnel> tunnelSet = null;
    Highlights highlights = new Highlights();
    paths.clear();
    tunnelSet = tunnelService.queryTunnel(MPLS);
    if (tunnelSet.size() == 0) {
        log.warn("Tunnel does not exist");
        sendMessage(highlightsMessage(highlights));
        return;
    }

    for (Tunnel tunnel : tunnelSet) {
        if (tunnel.path() == null) {
            log.error("path does not exist");
            sendMessage(highlightsMessage(highlights));
            return;
        }
        if (!tunnel.state().equals(ACTIVE)) {
            log.debug("Tunnel state is not active");
            sendMessage(highlightsMessage(highlights));
            return;
        }
        Link firstLink = tunnel.path().links().get(0);
        if (firstLink != null) {
            if (firstLink.src() != null) {
                highlights = addBadge(highlights, firstLink.src().deviceId().toString(), SRC);
            }
        }
        Link lastLink = tunnel.path().links().get(tunnel.path().links().size() - 1);
        if (lastLink != null) {
            if (lastLink.dst() != null) {
                highlights = addBadge(highlights, lastLink.dst().deviceId().toString(), DST);
            }
        }
        paths.add(tunnel.path());
    }

    ImmutableSet.Builder<Link> builder = ImmutableSet.builder();
    allPathLinks = buildPaths(builder).build();
    hilightAndSendPaths(highlights);
}
 
Example 8
Source File: PceWebTopovMessageHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Handles the event of topology listeners.
 */
private void highlightsForTunnel(List<Tunnel> tunnels) {
    Highlights highlights = new Highlights();
    paths.clear();

    if (tunnels.isEmpty()) {
        log.error("path does not exist");
        sendMessage(TopoJson.highlightsMessage(highlights));
        return;
    }
    for (Tunnel tunnel : tunnels) {
    if (tunnel.path() == null) {
        log.error("path does not exist");
        sendMessage(highlightsMessage(highlights));
        return;
    }
    if (!tunnel.state().equals(ACTIVE)) {
        log.debug("Tunnel state is not active");
        sendMessage(highlightsMessage(highlights));
        return;
    }

    Link firstLink = tunnel.path().links().get(0);
    if (firstLink != null) {
        if (firstLink.src() != null) {
            highlights = addBadge(highlights, firstLink.src().deviceId().toString(), SRC);
        }
    }
    Link lastLink = tunnel.path().links().get(tunnel.path().links().size() - 1);
    if (lastLink != null) {
        if (lastLink.dst() != null) {
            highlights = addBadge(highlights, lastLink.dst().deviceId().toString(), DST);
        }
    }
    paths.add(tunnel.path());
    }

    ImmutableSet.Builder<Link> builder = ImmutableSet.builder();
    allPathLinks = buildPaths(builder).build();
    hilightAndSendPaths(highlights);
}
 
Example 9
Source File: DefaultCheckLoop.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Process one output instruction.
 *
 * Params are passed from processOneInstruction directly,
 * and obey the same rules.
 *
 * @param instOne the instruction to be processed
 * @param currentDeviceId id of the device we are now in
 * @param initPkt the packet before being copied
 * @param matchedPkt the packet which matched the flow entry,
 *                   to which this instruction belongs
 * @param isFindLoop indicate if it is invoked by findLoop method
 * @param firstEntry the flow entry from which the packet is generated
 * @return true, if a loop is discovered;
 *         false, 1. invoked by matchDeviceFlows method, and detected no loop;
 *                2. invoked by findLoop method
 */
private boolean processOneOutputInstruction(Instruction instOne,
                                            DeviceId currentDeviceId,
                                            TsLoopPacket initPkt,
                                            TsLoopPacket matchedPkt,
                                            boolean isFindLoop,
                                            FlowEntry firstEntry) {
    OutputInstruction instOutput = (OutputInstruction) instOne;
    PortNumber instPort = instOutput.port();

    if (!instPort.isLogical()) {
        // single OUTPUT - NIC or normal port

        Set<Link> dstLink = tsGetEgressLinks(
                new ConnectPoint(currentDeviceId, instPort));
        if (!dstLink.isEmpty()) {

            // TODO - now, just deal with the first destination.
            // will there be more destinations?

            Link dstThisLink = dstLink.iterator().next();
            ConnectPoint dstPoint = dstThisLink.dst();

            // check output to devices only (output to a host is normal)
            if (isDevice(dstPoint)) {
                PortCriterion oldInPort =
                        updatePktInportPerHop(matchedPkt, dstPoint);
                matchedPkt.pushPathLink(dstThisLink);
                TsLoopPacket newNewPkt = matchedPkt.copyPacketMatch();

                boolean loopFound =
                        matchDeviceFlows(dstPoint.deviceId(), newNewPkt);
                if (isFindLoop) {
                    if (loopFound) {
                        loops.add(newNewPkt);
                        updateExcludeDeviceSet(newNewPkt);
                    }
                    matchedPkt.resetLinkFlow(firstEntry);
                } else {
                    if (loopFound) {
                        initPkt.handInLoopMatch(newNewPkt);
                        return true;
                    }
                    matchedPkt.popPathLink();
                }
                restorePktInportPerHop(matchedPkt, oldInPort);
            }
        } else {
            if (!isFindLoop) {
                //TODO - NEED
                log.warn("no link connecting at device {}, port {}",
                        currentDeviceId, instPort);
            }
        }
    } else if (instPort.equals(PortNumber.IN_PORT)) {
        //TODO - in the future,
        // we may need to resolve this condition 1
        log.warn("can not handle {} port now.", PortNumber.IN_PORT);
    } else if (instPort.equals(PortNumber.NORMAL) ||
            instPort.equals(PortNumber.FLOOD) ||
            instPort.equals(PortNumber.ALL)) {
        //TODO - in the future,
        // we may need to resolve this condition 2
        log.warn("can not handle {}/{}/{} now.",
                PortNumber.NORMAL, PortNumber.FLOOD, PortNumber.ALL);
    }
    return false;
}
 
Example 10
Source File: LinkCollectionCompiler.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Creates the domain intents that the {@link LinkCollectionIntent} contains.
 *
 * @param intent        the link collection intent
 * @param domainService the domain service
 * @return the resulting list of domain intents
 */
protected List<Intent> getDomainIntents(LinkCollectionIntent intent,
                                        DomainService domainService) {
    ImmutableList.Builder<Intent> intentList = ImmutableList.builder();
    // domain handling is only applied for a single entry and exit point
    // TODO: support multi point to multi point
    if (intent.filteredIngressPoints().size() != 1 || intent
            .filteredEgressPoints().size() != 1) {
        log.warn("Multiple ingress or egress ports not supported!");
        return intentList.build();
    }
    ImmutableList.Builder<Link> domainLinks = ImmutableList.builder();
    // get the initial ingress connection point
    FilteredConnectPoint ingress =
            intent.filteredIngressPoints().iterator().next();
    FilteredConnectPoint egress;
    DeviceId currentDevice = ingress.connectPoint().deviceId();
    // the current domain (or LOCAL)
    DomainId currentDomain = domainService.getDomain(currentDevice);
    // if we entered a domain store the domain ingress
    FilteredConnectPoint domainIngress =
            LOCAL.equals(currentDomain) ? null : ingress;
    // loop until (hopefully) all links have been checked once
    // this is necessary because a set is not sorted by default
    for (int i = 0; i < intent.links().size(); i++) {
        // find the next link
        List<Link> nextLinks =
                getEgressLinks(intent.links(), currentDevice);
        // no matching link exists
        if (nextLinks.isEmpty()) {
            throw new IntentCompilationException(
                    "No matching link starting at " + ingress
                            .connectPoint().deviceId());
        }
        // get the first link
        Link nextLink = nextLinks.get(0);
        ingress = new FilteredConnectPoint(nextLink.src());
        egress = new FilteredConnectPoint(nextLink.dst());
        // query the domain for the domain of the link's destination
        DomainId dstDomain = domainService
                .getDomain(egress.connectPoint().deviceId());
        if (!currentDomain.equals(dstDomain)) {
            // we are leaving the current domain or LOCAL
            log.debug("Domain transition from {} to {}.", currentDomain,
                      dstDomain);
            if (!LOCAL.equals(currentDomain)) {
                // add the domain intent to the intent list
                intentList.add(createDomainP2PIntent(intent, domainIngress,
                                                     ingress,
                                                     domainLinks.build()));
                // TODO: might end up with an unused builder
                // reset domain links builder
                domainLinks = ImmutableList.builder();
            }
            // update current domain (might be LOCAL)
            currentDomain = dstDomain;
            // update the domain's ingress
            domainIngress = LOCAL.equals(currentDomain) ? null : egress;
        } else {
            if (!LOCAL.equals(currentDomain)) {
                // we are staying in the same domain, store the traversed link
                domainLinks.add(nextLink);
                log.debug("{} belongs to the same domain.",
                          egress.connectPoint().deviceId());
            }
        }
        currentDevice = egress.connectPoint().deviceId();
    }
    // get the egress point
    egress = intent.filteredEgressPoints().iterator().next();
    // still inside a domain?
    if (!LOCAL.equals(currentDomain) &&
            currentDomain.equals(domainService.getDomain(
                    egress.connectPoint().deviceId()))) {
        // add intent
        intentList.add(createDomainP2PIntent(intent, domainIngress, egress,
                                             domainLinks.build()));
    }

    return intentList.build();
}
 
Example 11
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());
}