Search in sources :

Example 26 with Route

use of org.onosproject.routeservice.Route in project onos by opennetworkinglab.

the class Dhcp6HandlerImpl method handleLeaseQuery6ReplyMsg.

public void handleLeaseQuery6ReplyMsg(PacketContext context, DHCP6 dhcp6Payload) {
    ConnectPoint inPort = context.inPacket().receivedFrom();
    log.info("Got LQV6-REPLY on port {}", inPort);
    List<Dhcp6Option> lopt = dhcp6Payload.getOptions();
    log.info("Options list: {}", lopt);
    // find out if this lease is known is
    Dhcp6ClientDataOption clientDataOption = dhcp6Payload.getOptions().stream().filter(opt -> opt instanceof Dhcp6ClientDataOption).map(pld -> (Dhcp6ClientDataOption) pld).findFirst().orElse(null);
    if (clientDataOption == null) {
        log.warn("clientDataOption option is not present, " + "lease is UNKNOWN - not adding any new route...");
    } else {
        Dhcp6IaAddressOption aiAddressOption = clientDataOption.getOptions().stream().filter(opt -> opt instanceof Dhcp6IaAddressOption).map(pld -> (Dhcp6IaAddressOption) pld).findFirst().orElse(null);
        Dhcp6ClientIdOption clientIdOption = clientDataOption.getOptions().stream().filter(opt -> opt instanceof Dhcp6ClientIdOption).map(pld -> (Dhcp6ClientIdOption) pld).findFirst().orElse(null);
        if (aiAddressOption == null) {
            log.warn("clientDataOption from DHCP server does not " + "contains Dhcp6IaAddressOption for the client - giving up...");
        } else {
            Ip6Address clientAddress = aiAddressOption.getIp6Address();
            MacAddress clientMacAddress = MacAddress.valueOf(clientIdOption.getDuid().getLinkLayerAddress());
            Ethernet packet = context.inPacket().parsed();
            VlanId vlanId = VlanId.vlanId(packet.getVlanID());
            MacAddress potentialNextHopMac = findNextHopMacForIp6FromRelayStore(clientAddress, clientMacAddress, vlanId);
            if (potentialNextHopMac == null) {
                log.warn("Can't find next hop host mac for client {} mac:{}/{}", clientAddress, clientMacAddress, vlanId);
                return;
            } else {
                log.info("Next hop mac for {}/{}/{} is {}", clientAddress, clientMacAddress, vlanId, potentialNextHopMac.toString());
            }
            // search the next hop in the hosts store
            HostId gwHostId = HostId.hostId(potentialNextHopMac, vlanId);
            Host gwHost = hostService.getHost(gwHostId);
            if (gwHost == null) {
                log.warn("Can't find next hop host ID {}", gwHostId);
                return;
            }
            Ip6Address nextHopIp = gwHost.ipAddresses().stream().filter(IpAddress::isIp6).filter(IpAddress::isLinkLocal).map(IpAddress::getIp6Address).findFirst().orElse(null);
            if (nextHopIp == null) {
                log.warn("Can't find IP6 address of next hop {}", gwHost);
                return;
            }
            log.info("client " + clientAddress + " is known !");
            Route routeForIP6 = new Route(Route.Source.DHCP, clientAddress.toIpPrefix(), nextHopIp);
            log.debug("updating route of Client for indirectly connected.");
            log.debug("client ip: " + clientAddress + ", next hop ip6: " + nextHopIp);
            routeStore.updateRoute(routeForIP6);
        }
    }
}
Also used : Dhcp6IaPdOption(org.onlab.packet.dhcp.Dhcp6IaPdOption) DeviceService(org.onosproject.net.device.DeviceService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) IgnoreDhcpConfig(org.onosproject.dhcprelay.config.IgnoreDhcpConfig) ApplicationId(org.onosproject.core.ApplicationId) Dhcp6IaNaOption(org.onlab.packet.dhcp.Dhcp6IaNaOption) Dhcp6IaTaOption(org.onlab.packet.dhcp.Dhcp6IaTaOption) Ip6Address(org.onlab.packet.Ip6Address) DhcpRelayStore(org.onosproject.dhcprelay.store.DhcpRelayStore) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) MsgType(org.onlab.packet.DHCP6.MsgType) PacketService(org.onosproject.net.packet.PacketService) DeviceId(org.onosproject.net.DeviceId) DhcpServerConfig(org.onosproject.dhcprelay.config.DhcpServerConfig) LEARN_ROUTE_FROM_LEASE_QUERY_DEFAULT(org.onosproject.dhcprelay.OsgiPropertyConstants.LEARN_ROUTE_FROM_LEASE_QUERY_DEFAULT) Dictionary(java.util.Dictionary) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Pipeliner(org.onosproject.net.behaviour.Pipeliner) REMOVE(org.onosproject.net.flowobjective.Objective.Operation.REMOVE) DhcpFpmPrefixStore(org.onosproject.dhcprelay.store.DhcpFpmPrefixStore) HostProviderRegistry(org.onosproject.net.host.HostProviderRegistry) Tools(org.onlab.util.Tools) RouteStore(org.onosproject.routeservice.RouteStore) Host(org.onosproject.net.Host) ComponentContext(org.osgi.service.component.ComponentContext) LEARN_ROUTE_FROM_LEASE_QUERY(org.onosproject.dhcprelay.OsgiPropertyConstants.LEARN_ROUTE_FROM_LEASE_QUERY) HostListener(org.onosproject.net.host.HostListener) InterfaceService(org.onosproject.net.intf.InterfaceService) HostService(org.onosproject.net.host.HostService) Multimaps(com.google.common.collect.Multimaps) ArrayList(java.util.ArrayList) Dhcp6InterfaceIdOption(org.onlab.packet.dhcp.Dhcp6InterfaceIdOption) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) FpmRecord(org.onosproject.routing.fpm.api.FpmRecord) Dhcp6LeaseQueryOption(org.onlab.packet.dhcp.Dhcp6LeaseQueryOption) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) TpPort(org.onlab.packet.TpPort) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) BasePacket(org.onlab.packet.BasePacket) Executor(java.util.concurrent.Executor) HostProvider(org.onosproject.net.host.HostProvider) VlanId(org.onlab.packet.VlanId) ProviderId(org.onosproject.net.provider.ProviderId) Dhcp6IaAddressOption(org.onlab.packet.dhcp.Dhcp6IaAddressOption) IPv6(org.onlab.packet.IPv6) DHCP6(org.onlab.packet.DHCP6) HexString(org.onlab.util.HexString) DhcpRecord(org.onosproject.dhcprelay.store.DhcpRecord) Objective(org.onosproject.net.flowobjective.Objective) MacAddress(org.onlab.packet.MacAddress) Dhcp6Duid(org.onlab.packet.dhcp.Dhcp6Duid) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) Route(org.onosproject.routeservice.Route) HostLocation(org.onosproject.net.HostLocation) Interface(org.onosproject.net.intf.Interface) CoreService(org.onosproject.core.CoreService) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) Dhcp6ClientIdOption(org.onlab.packet.dhcp.Dhcp6ClientIdOption) ByteBuffer(java.nio.ByteBuffer) Ethernet(org.onlab.packet.Ethernet) HostProviderService(org.onosproject.net.host.HostProviderService) HashMultimap(com.google.common.collect.HashMultimap) Dhcp6IaPrefixOption(org.onlab.packet.dhcp.Dhcp6IaPrefixOption) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo) ImmutableSet(com.google.common.collect.ImmutableSet) Device(org.onosproject.net.Device) Collection(java.util.Collection) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) PacketContext(org.onosproject.net.packet.PacketContext) Optional(java.util.Optional) HostDescription(org.onosproject.net.host.HostDescription) IpPrefix(org.onlab.packet.IpPrefix) Dhcp6ClientDataOption(org.onlab.packet.dhcp.Dhcp6ClientDataOption) ADD(org.onosproject.net.flowobjective.Objective.Operation.ADD) Multimap(com.google.common.collect.Multimap) Dhcp6RelayOption(org.onlab.packet.dhcp.Dhcp6RelayOption) DhcpRelayCountersStore(org.onosproject.dhcprelay.store.DhcpRelayCountersStore) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) OutboundPacket(org.onosproject.net.packet.OutboundPacket) Activate(org.osgi.service.component.annotations.Activate) HostEvent(org.onosproject.net.host.HostEvent) HostId(org.onosproject.net.HostId) IpAddress(org.onlab.packet.IpAddress) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) Semaphore(java.util.concurrent.Semaphore) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Dhcp6Option(org.onlab.packet.dhcp.Dhcp6Option) UDP(org.onlab.packet.UDP) DhcpHandler(org.onosproject.dhcprelay.api.DhcpHandler) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Modified(org.osgi.service.component.annotations.Modified) PacketPriority(org.onosproject.net.packet.PacketPriority) Reference(org.osgi.service.component.annotations.Reference) Dhcp6ClientDataOption(org.onlab.packet.dhcp.Dhcp6ClientDataOption) Dhcp6IaAddressOption(org.onlab.packet.dhcp.Dhcp6IaAddressOption) Host(org.onosproject.net.Host) MacAddress(org.onlab.packet.MacAddress) HostId(org.onosproject.net.HostId) ConnectPoint(org.onosproject.net.ConnectPoint) Ip6Address(org.onlab.packet.Ip6Address) Dhcp6Option(org.onlab.packet.dhcp.Dhcp6Option) Ethernet(org.onlab.packet.Ethernet) IpAddress(org.onlab.packet.IpAddress) VlanId(org.onlab.packet.VlanId) Route(org.onosproject.routeservice.Route) Dhcp6ClientIdOption(org.onlab.packet.dhcp.Dhcp6ClientIdOption)

Example 27 with Route

use of org.onosproject.routeservice.Route in project onos by opennetworkinglab.

the class Dhcp4HandlerImpl method handleLeaseQueryActivateMsg.

private void handleLeaseQueryActivateMsg(Ethernet packet, DHCP dhcpPayload) {
    log.debug("LQ: Got DHCPLEASEACTIVE packet!");
    if (learnRouteFromLeasequery) {
        // TODO: release the ip address from client
        MacAddress clientMacAddress = MacAddress.valueOf(dhcpPayload.getClientHardwareAddress());
        VlanId vlanId = VlanId.vlanId(packet.getVlanID());
        HostId hostId = HostId.hostId(clientMacAddress, vlanId);
        DhcpRecord record = dhcpRelayStore.getDhcpRecord(hostId).orElse(null);
        if (record == null) {
            log.warn("Can't find record for host {} when processing DHCPLEASEACTIVE", hostId);
            return;
        }
        // need to update routes
        log.debug("Lease Query for Client results in DHCPLEASEACTIVE - route needs to be modified");
        // get current route
        // find the ip of that client with the DhcpRelay store
        Ip4Address clientIP = record.ip4Address().orElse(null);
        log.debug("LQ: IP of host is " + clientIP.getIp4Address());
        MacAddress nextHopMac = record.nextHop().orElse(null);
        log.debug("LQ: MAC of resulting *OLD* NH for that host is " + nextHopMac.toString());
        // find the new NH by looking at the src MAC of the dhcp request
        // from the LQ store
        MacAddress newNextHopMac = record.nextHopTemp().orElse(null);
        log.debug("LQ: MAC of resulting *NEW* NH for that host is " + newNextHopMac.toString());
        log.debug("LQ: updating dhcp relay record with new NH");
        record.nextHop(newNextHopMac);
        // find the next hop IP from its mac
        HostId gwHostId = HostId.hostId(newNextHopMac, vlanId);
        Host gwHost = hostService.getHost(gwHostId);
        if (gwHost == null) {
            log.warn("Can't find gateway for new NH host " + gwHostId);
            return;
        }
        Ip4Address nextHopIp = gwHost.ipAddresses().stream().filter(IpAddress::isIp4).map(IpAddress::getIp4Address).findFirst().orElse(null);
        if (nextHopIp == null) {
            log.warn("Can't find IP address of gateway " + gwHost);
            return;
        }
        log.debug("LQ: *NEW* NH IP for host is " + nextHopIp.getIp4Address());
        Route route = new Route(Route.Source.DHCP, clientIP.toIpPrefix(), nextHopIp);
        routeStore.updateRoute(route);
    }
    // and forward to client
    InternalPacket ethernetPacket = processLeaseQueryFromServer(packet);
    if (ethernetPacket != null) {
        sendResponseToClient(ethernetPacket, dhcpPayload);
    }
}
Also used : Ip4Address(org.onlab.packet.Ip4Address) DhcpRecord(org.onosproject.dhcprelay.store.DhcpRecord) Host(org.onosproject.net.Host) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) IpAddress(org.onlab.packet.IpAddress) MacAddress(org.onlab.packet.MacAddress) HostId(org.onosproject.net.HostId) VlanId(org.onlab.packet.VlanId) Route(org.onosproject.routeservice.Route)

Example 28 with Route

use of org.onosproject.routeservice.Route in project onos by opennetworkinglab.

the class SdnIpReactiveRouting method packetReactiveProcessor.

/**
 * Routes packet reactively.
 *
 * @param dstIpAddress the destination IP address of a packet
 * @param srcIpAddress the source IP address of a packet
 * @param srcConnectPoint the connect point where a packet comes from
 * @param srcMacAddress the source MAC address of a packet
 */
private void packetReactiveProcessor(IpAddress dstIpAddress, IpAddress srcIpAddress, ConnectPoint srcConnectPoint, MacAddress srcMacAddress) {
    checkNotNull(dstIpAddress);
    checkNotNull(srcIpAddress);
    checkNotNull(srcConnectPoint);
    checkNotNull(srcMacAddress);
    // 
    // Step1: Try to update the existing intent first if it exists.
    // 
    IpPrefix ipPrefix = null;
    Route route = null;
    if (config.isIpAddressLocal(dstIpAddress)) {
        if (dstIpAddress.isIp4()) {
            ipPrefix = IpPrefix.valueOf(dstIpAddress, Ip4Address.BIT_LENGTH);
        } else {
            ipPrefix = IpPrefix.valueOf(dstIpAddress, Ip6Address.BIT_LENGTH);
        }
    } else {
        // Get IP prefix from BGP route table
        route = routeService.longestPrefixMatch(dstIpAddress);
        if (route != null) {
            ipPrefix = route.prefix();
        }
    }
    if (ipPrefix != null && intentRequestListener.mp2pIntentExists(ipPrefix)) {
        intentRequestListener.updateExistingMp2pIntent(ipPrefix, srcConnectPoint);
        return;
    }
    // 
    // Step2: There is no existing intent for the destination IP address.
    // Check whether it is necessary to create a new one. If necessary then
    // create a new one.
    // 
    TrafficType trafficType = trafficTypeClassifier(srcConnectPoint, dstIpAddress);
    switch(trafficType) {
        case HOST_TO_INTERNET:
            // The Step 1 has already handled it. We do not need to do anything here.
            if (route != null) {
                intentRequestListener.setUpConnectivityHostToInternet(srcIpAddress, ipPrefix, route.nextHop());
            }
            break;
        case INTERNET_TO_HOST:
            intentRequestListener.setUpConnectivityInternetToHost(dstIpAddress);
            break;
        case HOST_TO_HOST:
            intentRequestListener.setUpConnectivityHostToHost(dstIpAddress, srcIpAddress, srcMacAddress, srcConnectPoint);
            break;
        case INTERNET_TO_INTERNET:
            log.trace("This is transit traffic, " + "the intent should be preinstalled already");
            break;
        case DROP:
            // We need a new type of intent here.
            break;
        case UNKNOWN:
            log.trace("This is unknown traffic, so we do nothing");
            break;
        default:
            break;
    }
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) Route(org.onosproject.routeservice.Route)

Example 29 with Route

use of org.onosproject.routeservice.Route in project onos by opennetworkinglab.

the class DistributedRouteStore method computeRouteTablesFromRoutes.

private Map<RouteTableId, Set<Route>> computeRouteTablesFromRoutes(Collection<Route> routes) {
    Map<RouteTableId, Set<Route>> computedTables = new HashMap<>();
    routes.forEach(route -> {
        RouteTableId routeTableId = (route.prefix().address().isIp4()) ? IPV4 : IPV6;
        Set<Route> tempRoutes = computedTables.computeIfAbsent(routeTableId, k -> Sets.newHashSet());
        tempRoutes.add(route);
    });
    return computedTables;
}
Also used : RouteTableId(org.onosproject.routeservice.RouteTableId) RouteSet(org.onosproject.routeservice.RouteSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) DistributedSet(org.onosproject.store.service.DistributedSet) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Route(org.onosproject.routeservice.Route)

Example 30 with Route

use of org.onosproject.routeservice.Route in project onos by opennetworkinglab.

the class RouteManagerTest method testRouteAdd.

/**
 * Tests adding routes to the route manager.
 */
@Test
public void testRouteAdd() {
    Route route = new Route(Route.Source.STATIC, V4_PREFIX1, V4_NEXT_HOP1);
    ResolvedRoute resolvedRoute = new ResolvedRoute(route, MAC1);
    verifyRouteAdd(route, resolvedRoute);
    route = new Route(Route.Source.STATIC, V6_PREFIX1, V6_NEXT_HOP1);
    resolvedRoute = new ResolvedRoute(route, MAC3);
    verifyRouteAdd(route, resolvedRoute);
}
Also used : ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Route(org.onosproject.routeservice.Route) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Test(org.junit.Test)

Aggregations

Route (org.onosproject.routeservice.Route)35 IpAddress (org.onlab.packet.IpAddress)17 ResolvedRoute (org.onosproject.routeservice.ResolvedRoute)14 IpPrefix (org.onlab.packet.IpPrefix)13 Host (org.onosproject.net.Host)12 MacAddress (org.onlab.packet.MacAddress)10 VlanId (org.onlab.packet.VlanId)9 DhcpRecord (org.onosproject.dhcprelay.store.DhcpRecord)9 HostId (org.onosproject.net.HostId)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 Collection (java.util.Collection)6 Optional (java.util.Optional)6 Set (java.util.Set)6 Test (org.junit.Test)6 DHCP6 (org.onlab.packet.DHCP6)6 HostLocation (org.onosproject.net.HostLocation)6 HostEvent (org.onosproject.net.host.HostEvent)6 RouteAdminService (org.onosproject.routeservice.RouteAdminService)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 ArrayList (java.util.ArrayList)4