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