+ if (isLastRouterDelete) {
+ removeLearntIpPorts(routers);
+ removeMipAdjacencies(routers);
+ }
+ return true;
+ }
+
+ @Override
+ public boolean addCentralizedRouter(TypedReadWriteTransaction<Configuration> confTx, Routers routers,
+ Uint64 primarySwitchId, Uint64 dpnId) {
+ if (!dpnId.equals(primarySwitchId)) {
+ LOG.info("addCentralizedRouter : Handle non NAPT switch {} for router {}",
+ dpnId, routers.getRouterName());
+ addCommonEntriesForNonNaptSwitch(confTx, routers, primarySwitchId, dpnId);
+ } else {
+ LOG.info("addCentralizedRouter : Handle NAPT switch {} for router {}", dpnId, routers.getRouterName());
+ addCommonEntriesForNaptSwitch(confTx, routers, dpnId);
+ }
+ return true;
+ }
+
+ @Override
+ public boolean removeCentralizedRouter(TypedReadWriteTransaction<Configuration> confTx, Routers routers,
+ Uint64 primarySwitchId, Uint64 dpnId) throws ExecutionException, InterruptedException {
+ if (!dpnId.equals(primarySwitchId)) {
+ LOG.info("removeCentralizedRouter : Handle non NAPT switch {} for router {}",
+ dpnId, routers.getRouterName());
+ removeCommonEntriesForNonNaptSwitch(confTx, routers, dpnId);
+ } else {
+ LOG.info("removeCentralizedRouter : Handle NAPT switch {} for router {}", dpnId, routers.getRouterName());
+ removeCommonEntriesForNaptSwitch(confTx, routers, dpnId);
+ }
+ return true;
+ }
+
+ @Override
+ public boolean handleRouterUpdate(TypedReadWriteTransaction<Configuration> confTx,
+ Routers origRouter, Routers updatedRouter) throws ExecutionException, InterruptedException {
+ return true;
+ }
+
+ private void addCommonEntriesForNaptSwitch(TypedReadWriteTransaction<Configuration> confTx, Routers routers,
+ Uint64 dpnId) {
+ String routerName = routers.getRouterName();
+ Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
+ addDefaultFibRouteForSNAT(confTx, dpnId, routerId);
+ for (ExternalIps externalIp : routers.nonnullExternalIps().values()) {
+ if (!NWUtil.isIpv4Address(externalIp.getIpAddress())) {
+ // In this class we handle only IPv4 use-cases.
+ continue;
+ }
+ //The logic now handle only one external IP per router, others if present will be ignored.
+ Uint32 extSubnetId = NatUtil.getExternalSubnetVpnId(dataBroker, externalIp.getSubnetId());
+ addInboundTerminatingServiceTblEntry(confTx, dpnId, routerId, extSubnetId);
+ addTerminatingServiceTblEntry(confTx, dpnId, routerId);
+ break;
+ }
+ }
+
+ private void removeCommonEntriesForNaptSwitch(TypedReadWriteTransaction<Configuration> confTx, Routers routers,
+ Uint64 dpnId) throws ExecutionException, InterruptedException {
+ String routerName = routers.getRouterName();
+ Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
+ removeDefaultFibRouteForSNAT(confTx, dpnId, routerId);
+ for (ExternalIps externalIp : routers.nonnullExternalIps().values()) {
+ if (!NWUtil.isIpv4Address(externalIp.getIpAddress())) {
+ // In this class we handle only IPv4 use-cases.
+ continue;
+ }
+ removeInboundTerminatingServiceTblEntry(confTx, dpnId, routerId);
+ removeTerminatingServiceTblEntry(confTx, dpnId, routerId);
+ break;
+ }
+ }
+
+ private void addSnatCommonEntriesForNaptSwitch(TypedReadWriteTransaction<Configuration> confTx, Routers routers,
+ Uint64 dpnId) {
+ String routerName = routers.getRouterName();
+ Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);