import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.JdkFutureAdapters;
import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
@Singleton
public class NatTunnelInterfaceStateListener
- extends AsyncDataTreeChangeListenerBase<StateTunnelList, NatTunnelInterfaceStateListener>
- implements AutoCloseable {
+ extends AsyncDataTreeChangeListenerBase<StateTunnelList, NatTunnelInterfaceStateListener> {
private static final Logger LOG = LoggerFactory.getLogger(NatTunnelInterfaceStateListener.class);
private final DataBroker dataBroker;
private final FibRpcService fibRpcService;
private final IElanService elanManager;
private final IInterfaceManager interfaceManager;
- private NatMode natMode = NatMode.Controller;
+ private final NatMode natMode;
protected enum TunnelAction {
TUNNEL_EP_ADD,
* @param naptSwitchHA - NAPT Switch HA
* @param mdsalManager - MDSAL Manager
* @param idManager - ID manager
- * @param externalRouterListner - External Router Listner
+ * @param externalRouterListner - External Router Listener
+ * @param natServiceManager - Nat Service Manager
* @param interfaceService - Interface Service
- * @param floatingIPListener - Floating IP Listner
+ * @param floatingIPListener - Floating IP Listener
* @param fibRpcService - FIB RPC Service
+ * @param config - Nat Service Config
* @param elanManager - Elan Manager
+ * @param interfaceManager - Interface Manager
*/
@Inject
public NatTunnelInterfaceStateListener(final DataBroker dataBroker,
this.interfaceManager = interfaceManager;
if (config != null) {
this.natMode = config.getNatMode();
+ } else {
+ this.natMode = NatMode.Controller;
}
}
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
- void removeSNATFromDPN(BigInteger dpnId, String routerName, long routerVpnId, Uuid networkId,
- WriteTransaction writeFlowInvTx) {
+ void removeSNATFromDPN(BigInteger dpnId, String routerName, long routerId, long routerVpnId,
+ Uuid networkId, ProviderTypes extNwProvType, WriteTransaction writeFlowInvTx) {
//irrespective of naptswitch or non-naptswitch, SNAT default miss entry need to be removed
//remove miss entry to NAPT switch
//if naptswitch elect new switch and install Snat flows and remove those flows in oldnaptswitch
- Long routerId = NatUtil.getVpnId(dataBroker, routerName);
if (routerId == NatConstants.INVALID_ID) {
LOG.error("removeSNATFromDPN : SNAT -> Invalid routerId returned for routerName {}", routerName);
return;
}
Collection<String> externalIpCache = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
- ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker,routerName);
if (extNwProvType == null) {
return;
}
externalIpLabel = NatUtil.getExternalIpsLabelForRouter(dataBroker, routerId);
}
try {
- final String externalVpnName = NatUtil.getAssociatedVPN(dataBroker, networkId, LOG);
+ final String externalVpnName = NatUtil.getAssociatedVPN(dataBroker, networkId);
if (externalVpnName == null) {
LOG.error("removeSNATFromDPN : SNAT -> No VPN associated with ext nw {} in router {}",
networkId, routerId);
BigInteger naptSwitch = dpnId;
boolean naptStatus =
- naptSwitchHA.isNaptSwitchDown(routerName, dpnId, naptSwitch, routerVpnId, externalIpCache, false,
- writeFlowInvTx);
+ naptSwitchHA.isNaptSwitchDown(routerName, routerId, dpnId, naptSwitch,
+ routerVpnId, externalIpCache, false, writeFlowInvTx);
if (!naptStatus) {
LOG.debug("removeSNATFromDPN:SNAT->NaptSwitchDown:Switch with DpnId {} is not naptSwitch for router {}",
dpnId, routerName);
LOG.debug("removeSNATFromDPN : SNAT->Removed default SNAT miss entry flow for dpnID {}, routerName {}",
dpnId, routerName);
} else {
- naptSwitchHA.removeSnatFlowsInOldNaptSwitch(routerName, dpnId, externalIpLabel, writeFlowInvTx);
+ naptSwitchHA.removeSnatFlowsInOldNaptSwitch(routerName, routerId, dpnId,
+ externalIpLabel, writeFlowInvTx);
//remove table 26 flow ppointing to table46
FlowEntity flowEntity = null;
try {
switch (tunnelAction) {
case TUNNEL_EP_ADD:
WriteTransaction writeFlowInvTx = dataBroker.newWriteOnlyTransaction();
- List<ListenableFuture<Void>> futures = new ArrayList<>();
if (isTunnelInLogicalGroup(stateTunnelList)
|| !hndlTepAddForAllRtrs(srcDpnId, tunnelType, tunnelName, srcTepIp, destTepIp,
writeFlowInvTx)) {
LOG.debug("hndlTepEvntsForDpn : Unable to process TEP ADD");
}
- futures.add(NatUtil.waitForTransactionToComplete(writeFlowInvTx));
+ NatUtil.waitForTransactionToComplete(writeFlowInvTx);
break;
case TUNNEL_EP_DELETE:
WriteTransaction writeFlowRemovetx = dataBroker.newWriteOnlyTransaction();
- List<ListenableFuture<Void>> futuresRemove = new ArrayList<>();
if (!handleTepDelForAllRtrs(srcDpnId, tunnelType, tunnelName, srcTepIp, destTepIp,
writeFlowRemovetx)) {
LOG.debug("hndlTepEvntsForDpn : Unable to process TEP DEL");
}
- futuresRemove.add(NatUtil.waitForTransactionToComplete(writeFlowRemovetx));
+ NatUtil.waitForTransactionToComplete(writeFlowRemovetx);
break;
default:
LOG.warn("hndlTepEvntsForDpn: unknown tunnelAction: {}", tunnelAction);
SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
LogicalDatastoreType.OPERATIONAL, dpnRoutersListId);
if (!optionalRouterDpnList.isPresent()) {
- LOG.warn("hndlTepAddForAllRtrs : RouterDpnList model is empty for DPN {}. Hence ignoring TEP add event "
+ LOG.info("hndlTepAddForAllRtrs : 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 {} ",
srcDpnId, tunnelType, srcTepIp, destTepIp, tunnelName);
return false;
String nextHopIp = NatUtil.getEndpointIpAddressForDPN(dataBroker, srcDpnId);
for (RoutersList router : routersList) {
+ String routerName = router.getRouter();
+ long routerId = NatUtil.getVpnId(dataBroker, routerName);
+ if (routerId == NatConstants.INVALID_ID) {
+ LOG.error("hndlTepAddForAllRtrs :Invalid ROUTER-ID {} returned for routerName {}",
+ routerId, routerName);
+ return false;
+ }
+ LOG.debug("hndlTepAddForAllRtrs : TEP ADD : DNAT -> Advertising routes for router {} ", routerName);
+ Uuid externalNetworkId = NatUtil.getNetworkIdFromRouterName(dataBroker,routerName);
+ ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker,
+ routerName, externalNetworkId);
+ if (extNwProvType == null) {
+ return false;
+ }
+ hndlTepAddForDnatInEachRtr(router, routerId, nextHopIp, srcDpnId, extNwProvType, writeFlowInvTx);
- LOG.debug("hndlTepAddForAllRtrs : TEP ADD : DNAT -> Advertising routes for router {} ", router.getRouter());
- hndlTepAddForDnatInEachRtr(router, nextHopIp, srcDpnId, writeFlowInvTx);
-
- LOG.debug("hndlTepAddForAllRtrs : TEP ADD : SNAT -> Advertising routes for router {} ", router.getRouter());
- hndlTepAddForSnatInEachRtr(router, srcDpnId, tunnelType, srcTepIp, destTepIp,
- tunnelName, nextHopIp, writeFlowInvTx);
+ LOG.debug("hndlTepAddForAllRtrs : TEP ADD : SNAT -> Advertising routes for router {} ", routerName);
+ hndlTepAddForSnatInEachRtr(router, routerId, srcDpnId, tunnelType, srcTepIp, destTepIp,
+ tunnelName, nextHopIp, extNwProvType, writeFlowInvTx);
}
return true;
}
}
for (RoutersList router : routersList) {
- LOG.debug("handleTepDelForAllRtrs : TEP DEL : DNAT -> Withdrawing routes for router {} ",
- router.getRouter());
- hndlTepDelForDnatInEachRtr(router, srcDpnId, writeFlowInvTx);
+ String routerName = router.getRouter();
+ LOG.debug("handleTepDelForAllRtrs : TEP DEL : DNAT -> Withdrawing routes for router {} ", routerName);
+ long routerId = NatUtil.getVpnId(dataBroker, routerName);
+ if (routerId == NatConstants.INVALID_ID) {
+ LOG.error("handleTepDelForAllRtrs :Invalid ROUTER-ID {} returned for routerName {}",
+ routerId, routerName);
+ return false;
+ }
+ Uuid externalNetworkId = NatUtil.getNetworkIdFromRouterName(dataBroker,routerName);
+ ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker,
+ routerName, externalNetworkId);
+ if (extNwProvType == null) {
+ return false;
+ }
+ hndlTepDelForDnatInEachRtr(router, routerId, srcDpnId, extNwProvType, writeFlowInvTx);
LOG.debug("handleTepDelForAllRtrs : TEP DEL : SNAT -> Withdrawing and Advertising routes for router {} ",
router.getRouter());
- hndlTepDelForSnatInEachRtr(router, srcDpnId, tunnelType, srcTepIp, destTepIp, tunnelName, writeFlowInvTx);
+ hndlTepDelForSnatInEachRtr(router, routerId, srcDpnId, tunnelType, srcTepIp, destTepIp,
+ tunnelName, extNwProvType, writeFlowInvTx);
}
return true;
}
- private void hndlTepAddForSnatInEachRtr(RoutersList router, final BigInteger srcDpnId, String tunnelType,
- String srcTepIp, String destTepIp, String tunnelName, String nextHopIp, WriteTransaction writeFlowInvTx) {
+ private void hndlTepAddForSnatInEachRtr(RoutersList router, long routerId, final BigInteger srcDpnId,
+ String tunnelType, String srcTepIp, String destTepIp, String tunnelName, String nextHopIp,
+ ProviderTypes extNwProvType, WriteTransaction writeFlowInvTx) {
/*SNAT : Remove the old routes to the external IP having the old TEP IP as the next hop IP
Advertise to the BGP about the new route to the external IP having the new TEP IP
return;
}
- long routerId = NatUtil.getVpnId(dataBroker, routerName);
BigInteger naptId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
if (naptId == null || naptId.equals(BigInteger.ZERO)) {
LOG.warn("hndlTepAddForSnatInEachRtr : SNAT -> Ignoring TEP add for the DPN {} having the router {} since"
natServiceManager.notify(routerData.get(), naptId, srcDpnId,
SnatServiceManager.Action.SNAT_ROUTER_ENBL);
} else {
+ Uuid bgpVpnUuId = NatUtil.getVpnForRouter(dataBroker, routerName);
//Check if the DPN having the router is the NAPT switch
if (!naptId.equals(srcDpnId)) {
/*
3) Install the flow 26 which forwards the packet to the group.
*/
if (!hndlTepAddOnNonNaptSwitch(srcDpnId, naptId, tunnelType, srcTepIp, destTepIp, tunnelName,
- routerName, routerId, writeFlowInvTx)) {
+ routerName, routerId, bgpVpnUuId, writeFlowInvTx)) {
LOG.error("hndlTepAddForSnatInEachRtr : Unable to process the TEP add event on NON-NAPT switch {}",
srcDpnId);
return;
return;
}
if (!hndlTepAddOnNaptSwitch(srcDpnId, tunnelType, srcTepIp, destTepIp, tunnelName, routerId,
- routerData, nextHopIp,writeFlowInvTx)) {
+ routerData, nextHopIp, bgpVpnUuId, extNwProvType, writeFlowInvTx)) {
LOG.debug("hndlTepAddForSnatInEachRtr : Unable to process the TEP add event on NAPT switch {}",
srcDpnId);
return;
private boolean hndlTepAddOnNonNaptSwitch(BigInteger srcDpnId, BigInteger primaryDpnId, String tunnelType,
String srcTepIp, String destTepIp, String tunnelName, String routerName,
- long routerId, WriteTransaction writeFlowInvTx) {
+ long routerId, Uuid vpnName, WriteTransaction writeFlowInvTx) {
/*
1) Install default NAT rule from table 21 to 26
+ "and TUNNEL NAME {} ",
srcDpnId, routerName, tunnelType, srcTepIp, destTepIp, tunnelName);
LOG.debug("hndlTepAddOnNonNaptSwitch : SNAT -> Install default NAT rule from table 21 to 26");
- Uuid vpnName = NatUtil.getVpnForRouter(dataBroker, routerName);
Long vpnId;
if (vpnName == null) {
LOG.debug("hndlTepAddOnNonNaptSwitch : SNAT -> Internal VPN associated to router {}", routerId);
LOG.debug("hndlTepAddOnNonNaptSwitch : SNAT -> Install the group which forward packet to the tunnel port "
+ "for the NAPT switch {} and the flow 26 which forwards to group", primaryDpnId);
- externalRouterListner.handleSwitches(srcDpnId, routerName, primaryDpnId, writeFlowInvTx);
+ externalRouterListner.handleSwitches(srcDpnId, routerName, routerId, primaryDpnId, writeFlowInvTx);
} else {
LOG.debug("hndlTepAddOnNonNaptSwitch : SNAT -> External BGP VPN (Private BGP) associated to router {}",
routerId);
LOG.debug("hndlTepAddOnNonNaptSwitch : Install group in non NAPT switch {} for router {}",
srcDpnId, routerName);
List<BucketInfo> bucketInfoForNonNaptSwitches =
- externalRouterListner.getBucketInfoForNonNaptSwitches(srcDpnId, primaryDpnId, routerName);
+ externalRouterListner.getBucketInfoForNonNaptSwitches(srcDpnId, primaryDpnId, routerName, routerId);
long groupId = externalRouterListner.installGroup(srcDpnId, routerName, bucketInfoForNonNaptSwitches);
LOG.debug("hndlTepAddOnNonNaptSwitch : SNAT -> in the SNAT miss entry pointing to group {} "
private boolean hndlTepAddOnNaptSwitch(BigInteger srcDpnId, String tunnelType, String srcTepIp,
String destTepIp, String tunnelName, long routerId,
- Optional<Routers> routerData, String nextHopIp,
- WriteTransaction writeFlowInvTx) {
+ Optional<Routers> routerData, String nextHopIp, Uuid vpnName,
+ ProviderTypes extNwProvType, WriteTransaction writeFlowInvTx) {
if (!routerData.isPresent()) {
LOG.warn("hndlTepAddOnNaptSwitch: routerData is not present");
return false;
}
LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Router {} is associated with Ext nw {}", routerId, networkId);
- Uuid vpnName = NatUtil.getVpnForRouter(dataBroker, routerName);
Long vpnId;
if (vpnName == null) {
LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Internal VPN associated to router {}", routerId);
//Withdraw the old route to the external IP from the BGP which was having the
//next hop as the old TEP IP.
- final String externalVpnName = NatUtil.getAssociatedVPN(dataBroker, networkId, LOG);
+ final String externalVpnName = NatUtil.getAssociatedVPN(dataBroker, networkId);
if (externalVpnName == null) {
LOG.error("hndlTepAddOnNaptSwitch : SNAT -> No VPN associated with ext nw {} in router {}",
networkId, routerId);
FIB manager.
*/
String rd = NatUtil.getVpnRd(dataBroker, externalVpnName);
- ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker,routerName);
if (extNwProvType == null) {
return false;
}
long l3Vni = 0;
if (extNwProvType == ProviderTypes.VXLAN) {
// Get the External Gateway MAC Address which is Router gateway MAC address for SNAT
- gwMacAddress = NatUtil.getExtGwMacAddFromRouterId(dataBroker, routerId);
+ gwMacAddress = NatUtil.getExtGwMacAddFromRouterName(dataBroker, routerName);
if (gwMacAddress != null) {
LOG.debug("hndlTepAddOnNaptSwitch : External Gateway MAC address {} found for External Router ID {}",
gwMacAddress, routerId);
l3Vni = NatOverVxlanUtil.getInternetVpnVni(idManager, externalVpnName, routerId).longValue();
}
}
- if (externalIps != null) {
- for (final String externalIp : externalIps) {
- long serviceId = 0;
- String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
- if (extNwProvType == ProviderTypes.VXLAN) {
- LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Advertise the route to the externalIp {} "
- + "having nextHopIp {}", externalIp, nextHopIp);
- NatEvpnUtil.addRoutesForVxLanProvType(dataBroker, bgpManager, fibManager, externalVpnName, rd,
- externalIp, nextHopIp, l3Vni, tunnelName, gwMacAddress, writeFlowInvTx, RouteOrigin.STATIC,
- srcDpnId);
- serviceId = l3Vni;
- } else {
- Long label = externalRouterListner.checkExternalIpLabel(routerId,
- externalIp);
- if (label == null || label == NatConstants.INVALID_ID) {
- LOG.error("hndlTepAddOnNaptSwitch : SNAT->Unable to advertise to the DC GW "
- + "since label is invalid");
- return false;
- }
- LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Advertise the route to the externalIp {} "
- + "having nextHopIp {}", externalIp, nextHopIp);
- long l3vni = 0;
- if (elanManager.isOpenStackVniSemanticsEnforced()) {
- l3vni = NatOverVxlanUtil.getInternetVpnVni(idManager, externalVpnName, l3vni).longValue();
- }
- Uuid externalSubnetId = NatUtil.getExternalSubnetForRouterExternalIp(dataBroker, externalIp,
- router);
- NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, externalVpnName, rd, externalSubnetId,
- fibExternalIp, nextHopIp, networkId.getValue(), null /* mac-address */, label, l3vni, LOG,
- RouteOrigin.STATIC, srcDpnId);
- serviceId = label;
+ for (final String externalIp : externalIps) {
+ long serviceId = 0;
+ String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
+ if (extNwProvType == ProviderTypes.VXLAN) {
+ LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Advertise the route to the externalIp {} "
+ + "having nextHopIp {}", externalIp, nextHopIp);
+ NatEvpnUtil.addRoutesForVxLanProvType(dataBroker, bgpManager, fibManager, externalVpnName, rd,
+ externalIp, nextHopIp, l3Vni, tunnelName, gwMacAddress, writeFlowInvTx, RouteOrigin.STATIC,
+ srcDpnId);
+ serviceId = l3Vni;
+ } else {
+
+ Long label = externalRouterListner.checkExternalIpLabel(routerId,
+ externalIp);
+ if (label == null || label == NatConstants.INVALID_ID) {
+ LOG.error("hndlTepAddOnNaptSwitch : SNAT->Unable to advertise to the DC GW "
+ + "since label is invalid");
+ return false;
+ }
+ LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Advertise the route to the externalIp {} "
+ + "having nextHopIp {}", externalIp, nextHopIp);
+ long l3vni = 0;
+ if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
+ l3vni = NatOverVxlanUtil.getInternetVpnVni(idManager, externalVpnName, l3vni).longValue();
}
+ Uuid externalSubnetId = NatUtil.getExternalSubnetForRouterExternalIp(dataBroker, externalIp,
+ router);
+ NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, externalVpnName, rd, externalSubnetId,
+ fibExternalIp, nextHopIp, networkId.getValue(), null /* mac-address */, label, l3vni,
+ RouteOrigin.STATIC, srcDpnId);
+ serviceId = label;
+ }
- LOG.debug("hndlTepAddOnNaptSwitch: SNAT -> Install custom FIB routes "
+ LOG.debug("hndlTepAddOnNaptSwitch: SNAT -> Install custom FIB routes "
+ "(Table 21 -> Push MPLS label to Tunnel port");
- List<Instruction> customInstructions = new ArrayList<>();
- int customInstructionIndex = 0;
- long externalSubnetVpnId = NatUtil.getExternalSubnetVpnIdForRouterExternalIp(dataBroker, externalIp,
- router);
- if (externalSubnetVpnId != NatConstants.INVALID_ID) {
- LOG.debug("hndlTepAddOnNaptSwitch : Will install custom FIB router with external subnet VPN ID {}",
- externalSubnetVpnId);
- BigInteger subnetIdMetaData = MetaDataUtil.getVpnIdMetadata(externalSubnetVpnId);
- customInstructions.add(new InstructionWriteMetadata(subnetIdMetaData,
- MetaDataUtil.METADATA_MASK_VRFID).buildInstruction(customInstructionIndex));
- customInstructionIndex++;
- }
- customInstructions.add(new InstructionGotoTable(NwConstants.INBOUND_NAPT_TABLE)
- .buildInstruction(customInstructionIndex));
- CreateFibEntryInput input =
+ List<Instruction> customInstructions = new ArrayList<>();
+ int customInstructionIndex = 0;
+ long externalSubnetVpnId = NatUtil.getExternalSubnetVpnIdForRouterExternalIp(dataBroker, externalIp,
+ router);
+ if (externalSubnetVpnId != NatConstants.INVALID_ID) {
+ LOG.debug("hndlTepAddOnNaptSwitch : Will install custom FIB router with external subnet VPN ID {}",
+ externalSubnetVpnId);
+ BigInteger subnetIdMetaData = MetaDataUtil.getVpnIdMetadata(externalSubnetVpnId);
+ customInstructions.add(new InstructionWriteMetadata(subnetIdMetaData,
+ MetaDataUtil.METADATA_MASK_VRFID).buildInstruction(customInstructionIndex));
+ customInstructionIndex++;
+ }
+ customInstructions.add(new InstructionGotoTable(NwConstants.INBOUND_NAPT_TABLE)
+ .buildInstruction(customInstructionIndex));
+ CreateFibEntryInput input =
new CreateFibEntryInputBuilder().setVpnName(externalVpnName).setSourceDpid(srcDpnId)
- .setInstruction(customInstructions).setIpAddress(fibExternalIp)
- .setServiceId(serviceId).setInstruction(customInstructions).build();
- Future<RpcResult<Void>> future = fibRpcService.createFibEntry(input);
- ListenableFuture<RpcResult<Void>> listenableFuture = JdkFutureAdapters.listenInPoolThread(future);
+ .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>>() {
+ Futures.addCallback(listenableFuture, new FutureCallback<RpcResult<Void>>() {
- @Override
- public void onFailure(@Nonnull Throwable error) {
- LOG.error("hndlTepAddOnNaptSwitch : SNAT->Error in generate label or fib install process",
- error);
- }
+ @Override
+ public void onFailure(@Nonnull Throwable error) {
+ LOG.error("hndlTepAddOnNaptSwitch : SNAT->Error in generate label or fib install process",
+ error);
+ }
- @Override
- public void onSuccess(RpcResult<Void> result) {
- if (result.isSuccessful()) {
- LOG.info("hndlTepAddOnNaptSwitch : SNAT -> Successfully installed custom FIB routes "
- + "for prefix {}", externalIp);
- } else {
- LOG.error("hndlTepAddOnNaptSwitch : SNAT -> Error in rpc call to create custom Fib entries "
- + "for prefix {} in DPN {}, {}", externalIp, srcDpnId, result.getErrors());
- }
+ @Override
+ public void onSuccess(@Nonnull RpcResult<Void> result) {
+ if (result.isSuccessful()) {
+ LOG.info("hndlTepAddOnNaptSwitch : SNAT -> Successfully installed custom FIB routes "
+ + "for prefix {}", externalIp);
+ } else {
+ LOG.error("hndlTepAddOnNaptSwitch : SNAT -> Error in rpc call to create custom Fib entries "
+ + "for prefix {} in DPN {}, {}", externalIp, srcDpnId, result.getErrors());
}
- });
- }
+ }
+ }, MoreExecutors.directExecutor());
}
+
return true;
}
- private void hndlTepAddForDnatInEachRtr(RoutersList router, String nextHopIp, BigInteger tepAddedDpnId,
- WriteTransaction writeFlowInvTx) {
+ private void hndlTepAddForDnatInEachRtr(RoutersList router, long routerId, String nextHopIp,
+ BigInteger tepAddedDpnId, ProviderTypes extNwProvType, WriteTransaction writeFlowInvTx) {
//DNAT : Advertise the new route to the floating IP having the new TEP IP as the next hop IP
final String routerName = router.getRouter();
}
RouterPorts routerPorts = optRouterPorts.get();
Uuid extNwId = routerPorts.getExternalNetworkId();
- final String vpnName = NatUtil.getAssociatedVPN(dataBroker, extNwId, LOG);
+ final String vpnName = NatUtil.getAssociatedVPN(dataBroker, extNwId);
if (vpnName == null) {
LOG.info("hndlTepAddForDnatInEachRtr : DNAT -> No External VPN associated with ext nw {} for router {}",
extNwId, routerName);
}
String rd = NatUtil.getVpnRd(dataBroker, vpnName);
- long routerId = NatUtil.getVpnId(dataBroker, routerName);
- ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker,routerName);
if (extNwProvType == null) {
return;
}
long l3Vni = 0;
if (extNwProvType == ProviderTypes.VXLAN) {
// Get the External Gateway MAC Address which is Router gateway MAC address for SNAT
- gwMacAddress = NatUtil.getExtGwMacAddFromRouterId(dataBroker, routerId);
+ gwMacAddress = NatUtil.getExtGwMacAddFromRouterName(dataBroker, routerName);
if (gwMacAddress != null) {
LOG.debug("hndlTepAddForDnatInEachRtr : External GwMAC address {} found for External Router ID {}",
gwMacAddress, routerId);
LOG.debug("hndlTepAddForDnatInEachRtr : DNAT -> Advertise the route to the externalIp {} "
+ "having nextHopIp {}", externalIp, nextHopIp);
long l3vni = 0;
- if (elanManager.isOpenStackVniSemanticsEnforced()) {
+ if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
l3vni = NatOverVxlanUtil.getInternetVpnVni(idManager, vpnName, l3vni).longValue();
}
NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, vpnName, rd, null,
- fibExternalIp, nextHopIp, null, null, label, l3vni, LOG, RouteOrigin.STATIC,
+ fibExternalIp, nextHopIp, null, null, label, l3vni, RouteOrigin.STATIC,
fipCfgdDpnId);
serviceId = label;
}
}
@Override
- public void onSuccess(RpcResult<Void> result) {
+ public void onSuccess(@Nonnull RpcResult<Void> result) {
if (result.isSuccessful()) {
LOG.info("hndlTepAddForDnatInEachRtr : DNAT -> Successfully installed custom FIB routes "
+ "for prefix {}", externalIp);
+ "entries for prefix {} in DPN {}, {}", externalIp, fipCfgdDpnId, result.getErrors());
}
}
- });
+ }, MoreExecutors.directExecutor());
}
}
}
- private void hndlTepDelForSnatInEachRtr(RoutersList router, BigInteger dpnId, String tunnelType,
+ private void hndlTepDelForSnatInEachRtr(RoutersList router, long routerId, BigInteger dpnId, String tunnelType,
String srcTepIp, String destTepIp, String tunnelName,
- WriteTransaction writeFlowInvTx) {
+ ProviderTypes extNwProvType, WriteTransaction writeFlowInvTx) {
/*SNAT :
1) Elect a new switch as the primary NAPT
2) Advertise the new routes to BGP for the newly elected TEP IP as the DPN IP
return;
}
- //Check if the router ID is valid
- long routerId = NatUtil.getVpnId(dataBroker, routerName);
- if (routerId == NatConstants.INVALID_ID) {
- LOG.error("hndlTepDelForSnatInEachRtr : SNAT -> Invalid ROUTER-ID {} returned for routerName {}",
- routerId, routerName);
- return;
- }
-
//Check if the DPN having the router is the NAPT switch
BigInteger naptId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
- if (naptId == null || naptId.equals(BigInteger.ZERO) || (!naptId.equals(dpnId))) {
+ if (naptId == null || naptId.equals(BigInteger.ZERO) || !naptId.equals(dpnId)) {
LOG.warn("hndlTepDelForSnatInEachRtr : SNAT -> Ignoring TEP delete for the DPN {} since"
+ " its NOT a NAPT switch for the TUNNEL TYPE {} b/w SRC IP {} and DST IP {} and"
+ "TUNNEL NAME {} ", dpnId, tunnelType, srcTepIp, destTepIp, tunnelName);
}
LOG.debug("hndlTepDelForSnatInEachRtr : SNAT->Router {} is associated with ext nw {}", routerId, networkId);
- Uuid vpnName = NatUtil.getVpnForRouter(dataBroker, routerName);
- Long vpnId;
- if (vpnName == null) {
+ Uuid bgpVpnUuid = NatUtil.getVpnForRouter(dataBroker, routerName);
+ Long bgpVpnId;
+ if (bgpVpnUuid == null) {
LOG.debug("hndlTepDelForSnatInEachRtr : SNAT->Internal VPN-ID {} associated to router {}",
routerId, routerName);
- vpnId = routerId;
+ bgpVpnId = routerId;
//Install default entry in FIB to SNAT table
LOG.debug("hndlTepDelForSnatInEachRtr : Installing default route in FIB on DPN {} for router {} with"
- + " vpn {}...", dpnId, routerName, vpnId);
- defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, vpnId, writeFlowInvTx);
+ + " vpn {}...", dpnId, routerName, bgpVpnId);
+ defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, bgpVpnId, writeFlowInvTx);
} else {
- vpnId = NatUtil.getVpnId(dataBroker, vpnName.getValue());
- if (vpnId == NatConstants.INVALID_ID) {
+ bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnUuid.getValue());
+ if (bgpVpnId == NatConstants.INVALID_ID) {
LOG.error("hndlTepDelForSnatInEachRtr :SNAT->Invalid Private BGP VPN ID returned for routerName {}",
routerName);
return;
}
LOG.debug("hndlTepDelForSnatInEachRtr :SNAT->External BGP VPN (Private BGP) {} associated to router {}",
- vpnId, routerName);
+ bgpVpnId, routerName);
//Install default entry in FIB to SNAT table
LOG.debug("hndlTepDelForSnatInEachRtr : Installing default route in FIB on dpn {} for routerId {} "
- + "with vpnId {}...", dpnId, routerId, vpnId);
- defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, vpnId, routerId, writeFlowInvTx);
+ + "with vpnId {}...", dpnId, routerId, bgpVpnId);
+ defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, bgpVpnId, routerId, writeFlowInvTx);
}
if (routerData.get().isEnableSnat()) {
LOG.info("hndlTepDelForSnatInEachRtr : SNAT enabled for router {}", routerId);
long routerVpnId = routerId;
- long bgpVpnId = NatConstants.INVALID_ID;
- Uuid bgpVpnUuid = NatUtil.getVpnForRouter(dataBroker, routerName);
- if (bgpVpnUuid != null) {
- bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnUuid.getValue());
- }
if (bgpVpnId != NatConstants.INVALID_ID) {
LOG.debug("hndlTepDelForSnatInEachRtr : SNAT -> Private BGP VPN ID (Internal BGP VPN ID) {} "
+ "associated to the router {}", bgpVpnId, routerName);
+ "associated to the router {}", routerVpnId, routerName);
}
//Re-elect the other available switch as the NAPT switch and program the NAT flows.
- removeSNATFromDPN(dpnId, routerName, routerVpnId, networkId, writeFlowInvTx);
+ removeSNATFromDPN(dpnId, routerName, routerId, routerVpnId, networkId, extNwProvType, writeFlowInvTx);
} else {
LOG.info("hndlTepDelForSnatInEachRtr : SNAT is not enabled for router {} to handle addDPN event {}",
routerId, dpnId);
}
}
- private void hndlTepDelForDnatInEachRtr(RoutersList router, BigInteger tepDeletedDpnId,
- WriteTransaction writeFlowInvTx) {
+ private void hndlTepDelForDnatInEachRtr(RoutersList router, long routerId, BigInteger tepDeletedDpnId,
+ ProviderTypes extNwProvType, WriteTransaction writeFlowInvTx) {
//DNAT : Withdraw the routes from the BGP
String routerName = router.getRouter();
- long routerId = NatUtil.getVpnId(dataBroker, routerName);
- if (routerId == NatConstants.INVALID_ID) {
- LOG.error("hndlTepDelForDnatInEachRtr : Unable to get RouterId from RouterName {}", routerName);
- return;
- }
+
LOG.debug("hndlTepDelForDnatInEachRtr : DNAT -> Trying to clear routes to the Floating IP "
+ "associated to the router {}", routerName);
}
RouterPorts routerPorts = optRouterPorts.get();
Uuid extNwId = routerPorts.getExternalNetworkId();
- final String vpnName = NatUtil.getAssociatedVPN(dataBroker, extNwId, LOG);
+ 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;
}
String rd = NatUtil.getVpnRd(dataBroker, vpnName);
- ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName);
if (extNwProvType == null) {
return;
}
}
@Override
- public void onSuccess(RpcResult<Void> result) {
+ public void onSuccess(@Nonnull RpcResult<Void> result) {
if (result.isSuccessful()) {
LOG.info("hndlTepDelForDnatInEachRtr : DNAT -> Successfully removed the entry pushing the "
+ "MPLS label to the tunnel");
+ "21 entry pushing the MPLS label to the tunnnel due to {}", result.getErrors());
}
}
- });
+ }, MoreExecutors.directExecutor());
}
}
}
String ifaceName = stateTunnelList.getTunnelInterfaceName();
if (getTunnelType(stateTunnelList) == NatConstants.ITMTunnelLocType.Internal.getValue()) {
Interface configIface = interfaceManager.getInterfaceInfoFromConfigDataStore(ifaceName);
- IfTunnel ifTunnel = (configIface != null) ? configIface.getAugmentation(IfTunnel.class) : null;
+ IfTunnel ifTunnel = configIface != null ? configIface.getAugmentation(IfTunnel.class) : null;
if (ifTunnel != null && ifTunnel.getTunnelInterfaceType().isAssignableFrom(TunnelTypeVxlan.class)) {
ParentRefs refs = configIface.getAugmentation(ParentRefs.class);
if (refs != null && !Strings.isNullOrEmpty(refs.getParentInterface())) {