use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryOutput in project netvirt by opendaylight.
the class NatTepChangeListener method hndlTepDelForDnatInEachRtr.
private boolean hndlTepDelForDnatInEachRtr(RoutersList router, Uint32 routerId, Uint64 tepDeletedDpnId, ProviderTypes extNwProvType) {
// DNAT : Withdraw the routes from the BGP
String routerName = router.getRouter();
Boolean isFipExists = Boolean.FALSE;
LOG.debug("hndlTepDelForDnatInEachRtr : DNAT -> Trying to clear routes to the Floating IP " + "associated to the router {}", routerName);
InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerName);
Optional<RouterPorts> optRouterPorts;
try {
optRouterPorts = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
} catch (ExecutionException | InterruptedException e) {
LOG.error("hndlTepDelForDnatInEachRtr: Exception while reading RouterPorts DS for the router {}", routerName, e);
return isFipExists;
}
if (!optRouterPorts.isPresent()) {
LOG.debug("hndlTepDelForDnatInEachRtr : DNAT -> Could not read Router Ports data object with id: {} " + "from DNAT FloatingIpInfo", routerName);
return isFipExists;
}
RouterPorts routerPorts = optRouterPorts.get();
Uuid extNwId = routerPorts.getExternalNetworkId();
final String vpnName = NatUtil.getAssociatedVPN(dataBroker, extNwId);
if (vpnName == null) {
LOG.error("hndlTepDelForDnatInEachRtr : DNAT -> No External VPN associated with Ext N/W {} for Router {}", extNwId, routerName);
return isFipExists;
}
String rd = NatUtil.getVpnRd(dataBroker, vpnName);
if (extNwProvType == null) {
return isFipExists;
}
Uint32 l3Vni = Uint32.ZERO;
if (extNwProvType == ProviderTypes.VXLAN) {
// get l3Vni value for external VPN
l3Vni = NatEvpnUtil.getL3Vni(dataBroker, rd);
if (l3Vni == NatConstants.DEFAULT_L3VNI_VALUE) {
LOG.debug("hndlTepDelForDnatInEachRtr : L3VNI value is not configured in Internet VPN {} and RD {} " + "Carve-out L3VNI value from OpenDaylight VXLAN VNI Pool and continue to installing " + "NAT flows", vpnName, rd);
l3Vni = natOverVxlanUtil.getInternetVpnVni(vpnName, routerId);
}
}
Map<PortsKey, Ports> interfacesMap = routerPorts.nonnullPorts();
for (Ports port : interfacesMap.values()) {
// Get the DPN on which this interface resides
String interfaceName = port.getPortName();
Uint64 fipCfgdDpnId = NatUtil.getDpnForInterface(interfaceService, interfaceName);
if (fipCfgdDpnId.equals(Uint64.ZERO)) {
LOG.info("hndlTepDelForDnatInEachRtr : DNAT -> Abort processing Floating ip configuration. " + "No DPN for port : {}", interfaceName);
continue;
}
if (!fipCfgdDpnId.equals(tepDeletedDpnId)) {
LOG.info("hndlTepDelForDnatInEachRtr : DNAT -> TEP deleted DPN {} is not the DPN {} which has the " + "floating IP configured for the port: {}", tepDeletedDpnId, fipCfgdDpnId, interfaceName);
continue;
}
isFipExists = Boolean.TRUE;
Map<InternalToExternalPortMapKey, InternalToExternalPortMap> keyInternalToExternalPortMapMap = port.nonnullInternalToExternalPortMap();
for (InternalToExternalPortMap intExtPortMap : keyInternalToExternalPortMapMap.values()) {
String internalIp = intExtPortMap.getInternalIp();
String externalIp = intExtPortMap.getExternalIp();
externalIp = NatUtil.validateAndAddNetworkMask(externalIp);
LOG.debug("hndlTepDelForDnatInEachRtr : DNAT -> Withdrawing the FIB route to the floating IP {} " + "configured for the port: {}", externalIp, interfaceName);
NatUtil.removePrefixFromBGP(bgpManager, fibManager, rd, externalIp, vpnName);
Uint32 serviceId = null;
if (extNwProvType == ProviderTypes.VXLAN) {
serviceId = l3Vni;
} else {
serviceId = floatingIPListener.getOperationalIpMapping(routerName, interfaceName, internalIp);
if (serviceId == null || serviceId == NatConstants.INVALID_ID) {
LOG.error("hndlTepDelForDnatInEachRtr : DNAT -> Unable to remove the table 21 entry pushing the" + " MPLS label to the tunnel since label is invalid");
continue;
}
}
RemoveFibEntryInput input = new RemoveFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(fipCfgdDpnId).setIpAddress(externalIp).setServiceId(serviceId).setIpAddressSource(RemoveFibEntryInput.IpAddressSource.FloatingIP).build();
ListenableFuture<RpcResult<RemoveFibEntryOutput>> future = fibRpcService.removeFibEntry(input);
Futures.addCallback(future, new FutureCallback<RpcResult<RemoveFibEntryOutput>>() {
@Override
public void onFailure(Throwable error) {
LOG.error("hndlTepDelForDnatInEachRtr : DNAT -> Error in removing the table 21 entry pushing " + "the MPLS label to the tunnel since label is invalid ", error);
}
@Override
public void onSuccess(RpcResult<RemoveFibEntryOutput> result) {
if (result.isSuccessful()) {
LOG.info("hndlTepDelForDnatInEachRtr : DNAT -> Successfully removed the entry pushing the " + "MPLS label to the tunnel");
} else {
LOG.error("hndlTepDelForDnatInEachRtr : DNAT -> Error in fib rpc call to remove the table " + "21 entry pushing the MPLS label to the tunnnel due to {}", result.getErrors());
}
}
}, MoreExecutors.directExecutor());
}
}
return isFipExists;
}
Aggregations