Search in sources :

Example 6 with DhcpServerInfo

use of org.onosproject.dhcprelay.api.DhcpServerInfo in project onos by opennetworkinglab.

the class Dhcp4HandlerImpl method findServerInfoFromServer.

private DhcpServerInfo findServerInfoFromServer(boolean directConnFlag, ConnectPoint inPort) {
    List<DhcpServerInfo> validServerInfoList = findValidServerInfo(directConnFlag);
    DhcpServerInfo foundServerInfo = null;
    for (DhcpServerInfo serverInfo : validServerInfoList) {
        if (inPort.equals(serverInfo.getDhcpServerConnectPoint().get())) {
            foundServerInfo = serverInfo;
            log.debug("ServerInfo found for Rcv port {} Server Connect Point {} for {}", inPort, serverInfo.getDhcpServerConnectPoint(), directConnFlag ? "direct" : "indirect");
            break;
        }
    }
    return foundServerInfo;
}
Also used : DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo)

Example 7 with DhcpServerInfo

use of org.onosproject.dhcprelay.api.DhcpServerInfo in project onos by opennetworkinglab.

the class Dhcp4HandlerImpl method getHostInfoForServerInfo.

/**
 * Checks if serverInfo's host info (mac and vlan) is filled in; if not, fills in.
 *
 * @param serverInfo server information
 * @return newServerInfo if host info can be either found or filled in.
 */
private DhcpServerInfo getHostInfoForServerInfo(DhcpServerInfo serverInfo, List<DhcpServerInfo> sererInfoList) {
    DhcpServerInfo newServerInfo = null;
    MacAddress dhcpServerConnectMac = serverInfo.getDhcpConnectMac().orElse(null);
    VlanId dhcpConnectVlan = serverInfo.getDhcpConnectVlan().orElse(null);
    ConnectPoint dhcpServerConnectPoint = serverInfo.getDhcpServerConnectPoint().orElse(null);
    if (dhcpServerConnectMac != null && dhcpConnectVlan != null) {
        newServerInfo = serverInfo;
        log.debug("DHCP server {} host info found. ConnectPt{}  Mac {} vlan {}", serverInfo.getDhcpServerIp4(), dhcpServerConnectPoint, dhcpServerConnectMac, dhcpConnectVlan);
    } else {
        log.debug("DHCP server {} not resolve yet connectPt {} mac {} vlan {}", serverInfo.getDhcpServerIp4(), dhcpServerConnectPoint, dhcpServerConnectMac, dhcpConnectVlan);
        Ip4Address ipToProbe;
        if (serverInfo.getDhcpGatewayIp4().isPresent()) {
            ipToProbe = serverInfo.getDhcpGatewayIp4().get();
        } else {
            ipToProbe = serverInfo.getDhcpServerIp4().orElse(null);
        }
        String hostToProbe = serverInfo.getDhcpGatewayIp6().map(ip -> "gateway").orElse("server");
        log.debug("Dynamically probing to resolve {} IP {}", hostToProbe, ipToProbe);
        hostService.startMonitoringIp(ipToProbe);
        Set<Host> hosts = hostService.getHostsByIp(ipToProbe);
        if (!hosts.isEmpty()) {
            int serverInfoIndex = sererInfoList.indexOf(serverInfo);
            Host host = hosts.iterator().next();
            serverInfo.setDhcpConnectVlan(host.vlan());
            serverInfo.setDhcpConnectMac(host.mac());
            // replace the serverInfo in the list
            sererInfoList.set(serverInfoIndex, serverInfo);
            newServerInfo = serverInfo;
            log.warn("Dynamically host found host {}", host);
        } else {
            log.debug("No host found host ip {} dynamically", ipToProbe);
        }
    }
    return newServerInfo;
}
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) Ip4Address(org.onlab.packet.Ip4Address) Host(org.onosproject.net.Host) MacAddress(org.onlab.packet.MacAddress) ConnectPoint(org.onosproject.net.ConnectPoint) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo) VlanId(org.onlab.packet.VlanId) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 8 with DhcpServerInfo

use of org.onosproject.dhcprelay.api.DhcpServerInfo in project onos by opennetworkinglab.

the class DhcpRelayWebResource method getDefaultDhcpServers.

/**
 * To get the list of default dhcp servers.
 *
 * @return node type ObjectNode.
 */
private ArrayNode getDefaultDhcpServers() {
    ObjectNode node = mapper().createObjectNode();
    DhcpRelayService dhcpDelayService = get(DhcpRelayService.class);
    List<DhcpServerInfo> defaultDhcpServerInfoList = dhcpDelayService.getDefaultDhcpServerInfoList();
    ArrayNode defaultDhcpServers = listServers(defaultDhcpServerInfoList);
    return defaultDhcpServers;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DhcpRelayService(org.onosproject.dhcprelay.api.DhcpRelayService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo)

Example 9 with DhcpServerInfo

use of org.onosproject.dhcprelay.api.DhcpServerInfo in project onos by opennetworkinglab.

the class DhcpRelayWebResource method listServers.

/**
 * To get the liset of dhcp servers.
 *
 * @param dhcpServerInfoList type List
 * @return servers type ArrayNode.
 */
private ArrayNode listServers(List<DhcpServerInfo> dhcpServerInfoList) {
    ArrayNode servers = mapper().createArrayNode();
    dhcpServerInfoList.forEach(dhcpServerInfo -> {
        ObjectNode serverNode = mapper().createObjectNode();
        String connectPoint = dhcpServerInfo.getDhcpServerConnectPoint().map(cp -> cp.toString()).orElse(NA);
        String serverMac = dhcpServerInfo.getDhcpConnectMac().map(mac -> mac.toString()).orElse(NA);
        String gatewayAddress;
        String serverIp;
        switch(dhcpServerInfo.getVersion()) {
            case DHCP_V4:
                gatewayAddress = dhcpServerInfo.getDhcpGatewayIp4().map(gw -> gw.toString()).orElse(null);
                serverIp = dhcpServerInfo.getDhcpServerIp4().map(ip -> ip.toString()).orElse(NA);
                break;
            case DHCP_V6:
                gatewayAddress = dhcpServerInfo.getDhcpGatewayIp6().map(gw -> gw.toString()).orElse(null);
                serverIp = dhcpServerInfo.getDhcpServerIp6().map(ip -> ip.toString()).orElse(NA);
                break;
            default:
                return;
        }
        serverNode.put("connectPoint", connectPoint);
        if (gatewayAddress != null) {
            serverNode.put("server", serverIp.concat(" via ").concat(gatewayAddress));
        } else {
            serverNode.put("server", serverIp);
        }
        serverNode.put("mac", serverMac);
        servers.add(serverNode);
    });
    return servers;
}
Also used : Route(org.onosproject.routeservice.Route) PathParam(javax.ws.rs.PathParam) AbstractWebResource(org.onosproject.rest.AbstractWebResource) Produces(javax.ws.rs.Produces) Tools(org.onlab.util.Tools) RouteStore(org.onosproject.routeservice.RouteStore) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DhcpRelayCountersStore(org.onosproject.dhcprelay.store.DhcpRelayCountersStore) MediaType(javax.ws.rs.core.MediaType) Map(java.util.Map) DhcpRelayCommand(org.onosproject.dhcprelay.cli.DhcpRelayCommand) DhcpRelayCounters(org.onosproject.dhcprelay.store.DhcpRelayCounters) FpmRecord(org.onosproject.routing.fpm.api.FpmRecord) IpAddress(org.onlab.packet.IpAddress) DELETE(javax.ws.rs.DELETE) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo) Logger(org.slf4j.Logger) Collection(java.util.Collection) DhcpRelayService(org.onosproject.dhcprelay.api.DhcpRelayService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) List(java.util.List) Response(javax.ws.rs.core.Response) DhcpRecord(org.onosproject.dhcprelay.store.DhcpRecord) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) IpPrefix(org.onlab.packet.IpPrefix) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 10 with DhcpServerInfo

use of org.onosproject.dhcprelay.api.DhcpServerInfo in project onos by opennetworkinglab.

the class DhcpRelayWebResource method getIndirectDhcpServers.

/**
 * To get the list of indirect dhcp servers.
 *
 * @return node type ObjectNode.
 */
private ArrayNode getIndirectDhcpServers() {
    DhcpRelayService dhcpDelayService = get(DhcpRelayService.class);
    List<DhcpServerInfo> indirectDhcpServerInfoList = dhcpDelayService.getIndirectDhcpServerInfoList();
    ArrayNode indirectDhcpServers = listServers(indirectDhcpServerInfoList);
    return indirectDhcpServers;
}
Also used : DhcpRelayService(org.onosproject.dhcprelay.api.DhcpRelayService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo)

Aggregations

DhcpServerInfo (org.onosproject.dhcprelay.api.DhcpServerInfo)22 ConnectPoint (org.onosproject.net.ConnectPoint)16 Ethernet (org.onlab.packet.Ethernet)14 VlanId (org.onlab.packet.VlanId)14 Interface (org.onosproject.net.intf.Interface)14 ArrayList (java.util.ArrayList)13 MacAddress (org.onlab.packet.MacAddress)13 UDP (org.onlab.packet.UDP)13 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)12 IpAddress (org.onlab.packet.IpAddress)12 DhcpRecord (org.onosproject.dhcprelay.store.DhcpRecord)12 List (java.util.List)11 DeviceId (org.onosproject.net.DeviceId)11 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)10 Collection (java.util.Collection)10 Optional (java.util.Optional)10 Set (java.util.Set)10 BasePacket (org.onlab.packet.BasePacket)10 Tools (org.onlab.util.Tools)10 Preconditions.checkState (com.google.common.base.Preconditions.checkState)9