Search in sources :

Example 1 with DhcpServerConfig

use of org.onosproject.dhcprelay.config.DhcpServerConfig in project onos by opennetworkinglab.

the class Dhcp4HandlerImpl method setDhcpServerConfigs.

public void setDhcpServerConfigs(Collection<DhcpServerConfig> configs, List<DhcpServerInfo> serverInfoList) {
    if (configs.size() == 0) {
        // no config to update
        return;
    }
    Boolean isConfigValid = false;
    for (DhcpServerConfig serverConfig : configs) {
        if (serverConfig.getDhcpServerIp4().isPresent()) {
            isConfigValid = true;
            break;
        }
    }
    if (!isConfigValid) {
        log.warn("No IP V4 server address found.");
        // No IP V6 address found
        return;
    }
    // if (!serverInfoList.isEmpty()) {
    for (DhcpServerInfo oldServerInfo : serverInfoList) {
        log.info("In for (DhcpServerInfo oldServerInfo : serverInfoList) {");
        // remove old server info
        // DhcpServerInfo oldServerInfo = serverInfoList.remove(0);
        // stop monitoring gateway or server
        oldServerInfo.getDhcpGatewayIp4().ifPresent(gatewayIp -> {
            hostService.stopMonitoringIp(gatewayIp);
        });
        oldServerInfo.getDhcpServerIp4().ifPresent(serverIp -> {
            hostService.stopMonitoringIp(serverIp);
            cancelDhcpPacket(serverIp);
        });
    }
    // Create new server info according to the config
    serverInfoList.clear();
    for (DhcpServerConfig serverConfig : configs) {
        log.debug("Create new server info according to the config");
        DhcpServerInfo newServerInfo = new DhcpServerInfo(serverConfig, DhcpServerInfo.Version.DHCP_V4);
        checkState(newServerInfo.getDhcpServerConnectPoint().isPresent(), "Connect point not exists");
        checkState(newServerInfo.getDhcpServerIp4().isPresent(), "IP of DHCP server not exists");
        log.debug("DHCP server connect point: {}", newServerInfo.getDhcpServerConnectPoint().orElse(null));
        log.debug("DHCP server IP: {}", newServerInfo.getDhcpServerIp4().orElse(null));
        Ip4Address serverIp = newServerInfo.getDhcpServerIp4().get();
        Ip4Address ipToProbe;
        if (newServerInfo.getDhcpGatewayIp4().isPresent()) {
            ipToProbe = newServerInfo.getDhcpGatewayIp4().get();
        } else {
            ipToProbe = newServerInfo.getDhcpServerIp4().orElse(null);
        }
        log.info("Probe_IP {}", ipToProbe);
        String hostToProbe = newServerInfo.getDhcpGatewayIp4().map(ip -> "gateway").orElse("server");
        log.debug("Probing to resolve {} IP {}", hostToProbe, ipToProbe);
        hostService.startMonitoringIp(ipToProbe);
        Set<Host> hosts = hostService.getHostsByIp(ipToProbe);
        if (!hosts.isEmpty()) {
            Host host = hosts.iterator().next();
            newServerInfo.setDhcpConnectVlan(host.vlan());
            newServerInfo.setDhcpConnectMac(host.mac());
        }
        // Add new server info
        synchronized (this) {
            // serverInfoList.clear();
            serverInfoList.add(newServerInfo);
        }
        requestDhcpPacket(serverIp);
    }
}
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) DhcpServerConfig(org.onosproject.dhcprelay.config.DhcpServerConfig) Ip4Address(org.onlab.packet.Ip4Address) Host(org.onosproject.net.Host) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo)

Example 2 with DhcpServerConfig

use of org.onosproject.dhcprelay.config.DhcpServerConfig in project onos by opennetworkinglab.

the class Dhcp6HandlerImpl method setDhcpServerConfigs.

public void setDhcpServerConfigs(Collection<DhcpServerConfig> configs, List<DhcpServerInfo> serverInfoList) {
    log.debug("config size {}.", configs.size());
    if (configs.size() == 0) {
        // no config to update
        return;
    }
    // TODO: currently we pick up first DHCP server config.
    // Will use other server configs in the future for HA.
    Boolean isConfigValid = false;
    for (DhcpServerConfig serverConfig : configs) {
        if (serverConfig.getDhcpServerIp6().isPresent()) {
            isConfigValid = true;
            break;
        }
    }
    if (!isConfigValid) {
        log.warn("No IP V6 server address found.");
        // No IP V6 address found
        return;
    }
    for (DhcpServerInfo oldServerInfo : serverInfoList) {
        // stop monitoring gateway or server
        oldServerInfo.getDhcpGatewayIp6().ifPresent(gatewayIp -> {
            hostService.stopMonitoringIp(gatewayIp);
        });
        oldServerInfo.getDhcpServerIp6().ifPresent(serverIp -> {
            hostService.stopMonitoringIp(serverIp);
            cancelDhcpPacket(serverIp);
        });
    }
    serverInfoList.clear();
    for (DhcpServerConfig serverConfig : configs) {
        // Create new server info according to the config
        DhcpServerInfo newServerInfo = new DhcpServerInfo(serverConfig, DhcpServerInfo.Version.DHCP_V6);
        checkState(newServerInfo.getDhcpServerConnectPoint().isPresent(), "Connect point not exists");
        checkState(newServerInfo.getDhcpServerIp6().isPresent(), "IP of DHCP server not exists");
        log.debug("DHCP server connect point: {}", newServerInfo.getDhcpServerConnectPoint().orElse(null));
        log.debug("DHCP server IP: {}", newServerInfo.getDhcpServerIp6().orElse(null));
        Ip6Address serverIp = newServerInfo.getDhcpServerIp6().get();
        Ip6Address ipToProbe;
        if (newServerInfo.getDhcpGatewayIp6().isPresent()) {
            ipToProbe = newServerInfo.getDhcpGatewayIp6().get();
        } else {
            ipToProbe = newServerInfo.getDhcpServerIp6().orElse(null);
        }
        String hostToProbe = newServerInfo.getDhcpGatewayIp6().map(ip -> "gateway").orElse("server");
        log.warn("Probing to resolve {} IP {}", hostToProbe, ipToProbe);
        hostService.startMonitoringIp(ipToProbe);
        Set<Host> hosts = hostService.getHostsByIp(ipToProbe);
        if (!hosts.isEmpty()) {
            Host host = hosts.iterator().next();
            newServerInfo.setDhcpConnectVlan(host.vlan());
            newServerInfo.setDhcpConnectMac(host.mac());
            log.warn("Host found host {}", host);
        } else {
            log.warn("No host found host ip {}", ipToProbe);
        }
        // Add new server info
        synchronized (this) {
            serverInfoList.add(newServerInfo);
        }
        if (!hosts.isEmpty()) {
            requestDhcpPacket(serverIp);
        }
    }
}
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) DhcpServerConfig(org.onosproject.dhcprelay.config.DhcpServerConfig) Host(org.onosproject.net.Host) HexString(org.onlab.util.HexString) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo)

Example 3 with DhcpServerConfig

use of org.onosproject.dhcprelay.config.DhcpServerConfig in project onos by opennetworkinglab.

the class DhcpRelayManager method getDhcpServerMacAddress.

@Override
public Optional<MacAddress> getDhcpServerMacAddress() {
    // TODO: depreated it
    DefaultDhcpRelayConfig config = cfgService.getConfig(appId, DefaultDhcpRelayConfig.class);
    DhcpServerConfig serverConfig = config.dhcpServerConfigs().get(0);
    Ip4Address serverip = serverConfig.getDhcpServerIp4().get();
    return hostService.getHostsByIp(serverip).stream().map(Host::mac).findFirst();
}
Also used : DhcpServerConfig(org.onosproject.dhcprelay.config.DhcpServerConfig) Ip4Address(org.onlab.packet.Ip4Address) DefaultDhcpRelayConfig(org.onosproject.dhcprelay.config.DefaultDhcpRelayConfig)

Aggregations

DhcpServerConfig (org.onosproject.dhcprelay.config.DhcpServerConfig)3 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)2 HashMultimap (com.google.common.collect.HashMultimap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Lists (com.google.common.collect.Lists)2 Multimap (com.google.common.collect.Multimap)2 Multimaps (com.google.common.collect.Multimaps)2 Sets (com.google.common.collect.Sets)2 ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Dictionary (java.util.Dictionary)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Executor (java.util.concurrent.Executor)2 Executors.newSingleThreadExecutor (java.util.concurrent.Executors.newSingleThreadExecutor)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2