Bug 8310 - SNAT flows not added when the first subnet is added to the 02/56202/2
authorAswin Suryanarayanan <asuryana@redhat.com>
Wed, 26 Apr 2017 10:11:22 +0000 (15:41 +0530)
committerSam Hague <shague@redhat.com>
Fri, 28 Apr 2017 12:42:18 +0000 (12:42 +0000)
external n/w after router g/w set

1)Check for the presence of external IP during add.
2)Update now considers whether a subnet is added after router g/w set.

Change-Id: Ibb6f2a5cf031db18a624e68391415e6574242434
Signed-off-by: Aswin Suryanarayanan <asuryana@redhat.com>
vpnservice/natservice/natservice-impl/src/main/java/org/opendaylight/netvirt/natservice/internal/ExternalRoutersListener.java

index cf57c0e10b4a69e9c65f012e2f44fa0174f0d3af..aa61718a3999c6f228f2468c360dc521823cce53 100644 (file)
@@ -99,6 +99,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev16011
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.RouterIdName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.ExternalCounters;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounter;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMap;
@@ -228,8 +229,9 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
             if (bgpVpnUuid != null) {
                 return;
             }
+            Optional<List<ExternalIps>> externalIps = Optional.of(routers.getExternalIps());
             // Allocate Primary Napt Switch for this router
-            if (routers.isEnableSnat()) {
+            if (routers.isEnableSnat() && externalIps.isPresent() && !externalIps.get().isEmpty()) {
                 boolean result = centralizedSwitchScheduler.scheduleCentralizedSwitch(routerName);
             }
             //snatServiceManger.notify(routers, null, Action.ADD);
@@ -1129,16 +1131,6 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
             LOG.error("NAT Service : Update external router event - Invalid routerId for routerName {}", routerName);
             return;
         }
-        /* Get Primary Napt Switch for existing router from "router-to-napt-switch" DS.
-         * if dpnId value is null or zero then go for electing new Napt switch for existing router.
-         */
-        BigInteger dpnId = getPrimaryNaptSwitch(routerName, routerId);
-        if (dpnId == null || dpnId.equals(BigInteger.ZERO)) {
-            LOG.error("NAT Service: Failed to get or allocate NAPT switch for router {} during Update()", routerName);
-            return;
-        }
-        Uuid networkId = original.getNetworkId();
-
         // Check if its update on SNAT flag
         boolean originalSNATEnabled = original.isEnableSnat();
         boolean updatedSNATEnabled = update.isEnableSnat();
@@ -1154,7 +1146,24 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
                     centralizedSwitchScheduler.scheduleCentralizedSwitch(routerName);
                 }
             }
+            Optional<List<ExternalIps>> originalExternalIp = Optional.of(original.getExternalIps());
+            Optional<List<ExternalIps>> updateExternalIp = Optional.of(update.getExternalIps());
+            if (!originalExternalIp.equals(updateExternalIp)) {
+                if (!originalExternalIp.isPresent() || originalExternalIp.get().isEmpty()) {
+                    centralizedSwitchScheduler.scheduleCentralizedSwitch(routerName);
+                }
+            }
         } else {
+            /* Get Primary Napt Switch for existing router from "router-to-napt-switch" DS.
+             * if dpnId value is null or zero then go for electing new Napt switch for existing router.
+             */
+            BigInteger dpnId = getPrimaryNaptSwitch(routerName, routerId);
+            if (dpnId == null || dpnId.equals(BigInteger.ZERO)) {
+                LOG.error("NAT Service: Failed to get or allocate NAPT switch for router {} during Update()",
+                        routerName);
+                return;
+            }
+            Uuid networkId = original.getNetworkId();
             if (originalSNATEnabled != updatedSNATEnabled) {
                 if (originalSNATEnabled) {
                     //SNAT disabled for the router