use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap in project netvirt by opendaylight.
the class VpnFloatingIpHandler method onRemoveFloatingIp.
@Override
public void onRemoveFloatingIp(final BigInteger dpnId, String routerUuid, long routerId, final Uuid networkId, InternalToExternalPortMap mapping, final long label, WriteTransaction removeFlowInvTx) {
String externalIp = mapping.getExternalIp();
Uuid floatingIpId = mapping.getExternalId();
Uuid subnetId = NatUtil.getFloatingIpPortSubnetIdFromFloatingIpId(dataBroker, floatingIpId);
Optional<Subnets> externalSubnet = NatUtil.getOptionalExternalSubnets(dataBroker, subnetId);
final String vpnName = externalSubnet.isPresent() ? subnetId.getValue() : NatUtil.getAssociatedVPN(dataBroker, networkId);
if (vpnName == null) {
LOG.error("onRemoveFloatingIp: No VPN associated with ext nw {} to remove floating ip {} configuration " + "for router {}", networkId, externalIp, routerUuid);
return;
}
// Remove floating mac from mymac table
LOG.debug("onRemoveFloatingIp: Removing FloatingIp {}", externalIp);
String floatingIpPortMacAddress = NatUtil.getFloatingIpPortMacFromFloatingIpId(dataBroker, floatingIpId);
if (floatingIpPortMacAddress == null) {
LOG.error("onRemoveFloatingIp: Unable to retrieve floatingIp port MAC address from floatingIpId {} for " + "router {} to remove floatingIp {}", floatingIpId, routerUuid, externalIp);
return;
}
ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
String networkVpnName = NatUtil.getAssociatedVPN(dataBroker, networkId);
vpnManager.removeSubnetMacFromVpnInstance(networkVpnName, subnetId.getValue(), floatingIpPortMacAddress, dpnId, tx);
vpnManager.removeArpResponderFlowsToExternalNetworkIps(routerUuid, Collections.singletonList(externalIp), floatingIpPortMacAddress, dpnId, networkId);
}), LOG, "onRemoveFloatingIp");
removeFromFloatingIpPortInfo(floatingIpId);
ProviderTypes provType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerUuid, networkId);
if (provType == null) {
return;
}
if (provType == ProviderTypes.VXLAN) {
Uuid floatingIpInterface = NatEvpnUtil.getFloatingIpInterfaceIdFromFloatingIpId(dataBroker, floatingIpId);
evpnDnatFlowProgrammer.onRemoveFloatingIp(dpnId, vpnName, externalIp, floatingIpInterface.getValue(), floatingIpPortMacAddress, routerId, removeFlowInvTx);
return;
}
cleanupFibEntries(dpnId, vpnName, externalIp, label, removeFlowInvTx, provType);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap 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