Search in sources :

Example 6 with AllocationPool

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.network.AllocationPool in project netvirt by opendaylight.

the class DhcpAllocationPoolManager method getIpAllocation.

public IpAddress getIpAllocation(String networkId, AllocationPool pool, String macAddress) {
    String poolIdKey = getPoolKeyIdByAllocationPool(networkId, pool);
    long allocatedIpLong = createIdAllocation(poolIdKey, macAddress);
    LOG.debug("allocated id {} for mac {}, from pool {}", allocatedIpLong, macAddress, poolIdKey);
    IpAddress allocatedIpAddress = allocatedIpLong != 0 ? DhcpServiceUtils.convertLongToIp(allocatedIpLong) : null;
    return allocatedIpAddress;
}
Also used : IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)

Example 7 with AllocationPool

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.network.AllocationPool in project netvirt by opendaylight.

the class DhcpPktHandler method getDhcpInfoFromAllocationPool.

private DhcpInfo getDhcpInfoFromAllocationPool(String networkId, AllocationPool pool, String macAddress) {
    IpAddress allocatedIp = dhcpAllocationPoolMgr.getIpAllocation(networkId, pool, macAddress);
    DhcpInfo dhcpInfo = getApDhcpInfo(pool, allocatedIp);
    LOG.info("AllocationPoolNetwork: {}, dhcpInfo {}", networkId, dhcpInfo);
    return dhcpInfo;
}
Also used : IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)

Example 8 with AllocationPool

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.network.AllocationPool in project netvirt by opendaylight.

the class DhcpAllocationPoolListener method add.

@Override
protected void add(InstanceIdentifier<AllocationPool> key, AllocationPool dataObjectModification) {
    String networkId = key.firstKeyOf(Network.class).getNetworkId();
    dhcpAllocationPoolManager.createIdAllocationPool(networkId, dataObjectModification);
    Map<BigInteger, List<String>> elanDpnInterfacesByName = getDpnInterfacesByNetwork(networkId);
    for (Entry<BigInteger, List<String>> entry : elanDpnInterfacesByName.entrySet()) {
        BigInteger dpnId = entry.getKey();
        for (String interfaceName : entry.getValue()) {
            LOG.debug("Install Dhcp Entries for dpId: {} interface : {}", dpnId, interfaceName);
            DhcpAllocationPoolAddJob job = new DhcpAllocationPoolAddJob(txRunner, interfaceName);
            jobCoordinator.enqueueJob(DhcpServiceUtils.getJobKey(interfaceName), job, DhcpMConstants.RETRY_COUNT);
        }
    }
}
Also used : Network(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.Network) BigInteger(java.math.BigInteger) DhcpAllocationPoolAddJob(org.opendaylight.netvirt.dhcpservice.jobs.DhcpAllocationPoolAddJob) List(java.util.List)

Example 9 with AllocationPool

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.network.AllocationPool in project netvirt by opendaylight.

the class NatRpcServiceImpl method getNatTranslationsForNetworkAndIpaddress.

public Future<RpcResult<GetNatTranslationsForNetworkAndIpaddressOutput>> getNatTranslationsForNetworkAndIpaddress(GetNatTranslationsForNetworkAndIpaddressInput input) {
    String ipAddress = String.valueOf(input.getIpAddress().getValue());
    RpcResultBuilder<GetNatTranslationsForNetworkAndIpaddressOutput> rpcResultBuilder = null;
    GetNatTranslationsForNetworkAndIpaddressOutputBuilder output = null;
    List<Uuid> subnetUuidList = NatUtil.getSubnetIdsFromNetworkId(dataBroker, input.getNetworkUuid());
    if (subnetUuidList.isEmpty()) {
        String errMsg = String.format("404 Not Found - Invalid Network UUID {%s} provided as no Subnetworks found", input.getNetworkUuid().getValue());
        rpcResultBuilder = RpcResultBuilder.<GetNatTranslationsForNetworkAndIpaddressOutput>failed().withError(RpcError.ErrorType.APPLICATION, errMsg);
        return Futures.immediateFuture(rpcResultBuilder.build());
    }
    Subnet subNet = null;
    Boolean isIpInSubnet = Boolean.FALSE;
    outerloop: for (Uuid subnetUuid : subnetUuidList) {
        subNet = nvpnManager.getNeutronSubnet(subnetUuid);
        for (AllocationPools allocationPool : subNet.getAllocationPools()) {
            if (NatUtil.isIpInSubnet(ipAddress, String.valueOf(allocationPool.getStart().getValue()), String.valueOf(allocationPool.getEnd().getValue()))) {
                LOG.debug("getNatTranslationsForNetworkAndIpaddress : IP Adderess {} falls within the Subnet {}", ipAddress, subNet.getUuid().getValue());
                isIpInSubnet = Boolean.TRUE;
                break outerloop;
            }
        }
    }
    if (!isIpInSubnet) {
        String errMsg = String.format("404 Not Found - IP Adress {%s} does not fall within the Subnet IP range" + " of Network {%s}", ipAddress, input.getNetworkUuid().getValue());
        rpcResultBuilder = RpcResultBuilder.<GetNatTranslationsForNetworkAndIpaddressOutput>failed().withError(RpcError.ErrorType.APPLICATION, errMsg);
        return Futures.immediateFuture(rpcResultBuilder.build());
    }
    Subnetmap subnetMap = NatUtil.getSubnetMap(dataBroker, subNet.getUuid());
    long routerId = NatUtil.getVpnId(dataBroker, subnetMap.getRouterId().getValue());
    List<Ports> fipPorts = NatUtil.getFloatingIpPortsForRouter(dataBroker, subnetMap.getRouterId());
    if (fipPorts.isEmpty()) {
        LOG.warn("getNatTranslationsForNetworkAndIpaddress : No DNAT IP Mapping found for IP {}", ipAddress);
    } else {
        for (Ports fipPort : fipPorts) {
            List<InternalToExternalPortMap> ipMapping = fipPort.getInternalToExternalPortMap();
            for (InternalToExternalPortMap fipMap : ipMapping) {
                if (fipMap.getInternalIp().equals(ipAddress)) {
                    output = new GetNatTranslationsForNetworkAndIpaddressOutputBuilder().setExternalIp(fipMap.getExternalIp()).setNatTranslation("DNAT");
                    rpcResultBuilder = RpcResultBuilder.success();
                    rpcResultBuilder.withResult(output.build());
                    return Futures.immediateFuture(rpcResultBuilder.build());
                }
            }
        }
    }
    IpPortMapping ipPortMapping = NatUtil.getIportMapping(dataBroker, routerId);
    if (ipPortMapping == null) {
        LOG.warn("getNatTranslationsForNetworkAndIpaddress : No SNAT IP Mapping found for IP {}", ipAddress);
    } else {
        for (IntextIpProtocolType protocolType : ipPortMapping.getIntextIpProtocolType()) {
            for (IpPortMap ipPortMap : protocolType.getIpPortMap()) {
                String[] internalIpPort = ipPortMap.getIpPortInternal().split(NwConstants.MACADDR_SEP);
                if (ipAddress.equals(internalIpPort[0])) {
                    output = new GetNatTranslationsForNetworkAndIpaddressOutputBuilder().setExternalIp(ipPortMap.getIpPortExternal().getIpAddress()).setInternalIp(internalIpPort[0]).setNatTranslation("SNAT").setInternalPort(internalIpPort[1]).setExternalPort(ipPortMap.getIpPortExternal().getPortNum().toString()).setProtocol(protocolType.getProtocol().getName());
                    rpcResultBuilder = RpcResultBuilder.success();
                    rpcResultBuilder.withResult(output.build());
                    return Futures.immediateFuture(rpcResultBuilder.build());
                }
            }
        }
    }
    String errMsg = String.format("404 Not Found - No NAT Translation found for IP {%s}", ipAddress);
    rpcResultBuilder = RpcResultBuilder.<GetNatTranslationsForNetworkAndIpaddressOutput>failed().withError(RpcError.ErrorType.APPLICATION, errMsg);
    return Futures.immediateFuture(rpcResultBuilder.build());
}
Also used : GetNatTranslationsForNetworkAndIpaddressOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.GetNatTranslationsForNetworkAndIpaddressOutputBuilder) GetNatTranslationsForNetworkAndIpaddressOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.GetNatTranslationsForNetworkAndIpaddressOutput) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports) AllocationPools(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnet.attributes.AllocationPools) IpPortMapping(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.IpPortMapping) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) IpPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.IpPortMap) IntextIpProtocolType(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.IntextIpProtocolType) Subnet(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)

Aggregations

Network (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.Network)3 AllocationPool (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.network.AllocationPool)3 BigInteger (java.math.BigInteger)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 DhcpAllocationPoolAddJob (org.opendaylight.netvirt.dhcpservice.jobs.DhcpAllocationPoolAddJob)2 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)2 DhcpAllocationPool (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.DhcpAllocationPool)2 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)2 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)1 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)1 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)1 AsyncDataTreeChangeListenerBase (org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase)1 ManagedNewTransactionRunner (org.opendaylight.genius.infra.ManagedNewTransactionRunner)1 ManagedNewTransactionRunnerImpl (org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl)1 JobCoordinator (org.opendaylight.infrautils.jobcoordinator.JobCoordinator)1 DhcpMConstants (org.opendaylight.netvirt.dhcpservice.api.DhcpMConstants)1 DhcpAllocationPoolRemoveJob (org.opendaylight.netvirt.dhcpservice.jobs.DhcpAllocationPoolRemoveJob)1