Search in sources :

Example 1 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 handleDhcpAllocationPoolPacket.

private DhcpInfo handleDhcpAllocationPoolPacket(byte msgType, String interfaceName, String macAddress) {
    try {
        String networkId = dhcpAllocationPoolMgr.getNetworkByPort(interfaceName);
        AllocationPool pool = networkId != null ? dhcpAllocationPoolMgr.getAllocationPoolByNetwork(networkId) : null;
        if (networkId == null || pool == null) {
            LOG.warn("No Dhcp Allocation Pool was found for interface: {}", interfaceName);
            return null;
        }
        switch(msgType) {
            case DHCPConstants.MSG_DISCOVER:
            case DHCPConstants.MSG_REQUEST:
                // FIXME: requested ip is currently ignored in moment of allocation
                return getDhcpInfoFromAllocationPool(networkId, pool, macAddress);
            case DHCPConstants.MSG_RELEASE:
                dhcpAllocationPoolMgr.releaseIpAllocation(networkId, pool, macAddress);
                break;
            default:
                break;
        }
    } catch (ReadFailedException e) {
        LOG.error("Error reading from MD-SAL", e);
    }
    return null;
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) AllocationPool(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.network.AllocationPool)

Example 2 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 remove.

@Override
protected void remove(InstanceIdentifier<AllocationPool> key, AllocationPool dataObjectModification) {
    String networkId = key.firstKeyOf(Network.class).getNetworkId();
    dhcpAllocationPoolManager.releaseIdAllocationPool(networkId, dataObjectModification);
    Map<BigInteger, List<String>> elanDpnInterfacesByName = getDpnInterfacesByNetwork(networkId);
    elanDpnInterfacesByName.values().forEach(interfaceNames -> interfaceNames.forEach(interfaceName -> {
        DhcpAllocationPoolRemoveJob job = new DhcpAllocationPoolRemoveJob(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) DhcpAllocationPool(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.DhcpAllocationPool) Logger(org.slf4j.Logger) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) DhcpMConstants(org.opendaylight.netvirt.dhcpservice.api.DhcpMConstants) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) LoggerFactory(org.slf4j.LoggerFactory) AsyncDataTreeChangeListenerBase(org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) List(java.util.List) AllocationPool(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.network.AllocationPool) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) DhcpAllocationPoolRemoveJob(org.opendaylight.netvirt.dhcpservice.jobs.DhcpAllocationPoolRemoveJob) Map(java.util.Map) ManagedNewTransactionRunnerImpl(org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl) Entry(java.util.Map.Entry) BigInteger(java.math.BigInteger) DhcpAllocationPoolAddJob(org.opendaylight.netvirt.dhcpservice.jobs.DhcpAllocationPoolAddJob) DhcpAllocationPoolRemoveJob(org.opendaylight.netvirt.dhcpservice.jobs.DhcpAllocationPoolRemoveJob) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.Network) BigInteger(java.math.BigInteger) List(java.util.List)

Example 3 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 createIdAllocationPool.

protected void createIdAllocationPool(String networkId, AllocationPool pool) {
    String poolName = getPoolKeyIdByAllocationPool(networkId, pool);
    long low = DhcpServiceUtils.convertIpToLong(pool.getAllocateFrom());
    long high = DhcpServiceUtils.convertIpToLong(pool.getAllocateTo());
    CreateIdPoolInput createPool = new CreateIdPoolInputBuilder().setPoolName(poolName).setLow(low).setHigh(high).build();
    try {
        Future<RpcResult<Void>> result = idManager.createIdPool(createPool);
        if (result != null && result.get().isSuccessful()) {
            LOG.info("DHCP Allocation Pool Service : Created IdPool name {}", poolName);
        } else {
            LOG.error("DHCP Allocation Pool Service : Unable to create IdPool name {}", poolName);
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("Failed to create Pool for DHCP Allocation Pool Service", e);
    }
}
Also used : RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) CreateIdPoolInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInput) ExecutionException(java.util.concurrent.ExecutionException) CreateIdPoolInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInputBuilder)

Example 4 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 releaseIdAllocationPool.

protected void releaseIdAllocationPool(String networkId, AllocationPool pool) {
    String poolName = getPoolKeyIdByAllocationPool(networkId, pool);
    DeleteIdPoolInput deletePool = new DeleteIdPoolInputBuilder().setPoolName(poolName).build();
    try {
        Future<RpcResult<Void>> result = idManager.deleteIdPool(deletePool);
        if (result != null && result.get().isSuccessful()) {
            LOG.info("DHCP Allocation Pool Service : Deleted IdPool name {}", poolName);
        } else {
            LOG.error("DHCP Allocation Pool Service : Unable to delete IdPool name {}", poolName);
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("Failed to delete Pool for DHCP Allocation Pool Service", e);
    }
}
Also used : DeleteIdPoolInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.DeleteIdPoolInputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ExecutionException(java.util.concurrent.ExecutionException) DeleteIdPoolInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.DeleteIdPoolInput)

Example 5 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 getAllocationPoolByNetwork.

public AllocationPool getAllocationPoolByNetwork(String networkId) throws ReadFailedException {
    InstanceIdentifier<Network> network = InstanceIdentifier.builder(DhcpAllocationPool.class).child(Network.class, new NetworkKey(networkId)).build();
    Optional<Network> optionalNetworkConfData = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, network);
    if (!optionalNetworkConfData.isPresent()) {
        LOG.info("No network configuration data for network {}", networkId);
        return null;
    }
    Network networkConfData = optionalNetworkConfData.get();
    List<AllocationPool> allocationPoolList = networkConfData.getAllocationPool();
    // as we have no info about a specific subnet
    if (allocationPoolList != null && !allocationPoolList.isEmpty()) {
        return allocationPoolList.get(0);
    } else {
        LOG.warn("No allocation pools for network {}", networkId);
        return null;
    }
}
Also used : NetworkKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.NetworkKey) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.Network) DhcpAllocationPool(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.DhcpAllocationPool) AllocationPool(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.network.AllocationPool)

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