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;
}
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);
}));
}
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);
}
}
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);
}
}
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;
}
}
Aggregations