Search in sources :

Example 36 with IpAddress

use of org.onlab.packet.IpAddress in project onos by opennetworkinglab.

the class IpAddressCompleter method complete.

@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    StringsCompleter delegate = new StringsCompleter();
    OpenstackNetworkService osNetService = get(OpenstackNetworkService.class);
    Set<IpAddress> set = osNetService.externalPeerRouters().stream().map(ExternalPeerRouter::ipAddress).collect(Collectors.toSet());
    SortedSet<String> strings = delegate.getStrings();
    Iterator<IpAddress> it = set.iterator();
    while (it.hasNext()) {
        strings.add(it.next().toString());
    }
    return delegate.complete(session, commandLine, candidates);
}
Also used : OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) IpAddress(org.onlab.packet.IpAddress)

Example 37 with IpAddress

use of org.onlab.packet.IpAddress in project onos by opennetworkinglab.

the class DirectHostManager method handle.

private boolean handle(Ethernet eth) {
    checkNotNull(eth);
    // skip them.
    if (!enabled || (eth.getEtherType() != Ethernet.TYPE_IPV6 && eth.getEtherType() != Ethernet.TYPE_IPV4)) {
        return false;
    }
    // According to the type we set the destIp.
    IpAddress dstIp;
    if (eth.getEtherType() == Ethernet.TYPE_IPV4) {
        IPv4 ip = (IPv4) eth.getPayload();
        dstIp = IpAddress.valueOf(ip.getDestinationAddress());
    } else {
        IPv6 ip = (IPv6) eth.getPayload();
        dstIp = IpAddress.valueOf(INET6, ip.getDestinationAddress());
    }
    // Looking for a candidate output port.
    Interface egressInterface = interfaceService.getMatchingInterface(dstIp);
    if (egressInterface == null) {
        log.info("No egress interface found for {}", dstIp);
        return false;
    }
    // Looking for the destination mac.
    Optional<Host> host = hostService.getHostsByIp(dstIp).stream().filter(h -> h.location().equals(egressInterface.connectPoint())).filter(h -> h.vlan().equals(egressInterface.vlan())).findAny();
    // and we queue the packets waiting for a destination.
    if (host.isPresent()) {
        transformAndSend((IP) eth.getPayload(), eth.getEtherType(), egressInterface, host.get().mac());
    } else {
        hostService.startMonitoringIp(dstIp);
        ipPacketCache.asMap().compute(dstIp, (ip, queue) -> {
            if (queue == null) {
                queue = new ConcurrentLinkedQueue<>();
            }
            queue.add((IP) eth.getPayload());
            return queue;
        });
    }
    return true;
}
Also used : ENABLED(org.onosproject.routing.impl.OsgiPropertyConstants.ENABLED) Tools(org.onlab.util.Tools) Host(org.onosproject.net.Host) Interface(org.onosproject.net.intf.Interface) CoreService(org.onosproject.core.CoreService) ComponentContext(org.osgi.service.component.ComponentContext) LoggerFactory(org.slf4j.LoggerFactory) INET6(org.onlab.packet.IpAddress.Version.INET6) HostListener(org.onosproject.net.host.HostListener) InterfaceService(org.onosproject.net.intf.InterfaceService) HostService(org.onosproject.net.host.HostService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) Ethernet(org.onlab.packet.Ethernet) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) OutboundPacket(org.onosproject.net.packet.OutboundPacket) ApplicationId(org.onosproject.core.ApplicationId) HostEvent(org.onosproject.net.host.HostEvent) Activate(org.osgi.service.component.annotations.Activate) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IpAddress(org.onlab.packet.IpAddress) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) Logger(org.slf4j.Logger) Deactivate(org.osgi.service.component.annotations.Deactivate) ENABLED_DEFAULT(org.onosproject.routing.impl.OsgiPropertyConstants.ENABLED_DEFAULT) VlanId(org.onlab.packet.VlanId) PacketProcessor(org.onosproject.net.packet.PacketProcessor) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) PacketService(org.onosproject.net.packet.PacketService) IPv6(org.onlab.packet.IPv6) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TimeUnit(java.util.concurrent.TimeUnit) EthType(org.onlab.packet.EthType) IPv4(org.onlab.packet.IPv4) IP(org.onlab.packet.IP) PacketContext(org.onosproject.net.packet.PacketContext) Modified(org.osgi.service.component.annotations.Modified) Optional(java.util.Optional) MacAddress(org.onlab.packet.MacAddress) CacheBuilder(com.google.common.cache.CacheBuilder) PacketPriority(org.onosproject.net.packet.PacketPriority) Queue(java.util.Queue) Cache(com.google.common.cache.Cache) Reference(org.osgi.service.component.annotations.Reference) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) IPv6(org.onlab.packet.IPv6) IPv4(org.onlab.packet.IPv4) IpAddress(org.onlab.packet.IpAddress) Host(org.onosproject.net.Host) Interface(org.onosproject.net.intf.Interface)

Example 38 with IpAddress

use of org.onlab.packet.IpAddress in project onos by opennetworkinglab.

the class FpmManager method fpmMessage.

private void fpmMessage(FpmPeer peer, FpmHeader fpmMessage) {
    if (fpmMessage.type() == FpmHeader.FPM_TYPE_KEEPALIVE) {
        return;
    }
    Netlink netlink = fpmMessage.netlink();
    RtNetlink rtNetlink = netlink.rtNetlink();
    if (log.isTraceEnabled()) {
        log.trace("Received FPM message: {}", fpmMessage);
    }
    if (!(rtNetlink.protocol() == RtProtocol.ZEBRA || rtNetlink.protocol() == RtProtocol.UNSPEC)) {
        log.trace("Ignoring non-zebra route");
        return;
    }
    IpAddress dstAddress = null;
    IpAddress gateway = null;
    for (RouteAttribute attribute : rtNetlink.attributes()) {
        if (attribute.type() == RouteAttribute.RTA_DST) {
            RouteAttributeDst raDst = (RouteAttributeDst) attribute;
            dstAddress = raDst.dstAddress();
        } else if (attribute.type() == RouteAttribute.RTA_GATEWAY) {
            RouteAttributeGateway raGateway = (RouteAttributeGateway) attribute;
            gateway = raGateway.gateway();
        }
    }
    if (dstAddress == null) {
        log.error("Dst address missing!");
        return;
    }
    IpPrefix prefix = IpPrefix.valueOf(dstAddress, rtNetlink.dstLength());
    // Ignore routes that we sent.
    if (gateway != null && ((prefix.isIp4() && pdPushNextHopIPv4 != null && pdPushNextHopIPv4.contains(gateway.getIp4Address())) || (prefix.isIp6() && pdPushNextHopIPv6 != null && pdPushNextHopIPv6.contains(gateway.getIp6Address())))) {
        if (routeInDhcpStore(prefix) || routeInRipStore(prefix)) {
            return;
        }
    }
    List<Route> updates = new LinkedList<>();
    List<Route> withdraws = new LinkedList<>();
    Route route;
    switch(netlink.type()) {
        case RTM_NEWROUTE:
            if (gateway == null) {
                // We ignore interface routes with no gateway for now.
                return;
            }
            route = new Route(Route.Source.FPM, prefix, gateway, clusterService.getLocalNode().id());
            Route oldRoute = fpmRoutes.get(peer).put(prefix, route);
            if (oldRoute != null) {
                log.trace("Swapping {} with {}", oldRoute, route);
                withdraws.add(oldRoute);
            }
            updates.add(route);
            break;
        case RTM_DELROUTE:
            Route existing = fpmRoutes.get(peer).remove(prefix);
            if (existing == null) {
                log.warn("Got delete for non-existent prefix");
                return;
            }
            route = new Route(Route.Source.FPM, prefix, existing.nextHop(), clusterService.getLocalNode().id());
            withdraws.add(route);
            break;
        case RTM_GETROUTE:
        default:
            break;
    }
    updateRouteStore(updates, withdraws);
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) Netlink(org.onosproject.routing.fpm.protocol.Netlink) RtNetlink(org.onosproject.routing.fpm.protocol.RtNetlink) RouteAttributeDst(org.onosproject.routing.fpm.protocol.RouteAttributeDst) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) IpAddress(org.onlab.packet.IpAddress) RouteAttributeGateway(org.onosproject.routing.fpm.protocol.RouteAttributeGateway) RouteAttribute(org.onosproject.routing.fpm.protocol.RouteAttribute) RtNetlink(org.onosproject.routing.fpm.protocol.RtNetlink) Route(org.onosproject.routeservice.Route) LinkedList(java.util.LinkedList)

Example 39 with IpAddress

use of org.onlab.packet.IpAddress in project onos by opennetworkinglab.

the class FpmAcceptRoutesInfoCommand method doExecute.

@Override
protected void doExecute() {
    FpmInfoService fpmInfo = get(FpmInfoService.class);
    if (peerAddress != null) {
        IpAddress address = IpAddress.valueOf(peerAddress);
        fpmInfo.peers().entrySet().stream().filter(peer -> peer.getKey().address().equals(address)).map(Map.Entry::getValue).forEach(this::print);
    } else {
        fpmInfo.peers().entrySet().stream().sorted(Comparator.<Map.Entry<FpmPeer, FpmPeerInfo>, IpAddress>comparing(e -> e.getKey().address()).thenComparing(e -> e.getKey().port())).map(Map.Entry::getValue).forEach(this::print);
    }
}
Also used : FpmInfoService(org.onosproject.routing.fpm.FpmInfoService) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) FpmPeer(org.onosproject.routing.fpm.FpmPeer) FpmInfoService(org.onosproject.routing.fpm.FpmInfoService) FpmPeerInfo(org.onosproject.routing.fpm.FpmPeerInfo) Map(java.util.Map) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Argument(org.apache.karaf.shell.api.action.Argument) Comparator(java.util.Comparator) Command(org.apache.karaf.shell.api.action.Command) IpAddress(org.onlab.packet.IpAddress) IpAddress(org.onlab.packet.IpAddress) Map(java.util.Map)

Example 40 with IpAddress

use of org.onlab.packet.IpAddress in project onos by opennetworkinglab.

the class FpmConnectionsList method doExecute.

@Override
protected void doExecute() {
    FpmInfoService fpmInfo = get(FpmInfoService.class);
    print(String.format("PD Pushing is %s.", fpmInfo.isPdPushEnabled() ? "enabled" : "disabled"));
    if (peerAddress != null) {
        IpAddress address = IpAddress.valueOf(peerAddress);
        fpmInfo.peers().entrySet().stream().filter(peer -> peer.getKey().address().equals(address)).map(Map.Entry::getValue).forEach(this::print);
    } else {
        fpmInfo.peers().entrySet().stream().sorted(Comparator.<Map.Entry<FpmPeer, FpmPeerInfo>, IpAddress>comparing(e -> e.getKey().address()).thenComparing(e -> e.getKey().port())).map(Map.Entry::getValue).forEach(this::print);
    }
}
Also used : FpmInfoService(org.onosproject.routing.fpm.FpmInfoService) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) FpmPeer(org.onosproject.routing.fpm.FpmPeer) FpmInfoService(org.onosproject.routing.fpm.FpmInfoService) Tools(org.onlab.util.Tools) FpmPeerInfo(org.onosproject.routing.fpm.FpmPeerInfo) Map(java.util.Map) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Argument(org.apache.karaf.shell.api.action.Argument) ClusterService(org.onosproject.cluster.ClusterService) Comparator(java.util.Comparator) Command(org.apache.karaf.shell.api.action.Command) IpAddress(org.onlab.packet.IpAddress) IpAddress(org.onlab.packet.IpAddress) Map(java.util.Map)

Aggregations

IpAddress (org.onlab.packet.IpAddress)288 MacAddress (org.onlab.packet.MacAddress)63 VlanId (org.onlab.packet.VlanId)52 ConnectPoint (org.onosproject.net.ConnectPoint)48 Set (java.util.Set)46 DeviceId (org.onosproject.net.DeviceId)44 Logger (org.slf4j.Logger)40 Test (org.junit.Test)37 Collectors (java.util.stream.Collectors)36 Ethernet (org.onlab.packet.Ethernet)36 IpPrefix (org.onlab.packet.IpPrefix)36 HostId (org.onosproject.net.HostId)33 Host (org.onosproject.net.Host)32 Optional (java.util.Optional)30 HostLocation (org.onosproject.net.HostLocation)30 LoggerFactory (org.slf4j.LoggerFactory)30 ApplicationId (org.onosproject.core.ApplicationId)29 CoreService (org.onosproject.core.CoreService)29 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)29 JsonNode (com.fasterxml.jackson.databind.JsonNode)28