Bug 9299 - In conntrack SNAT Vpn to dpn maps fails to update when a 87/64387/13
authorAswin Suryanarayanan <asuryana@redhat.com>
Tue, 17 Oct 2017 07:01:21 +0000 (12:31 +0530)
committerAswin Suryanarayanan <asuryana@redhat.com>
Sat, 4 Nov 2017 15:23:30 +0000 (15:23 +0000)
subnet is added/removed

Added update method in centralized switch scheduler. This will update
the maps when a subnet is added/ removed from the router.

Change-Id: I7418cf0e3586fc643c14c86f807c542ed586305d
Signed-off-by: Aswin Suryanarayanan <asuryana@redhat.com>
vpnservice/natservice/natservice-api/src/main/java/org/opendaylight/netvirt/natservice/api/CentralizedSwitchScheduler.java
vpnservice/natservice/natservice-impl/src/main/java/org/opendaylight/netvirt/natservice/ha/WeightedCentralizedSwitchScheduler.java
vpnservice/natservice/natservice-impl/src/main/java/org/opendaylight/netvirt/natservice/internal/AbstractSnatService.java
vpnservice/natservice/natservice-impl/src/main/java/org/opendaylight/netvirt/natservice/internal/ConntrackBasedSnatService.java
vpnservice/natservice/natservice-impl/src/main/java/org/opendaylight/netvirt/natservice/internal/ExternalRoutersListener.java
vpnservice/natservice/natservice-impl/src/main/java/org/opendaylight/netvirt/natservice/internal/RouterDpnChangeListener.java
vpnservice/natservice/natservice-impl/src/main/java/org/opendaylight/netvirt/natservice/internal/SnatServiceImplFactory.java

index 813f6f0bcaf24460f909050bac5a179d34848518..dc01d12e0206d952688bacd0ca85f6a466fdce3d 100644 (file)
@@ -10,21 +10,31 @@ package org.opendaylight.netvirt.natservice.api;
 
 import java.math.BigInteger;
 
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers;
+
 public interface CentralizedSwitchScheduler {
 
     /**
      * Schedule the centralized switch for the router.
-     * @param routerName the router name.
+     * @param router the external router.
      * @return success/failure
      */
-    boolean scheduleCentralizedSwitch(String routerName);
+    boolean scheduleCentralizedSwitch(Routers router);
+
+    /**
+     * Update the centralized switch scheduled for the router.
+     * @param oldRouter the existing external router.
+     * @param newRouter the new external router.
+     * @return  success/failure
+     */
+    boolean updateCentralizedSwitch(Routers oldRouter, Routers newRouter);
 
     /**
      * Releases the centralized switch scheduled for the router.
-     * @param routerName the router name.
+     * @param router the external router.
      * @return success/failure
      */
-    boolean releaseCentralizedSwitch(String routerName);
+    boolean releaseCentralizedSwitch(Routers router);
 
     /**
      * Retrieves the centralized switch scheduled for the router.
index ed451c8d2738668d7f976aea470e63ac14a3df9f..645cf9cacaaf3f18065d3789146619584ce55ee9 100644 (file)
@@ -8,17 +8,19 @@
 
 package org.opendaylight.netvirt.natservice.ha;
 
-import com.google.common.base.Optional;
-
 import java.math.BigInteger;
-import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
 import org.opendaylight.netvirt.natservice.api.CentralizedSwitchScheduler;
@@ -35,86 +37,64 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev15060
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 @Singleton
 public class WeightedCentralizedSwitchScheduler implements CentralizedSwitchScheduler {
-    private final Map<BigInteger,Integer> switchWeightsMap = new HashMap<>();
+    private static final Logger LOG = LoggerFactory.getLogger(WeightedCentralizedSwitchScheduler.class);
+    private final Map<BigInteger,Integer> switchWeightsMap = new ConcurrentHashMap<>();
+    private final Map<String,String> subnetIdToRouterPortMap = new ConcurrentHashMap<>();
     private final DataBroker dataBroker;
-    private final NatDataUtil natDataUtil;
     final OdlInterfaceRpcService interfaceManager;
     private final int initialSwitchWeight = 0;
     private final IVpnFootprintService vpnFootprintService;
 
     @Inject
     public WeightedCentralizedSwitchScheduler(DataBroker dataBroker, OdlInterfaceRpcService interfaceManager,
-            NatDataUtil natDataUtil, IVpnFootprintService vpnFootprintService) {
+            IVpnFootprintService vpnFootprintService) {
         this.dataBroker = dataBroker;
         this.interfaceManager = interfaceManager;
-        this.natDataUtil = natDataUtil;
         this.vpnFootprintService = vpnFootprintService;
     }
 
     @Override
-    public boolean scheduleCentralizedSwitch(String routerName) {
+    public boolean scheduleCentralizedSwitch(Routers router) {
         BigInteger nextSwitchId = getSwitchWithLowestWeight();
+        String routerName = router.getRouterName();
         RouterToNaptSwitchBuilder routerToNaptSwitchBuilder =
                 new RouterToNaptSwitchBuilder().setRouterName(routerName);
         RouterToNaptSwitch id = routerToNaptSwitchBuilder.setPrimarySwitchId(nextSwitchId).build();
+        addToDpnMaps(routerName, router.getSubnetIds(), nextSwitchId);
         try {
-            WriteTransaction writeOperTxn = dataBroker.newWriteOnlyTransaction();
-            Routers router = NatUtil.getRoutersFromConfigDS(dataBroker, routerName);
-            String vpnName = router.getRouterName();
-            String primaryRd = NatUtil.getPrimaryRd(dataBroker, vpnName);
-            for (Uuid subnetUuid :router.getSubnetIds()) {
-                Optional<Subnetmap> subnetMapEntry =
-                        SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(
-                                dataBroker, LogicalDatastoreType.CONFIGURATION, getSubnetMapIdentifier(subnetUuid));
-                if (subnetMapEntry.isPresent()) {
-
-                    Uuid routerPortUuid = subnetMapEntry.get().getRouterInterfacePortId();
-
-                    vpnFootprintService.updateVpnToDpnMapping(nextSwitchId, vpnName, primaryRd,
-                            routerPortUuid.getValue(), null, true);
-                    NatUtil.addToNeutronRouterDpnsMap(dataBroker, routerName, routerPortUuid.getValue(),
-                            nextSwitchId, writeOperTxn);
-                    NatUtil.addToDpnRoutersMap(dataBroker, routerName, routerPortUuid.getValue(),
-                            nextSwitchId, writeOperTxn);
-                }
-            }
-            writeOperTxn.submit();
             SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
                     getNaptSwitchesIdentifier(routerName), id);
             switchWeightsMap.put(nextSwitchId,switchWeightsMap.get(nextSwitchId) + 1);
 
         } catch (TransactionCommitFailedException e) {
-            // TODO Auto-generated catch block
+            LOG.error("ScheduleCentralizedSwitch failed for {}", routerName);
         }
         return true;
 
     }
 
     @Override
-    public boolean releaseCentralizedSwitch(String routerName) {
+    public boolean updateCentralizedSwitch(Routers oldRouter, Routers newRouter) {
+        String routerName = newRouter.getRouterName();
+        List<Uuid> addedSubnetIds = getUpdatedSubnetIds(newRouter.getSubnetIds(), oldRouter.getSubnetIds());
+        List<Uuid> deletedSubnetIds = getUpdatedSubnetIds(oldRouter.getSubnetIds(), newRouter.getSubnetIds());
+        BigInteger primarySwitchId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, newRouter.getRouterName());
+        addToDpnMaps(routerName, addedSubnetIds, primarySwitchId);
+        deleteFromDpnMaps(routerName, deletedSubnetIds, primarySwitchId);
+        return true;
+    }
+
+    @Override
+    public boolean releaseCentralizedSwitch(Routers router) {
+        String routerName = router.getRouterName();
         BigInteger primarySwitchId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
+        deleteFromDpnMaps(routerName, router.getSubnetIds(), primarySwitchId);
         try {
-            WriteTransaction writeOperTxn = dataBroker.newWriteOnlyTransaction();
-            Routers router = natDataUtil.getRouter(routerName);
-            String vpnName = router.getRouterName();
-            String primaryRd = NatUtil.getPrimaryRd(dataBroker, vpnName);
-            for (Uuid subnetUuid :router.getSubnetIds()) {
-                Optional<Subnetmap> subnetMapEntry =
-                        SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(
-                                dataBroker, LogicalDatastoreType.CONFIGURATION, getSubnetMapIdentifier(subnetUuid));
-                if (subnetMapEntry.isPresent()) {
-                    Uuid routerPortUuid = subnetMapEntry.get().getRouterInterfacePortId();
-                    vpnFootprintService.updateVpnToDpnMapping(primarySwitchId, vpnName, primaryRd,
-                            routerPortUuid.getValue(), null, false);
-                    NatUtil.removeFromNeutronRouterDpnsMap(dataBroker, routerName, primarySwitchId, writeOperTxn);
-                    NatUtil.removeFromDpnRoutersMap(dataBroker, routerName, routerName, interfaceManager,
-                            writeOperTxn);
-                }
-            }
-            writeOperTxn.submit();
             SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
                     getNaptSwitchesIdentifier(routerName));
             switchWeightsMap.put(primarySwitchId,switchWeightsMap.get(primarySwitchId) - 1);
@@ -124,6 +104,56 @@ public class WeightedCentralizedSwitchScheduler implements CentralizedSwitchSche
         return true;
     }
 
+    private void addToDpnMaps(String routerName, List<Uuid> addedSubnetIds, BigInteger primarySwitchId) {
+        if (addedSubnetIds == null || addedSubnetIds.isEmpty()) {
+            LOG.debug("addToDpnMaps no subnets associated with {}", routerName);
+            return;
+        }
+        String primaryRd = NatUtil.getPrimaryRd(dataBroker, routerName);
+        WriteTransaction writeOperTxn = dataBroker.newWriteOnlyTransaction();
+        for (Uuid subnetUuid : addedSubnetIds) {
+            try {
+                Subnetmap subnetMapEntry = SingleTransactionDataBroker.syncRead(dataBroker,
+                        LogicalDatastoreType.CONFIGURATION, getSubnetMapIdentifier(subnetUuid));
+                Uuid routerPortUuid = subnetMapEntry.getRouterInterfacePortId();
+                subnetIdToRouterPortMap.put(subnetUuid.getValue(), routerPortUuid.getValue());
+                vpnFootprintService.updateVpnToDpnMapping(primarySwitchId, routerName, primaryRd,
+                        routerPortUuid.getValue(), null, true);
+                NatUtil.addToNeutronRouterDpnsMap(dataBroker, routerName, routerPortUuid.getValue(),
+                        primarySwitchId, writeOperTxn);
+                NatUtil.addToDpnRoutersMap(dataBroker, routerName, routerPortUuid.getValue(),
+                        primarySwitchId, writeOperTxn);
+            } catch (ReadFailedException e) {
+                LOG.error("addToDpnMaps failed for {}", routerName);
+            }
+        }
+        writeOperTxn.submit();
+    }
+
+
+
+    private void deleteFromDpnMaps(String routerName, List<Uuid> deletedSubnetIds, BigInteger primarySwitchId) {
+        if (deletedSubnetIds == null || deletedSubnetIds.isEmpty()) {
+            LOG.debug("deleteFromDpnMaps no subnets associated with {}", routerName);
+            return;
+        }
+        WriteTransaction writeOperTxn = dataBroker.newWriteOnlyTransaction();
+        String primaryRd = NatUtil.getPrimaryRd(dataBroker, routerName);
+        for (Uuid subnetUuid :deletedSubnetIds) {
+            String routerPort = subnetIdToRouterPortMap.remove(subnetUuid.getValue());
+            if (routerPort == null) {
+                LOG.error("The router port was not found for {}", subnetUuid.getValue());
+                continue;
+            }
+            vpnFootprintService.updateVpnToDpnMapping(primarySwitchId, routerName, primaryRd,
+                    routerPort, null, false);
+            NatUtil.removeFromNeutronRouterDpnsMap(dataBroker, routerName, primarySwitchId, writeOperTxn);
+            NatUtil.removeFromDpnRoutersMap(dataBroker, routerName, routerName, interfaceManager,
+                    writeOperTxn);
+        }
+        writeOperTxn.submit();
+    }
+
     @Override
     public boolean addSwitch(BigInteger dpnId) {
         /* Initialize the switch in the map with weight 0 */
@@ -138,9 +168,10 @@ public class WeightedCentralizedSwitchScheduler implements CentralizedSwitchSche
             NaptSwitches naptSwitches = getNaptSwitches(dataBroker);
             for (RouterToNaptSwitch routerToNaptSwitch : naptSwitches.getRouterToNaptSwitch()) {
                 if (dpnId.equals(routerToNaptSwitch.getPrimarySwitchId())) {
-                    releaseCentralizedSwitch(routerToNaptSwitch.getRouterName());
+                    Routers router = NatUtil.getRoutersFromConfigDS(dataBroker, routerToNaptSwitch.getRouterName());
+                    releaseCentralizedSwitch(router);
                     switchWeightsMap.remove(dpnId);
-                    scheduleCentralizedSwitch(routerToNaptSwitch.getRouterName());
+                    scheduleCentralizedSwitch(router);
                     break;
                 }
             }
@@ -183,4 +214,27 @@ public class WeightedCentralizedSwitchScheduler implements CentralizedSwitchSche
         // TODO Auto-generated method stub
         return false;
     }
+
+    public static List<Uuid> getUpdatedSubnetIds(
+            List<Uuid> updatedSubnetIds,
+            List<Uuid> currentSubnetIds) {
+        if (updatedSubnetIds == null) {
+            return null;
+        }
+        List<Uuid> newSubnetIds = new ArrayList<>(updatedSubnetIds);
+        if (currentSubnetIds == null) {
+            return newSubnetIds;
+        }
+        List<Uuid> origSubnetIds = new ArrayList<>(currentSubnetIds);
+        for (Iterator<Uuid> iterator = newSubnetIds.iterator(); iterator.hasNext();) {
+            Uuid updatedSubnetId = iterator.next();
+            for (Uuid currentSubnetId : origSubnetIds) {
+                if (updatedSubnetId.getValue().equals(currentSubnetId.getValue())) {
+                    iterator.remove();
+                    break;
+                }
+            }
+        }
+        return newSubnetIds;
+    }
 }
\ No newline at end of file
index 1d6c2fc368afba82734b964f37322f3863e259c6..b544dd6be1f9555886a85c3c6c113cdfa5bdd45c 100644 (file)
@@ -36,7 +36,6 @@ import org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination;
 import org.opendaylight.genius.mdsalutil.matches.MatchMetadata;
 import org.opendaylight.genius.mdsalutil.matches.MatchTunnelId;
 import org.opendaylight.netvirt.natservice.api.SnatServiceListener;
-import org.opendaylight.netvirt.vpnmanager.api.IVpnManager;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput;
@@ -57,34 +56,28 @@ import org.slf4j.LoggerFactory;
 
 public abstract class AbstractSnatService implements SnatServiceListener {
 
+    private static final Logger LOG = LoggerFactory.getLogger(AbstractSnatService.class);
+    static final int LOAD_START = mostSignificantBit(MetaDataUtil.METADATA_MASK_SH_FLAG.intValue());
+    static final int LOAD_END = mostSignificantBit(MetaDataUtil.METADATA_MASK_VRFID.intValue() | MetaDataUtil
+            .METADATA_MASK_SH_FLAG.intValue());
     protected final DataBroker dataBroker;
     protected final IMdsalApiManager mdsalManager;
     protected final IdManagerService idManager;
-    protected final NaptManager naptManager;
     protected final NAPTSwitchSelector naptSwitchSelector;
     protected final ItmRpcService itmManager;
     protected final OdlInterfaceRpcService interfaceManager;
-    private final IVpnManager vpnManager;
-    private static final Logger LOG = LoggerFactory.getLogger(AbstractSnatService.class);
-    static final int LOAD_START = mostSignificantBit(MetaDataUtil.METADATA_MASK_SH_FLAG.intValue());
-    static final int LOAD_END = mostSignificantBit(MetaDataUtil.METADATA_MASK_VRFID.intValue() | MetaDataUtil
-            .METADATA_MASK_SH_FLAG.intValue());
 
     public AbstractSnatService(final DataBroker dataBroker, final IMdsalApiManager mdsalManager,
             final ItmRpcService itmManager,
             final OdlInterfaceRpcService interfaceManager,
             final IdManagerService idManager,
-            final NaptManager naptManager,
-            final NAPTSwitchSelector naptSwitchSelector,
-            final IVpnManager vpnManager) {
+            final NAPTSwitchSelector naptSwitchSelector) {
         this.dataBroker = dataBroker;
         this.mdsalManager = mdsalManager;
         this.itmManager = itmManager;
         this.interfaceManager = interfaceManager;
         this.idManager = idManager;
-        this.naptManager = naptManager;
         this.naptSwitchSelector = naptSwitchSelector;
-        this.vpnManager = vpnManager;
     }
 
     public void init() {
@@ -304,24 +297,6 @@ public abstract class AbstractSnatService implements SnatServiceListener {
                 NwConstants.COOKIE_SNAT_TABLE, matches, instructions, addOrRemove);
     }
 
-    protected BigInteger getPrimaryNaptSwitch(String routerName, long routerId) {
-        // Allocate Primary Napt Switch for this router
-        BigInteger primarySwitchId = NatUtil.getPrimaryNaptfromRouterId(dataBroker, routerId);
-        if (primarySwitchId != null && !primarySwitchId.equals(BigInteger.ZERO)) {
-            LOG.debug("getPrimaryNaptSwitch : Primary NAPT switch with DPN ID {} is already elected for router",
-                    primarySwitchId, routerName);
-            return primarySwitchId;
-        }
-
-        primarySwitchId = naptSwitchSelector.selectNewNAPTSwitch(routerName);
-        LOG.debug("getPrimaryNaptSwitch : Primary NAPT switch DPN ID {}", primarySwitchId);
-        if (primarySwitchId == null || primarySwitchId.equals(BigInteger.ZERO)) {
-            LOG.error("getPrimaryNaptSwitch : Unable to to select the primary NAPT switch");
-        }
-
-        return primarySwitchId;
-    }
-
     protected String getFlowRef(BigInteger dpnId, short tableId, long routerID) {
         return new StringBuilder().append(NatConstants.NAPT_FLOWID_PREFIX).append(dpnId).append(NatConstants
                 .FLOWID_SEPARATOR).append(tableId).append(NatConstants.FLOWID_SEPARATOR).append(routerID).toString();
index 87727289b3b271afdbb2ba04d833005b2a2c569a..0149706e7363f719186f21c9252c5747da5a9dbd 100644 (file)
@@ -31,7 +31,6 @@ import org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination;
 import org.opendaylight.genius.mdsalutil.matches.MatchMetadata;
 import org.opendaylight.genius.mdsalutil.matches.MatchTunnelId;
 import org.opendaylight.genius.mdsalutil.nxmatches.NxMatchCtState;
-import org.opendaylight.netvirt.vpnmanager.api.IVpnManager;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService;
@@ -46,19 +45,18 @@ import org.slf4j.LoggerFactory;
 
 public class ConntrackBasedSnatService extends AbstractSnatService {
 
+    private static final Logger LOG = LoggerFactory.getLogger(ConntrackBasedSnatService.class);
     protected final int trackedNewCtState = 0x21;
     protected final int trackedNewCtMask = 0x21;
     protected final int snatCtState = 0x40;
     protected final int snatCtStateMask = 0x40;
     protected final int dnatCtState = 0x80;
     protected final int dnatCtStateMask = 0x80;
-    private static final Logger LOG = LoggerFactory.getLogger(ConntrackBasedSnatService.class);
 
     public ConntrackBasedSnatService(DataBroker dataBroker, IMdsalApiManager mdsalManager, ItmRpcService itmManager,
-            OdlInterfaceRpcService interfaceManager, IdManagerService idManager, NaptManager naptManager,
-            NAPTSwitchSelector naptSwitchSelector, IVpnManager vpnManager) {
-        super(dataBroker, mdsalManager, itmManager, interfaceManager, idManager, naptManager, naptSwitchSelector,
-                vpnManager);
+            OdlInterfaceRpcService interfaceManager, IdManagerService idManager,
+            NAPTSwitchSelector naptSwitchSelector) {
+        super(dataBroker, mdsalManager, itmManager, interfaceManager, idManager, naptSwitchSelector);
     }
 
     @Override
index d9187494934487695d572315b0fe20e7daadf083..0a14e9eab7966f65a2b824726c3917652de34848 100644 (file)
@@ -239,7 +239,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
             List<ExternalIps> externalIps = routers.getExternalIps();
             // Allocate Primary Napt Switch for this router
             if (routers.isEnableSnat() && externalIps != null && !externalIps.isEmpty()) {
-                boolean result = centralizedSwitchScheduler.scheduleCentralizedSwitch(routerName);
+                boolean result = centralizedSwitchScheduler.scheduleCentralizedSwitch(routers);
             }
             //snatServiceManger.notify(routers, null, Action.ADD);
         } else {
@@ -1190,16 +1190,18 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
                 BigInteger primarySwitchId;
                 if (originalSNATEnabled) {
                     //SNAT disabled for the router
-                    centralizedSwitchScheduler.releaseCentralizedSwitch(routerName);
+                    centralizedSwitchScheduler.releaseCentralizedSwitch(update);
                 } else {
-                    centralizedSwitchScheduler.scheduleCentralizedSwitch(routerName);
+                    centralizedSwitchScheduler.scheduleCentralizedSwitch(update);
                 }
+            } else if (updatedSNATEnabled) {
+                centralizedSwitchScheduler.updateCentralizedSwitch(original,update);
             }
             List<ExternalIps> originalExternalIps = original.getExternalIps();
             List<ExternalIps> updateExternalIps = update.getExternalIps();
             if (!Objects.equals(originalExternalIps, updateExternalIps)) {
                 if (originalExternalIps == null || originalExternalIps.isEmpty()) {
-                    centralizedSwitchScheduler.scheduleCentralizedSwitch(routerName);
+                    centralizedSwitchScheduler.scheduleCentralizedSwitch(update);
                 }
             }
         } else {
@@ -1653,7 +1655,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
             String routerName = router.getRouterName();
             if (natMode == NatMode.Conntrack) {
                 if (router.isEnableSnat()) {
-                    centralizedSwitchScheduler.releaseCentralizedSwitch(routerName);
+                    centralizedSwitchScheduler.releaseCentralizedSwitch(router);
                 }
             } else {
                 DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance();
index 0d723c1b28eced1580e9e9ec183e1148e700c739..856c0e9233d3f5c6175f8e010ce753193b564359 100644 (file)
@@ -23,7 +23,6 @@ import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
 import org.opendaylight.genius.datastoreutils.DataStoreJobCoordinator;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
@@ -41,7 +40,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.NeutronRouterDpns;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.RouterDpnList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesList;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.config.rev170206.NatserviceConfig;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.config.rev170206.NatserviceConfig.NatMode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes;
@@ -133,26 +131,10 @@ public class RouterDpnChangeListener
                         LOG.warn("add : NAPT switch is not selected.");
                         return;
                     }
-                    //If it is a router port skip the notify.
-                    for (Uuid subnetUuid :router.getSubnetIds()) {
-                        try {
-                            Optional<Subnetmap> subnetMapEntry =
-                                    SingleTransactionDataBroker.syncReadOptional(dataBroker,
-                                            LogicalDatastoreType.CONFIGURATION, getSubnetMapIdentifier(subnetUuid));
-                            if (subnetMapEntry.isPresent()) {
-                                String routerPortUuid = subnetMapEntry.get().getRouterInterfacePortId().getValue();
-                                List<RouterInterfaces> routerInterfaces = dpnInfo.getRouterInterfaces();
-                                for (RouterInterfaces routerInterface : routerInterfaces) {
-                                    if (routerPortUuid.equals(routerInterface.getInterface())) {
-                                        return;
-                                    }
-                                }
-                            }
-                        } catch (ReadFailedException e) {
-                            LOG.warn("add : The subnet map entry is not present.");
-                            return;
-                        }
-
+                    //If it is for NAPT switch skip as the flows would be already programmed.
+                    if (naptSwitch.equals(dpnId)) {
+                        LOG.debug("Skipping the notification recived for NAPT switch {}", routerUuid);
+                        return;
                     }
                     natServiceManager.notify(router, naptSwitch, dpnId,
                             SnatServiceManager.Action.SNAT_ROUTER_ENBL);
@@ -261,6 +243,11 @@ public class RouterDpnChangeListener
                         LOG.warn("remove : NAPT switch is not selected.");
                         return;
                     }
+                    //If it is for NAPT switch skip as the flows would be already programmed.
+                    if (naptSwitch.equals(dpnId)) {
+                        LOG.debug("Skipping the notification recived for NAPT switch {}", routerUuid);
+                        return;
+                    }
                     natServiceManager.notify(router, naptSwitch, dpnId,
                             SnatServiceManager.Action.SNAT_ROUTER_DISBL);
                 } else {
index 66c50a56315efd71c8b31e1308b00aac4e744364..72db0b65c8cdeebfa56a578a753f1effd5a02a31 100644 (file)
@@ -13,7 +13,6 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.infrautils.inject.AbstractLifecycle;
 import org.opendaylight.netvirt.neutronvpn.interfaces.INeutronVpnManager;
-import org.opendaylight.netvirt.vpnmanager.api.IVpnManager;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
@@ -32,10 +31,8 @@ public class SnatServiceImplFactory extends AbstractLifecycle {
     private final ItmRpcService itmManager;
     private final OdlInterfaceRpcService interfaceManager;
     private final IdManagerService idManager;
-    private final NaptManager naptManager;
     private final NAPTSwitchSelector naptSwitchSelector;
     private NatMode natMode;
-    private final IVpnManager vpnManager;
     private final INeutronVpnManager nvpnManager;
 
     @Inject
@@ -43,9 +40,7 @@ public class SnatServiceImplFactory extends AbstractLifecycle {
             final ItmRpcService itmManager,
             final OdlInterfaceRpcService interfaceManager,
             final IdManagerService idManager,
-            final NaptManager naptManager,
             final NAPTSwitchSelector naptSwitchSelector,
-            final IVpnManager vpnManager,
             final NatserviceConfig config,
             final INeutronVpnManager nvpnManager) {
         this.dataBroker = dataBroker;
@@ -53,9 +48,7 @@ public class SnatServiceImplFactory extends AbstractLifecycle {
         this.itmManager = itmManager;
         this.interfaceManager = interfaceManager;
         this.idManager = idManager;
-        this.naptManager = naptManager;
         this.naptSwitchSelector = naptSwitchSelector;
-        this.vpnManager = vpnManager;
         if (config != null) {
             this.natMode = config.getNatMode();
         }
@@ -78,7 +71,7 @@ public class SnatServiceImplFactory extends AbstractLifecycle {
             NatOverVxlanUtil.validateAndCreateVxlanVniPool(dataBroker, nvpnManager, idManager,
                     NatConstants.ODL_VNI_POOL_NAME);
             return new ConntrackBasedSnatService(dataBroker, mdsalManager, itmManager, interfaceManager, idManager,
-                naptManager, naptSwitchSelector, vpnManager);
+                    naptSwitchSelector);
         }
         return null;
     }