Search in sources :

Example 1 with DHCP6

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

the class Dhcp6HandlerImpl method removeHostOrRoute.

/**
 * remove host or route and update dhcp relay record attributes.
 *
 * @param directConnFlag  flag to show that packet is from directly connected client
 * @param location  client side connect point
 * @param dhcp6Packet the dhcp6 payload
 * @param clientPacket client's ethernet packet
 * @param clientIpv6 client's Ipv6 packet
 * @param clientInterface client interfaces
 */
private void removeHostOrRoute(boolean directConnFlag, ConnectPoint location, DHCP6 dhcp6Packet, Ethernet clientPacket, IPv6 clientIpv6, Interface clientInterface) {
    log.debug("removeHostOrRoute  enters {}", dhcp6Packet);
    VlanId vlanId = clientInterface.vlan();
    // could be gw or host
    MacAddress srcMac = clientPacket.getSourceMAC();
    MacAddress leafClientMac;
    byte leafMsgType;
    log.debug("client mac {} client vlan {}", HexString.toHexString(srcMac.toBytes(), ":"), vlanId);
    Dhcp6ClientIdOption clientIdOption = Dhcp6HandlerUtil.extractClientId(directConnFlag, dhcp6Packet);
    if (clientIdOption != null) {
        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. Don't create DhcpRelay Record.");
        // 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(leafHostId);
    } else {
        record = record.clone();
    }
    Boolean isMsgRelease = Dhcp6HandlerUtil.isDhcp6Release(dhcp6Packet);
    IpAddressInfo ipInfo;
    PdPrefixInfo pdInfo = null;
    if (directConnFlag) {
        // Add to host store if it is connected to network directly
        ipInfo = extractIpAddress(dhcp6Packet);
        if (ipInfo != null) {
            if (isMsgRelease) {
                HostId hostId = HostId.hostId(srcMac, vlanId);
                log.debug("remove Host {} ip for directly connected.", hostId.toString());
                providerService.removeIpFromHost(hostId, ipInfo.ip6Address);
            }
        } else {
            log.debug("ipAddress not found. Do not remove Host {} for directly connected.", HostId.hostId(srcMac, vlanId).toString());
        }
        leafMsgType = dhcp6Packet.getMsgType();
    } else {
        // Remove from route store if it is not connected 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(dhcp6Packet);
        ipInfo = extractIpAddress(leafDhcp);
        if (ipInfo == null) {
            log.debug("ip is null");
        } else {
            if (isMsgRelease) {
                Route routeForIP = new Route(Route.Source.DHCP, ipInfo.ip6Address.toIpPrefix(), nextHopIp);
                log.debug("removing route of 128 address for indirectly connected.");
                log.debug("128 ip {}, nexthop {}", HexString.toHexString(ipInfo.ip6Address.toOctets(), ":"), HexString.toHexString(nextHopIp.toOctets(), ":"));
                routeStore.removeRoute(routeForIP);
            }
        }
        pdInfo = extractPrefix(leafDhcp);
        if (pdInfo == null) {
            log.debug("ipPrefix is null ");
        } else {
            if (isMsgRelease) {
                Route routeForPrefix = new Route(Route.Source.DHCP, pdInfo.pdPrefix, nextHopIp);
                log.debug("removing route of PD for indirectly connected.");
                log.debug("pd ip {}, nexthop {}", HexString.toHexString(pdInfo.pdPrefix.address().toOctets(), ":"), HexString.toHexString(nextHopIp.toOctets(), ":"));
                routeStore.removeRoute(routeForPrefix);
                if (this.dhcpFpmEnabled) {
                    dhcpFpmPrefixStore.removeFpmRecord(pdInfo.pdPrefix);
                }
            }
        }
        leafMsgType = leafDhcp.getMsgType();
    }
    if (isMsgRelease) {
        log.debug("DHCP6 RELEASE msg.");
        if (record != null) {
            if (ipInfo != null) {
                log.debug("DhcpRelay Record ip6Address is set to null.");
                record.ip6Address(null);
            }
            if (pdInfo != null) {
                log.debug("DhcpRelay Record pdPrefix is set to null.");
            }
            if (!record.ip6Address().isPresent() && !record.pdPrefix().isPresent()) {
                log.warn("IP6 address and IP6 PD both are null. Remove record.");
            // do not remove a record. Let timer task handler it.
            // dhcpRelayStore.removeDhcpRecord(HostId.hostId(leafClientMac, vlanId));
            }
        }
    }
    if (record != null) {
        record.getV6Counters().incrementCounter(Dhcp6HandlerUtil.getMsgTypeStr(leafMsgType));
        record.addLocation(new HostLocation(location, System.currentTimeMillis()));
        record.ip6Status(DHCP6.MsgType.getType(leafMsgType));
        record.setDirectlyConnected(directConnFlag);
        if (!directConnFlag) {
            // Update gateway mac address if the host is not directly connected
            record.nextHop(srcMac);
        }
        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 : DhcpRecord(org.onosproject.dhcprelay.store.DhcpRecord) MacAddress(org.onlab.packet.MacAddress) HostId(org.onosproject.net.HostId) HostLocation(org.onosproject.net.HostLocation) 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)

Example 2 with DHCP6

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

the class Dhcp6HandlerImpl method extractPrefix.

/**
 * extract from dhcp6 packet Prefix prefix provided by dhcp server.
 *
 * @param dhcp6 the dhcp6 payload
 * @return IpPrefix Prefix Delegation prefix, or null if not exists.
 */
private PdPrefixInfo extractPrefix(DHCP6 dhcp6) {
    log.debug("extractPrefix  enters {}", dhcp6);
    // extract prefix
    PdPrefixInfo pdPrefixInfo = new PdPrefixInfo();
    Ip6Address prefixAddress = null;
    // Extract IPv6 prefix from IA PD option
    Optional<Dhcp6IaPdOption> iaPdOption = dhcp6.getOptions().stream().filter(opt -> opt instanceof Dhcp6IaPdOption).map(opt -> (Dhcp6IaPdOption) opt).findFirst();
    Optional<Dhcp6IaPrefixOption> iaPrefixOption;
    if (iaPdOption.isPresent()) {
        log.debug("IA_PD option found {}", iaPdOption);
        iaPrefixOption = iaPdOption.get().getOptions().stream().filter(opt -> opt instanceof Dhcp6IaPrefixOption).map(opt -> (Dhcp6IaPrefixOption) opt).findFirst();
    } else {
        log.debug("IA_PD option NOT found");
        iaPrefixOption = Optional.empty();
    }
    if (iaPrefixOption.isPresent()) {
        log.debug("IAPrefix Option within IA_PD option found {}", iaPrefixOption);
        prefixAddress = iaPrefixOption.get().getIp6Prefix();
        int prefixLen = (int) iaPrefixOption.get().getPrefixLength();
        log.debug("Prefix length is  {} bits", prefixLen);
        pdPrefixInfo.pdPrefix = IpPrefix.valueOf(prefixAddress, prefixLen);
        pdPrefixInfo.prefTime = iaPrefixOption.get().getPreferredLifetime();
    } else {
        log.debug("Can't find IPv6 prefix from DHCPv6 {}", dhcp6);
        return null;
    }
    return pdPrefixInfo;
}
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) Ip6Address(org.onlab.packet.Ip6Address) Dhcp6IaPrefixOption(org.onlab.packet.dhcp.Dhcp6IaPrefixOption) Dhcp6IaPdOption(org.onlab.packet.dhcp.Dhcp6IaPdOption) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 3 with DHCP6

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

the class Dhcp6HandlerImpl method timeTick.

/**
 * Find lease-expired ipaddresses and pd prefixes.
 * Removing host/route/fpm entries.
 */
public void timeTick() {
    long currentTime = System.currentTimeMillis();
    Collection<DhcpRecord> records = dhcpRelayStore.getDhcpRecords();
    log.debug("timeTick called currenttime {} records num {} ", currentTime, records.size());
    records.forEach(record -> {
        boolean addrOrPdRemoved = false;
        DHCP6.MsgType ip6Status = record.ip6Status().orElse(null);
        if (ip6Status == null) {
            log.debug("record is not valid v6 record.");
            return;
        }
        if ((currentTime - record.getLastIp6Update()) > ((record.addrPrefTime() + getDhcp6PollInterval() / 2) * 1000)) {
            // remove ipaddress from host/route table
            IpAddress ip = record.ip6Address().orElse(null);
            if (ip != null) {
                if (record.directlyConnected()) {
                    providerService.removeIpFromHost(HostId.hostId(record.macAddress(), record.vlanId()), ip);
                } else {
                    MacAddress gwMac = record.nextHop().orElse(null);
                    if (gwMac == null) {
                        log.warn("Can't find gateway mac address from record {} for ip6Addr", record);
                        return;
                    }
                    IpAddress nextHopIp = getFirstIpByHost(record.directlyConnected(), gwMac, record.vlanId());
                    Route route = new Route(Route.Source.DHCP, ip.toIpPrefix(), nextHopIp);
                    routeStore.removeRoute(route);
                }
                record.updateAddrPrefTime(0);
                record.ip6Address(null);
                addrOrPdRemoved = true;
                dhcpRelayStore.updateDhcpRecord(HostId.hostId(record.macAddress(), record.vlanId()), record);
                log.warn("IP6 address is set to null. delta {} lastUpdate {} addrPrefTime {}", (currentTime - record.getLastIp6Update()), record.getLastIp6Update(), record.addrPrefTime());
            }
        }
        if ((currentTime - record.getLastPdUpdate()) > ((record.pdPrefTime() + getDhcp6PollInterval() / 2) * 1000)) {
            // remove PD from route/fpm table
            IpPrefix pdIpPrefix = record.pdPrefix().orElse(null);
            if (pdIpPrefix != null) {
                if (record.directlyConnected()) {
                    providerService.removeIpFromHost(HostId.hostId(record.macAddress(), record.vlanId()), pdIpPrefix.address().getIp6Address());
                } else {
                    MacAddress gwMac = record.nextHop().orElse(null);
                    if (gwMac == null) {
                        log.warn("Can't find gateway mac address from record {} for PD prefix", record);
                        return;
                    }
                    IpAddress nextHopIp = getFirstIpByHost(record.directlyConnected(), gwMac, record.vlanId());
                    Route route = new Route(Route.Source.DHCP, pdIpPrefix, nextHopIp);
                    routeStore.removeRoute(route);
                    if (this.dhcpFpmEnabled) {
                        dhcpFpmPrefixStore.removeFpmRecord(pdIpPrefix);
                    }
                }
                record.updatePdPrefTime(0);
                record.pdPrefix(null);
                addrOrPdRemoved = true;
                dhcpRelayStore.updateDhcpRecord(HostId.hostId(record.macAddress(), record.vlanId()), record);
                log.warn("PD prefix is set to null.delta {} pdPrefTime {}", (currentTime - record.getLastPdUpdate()), record.pdPrefTime());
            }
        }
        if (addrOrPdRemoved && !record.ip6Address().isPresent() && !record.pdPrefix().isPresent()) {
            log.warn("ip6Status {} IP6 address and IP6 PD both are null. Remove record.", ip6Status);
            dhcpRelayStore.removeDhcpRecord(HostId.hostId(record.macAddress(), record.vlanId()));
        }
    });
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) DhcpRecord(org.onosproject.dhcprelay.store.DhcpRecord) MsgType(org.onlab.packet.DHCP6.MsgType) DHCP6(org.onlab.packet.DHCP6) IpAddress(org.onlab.packet.IpAddress) MacAddress(org.onlab.packet.MacAddress) Route(org.onosproject.routeservice.Route)

Example 4 with DHCP6

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

the class Dhcp6HandlerUtil method getDhcp6Leaf.

/**
 * find the leaf DHCP6 packet from multi-level relay packet.
 *
 * @param relayPacket dhcp6 relay packet
 * @return leafPacket non-relay dhcp6 packet
 */
public static DHCP6 getDhcp6Leaf(DHCP6 relayPacket) {
    DHCP6 dhcp6Parent = relayPacket;
    DHCP6 dhcp6Child = null;
    log.debug("getDhcp6Leaf entered.");
    while (dhcp6Parent != null) {
        dhcp6Child = dhcp6PacketFromRelayPacket(dhcp6Parent);
        if (dhcp6Child != null) {
            if (dhcp6Child.getMsgType() != DHCP6.MsgType.RELAY_FORW.value() && dhcp6Child.getMsgType() != DHCP6.MsgType.RELAY_REPL.value()) {
                log.debug("leaf dhcp6 packet found.");
                break;
            } else {
                // found another relay, go for another loop
                dhcp6Parent = dhcp6Child;
            }
        } else {
            log.debug("Expected dhcp6 within relay pkt, but no dhcp6 leaf found.");
            break;
        }
    }
    return dhcp6Child;
}
Also used : DHCP6(org.onlab.packet.DHCP6)

Example 5 with DHCP6

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

the class Dhcp6HandlerUtil method processLQ6PacketFromServer.

/**
 * process the LQ reply packet from dhcp server.
 *
 * @param defaultServerInfoList default server list
 * @param indirectServerInfoList default indirect server list
 * @param serverInterface server interface
 * @param interfaceService interface service
 * @param hostService host service
 * @param context packet context
 * @param receivedPacket server ethernet packet
 * @param recevingInterfaces set of server side interfaces
 * @return a packet ready to be sent to relevant output interface
 */
public static InternalPacket processLQ6PacketFromServer(List<DhcpServerInfo> defaultServerInfoList, List<DhcpServerInfo> indirectServerInfoList, Interface serverInterface, InterfaceService interfaceService, HostService hostService, PacketContext context, Ethernet receivedPacket, Set<Interface> recevingInterfaces) {
    // get dhcp6 header.
    Ethernet etherReply = (Ethernet) receivedPacket.clone();
    IPv6 ipv6Packet = (IPv6) etherReply.getPayload();
    UDP udpPacket = (UDP) ipv6Packet.getPayload();
    DHCP6 lq6Reply = (DHCP6) udpPacket.getPayload();
    // TODO: refactor
    ConnectPoint receivedFrom = context.inPacket().receivedFrom();
    DeviceId receivedFromDevice = receivedFrom.deviceId();
    DhcpServerInfo serverInfo;
    Ip6Address dhcpServerIp = null;
    ConnectPoint dhcpServerConnectPoint = null;
    MacAddress dhcpConnectMac = null;
    VlanId dhcpConnectVlan = null;
    Ip6Address dhcpGatewayIp = null;
    // todo: refactor
    Ip6Address indirectDhcpServerIp = null;
    ConnectPoint indirectDhcpServerConnectPoint = null;
    MacAddress indirectDhcpConnectMac = null;
    VlanId indirectDhcpConnectVlan = null;
    Ip6Address indirectDhcpGatewayIp = null;
    Ip6Address indirectRelayAgentIpFromCfg = null;
    if (!defaultServerInfoList.isEmpty()) {
        serverInfo = defaultServerInfoList.get(0);
        dhcpConnectMac = serverInfo.getDhcpConnectMac().orElse(null);
        dhcpGatewayIp = serverInfo.getDhcpGatewayIp6().orElse(null);
        dhcpServerIp = serverInfo.getDhcpServerIp6().orElse(null);
        dhcpServerConnectPoint = serverInfo.getDhcpServerConnectPoint().orElse(null);
        dhcpConnectVlan = serverInfo.getDhcpConnectVlan().orElse(null);
    }
    if (!indirectServerInfoList.isEmpty()) {
        serverInfo = indirectServerInfoList.get(0);
        indirectDhcpConnectMac = serverInfo.getDhcpConnectMac().orElse(null);
        indirectDhcpGatewayIp = serverInfo.getDhcpGatewayIp6().orElse(null);
        indirectDhcpServerIp = serverInfo.getDhcpServerIp6().orElse(null);
        indirectDhcpServerConnectPoint = serverInfo.getDhcpServerConnectPoint().orElse(null);
        indirectDhcpConnectVlan = serverInfo.getDhcpConnectVlan().orElse(null);
        indirectRelayAgentIpFromCfg = serverInfo.getRelayAgentIp6(receivedFromDevice).orElse(null);
    }
    Boolean directConnFlag = directlyConnected(lq6Reply);
    ConnectPoint inPort = context.inPacket().receivedFrom();
    if ((directConnFlag || indirectDhcpServerIp == null) && !inPort.equals(dhcpServerConnectPoint)) {
        log.warn("Receiving port {} is not the same as server connect point {} for direct or indirect-null", inPort, dhcpServerConnectPoint);
        return null;
    }
    if (!directConnFlag && indirectDhcpServerIp != null && !inPort.equals(indirectDhcpServerConnectPoint)) {
        log.warn("Receiving port {} is not the same as server connect point {} for indirect", inPort, indirectDhcpServerConnectPoint);
        return null;
    }
    Ip6Address nextHopIP = Ip6Address.valueOf(ipv6Packet.getDestinationAddress());
    // use hosts store to find out the next hop mac and connection point
    Set<Host> hosts = hostService.getHostsByIp(nextHopIP);
    Host host;
    if (!hosts.isEmpty()) {
        host = hosts.iterator().next();
    } else {
        log.warn("Host {} is not in store", nextHopIP);
        return null;
    }
    HostLocation hl = host.location();
    // iterator().next());
    String clientConnectionPointStr = hl.toString();
    ConnectPoint clientConnectionPoint = ConnectPoint.deviceConnectPoint(clientConnectionPointStr);
    VlanId originalPacketVlanId = VlanId.vlanId(etherReply.getVlanID());
    Interface iface;
    iface = interfaceService.getInterfacesByPort(clientConnectionPoint).stream().filter(iface1 -> interfaceContainsVlan(iface1, originalPacketVlanId)).findFirst().orElse(null);
    etherReply.setSourceMACAddress(iface.mac());
    etherReply.setDestinationMACAddress(host.mac());
    // workaround for a bug where core sends src port as 547 (server)
    udpPacket.setDestinationPort(UDP.DHCP_V6_SERVER_PORT);
    udpPacket.setPayload(lq6Reply);
    udpPacket.resetChecksum();
    ipv6Packet.setPayload(udpPacket);
    etherReply.setPayload(ipv6Packet);
    return InternalPacket.internalPacket(etherReply, clientConnectionPoint);
}
Also used : UDP(org.onlab.packet.UDP) HostLocation(org.onosproject.net.HostLocation) Host(org.onosproject.net.Host) Interface(org.onosproject.net.intf.Interface) LoggerFactory(org.slf4j.LoggerFactory) InterfaceService(org.onosproject.net.intf.InterfaceService) HostService(org.onosproject.net.host.HostService) Dhcp6ClientIdOption(org.onlab.packet.dhcp.Dhcp6ClientIdOption) Dhcp6RelayOption(org.onlab.packet.dhcp.Dhcp6RelayOption) ConnectPoint(org.onosproject.net.ConnectPoint) ArrayList(java.util.ArrayList) Ethernet(org.onlab.packet.Ethernet) DhcpRelayCounters(org.onosproject.dhcprelay.store.DhcpRelayCounters) IpAddress(org.onlab.packet.IpAddress) BasePacket(org.onlab.packet.BasePacket) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo) Ip6Address(org.onlab.packet.Ip6Address) Logger(org.slf4j.Logger) VlanId(org.onlab.packet.VlanId) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Dhcp6Option(org.onlab.packet.dhcp.Dhcp6Option) Set(java.util.Set) MsgType(org.onlab.packet.DHCP6.MsgType) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) UDP(org.onlab.packet.UDP) IPv6(org.onlab.packet.IPv6) DHCP6(org.onlab.packet.DHCP6) List(java.util.List) HexString(org.onlab.util.HexString) PacketContext(org.onosproject.net.packet.PacketContext) MacAddress(org.onlab.packet.MacAddress) DeviceId(org.onosproject.net.DeviceId) IPv6(org.onlab.packet.IPv6) DeviceId(org.onosproject.net.DeviceId) 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) HostLocation(org.onosproject.net.HostLocation) DHCP6(org.onlab.packet.DHCP6) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo) VlanId(org.onlab.packet.VlanId) Interface(org.onosproject.net.intf.Interface)

Aggregations

DHCP6 (org.onlab.packet.DHCP6)34 Ethernet (org.onlab.packet.Ethernet)26 IPv6 (org.onlab.packet.IPv6)19 UDP (org.onlab.packet.UDP)19 Test (org.junit.Test)16 MacAddress (org.onlab.packet.MacAddress)11 Ip6Address (org.onlab.packet.Ip6Address)9 IpAddress (org.onlab.packet.IpAddress)9 VlanId (org.onlab.packet.VlanId)9 ConnectPoint (org.onosproject.net.ConnectPoint)9 ArrayList (java.util.ArrayList)8 MsgType (org.onlab.packet.DHCP6.MsgType)8 Dhcp6ClientIdOption (org.onlab.packet.dhcp.Dhcp6ClientIdOption)8 HostLocation (org.onosproject.net.HostLocation)8 Interface (org.onosproject.net.intf.Interface)8 BasePacket (org.onlab.packet.BasePacket)7 Dhcp6RelayOption (org.onlab.packet.dhcp.Dhcp6RelayOption)7 DhcpServerInfo (org.onosproject.dhcprelay.api.DhcpServerInfo)7 DhcpRecord (org.onosproject.dhcprelay.store.DhcpRecord)7 Host (org.onosproject.net.Host)7