Java Code Examples for org.onosproject.net.link.LinkService#getEgressLinks()

The following examples show how to use org.onosproject.net.link.LinkService#getEgressLinks() . 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: FlowRuleJuniperImpl.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method to find the next hop IP address.
 * The logic is to check if the destination ports have an IP address
 * by checking the logical interface (e.g., for port physical ge-2/0/1,
 * a logical interface may be ge-2/0/1.0
 *
 * @param deviceId the device id of the flow rule to be installed
 * @param port     output port of the flow rule treatment
 * @return optional IPv4 address of a next hop
 */
private Optional<Ip4Address> findIpDst(DeviceId deviceId, Port port) {
    LinkService linkService = this.handler().get(LinkService.class);
    Set<Link> links = linkService.getEgressLinks(new ConnectPoint(deviceId, port.number()));
    DeviceService deviceService = this.handler().get(DeviceService.class);
    //Using only links with adjacency discovered by the LLDP protocol (see LinkDiscoveryJuniperImpl)
    Map<DeviceId, Port> dstPorts = links.stream().filter(l ->
            JuniperUtils.AK_IP.toUpperCase().equals(l.annotations().value(AnnotationKeys.LAYER)))
            .collect(Collectors.toMap(
                    l -> l.dst().deviceId(),
                    l -> deviceService.getPort(l.dst().deviceId(), l.dst().port())));
    for (Map.Entry<DeviceId, Port> entry : dstPorts.entrySet()) {
        String portName = entry.getValue().annotations().value(AnnotationKeys.PORT_NAME);

        Optional<Port> childPort = deviceService.getPorts(entry.getKey()).stream()
                .filter(p -> Strings.nullToEmpty(
                        p.annotations().value(AnnotationKeys.PORT_NAME)).contains(portName.trim()))
                .filter(this::isIp)
                .findAny();
        if (childPort.isPresent()) {
            return Optional.ofNullable(Ip4Address.valueOf(childPort.get().annotations().value(JuniperUtils.AK_IP)));
        }
    }

    return Optional.empty();
}
 
Example 2
Source File: LinksWebResource.java    From onos with Apache License 2.0 5 votes vote down vote up
private Iterable<Link> getConnectPointLinks(ConnectPoint point,
                                            String direction,
                                            LinkService service) {
    Direction dir = direction != null ?
            Direction.valueOf(direction.toUpperCase()) : Direction.ALL;
    switch (dir) {
        case INGRESS:
            return service.getIngressLinks(point);
        case EGRESS:
            return service.getEgressLinks(point);
        default:
            return service.getLinks(point);
    }
}
 
Example 3
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 4
Source File: VirtualNetworkLinkManagerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests querying for egress links using a null connect point.
 */
@Test(expected = NullPointerException.class)
public void testGetEgressLinksByNullId() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    LinkService linkService = manager.get(virtualNetwork.id(), LinkService.class);

    // test the getEgressLinks() method with a null connect point.
    linkService.getEgressLinks(null);
}
 
Example 5
Source File: OFSwitchManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public ConnectPoint neighbour(NetworkId networkId, DeviceId deviceId, PortNumber portNumber) {
    ConnectPoint cp = new ConnectPoint(deviceId, portNumber);
    LinkService linkService = virtualNetService.get(networkId, LinkService.class);
    Set<Link> links = linkService.getEgressLinks(cp);
    log.trace("neighbour cp {} egressLinks {}", cp, links);
    if (links != null && links.size() > 0) {
        Link link = links.iterator().next();
        return link.src();
    }
    return null;
}