Search in sources :

Example 76 with MacAddress

use of org.onlab.packet.MacAddress 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)

Example 77 with MacAddress

use of org.onlab.packet.MacAddress 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 78 with MacAddress

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

the class Dhcp4HandlerImpl method getClientInterface.

/**
 * Gets output interface of a dhcp packet.
 * If option 82 exists in the dhcp packet and the option was sent by
 * ONOS (circuit format is correct), use the connect
 * point and vlan id from circuit id; otherwise, find host by destination
 * address and use vlan id from sender (dhcp server).
 *
 * @param ethPacket the ethernet packet
 * @param dhcpPayload the dhcp packet
 * @return an interface represent the output port and vlan; empty value
 *         if the host or circuit id not found
 */
private Optional<Interface> getClientInterface(Ethernet ethPacket, DHCP dhcpPayload) {
    VlanId originalPacketVlanId = VlanId.vlanId(ethPacket.getVlanID());
    DhcpRelayAgentOption option = (DhcpRelayAgentOption) dhcpPayload.getOption(OptionCode_CircuitID);
    DhcpOption circuitIdSubOption = option.getSubOption(CIRCUIT_ID.getValue());
    try {
        CircuitId circuitId = CircuitId.deserialize(circuitIdSubOption.getData());
        ConnectPoint connectPoint = ConnectPoint.deviceConnectPoint(circuitId.connectPoint());
        VlanId vlanId = circuitId.vlanId();
        return interfaceService.getInterfacesByPort(connectPoint).stream().filter(iface -> interfaceContainsVlan(iface, vlanId)).findFirst();
    } catch (IllegalArgumentException ex) {
        // invalid circuit format, didn't sent by ONOS
        log.debug("Invalid circuit {}, use information from dhcp payload", circuitIdSubOption.getData());
    }
    // Use Vlan Id from DHCP server if DHCP relay circuit id was not
    // sent by ONOS or circuit Id can't be parsed
    // TODO: remove relay store from this method
    MacAddress dstMac = valueOf(dhcpPayload.getClientHardwareAddress());
    VlanId filteredVlanId = getVlanIdFromDhcpRecord(dstMac, originalPacketVlanId);
    // Get the vlan from the dhcp record
    if (filteredVlanId == null) {
        log.debug("not find the matching DHCP record for mac: {} and vlan: {}", dstMac, originalPacketVlanId);
        return Optional.empty();
    }
    Optional<DhcpRecord> dhcpRecord = dhcpRelayStore.getDhcpRecord(HostId.hostId(dstMac, filteredVlanId));
    ConnectPoint clientConnectPoint = dhcpRecord.map(DhcpRecord::locations).orElse(Collections.emptySet()).stream().reduce((hl1, hl2) -> {
        // find latest host connect point
        if (hl1 == null || hl2 == null) {
            return hl1 == null ? hl2 : hl1;
        }
        return hl1.time() > hl2.time() ? hl1 : hl2;
    }).orElse(null);
    if (clientConnectPoint != null) {
        return interfaceService.getInterfacesByPort(clientConnectPoint).stream().filter(iface -> interfaceContainsVlan(iface, filteredVlanId)).findFirst();
    }
    return Optional.empty();
}
Also used : DeviceService(org.onosproject.net.device.DeviceService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) OptionCode_END(org.onlab.packet.DHCP.DHCPOptionCode.OptionCode_END) IgnoreDhcpConfig(org.onosproject.dhcprelay.config.IgnoreDhcpConfig) Port(org.onosproject.net.Port) ApplicationId(org.onosproject.core.ApplicationId) DhcpRelayStore(org.onosproject.dhcprelay.store.DhcpRelayStore) Ip4Address(org.onlab.packet.Ip4Address) Deactivate(org.osgi.service.component.annotations.Deactivate) OptionCode_MessageType(org.onlab.packet.DHCP.DHCPOptionCode.OptionCode_MessageType) Set(java.util.Set) MacAddress.valueOf(org.onlab.packet.MacAddress.valueOf) PacketService(org.onosproject.net.packet.PacketService) DhcpServerConfig(org.onosproject.dhcprelay.config.DhcpServerConfig) DeviceId(org.onosproject.net.DeviceId) 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) HostProviderRegistry(org.onosproject.net.host.HostProviderRegistry) Tools(org.onlab.util.Tools) Host(org.onosproject.net.Host) RouteStore(org.onosproject.routeservice.RouteStore) 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) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) CIRCUIT_ID(org.onlab.packet.dhcp.DhcpRelayAgentOption.RelayAgentInfoOptions.CIRCUIT_ID) OptionCode_CircuitID(org.onlab.packet.DHCP.DHCPOptionCode.OptionCode_CircuitID) CircuitId(org.onlab.packet.dhcp.CircuitId) DhcpRelayAgentOption(org.onlab.packet.dhcp.DhcpRelayAgentOption) 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) IPv4(org.onlab.packet.IPv4) DhcpRecord(org.onosproject.dhcprelay.store.DhcpRecord) Objective(org.onosproject.net.flowobjective.Objective) MacAddress(org.onlab.packet.MacAddress) DHCP(org.onlab.packet.DHCP) 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) ByteBuffer(java.nio.ByteBuffer) Ethernet(org.onlab.packet.Ethernet) HostProviderService(org.onosproject.net.host.HostProviderService) HashMultimap(com.google.common.collect.HashMultimap) 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) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) Collectors(java.util.stream.Collectors) 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) ADD(org.onosproject.net.flowobjective.Objective.Operation.ADD) Multimap(com.google.common.collect.Multimap) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) OutboundPacket(org.onosproject.net.packet.OutboundPacket) HostEvent(org.onosproject.net.host.HostEvent) Activate(org.osgi.service.component.annotations.Activate) HostId(org.onosproject.net.HostId) IpAddress(org.onlab.packet.IpAddress) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) UDP(org.onlab.packet.UDP) DhcpHandler(org.onosproject.dhcprelay.api.DhcpHandler) DhcpOption(org.onlab.packet.dhcp.DhcpOption) 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) Collections(java.util.Collections) DhcpRelayAgentOption(org.onlab.packet.dhcp.DhcpRelayAgentOption) CircuitId(org.onlab.packet.dhcp.CircuitId) DhcpOption(org.onlab.packet.dhcp.DhcpOption) DhcpRecord(org.onosproject.dhcprelay.store.DhcpRecord) MacAddress(org.onlab.packet.MacAddress) ConnectPoint(org.onosproject.net.ConnectPoint) VlanId(org.onlab.packet.VlanId)

Example 79 with MacAddress

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

the class Dhcp4HandlerImpl method writeResponseDhcpRecord.

/**
 * Writes DHCP record to the store according to the response DHCP packet (Offer, Ack).
 *
 * @param ethernet the DHCP packet
 * @param dhcpPayload the DHCP payload
 */
private void writeResponseDhcpRecord(Ethernet ethernet, DHCP dhcpPayload) {
    Optional<Interface> outInterface = getClientInterface(ethernet, dhcpPayload);
    if (!outInterface.isPresent()) {
        log.warn("Failed to determine where to send {}", dhcpPayload.getPacketType());
        return;
    }
    Interface outIface = outInterface.get();
    ConnectPoint location = outIface.connectPoint();
    if (!location.port().hasName()) {
        location = translateSwitchPort(location);
    }
    VlanId vlanId = getVlanIdFromRelayAgentOption(dhcpPayload);
    if (vlanId == null) {
        vlanId = outIface.vlan();
    }
    MacAddress macAddress = MacAddress.valueOf(dhcpPayload.getClientHardwareAddress());
    HostId hostId = HostId.hostId(macAddress, vlanId);
    DhcpRecord record = dhcpRelayStore.getDhcpRecord(hostId).orElse(null);
    if (record == null) {
        record = new DhcpRecord(HostId.hostId(macAddress, vlanId));
    } else {
        record = record.clone();
    }
    record.addLocation(new HostLocation(location, System.currentTimeMillis()));
    if (dhcpPayload.getPacketType() == DHCP.MsgType.DHCPACK) {
        record.ip4Address(Ip4Address.valueOf(dhcpPayload.getYourIPAddress()));
    }
    record.ip4Status(dhcpPayload.getPacketType());
    record.setDirectlyConnected(directlyConnected(dhcpPayload));
    record.updateLastSeen();
    dhcpRelayStore.updateDhcpRecord(HostId.hostId(macAddress, vlanId), record);
}
Also used : HostLocation(org.onosproject.net.HostLocation) DhcpRecord(org.onosproject.dhcprelay.store.DhcpRecord) MacAddress(org.onlab.packet.MacAddress) HostId(org.onosproject.net.HostId) ConnectPoint(org.onosproject.net.ConnectPoint) Interface(org.onosproject.net.intf.Interface) VlanId(org.onlab.packet.VlanId)

Example 80 with MacAddress

use of org.onlab.packet.MacAddress 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)

Aggregations

MacAddress (org.onlab.packet.MacAddress)139 IpAddress (org.onlab.packet.IpAddress)56 VlanId (org.onlab.packet.VlanId)49 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)42 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)42 ConnectPoint (org.onosproject.net.ConnectPoint)38 Host (org.onosproject.net.Host)33 Ethernet (org.onlab.packet.Ethernet)31 DeviceId (org.onosproject.net.DeviceId)29 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)29 TrafficSelector (org.onosproject.net.flow.TrafficSelector)29 HostLocation (org.onosproject.net.HostLocation)27 HostId (org.onosproject.net.HostId)26 Interface (org.onosproject.net.intf.Interface)26 Set (java.util.Set)24 Logger (org.slf4j.Logger)24 Device (org.onosproject.net.Device)22 DeviceService (org.onosproject.net.device.DeviceService)21 Activate (org.osgi.service.component.annotations.Activate)20 List (java.util.List)19