Search in sources :

Example 21 with Route

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

the class DhcpRelayManagerTest method relayDhcpWithAgentInfo.

/**
 * Relay a DHCP packet with option 82 (Indirectly connected host).
 */
@Test
public void relayDhcpWithAgentInfo() {
    replay(mockHostProviderService);
    // Assume outer dhcp relay agent exists in store already
    // send request
    packetService.processPacket(new TestDhcpRequestPacketContext(CLIENT2_MAC, CLIENT2_VLAN, CLIENT2_CP, INTERFACE_IP.ipAddress().getIp4Address(), true));
    // No routes
    assertEquals(0, mockRouteStore.routes.size());
    // Make sure the REQUEST packet has been processed before start sending ACK
    assertAfter(PKT_PROCESSING_MS, () -> assertNotNull(packetService.emittedPacket));
    // send ack
    packetService.processPacket(new TestDhcpAckPacketContext(CLIENT2_CP, CLIENT2_MAC, CLIENT2_VLAN, INTERFACE_IP.ipAddress().getIp4Address(), true));
    // won't trigger the host provider service
    verify(mockHostProviderService);
    reset(mockHostProviderService);
    assertAfter(PKT_PROCESSING_MS, () -> assertEquals(1, mockRouteStore.routes.size()));
    Route route = mockRouteStore.routes.get(0);
    assertAfter(PKT_PROCESSING_MS, () -> assertEquals(OUTER_RELAY_IP, route.nextHop()));
    assertAfter(PKT_PROCESSING_MS, () -> assertEquals(IP_FOR_CLIENT.toIpPrefix(), route.prefix()));
    assertAfter(PKT_PROCESSING_MS, () -> assertEquals(Route.Source.DHCP, route.source()));
}
Also used : Route(org.onosproject.routeservice.Route) Test(org.junit.Test)

Example 22 with Route

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

the class DhcpRelayWebResource method dhcpFpmDelete.

/**
 * Deletes the fpm route from fpm record.
 * Corresponding route from the route store
 *
 * @param prefix IpPrefix
 * @return 204 NO CONTENT, 404; 401
 */
@DELETE
@Path("fpm/{prefix}")
public Response dhcpFpmDelete(@PathParam("prefix") String prefix) {
    DhcpRelayService dhcpRelayService = get(DhcpRelayService.class);
    RouteStore routeStore = get(RouteStore.class);
    try {
        // removes fpm route from fpm record
        Optional<FpmRecord> fpmRecord = dhcpRelayService.removeFpmRecord(IpPrefix.valueOf(prefix));
        if (fpmRecord.isPresent()) {
            IpAddress nextHop = fpmRecord.get().nextHop();
            Route route = new Route(Route.Source.DHCP, IpPrefix.valueOf(prefix), nextHop);
            // removes DHCP route from route store
            routeStore.removeRoute(route);
        } else {
            LOG.warn("fpmRecord is not present");
        }
    } catch (IllegalArgumentException ex) {
        throw new IllegalArgumentException(ex);
    }
    return Response.noContent().build();
}
Also used : RouteStore(org.onosproject.routeservice.RouteStore) FpmRecord(org.onosproject.routing.fpm.api.FpmRecord) DhcpRelayService(org.onosproject.dhcprelay.api.DhcpRelayService) IpAddress(org.onlab.packet.IpAddress) Route(org.onosproject.routeservice.Route) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 23 with Route

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

the class Dhcp6HandlerImpl method processDhcp6PacketFromServer.

/**
 * process the DHCP6 relay-reply packet from dhcp server.
 *
 * @param context packet context
 * @param receivedPacket server ethernet packet
 * @param recevingInterfaces set of server side interfaces
 * @return internalPacket toward client
 */
private InternalPacket processDhcp6PacketFromServer(PacketContext context, Ethernet receivedPacket, Set<Interface> recevingInterfaces) {
    // get dhcp6 header.
    Ethernet etherReply = receivedPacket.duplicate();
    IPv6 ipv6Packet = (IPv6) etherReply.getPayload();
    UDP udpPacket = (UDP) ipv6Packet.getPayload();
    DHCP6 dhcp6Relay = (DHCP6) udpPacket.getPayload();
    Boolean directConnFlag = Dhcp6HandlerUtil.directlyConnected(dhcp6Relay);
    DHCP6 embeddedDhcp6 = dhcp6Relay.getOptions().stream().filter(opt -> opt instanceof Dhcp6RelayOption).map(BasePacket::getPayload).map(pld -> (DHCP6) pld).findFirst().orElse(null);
    ConnectPoint inPort = context.inPacket().receivedFrom();
    DhcpServerInfo foundServerInfo = findServerInfoFromServer(directConnFlag, inPort);
    if (foundServerInfo == null) {
        log.warn("Cannot find server info for {} server, inPort {}", directConnFlag ? "direct" : "indirect", inPort);
        // dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_SERVER_INFO);
        return null;
    } else {
        if (Dhcp6HandlerUtil.isServerIpEmpty(foundServerInfo)) {
            log.warn("Cannot find server info's ipaddress");
            // dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_SERVER_IP6ADDR);
            return null;
        }
    }
    Dhcp6InterfaceIdOption interfaceIdOption = dhcp6Relay.getOptions().stream().filter(opt -> opt instanceof Dhcp6InterfaceIdOption).map(opt -> (Dhcp6InterfaceIdOption) opt).findFirst().orElse(null);
    if (interfaceIdOption == null) {
        log.warn("Interface Id option is not present, abort packet...");
        // dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.OPTION_MISSING_FAIL);
        return null;
    }
    MacAddress peerMac = interfaceIdOption.getMacAddress();
    String clientConnectionPointStr = new String(interfaceIdOption.getInPort());
    ConnectPoint clientConnectionPoint = ConnectPoint.deviceConnectPoint(clientConnectionPointStr);
    VlanId vlanIdInUse = VlanId.vlanId(interfaceIdOption.getVlanId());
    log.debug("processDhcp6PacketFromServer Interface Id Mac {}, port{}, vlan {}", peerMac, clientConnectionPointStr, vlanIdInUse);
    Interface clientInterface = interfaceService.getInterfacesByPort(clientConnectionPoint).stream().filter(iface -> Dhcp6HandlerUtil.interfaceContainsVlan(iface, vlanIdInUse)).findFirst().orElse(null);
    if (clientInterface == null) {
        log.warn("Cannot get client interface for from packet, abort... vlan {}", vlanIdInUse.toString());
        // dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_MATCHING_INTF);
        return null;
    }
    etherReply.setVlanID(vlanIdInUse.toShort());
    MacAddress relayAgentMac = clientInterface.mac();
    if (relayAgentMac == null) {
        log.warn("Can not get client interface mac, abort packet..");
        // dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_CLIENT_INTF_MAC);
        return null;
    }
    etherReply.setSourceMACAddress(relayAgentMac);
    // find destMac
    MacAddress clientMac;
    Ip6Address peerAddress = Ip6Address.valueOf(dhcp6Relay.getPeerAddress());
    Set<Host> clients = hostService.getHostsByIp(peerAddress);
    if (clients.isEmpty()) {
        log.trace("There's no host found for this address {}", HexString.toHexString(dhcp6Relay.getPeerAddress(), ":"));
        log.trace("Let's look up interfaceId {}", HexString.toHexString(peerMac.toBytes(), ":"));
        clientMac = peerMac;
    } else {
        clientMac = clients.iterator().next().mac();
        if (clientMac == null) {
            log.warn("No client mac address found, abort packet...");
            // dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_CLIENT_INTF_MAC);
            return null;
        }
        log.trace("Client mac address found from getHostByIp");
    }
    etherReply.setDestinationMACAddress(clientMac);
    // ip header
    ipv6Packet.setSourceAddress(dhcp6Relay.getLinkAddress());
    ipv6Packet.setDestinationAddress(dhcp6Relay.getPeerAddress());
    // udp header
    udpPacket.setSourcePort(UDP.DHCP_V6_SERVER_PORT);
    if (directConnFlag) {
        udpPacket.setDestinationPort(UDP.DHCP_V6_CLIENT_PORT);
    } else {
        udpPacket.setDestinationPort(UDP.DHCP_V6_SERVER_PORT);
    }
    boolean hostOrRouteAllowed = learnRouteFromLeasequery || Dhcp6HandlerUtil.getDhcp6LeafMessageType(dhcp6Relay) != MsgType.LEASEQUERY_REPLY;
    log.debug("Can add host or route: {}", hostOrRouteAllowed);
    if (hostOrRouteAllowed) {
        // add host or route
        addHostOrRoute(directConnFlag, clientConnectionPoint, dhcp6Relay, embeddedDhcp6, clientMac, clientInterface, vlanIdInUse);
    }
    udpPacket.setPayload(embeddedDhcp6);
    udpPacket.resetChecksum();
    ipv6Packet.setPayload(udpPacket);
    etherReply.setPayload(ipv6Packet);
    return InternalPacket.internalPacket(etherReply, clientConnectionPoint);
}
Also used : UDP(org.onlab.packet.UDP) 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) IPv6(org.onlab.packet.IPv6) Host(org.onosproject.net.Host) HexString(org.onlab.util.HexString) MacAddress(org.onlab.packet.MacAddress) ConnectPoint(org.onosproject.net.ConnectPoint) Ip6Address(org.onlab.packet.Ip6Address) Ethernet(org.onlab.packet.Ethernet) Dhcp6InterfaceIdOption(org.onlab.packet.dhcp.Dhcp6InterfaceIdOption) DHCP6(org.onlab.packet.DHCP6) Dhcp6RelayOption(org.onlab.packet.dhcp.Dhcp6RelayOption) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo) VlanId(org.onlab.packet.VlanId) Interface(org.onosproject.net.intf.Interface)

Example 24 with Route

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

the class Dhcp6HandlerImpl method processLQ6PacketFromClient.

private List<InternalPacket> processLQ6PacketFromClient(PacketContext context, Ethernet clientPacket, Set<Interface> clientInterfaces, DHCP6 dhcp6Payload) {
    ConnectPoint inPort = context.inPacket().receivedFrom();
    log.info("Got LQ-REQUEST V6 on port {}", inPort);
    List<Dhcp6Option> lopt = dhcp6Payload.getOptions();
    log.info("Options list: {}", lopt);
    Dhcp6LeaseQueryOption lqoption = dhcp6Payload.getOptions().stream().filter(opt -> opt instanceof Dhcp6LeaseQueryOption).map(pld -> (Dhcp6LeaseQueryOption) pld).findFirst().orElse(null);
    if (lqoption == null) {
        // Can't find dhcp payload
        log.warn("Can't find dhcp6 lease query message - aborting");
        return null;
    } else {
        log.info("dhcp6 lqv6 options found: {}", lqoption);
    }
    log.warn("LQv6 for " + lqoption.linkAddress.toString() + " comes from " + inPort.toString());
    Ethernet packet = context.inPacket().parsed();
    Ip6Address clientAddress = lqoption.linkAddress;
    IPv6 ipv6Packet = (IPv6) packet.getPayload();
    Ip6Address nextHopIp = findNextHopIp6FromRelayStore(clientAddress);
    // 1. only if there is a route to remove - remove it
    if (nextHopIp != null) {
        Route routeForIP6 = new Route(Route.Source.DHCP, clientAddress.toIpPrefix(), nextHopIp);
        log.debug("Removing route of Client " + clientAddress + " for indirectly connected - next hop ip6 " + nextHopIp);
        routeStore.removeRoute(routeForIP6);
    }
    // 2. note the potential NH this packet came from in case it's a known lease
    // this NH will then be used to build the route
    MacAddress potentialNH = packet.getSourceMAC();
    VlanId vlanId = VlanId.vlanId(packet.getVlanID());
    setPotentialNextHopForIp6InRelayStore(clientAddress, vlanId, potentialNH);
    // 3. route this LQ6 to all relevant servers
    IPv6 clientIpv6 = (IPv6) clientPacket.getPayload();
    UDP clientUdp = (UDP) clientIpv6.getPayload();
    DHCP6 clientDhcp6 = (DHCP6) clientUdp.getPayload();
    boolean directConnFlag = Dhcp6HandlerUtil.directlyConnected(clientDhcp6);
    boolean serverFound = false;
    List<InternalPacket> internalPackets = new ArrayList<>();
    List<DhcpServerInfo> serverInfoList = findValidServerInfo(directConnFlag);
    List<DhcpServerInfo> copyServerInfoList = new ArrayList<DhcpServerInfo>(serverInfoList);
    for (DhcpServerInfo serverInfo : copyServerInfoList) {
        if (!Dhcp6HandlerUtil.checkDhcpServerConnPt(directConnFlag, serverInfo)) {
            log.warn("Can't get server connect point, ignore");
            continue;
        }
        DhcpServerInfo newServerInfo = getHostInfoForServerInfo(serverInfo, serverInfoList);
        if (newServerInfo == null) {
            log.debug("Can't get server interface with host info resolved, ignore serverInfo {} serverInfoList {}", serverInfo, serverInfoList);
            continue;
        }
        Interface serverInterface = getServerInterface(newServerInfo);
        if (serverInterface == null) {
            log.debug("Can't get server interface, ignore for serverInfo {}, serverInfoList {}", serverInfo, serverInfoList);
            continue;
        }
        serverFound = true;
        log.debug("Server Info Found {}", serverInfo.getDhcpConnectMac());
        Ethernet etherRouted = (Ethernet) clientPacket.clone();
        MacAddress macFacingServer = serverInterface.mac();
        if (macFacingServer == null) {
            log.warn("No MAC address for server Interface {}", serverInterface);
            return null;
        }
        etherRouted.setSourceMACAddress(macFacingServer);
        etherRouted.setDestinationMACAddress(newServerInfo.getDhcpConnectMac().get());
        InternalPacket internalPacket = InternalPacket.internalPacket(etherRouted, serverInfo.getDhcpServerConnectPoint().get());
        internalPackets.add(internalPacket);
        log.debug("Sending LQ to DHCP server {}", newServerInfo.getDhcpServerIp6());
    }
    if (!serverFound) {
        log.warn("ProcessDhcp6PacketFromClient No Server Found");
    }
    log.debug("num of client packets to send is{}", internalPackets.size());
    return internalPackets;
}
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) UDP(org.onlab.packet.UDP) IPv6(org.onlab.packet.IPv6) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) MacAddress(org.onlab.packet.MacAddress) ConnectPoint(org.onosproject.net.ConnectPoint) Dhcp6LeaseQueryOption(org.onlab.packet.dhcp.Dhcp6LeaseQueryOption) Ip6Address(org.onlab.packet.Ip6Address) Dhcp6Option(org.onlab.packet.dhcp.Dhcp6Option) Ethernet(org.onlab.packet.Ethernet) DHCP6(org.onlab.packet.DHCP6) Route(org.onosproject.routeservice.Route) VlanId(org.onlab.packet.VlanId) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo) Interface(org.onosproject.net.intf.Interface)

Example 25 with Route

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

the class Dhcp6HandlerImpl method addHostOrRoute.

/**
 * add host or route and update dhcp relay record.
 *
 * @param directConnFlag  flag to show that packet is from directly connected client
 * @param location  client side connect point
 * @param dhcp6Relay the dhcp6 payload
 * @param embeddedDhcp6 the dhcp6 payload within relay
 * @param srcMac client gw/host macAddress
 * @param clientInterface client interface
 * @param vlanIdInUse vlanid encoded in the interface id Option
 */
private void addHostOrRoute(boolean directConnFlag, ConnectPoint location, DHCP6 dhcp6Relay, DHCP6 embeddedDhcp6, MacAddress srcMac, Interface clientInterface, VlanId vlanIdInUse) {
    log.debug("addHostOrRoute entered.");
    VlanId vlanId;
    if (clientInterface.vlanTagged().isEmpty()) {
        vlanId = clientInterface.vlan();
    } else {
        // might be multiple vlan in same interface
        vlanId = vlanIdInUse;
    }
    if (vlanId == null) {
        vlanId = VlanId.NONE;
    }
    Boolean isMsgReply = Dhcp6HandlerUtil.isDhcp6Reply(dhcp6Relay);
    MacAddress leafClientMac;
    Byte leafMsgType;
    Dhcp6ClientIdOption clientIdOption = Dhcp6HandlerUtil.extractClientId(directConnFlag, embeddedDhcp6);
    if (clientIdOption != null) {
        log.debug("CLIENTID option found {}", clientIdOption);
        if ((clientIdOption.getDuid().getDuidType() == Dhcp6Duid.DuidType.DUID_LLT) || (clientIdOption.getDuid().getDuidType() == Dhcp6Duid.DuidType.DUID_LL)) {
            leafClientMac = MacAddress.valueOf(clientIdOption.getDuid().getLinkLayerAddress());
        } else {
            log.warn("Link-Layer Address not supported in CLIENTID option. No DhcpRelay Record created.");
            // dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_LINKLOCAL_FAIL);
            return;
        }
    } else {
        log.warn("CLIENTID option NOT found. No DhcpRelay Record created.");
        // dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_CLIENTID_FAIL);
        return;
    }
    HostId leafHostId = HostId.hostId(leafClientMac, vlanId);
    DhcpRecord record = dhcpRelayStore.getDhcpRecord(leafHostId).orElse(null);
    if (record == null) {
        record = new DhcpRecord(HostId.hostId(leafClientMac, vlanId));
    } else {
        record = record.clone();
    }
    IpAddressInfo ipInfo;
    PdPrefixInfo pdInfo = null;
    if (directConnFlag) {
        // Add to host store if it connect to network directly
        ipInfo = extractIpAddress(embeddedDhcp6);
        if (ipInfo != null) {
            if (isMsgReply) {
                Set<IpAddress> ips = Sets.newHashSet(ipInfo.ip6Address);
                HostId hostId = HostId.hostId(srcMac, vlanId);
                Host host = hostService.getHost(hostId);
                HostLocation hostLocation = new HostLocation(clientInterface.connectPoint(), System.currentTimeMillis());
                Set<HostLocation> hostLocations = Sets.newHashSet(hostLocation);
                if (host != null) {
                    // Dual homing support:
                    // if host exists, use old locations and new location
                    hostLocations.addAll(host.locations());
                }
                HostDescription desc = new DefaultHostDescription(srcMac, vlanId, hostLocations, ips, false);
                log.debug("adding Host for directly connected.");
                log.debug("client mac {} client vlan {} hostlocation {}", HexString.toHexString(srcMac.toBytes(), ":"), vlanId, hostLocation.toString());
                // Replace the ip when dhcp server give the host new ip address
                providerService.hostDetected(hostId, desc, false);
            }
        } else {
            log.warn("ipAddress not found. Do not add Host {} for directly connected.", HostId.hostId(srcMac, vlanId).toString());
        }
        leafMsgType = embeddedDhcp6.getMsgType();
    } else {
        // Add to route store if it does not connect to network directly
        // pick out the first link-local ip address
        IpAddress nextHopIp = getFirstIpByHost(directConnFlag, srcMac, vlanId);
        if (nextHopIp == null) {
            log.warn("Can't find link-local IP address of gateway mac {} vlanId {}", srcMac, vlanId);
            // dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_LINKLOCAL_GW);
            return;
        }
        DHCP6 leafDhcp = Dhcp6HandlerUtil.getDhcp6Leaf(embeddedDhcp6);
        ipInfo = extractIpAddress(leafDhcp);
        if (ipInfo == null) {
            log.debug("ip is null");
        } else {
            if (isMsgReply) {
                Route routeForIP = new Route(Route.Source.DHCP, ipInfo.ip6Address.toIpPrefix(), nextHopIp);
                log.debug("adding Route of 128 address for indirectly connected.");
                routeStore.replaceRoute(routeForIP);
            }
        }
        pdInfo = extractPrefix(leafDhcp);
        if (pdInfo == null) {
            log.debug("ipPrefix is null ");
        } else {
            if (isMsgReply) {
                Route routeForPrefix = new Route(Route.Source.DHCP, pdInfo.pdPrefix, nextHopIp);
                log.debug("adding Route of PD for indirectly connected.");
                routeStore.replaceRoute(routeForPrefix);
                if (this.dhcpFpmEnabled) {
                    FpmRecord fpmRecord = new FpmRecord(pdInfo.pdPrefix, nextHopIp, FpmRecord.Type.DHCP_RELAY);
                    dhcpFpmPrefixStore.addFpmRecord(pdInfo.pdPrefix, fpmRecord);
                }
            }
        }
        leafMsgType = leafDhcp.getMsgType();
    }
    if (leafMsgType == DHCP6.MsgType.RELEASE.value() || (leafMsgType == DHCP6.MsgType.REPLY.value()) && ipInfo == null) {
        log.warn("DHCP6 RELEASE/REPLY(null ip) from Server. MsgType {}", leafMsgType);
    // return;
    }
    record.addLocation(new HostLocation(location, System.currentTimeMillis()));
    if (leafMsgType == DHCP6.MsgType.REPLY.value()) {
        if (ipInfo != null) {
            log.debug("IP6 address is being stored into dhcp-relay store.");
            log.debug("Client IP6 address {}", HexString.toHexString(ipInfo.ip6Address.toOctets(), ":"));
            record.ip6Address(ipInfo.ip6Address);
            record.updateAddrPrefTime(ipInfo.prefTime);
            record.updateLastIp6Update();
        } else {
            log.debug("IP6 address is not returned from server. Maybe only PD is returned.");
        }
        if (pdInfo != null) {
            log.debug("IP6 PD address {}", HexString.toHexString(pdInfo.pdPrefix.address().toOctets(), ":"));
            record.pdPrefix(pdInfo.pdPrefix);
            record.updatePdPrefTime(pdInfo.prefTime);
            record.updateLastPdUpdate();
        } else {
            log.debug("IP6 PD address is not returned from server. Maybe only IPAddress is returned.");
        }
    }
    record.getV6Counters().incrementCounter(Dhcp6HandlerUtil.getMsgTypeStr(leafMsgType));
    record.ip6Status(DHCP6.MsgType.getType(leafMsgType));
    record.setDirectlyConnected(directConnFlag);
    record.updateLastSeen();
    dhcpRelayStore.updateDhcpRecord(leafHostId, record);
/*
        // TODO Use AtomicInteger for the counters
        try {
            recordSemaphore.acquire();
            try {
                dhcpRelayCountersStore.incrementCounter(gCount, Dhcp6HandlerUtil.getMsgTypeStr(leafMsgType));
            } finally {
                // calling release() after a successful acquire()
                recordSemaphore.release();
            }
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        */
}
Also used : DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) DhcpRecord(org.onosproject.dhcprelay.store.DhcpRecord) Host(org.onosproject.net.Host) MacAddress(org.onlab.packet.MacAddress) HostId(org.onosproject.net.HostId) HostDescription(org.onosproject.net.host.HostDescription) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) HostLocation(org.onosproject.net.HostLocation) FpmRecord(org.onosproject.routing.fpm.api.FpmRecord) IpAddress(org.onlab.packet.IpAddress) DHCP6(org.onlab.packet.DHCP6) VlanId(org.onlab.packet.VlanId) Route(org.onosproject.routeservice.Route) Dhcp6ClientIdOption(org.onlab.packet.dhcp.Dhcp6ClientIdOption)

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