Search in sources :

Example 1 with Dhcp6IaAddressOption

use of org.onlab.packet.dhcp.Dhcp6IaAddressOption 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 2 with Dhcp6IaAddressOption

use of org.onlab.packet.dhcp.Dhcp6IaAddressOption in project onos by opennetworkinglab.

the class DhcpRelayManagerTest method buildDhcp6Packet.

/**
 * Generates DHCP6 REQUEST packet.
 */
private void buildDhcp6Packet(DHCP6 dhcp6, byte msgType, Ip6Address ip6Addr, IpPrefix prefix) {
    // build address option
    Dhcp6IaAddressOption iaAddressOption = new Dhcp6IaAddressOption();
    iaAddressOption.setCode(DHCP6.OptionCode.IAADDR.value());
    iaAddressOption.setIp6Address(ip6Addr);
    iaAddressOption.setPreferredLifetime(3600);
    iaAddressOption.setValidLifetime(1200);
    iaAddressOption.setLength((short) Dhcp6IaAddressOption.DEFAULT_LEN);
    Dhcp6ClientIdOption clientIdOption = new Dhcp6ClientIdOption();
    Dhcp6Duid dhcp6Duip = new Dhcp6Duid();
    dhcp6Duip.setDuidType(Dhcp6Duid.DuidType.DUID_LLT);
    // Ethernet
    dhcp6Duip.setHardwareType((short) 0x01);
    dhcp6Duip.setDuidTime(1234);
    dhcp6Duip.setLinkLayerAddress(CLIENT_MAC.toBytes());
    clientIdOption.setDuid(dhcp6Duip);
    Dhcp6IaNaOption iaNaOption = new Dhcp6IaNaOption();
    iaNaOption.setCode(DHCP6.OptionCode.IA_NA.value());
    iaNaOption.setIaId(0);
    iaNaOption.setT1(302400);
    iaNaOption.setT2(483840);
    List<Dhcp6Option> iaNaSubOptions = new ArrayList<Dhcp6Option>();
    iaNaSubOptions.add(iaAddressOption);
    iaNaOption.setOptions(iaNaSubOptions);
    iaNaOption.setLength((short) (Dhcp6IaNaOption.DEFAULT_LEN + iaAddressOption.getLength()));
    // build prefix option
    Dhcp6IaPrefixOption iaPrefixOption = new Dhcp6IaPrefixOption();
    iaPrefixOption.setCode(DHCP6.OptionCode.IAPREFIX.value());
    iaPrefixOption.setIp6Prefix(prefix.address().getIp6Address());
    iaPrefixOption.setPrefixLength((byte) prefix.prefixLength());
    iaPrefixOption.setPreferredLifetime(3601);
    iaPrefixOption.setValidLifetime(1201);
    iaPrefixOption.setLength((short) Dhcp6IaPrefixOption.DEFAULT_LEN);
    Dhcp6IaPdOption iaPdOption = new Dhcp6IaPdOption();
    iaPdOption.setCode(DHCP6.OptionCode.IA_PD.value());
    iaPdOption.setIaId(0);
    iaPdOption.setT1(302401);
    iaPdOption.setT2(483841);
    List<Dhcp6Option> iaPdSubOptions = new ArrayList<Dhcp6Option>();
    iaPdSubOptions.add(iaPrefixOption);
    iaPdOption.setOptions(iaPdSubOptions);
    iaPdOption.setLength((short) (Dhcp6IaPdOption.DEFAULT_LEN + iaPrefixOption.getLength()));
    dhcp6.setMsgType(msgType);
    List<Dhcp6Option> dhcp6Options = new ArrayList<Dhcp6Option>();
    dhcp6Options.add(iaNaOption);
    dhcp6Options.add(clientIdOption);
    dhcp6Options.add(iaPdOption);
    dhcp6.setOptions(dhcp6Options);
}
Also used : Dhcp6Option(org.onlab.packet.dhcp.Dhcp6Option) Dhcp6IaPrefixOption(org.onlab.packet.dhcp.Dhcp6IaPrefixOption) Dhcp6Duid(org.onlab.packet.dhcp.Dhcp6Duid) ArrayList(java.util.ArrayList) Dhcp6IaPdOption(org.onlab.packet.dhcp.Dhcp6IaPdOption) Dhcp6IaAddressOption(org.onlab.packet.dhcp.Dhcp6IaAddressOption) Dhcp6ClientIdOption(org.onlab.packet.dhcp.Dhcp6ClientIdOption) Dhcp6IaNaOption(org.onlab.packet.dhcp.Dhcp6IaNaOption)

Aggregations

ArrayList (java.util.ArrayList)2 Dhcp6ClientIdOption (org.onlab.packet.dhcp.Dhcp6ClientIdOption)2 Dhcp6Duid (org.onlab.packet.dhcp.Dhcp6Duid)2 Dhcp6IaAddressOption (org.onlab.packet.dhcp.Dhcp6IaAddressOption)2 Dhcp6IaNaOption (org.onlab.packet.dhcp.Dhcp6IaNaOption)2 Dhcp6IaPdOption (org.onlab.packet.dhcp.Dhcp6IaPdOption)2 Dhcp6IaPrefixOption (org.onlab.packet.dhcp.Dhcp6IaPrefixOption)2 Dhcp6Option (org.onlab.packet.dhcp.Dhcp6Option)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 HashMultimap (com.google.common.collect.HashMultimap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 Multimap (com.google.common.collect.Multimap)1 Multimaps (com.google.common.collect.Multimaps)1 Sets (com.google.common.collect.Sets)1 ByteBuffer (java.nio.ByteBuffer)1 Collection (java.util.Collection)1 Dictionary (java.util.Dictionary)1 List (java.util.List)1