+
+ private void reElectNewNaptSwitch(String routerName, Uint64 primaryNaptDpnId,
+ TypedReadWriteTransaction<Configuration> confTx) throws ExecutionException, InterruptedException {
+ // Check if this is externalRouter else ignore
+ InstanceIdentifier<Routers> extRoutersId = NatUtil.buildRouterIdentifier(routerName);
+ Optional<Routers> routerData =
+ SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
+ LogicalDatastoreType.CONFIGURATION, extRoutersId);
+ if (!routerData.isPresent()) {
+ LOG.debug("reElectNewNaptSwitch : SNAT->Ignoring Re-election for router {} since its not External Router",
+ routerName);
+ return;
+ }
+ Routers extRouters = routerData.get();
+ Uuid networkId = extRouters.getNetworkId();
+ if (networkId == null) {
+ LOG.error("hndlTepDelForSnatInEachRtr : SNAT -> Ignoring Re-election with Napt {} for router {}"
+ + "as external network configuraton is missing", primaryNaptDpnId, routerName);
+ return;
+ }
+ Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
+ LOG.debug("hndlTepDelForSnatInEachRtr : SNAT->Router {} is associated with ext nw {}", routerId, networkId);
+ Uuid bgpVpnUuid = NatUtil.getVpnForRouter(dataBroker, routerName);
+ Uint32 bgpVpnId;
+ if (bgpVpnUuid == null) {
+ LOG.debug("hndlTepDelForSnatInEachRtr : SNAT->Internal VPN-ID {} associated to router {}",
+ routerId, routerName);
+ bgpVpnId = routerId;
+ } else {
+ 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;
+ }
+ }
+ defaultRouteProgrammer.removeDefNATRouteInDPN(primaryNaptDpnId, bgpVpnId, confTx);
+ if (routerData.get().isEnableSnat()) {
+ LOG.info("hndlTepDelForSnatInEachRtr : SNAT enabled for router {}", routerId);
+
+ Uint32 routerVpnId = routerId;
+ if (bgpVpnId != NatConstants.INVALID_ID) {
+ LOG.debug("hndlTepDelForSnatInEachRtr : SNAT -> Private BGP VPN ID (Internal BGP VPN ID) {} "
+ + "associated to the router {}", bgpVpnId, routerName);
+ routerVpnId = bgpVpnId;
+ } else {
+ LOG.debug("hndlTepDelForSnatInEachRtr : SNAT -> Internal L3 VPN ID (Router ID) {} "
+ + "associated to the router {}", routerVpnId, routerName);
+ }
+ //Re-elect the other available switch as the NAPT switch and program the NAT flows.
+ ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker,
+ routerName, networkId);
+ String externalVpnName = NatUtil.getAssociatedVPN(dataBroker,extRouters.getNetworkId());
+ if (extNwProvType == null) {
+ return;
+ }
+ NatUtil.removeSNATFromDPN(dataBroker, mdsalManager, idManager, naptSwitchHA, primaryNaptDpnId, extRouters,
+ routerId, routerVpnId, externalVpnName, extNwProvType, confTx);
+
+ } else {
+ LOG.info("hndlTepDelForSnatInEachRtr : SNAT is not enabled for router {} to handle addDPN event {}",
+ routerId, primaryNaptDpnId);
+ }
+ }
+