Search in sources :

Example 1 with SubnetToDhcpPort

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710.subnet.dhcp.port.data.SubnetToDhcpPort in project netvirt by opendaylight.

the class DhcpPktHandler method onPacketReceived.

// TODO: Handle this in a separate thread
@Override
public void onPacketReceived(PacketReceived packet) {
    if (!config.isControllerDhcpEnabled()) {
        return;
    }
    Class<? extends PacketInReason> pktInReason = packet.getPacketInReason();
    short tableId = packet.getTableId().getValue();
    if ((tableId == NwConstants.DHCP_TABLE || tableId == NwConstants.DHCP_TABLE_EXTERNAL_TUNNEL) && isPktInReasonSendtoCtrl(pktInReason)) {
        byte[] inPayload = packet.getPayload();
        Ethernet ethPkt = new Ethernet();
        try {
            ethPkt.deserialize(inPayload, 0, inPayload.length * NetUtils.NUM_BITS_IN_A_BYTE);
        } catch (PacketException e) {
            LOG.warn("Failed to decode DHCP Packet.", e);
            LOG.trace("Received packet {}", packet);
            return;
        }
        DHCP pktIn;
        pktIn = getDhcpPktIn(ethPkt);
        if (pktIn != null) {
            LOG.trace("DHCPPkt received: {}", pktIn);
            LOG.trace("Received Packet: {}", packet);
            BigInteger metadata = packet.getMatch().getMetadata().getMetadata();
            long portTag = MetaDataUtil.getLportFromMetadata(metadata).intValue();
            String macAddress = DHCPUtils.byteArrayToString(ethPkt.getSourceMACAddress());
            BigInteger tunnelId = packet.getMatch().getTunnel() == null ? null : packet.getMatch().getTunnel().getTunnelId();
            String interfaceName = getInterfaceNameFromTag(portTag);
            InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfoFromOperationalDataStore(interfaceName);
            if (interfaceInfo == null) {
                LOG.error("Failed to get interface info for interface name {}", interfaceName);
                return;
            }
            Port port;
            if (tunnelId != null) {
                port = dhcpExternalTunnelManager.readVniMacToPortCache(tunnelId, macAddress);
            } else {
                port = getNeutronPort(interfaceName);
            }
            Subnet subnet = getNeutronSubnet(port);
            String serverMacAddress = interfaceInfo.getMacAddress();
            String serverIp = null;
            if (subnet != null) {
                java.util.Optional<SubnetToDhcpPort> dhcpPortData = DhcpServiceUtils.getSubnetDhcpPortData(broker, subnet.getUuid().getValue());
                /* If enable_dhcp_service flag was enabled and an ODL network DHCP Port data was made available use
                     * the ports Fixed IP as server IP for DHCP communication.
                     */
                if (dhcpPortData.isPresent()) {
                    serverIp = dhcpPortData.get().getPortFixedip();
                    serverMacAddress = dhcpPortData.get().getPortMacaddress();
                } else {
                    // DHCP Neutron Port not found for this network
                    LOG.error("Neutron DHCP port is not available for the Subnet {} and port {}.", subnet.getUuid(), port.getUuid());
                    return;
                }
            }
            DHCP replyPkt = handleDhcpPacket(pktIn, interfaceName, macAddress, port, subnet, serverIp);
            if (replyPkt == null) {
                LOG.warn("Unable to construct reply packet for interface name {}", interfaceName);
                return;
            }
            byte[] pktOut = getDhcpPacketOut(replyPkt, ethPkt, serverMacAddress);
            sendPacketOut(pktOut, interfaceInfo.getDpId(), interfaceName, tunnelId);
        }
    }
}
Also used : SubnetToDhcpPort(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710.subnet.dhcp.port.data.SubnetToDhcpPort) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) DHCP(org.opendaylight.netvirt.dhcpservice.api.DHCP) SubnetToDhcpPort(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710.subnet.dhcp.port.data.SubnetToDhcpPort) Ethernet(org.opendaylight.genius.mdsalutil.packet.Ethernet) BigInteger(java.math.BigInteger) InterfaceInfo(org.opendaylight.genius.interfacemanager.globals.InterfaceInfo) Subnet(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet)

Example 2 with SubnetToDhcpPort

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710.subnet.dhcp.port.data.SubnetToDhcpPort in project netvirt by opendaylight.

the class DhcpServiceUtils method createSubnetDhcpPortData.

@SuppressWarnings("checkstyle:IllegalCatch")
protected static void createSubnetDhcpPortData(Port port, BiConsumer<InstanceIdentifier<SubnetToDhcpPort>, SubnetToDhcpPort> consumer) {
    java.util.Optional<String> ip4Address = getIpV4Address(port);
    java.util.Optional<String> subnetId = getNeutronSubnetId(port);
    if (!(ip4Address.isPresent() && subnetId.isPresent())) {
        return;
    }
    LOG.trace("Adding SubnetPortData entry for subnet {}", subnetId.get());
    InstanceIdentifier<SubnetToDhcpPort> identifier = buildSubnetToDhcpPort(subnetId.get());
    SubnetToDhcpPort subnetToDhcpPort = getSubnetToDhcpPort(port, subnetId.get(), ip4Address.get());
    try {
        LOG.trace("Adding to SubnetToDhcpPort subnet {}  mac {}.", subnetId.get(), port.getMacAddress().getValue());
        consumer.accept(identifier, subnetToDhcpPort);
    } catch (Exception e) {
        LOG.error("Failure while creating SubnetToDhcpPort map for network {}.", port.getNetworkId(), e);
    }
}
Also used : SubnetToDhcpPort(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710.subnet.dhcp.port.data.SubnetToDhcpPort) UnknownHostException(java.net.UnknownHostException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)

Example 3 with SubnetToDhcpPort

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710.subnet.dhcp.port.data.SubnetToDhcpPort in project netvirt by opendaylight.

the class DhcpExternalTunnelManager method getSubnetDhcpPortData.

public java.util.Optional<SubnetToDhcpPort> getSubnetDhcpPortData(String elanInstanceName) {
    java.util.Optional<SubnetToDhcpPort> optSubnetDhcp = java.util.Optional.empty();
    Uuid nwUuid = new Uuid(elanInstanceName);
    List<Uuid> subnets = DhcpServiceUtils.getSubnetIdsFromNetworkId(broker, nwUuid);
    for (Uuid subnet : subnets) {
        if (DhcpServiceUtils.isIpv4Subnet(broker, subnet)) {
            optSubnetDhcp = DhcpServiceUtils.getSubnetDhcpPortData(broker, subnet.getValue());
            return optSubnetDhcp;
        }
    }
    return optSubnetDhcp;
}
Also used : SubnetToDhcpPort(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710.subnet.dhcp.port.data.SubnetToDhcpPort) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)

Example 4 with SubnetToDhcpPort

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710.subnet.dhcp.port.data.SubnetToDhcpPort in project netvirt by opendaylight.

the class DhcpInterfaceAddJob method call.

@Override
public List<ListenableFuture<Void>> call() {
    String interfaceName = interfaceAdd.getName();
    LOG.trace("Received add DCN for interface {}, dpid {}", interfaceName, dpnId);
    org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface = interfaceManager.getInterfaceInfoFromConfigDataStore(interfaceName);
    if (iface != null) {
        IfTunnel tunnelInterface = iface.getAugmentation(IfTunnel.class);
        if (tunnelInterface != null && !tunnelInterface.isInternal()) {
            IpAddress tunnelIp = tunnelInterface.getTunnelDestination();
            List<BigInteger> dpns = DhcpServiceUtils.getListOfDpns(dataBroker);
            if (dpns.contains(dpnId)) {
                return dhcpExternalTunnelManager.handleTunnelStateUp(tunnelIp, dpnId);
            }
            return Collections.emptyList();
        }
    }
    if (!dpnId.equals(DhcpMConstants.INVALID_DPID)) {
        Port port = dhcpManager.getNeutronPort(interfaceName);
        Subnet subnet = dhcpManager.getNeutronSubnet(port);
        if (null == subnet || !subnet.isEnableDhcp()) {
            LOG.debug("DHCP is not enabled for port {}", port.getName());
            return Collections.emptyList();
        }
        List<ListenableFuture<Void>> futures = new ArrayList<>();
        // Support for VM migration use cases.
        futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> DhcpServiceUtils.bindDhcpService(interfaceName, NwConstants.DHCP_TABLE, tx)));
        LOG.info("DhcpInterfaceEventListener add isEnableDhcp:{}", subnet.isEnableDhcp());
        futures.addAll(installDhcpEntries(interfaceAdd.getName(), dpnId));
        LOG.trace("Checking ElanDpnInterface {} for dpn {} ", interfaceName, dpnId);
        String subnetId = subnet.getUuid().getValue();
        java.util.Optional<SubnetToDhcpPort> subnetToDhcp = DhcpServiceUtils.getSubnetDhcpPortData(dataBroker, subnetId);
        if (!subnetToDhcp.isPresent()) {
            return Collections.emptyList();
        }
        LOG.trace("Installing the Arp responder for interface {} with DHCP MAC {} & IP {}.", interfaceName, subnetToDhcp.get().getPortMacaddress(), subnetToDhcp.get().getPortFixedip());
        ArpReponderInputBuilder builder = new ArpReponderInputBuilder();
        builder.setDpId(dpnId).setInterfaceName(interfaceName).setSpa(subnetToDhcp.get().getPortFixedip()).setSha(subnetToDhcp.get().getPortMacaddress()).setLportTag(interfaceAdd.getIfIndex());
        builder.setInstructions(ArpResponderUtil.getInterfaceInstructions(interfaceManager, interfaceName, subnetToDhcp.get().getPortFixedip(), subnetToDhcp.get().getPortMacaddress()));
        elanService.addArpResponderFlow(builder.buildForInstallFlow());
        return futures;
    }
    return Collections.emptyList();
}
Also used : ListenableFuture(com.google.common.util.concurrent.ListenableFuture) DhcpMConstants(org.opendaylight.netvirt.dhcpservice.api.DhcpMConstants) LoggerFactory(org.slf4j.LoggerFactory) Callable(java.util.concurrent.Callable) IElanService(org.opendaylight.netvirt.elanmanager.api.IElanService) DhcpExternalTunnelManager(org.opendaylight.netvirt.dhcpservice.DhcpExternalTunnelManager) ArrayList(java.util.ArrayList) IfTunnel(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel) DhcpServiceUtils(org.opendaylight.netvirt.dhcpservice.DhcpServiceUtils) ArpReponderInputBuilder(org.opendaylight.netvirt.elan.arp.responder.ArpResponderInput.ArpReponderInputBuilder) ArpResponderUtil(org.opendaylight.netvirt.elan.arp.responder.ArpResponderUtil) ManagedNewTransactionRunnerImpl(org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl) BigInteger(java.math.BigInteger) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) IInterfaceManager(org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager) Logger(org.slf4j.Logger) Subnet(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) DhcpManager(org.opendaylight.netvirt.dhcpservice.DhcpManager) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) List(java.util.List) SubnetToDhcpPort(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710.subnet.dhcp.port.data.SubnetToDhcpPort) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) Collections(java.util.Collections) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) SubnetToDhcpPort(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710.subnet.dhcp.port.data.SubnetToDhcpPort) ArrayList(java.util.ArrayList) IfTunnel(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel) SubnetToDhcpPort(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710.subnet.dhcp.port.data.SubnetToDhcpPort) ArpReponderInputBuilder(org.opendaylight.netvirt.elan.arp.responder.ArpResponderInput.ArpReponderInputBuilder) BigInteger(java.math.BigInteger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) Subnet(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet)

Example 5 with SubnetToDhcpPort

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710.subnet.dhcp.port.data.SubnetToDhcpPort in project netvirt by opendaylight.

the class DhcpInterfaceRemoveJob method call.

@Override
public List<ListenableFuture<Void>> call() {
    String interfaceName = interfaceDel.getName();
    org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface = interfaceManager.getInterfaceInfoFromConfigDataStore(interfaceName);
    if (iface != null) {
        IfTunnel tunnelInterface = iface.getAugmentation(IfTunnel.class);
        if (tunnelInterface != null && !tunnelInterface.isInternal()) {
            IpAddress tunnelIp = tunnelInterface.getTunnelDestination();
            List<BigInteger> dpns = DhcpServiceUtils.getListOfDpns(dataBroker);
            if (dpns.contains(dpnId)) {
                return dhcpExternalTunnelManager.handleTunnelStateDown(tunnelIp, dpnId);
            }
            return Collections.emptyList();
        }
    }
    List<ListenableFuture<Void>> futures = new ArrayList<>();
    // Support for VM migration use cases.
    futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> DhcpServiceUtils.unbindDhcpService(interfaceName, tx)));
    java.util.Optional<String> subnetId = DhcpServiceUtils.getNeutronSubnetId(port);
    if (subnetId.isPresent()) {
        java.util.Optional<SubnetToDhcpPort> subnetToDhcp = DhcpServiceUtils.getSubnetDhcpPortData(dataBroker, subnetId.get());
        if (subnetToDhcp.isPresent()) {
            LOG.trace("Removing ArpResponder flow for last interface {} on DPN {}", interfaceName, dpnId);
            ArpResponderInput arpInput = new ArpResponderInput.ArpReponderInputBuilder().setDpId(dpnId).setInterfaceName(interfaceName).setSpa(subnetToDhcp.get().getPortFixedip()).setLportTag(interfaceDel.getIfIndex()).buildForRemoveFlow();
            elanService.removeArpResponderFlow(arpInput);
        }
    }
    futures.addAll(unInstallDhcpEntries(interfaceDel.getName(), dpnId));
    return futures;
}
Also used : ListenableFuture(com.google.common.util.concurrent.ListenableFuture) InterfaceNameMacAddresses(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710.InterfaceNameMacAddresses) LoggerFactory(org.slf4j.LoggerFactory) Callable(java.util.concurrent.Callable) IElanService(org.opendaylight.netvirt.elanmanager.api.IElanService) DhcpExternalTunnelManager(org.opendaylight.netvirt.dhcpservice.DhcpExternalTunnelManager) ArrayList(java.util.ArrayList) IfTunnel(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel) DhcpServiceUtils(org.opendaylight.netvirt.dhcpservice.DhcpServiceUtils) ManagedNewTransactionRunnerImpl(org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl) BigInteger(java.math.BigInteger) InterfaceNameMacAddressKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710._interface.name.mac.addresses.InterfaceNameMacAddressKey) Nullable(javax.annotation.Nullable) IInterfaceManager(org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager) Logger(org.slf4j.Logger) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) InterfaceNameMacAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710._interface.name.mac.addresses.InterfaceNameMacAddress) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface) FutureCallback(com.google.common.util.concurrent.FutureCallback) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) DhcpManager(org.opendaylight.netvirt.dhcpservice.DhcpManager) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) List(java.util.List) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) SubnetToDhcpPort(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710.subnet.dhcp.port.data.SubnetToDhcpPort) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) Collections(java.util.Collections) ArpResponderInput(org.opendaylight.netvirt.elan.arp.responder.ArpResponderInput) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) ArrayList(java.util.ArrayList) IfTunnel(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel) ArpResponderInput(org.opendaylight.netvirt.elan.arp.responder.ArpResponderInput) SubnetToDhcpPort(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710.subnet.dhcp.port.data.SubnetToDhcpPort) BigInteger(java.math.BigInteger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)

Aggregations

SubnetToDhcpPort (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710.subnet.dhcp.port.data.SubnetToDhcpPort)8 BigInteger (java.math.BigInteger)6 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)4 Port (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Callable (java.util.concurrent.Callable)2 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)2 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)2 ManagedNewTransactionRunner (org.opendaylight.genius.infra.ManagedNewTransactionRunner)2 ManagedNewTransactionRunnerImpl (org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl)2 IInterfaceManager (org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager)2 DhcpExternalTunnelManager (org.opendaylight.netvirt.dhcpservice.DhcpExternalTunnelManager)2 DhcpManager (org.opendaylight.netvirt.dhcpservice.DhcpManager)2 DhcpServiceUtils (org.opendaylight.netvirt.dhcpservice.DhcpServiceUtils)2 IElanService (org.opendaylight.netvirt.elanmanager.api.IElanService)2 Interface (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface)2 IfTunnel (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel)2