import com.google.common.util.concurrent.ListenableFuture;
import java.math.BigInteger;
import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.Collection;
+import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.Future;
+import javax.annotation.Nonnull;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
+import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
import org.opendaylight.genius.mdsalutil.BucketInfo;
import org.opendaylight.genius.mdsalutil.FlowEntity;
//remove miss entry to NAPT switch
//if naptswitch elect new switch and install Snat flows and remove those flows in oldnaptswitch
- //get ExternalIpIn prior
- List<String> externalIpCache;
- //HashMap Label
- HashMap<String, Long> externalIpLabel;
Long routerId = NatUtil.getVpnId(dataBroker, routerName);
if (routerId == NatConstants.INVALID_ID) {
LOG.error("NAT Service : SNAT -> Invalid routerId returned for routerName {}", routerName);
return;
}
- externalIpCache = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
+ Collection<String> externalIpCache = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker,routerName);
if (extNwProvType == null) {
return;
}
+ Map<String, Long> externalIpLabel;
if (extNwProvType == ProviderTypes.VXLAN) {
externalIpLabel = null;
} else {
GroupEntity groupEntity = null;
try {
groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName,
- GroupTypes.GroupAll, null);
+ GroupTypes.GroupAll, Collections.emptyList() /*listBucketInfo*/);
LOG.info("NAT Service : SNAT -> Removing NAPT GroupEntity:{} on Dpn {}", groupEntity, dpnId);
mdsalManager.removeGroup(groupEntity);
} catch (Exception ex) {
+ " : {} and DEST IP: {}", fibManager.getTransportTypeStr(tunnelType), srcTepIp, destTepIp);
InstanceIdentifier<DpnRoutersList> dpnRoutersListId = NatUtil.getDpnRoutersId(srcDpnId);
- Optional<DpnRoutersList> optionalRouterDpnList = NatUtil.read(dataBroker, LogicalDatastoreType
- .OPERATIONAL, dpnRoutersListId);
+ Optional<DpnRoutersList> optionalRouterDpnList =
+ SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
+ LogicalDatastoreType.OPERATIONAL, dpnRoutersListId);
if (!optionalRouterDpnList.isPresent()) {
LOG.warn("NAT Service : RouterDpnList model is empty for DPN {}. Hence ignoring TEP add event for the ITM "
+ "TUNNEL TYPE {} b/w SRC IP {} and DST IP {} and TUNNEL NAME {} ",
List<RoutersList> routersList = null;
InstanceIdentifier<DpnRoutersList> dpnRoutersListId = NatUtil.getDpnRoutersId(srcDpnId);
- Optional<DpnRoutersList> optionalRouterDpnList = NatUtil.read(dataBroker, LogicalDatastoreType
- .OPERATIONAL, dpnRoutersListId);
+ Optional<DpnRoutersList> optionalRouterDpnList =
+ SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
+ LogicalDatastoreType.OPERATIONAL, dpnRoutersListId);
if (optionalRouterDpnList.isPresent()) {
routersList = optionalRouterDpnList.get().getRoutersList();
} else {
// Check if this is externalRouter else ignore
InstanceIdentifier<Routers> extRoutersId = NatUtil.buildRouterIdentifier(routerName);
- Optional<Routers> routerData = NatUtil.read(dataBroker, LogicalDatastoreType
- .CONFIGURATION, extRoutersId);
+ Optional<Routers> routerData =
+ SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
+ LogicalDatastoreType.CONFIGURATION, extRoutersId);
if (!routerData.isPresent()) {
LOG.debug("NAT Service : SNAT -> Ignoring TEP add for router {} since its not External Router",
routerName);
networkId, routerId);
return false;
}
- List<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
- if (externalIps != null) {
- LOG.debug("NAT Service : Clearing the FIB entries but not the BGP routes");
- for (String externalIp : externalIps) {
- String rd = NatUtil.getVpnRd(dataBroker, externalVpnName);
- LOG.debug("NAT Service : Removing Fib entry rd {} prefix {}", rd, externalIp);
- fibManager.removeFibEntry(dataBroker, rd, externalIp, null);
- }
+ Collection<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
+ LOG.debug("NAT Service : Clearing the FIB entries but not the BGP routes");
+ for (String externalIp : externalIps) {
+ String rd = NatUtil.getVpnRd(dataBroker, externalVpnName);
+ LOG.debug("NAT Service : Removing Fib entry rd {} prefix {}", rd, externalIp);
+ fibManager.removeFibEntry(dataBroker, rd, externalIp, null);
}
/*
if (extNwProvType == ProviderTypes.VXLAN) {
// Get the External Gateway MAC Address which is Router gateway MAC address for SNAT
gwMacAddress = NatUtil.getExtGwMacAddFromRouterId(dataBroker, routerId);
+ if (gwMacAddress != null) {
+ LOG.debug("External Gateway MAC address {} found for External Router ID {}", gwMacAddress,
+ routerId);
+ } else {
+ LOG.error("No External Gateway MAC address found for External Router ID {}", routerId);
+ return false;
+ }
//get l3Vni value for external VPN
l3Vni = NatEvpnUtil.getL3Vni(dataBroker, rd);
if (l3Vni == NatConstants.DEFAULT_L3VNI_VALUE) {
if (externalIps != null) {
for (final String externalIp : externalIps) {
long serviceId = 0;
+ String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
if (extNwProvType == ProviderTypes.VXLAN) {
LOG.debug("NAT Service : SNAT -> Advertise the route to the externalIp {} having nextHopIp {}",
externalIp, nextHopIp);
Uuid externalSubnetId = NatUtil.getExternalSubnetForRouterExternalIp(dataBroker, externalIp,
router);
NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, externalVpnName, rd, externalSubnetId,
- externalIp, nextHopIp, networkId.getValue(), null /* mac-address */, label, l3vni, LOG,
+ fibExternalIp, nextHopIp, networkId.getValue(), null /* mac-address */, label, l3vni, LOG,
RouteOrigin.STATIC, srcDpnId);
serviceId = label;
}
.buildInstruction(customInstructionIndex));
CreateFibEntryInput input =
new CreateFibEntryInputBuilder().setVpnName(externalVpnName).setSourceDpid(srcDpnId)
- .setInstruction(customInstructions).setIpAddress(externalIp + "/32")
+ .setInstruction(customInstructions).setIpAddress(fibExternalIp)
.setServiceId(serviceId).setInstruction(customInstructions).build();
Future<RpcResult<Void>> future = fibRpcService.createFibEntry(input);
ListenableFuture<RpcResult<Void>> listenableFuture = JdkFutureAdapters.listenInPoolThread(future);
Futures.addCallback(listenableFuture, new FutureCallback<RpcResult<Void>>() {
@Override
- public void onFailure(Throwable error) {
+ public void onFailure(@Nonnull Throwable error) {
LOG.error("NAT Service : SNAT -> Error in generate label or fib install process", error);
}
if (extNwProvType == ProviderTypes.VXLAN) {
// Get the External Gateway MAC Address which is Router gateway MAC address for SNAT
gwMacAddress = NatUtil.getExtGwMacAddFromRouterId(dataBroker, routerId);
+ if (gwMacAddress != null) {
+ LOG.debug("External Gateway MAC address {} found for External Router ID {}", gwMacAddress,
+ routerId);
+ } else {
+ LOG.error("No External Gateway MAC address found for External Router ID {}", routerId);
+ return;
+ }
//get l3Vni value for external VPN
l3Vni = NatEvpnUtil.getL3Vni(dataBroker, rd);
if (l3Vni == NatConstants.DEFAULT_L3VNI_VALUE) {
+ "for the port: {}",
externalIp, interfaceName);
long serviceId = 0;
+ String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
+
if (extNwProvType == ProviderTypes.VXLAN) {
LOG.debug("NAT Service : DNAT -> Advertise the route to the externalIp {} having nextHopIp {}",
externalIp, nextHopIp);
l3vni = NatOverVxlanUtil.getInternetVpnVni(idManager, vpnName, l3vni).longValue();
}
NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, vpnName, rd, null,
- externalIp + "/32", nextHopIp, null, null, label, l3vni, LOG, RouteOrigin.STATIC,
+ fibExternalIp, nextHopIp, null, null, label, l3vni, LOG, RouteOrigin.STATIC,
fipCfgdDpnId);
serviceId = label;
}
customInstructions.add(new InstructionGotoTable(NwConstants.PDNAT_TABLE).buildInstruction(0));
CreateFibEntryInput input = new CreateFibEntryInputBuilder().setVpnName(vpnName)
.setSourceDpid(fipCfgdDpnId).setInstruction(customInstructions)
- .setIpAddress(externalIp + "/32").setServiceId(serviceId).setInstruction(customInstructions)
+ .setIpAddress(fibExternalIp).setServiceId(serviceId).setInstruction(customInstructions)
.build();
Future<RpcResult<Void>> future = fibRpcService.createFibEntry(input);
ListenableFuture<RpcResult<Void>> listenableFuture = JdkFutureAdapters.listenInPoolThread(future);
Futures.addCallback(listenableFuture, new FutureCallback<RpcResult<Void>>() {
@Override
- public void onFailure(Throwable error) {
+ public void onFailure(@Nonnull Throwable error) {
LOG.error("NAT Service : DNAT -> Error in generate label or fib install process", error);
}
// Check if this is externalRouter else ignore
InstanceIdentifier<Routers> extRoutersId = NatUtil.buildRouterIdentifier(routerName);
- Optional<Routers> routerData = NatUtil.read(dataBroker, LogicalDatastoreType
- .CONFIGURATION, extRoutersId);
+ Optional<Routers> routerData =
+ SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
+ LogicalDatastoreType.CONFIGURATION, extRoutersId);
if (!routerData.isPresent()) {
LOG.debug("NAT Service : SNAT -> Ignoring TEP del for router {} since its not External Router",
routerName);
for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
String internalIp = intExtPortMap.getInternalIp();
String externalIp = intExtPortMap.getExternalIp();
+ externalIp = NatUtil.validateAndAddNetworkMask(externalIp);
LOG.debug("NAT Service : DNAT -> Withdrawing the FIB route to the floating IP {} "
+ "configured for the port: {}",
externalIp, interfaceName);
- NatUtil.removePrefixFromBGP(dataBroker, bgpManager, fibManager, rd, externalIp + "/32", vpnName, LOG);
+ NatUtil.removePrefixFromBGP(dataBroker, bgpManager, fibManager, rd, externalIp, vpnName, LOG);
long serviceId = 0;
if (extNwProvType == ProviderTypes.VXLAN) {
serviceId = l3Vni;
}
serviceId = label;
}
+
RemoveFibEntryInput input = new RemoveFibEntryInputBuilder().setVpnName(vpnName)
- .setSourceDpid(fipCfgdDpnId).setIpAddress(externalIp + "/32").setServiceId(serviceId).build();
+ .setSourceDpid(fipCfgdDpnId).setIpAddress(externalIp).setServiceId(serviceId)
+ .setIpAddressSource(RemoveFibEntryInput.IpAddressSource.FloatingIP).build();
Future<RpcResult<Void>> future = fibRpcService.removeFibEntry(input);
ListenableFuture<RpcResult<Void>> listenableFuture = JdkFutureAdapters.listenInPoolThread(future);
Futures.addCallback(listenableFuture, new FutureCallback<RpcResult<Void>>() {
@Override
- public void onFailure(Throwable error) {
+ public void onFailure(@Nonnull Throwable error) {
LOG.error("NAT Service : DNAT -> Error in removing the table 21 entry pushing "
+ "the MPLS label to the tunnel since label is invalid ", error);
}