Clean up MDSALManager exception handling 29/74229/4
authorStephen Kitt <skitt@redhat.com>
Wed, 18 Jul 2018 16:24:34 +0000 (18:24 +0200)
committerSam Hague <shague@redhat.com>
Sat, 28 Jul 2018 04:05:07 +0000 (04:05 +0000)
Now that the MDSALManager interfaces have been updated, we can adjust
NetVirt to use the exceptions as declared instead of dealing with
Exception.

Change-Id: I4b41025f54f63a66a01b1f9b50d4f12918863289
Signed-off-by: Stephen Kitt <skitt@redhat.com>
31 files changed:
dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpExternalTunnelManager.java
dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpManager.java
dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpServiceUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanInterfaceManager.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanLearntVpnVipToPortListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanUtils.java
natservice/api/src/main/java/org/opendaylight/netvirt/natservice/api/SnatServiceListener.java
natservice/api/src/main/java/org/opendaylight/netvirt/natservice/api/SnatServiceManager.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/ha/SnatCentralizedSwitchChangeListener.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/AbstractSnatService.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/ConntrackBasedSnatService.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/EvpnDnatFlowProgrammer.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/EvpnNaptSwitchHA.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/EvpnSnatFlowProgrammer.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/ExternalNetworksChangeListener.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/ExternalRoutersListener.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/FlatVlanConntrackBasedSnatService.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/FloatingIPListener.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NaptSwitchHA.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NatEvpnUtil.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NatTunnelInterfaceStateListener.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NatUtil.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/RouterDpnChangeListener.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/RouterToVpnListener.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/SNATDefaultRouteProgrammer.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/SnatServiceManagerImpl.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/VpnFloatingIpHandler.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/VxlanGreConntrackBasedSnatService.java
vpnmanager/api/src/main/java/org/opendaylight/netvirt/vpnmanager/api/IVpnManager.java
vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/CentralizedSwitchChangeListener.java
vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnManagerImpl.java

index 002999482e800994990e56fcd8739b28d29ba874..07d590a0a9d242cfc60d2fb75b1cde0fb9b453d3 100644 (file)
@@ -248,7 +248,7 @@ public class DhcpExternalTunnelManager implements IDhcpExternalTunnelManager {
     }
 
     public void installDhcpFlowsForVms(BigInteger designatedDpnId, Set<String> listVmMacAddress,
-        TypedReadWriteTransaction<Configuration> tx) {
+            TypedReadWriteTransaction<Configuration> tx) throws ExecutionException, InterruptedException {
         for (String vmMacAddress : listVmMacAddress) {
             installDhcpEntries(designatedDpnId, vmMacAddress, tx);
         }
@@ -428,7 +428,7 @@ public class DhcpExternalTunnelManager implements IDhcpExternalTunnelManager {
     }
 
     public void updateCacheAndInstallNewFlows(List<BigInteger> listOfDpns, Pair<IpAddress, String> pair,
-            TypedReadWriteTransaction<Configuration> tx) {
+            TypedReadWriteTransaction<Configuration> tx) throws ExecutionException, InterruptedException {
         BigInteger newDesignatedDpn = chooseDpn(pair.getLeft(), pair.getRight(), listOfDpns);
         if (newDesignatedDpn.equals(DhcpMConstants.INVALID_DPID)) {
             return;
@@ -446,7 +446,8 @@ public class DhcpExternalTunnelManager implements IDhcpExternalTunnelManager {
     }
 
     private void changeExistingFlowToDrop(Pair<IpAddress, String> tunnelIpElanNamePair, BigInteger dpnId,
-                                          TypedReadWriteTransaction<Configuration> tx) {
+                                          TypedReadWriteTransaction<Configuration> tx)
+            throws ExecutionException, InterruptedException {
         Set<String> setOfVmMacAddress = tunnelIpElanNameToVmMacCache.get(tunnelIpElanNamePair);
         if (setOfVmMacAddress == null || setOfVmMacAddress.isEmpty()) {
             return;
@@ -517,7 +518,7 @@ public class DhcpExternalTunnelManager implements IDhcpExternalTunnelManager {
     }
 
     private void installDhcpEntries(BigInteger dpnId, String vmMacAddress,
-        TypedReadWriteTransaction<Configuration> tx) {
+            TypedReadWriteTransaction<Configuration> tx) throws ExecutionException, InterruptedException {
         DhcpServiceUtils.setupDhcpFlowEntry(dpnId, NwConstants.DHCP_TABLE_EXTERNAL_TUNNEL,
                 vmMacAddress, NwConstants.ADD_FLOW, mdsalUtil, dhcpServiceCounters, tx);
     }
@@ -639,13 +640,13 @@ public class DhcpExternalTunnelManager implements IDhcpExternalTunnelManager {
 
 
     public void unInstallDhcpEntries(BigInteger dpnId, String vmMacAddress,
-        TypedReadWriteTransaction<Configuration> tx) {
+            TypedReadWriteTransaction<Configuration> tx) throws ExecutionException, InterruptedException {
         DhcpServiceUtils.setupDhcpFlowEntry(dpnId, NwConstants.DHCP_TABLE_EXTERNAL_TUNNEL,
                 vmMacAddress, NwConstants.DEL_FLOW, mdsalUtil, dhcpServiceCounters, tx);
     }
 
     private void installDhcpDropAction(BigInteger dpn, String vmMacAddress,
-        TypedReadWriteTransaction<Configuration> tx) {
+            TypedReadWriteTransaction<Configuration> tx) throws ExecutionException, InterruptedException {
         DhcpServiceUtils.setupDhcpDropAction(dpn, NwConstants.DHCP_TABLE_EXTERNAL_TUNNEL,
                 vmMacAddress, NwConstants.ADD_FLOW, mdsalUtil, dhcpServiceCounters, tx);
     }
index f5b049a70e2fa51fdcf0c4e65a7fa8873d26a8d0..62961362ab1470292b0f0a33345524a1b60930e4 100644 (file)
@@ -11,6 +11,7 @@ import com.google.common.base.Optional;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
 import javax.annotation.Nullable;
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
@@ -186,13 +187,13 @@ public class DhcpManager {
     }
 
     public void installDhcpEntries(@Nullable BigInteger dpnId, @Nullable String vmMacAddress,
-        TypedReadWriteTransaction<Configuration> tx) {
+            TypedReadWriteTransaction<Configuration> tx) throws ExecutionException, InterruptedException {
         DhcpServiceUtils.setupDhcpFlowEntry(dpnId, NwConstants.DHCP_TABLE, vmMacAddress, NwConstants.ADD_FLOW,
                 mdsalUtil, dhcpServiceCounters, tx);
     }
 
     public void unInstallDhcpEntries(@Nullable BigInteger dpId, @Nullable String vmMacAddress,
-        TypedReadWriteTransaction<Configuration> tx) {
+            TypedReadWriteTransaction<Configuration> tx) throws ExecutionException, InterruptedException {
         DhcpServiceUtils.setupDhcpFlowEntry(dpId, NwConstants.DHCP_TABLE, vmMacAddress, NwConstants.DEL_FLOW,
                 mdsalUtil, dhcpServiceCounters, tx);
     }
index 0ffdce200d22fa27679aa1a8c1c084f72590ec81..fcb394ced41362d880bc7041376615b1b08a4afb 100644 (file)
@@ -11,7 +11,6 @@ package org.opendaylight.netvirt.dhcpservice;
 import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
 
 import com.google.common.base.Optional;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.math.BigInteger;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
@@ -120,13 +119,11 @@ public final class DhcpServiceUtils {
 
     private DhcpServiceUtils() { }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
     public static void setupDhcpFlowEntry(@Nullable BigInteger dpId, short tableId, @Nullable String vmMacAddress,
                                           int addOrRemove,
                                           IMdsalApiManager mdsalUtil, DhcpServiceCounters dhcpServiceCounters,
-                                          TypedReadWriteTransaction<Configuration> tx) {
+                                          TypedReadWriteTransaction<Configuration> tx)
+            throws ExecutionException, InterruptedException {
         if (dpId == null || dpId.equals(DhcpMConstants.INVALID_DPID) || vmMacAddress == null) {
             return;
         }
@@ -140,12 +137,7 @@ public final class DhcpServiceUtils {
         if (addOrRemove == NwConstants.DEL_FLOW) {
             LOG.trace("Removing DHCP Flow DpId {}, vmMacAddress {}", dpId, vmMacAddress);
             dhcpServiceCounters.removeDhcpFlow();
-            try {
-                mdsalUtil.removeFlow(tx, dpId, getDhcpFlowRef(dpId, tableId, vmMacAddress), tableId);
-            } catch (Exception e) {
-                LOG.error("Error removing flow", e);
-                throw new RuntimeException("Error removing flow", e);
-            }
+            mdsalUtil.removeFlow(tx, dpId, getDhcpFlowRef(dpId, tableId, vmMacAddress), tableId);
         } else {
             FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, tableId,
                     getDhcpFlowRef(dpId, tableId, vmMacAddress), DhcpMConstants.DEFAULT_DHCP_FLOW_PRIORITY,
@@ -171,12 +163,10 @@ public final class DhcpServiceUtils {
                 .append(ipAddress).toString();
     }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
     public static void setupDhcpDropAction(BigInteger dpId, short tableId, String vmMacAddress, int addOrRemove,
                                            IMdsalApiManager mdsalUtil, DhcpServiceCounters dhcpServiceCounters,
-                                           TypedReadWriteTransaction<Configuration> tx) {
+                                           TypedReadWriteTransaction<Configuration> tx)
+            throws ExecutionException, InterruptedException {
         if (dpId == null || dpId.equals(DhcpMConstants.INVALID_DPID) || vmMacAddress == null) {
             return;
         }
@@ -190,12 +180,7 @@ public final class DhcpServiceUtils {
         if (addOrRemove == NwConstants.DEL_FLOW) {
             LOG.trace("Removing DHCP Drop Flow DpId {}, vmMacAddress {}", dpId, vmMacAddress);
             dhcpServiceCounters.removeDhcpDropFlow();
-            try {
-                mdsalUtil.removeFlow(tx, dpId, getDhcpFlowRef(dpId, tableId, vmMacAddress), tableId);
-            } catch (Exception e) {
-                LOG.error("Error removing flow", e);
-                throw new RuntimeException("Error removing flow", e);
-            }
+            mdsalUtil.removeFlow(tx, dpId, getDhcpFlowRef(dpId, tableId, vmMacAddress), tableId);
         } else {
             FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, tableId,
                     getDhcpFlowRef(dpId, tableId, vmMacAddress), DhcpMConstants.DEFAULT_DHCP_FLOW_PRIORITY,
@@ -206,7 +191,6 @@ public final class DhcpServiceUtils {
         }
     }
 
-    @SuppressWarnings("checkstyle:IllegalCatch")
     public static void setupDhcpArpRequest(BigInteger dpId, short tableId, BigInteger vni, String dhcpIpAddress,
                                            int lportTag, Long elanTag, boolean add, IMdsalApiManager mdsalUtil) {
         List<MatchInfo> matches = getDhcpArpMatch(vni, dhcpIpAddress);
index 83b04cfcde3df702c88402c04e0585fcd4d83382..114566c3580a588982186b37aa4d516dabd8b165 100644 (file)
@@ -14,7 +14,6 @@ import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
 import com.google.common.util.concurrent.ListenableFuture;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -26,6 +25,7 @@ import java.util.Queue;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.ExecutionException;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -956,28 +956,20 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         mdsalManager.addFlowToTx(interfaceInfo.getDpId(), flowEntry, writeFlowGroupTx);
     }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
     public void removeFilterEqualsTable(ElanInstance elanInfo, InterfaceInfo interfaceInfo,
-            TypedReadWriteTransaction<Configuration> flowTx) {
-        try {
-            int ifTag = interfaceInfo.getInterfaceTag();
-            Flow flow = MDSALUtil.buildFlow(NwConstants.ELAN_FILTER_EQUALS_TABLE,
-                getFlowRef(NwConstants.ELAN_FILTER_EQUALS_TABLE, ifTag, "group"));
+            TypedReadWriteTransaction<Configuration> flowTx) throws ExecutionException, InterruptedException {
+        int ifTag = interfaceInfo.getInterfaceTag();
+        Flow flow = MDSALUtil.buildFlow(NwConstants.ELAN_FILTER_EQUALS_TABLE,
+            getFlowRef(NwConstants.ELAN_FILTER_EQUALS_TABLE, ifTag, "group"));
 
-            mdsalManager.removeFlow(flowTx, interfaceInfo.getDpId(), flow);
+        mdsalManager.removeFlow(flowTx, interfaceInfo.getDpId(), flow);
 
-            Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.ELAN_FILTER_EQUALS_TABLE,
-                getFlowRef(NwConstants.ELAN_FILTER_EQUALS_TABLE, ifTag, "drop"), 10, elanInfo.getElanInstanceName(), 0,
-                0, ElanConstants.COOKIE_ELAN_FILTER_EQUALS.add(BigInteger.valueOf(ifTag)),
-                getMatchesForFilterEqualsLPortTag(ifTag), MDSALUtil.buildInstructionsDrop());
+        Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.ELAN_FILTER_EQUALS_TABLE,
+            getFlowRef(NwConstants.ELAN_FILTER_EQUALS_TABLE, ifTag, "drop"), 10, elanInfo.getElanInstanceName(), 0,
+            0, ElanConstants.COOKIE_ELAN_FILTER_EQUALS.add(BigInteger.valueOf(ifTag)),
+            getMatchesForFilterEqualsLPortTag(ifTag), MDSALUtil.buildInstructionsDrop());
 
-            mdsalManager.removeFlow(flowTx, interfaceInfo.getDpId(), flowEntity);
-        } catch (Exception e) {
-            LOG.error("Error removing flow", e);
-            throw new RuntimeException("Error removing flow", e);
-        }
+        mdsalManager.removeFlow(flowTx, interfaceInfo.getDpId(), flowEntity);
     }
 
     private List<Bucket> getRemoteBCGroupBucketInfos(ElanInstance elanInfo, int bucketKeyStart,
index 84b863a8752fee20808ce2812183203dc3c4dc25..912558c1be0dd23091dee729498ea916e31ce122 100644 (file)
@@ -19,6 +19,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.Callable;
 
+import java.util.concurrent.ExecutionException;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -186,7 +187,8 @@ public class ElanLearntVpnVipToPortListener extends
         }
 
         private void deleteMacEntryFromDsAndRemoveFlows(String elanName,
-                TypedWriteTransaction<Operational> interfaceTx, TypedReadWriteTransaction<Configuration> flowTx) {
+                TypedWriteTransaction<Operational> interfaceTx, TypedReadWriteTransaction<Configuration> flowTx)
+                throws ExecutionException, InterruptedException {
             LOG.trace("Deleting mac address {} and interface name {} from ElanInterfaceForwardingEntries "
                     + "and ElanForwardingTables DS", macAddress, interfaceName);
             PhysAddress physAddress = new PhysAddress(macAddress);
index a2aaacfb8de024fcd06861c19104b86e020c7b00..aaeb5d416e2a4a39c21909cdb8929a2a5c93acff 100755 (executable)
@@ -20,7 +20,6 @@ import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
 
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -1049,7 +1048,8 @@ public class ElanUtils {
     }
 
     public void deleteMacFlows(@Nullable ElanInstance elanInfo, @Nullable InterfaceInfo interfaceInfo,
-            MacEntry macEntry, TypedReadWriteTransaction<Configuration> flowTx) {
+            MacEntry macEntry, TypedReadWriteTransaction<Configuration> flowTx)
+            throws ExecutionException, InterruptedException {
         if (elanInfo == null || interfaceInfo == null) {
             return;
         }
@@ -1060,7 +1060,8 @@ public class ElanUtils {
     }
 
     public void deleteMacFlows(ElanInstance elanInfo, InterfaceInfo interfaceInfo, String macAddress,
-            boolean deleteSmac, TypedReadWriteTransaction<Configuration> flowTx) {
+            boolean deleteSmac, TypedReadWriteTransaction<Configuration> flowTx)
+            throws ExecutionException, InterruptedException {
         String elanInstanceName = elanInfo.getElanInstanceName();
         List<DpnInterfaces> remoteFEs = getInvolvedDpnsInElan(elanInstanceName);
         BigInteger srcdpId = interfaceInfo.getDpId();
@@ -1082,7 +1083,7 @@ public class ElanUtils {
 
     private void executeEtreeDeleteMacFlows(ElanInstance elanInfo, InterfaceInfo interfaceInfo, String macAddress,
             boolean deleteSmac, String elanInstanceName, BigInteger srcdpId, Long elanTag, BigInteger dstDpId,
-            TypedReadWriteTransaction<Configuration> flowTx) {
+            TypedReadWriteTransaction<Configuration> flowTx) throws ExecutionException, InterruptedException {
         EtreeLeafTagName etreeLeafTag = elanEtreeUtils.getEtreeLeafTagByElanTag(elanTag);
         if (etreeLeafTag != null) {
             executeDeleteMacFlows(elanInfo, interfaceInfo, macAddress, deleteSmac, elanInstanceName, srcdpId,
@@ -1090,55 +1091,40 @@ public class ElanUtils {
         }
     }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
     private boolean executeDeleteMacFlows(ElanInstance elanInfo, InterfaceInfo interfaceInfo, String macAddress,
             boolean deleteSmac, String elanInstanceName, BigInteger srcdpId, Long elanTag, BigInteger dstDpId,
-            TypedReadWriteTransaction<Configuration> flowTx) {
+            TypedReadWriteTransaction<Configuration> flowTx) throws ExecutionException, InterruptedException {
         boolean isFlowsRemovedInSrcDpn = false;
         if (dstDpId.equals(srcdpId)) {
             isFlowsRemovedInSrcDpn = true;
             deleteSmacAndDmacFlows(elanInfo, interfaceInfo, macAddress, deleteSmac, flowTx);
         } else if (isDpnPresent(dstDpId)) {
-            try {
-                mdsalManager
-                    .removeFlow(flowTx, dstDpId,
-                        MDSALUtil.buildFlow(NwConstants.ELAN_DMAC_TABLE, getKnownDynamicmacFlowRef(
-                            NwConstants.ELAN_DMAC_TABLE, dstDpId, srcdpId, macAddress, elanTag)));
-            } catch (Exception e) {
-                LOG.error("Error removing flow", e);
-                throw new RuntimeException("Error removing flow", e);
-            }
+            mdsalManager
+                .removeFlow(flowTx, dstDpId,
+                    MDSALUtil.buildFlow(NwConstants.ELAN_DMAC_TABLE, getKnownDynamicmacFlowRef(
+                        NwConstants.ELAN_DMAC_TABLE, dstDpId, srcdpId, macAddress, elanTag)));
             LOG.debug("Dmac flow entry deleted for elan:{}, logical interface port:{} and mac address:{} on dpn:{}",
                     elanInstanceName, interfaceInfo.getPortName(), macAddress, dstDpId);
         }
         return isFlowsRemovedInSrcDpn;
     }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
     private void deleteSmacAndDmacFlows(ElanInstance elanInfo, InterfaceInfo interfaceInfo, String macAddress,
-            boolean deleteSmac, TypedReadWriteTransaction<Configuration> flowTx) {
+            boolean deleteSmac, TypedReadWriteTransaction<Configuration> flowTx)
+            throws ExecutionException, InterruptedException {
         String elanInstanceName = elanInfo.getElanInstanceName();
         long ifTag = interfaceInfo.getInterfaceTag();
         BigInteger srcdpId = interfaceInfo.getDpId();
         Long elanTag = elanInfo.getElanTag();
-        try {
-            if (deleteSmac) {
-                mdsalManager
-                        .removeFlow(flowTx, srcdpId,
-                                MDSALUtil.buildFlow(NwConstants.ELAN_SMAC_TABLE, getKnownDynamicmacFlowRef(
-                                        NwConstants.ELAN_SMAC_TABLE, srcdpId, ifTag, macAddress, elanTag)));
-            }
-            mdsalManager.removeFlow(flowTx, srcdpId,
-                MDSALUtil.buildFlow(NwConstants.ELAN_DMAC_TABLE,
-                    getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, srcdpId, ifTag, macAddress, elanTag)));
-        } catch (Exception e) {
-            LOG.error("Error removing flow", e);
-            throw new RuntimeException("Error removing flow", e);
+        if (deleteSmac) {
+            mdsalManager
+                    .removeFlow(flowTx, srcdpId,
+                            MDSALUtil.buildFlow(NwConstants.ELAN_SMAC_TABLE, getKnownDynamicmacFlowRef(
+                                    NwConstants.ELAN_SMAC_TABLE, srcdpId, ifTag, macAddress, elanTag)));
         }
+        mdsalManager.removeFlow(flowTx, srcdpId,
+            MDSALUtil.buildFlow(NwConstants.ELAN_DMAC_TABLE,
+                getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, srcdpId, ifTag, macAddress, elanTag)));
         LOG.debug("All the required flows deleted for elan:{}, logical Interface port:{} and MAC address:{} on dpn:{}",
                 elanInstanceName, interfaceInfo.getPortName(), macAddress, srcdpId);
     }
index 1fbfc0a2d7266863ff7052f22bc8194c13a2f860..8fed4756faef381452c391416e1da02d47510c93 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.netvirt.natservice.api;
 
 import java.math.BigInteger;
 
+import java.util.concurrent.ExecutionException;
 import org.opendaylight.genius.infra.Datastore.Configuration;
 import org.opendaylight.genius.infra.TypedReadWriteTransaction;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers;
@@ -47,7 +48,7 @@ public interface SnatServiceListener {
      * @return returns success/failure.
      */
     boolean removeSnatAllSwitch(TypedReadWriteTransaction<Configuration> confTx, Routers routers,
-        BigInteger primarySwitchId);
+        BigInteger primarySwitchId) throws ExecutionException, InterruptedException;
 
     /**
      * Removes snat flows for the dpnId.
@@ -59,6 +60,6 @@ public interface SnatServiceListener {
      * @return returns success/failure.
      */
     boolean removeSnat(TypedReadWriteTransaction<Configuration> confTx, Routers routers, BigInteger primarySwitchId,
-        BigInteger dpnId);
+        BigInteger dpnId) throws ExecutionException, InterruptedException;
 
 }
index abc1aac47dc6836b2b6063ba22f4606489581bd3..0154516c598b25cd15b0d9833378effa2d2321f8 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.netvirt.natservice.api;
 
 import java.math.BigInteger;
 
+import java.util.concurrent.ExecutionException;
 import org.opendaylight.genius.infra.Datastore.Configuration;
 import org.opendaylight.genius.infra.TypedReadWriteTransaction;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers;
@@ -27,6 +28,7 @@ public interface SnatServiceManager {
     void removeNatServiceListener(SnatServiceListener aclServiceListner);
 
     void notify(TypedReadWriteTransaction<Configuration> confTx,
-        Routers router, BigInteger primarySwitchId, BigInteger dpnId, Action action);
+        Routers router, BigInteger primarySwitchId, BigInteger dpnId, Action action)
+        throws ExecutionException, InterruptedException;
 
 }
index cdf598d4a858c2b4e6f2a20367d48de4eb7a9ef3..aa6940248cb060d2f27cf865dec977dadf395d4b 100644 (file)
@@ -13,6 +13,7 @@ import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 import java.math.BigInteger;
 
 import java.time.Duration;
+import java.util.concurrent.ExecutionException;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -136,7 +137,8 @@ public class SnatCentralizedSwitchChangeListener
     }
 
     private void handleAdd(TypedReadWriteTransaction<Datastore.Configuration> confTx,
-        String routerName, Routers router, BigInteger primarySwitchId) {
+            String routerName, Routers router, BigInteger primarySwitchId)
+            throws ExecutionException, InterruptedException {
         if (router != null) {
             natDataUtil.addtoRouterMap(router);
             snatServiceManger.notify(confTx, router, primarySwitchId, null,
index 3615ccb4a693f548ce6321aab91656090da7df22..6358b140342e71a94d0703eb04d8d2e3ef38a9d6 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.netvirt.natservice.internal;
 
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.math.BigInteger;
 import java.time.Duration;
 import java.util.ArrayList;
@@ -165,7 +164,7 @@ public abstract class AbstractSnatService implements SnatServiceListener {
 
     @Override
     public boolean removeSnatAllSwitch(TypedReadWriteTransaction<Configuration> confTx, Routers routers,
-        BigInteger primarySwitchId) {
+            BigInteger primarySwitchId) throws ExecutionException, InterruptedException {
         LOG.info("handleSnatAllSwitch : Handle Snat in all switches for router {}", routers.getRouterName());
         String routerName = routers.getRouterName();
         List<BigInteger> switches = naptSwitchSelector.getDpnsForVpn(routerName);
@@ -209,7 +208,7 @@ public abstract class AbstractSnatService implements SnatServiceListener {
 
     @Override
     public boolean removeSnat(TypedReadWriteTransaction<Configuration> confTx, Routers routers,
-        BigInteger primarySwitchId, BigInteger dpnId) {
+            BigInteger primarySwitchId, BigInteger dpnId) throws ExecutionException, InterruptedException {
 
         // Handle non NAPT switches and NAPT switches separately
         if (!dpnId.equals(primarySwitchId)) {
@@ -246,7 +245,7 @@ public abstract class AbstractSnatService implements SnatServiceListener {
     }
 
     protected void removeSnatCommonEntriesForNaptSwitch(TypedReadWriteTransaction<Configuration> confTx,
-        Routers routers, BigInteger dpnId) {
+            Routers routers, BigInteger dpnId) throws ExecutionException, InterruptedException {
         String routerName = routers.getRouterName();
         Long routerId = NatUtil.getVpnId(confTx, routerName);
         removeDefaultFibRouteForSNAT(confTx, dpnId, routerId);
@@ -272,7 +271,7 @@ public abstract class AbstractSnatService implements SnatServiceListener {
     }
 
     protected void removeSnatCommonEntriesForNonNaptSwitch(TypedReadWriteTransaction<Configuration> confTx,
-        Routers routers, BigInteger dpnId) {
+            Routers routers, BigInteger dpnId) throws ExecutionException, InterruptedException {
         String routerName = routers.getRouterName();
         Long routerId = NatUtil.getVpnId(dataBroker, routerName);
         removeDefaultFibRouteForSNAT(confTx, dpnId, routerId);
@@ -283,7 +282,7 @@ public abstract class AbstractSnatService implements SnatServiceListener {
         Routers routers, BigInteger dpnId);
 
     protected abstract void removeSnatSpecificEntriesForNaptSwitch(TypedReadWriteTransaction<Configuration> confTx,
-        Routers routers, BigInteger dpnId);
+        Routers routers, BigInteger dpnId) throws ExecutionException, InterruptedException;
 
     protected abstract void addSnatSpecificEntriesForNonNaptSwitch(TypedReadWriteTransaction<Configuration> confTx,
         Routers routers, BigInteger dpnId);
@@ -325,8 +324,7 @@ public abstract class AbstractSnatService implements SnatServiceListener {
     }
 
     protected void removeInboundFibEntry(TypedReadWriteTransaction<Configuration> confTx, BigInteger dpnId,
-        String externalIp, Long routerId, String subNetId) {
-
+            String externalIp, Long routerId, String subNetId) throws ExecutionException, InterruptedException {
         String flowRef = getFlowRef(dpnId, NwConstants.L3_FIB_TABLE, routerId);
         flowRef = flowRef + "inbound" + externalIp;
         removeFlow(confTx, dpnId, NwConstants.L3_FIB_TABLE, flowRef);
@@ -392,22 +390,14 @@ public abstract class AbstractSnatService implements SnatServiceListener {
             NwConstants.COOKIE_SNAT_TABLE, matches, instructions);
     }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
     protected void removeSnatMissEntry(TypedReadWriteTransaction<Configuration> confTx, BigInteger dpnId,
-        Long routerId, String routerName) {
+            Long routerId, String routerName) throws ExecutionException, InterruptedException {
         LOG.debug("installSnatMissEntry : Removing SNAT miss entry from switch {}", dpnId);
         // Install the select group
         long groupId = createGroupId(getGroupIdKey(routerName));
 
         LOG.debug("removing the PSNAT to NAPTSwitch on DPN {} with GroupId: {}", dpnId, groupId);
-        try {
-            mdsalManager.removeGroup(confTx, dpnId, groupId);
-        } catch (Exception e) {
-            LOG.error("Error removing flow", e);
-            throw new RuntimeException("Error removing flow", e);
-        }
+        mdsalManager.removeGroup(confTx, dpnId, groupId);
 
         // Install miss entry pointing to group
         LOG.debug("installSnatMissEntry : buildSnatFlowEntity is called for dpId {}, routerName {} and groupId {}",
@@ -443,8 +433,7 @@ public abstract class AbstractSnatService implements SnatServiceListener {
     }
 
     protected void removeInboundTerminatingServiceTblEntry(TypedReadWriteTransaction<Configuration> confTx,
-        BigInteger dpnId, Long routerId) {
-
+            BigInteger dpnId, Long routerId) throws ExecutionException, InterruptedException {
         //Install the tunnel table entry in NAPT switch for inbound traffic to SNAP IP from a non a NAPT switch.
         LOG.info("installInboundTerminatingServiceTblEntry : creating entry for Terminating Service Table "
             + "for switch {}, routerId {}", dpnId, routerId);
@@ -469,25 +458,14 @@ public abstract class AbstractSnatService implements SnatServiceListener {
     }
 
     protected void removeDefaultFibRouteForSNAT(TypedReadWriteTransaction<Configuration> confTx, BigInteger dpnId,
-        Long extNetId) {
-
+            Long extNetId) throws ExecutionException, InterruptedException {
         String flowRef = "DefaultFibRouteForSNAT" + getFlowRef(dpnId, NwConstants.L3_FIB_TABLE, extNetId);
         removeFlow(confTx, dpnId, NwConstants.L3_FIB_TABLE, flowRef);
     }
 
     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();
-    }
-
-    protected void syncFlow(TypedReadWriteTransaction<Configuration> confTx, BigInteger dpId, short tableId,
-        String flowId, int priority, String flowName, BigInteger cookie, List<? extends MatchInfoBase> matches,
-        List<InstructionInfo> instructions, int addOrRemove) {
-        if (addOrRemove == NwConstants.DEL_FLOW) {
-            removeFlow(confTx, dpId, tableId, flowId);
-        } else {
-            addFlow(confTx, dpId, tableId, flowId, priority, flowName, cookie, matches, instructions);
-        }
+        return NatConstants.NAPT_FLOWID_PREFIX + dpnId + NatConstants.FLOWID_SEPARATOR
+            + tableId + NatConstants.FLOWID_SEPARATOR + routerID;
     }
 
     protected void addFlow(TypedWriteTransaction<Configuration> confTx, BigInteger dpId, short tableId,
@@ -500,18 +478,10 @@ public abstract class AbstractSnatService implements SnatServiceListener {
         mdsalManager.addFlow(confTx, flowEntity);
     }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
     protected void removeFlow(TypedReadWriteTransaction<Configuration> confTx, BigInteger dpId, short tableId,
-        String flowId) {
+            String flowId) throws ExecutionException, InterruptedException {
         LOG.trace("syncFlow : Removing Acl Flow DpnId {}, flowId {}", dpId, flowId);
-        try {
-            mdsalManager.removeFlow(confTx, dpId, flowId, tableId);
-        } catch (Exception e) {
-            LOG.error("Error removing flow", e);
-            throw new RuntimeException("Error removing flow", e);
-        }
+        mdsalManager.removeFlow(confTx, dpId, flowId, tableId);
     }
 
     protected long createGroupId(String groupIdKey) {
index 85b5361eb90c02a9c23fca6d398a08f9de554f32..3a66f86828c72a73b07686df3819f9b011233712 100644 (file)
@@ -11,6 +11,7 @@ import com.google.common.base.Optional;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar;
@@ -125,7 +126,7 @@ public abstract class ConntrackBasedSnatService extends AbstractSnatService {
 
     @Override
     protected void removeSnatSpecificEntriesForNaptSwitch(TypedReadWriteTransaction<Configuration> confTx,
-        Routers routers, BigInteger dpnId) {
+            Routers routers, BigInteger dpnId) throws ExecutionException, InterruptedException {
         LOG.info("installSnatSpecificEntriesForNaptSwitch: called for router {}",
             routers.getRouterName());
         String routerName = routers.getRouterName();
@@ -201,7 +202,7 @@ public abstract class ConntrackBasedSnatService extends AbstractSnatService {
     }
 
     protected void removeSnatMissEntryForPrimrySwch(TypedReadWriteTransaction<Configuration> confTx, BigInteger dpnId,
-        Long routerId) {
+            Long routerId) throws ExecutionException, InterruptedException {
         LOG.info("installSnatSpecificEntriesForNaptSwitch : called for the primary NAPT switch dpnId {}", dpnId);
 
         String flowRef = getFlowRef(dpnId, NwConstants.PSNAT_TABLE, routerId);
@@ -234,7 +235,7 @@ public abstract class ConntrackBasedSnatService extends AbstractSnatService {
     }
 
     protected void removeTerminatingServiceTblEntry(TypedReadWriteTransaction<Configuration> confTx, BigInteger dpnId,
-        Long routerId) {
+            Long routerId) throws ExecutionException, InterruptedException {
         LOG.info("installTerminatingServiceTblEntry : creating entry for Terminating Service Table "
             + "for switch {}, routerId {}", dpnId, routerId);
 
@@ -261,7 +262,7 @@ public abstract class ConntrackBasedSnatService extends AbstractSnatService {
     }
 
     protected void removeOutboundTblTrackEntry(TypedReadWriteTransaction<Configuration> confTx, BigInteger dpnId,
-        Long routerId) {
+            Long routerId) throws ExecutionException, InterruptedException {
         LOG.info("createOutboundTblTrackEntry : called for switch {}, routerId {}", dpnId, routerId);
 
         String flowRef = getFlowRef(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId) + "trkest";
@@ -295,7 +296,7 @@ public abstract class ConntrackBasedSnatService extends AbstractSnatService {
     }
 
     protected void removeOutboundTblEntry(TypedReadWriteTransaction<Configuration> confTx, BigInteger dpnId,
-        long routerId) {
+            long routerId) throws ExecutionException, InterruptedException {
         LOG.info("createOutboundTblEntry : dpId {} and routerId {}", dpnId, routerId);
         String flowRef = getFlowRef(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId);
         removeFlow(confTx, dpnId, NwConstants.OUTBOUND_NAPT_TABLE, flowRef);
@@ -329,7 +330,7 @@ public abstract class ConntrackBasedSnatService extends AbstractSnatService {
     }
 
     protected void removeNaptPfibFlow(TypedReadWriteTransaction<Configuration> confTx, Routers routers,
-        BigInteger dpnId, long routerId) {
+            BigInteger dpnId, long routerId) throws ExecutionException, InterruptedException {
         Long extNetId = NatUtil.getVpnId(confTx, routers.getNetworkId().getValue());
         LOG.info("installNaptPfibFlow : dpId {}, extNetId {}", dpnId, extNetId);
         String flowRef = getFlowRef(dpnId, NwConstants.NAPT_PFIB_TABLE, routerId) + "OUTBOUND";
@@ -368,7 +369,7 @@ public abstract class ConntrackBasedSnatService extends AbstractSnatService {
     }
 
     protected void removeInboundEntry(TypedReadWriteTransaction<Configuration> confTx, BigInteger dpnId,
-        long routerId) {
+            long routerId) throws ExecutionException, InterruptedException {
         LOG.info("installInboundEntry : dpId {} and routerId {}", dpnId, routerId);
 
         String flowRef = getFlowRef(dpnId, NwConstants.INBOUND_NAPT_TABLE, routerId) + "OUTBOUND";
@@ -394,7 +395,7 @@ public abstract class ConntrackBasedSnatService extends AbstractSnatService {
     }
 
     protected void removeNaptPfibEntry(TypedReadWriteTransaction<Configuration> confTx, BigInteger dpnId,
-        long routerId) {
+            long routerId) throws ExecutionException, InterruptedException {
         LOG.info("installNaptPfibEntry : called for dpnId {} and routerId {} ", dpnId, routerId);
         String flowRef = getFlowRef(dpnId, NwConstants.NAPT_PFIB_TABLE, routerId) + "INBOUND";
         removeFlow(confTx, dpnId, NwConstants.NAPT_PFIB_TABLE, flowRef);
index 3b0cec734ef0c778484bae089ef32c3e54390faa..de5bab6bcad85a4411527c7127eab8752a9f6ab5 100644 (file)
@@ -17,11 +17,11 @@ import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
 import javax.annotation.Nonnull;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -381,10 +381,8 @@ public class EvpnDnatFlowProgrammer {
                 terminatingServiceTableFlowEntity, dpnId);
     }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
-    private void removeTunnelTableEntry(BigInteger dpnId, long l3Vni, TypedReadWriteTransaction<Configuration> confTx) {
+    private void removeTunnelTableEntry(BigInteger dpnId, long l3Vni, TypedReadWriteTransaction<Configuration> confTx)
+            throws ExecutionException, InterruptedException {
         LOG.debug("removeTunnelTableEntry : Remove terminating service table {} --> table {} flow on DpnId {} "
                 + "with l3Vni {} as matching parameter", NwConstants.INTERNAL_TUNNEL_TABLE, NwConstants.PDNAT_TABLE,
                 dpnId, l3Vni);
@@ -394,12 +392,7 @@ public class EvpnDnatFlowProgrammer {
                 NatEvpnUtil.getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, l3Vni, NatConstants.DNAT_FLOW_NAME),
                 6, String.format("%s:%d", "TST Flow Entry ", l3Vni), 0, 0,
                 COOKIE_TUNNEL.add(BigInteger.valueOf(l3Vni)), mkMatches, null);
-        try {
-            mdsalManager.removeFlow(confTx, dpnId, flowEntity);
-        } catch (Exception e) {
-            LOG.error("Error removing flow", e);
-            throw new RuntimeException("Error removing flow", e);
-        }
+        mdsalManager.removeFlow(confTx, dpnId, flowEntity);
         LOG.debug("removeTunnelTableEntry : Successfully removed terminating service table flow {} on DpnId {}",
                 flowEntity, dpnId);
     }
index 8032f5ddb7eaa8918ea7ff43ca479ff7c65ae286..9ce1fe883528a0eb1466f57fa179b0b88d66f8f7 100644 (file)
@@ -8,9 +8,9 @@
 
 package org.opendaylight.netvirt.natservice.internal;
 
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.math.BigInteger;
 
+import java.util.concurrent.ExecutionException;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -42,11 +42,9 @@ public class EvpnNaptSwitchHA {
         this.idManager = idManager;
     }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
     public void evpnRemoveSnatFlowsInOldNaptSwitch(String routerName, long routerId, String vpnName,
-            BigInteger naptSwitch, TypedReadWriteTransaction<Configuration> confTx) {
+            BigInteger naptSwitch, TypedReadWriteTransaction<Configuration> confTx)
+            throws ExecutionException, InterruptedException {
         //Handling VXLAN Provider type flow removal from old NAPT switch
         Long vpnId = NatUtil.getNetworkVpnIdFromRouterId(dataBroker, routerId);
         if (vpnId == NatConstants.INVALID_ID) {
@@ -83,12 +81,7 @@ public class EvpnNaptSwitchHA {
         LOG.info("evpnRemoveSnatFlowsInOldNaptSwitch: Remove the flow (table26->46) in table {} "
                 + "for the old napt switch with the DPN ID {} and router ID {}",
                 NwConstants.PSNAT_TABLE, naptSwitch, routerId);
-        try {
-            mdsalManager.removeFlow(confTx, flowEntity);
-        } catch (Exception e) {
-            LOG.error("Error removing flow", e);
-            throw new RuntimeException("Error removing flow", e);
-        }
+        mdsalManager.removeFlow(confTx, flowEntity);
 
         //Remove the Terminating Service table entry which forwards the packet to Inbound NAPT Table (table36->44)
         LOG.info("evpnRemoveSnatFlowsInOldNaptSwitch : Remove the flow (table36->44) in table {} "
@@ -103,13 +96,7 @@ public class EvpnNaptSwitchHA {
         FlowEntity tsNatFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.INTERNAL_TUNNEL_TABLE, tsFlowRef);
         LOG.info("evpnRemoveSnatFlowsInOldNaptSwitch : Remove the flow in the {} for the active switch "
                 + "with the DPN ID {} and router ID {}", NwConstants.INTERNAL_TUNNEL_TABLE, naptSwitch, routerId);
-        try {
-            mdsalManager.removeFlow(confTx, tsNatFlowEntity);
-        } catch (Exception e) {
-            LOG.error("Error removing flow", e);
-            throw new RuntimeException("Error removing flow", e);
-        }
-
+        mdsalManager.removeFlow(confTx, tsNatFlowEntity);
     }
 
     private String getFlowRefTs(BigInteger dpnId, short tableId, long routerID) {
index a283d45d315ee01c5108df279fba227d57254340..d06176485c5f0c3b6cf32d5d3fc0fdbbf05912b3 100644 (file)
@@ -14,10 +14,10 @@ import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
 import javax.annotation.Nonnull;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -279,10 +279,8 @@ public class EvpnSnatFlowProgrammer {
                 terminatingServiceTableFlowEntity, dpnId);
     }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
-    public void removeTunnelTableEntry(BigInteger dpnId, long l3Vni, TypedReadWriteTransaction<Configuration> confTx) {
+    public void removeTunnelTableEntry(BigInteger dpnId, long l3Vni, TypedReadWriteTransaction<Configuration> confTx)
+            throws ExecutionException, InterruptedException {
         LOG.debug("removeTunnelTableEntry : Remove terminating service table {} --> table {} flow on NAPT DpnId {} "
                 + "with l3Vni {} as matching parameter", NwConstants.INTERNAL_TUNNEL_TABLE,
                 NwConstants.INBOUND_NAPT_TABLE, dpnId, l3Vni);
@@ -293,12 +291,7 @@ public class EvpnSnatFlowProgrammer {
                 NatEvpnUtil.getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, l3Vni, NatConstants.SNAT_FLOW_NAME),
                 5, String.format("%s:%d", "TST Flow Entry ", l3Vni), 0, 0,
                 COOKIE_TUNNEL.add(BigInteger.valueOf(l3Vni)), mkMatches, null);
-        try {
-            mdsalManager.removeFlow(confTx, dpnId, flowEntity);
-        } catch (Exception e) {
-            LOG.error("Error removing flow", e);
-            throw new RuntimeException("Error removing flow", e);
-        }
+        mdsalManager.removeFlow(confTx, dpnId, flowEntity);
         LOG.debug("removeTunnelTableEntry : Successfully removed terminating service table flow {} on DpnId {}",
                 flowEntity, dpnId);
     }
index 844b3878dc7482045bb175797050fc4aec6323c3..d6421e2e3a697aac5e0cbd275b5b56e7337ecaf3 100644 (file)
@@ -155,7 +155,8 @@ public class ExternalNetworksChangeListener
         }
     }
 
-    private void associateExternalNetworkWithVPN(Networks network, TypedReadWriteTransaction<Configuration> confTx) {
+    private void associateExternalNetworkWithVPN(Networks network, TypedReadWriteTransaction<Configuration> confTx)
+            throws ExecutionException, InterruptedException {
         List<Uuid> routerIds = network.getRouterIds();
         for (Uuid routerId : routerIds) {
             //long router = NatUtil.getVpnId(dataBroker, routerId.getValue());
index b26a36d6c99f555dc06e455bc002a8ee6daf060d..bf52adda1b724b64c4ec4b460df9518b8e4b3027 100644 (file)
@@ -15,7 +15,6 @@ import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.math.BigInteger;
 import java.net.Inet6Address;
 import java.net.InetAddress;
@@ -494,7 +493,8 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
     }
 
     private void addOrDelDefFibRouteToSNAT(String routerName, long routerId, long bgpVpnId,
-            Uuid bgpVpnUuid, boolean create, TypedReadWriteTransaction<Configuration> confTx) {
+            Uuid bgpVpnUuid, boolean create, TypedReadWriteTransaction<Configuration> confTx)
+            throws ExecutionException, InterruptedException {
         //Check if BGP VPN exists. If exists then invoke the new method.
         if (bgpVpnId != NatConstants.INVALID_ID) {
             if (bgpVpnUuid != null) {
@@ -518,7 +518,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
     }
 
     private void addOrDelDefaultFibRouteForSNAT(String routerName, long routerId, boolean create,
-            TypedReadWriteTransaction<Configuration> confTx) {
+            TypedReadWriteTransaction<Configuration> confTx) throws ExecutionException, InterruptedException {
         List<BigInteger> switches = naptSwitchSelector.getDpnsForVpn(routerName);
         if (switches.isEmpty()) {
             LOG.info("addOrDelDefaultFibRouteForSNAT : No switches found for router {}", routerName);
@@ -564,7 +564,8 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
     }
 
     private void removeDefaultFibRouteForSnatWithBgpVpn(String routerName, long routerId,
-        long bgpVpnId, TypedReadWriteTransaction<Configuration> confTx) {
+            long bgpVpnId, TypedReadWriteTransaction<Configuration> confTx)
+            throws ExecutionException, InterruptedException {
         List<BigInteger> dpnIds = NatUtil.getDpnsForRouter(dataBroker, routerName);
         if (dpnIds.isEmpty()) {
             LOG.error("addOrDelDefaultFibRouteForSNATWIthBgpVpn: No dpns are part of router {} to program "
@@ -1767,8 +1768,6 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
             })), NatConstants.NAT_DJC_MAX_RETRIES);
     }
 
-    // TODO Clean up the exception handling
-    @SuppressWarnings("checkstyle:IllegalCatch")
     public void handleDisableSnat(Routers router, Uuid networkUuid, @Nonnull Collection<String> externalIps,
                                   boolean routerFlag, String vpnName, BigInteger naptSwitchDpnId,
                                   long routerId, TypedReadWriteTransaction<Configuration> removeFlowInvTx) {
@@ -1800,32 +1799,27 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
             removeNaptFlowsFromActiveSwitch(routerId, routerName, naptSwitchDpnId, networkUuid, vpnName, externalIps,
                     externalSubnetList, removeFlowInvTx, extNwProvType);
             removeFlowsFromNonActiveSwitches(routerId, routerName, naptSwitchDpnId, removeFlowInvTx);
-            try {
-                String externalSubnetVpn = null;
-                for (Uuid externalSubnetId : externalSubnetList) {
-                    Optional<Subnets> externalSubnet = NatUtil.getOptionalExternalSubnets(dataBroker, externalSubnetId);
-                    // externalSubnet data model will exist for FLAT/VLAN external netowrk UCs.
-                    if (externalSubnet.isPresent()) {
-                        externalSubnetVpn =  externalSubnetId.getValue();
-                        clrRtsFromBgpAndDelFibTs(naptSwitchDpnId, routerId, networkUuid, externalIps, externalSubnetVpn,
-                                router.getExtGwMacAddress(), removeFlowInvTx);
-                    }
-                }
-                if (externalSubnetVpn == null) {
-                    clrRtsFromBgpAndDelFibTs(naptSwitchDpnId, routerId, networkUuid, externalIps, vpnName,
+            String externalSubnetVpn = null;
+            for (Uuid externalSubnetId : externalSubnetList) {
+                Optional<Subnets> externalSubnet = NatUtil.getOptionalExternalSubnets(dataBroker, externalSubnetId);
+                // externalSubnet data model will exist for FLAT/VLAN external netowrk UCs.
+                if (externalSubnet.isPresent()) {
+                    externalSubnetVpn =  externalSubnetId.getValue();
+                    clrRtsFromBgpAndDelFibTs(naptSwitchDpnId, routerId, networkUuid, externalIps, externalSubnetVpn,
                             router.getExtGwMacAddress(), removeFlowInvTx);
                 }
-            } catch (Exception ex) {
-                LOG.error("handleDisableSnat : Failed to remove fib entries for routerId {} in naptSwitchDpnId {}",
-                    routerId, naptSwitchDpnId, ex);
+            }
+            if (externalSubnetVpn == null) {
+                clrRtsFromBgpAndDelFibTs(naptSwitchDpnId, routerId, networkUuid, externalIps, vpnName,
+                        router.getExtGwMacAddress(), removeFlowInvTx);
             }
             // Use the NaptMananager removeMapping API to remove the entire list of IP addresses maintained
             // for the router ID.
             LOG.debug("handleDisableSnat : Remove the Internal to external IP address maintained for the "
                     + "router ID {} in the DS", routerId);
             naptManager.removeMapping(routerId);
-        } catch (Exception ex) {
-            LOG.error("handleDisableSnat : Exception while handling disableSNAT for router :{}", routerName, ex);
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("handleDisableSnat : Exception while handling disableSNAT for router :{}", routerName, e);
         }
         LOG.info("handleDisableSnat : Exit");
     }
@@ -1867,9 +1861,9 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
                         + "in naptSwitchDpnId {}", routerId, naptSwitchDpnId, ex);
             }
             NatOverVxlanUtil.releaseVNI(vpnId, idManager);
-        } catch (Exception ex) {
+        } catch (InterruptedException | ExecutionException e) {
             LOG.error("handleDisableSnatInternetVpn: Exception while handling disableSNATInternetVpn for router {} "
-                    + "with internet vpn {}", routerName, vpnId, ex);
+                    + "with internet vpn {}", routerName, vpnId, e);
         }
         LOG.debug("handleDisableSnatInternetVpn: Processed handle disable snat for router {} with internet vpn {}",
                 routerName, vpnId);
@@ -1902,190 +1896,182 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
         NatEvpnUtil.releaseLPortTagForRouter(dataBroker, idManager, routerName);
     }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
     public void removeNaptFlowsFromActiveSwitch(long routerId, String routerName,
                                                 BigInteger dpnId, Uuid networkId, String vpnName,
                                                 @Nonnull Collection<String> externalIps,
                                                 Collection<Uuid> externalSubnetList,
                                                 TypedReadWriteTransaction<Configuration> confTx,
-                                                ProviderTypes extNwProvType) {
-        try {
-            LOG.debug("removeNaptFlowsFromActiveSwitch : Remove NAPT flows from Active switch");
-            BigInteger cookieSnatFlow = NatUtil.getCookieNaptFlow(routerId);
-
-            //Remove the PSNAT entry which forwards the packet to Outbound NAPT Table (For the
-            // traffic which comes from the  VMs of the NAPT switches)
-            String preSnatFlowRef = getFlowRefSnat(dpnId, NwConstants.PSNAT_TABLE, routerName);
-            FlowEntity preSnatFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.PSNAT_TABLE, preSnatFlowRef);
-
-            LOG.info(
-                "removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active switch with the DPN ID {} "
-                    + "and router ID {}", NwConstants.PSNAT_TABLE, dpnId, routerId);
-            mdsalManager.removeFlow(confTx, preSnatFlowEntity);
-
-            //Remove the Terminating Service table entry which forwards the packet to Outbound NAPT Table (For the
-            // traffic which comes from the VMs of the non NAPT switches)
-            long tunnelId = NatUtil.getTunnelIdForNonNaptToNaptFlow(dataBroker, elanManager, idManager, routerId,
-                routerName);
-            String tsFlowRef = getFlowRefTs(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, tunnelId);
-            FlowEntity tsNatFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, tsFlowRef);
-            LOG.info(
-                "removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active switch with the DPN ID {} "
-                    + "and router ID {}", NwConstants.INTERNAL_TUNNEL_TABLE, dpnId, routerId);
-            mdsalManager.removeFlow(confTx, tsNatFlowEntity);
-
-            //Remove the flow table 25->44 from NAPT Switch
-            if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
-                NatUtil.removePreDnatToSnatTableEntry(confTx, mdsalManager, dpnId);
-            }
+                                                ProviderTypes extNwProvType)
+            throws InterruptedException, ExecutionException {
 
-            //Remove the Outbound flow entry which forwards the packet to FIB Table
-            LOG.info(
-                "removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active switch with the DPN ID {}"
-                    + " and router ID {}", NwConstants.OUTBOUND_NAPT_TABLE, dpnId, routerId);
+        LOG.debug("removeNaptFlowsFromActiveSwitch : Remove NAPT flows from Active switch");
+        BigInteger cookieSnatFlow = NatUtil.getCookieNaptFlow(routerId);
 
-            String outboundTcpNatFlowRef = getFlowRefOutbound(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId,
-                NwConstants.IP_PROT_TCP);
-            FlowEntity outboundTcpNatFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.OUTBOUND_NAPT_TABLE,
-                outboundTcpNatFlowRef);
-            mdsalManager.removeFlow(confTx, outboundTcpNatFlowEntity);
+        //Remove the PSNAT entry which forwards the packet to Outbound NAPT Table (For the
+        // traffic which comes from the  VMs of the NAPT switches)
+        String preSnatFlowRef = getFlowRefSnat(dpnId, NwConstants.PSNAT_TABLE, routerName);
+        FlowEntity preSnatFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.PSNAT_TABLE, preSnatFlowRef);
 
-            String outboundUdpNatFlowRef = getFlowRefOutbound(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId,
-                NwConstants.IP_PROT_UDP);
-            FlowEntity outboundUdpNatFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.OUTBOUND_NAPT_TABLE,
-                outboundUdpNatFlowRef);
-            mdsalManager.removeFlow(confTx, outboundUdpNatFlowEntity);
+        LOG.info(
+            "removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active switch with the DPN ID {} "
+                + "and router ID {}", NwConstants.PSNAT_TABLE, dpnId, routerId);
+        mdsalManager.removeFlow(confTx, preSnatFlowEntity);
 
-            String icmpDropFlowRef = getFlowRefOutbound(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId,
-                NwConstants.IP_PROT_ICMP);
-            FlowEntity icmpDropFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.OUTBOUND_NAPT_TABLE,
-                icmpDropFlowRef);
-            mdsalManager.removeFlow(confTx, icmpDropFlowEntity);
-            boolean lastRouterOnExternalNetwork =
-                !NatUtil.checkForRoutersWithSameExtNetAndNaptSwitch(dataBroker, networkId, routerName, dpnId);
-            if (lastRouterOnExternalNetwork) {
-                removeNaptFibExternalOutputFlows(routerId, dpnId, networkId, externalIps, confTx);
-            }
-            //Remove the NAPT PFIB TABLE (47->21) which forwards the incoming packet to FIB Table matching on the
-            // External Subnet Vpn Id.
-            for (Uuid externalSubnetId : externalSubnetList) {
-                long subnetVpnId = NatUtil.getVpnId(dataBroker, externalSubnetId.getValue());
-                if (subnetVpnId != -1 && !NatUtil.checkForRoutersWithSameExtSubnetAndNaptSwitch(
-                    dataBroker, externalSubnetId, routerName, dpnId)) {
-                    String natPfibSubnetFlowRef = getFlowRefTs(dpnId, NwConstants.NAPT_PFIB_TABLE, subnetVpnId);
-                    FlowEntity natPfibFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.NAPT_PFIB_TABLE,
-                        natPfibSubnetFlowRef);
-                    mdsalManager.removeFlow(confTx, natPfibFlowEntity);
-                    LOG.debug("removeNaptFlowsFromActiveSwitch : Removed the flow in table {} with external subnet "
-                              + "Vpn Id {} as metadata on Napt Switch {}", NwConstants.NAPT_PFIB_TABLE,
-                        subnetVpnId, dpnId);
-                }
+        //Remove the Terminating Service table entry which forwards the packet to Outbound NAPT Table (For the
+        // traffic which comes from the VMs of the non NAPT switches)
+        long tunnelId = NatUtil.getTunnelIdForNonNaptToNaptFlow(dataBroker, elanManager, idManager, routerId,
+            routerName);
+        String tsFlowRef = getFlowRefTs(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, tunnelId);
+        FlowEntity tsNatFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, tsFlowRef);
+        LOG.info(
+            "removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active switch with the DPN ID {} "
+                + "and router ID {}", NwConstants.INTERNAL_TUNNEL_TABLE, dpnId, routerId);
+        mdsalManager.removeFlow(confTx, tsNatFlowEntity);
+
+        //Remove the flow table 25->44 from NAPT Switch
+        if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
+            NatUtil.removePreDnatToSnatTableEntry(confTx, mdsalManager, dpnId);
+        }
+
+        //Remove the Outbound flow entry which forwards the packet to FIB Table
+        LOG.info(
+            "removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active switch with the DPN ID {}"
+                + " and router ID {}", NwConstants.OUTBOUND_NAPT_TABLE, dpnId, routerId);
+
+        String outboundTcpNatFlowRef = getFlowRefOutbound(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId,
+            NwConstants.IP_PROT_TCP);
+        FlowEntity outboundTcpNatFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.OUTBOUND_NAPT_TABLE,
+            outboundTcpNatFlowRef);
+        mdsalManager.removeFlow(confTx, outboundTcpNatFlowEntity);
+
+        String outboundUdpNatFlowRef = getFlowRefOutbound(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId,
+            NwConstants.IP_PROT_UDP);
+        FlowEntity outboundUdpNatFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.OUTBOUND_NAPT_TABLE,
+            outboundUdpNatFlowRef);
+        mdsalManager.removeFlow(confTx, outboundUdpNatFlowEntity);
+
+        String icmpDropFlowRef = getFlowRefOutbound(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId,
+            NwConstants.IP_PROT_ICMP);
+        FlowEntity icmpDropFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.OUTBOUND_NAPT_TABLE,
+            icmpDropFlowRef);
+        mdsalManager.removeFlow(confTx, icmpDropFlowEntity);
+        boolean lastRouterOnExternalNetwork =
+            !NatUtil.checkForRoutersWithSameExtNetAndNaptSwitch(dataBroker, networkId, routerName, dpnId);
+        if (lastRouterOnExternalNetwork) {
+            removeNaptFibExternalOutputFlows(routerId, dpnId, networkId, externalIps, confTx);
+        }
+        //Remove the NAPT PFIB TABLE (47->21) which forwards the incoming packet to FIB Table matching on the
+        // External Subnet Vpn Id.
+        for (Uuid externalSubnetId : externalSubnetList) {
+            long subnetVpnId = NatUtil.getVpnId(dataBroker, externalSubnetId.getValue());
+            if (subnetVpnId != -1 && !NatUtil.checkForRoutersWithSameExtSubnetAndNaptSwitch(
+                dataBroker, externalSubnetId, routerName, dpnId)) {
+                String natPfibSubnetFlowRef = getFlowRefTs(dpnId, NwConstants.NAPT_PFIB_TABLE, subnetVpnId);
+                FlowEntity natPfibFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.NAPT_PFIB_TABLE,
+                    natPfibSubnetFlowRef);
+                mdsalManager.removeFlow(confTx, natPfibFlowEntity);
+                LOG.debug("removeNaptFlowsFromActiveSwitch : Removed the flow in table {} with external subnet "
+                          + "Vpn Id {} as metadata on Napt Switch {}", NwConstants.NAPT_PFIB_TABLE,
+                    subnetVpnId, dpnId);
             }
+        }
 
-            //Remove the NAPT PFIB TABLE which forwards the incoming packet to FIB Table matching on the router ID.
-            String natPfibFlowRef = getFlowRefTs(dpnId, NwConstants.NAPT_PFIB_TABLE, routerId);
-            FlowEntity natPfibFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.NAPT_PFIB_TABLE, natPfibFlowRef);
-
-            LOG.info(
-                "removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active switch with the DPN ID {} "
-                + "and router ID {}", NwConstants.NAPT_PFIB_TABLE, dpnId, routerId);
-            mdsalManager.removeFlow(confTx, natPfibFlowEntity);
-
-            if (lastRouterOnExternalNetwork) {
-                // Long vpnId = NatUtil.getVpnId(dataBroker, routerId);
-                // - This does not work since ext-routers is deleted already - no network info
-                //Get the VPN ID from the ExternalNetworks model
-                long vpnId = -1;
-                if (vpnName == null || vpnName.isEmpty()) {
-                    // ie called from router delete cases
-                    Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
-                    LOG.debug("removeNaptFlowsFromActiveSwitch : vpnUuid is {}", vpnUuid);
-                    if (vpnUuid != null) {
-                        vpnId = NatUtil.getVpnId(dataBroker, vpnUuid.getValue());
-                        LOG.debug("removeNaptFlowsFromActiveSwitch : vpnId {} for external  network {} router delete "
-                                  + "or disableSNAT scenario", vpnId, networkId);
-                    }
-                } else {
-                    // ie called from disassociate vpn case
-                    LOG.debug("removeNaptFlowsFromActiveSwitch : This is disassociate nw with vpn case with vpnName {}",
-                        vpnName);
-                    vpnId = NatUtil.getVpnId(dataBroker, vpnName);
-                    LOG.debug("removeNaptFlowsFromActiveSwitch : vpnId for disassociate nw with vpn scenario {}",
-                        vpnId);
-                }
-
-                if (vpnId != NatConstants.INVALID_ID) {
-                    //Remove the NAPT PFIB TABLE which forwards the outgoing packet to FIB Table matching on the VPN ID.
-                    String natPfibVpnFlowRef = getFlowRefTs(dpnId, NwConstants.NAPT_PFIB_TABLE, vpnId);
-                    FlowEntity natPfibVpnFlowEntity =
-                        NatUtil.buildFlowEntity(dpnId, NwConstants.NAPT_PFIB_TABLE, natPfibVpnFlowRef);
-                    LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in {} for the active switch with the "
-                             + "DPN ID {} and VPN ID {}", NwConstants.NAPT_PFIB_TABLE, dpnId, vpnId);
-                    mdsalManager.removeFlow(confTx, natPfibVpnFlowEntity);
+        //Remove the NAPT PFIB TABLE which forwards the incoming packet to FIB Table matching on the router ID.
+        String natPfibFlowRef = getFlowRefTs(dpnId, NwConstants.NAPT_PFIB_TABLE, routerId);
+        FlowEntity natPfibFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.NAPT_PFIB_TABLE, natPfibFlowRef);
+
+        LOG.info(
+            "removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active switch with the DPN ID {} "
+            + "and router ID {}", NwConstants.NAPT_PFIB_TABLE, dpnId, routerId);
+        mdsalManager.removeFlow(confTx, natPfibFlowEntity);
+
+        if (lastRouterOnExternalNetwork) {
+            // Long vpnId = NatUtil.getVpnId(dataBroker, routerId);
+            // - This does not work since ext-routers is deleted already - no network info
+            //Get the VPN ID from the ExternalNetworks model
+            long vpnId = -1;
+            if (vpnName == null || vpnName.isEmpty()) {
+                // ie called from router delete cases
+                Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
+                LOG.debug("removeNaptFlowsFromActiveSwitch : vpnUuid is {}", vpnUuid);
+                if (vpnUuid != null) {
+                    vpnId = NatUtil.getVpnId(dataBroker, vpnUuid.getValue());
+                    LOG.debug("removeNaptFlowsFromActiveSwitch : vpnId {} for external  network {} router delete "
+                              + "or disableSNAT scenario", vpnId, networkId);
                 }
+            } else {
+                // ie called from disassociate vpn case
+                LOG.debug("removeNaptFlowsFromActiveSwitch : This is disassociate nw with vpn case with vpnName {}",
+                    vpnName);
+                vpnId = NatUtil.getVpnId(dataBroker, vpnName);
+                LOG.debug("removeNaptFlowsFromActiveSwitch : vpnId for disassociate nw with vpn scenario {}",
+                    vpnId);
             }
 
-            //For the router ID get the internal IP , internal port and the corresponding external IP and external Port.
-            IpPortMapping ipPortMapping = NatUtil.getIportMapping(dataBroker, routerId);
-            if (ipPortMapping == null) {
-                LOG.error("removeNaptFlowsFromActiveSwitch : Unable to retrieve the IpPortMapping");
-                return;
+            if (vpnId != NatConstants.INVALID_ID) {
+                //Remove the NAPT PFIB TABLE which forwards the outgoing packet to FIB Table matching on the VPN ID.
+                String natPfibVpnFlowRef = getFlowRefTs(dpnId, NwConstants.NAPT_PFIB_TABLE, vpnId);
+                FlowEntity natPfibVpnFlowEntity =
+                    NatUtil.buildFlowEntity(dpnId, NwConstants.NAPT_PFIB_TABLE, natPfibVpnFlowRef);
+                LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in {} for the active switch with the "
+                         + "DPN ID {} and VPN ID {}", NwConstants.NAPT_PFIB_TABLE, dpnId, vpnId);
+                mdsalManager.removeFlow(confTx, natPfibVpnFlowEntity);
             }
+        }
 
-            List<IntextIpProtocolType> intextIpProtocolTypes = ipPortMapping.getIntextIpProtocolType();
-            for (IntextIpProtocolType intextIpProtocolType : intextIpProtocolTypes) {
-                List<IpPortMap> ipPortMaps = intextIpProtocolType.getIpPortMap();
-                for (IpPortMap ipPortMap : ipPortMaps) {
-                    String ipPortInternal = ipPortMap.getIpPortInternal();
-                    String[] ipPortParts = ipPortInternal.split(":");
-                    if (ipPortParts.length != 2) {
-                        LOG.error("removeNaptFlowsFromActiveSwitch : Unable to retrieve the Internal IP and port");
-                        return;
-                    }
-                    String internalIp = ipPortParts[0];
-                    String internalPort = ipPortParts[1];
-
-                    //Build the flow for the outbound NAPT table
-                    naptPacketInHandler.removeIncomingPacketMap(routerId + NatConstants.COLON_SEPARATOR + internalIp
-                        + NatConstants.COLON_SEPARATOR + internalPort);
-                    String switchFlowRef = NatUtil.getNaptFlowRef(dpnId, NwConstants.OUTBOUND_NAPT_TABLE,
-                        String.valueOf(routerId), internalIp, Integer.parseInt(internalPort));
-                    FlowEntity outboundNaptFlowEntity =
-                        NatUtil.buildFlowEntity(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, cookieSnatFlow, switchFlowRef);
-
-                    LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active switch "
-                        + "with the DPN ID {} and router ID {}", NwConstants.OUTBOUND_NAPT_TABLE, dpnId, routerId);
-                    mdsalManager.removeFlow(confTx, outboundNaptFlowEntity);
-
-                    IpPortExternal ipPortExternal = ipPortMap.getIpPortExternal();
-                    String externalIp = ipPortExternal.getIpAddress();
-                    int externalPort = ipPortExternal.getPortNum();
-
-                    //Build the flow for the inbound NAPT table
-                    switchFlowRef = NatUtil.getNaptFlowRef(dpnId, NwConstants.INBOUND_NAPT_TABLE,
-                        String.valueOf(routerId), externalIp, externalPort);
-                    FlowEntity inboundNaptFlowEntity =
-                        NatUtil.buildFlowEntity(dpnId, NwConstants.INBOUND_NAPT_TABLE, cookieSnatFlow, switchFlowRef);
+        //For the router ID get the internal IP , internal port and the corresponding external IP and external Port.
+        IpPortMapping ipPortMapping = NatUtil.getIportMapping(dataBroker, routerId);
+        if (ipPortMapping == null) {
+            LOG.error("removeNaptFlowsFromActiveSwitch : Unable to retrieve the IpPortMapping");
+            return;
+        }
 
-                    LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active active switch "
-                        + "with the DPN ID {} and router ID {}", NwConstants.INBOUND_NAPT_TABLE, dpnId, routerId);
-                    mdsalManager.removeFlow(confTx, inboundNaptFlowEntity);
+        List<IntextIpProtocolType> intextIpProtocolTypes = ipPortMapping.getIntextIpProtocolType();
+        for (IntextIpProtocolType intextIpProtocolType : intextIpProtocolTypes) {
+            List<IpPortMap> ipPortMaps = intextIpProtocolType.getIpPortMap();
+            for (IpPortMap ipPortMap : ipPortMaps) {
+                String ipPortInternal = ipPortMap.getIpPortInternal();
+                String[] ipPortParts = ipPortInternal.split(":");
+                if (ipPortParts.length != 2) {
+                    LOG.error("removeNaptFlowsFromActiveSwitch : Unable to retrieve the Internal IP and port");
+                    return;
                 }
+                String internalIp = ipPortParts[0];
+                String internalPort = ipPortParts[1];
+
+                //Build the flow for the outbound NAPT table
+                naptPacketInHandler.removeIncomingPacketMap(routerId + NatConstants.COLON_SEPARATOR + internalIp
+                    + NatConstants.COLON_SEPARATOR + internalPort);
+                String switchFlowRef = NatUtil.getNaptFlowRef(dpnId, NwConstants.OUTBOUND_NAPT_TABLE,
+                    String.valueOf(routerId), internalIp, Integer.parseInt(internalPort));
+                FlowEntity outboundNaptFlowEntity =
+                    NatUtil.buildFlowEntity(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, cookieSnatFlow, switchFlowRef);
+
+                LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active switch "
+                    + "with the DPN ID {} and router ID {}", NwConstants.OUTBOUND_NAPT_TABLE, dpnId, routerId);
+                mdsalManager.removeFlow(confTx, outboundNaptFlowEntity);
+
+                IpPortExternal ipPortExternal = ipPortMap.getIpPortExternal();
+                String externalIp = ipPortExternal.getIpAddress();
+                int externalPort = ipPortExternal.getPortNum();
+
+                //Build the flow for the inbound NAPT table
+                switchFlowRef = NatUtil.getNaptFlowRef(dpnId, NwConstants.INBOUND_NAPT_TABLE,
+                    String.valueOf(routerId), externalIp, externalPort);
+                FlowEntity inboundNaptFlowEntity =
+                    NatUtil.buildFlowEntity(dpnId, NwConstants.INBOUND_NAPT_TABLE, cookieSnatFlow, switchFlowRef);
+
+                LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active active switch "
+                    + "with the DPN ID {} and router ID {}", NwConstants.INBOUND_NAPT_TABLE, dpnId, routerId);
+                mdsalManager.removeFlow(confTx, inboundNaptFlowEntity);
             }
-        } catch (Exception e) {
-            LOG.error("Error removing flow", e);
-            throw new RuntimeException("Error removing flow", e);
         }
     }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
     protected void removeNaptFibExternalOutputFlows(long routerId, BigInteger dpnId, Uuid networkId,
                                                     @Nonnull Collection<String> externalIps,
-                                                    TypedReadWriteTransaction<Configuration> writeFlowInvTx) {
+                                                    TypedReadWriteTransaction<Configuration> writeFlowInvTx)
+            throws ExecutionException, InterruptedException {
         long extVpnId = NatConstants.INVALID_ID;
         if (networkId != null) {
             Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
@@ -2109,12 +2095,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
                 + " with the DPN ID {} and router ID {} and IP {} flowRef {}",
                 NwConstants.NAPT_PFIB_TABLE, dpnId, routerId, extIp, naptFlowRef);
             FlowEntity natPfibVpnFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.NAPT_PFIB_TABLE, naptFlowRef);
-            try {
-                mdsalManager.removeFlow(writeFlowInvTx, natPfibVpnFlowEntity);
-            } catch (Exception e) {
-                LOG.error("Error removing flow", e);
-                throw new RuntimeException("Error removing flow", e);
-            }
+            mdsalManager.removeFlow(writeFlowInvTx, natPfibVpnFlowEntity);
         }
     }
 
@@ -2125,12 +2106,10 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
         return ip;
     }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
     public void removeNaptFlowsFromActiveSwitchInternetVpn(long routerId, String routerName,
                                                            BigInteger dpnId, Uuid networkId, String vpnName,
-                                                           TypedReadWriteTransaction<Configuration> writeFlowInvTx) {
+                                                           TypedReadWriteTransaction<Configuration> writeFlowInvTx)
+            throws ExecutionException, InterruptedException {
         LOG.debug("removeNaptFlowsFromActiveSwitchInternetVpn : Remove NAPT flows from Active switch Internet Vpn");
         BigInteger cookieSnatFlow = NatUtil.getCookieNaptFlow(routerId);
 
@@ -2153,12 +2132,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
                 NatUtil.buildFlowEntity(dpnId, NwConstants.NAPT_PFIB_TABLE, natPfibVpnFlowRef);
             LOG.info("removeNaptFlowsFromActiveSwitchInternetVpn : Remove the flow in the {} for the active switch "
                     + "with the DPN ID {} and VPN ID {}", NwConstants.NAPT_PFIB_TABLE, dpnId, vpnId);
-            try {
-                mdsalManager.removeFlow(writeFlowInvTx, natPfibVpnFlowEntity);
-            } catch (Exception e) {
-                LOG.error("Error removing flow", e);
-                throw new RuntimeException("Error removing flow", e);
-            }
+            mdsalManager.removeFlow(writeFlowInvTx, natPfibVpnFlowEntity);
 
             // Remove IP-PORT active NAPT entries and release port from IdManager
             // For the router ID get the internal IP , internal port and the corresponding
@@ -2193,12 +2167,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
                     LOG.info("removeNaptFlowsFromActiveSwitchInternetVpn : Remove the flow in the {} for the "
                             + "active switch with the DPN ID {} and router ID {}",
                             NwConstants.OUTBOUND_NAPT_TABLE, dpnId, routerId);
-                    try {
-                        mdsalManager.removeFlow(writeFlowInvTx, outboundNaptFlowEntity);
-                    } catch (Exception e) {
-                        LOG.error("Error removing flow", e);
-                        throw new RuntimeException("Error removing flow", e);
-                    }
+                    mdsalManager.removeFlow(writeFlowInvTx, outboundNaptFlowEntity);
 
                     IpPortExternal ipPortExternal = ipPortMap.getIpPortExternal();
                     String externalIp = ipPortExternal.getIpAddress();
@@ -2213,12 +2182,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
                     LOG.info("removeNaptFlowsFromActiveSwitchInternetVpn : Remove the flow in the {} for the "
                             + "active active switch with the DPN ID {} and router ID {}",
                             NwConstants.INBOUND_NAPT_TABLE, dpnId, routerId);
-                    try {
-                        mdsalManager.removeFlow(writeFlowInvTx, inboundNaptFlowEntity);
-                    } catch (Exception e) {
-                        LOG.error("Error removing flow", e);
-                        throw new RuntimeException("Error removing flow", e);
-                    }
+                    mdsalManager.removeFlow(writeFlowInvTx, inboundNaptFlowEntity);
 
                     // Finally release port from idmanager
                     String internalIpPort = internalIp + ":" + internalPort;
@@ -2234,11 +2198,9 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
         }
     }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
     public void removeFlowsFromNonActiveSwitches(long routerId, String routerName,
-            BigInteger naptSwitchDpnId, TypedReadWriteTransaction<Configuration> removeFlowInvTx) {
+            BigInteger naptSwitchDpnId, TypedReadWriteTransaction<Configuration> removeFlowInvTx)
+            throws ExecutionException, InterruptedException {
         LOG.debug("removeFlowsFromNonActiveSwitches : Remove NAPT related flows from non active switches");
 
         // Remove the flows from the other switches which points to the primary and secondary switches
@@ -2248,41 +2210,33 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
             LOG.error("removeFlowsFromNonActiveSwitches : Unable to get the swithces for the router {}", routerName);
             return;
         }
-        try {
-            for (BigInteger dpnId : allSwitchList) {
-                if (!naptSwitchDpnId.equals(dpnId)) {
-                    LOG.info("removeFlowsFromNonActiveSwitches : Handle Ordinary switch");
+        for (BigInteger dpnId : allSwitchList) {
+            if (!naptSwitchDpnId.equals(dpnId)) {
+                LOG.info("removeFlowsFromNonActiveSwitches : Handle Ordinary switch");
 
-                    //Remove the PSNAT entry which forwards the packet to Terminating Service table
-                    String preSnatFlowRef = getFlowRefSnat(dpnId, NwConstants.PSNAT_TABLE, String.valueOf(routerName));
-                    FlowEntity preSnatFlowEntity =
-                        NatUtil.buildFlowEntity(dpnId, NwConstants.PSNAT_TABLE, preSnatFlowRef);
+                //Remove the PSNAT entry which forwards the packet to Terminating Service table
+                String preSnatFlowRef = getFlowRefSnat(dpnId, NwConstants.PSNAT_TABLE, String.valueOf(routerName));
+                FlowEntity preSnatFlowEntity =
+                    NatUtil.buildFlowEntity(dpnId, NwConstants.PSNAT_TABLE, preSnatFlowRef);
 
-                    LOG.info("removeFlowsFromNonActiveSwitches : Remove the flow in the {} for the non active switch "
-                        + "with the DPN ID {} and router ID {}", NwConstants.PSNAT_TABLE, dpnId, routerId);
-                    mdsalManager.removeFlow(removeFlowInvTx, preSnatFlowEntity);
+                LOG.info("removeFlowsFromNonActiveSwitches : Remove the flow in the {} for the non active switch "
+                    + "with the DPN ID {} and router ID {}", NwConstants.PSNAT_TABLE, dpnId, routerId);
+                mdsalManager.removeFlow(removeFlowInvTx, preSnatFlowEntity);
 
-                    //Remove the group entry which forwards the traffic to the out port (VXLAN tunnel).
-                    long groupId = createGroupId(getGroupIdKey(routerName));
-                    List<BucketInfo> listBucketInfo = new ArrayList<>();
-                    GroupEntity preSnatGroupEntity =
-                        MDSALUtil.buildGroupEntity(dpnId, groupId, routerName, GroupTypes.GroupAll, listBucketInfo);
-
-                    LOG.info("removeFlowsFromNonActiveSwitches : Remove the group {} for the non active switch with "
-                        + "the DPN ID {} and router ID {}", groupId, dpnId, routerId);
-                    mdsalManager.removeGroup(removeFlowInvTx, preSnatGroupEntity);
+                //Remove the group entry which forwards the traffic to the out port (VXLAN tunnel).
+                long groupId = createGroupId(getGroupIdKey(routerName));
 
-                }
+                LOG.info("removeFlowsFromNonActiveSwitches : Remove the group {} for the non active switch with "
+                    + "the DPN ID {} and router ID {}", groupId, dpnId, routerId);
+                mdsalManager.removeGroup(removeFlowInvTx, dpnId, groupId);
             }
-        } catch (Exception e) {
-            LOG.error("Error removing flow", e);
-            throw new RuntimeException("Error removing flow", e);
         }
     }
 
     public void clrRtsFromBgpAndDelFibTs(final BigInteger dpnId, Long routerId, Uuid networkUuid,
                                          @Nonnull Collection<String> externalIps, String vpnName,
-                                         String extGwMacAddress, TypedReadWriteTransaction<Configuration> confTx) {
+                                         String extGwMacAddress, TypedReadWriteTransaction<Configuration> confTx)
+            throws ExecutionException, InterruptedException {
         //Withdraw the corresponding routes from the BGP.
         //Get the network ID using the router ID.
         LOG.debug("clrRtsFromBgpAndDelFibTs : Advertise to BGP and remove routes for externalIps {} with routerId {},"
@@ -2317,7 +2271,8 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
 
     protected void clrRtsFromBgpAndDelFibTs(final BigInteger dpnId, long routerId, String extIp, final String vpnName,
                                             final Uuid networkUuid, String extGwMacAddress,
-                                            TypedReadWriteTransaction<Configuration> removeFlowInvTx) {
+                                            TypedReadWriteTransaction<Configuration> removeFlowInvTx)
+            throws ExecutionException, InterruptedException {
         clearBgpRoutes(extIp, vpnName);
         delFibTsAndReverseTraffic(dpnId, routerId, extIp, vpnName, networkUuid, extGwMacAddress, false,
                 removeFlowInvTx);
@@ -2326,7 +2281,8 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
     protected void delFibTsAndReverseTraffic(final BigInteger dpnId, long routerId, String extIp,
                                              final String vpnName, Uuid extNetworkId, long tempLabel,
                                              String gwMacAddress, boolean switchOver,
-                                             TypedReadWriteTransaction<Configuration> removeFlowInvTx) {
+                                             TypedReadWriteTransaction<Configuration> removeFlowInvTx)
+            throws ExecutionException, InterruptedException {
         LOG.debug("delFibTsAndReverseTraffic : Removing fib entry for externalIp {} in routerId {}", extIp, routerId);
         String routerName = NatUtil.getRouterName(dataBroker,routerId);
         if (routerName == null) {
@@ -2410,7 +2366,8 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
 
     private void delFibTsAndReverseTraffic(final BigInteger dpnId, long routerId, String extIp, final String vpnName,
                                            final Uuid networkUuid, String extGwMacAddress, boolean switchOver,
-                                           TypedReadWriteTransaction<Configuration> removeFlowInvTx) {
+                                           TypedReadWriteTransaction<Configuration> removeFlowInvTx)
+            throws ExecutionException, InterruptedException {
         LOG.debug("delFibTsAndReverseTraffic : Removing fib entry for externalIp {} in routerId {}", extIp, routerId);
         String routerName = NatUtil.getRouterName(dataBroker,routerId);
         if (routerName == null) {
@@ -2513,7 +2470,8 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
 
     protected void clearFibTsAndReverseTraffic(final BigInteger dpnId, Long routerId, Uuid networkUuid,
                                                List<String> externalIps, String vpnName, String extGwMacAddress,
-                                               TypedReadWriteTransaction<Configuration> writeFlowInvTx) {
+                                               TypedReadWriteTransaction<Configuration> writeFlowInvTx)
+            throws ExecutionException, InterruptedException {
         //Withdraw the corresponding routes from the BGP.
         //Get the network ID using the router ID.
         LOG.debug("clearFibTsAndReverseTraffic : for externalIps {} with routerId {},"
@@ -2554,52 +2512,19 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
         NatUtil.removePrefixFromBGP(bgpManager, fibManager, rd, externalIp, vpnName, LOG);
     }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
     private void removeTunnelTableEntry(BigInteger dpnId, long serviceId,
-        TypedReadWriteTransaction<Configuration> writeFlowInvTx) {
+            TypedReadWriteTransaction<Configuration> writeFlowInvTx) throws ExecutionException, InterruptedException {
         LOG.info("removeTunnelTableEntry : called with DpnId = {} and label = {}", dpnId, serviceId);
-        List<MatchInfo> mkMatches = new ArrayList<>();
-        // Matching metadata
-        mkMatches.add(new MatchTunnelId(BigInteger.valueOf(serviceId)));
-        Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.INTERNAL_TUNNEL_TABLE,
-            getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, serviceId, ""),
-            5, String.format("%s:%d", "TST Flow Entry ", serviceId), 0, 0,
-            COOKIE_TUNNEL.add(BigInteger.valueOf(serviceId)), mkMatches, null);
-        try {
-            mdsalManager.removeFlow(writeFlowInvTx, dpnId, flowEntity);
-        } catch (Exception e) {
-            LOG.error("Error removing flow", e);
-            throw new RuntimeException("Error removing flow", e);
-        }
+        mdsalManager.removeFlow(writeFlowInvTx, dpnId,
+            getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, serviceId, ""), NwConstants.INTERNAL_TUNNEL_TABLE);
         LOG.debug("removeTunnelTableEntry : dpID {} : label : {} removed successfully", dpnId, serviceId);
     }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
     private void removeLFibTableEntry(BigInteger dpnId, long serviceId,
-        TypedReadWriteTransaction<Configuration> writeFlowInvTx) {
-        List<MatchInfo> matches = new ArrayList<>();
-        matches.add(MatchEthernetType.MPLS_UNICAST);
-        matches.add(new MatchMplsLabel(serviceId));
-
+            TypedReadWriteTransaction<Configuration> writeFlowInvTx) throws ExecutionException, InterruptedException {
         String flowRef = getFlowRef(dpnId, NwConstants.L3_LFIB_TABLE, serviceId, "");
-
         LOG.debug("removeLFibTableEntry : with flow ref {}", flowRef);
-
-        Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_LFIB_TABLE, flowRef,
-            10, flowRef, 0, 0,
-            COOKIE_VM_LFIB_TABLE, matches, null);
-
-        try {
-            mdsalManager.removeFlow(writeFlowInvTx, dpnId, flowEntity);
-        } catch (Exception e) {
-            LOG.error("Error removing flow", e);
-            throw new RuntimeException("Error removing flow", e);
-        }
-
+        mdsalManager.removeFlow(writeFlowInvTx, dpnId, flowRef, NwConstants.L3_LFIB_TABLE);
         LOG.debug("removeLFibTableEntry : dpID : {} label : {} removed successfully", dpnId, serviceId);
     }
 
index 887788f47519e44d8ff583921a97550c85827561..cb0b7f2d69e9cef924de3f60ebfd2ac15a17a433 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.netvirt.natservice.internal;
 
 import java.math.BigInteger;
 
+import java.util.concurrent.ExecutionException;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar;
 import org.opendaylight.genius.infra.Datastore.Configuration;
@@ -53,7 +54,7 @@ public class FlatVlanConntrackBasedSnatService extends ConntrackBasedSnatService
 
     @Override
     public boolean removeSnatAllSwitch(TypedReadWriteTransaction<Configuration> confTx, Routers routers,
-        BigInteger primarySwitchId) {
+            BigInteger primarySwitchId) throws ExecutionException, InterruptedException {
         return !checkProviderType(confTx, routers) && super.removeSnatAllSwitch(confTx, routers, primarySwitchId);
     }
 
@@ -65,7 +66,7 @@ public class FlatVlanConntrackBasedSnatService extends ConntrackBasedSnatService
 
     @Override
     public boolean removeSnat(TypedReadWriteTransaction<Configuration> confTx, Routers routers,
-        BigInteger primarySwitchId, BigInteger dpnId) {
+            BigInteger primarySwitchId, BigInteger dpnId) throws ExecutionException, InterruptedException {
         return !checkProviderType(confTx, routers) && super.removeSnat(confTx, routers, primarySwitchId, dpnId);
     }
 
index c0b45ecfce0ad98e523afcc519d721c1e5ae6e17..2909fac1b7413350db153abcc90d0ab92d68507b 100644 (file)
@@ -10,13 +10,13 @@ package org.opendaylight.netvirt.natservice.internal;
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 
 import com.google.common.base.Optional;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.math.BigInteger;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -302,22 +302,14 @@ public class FloatingIPListener extends AsyncDataTreeChangeListenerBase<Internal
         }
     }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
     private void removeDNATTblEntry(BigInteger dpnId, String internalIp, String externalIp, long routerId,
-            TypedReadWriteTransaction<Configuration> confTx) {
-        try {
-            FlowEntity preFlowEntity = buildPreDNATDeleteFlowEntity(dpnId, externalIp, routerId);
-            mdsalManager.removeFlow(confTx, preFlowEntity);
+            TypedReadWriteTransaction<Configuration> confTx) throws ExecutionException, InterruptedException {
+        FlowEntity preFlowEntity = buildPreDNATDeleteFlowEntity(dpnId, externalIp, routerId);
+        mdsalManager.removeFlow(confTx, preFlowEntity);
 
-            FlowEntity flowEntity = buildDNATDeleteFlowEntity(dpnId, internalIp, routerId);
-            if (flowEntity != null) {
-                mdsalManager.removeFlow(confTx, flowEntity);
-            }
-        } catch (Exception e) {
-            LOG.error("Error removing flow", e);
-            throw new RuntimeException("Error removing flow", e);
+        FlowEntity flowEntity = buildDNATDeleteFlowEntity(dpnId, internalIp, routerId);
+        if (flowEntity != null) {
+            mdsalManager.removeFlow(confTx, flowEntity);
         }
     }
 
@@ -333,22 +325,15 @@ public class FloatingIPListener extends AsyncDataTreeChangeListenerBase<Internal
         }
     }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
     private void removeSNATTblEntry(BigInteger dpnId, String internalIp, String externalIp, long routerId, long vpnId,
-                                    TypedReadWriteTransaction<Configuration> removeFlowInvTx) {
-        try {
-            FlowEntity preFlowEntity = buildPreSNATDeleteFlowEntity(dpnId, internalIp, routerId);
-            mdsalManager.removeFlow(removeFlowInvTx, preFlowEntity);
+                                    TypedReadWriteTransaction<Configuration> removeFlowInvTx)
+            throws ExecutionException, InterruptedException {
+        FlowEntity preFlowEntity = buildPreSNATDeleteFlowEntity(dpnId, internalIp, routerId);
+        mdsalManager.removeFlow(removeFlowInvTx, preFlowEntity);
 
-            FlowEntity flowEntity = buildSNATDeleteFlowEntity(dpnId, externalIp, vpnId);
-            if (flowEntity != null) {
-                mdsalManager.removeFlow(removeFlowInvTx, flowEntity);
-            }
-        } catch (Exception e) {
-            LOG.error("Error removing flow", e);
-            throw new RuntimeException("Error removing flow", e);
+        FlowEntity flowEntity = buildSNATDeleteFlowEntity(dpnId, externalIp, vpnId);
+        if (flowEntity != null) {
+            mdsalManager.removeFlow(removeFlowInvTx, flowEntity);
         }
     }
 
@@ -442,7 +427,7 @@ public class FloatingIPListener extends AsyncDataTreeChangeListenerBase<Internal
 
     void createNATFlowEntries(String interfaceName, final InternalToExternalPortMap mapping,
                               final InstanceIdentifier<RouterPorts> portIid, final String routerName,
-        TypedReadWriteTransaction<Configuration> confTx) {
+            TypedReadWriteTransaction<Configuration> confTx) throws ExecutionException, InterruptedException {
         if (!validateIpMapping(mapping)) {
             LOG.error("createNATFlowEntries : Not a valid ip addresses in the mapping {}", mapping);
             return;
@@ -501,7 +486,8 @@ public class FloatingIPListener extends AsyncDataTreeChangeListenerBase<Internal
     }
 
     void createNATFlowEntries(BigInteger dpnId,  String interfaceName, String routerName, Uuid externalNetworkId,
-                              InternalToExternalPortMap mapping, TypedReadWriteTransaction<Configuration> confTx) {
+                              InternalToExternalPortMap mapping, TypedReadWriteTransaction<Configuration> confTx)
+            throws ExecutionException, InterruptedException {
         String internalIp = mapping.getInternalIp();
         long routerId = NatUtil.getVpnId(dataBroker, routerName);
         if (routerId == NatConstants.INVALID_ID) {
@@ -537,7 +523,8 @@ public class FloatingIPListener extends AsyncDataTreeChangeListenerBase<Internal
     }
 
     void createNATOnlyFlowEntries(BigInteger dpnId, String routerName, String associatedVPN,
-                                  Uuid externalNetworkId, InternalToExternalPortMap mapping) {
+                                  Uuid externalNetworkId, InternalToExternalPortMap mapping)
+            throws ExecutionException, InterruptedException {
         String internalIp = mapping.getInternalIp();
         //String segmentId = associatedVPN == null ? routerName : associatedVPN;
         LOG.debug("createNATOnlyFlowEntries : Retrieving vpn id for VPN {} to proceed with create NAT Flows",
@@ -580,7 +567,8 @@ public class FloatingIPListener extends AsyncDataTreeChangeListenerBase<Internal
 
     void removeNATFlowEntries(String interfaceName, final InternalToExternalPortMap mapping,
                               InstanceIdentifier<RouterPorts> portIid, final String routerName, BigInteger dpnId,
-                              TypedReadWriteTransaction<Configuration> removeFlowInvTx) {
+                              TypedReadWriteTransaction<Configuration> removeFlowInvTx)
+            throws ExecutionException, InterruptedException {
         String internalIp = mapping.getInternalIp();
         String externalIp = mapping.getExternalIp();
         //Get the DPN on which this interface resides
@@ -644,7 +632,8 @@ public class FloatingIPListener extends AsyncDataTreeChangeListenerBase<Internal
     }
 
     void removeNATFlowEntries(BigInteger dpnId, String interfaceName, String vpnName, String routerName,
-                              InternalToExternalPortMap mapping, TypedReadWriteTransaction<Configuration> confTx) {
+                              InternalToExternalPortMap mapping, TypedReadWriteTransaction<Configuration> confTx)
+            throws ExecutionException, InterruptedException {
         String internalIp = mapping.getInternalIp();
         String externalIp = mapping.getExternalIp();
         long routerId = NatUtil.getVpnId(dataBroker, routerName);
@@ -788,7 +777,8 @@ public class FloatingIPListener extends AsyncDataTreeChangeListenerBase<Internal
     }
 
     private void addOrDelDefaultFibRouteForDnat(BigInteger dpnId, String routerName, long routerId,
-        TypedReadWriteTransaction<Configuration> confTx, boolean create) {
+            TypedReadWriteTransaction<Configuration> confTx, boolean create)
+            throws ExecutionException, InterruptedException {
         if (confTx == null) {
             ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
                 newTx -> addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, newTx, create)), LOG,
index f0fe1d71e13c42d734880404aeade9e5e31b8a4e..1a052370dee4563d951adc2db1ae94f6783414de 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.netvirt.natservice.internal;
 
 import com.google.common.base.Optional;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -141,266 +140,223 @@ public class NaptSwitchHA {
         }
     }
 
-    /* This method checks the switch that gone down is a NaptSwitch for a router.
-       If it is a NaptSwitch
-          1) selects new NAPT switch
-          2) installs nat flows in new NAPT switch
-          table 21(FIB)->26(PSNAT)->group(resubmit/napttunnel)->36(Terminating)->46(outbound)->47(resubmit)->21
-          3) modify the group and miss entry flow in other vSwitches pointing to newNaptSwitch
-          4) Remove nat flows in oldNaptSwitch
-     */
-    /*public void handleNaptSwitchDown(BigInteger dpnId){
-
-        LOG.debug("handleNaptSwitchDown method is called with dpnId {}",dpnId);
-        BigInteger naptSwitch;
-        try {
-            NaptSwitches naptSwitches = NatUtil.getNaptSwitch(dataBroker);
-            if (naptSwitches == null || naptSwitches.getRouterToNaptSwitch() == null
-             || naptSwitches.getRouterToNaptSwitch().isEmpty()) {
-                LOG.debug("NaptSwitchDown: NaptSwitch is not allocated for none of the routers");
-                return;
-            }
-            for (RouterToNaptSwitch routerToNaptSwitch : naptSwitches.getRouterToNaptSwitch()) {
-                String routerName = routerToNaptSwitch.getRouterName();
-                naptSwitch = routerToNaptSwitch.getPrimarySwitchId();
-                boolean naptStatus = isNaptSwitchDown(routerName,dpnId,naptSwitch);
-                if (!naptStatus) {
-                    LOG.debug("NaptSwitchDown: Switch with DpnId {} is not naptSwitch for router {}",
-                            dpnId, routerName);
-                } else {
-                    removeSnatFlowsInOldNaptSwitch(routerName,naptSwitch);
-                    return;
-                }
-            }
-        } catch (Exception ex) {
-            LOG.error("Exception in handleNaptSwitchDown method {}",ex);
-        }
-    }*/
-
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
     protected void removeSnatFlowsInOldNaptSwitch(String routerName, Long routerId, BigInteger naptSwitch,
                                                   Map<String, Long> externalIpmap,
-                                                  TypedReadWriteTransaction<Configuration> confTx) {
+                                                  TypedReadWriteTransaction<Configuration> confTx)
+            throws ExecutionException, InterruptedException {
 
-        try {
-            //remove SNAT flows in old NAPT SWITCH
-            Uuid networkId = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
-            String vpnName = getExtNetworkVpnName(routerName, networkId);
-            if (vpnName == null) {
-                LOG.error("removeSnatFlowsInOldNaptSwitch : Vpn is not associated to externalN/w of router {}",
-                    routerName);
-                return;
-            }
-            ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, networkId);
-            if (extNwProvType == null) {
-                LOG.error("removeSnatFlowsInOldNaptSwitch : Unable to retrieve the External Network Provider Type "
-                    + "for Router {}", routerName);
-                return;
-            }
-            if (extNwProvType == ProviderTypes.VXLAN) {
-                evpnNaptSwitchHA.evpnRemoveSnatFlowsInOldNaptSwitch(routerName, routerId, vpnName, naptSwitch, confTx);
-            } else {
-                //Remove the Terminating Service table entry which forwards the packet to Outbound NAPT Table
-                long tunnelId = NatUtil.getTunnelIdForNonNaptToNaptFlow(dataBroker, elanManager, idManager, routerId,
-                    routerName);
-                String tsFlowRef = externalRouterListener.getFlowRefTs(naptSwitch, NwConstants.INTERNAL_TUNNEL_TABLE,
-                    tunnelId);
-                FlowEntity tsNatFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.INTERNAL_TUNNEL_TABLE,
-                    tsFlowRef);
-
-                LOG.info("removeSnatFlowsInOldNaptSwitch : Remove the flow in table {} for the old napt switch "
-                    + "with the DPN ID {} and router ID {}", NwConstants.INTERNAL_TUNNEL_TABLE, naptSwitch, routerId);
-                mdsalManager.removeFlow(confTx, tsNatFlowEntity);
-            }
-            if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
-                //Remove the flow table 25->44 If there is no FIP Match on table 25 (PDNAT_TABLE)
-                NatUtil.removePreDnatToSnatTableEntry(confTx, mdsalManager, naptSwitch);
-            }
-            //Remove the Outbound flow entry which forwards the packet to Outbound NAPT Table
-            LOG.info("Remove the flow in table {} for the old napt switch with the DPN ID {} and router ID {}",
-                NwConstants.OUTBOUND_NAPT_TABLE, naptSwitch, routerId);
-
-            String outboundTcpNatFlowRef = externalRouterListener.getFlowRefOutbound(naptSwitch,
-                NwConstants.OUTBOUND_NAPT_TABLE, routerId, NwConstants.IP_PROT_TCP);
-            FlowEntity outboundTcpNatFlowEntity = NatUtil.buildFlowEntity(naptSwitch,
-                NwConstants.OUTBOUND_NAPT_TABLE, outboundTcpNatFlowRef);
-            mdsalManager.removeFlow(confTx, outboundTcpNatFlowEntity);
-
-            String outboundUdpNatFlowRef = externalRouterListener.getFlowRefOutbound(naptSwitch,
-                NwConstants.OUTBOUND_NAPT_TABLE, routerId, NwConstants.IP_PROT_UDP);
-            FlowEntity outboundUdpNatFlowEntity = NatUtil.buildFlowEntity(naptSwitch,
-                NwConstants.OUTBOUND_NAPT_TABLE, outboundUdpNatFlowRef);
-            mdsalManager.removeFlow(confTx, outboundUdpNatFlowEntity);
-
-            String icmpDropFlowRef = externalRouterListener.getFlowRefOutbound(naptSwitch,
-                NwConstants.OUTBOUND_NAPT_TABLE, routerId, NwConstants.IP_PROT_ICMP);
-            FlowEntity icmpDropFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE,
-                icmpDropFlowRef);
-            mdsalManager.removeFlow(confTx, icmpDropFlowEntity);
-
-            //Remove the NAPT PFIB TABLE (47->21) which forwards the incoming packet to FIB Table matching on the
-            // External Subnet Vpn Id.
-            Collection<Uuid> externalSubnetIdsForRouter = NatUtil.getExternalSubnetIdsForRouter(dataBroker,
+        //remove SNAT flows in old NAPT SWITCH
+        Uuid networkId = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
+        String vpnName = getExtNetworkVpnName(routerName, networkId);
+        if (vpnName == null) {
+            LOG.error("removeSnatFlowsInOldNaptSwitch : Vpn is not associated to externalN/w of router {}",
                 routerName);
-            for (Uuid externalSubnetId : externalSubnetIdsForRouter) {
-                long subnetVpnId = NatUtil.getVpnId(dataBroker, externalSubnetId.getValue());
-                if (subnetVpnId != -1 && !NatUtil.checkForRoutersWithSameExtSubnetAndNaptSwitch(
-                    dataBroker, externalSubnetId, routerName, naptSwitch)) {
-                    String natPfibSubnetFlowRef = externalRouterListener.getFlowRefTs(naptSwitch,
-                        NwConstants.NAPT_PFIB_TABLE, subnetVpnId);
-                    FlowEntity natPfibFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.NAPT_PFIB_TABLE,
-                        natPfibSubnetFlowRef);
-                    mdsalManager.removeFlow(confTx, natPfibFlowEntity);
-                    LOG.debug("removeSnatFlowsInOldNaptSwitch : Removed the flow in table {} with external subnet "
-                              + "Vpn Id {} as metadata on Napt Switch {}", NwConstants.NAPT_PFIB_TABLE,
-                        subnetVpnId, naptSwitch);
-                }
-            }
+            return;
+        }
+        ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, networkId);
+        if (extNwProvType == null) {
+            LOG.error("removeSnatFlowsInOldNaptSwitch : Unable to retrieve the External Network Provider Type "
+                + "for Router {}", routerName);
+            return;
+        }
+        if (extNwProvType == ProviderTypes.VXLAN) {
+            evpnNaptSwitchHA.evpnRemoveSnatFlowsInOldNaptSwitch(routerName, routerId, vpnName, naptSwitch, confTx);
+        } else {
+            //Remove the Terminating Service table entry which forwards the packet to Outbound NAPT Table
+            long tunnelId = NatUtil.getTunnelIdForNonNaptToNaptFlow(dataBroker, elanManager, idManager, routerId,
+                routerName);
+            String tsFlowRef = externalRouterListener.getFlowRefTs(naptSwitch, NwConstants.INTERNAL_TUNNEL_TABLE,
+                tunnelId);
+            FlowEntity tsNatFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.INTERNAL_TUNNEL_TABLE,
+                tsFlowRef);
 
-            // Remove the NAPT_PFIB_TABLE(47) flow entry forwards the packet to Fib Table for inbound traffic
-            // matching on the router ID.
-            String naptPFibflowRef =
-                externalRouterListener.getFlowRefTs(naptSwitch, NwConstants.NAPT_PFIB_TABLE, routerId);
-            FlowEntity naptPFibFlowEntity =
-                NatUtil.buildFlowEntity(naptSwitch, NwConstants.NAPT_PFIB_TABLE, naptPFibflowRef);
             LOG.info("removeSnatFlowsInOldNaptSwitch : Remove the flow in table {} for the old napt switch "
-                + "with the DPN ID {} and router ID {}", NwConstants.NAPT_PFIB_TABLE, naptSwitch, routerId);
-            mdsalManager.removeFlow(confTx, naptPFibFlowEntity);
-
-            // Remove the NAPT_PFIB_TABLE(47) flow entry forwards the packet to Fib Table for outbound traffic
-            // matching on the vpn ID.
-            boolean switchSharedByRouters = false;
-            Uuid extNetworkId = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
-            if (extNetworkId != null && !NatUtil.checkForRoutersWithSameExtNetAndNaptSwitch(
-                dataBroker, networkId, routerName, naptSwitch)) {
-                List<String> routerNamesAssociated = getRouterIdsForExtNetwork(extNetworkId);
-                for (String routerNameAssociated : routerNamesAssociated) {
-                    if (!routerNameAssociated.equals(routerName)) {
-                        Long routerIdAssociated = NatUtil.getVpnId(dataBroker, routerNameAssociated);
-                        BigInteger naptDpn = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerNameAssociated);
-                        if (naptDpn != null && naptDpn.equals(naptSwitch)) {
-                            LOG.debug("removeSnatFlowsInOldNaptSwitch : Napt switch {} is also acting as primary "
-                                + "for router {}", naptSwitch, routerIdAssociated);
-                            switchSharedByRouters = true;
-                            break;
-                        }
-                    }
-                }
-                if (!switchSharedByRouters) {
-                    Long vpnId = getVpnIdForRouter(routerId, extNetworkId);
-                    if (vpnId != NatConstants.INVALID_ID) {
-                        String naptFibflowRef =
-                            externalRouterListener.getFlowRefTs(naptSwitch, NwConstants.NAPT_PFIB_TABLE, vpnId);
-                        FlowEntity naptFibFlowEntity =
-                            NatUtil.buildFlowEntity(naptSwitch, NwConstants.NAPT_PFIB_TABLE, naptFibflowRef);
-                        LOG.info("removeSnatFlowsInOldNaptSwitch : Remove the flow in table {} for the old napt switch"
-                            + " with the DPN ID {} and vpnId {}", NwConstants.NAPT_PFIB_TABLE, naptSwitch, vpnId);
-                        mdsalManager.removeFlow(confTx, naptFibFlowEntity);
-                    } else {
-                        LOG.error("removeSnatFlowsInOldNaptSwitch : Invalid vpnId retrieved for routerId {}",
-                            routerId);
-                        return;
-                    }
-                }
+                + "with the DPN ID {} and router ID {}", NwConstants.INTERNAL_TUNNEL_TABLE, naptSwitch, routerId);
+            mdsalManager.removeFlow(confTx, tsNatFlowEntity);
+        }
+        if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
+            //Remove the flow table 25->44 If there is no FIP Match on table 25 (PDNAT_TABLE)
+            NatUtil.removePreDnatToSnatTableEntry(confTx, mdsalManager, naptSwitch);
+        }
+        //Remove the Outbound flow entry which forwards the packet to Outbound NAPT Table
+        LOG.info("Remove the flow in table {} for the old napt switch with the DPN ID {} and router ID {}",
+            NwConstants.OUTBOUND_NAPT_TABLE, naptSwitch, routerId);
+
+        String outboundTcpNatFlowRef = externalRouterListener.getFlowRefOutbound(naptSwitch,
+            NwConstants.OUTBOUND_NAPT_TABLE, routerId, NwConstants.IP_PROT_TCP);
+        FlowEntity outboundTcpNatFlowEntity = NatUtil.buildFlowEntity(naptSwitch,
+            NwConstants.OUTBOUND_NAPT_TABLE, outboundTcpNatFlowRef);
+        mdsalManager.removeFlow(confTx, outboundTcpNatFlowEntity);
+
+        String outboundUdpNatFlowRef = externalRouterListener.getFlowRefOutbound(naptSwitch,
+            NwConstants.OUTBOUND_NAPT_TABLE, routerId, NwConstants.IP_PROT_UDP);
+        FlowEntity outboundUdpNatFlowEntity = NatUtil.buildFlowEntity(naptSwitch,
+            NwConstants.OUTBOUND_NAPT_TABLE, outboundUdpNatFlowRef);
+        mdsalManager.removeFlow(confTx, outboundUdpNatFlowEntity);
+
+        String icmpDropFlowRef = externalRouterListener.getFlowRefOutbound(naptSwitch,
+            NwConstants.OUTBOUND_NAPT_TABLE, routerId, NwConstants.IP_PROT_ICMP);
+        FlowEntity icmpDropFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE,
+            icmpDropFlowRef);
+        mdsalManager.removeFlow(confTx, icmpDropFlowEntity);
+
+        //Remove the NAPT PFIB TABLE (47->21) which forwards the incoming packet to FIB Table matching on the
+        // External Subnet Vpn Id.
+        Collection<Uuid> externalSubnetIdsForRouter = NatUtil.getExternalSubnetIdsForRouter(dataBroker,
+            routerName);
+        for (Uuid externalSubnetId : externalSubnetIdsForRouter) {
+            long subnetVpnId = NatUtil.getVpnId(dataBroker, externalSubnetId.getValue());
+            if (subnetVpnId != -1 && !NatUtil.checkForRoutersWithSameExtSubnetAndNaptSwitch(
+                dataBroker, externalSubnetId, routerName, naptSwitch)) {
+                String natPfibSubnetFlowRef = externalRouterListener.getFlowRefTs(naptSwitch,
+                    NwConstants.NAPT_PFIB_TABLE, subnetVpnId);
+                FlowEntity natPfibFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.NAPT_PFIB_TABLE,
+                    natPfibSubnetFlowRef);
+                mdsalManager.removeFlow(confTx, natPfibFlowEntity);
+                LOG.debug("removeSnatFlowsInOldNaptSwitch : Removed the flow in table {} with external subnet "
+                          + "Vpn Id {} as metadata on Napt Switch {}", NwConstants.NAPT_PFIB_TABLE,
+                    subnetVpnId, naptSwitch);
             }
+        }
 
-            //Remove Fib entries,tables 20->44 ,36-> 44
-            String gwMacAddress = NatUtil.getExtGwMacAddFromRouterName(dataBroker, routerName);
-            if (externalIpmap != null && !externalIpmap.isEmpty()) {
-                for (Entry<String, Long> entry : externalIpmap.entrySet()) {
-                    String externalIp = entry.getKey();
-                    Long label = entry.getValue();
-                    externalRouterListener.delFibTsAndReverseTraffic(naptSwitch, routerId, externalIp, vpnName,
-                        extNetworkId, label, gwMacAddress, true, confTx);
-                    LOG.debug("removeSnatFlowsInOldNaptSwitch : Successfully removed fib entries in old naptswitch {} "
-                        + "for router {} and externalIps {} label {}", naptSwitch, routerId, externalIp, label);
+        // Remove the NAPT_PFIB_TABLE(47) flow entry forwards the packet to Fib Table for inbound traffic
+        // matching on the router ID.
+        String naptPFibflowRef =
+            externalRouterListener.getFlowRefTs(naptSwitch, NwConstants.NAPT_PFIB_TABLE, routerId);
+        FlowEntity naptPFibFlowEntity =
+            NatUtil.buildFlowEntity(naptSwitch, NwConstants.NAPT_PFIB_TABLE, naptPFibflowRef);
+        LOG.info("removeSnatFlowsInOldNaptSwitch : Remove the flow in table {} for the old napt switch "
+            + "with the DPN ID {} and router ID {}", NwConstants.NAPT_PFIB_TABLE, naptSwitch, routerId);
+        mdsalManager.removeFlow(confTx, naptPFibFlowEntity);
+
+        // Remove the NAPT_PFIB_TABLE(47) flow entry forwards the packet to Fib Table for outbound traffic
+        // matching on the vpn ID.
+        boolean switchSharedByRouters = false;
+        Uuid extNetworkId = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
+        if (extNetworkId != null && !NatUtil.checkForRoutersWithSameExtNetAndNaptSwitch(
+            dataBroker, networkId, routerName, naptSwitch)) {
+            List<String> routerNamesAssociated = getRouterIdsForExtNetwork(extNetworkId);
+            for (String routerNameAssociated : routerNamesAssociated) {
+                if (!routerNameAssociated.equals(routerName)) {
+                    Long routerIdAssociated = NatUtil.getVpnId(dataBroker, routerNameAssociated);
+                    BigInteger naptDpn = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerNameAssociated);
+                    if (naptDpn != null && naptDpn.equals(naptSwitch)) {
+                        LOG.debug("removeSnatFlowsInOldNaptSwitch : Napt switch {} is also acting as primary "
+                            + "for router {}", naptSwitch, routerIdAssociated);
+                        switchSharedByRouters = true;
+                        break;
+                    }
                 }
-            } else {
-                List<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerName);
-                if (networkId != null) {
-                    externalRouterListener.clearFibTsAndReverseTraffic(naptSwitch, routerId, networkId,
-                        externalIps, null, gwMacAddress, confTx);
-                    LOG.debug(
-                        "removeSnatFlowsInOldNaptSwitch : Successfully removed fib entries in old naptswitch {} for "
-                            + "router {} with networkId {} and externalIps {}", naptSwitch, routerId, networkId,
-                        externalIps);
+            }
+            if (!switchSharedByRouters) {
+                Long vpnId = getVpnIdForRouter(routerId, extNetworkId);
+                if (vpnId != NatConstants.INVALID_ID) {
+                    String naptFibflowRef =
+                        externalRouterListener.getFlowRefTs(naptSwitch, NwConstants.NAPT_PFIB_TABLE, vpnId);
+                    FlowEntity naptFibFlowEntity =
+                        NatUtil.buildFlowEntity(naptSwitch, NwConstants.NAPT_PFIB_TABLE, naptFibflowRef);
+                    LOG.info("removeSnatFlowsInOldNaptSwitch : Remove the flow in table {} for the old napt switch"
+                        + " with the DPN ID {} and vpnId {}", NwConstants.NAPT_PFIB_TABLE, naptSwitch, vpnId);
+                    mdsalManager.removeFlow(confTx, naptFibFlowEntity);
                 } else {
-                    LOG.debug("removeSnatFlowsInOldNaptSwitch : External network not associated to router {}",
+                    LOG.error("removeSnatFlowsInOldNaptSwitch : Invalid vpnId retrieved for routerId {}",
                         routerId);
+                    return;
                 }
-                externalRouterListener.removeNaptFibExternalOutputFlows(routerId, naptSwitch, extNetworkId,
-                    externalIps, confTx);
             }
+        }
 
-            //For the router ID get the internal IP , internal port and the corresponding external IP and external Port.
-            IpPortMapping ipPortMapping = NatUtil.getIportMapping(dataBroker, routerId);
-            if (ipPortMapping == null || ipPortMapping.getIntextIpProtocolType() == null
-                || ipPortMapping.getIntextIpProtocolType().isEmpty()) {
-                LOG.warn("removeSnatFlowsInOldNaptSwitch : No Internal Ip Port mapping associated to router {}, "
-                    + "no flows need to be removed in oldNaptSwitch {}", routerId, naptSwitch);
-                return;
+        //Remove Fib entries,tables 20->44 ,36-> 44
+        String gwMacAddress = NatUtil.getExtGwMacAddFromRouterName(dataBroker, routerName);
+        if (externalIpmap != null && !externalIpmap.isEmpty()) {
+            for (Entry<String, Long> entry : externalIpmap.entrySet()) {
+                String externalIp = entry.getKey();
+                Long label = entry.getValue();
+                externalRouterListener.delFibTsAndReverseTraffic(naptSwitch, routerId, externalIp, vpnName,
+                    extNetworkId, label, gwMacAddress, true, confTx);
+                LOG.debug("removeSnatFlowsInOldNaptSwitch : Successfully removed fib entries in old naptswitch {} "
+                    + "for router {} and externalIps {} label {}", naptSwitch, routerId, externalIp, label);
+            }
+        } else {
+            List<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerName);
+            if (networkId != null) {
+                externalRouterListener.clearFibTsAndReverseTraffic(naptSwitch, routerId, networkId,
+                    externalIps, null, gwMacAddress, confTx);
+                LOG.debug(
+                    "removeSnatFlowsInOldNaptSwitch : Successfully removed fib entries in old naptswitch {} for "
+                        + "router {} with networkId {} and externalIps {}", naptSwitch, routerId, networkId,
+                    externalIps);
+            } else {
+                LOG.debug("removeSnatFlowsInOldNaptSwitch : External network not associated to router {}",
+                    routerId);
+            }
+            externalRouterListener.removeNaptFibExternalOutputFlows(routerId, naptSwitch, extNetworkId,
+                externalIps, confTx);
+        }
+
+        //For the router ID get the internal IP , internal port and the corresponding external IP and external Port.
+        IpPortMapping ipPortMapping = NatUtil.getIportMapping(dataBroker, routerId);
+        if (ipPortMapping == null || ipPortMapping.getIntextIpProtocolType() == null
+            || ipPortMapping.getIntextIpProtocolType().isEmpty()) {
+            LOG.warn("removeSnatFlowsInOldNaptSwitch : No Internal Ip Port mapping associated to router {}, "
+                + "no flows need to be removed in oldNaptSwitch {}", routerId, naptSwitch);
+            return;
+        }
+        BigInteger cookieSnatFlow = NatUtil.getCookieNaptFlow(routerId);
+        List<IntextIpProtocolType> intextIpProtocolTypes = ipPortMapping.getIntextIpProtocolType();
+        for (IntextIpProtocolType intextIpProtocolType : intextIpProtocolTypes) {
+            if (intextIpProtocolType.getIpPortMap() == null || intextIpProtocolType.getIpPortMap().isEmpty()) {
+                LOG.debug("removeSnatFlowsInOldNaptSwitch : No {} session associated to router {},"
+                        + "no flows need to be removed in oldNaptSwitch {}",
+                    intextIpProtocolType.getProtocol(), routerId, naptSwitch);
+                break;
             }
-            BigInteger cookieSnatFlow = NatUtil.getCookieNaptFlow(routerId);
-            List<IntextIpProtocolType> intextIpProtocolTypes = ipPortMapping.getIntextIpProtocolType();
-            for (IntextIpProtocolType intextIpProtocolType : intextIpProtocolTypes) {
-                if (intextIpProtocolType.getIpPortMap() == null || intextIpProtocolType.getIpPortMap().isEmpty()) {
-                    LOG.debug("removeSnatFlowsInOldNaptSwitch : No {} session associated to router {},"
-                            + "no flows need to be removed in oldNaptSwitch {}",
-                        intextIpProtocolType.getProtocol(), routerId, naptSwitch);
-                    break;
+            List<IpPortMap> ipPortMaps = intextIpProtocolType.getIpPortMap();
+            for (IpPortMap ipPortMap : ipPortMaps) {
+                String ipPortInternal = ipPortMap.getIpPortInternal();
+                String[] ipPortParts = ipPortInternal.split(":");
+                if (ipPortParts.length != 2) {
+                    LOG.error("removeSnatFlowsInOldNaptSwitch : Unable to retrieve the Internal IP and port");
+                    continue;
                 }
-                List<IpPortMap> ipPortMaps = intextIpProtocolType.getIpPortMap();
-                for (IpPortMap ipPortMap : ipPortMaps) {
-                    String ipPortInternal = ipPortMap.getIpPortInternal();
-                    String[] ipPortParts = ipPortInternal.split(":");
-                    if (ipPortParts.length != 2) {
-                        LOG.error("removeSnatFlowsInOldNaptSwitch : Unable to retrieve the Internal IP and port");
-                        continue;
-                    }
-                    String internalIp = ipPortParts[0];
-                    String internalPort = ipPortParts[1];
-
-                    //Build and remove flow in outbound NAPT table
-                    String switchFlowRef =
-                        NatUtil.getNaptFlowRef(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, String.valueOf(routerId),
-                            internalIp, Integer.parseInt(internalPort));
-                    FlowEntity outboundNaptFlowEntity =
-                        NatUtil.buildFlowEntity(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE,
-                            cookieSnatFlow, switchFlowRef);
-
-                    LOG.info("removeSnatFlowsInOldNaptSwitch : Remove the flow in table {} for old napt switch "
-                        + "with the DPN ID {} and router ID {}", NwConstants.OUTBOUND_NAPT_TABLE, naptSwitch, routerId);
-                    mdsalManager.removeFlow(confTx, outboundNaptFlowEntity);
-
-                    IpPortExternal ipPortExternal = ipPortMap.getIpPortExternal();
-                    if (ipPortExternal == null) {
-                        LOG.debug(
-                            "removeSnatFlowsInOldNaptSwitch : External Ipport mapping not found for internalIp {} "
-                                + "with port {} for router {}", internalIp, internalPort, routerId);
-                        continue;
-                    }
-                    String externalIp = ipPortExternal.getIpAddress();
-                    int externalPort = ipPortExternal.getPortNum();
-
-                    //Build and remove flow in  inbound NAPT table
-                    switchFlowRef =
-                        NatUtil.getNaptFlowRef(naptSwitch, NwConstants.INBOUND_NAPT_TABLE, String.valueOf(routerId),
-                            externalIp, externalPort);
-                    FlowEntity inboundNaptFlowEntity =
-                        NatUtil.buildFlowEntity(naptSwitch, NwConstants.INBOUND_NAPT_TABLE,
-                            cookieSnatFlow, switchFlowRef);
-
-                    LOG.info(
-                        "removeSnatFlowsInOldNaptSwitch : Remove the flow in table {} for old napt switch with the "
-                            + "DPN ID {} and router ID {}", NwConstants.INBOUND_NAPT_TABLE, naptSwitch, routerId);
-                    mdsalManager.removeFlow(confTx, inboundNaptFlowEntity);
+                String internalIp = ipPortParts[0];
+                String internalPort = ipPortParts[1];
+
+                //Build and remove flow in outbound NAPT table
+                String switchFlowRef =
+                    NatUtil.getNaptFlowRef(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, String.valueOf(routerId),
+                        internalIp, Integer.parseInt(internalPort));
+                FlowEntity outboundNaptFlowEntity =
+                    NatUtil.buildFlowEntity(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE,
+                        cookieSnatFlow, switchFlowRef);
+
+                LOG.info("removeSnatFlowsInOldNaptSwitch : Remove the flow in table {} for old napt switch "
+                    + "with the DPN ID {} and router ID {}", NwConstants.OUTBOUND_NAPT_TABLE, naptSwitch, routerId);
+                mdsalManager.removeFlow(confTx, outboundNaptFlowEntity);
+
+                IpPortExternal ipPortExternal = ipPortMap.getIpPortExternal();
+                if (ipPortExternal == null) {
+                    LOG.debug(
+                        "removeSnatFlowsInOldNaptSwitch : External Ipport mapping not found for internalIp {} "
+                            + "with port {} for router {}", internalIp, internalPort, routerId);
+                    continue;
                 }
+                String externalIp = ipPortExternal.getIpAddress();
+                int externalPort = ipPortExternal.getPortNum();
+
+                //Build and remove flow in  inbound NAPT table
+                switchFlowRef =
+                    NatUtil.getNaptFlowRef(naptSwitch, NwConstants.INBOUND_NAPT_TABLE, String.valueOf(routerId),
+                        externalIp, externalPort);
+                FlowEntity inboundNaptFlowEntity =
+                    NatUtil.buildFlowEntity(naptSwitch, NwConstants.INBOUND_NAPT_TABLE,
+                        cookieSnatFlow, switchFlowRef);
+
+                LOG.info(
+                    "removeSnatFlowsInOldNaptSwitch : Remove the flow in table {} for old napt switch with the "
+                        + "DPN ID {} and router ID {}", NwConstants.INBOUND_NAPT_TABLE, naptSwitch, routerId);
+                mdsalManager.removeFlow(confTx, inboundNaptFlowEntity);
             }
-        } catch (Exception e) {
-            LOG.error("Error removing flow", e);
-            throw new RuntimeException("Error removing flow", e);
         }
     }
 
@@ -425,7 +381,8 @@ public class NaptSwitchHA {
 
     public boolean isNaptSwitchDown(String routerName, Long routerId, BigInteger dpnId, BigInteger naptSwitch,
                                     Long routerVpnId, Collection<String> externalIpCache,
-                                    TypedReadWriteTransaction<Configuration> confTx) {
+                                    TypedReadWriteTransaction<Configuration> confTx)
+            throws ExecutionException, InterruptedException {
         return isNaptSwitchDown(routerName, routerId, dpnId, naptSwitch, routerVpnId, externalIpCache, true,
                 confTx);
     }
@@ -434,7 +391,8 @@ public class NaptSwitchHA {
     @SuppressWarnings("checkstyle:IllegalCatch")
     public boolean isNaptSwitchDown(String routerName, Long routerId, BigInteger dpnId, BigInteger naptSwitch,
                                     Long routerVpnId, Collection<String> externalIpCache, boolean isClearBgpRts,
-                                    TypedReadWriteTransaction<Configuration> confTx) {
+                                    TypedReadWriteTransaction<Configuration> confTx)
+            throws ExecutionException, InterruptedException {
         externalIpsCache = externalIpCache;
         if (!naptSwitch.equals(dpnId)) {
             LOG.debug("isNaptSwitchDown : DpnId {} is not a naptSwitch {} for Router {}",
@@ -1005,7 +963,8 @@ public class NaptSwitchHA {
     }
 
     protected void bestEffortDeletion(long routerId, String routerName, Map<String, Long> externalIpLabel,
-                                      TypedReadWriteTransaction<Configuration> confTx) {
+                                      TypedReadWriteTransaction<Configuration> confTx)
+            throws ExecutionException, InterruptedException {
         Collection<String> newExternalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
         if (externalIpsCache != null) {
             Set<String> removedExternalIps = new HashSet<>(externalIpsCache);
index 5cdaa7bf27905c74030858ba59a91afa6582201d..0044863561a457f7c65232e03ef5c4dd96b2170f 100644 (file)
@@ -8,7 +8,6 @@
 
 package org.opendaylight.netvirt.natservice.internal;
 
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -221,11 +220,9 @@ public final class NatEvpnUtil {
                 l3GwMacTableFlowEntity, dpnId);
     }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
     static void removeL3GwMacTableEntry(final BigInteger dpnId, final long vpnId, final String macAddress,
-        IMdsalApiManager mdsalManager, TypedReadWriteTransaction<Configuration> confTx) {
+            IMdsalApiManager mdsalManager, TypedReadWriteTransaction<Configuration> confTx)
+            throws ExecutionException, InterruptedException {
         List<MatchInfo> matchInfo = new ArrayList<>();
         matchInfo.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
         matchInfo.add(new MatchEthernetSource(new MacAddress(macAddress)));
@@ -237,12 +234,7 @@ public final class NatEvpnUtil {
         Flow l3GwMacTableFlowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_GW_MAC_TABLE,
                 flowRef, 21, flowRef, 0, 0, NwConstants.COOKIE_L3_GW_MAC_TABLE, matchInfo, null);
 
-        try {
-            mdsalManager.removeFlow(confTx, dpnId, l3GwMacTableFlowEntity);
-        } catch (Exception e) {
-            LOG.error("Error removing flow", e);
-            throw new RuntimeException("Error removing flow", e);
-        }
+        mdsalManager.removeFlow(confTx, dpnId, l3GwMacTableFlowEntity);
         LOG.debug("removeL3GwMacTableEntry : Successfully removed flow entity {} on DPN = {}",
                 l3GwMacTableFlowEntity, dpnId);
     }
index 5df13fae3272151caff18614ac93b5bf113ff1d9..915eaa095059700f7fdbec7f461188da53b226ae 100644 (file)
@@ -316,9 +316,9 @@ public class NatTunnelInterfaceStateListener
                 //best effort to check IntExt model
                 naptSwitchHA.bestEffortDeletion(routerId, routerName, externalIpLabel, confTx);
             }
-        } catch (Exception ex) {
+        } catch (InterruptedException | ExecutionException e) {
             LOG.error("removeSNATFromDPN : SNAT->Exception while handling naptSwitch down for router {}",
-                routerName, ex);
+                routerName, e);
         }
     }
 
@@ -375,7 +375,8 @@ public class NatTunnelInterfaceStateListener
     }
 
     private boolean hndlTepAddForAllRtrs(BigInteger srcDpnId, String tunnelType, String tunnelName, String srcTepIp,
-                                         String destTepIp, TypedReadWriteTransaction<Configuration> writeFlowInvTx) {
+                                         String destTepIp, TypedReadWriteTransaction<Configuration> writeFlowInvTx)
+            throws ExecutionException, InterruptedException {
         LOG.trace("hndlTepAddForAllRtrs: TEP ADD ----- for EXTERNAL/HWVTEP ITM Tunnel, TYPE {} ,State is UP b/w SRC IP"
             + " : {} and DEST IP: {}", fibManager.getTransportTypeStr(tunnelType), srcTepIp, destTepIp);
 
@@ -426,7 +427,8 @@ public class NatTunnelInterfaceStateListener
     // TODO Clean up the exception handling
     @SuppressWarnings("checkstyle:IllegalCatch")
     private boolean handleTepDelForAllRtrs(BigInteger srcDpnId, String tunnelType, String tunnelName, String srcTepIp,
-                                           String destTepIp, TypedReadWriteTransaction<Configuration> writeFlowInvTx) {
+                                           String destTepIp, TypedReadWriteTransaction<Configuration> writeFlowInvTx)
+            throws ExecutionException, InterruptedException {
 
         LOG.trace("handleTepDelForAllRtrs : TEP DEL ----- for EXTERNAL/HWVTEP ITM Tunnel,TYPE {},State is UP b/w SRC IP"
             + " : {} and DEST IP: {}", fibManager.getTransportTypeStr(tunnelType), srcTepIp, destTepIp);
@@ -495,7 +497,8 @@ public class NatTunnelInterfaceStateListener
 
     private void hndlTepAddForSnatInEachRtr(RoutersList router, long routerId, final BigInteger srcDpnId,
             String tunnelType, String srcTepIp, String destTepIp, String tunnelName, String nextHopIp,
-            ProviderTypes extNwProvType, TypedReadWriteTransaction<Configuration> writeFlowInvTx) {
+            ProviderTypes extNwProvType, TypedReadWriteTransaction<Configuration> writeFlowInvTx)
+            throws ExecutionException, InterruptedException {
 
         /*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
@@ -932,8 +935,8 @@ public class NatTunnelInterfaceStateListener
     }
 
     private void hndlTepDelForSnatInEachRtr(RoutersList router, long routerId, BigInteger dpnId, String tunnelType,
-        String srcTepIp, String destTepIp, String tunnelName, ProviderTypes extNwProvType,
-        TypedReadWriteTransaction<Configuration> confTx) {
+            String srcTepIp, String destTepIp, String tunnelName, ProviderTypes extNwProvType,
+            TypedReadWriteTransaction<Configuration> confTx) throws ExecutionException, InterruptedException {
        /*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
index 7690c0c7aed7fdd2aa26437f038435e4eefa0809..c5dcdef7e4e4cc45cdf31e6a759526ca17c6013d 100644 (file)
@@ -1933,24 +1933,14 @@ public final class NatUtil {
                 preDnatToSnatTableFlowEntity,  naptDpnId);
     }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
     public static void removePreDnatToSnatTableEntry(TypedReadWriteTransaction<Configuration> confTx,
-        IMdsalApiManager mdsalManager, BigInteger naptDpnId) {
+            IMdsalApiManager mdsalManager, BigInteger naptDpnId) throws ExecutionException, InterruptedException {
         LOG.debug("removePreDnatToSnatTableEntry : Remove Pre-DNAT table {} --> table {} flow on NAPT DpnId {} ",
                 NwConstants.PDNAT_TABLE, NwConstants.INBOUND_NAPT_TABLE, naptDpnId);
         String flowRef = getFlowRefPreDnatToSnat(naptDpnId, NwConstants.PDNAT_TABLE, "PreDNATToSNAT");
-        Flow preDnatToSnatTableFlowEntity = MDSALUtil.buildFlowNew(NwConstants.PDNAT_TABLE,flowRef,
-                5, flowRef, 0, 0,  NwConstants.COOKIE_DNAT_TABLE, null, null);
-        try {
-            mdsalManager.removeFlow(confTx, naptDpnId, preDnatToSnatTableFlowEntity);
-        } catch (Exception e) {
-            LOG.error("Error removing flow", e);
-            throw new RuntimeException("Error removing flow", e);
-        }
+        mdsalManager.removeFlow(confTx, naptDpnId, flowRef, NwConstants.PDNAT_TABLE);
         LOG.debug("removePreDnatToSnatTableEntry: Successfully removed Pre-DNAT flow {} on NAPT DpnId = {}",
-                preDnatToSnatTableFlowEntity, naptDpnId);
+                flowRef, naptDpnId);
     }
 
     private static String getFlowRefPreDnatToSnat(BigInteger dpnId, short tableId, String uniqueId) {
index ff84a60fcdbdca6e1db452573fa0b968960dd076..3e7131a47d87da3f2ed45739a71a41ca638928e8 100644 (file)
@@ -15,6 +15,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ExecutionException;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -294,8 +295,6 @@ public class RouterDpnChangeListener
         LOG.trace("Update key: {}, original: {}, update: {}", update.key(), original, update);
     }
 
-    // TODO Clean up the exception handling
-    @SuppressWarnings("checkstyle:IllegalCatch")
     void handleSNATForDPN(BigInteger dpnId, String routerName, long routerId, Long routerVpnId,
         TypedReadWriteTransaction<Configuration> confTx, ProviderTypes extNwProvType) {
        //Check if primary and secondary switch are selected, If not select the role
@@ -372,8 +371,8 @@ public class RouterDpnChangeListener
                 mdsalManager.addFlow(confTx, flowEntity);
             }
 
-        } catch (Exception ex) {
-            LOG.error("handleSNATForDPN : Exception in handleSNATForDPN", ex);
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("handleSNATForDPN : Exception in handleSNATForDPN", e);
         }
     }
 
@@ -471,8 +470,8 @@ public class RouterDpnChangeListener
                 //best effort to check IntExt model
                 naptSwitchHA.bestEffortDeletion(routerId, routerName, externalIpLabel, confTx);
             }
-        } catch (Exception ex) {
-            LOG.error("removeSNATFromDPN : Exception while handling naptSwitch down for router {}", routerName, ex);
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("removeSNATFromDPN : Exception while handling naptSwitch down for router {}", routerName, e);
         }
     }
 
index 27f48ebadb006ae8812ba9f2620549d3fc0fb1dc..68341c7466a04a8532c4dface7000af2aded1c1b 100644 (file)
@@ -64,22 +64,22 @@ public class RouterToVpnListener implements NeutronvpnListener {
         //check router is associated to external network
         String extNetwork = NatUtil.getAssociatedExternalNetwork(dataBroker, routerName);
         if (extNetwork != null) {
-            LOG.debug("onRouterAssociatedToVpn : Router {} is associated with ext nw {}", routerName, extNetwork);
-            handleDNATConfigurationForRouterAssociation(routerName, vpnName, extNetwork);
-            Uuid extNetworkUuid = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
-            if (extNetworkUuid == null) {
-                LOG.error("onRouterAssociatedToVpn : Unable to retrieve external network Uuid for router {}",
+            try {
+                LOG.debug("onRouterAssociatedToVpn : Router {} is associated with ext nw {}", routerName, extNetwork);
+                handleDNATConfigurationForRouterAssociation(routerName, vpnName, extNetwork);
+                Uuid extNetworkUuid = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
+                if (extNetworkUuid == null) {
+                    LOG.error("onRouterAssociatedToVpn : Unable to retrieve external network Uuid for router {}",
                         routerName);
-                return;
-            }
-            ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName,
+                    return;
+                }
+                ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName,
                     extNetworkUuid);
-            if (extNwProvType == null) {
-                LOG.error("onRouterAssociatedToVpn : External Network Provider Type missing");
-                return;
-            }
-            long routerId = NatUtil.getVpnId(dataBroker, routerName);
-            try {
+                if (extNwProvType == null) {
+                    LOG.error("onRouterAssociatedToVpn : External Network Provider Type missing");
+                    return;
+                }
+                long routerId = NatUtil.getVpnId(dataBroker, routerName);
                 txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
                     tx -> externalRoutersListener.changeLocalVpnIdToBgpVpnId(routerName, routerId, vpnName, tx,
                             extNwProvType)).get();
@@ -102,22 +102,23 @@ public class RouterToVpnListener implements NeutronvpnListener {
         //check router is associated to external network
         String extNetwork = NatUtil.getAssociatedExternalNetwork(dataBroker, routerName);
         if (extNetwork != null) {
-            LOG.debug("onRouterDisassociatedFromVpn : Router {} is associated with ext nw {}", routerName, extNetwork);
-            handleDNATConfigurationForRouterDisassociation(routerName, vpnName, extNetwork);
-            Uuid extNetworkUuid = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
-            if (extNetworkUuid == null) {
-                LOG.error("onRouterDisassociatedFromVpn : Unable to retrieve external network Uuid for router {}",
-                        routerName);
-                return;
-            }
-            ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName,
-                    extNetworkUuid);
-            if (extNwProvType == null) {
-                LOG.error("onRouterDisassociatedFromVpn : External Network Provider Type missing");
-                return;
-            }
-            long routerId = NatUtil.getVpnId(dataBroker, routerName);
             try {
+                LOG.debug("onRouterDisassociatedFromVpn : Router {} is associated with ext nw {}", routerName,
+                    extNetwork);
+                handleDNATConfigurationForRouterDisassociation(routerName, vpnName, extNetwork);
+                Uuid extNetworkUuid = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
+                if (extNetworkUuid == null) {
+                    LOG.error("onRouterDisassociatedFromVpn : Unable to retrieve external network Uuid for router {}",
+                            routerName);
+                    return;
+                }
+                ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName,
+                        extNetworkUuid);
+                if (extNwProvType == null) {
+                    LOG.error("onRouterDisassociatedFromVpn : External Network Provider Type missing");
+                    return;
+                }
+                long routerId = NatUtil.getVpnId(dataBroker, routerName);
                 txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
                     tx -> externalRoutersListener.changeBgpVpnIdToLocalVpnId(routerName, routerId, vpnName, tx,
                             extNwProvType)).get();
@@ -130,7 +131,8 @@ public class RouterToVpnListener implements NeutronvpnListener {
         }
     }
 
-    void handleDNATConfigurationForRouterAssociation(String routerName, String vpnName, String externalNetwork) {
+    void handleDNATConfigurationForRouterAssociation(String routerName, String vpnName, String externalNetwork)
+            throws ExecutionException, InterruptedException {
         InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerName);
         Optional<RouterPorts> optRouterPorts =
             MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
@@ -164,7 +166,8 @@ public class RouterToVpnListener implements NeutronvpnListener {
         }
     }
 
-    void handleDNATConfigurationForRouterDisassociation(String routerName, String vpnName, String externalNetwork) {
+    void handleDNATConfigurationForRouterDisassociation(String routerName, String vpnName, String externalNetwork)
+            throws ExecutionException, InterruptedException {
         InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerName);
         Optional<RouterPorts> optRouterPorts =
             MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
index c5da04cd17759b2bdb02a822653fd68b1151e4d5..be6a548e96dbcbca51288ce411d8357220c7aa09 100644 (file)
@@ -8,13 +8,13 @@
 package org.opendaylight.netvirt.natservice.internal;
 
 import com.google.common.base.Optional;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.math.BigInteger;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.List;
 
+import java.util.concurrent.ExecutionException;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 
@@ -164,10 +164,8 @@ public class SNATDefaultRouteProgrammer {
         mdsalManager.installFlow(flowEntity);
     }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
-    void removeDefNATRouteInDPN(BigInteger dpnId, long vpnId, TypedReadWriteTransaction<Configuration> confTx) {
+    void removeDefNATRouteInDPN(BigInteger dpnId, long vpnId, TypedReadWriteTransaction<Configuration> confTx)
+            throws ExecutionException, InterruptedException {
         FlowEntity flowEntity = buildDefNATFlowEntity(dpnId, vpnId);
         if (flowEntity == null) {
             LOG.error("removeDefNATRouteInDPN : Flow entity received is NULL."
@@ -175,19 +173,11 @@ public class SNATDefaultRouteProgrammer {
             return;
         }
         natServiceCounters.removeDefaultNatFlow();
-        try {
-            mdsalManager.removeFlow(confTx, flowEntity);
-        } catch (Exception e) {
-            LOG.error("Error removing flow", e);
-            throw new RuntimeException("Error removing flow", e);
-        }
+        mdsalManager.removeFlow(confTx, flowEntity);
     }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
     void removeDefNATRouteInDPN(BigInteger dpnId, long bgpVpnId, long routerId,
-        TypedReadWriteTransaction<Configuration> confTx) {
+            TypedReadWriteTransaction<Configuration> confTx) throws ExecutionException, InterruptedException {
         FlowEntity flowEntity = buildDefNATFlowEntity(dpnId, bgpVpnId, routerId);
         if (flowEntity == null) {
             LOG.error("removeDefNATRouteInDPN : Flow entity received is NULL."
@@ -195,12 +185,7 @@ public class SNATDefaultRouteProgrammer {
             return;
         }
         natServiceCounters.removeDefaultNatFlow();
-        try {
-            mdsalManager.removeFlow(confTx, flowEntity);
-        } catch (Exception e) {
-            LOG.error("Error removing flow", e);
-            throw new RuntimeException("Error removing flow", e);
-        }
+        mdsalManager.removeFlow(confTx, flowEntity);
     }
 
     void addOrDelDefaultFibRouteToSNATForSubnet(Subnets subnet, String networkId, int flowAction, long vpnId) {
index 2e90cb1d34095df3fe30352f600aba0c7485d5df..a0275b1d7c5e862b00eff5ce9eb289c1f1409d54 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.netvirt.natservice.internal;
 import java.math.BigInteger;
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.ExecutionException;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.genius.infra.Datastore;
@@ -51,7 +52,8 @@ public class SnatServiceManagerImpl implements SnatServiceManager {
 
     @Override
     public void notify(TypedReadWriteTransaction<Datastore.Configuration> confTx,
-        Routers router, BigInteger primarySwitchId, BigInteger dpnId, Action action) {
+            Routers router, BigInteger primarySwitchId, BigInteger dpnId, Action action)
+            throws ExecutionException, InterruptedException {
         for (SnatServiceListener snatServiceListener : snatServiceListeners) {
             boolean result = false;
             switch (action) {
index 30f2b3ecf2554540d71157d1c863843a47b6ea5c..8faf3ae21eedf14563c9c4ab4a919c3afa8fc6db 100644 (file)
@@ -15,11 +15,11 @@ import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
 import javax.annotation.Nonnull;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -410,21 +410,13 @@ public class VpnFloatingIpHandler implements FloatingIPHandler {
                 + NwConstants.FLOWID_SEPARATOR + ipAddress;
     }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
     private void removeTunnelTableEntry(BigInteger dpnId, long serviceId,
-        TypedReadWriteTransaction<Configuration> confTx) {
+            TypedReadWriteTransaction<Configuration> confTx) throws ExecutionException, InterruptedException {
 
         LOG.debug("removeTunnelTableEntry : called with DpnId = {} and label = {}", dpnId, serviceId);
-        try {
-            mdsalManager.removeFlow(confTx, dpnId,
-                new FlowKey(new FlowId(getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, serviceId, ""))),
-                NwConstants.INTERNAL_TUNNEL_TABLE);
-        } catch (Exception e) {
-            LOG.error("Error removing flow", e);
-            throw new RuntimeException("Error removing flow", e);
-        }
+        mdsalManager.removeFlow(confTx, dpnId,
+            new FlowKey(new FlowId(getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, serviceId, ""))),
+            NwConstants.INTERNAL_TUNNEL_TABLE);
         LOG.debug("removeTunnelTableEntry : Terminating service Entry for dpID {} : label : {} removed successfully",
                 dpnId, serviceId);
     }
@@ -480,22 +472,14 @@ public class VpnFloatingIpHandler implements FloatingIPHandler {
         LOG.debug("makeLFibTableEntry : LFIB Entry for dpID {} : label : {} modified successfully", dpId, serviceId);
     }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
     private void removeLFibTableEntry(BigInteger dpnId, long serviceId,
-        TypedReadWriteTransaction<Configuration> confTx) {
+            TypedReadWriteTransaction<Configuration> confTx) throws ExecutionException, InterruptedException {
 
         String flowRef = getFlowRef(dpnId, NwConstants.L3_LFIB_TABLE, serviceId, "");
 
         LOG.debug("removeLFibTableEntry : removing LFib entry with flow ref {}", flowRef);
 
-        try {
-            mdsalManager.removeFlow(confTx, dpnId, new FlowKey(new FlowId(flowRef)), NwConstants.L3_LFIB_TABLE);
-        } catch (Exception e) {
-            LOG.error("Error removing flow", e);
-            throw new RuntimeException("Error removing flow", e);
-        }
+        mdsalManager.removeFlow(confTx, dpnId, new FlowKey(new FlowId(flowRef)), NwConstants.L3_LFIB_TABLE);
 
         LOG.debug("removeLFibTableEntry : LFIB Entry for dpID : {} label : {} removed successfully",
                 dpnId, serviceId);
index 9cc0298dc9969bc57f1aefffb0ce5e69820f2bd2..e58a8ca9e6f991887e9a12e854fb813dc5b0d0b8 100644 (file)
@@ -11,6 +11,7 @@ import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar;
 import org.opendaylight.genius.infra.Datastore.Configuration;
@@ -92,7 +93,7 @@ public class VxlanGreConntrackBasedSnatService extends ConntrackBasedSnatService
 
     @Override
     public boolean removeSnatAllSwitch(TypedReadWriteTransaction<Configuration> confTx, Routers routers,
-        BigInteger primarySwitchId) {
+            BigInteger primarySwitchId) throws ExecutionException, InterruptedException {
         ProviderTypes extNwProviderType = NatUtil.getProviderTypefromNetworkId(confTx, routers.getNetworkId());
         LOG.debug("VxlanGreConntrackBasedSnatService: handleSnatAllSwitch ProviderTypes {}", extNwProviderType);
         if (extNwProviderType == ProviderTypes.FLAT || extNwProviderType == ProviderTypes.VLAN) {
@@ -116,7 +117,7 @@ public class VxlanGreConntrackBasedSnatService extends ConntrackBasedSnatService
 
     @Override
     public boolean removeSnat(TypedReadWriteTransaction<Configuration> confTx, Routers routers,
-        BigInteger primarySwitchId, BigInteger dpnId) {
+            BigInteger primarySwitchId, BigInteger dpnId) throws ExecutionException, InterruptedException {
         ProviderTypes extNwProviderType = NatUtil.getProviderTypefromNetworkId(confTx, routers.getNetworkId());
         LOG.debug("VxlanGreConntrackBasedSnatService: handleSnat ProviderTypes {}", extNwProviderType);
         if (extNwProviderType == ProviderTypes.FLAT || extNwProviderType == ProviderTypes.VLAN) {
@@ -170,7 +171,7 @@ public class VxlanGreConntrackBasedSnatService extends ConntrackBasedSnatService
 
     @Override
     protected void removeSnatSpecificEntriesForNaptSwitch(TypedReadWriteTransaction<Configuration> confTx,
-        Routers routers, BigInteger dpnId) {
+            Routers routers, BigInteger dpnId) throws ExecutionException, InterruptedException {
 
         LOG.info("installSnatSpecificEntriesForNaptSwitch for router {}",
             routers.getRouterName());
@@ -232,7 +233,7 @@ public class VxlanGreConntrackBasedSnatService extends ConntrackBasedSnatService
     }
 
     protected void removeOutboundTblTrackEntryForVxlanGre(TypedReadWriteTransaction<Configuration> confTx,
-        BigInteger dpnId, Long routerId) {
+            BigInteger dpnId, Long routerId) throws ExecutionException, InterruptedException {
         LOG.info("createOutboundTblTrackEntryForVxlanGre: Install Outbound tracking table flow on dpId {} for "
             + "routerId {}", dpnId, routerId);
 
@@ -278,7 +279,7 @@ public class VxlanGreConntrackBasedSnatService extends ConntrackBasedSnatService
     }
 
     protected void removeOutboundTblEntryForVxlanGre(TypedReadWriteTransaction<Configuration> confTx, BigInteger dpnId,
-        long routerId, List<ExternalIps> externalIps) {
+            long routerId, List<ExternalIps> externalIps) throws ExecutionException, InterruptedException {
         LOG.info("createOutboundTblEntryForVxlanGre: Install Outbound table flow on dpId {} for routerId {}", dpnId,
             routerId);
         if (externalIps.isEmpty()) {
@@ -310,7 +311,7 @@ public class VxlanGreConntrackBasedSnatService extends ConntrackBasedSnatService
     }
 
     protected void removeNaptPfibFlowForVxlanGre(TypedReadWriteTransaction<Configuration> confTx, Routers routers,
-        BigInteger dpnId, Long extNetVpnId) {
+            BigInteger dpnId, Long extNetVpnId) throws ExecutionException, InterruptedException {
         LOG.info("installNaptPfibFlowForVxlanGre: Install Napt preFibFlow on dpId {} with matching extNetVpnId {} "
             + "for router {}", dpnId, extNetVpnId, routers.getRouterName());
         String flowRef = getFlowRef(dpnId, NwConstants.NAPT_PFIB_TABLE, extNetVpnId);
@@ -350,7 +351,7 @@ public class VxlanGreConntrackBasedSnatService extends ConntrackBasedSnatService
     }
 
     protected void removeInboundEntryForVxlanGre(TypedReadWriteTransaction<Configuration> confTx, BigInteger dpnId,
-        long routerId, List<ExternalIps> externalIps) {
+            long routerId, List<ExternalIps> externalIps) throws ExecutionException, InterruptedException {
         LOG.info("removeInboundEntryForVxlanGre: remove Inbound table entry on dpId {} for routerId {}",
             dpnId, routerId);
         if (externalIps.isEmpty()) {
@@ -395,7 +396,7 @@ public class VxlanGreConntrackBasedSnatService extends ConntrackBasedSnatService
     }
 
     protected void removeTerminatingServiceTblEntryForVxlanGre(TypedReadWriteTransaction<Configuration> confTx,
-        BigInteger dpnId, Long routerId) {
+            BigInteger dpnId, Long routerId) throws ExecutionException, InterruptedException {
         LOG.info("removeTerminatingServiceTblEntryForVxlanGre : removing entry for"
             + "Terminating Service Table for switch {}, routerId {}", dpnId, routerId);
 
@@ -452,7 +453,7 @@ public class VxlanGreConntrackBasedSnatService extends ConntrackBasedSnatService
 
     @Override
     protected void removeSnatMissEntry(TypedReadWriteTransaction<Configuration> confTx, BigInteger dpnId,
-        Long routerId, String routerName) {
+            Long routerId, String routerName) throws ExecutionException, InterruptedException {
         LOG.debug("installSnatMissEntry : Removing SNAT miss entry in switch {}", dpnId);
 
         String flowRef = getFlowRef(dpnId, NwConstants.PSNAT_TABLE, routerId);
index 83413493c66342a72153e60f25374d434539a30b..52a6815e86e437a080809f1860e59fc339fdd3ea 100644 (file)
@@ -13,6 +13,7 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Set;
 
+import java.util.concurrent.ExecutionException;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.genius.infra.Datastore.Configuration;
@@ -62,31 +63,34 @@ public interface IVpnManager {
 
     @Deprecated
     void addSubnetMacIntoVpnInstance(String vpnName, String subnetVpnName, String srcMacAddress,
-            BigInteger dpnId, WriteTransaction tx);
+            BigInteger dpnId, WriteTransaction tx) throws ExecutionException, InterruptedException;
 
     void addSubnetMacIntoVpnInstance(String vpnName, String subnetVpnName, String srcMacAddress,
-        BigInteger dpnId, TypedWriteTransaction<Configuration> confTx);
+        BigInteger dpnId, TypedWriteTransaction<Configuration> confTx) throws ExecutionException, InterruptedException;
 
     @Deprecated
     void removeSubnetMacFromVpnInstance(String vpnName, String subnetVpnName, String srcMacAddress,
-            BigInteger dpnId, WriteTransaction tx);
+            BigInteger dpnId, WriteTransaction tx) throws ExecutionException, InterruptedException;
 
     void removeSubnetMacFromVpnInstance(String vpnName, String subnetVpnName, String srcMacAddress,
-        BigInteger dpnId, TypedReadWriteTransaction<Configuration> confTx);
+        BigInteger dpnId, TypedReadWriteTransaction<Configuration> confTx)
+        throws ExecutionException, InterruptedException;
 
     @Deprecated
     void addRouterGwMacFlow(String routerName, String routerGwMac, BigInteger dpnId, Uuid extNetworkId,
-            String subnetVpnName, WriteTransaction writeTx);
+            String subnetVpnName, WriteTransaction writeTx) throws ExecutionException, InterruptedException;
 
     void addRouterGwMacFlow(String routerName, String routerGwMac, BigInteger dpnId, Uuid extNetworkId,
-        String subnetVpnName, TypedWriteTransaction<Configuration> confTx);
+        String subnetVpnName, TypedWriteTransaction<Configuration> confTx)
+        throws ExecutionException, InterruptedException;
 
     @Deprecated
     void removeRouterGwMacFlow(String routerName, String routerGwMac, BigInteger dpnId, Uuid extNetworkId,
-            String subnetVpnName, WriteTransaction writeTx);
+            String subnetVpnName, WriteTransaction writeTx) throws ExecutionException, InterruptedException;
 
     void removeRouterGwMacFlow(String routerName, String routerGwMac, BigInteger dpnId, Uuid extNetworkId,
-        String subnetVpnName, TypedReadWriteTransaction<Configuration> confTx);
+        String subnetVpnName, TypedReadWriteTransaction<Configuration> confTx)
+        throws ExecutionException, InterruptedException;
 
     @Deprecated
     void addArpResponderFlowsToExternalNetworkIps(String id, Collection<String> fixedIps, String macAddress,
index 689096940d84bd65e173bfa230453c541de37c0d..c8367f09a1fec60e339e176c9a108bc6406baebb 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.netvirt.vpnmanager;
 import java.math.BigInteger;
 import java.util.List;
 import java.util.Objects;
+import java.util.concurrent.ExecutionException;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -110,7 +111,8 @@ public class CentralizedSwitchChangeListener
         return this;
     }
 
-    private void setupRouterGwFlows(RouterToNaptSwitch routerToNaptSwitch, WriteTransaction writeTx, int addOrRemove) {
+    private void setupRouterGwFlows(RouterToNaptSwitch routerToNaptSwitch, WriteTransaction writeTx, int addOrRemove)
+            throws ExecutionException, InterruptedException {
         Routers router = null;
         if (addOrRemove == NwConstants.ADD_FLOW) {
             router = vpnUtil.getExternalRouter(routerToNaptSwitch.getRouterName());
index 43e55e2897cd5adc9bca3d051545c114e46d5b9b..aa5bb32e17f42f70e0bb6496865dccabdfef0337 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.netvirt.vpnmanager;
 
 import com.google.common.base.Optional;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -18,7 +17,6 @@ import java.util.List;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
-import java.util.function.Consumer;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -45,6 +43,7 @@ import org.opendaylight.genius.mdsalutil.UpgradeState;
 import org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata;
 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
+import org.opendaylight.infrautils.utils.function.InterruptibleCheckedConsumer;
 import org.opendaylight.netvirt.bgpmanager.api.IBgpManager;
 import org.opendaylight.netvirt.elan.arp.responder.ArpResponderInput;
 import org.opendaylight.netvirt.elan.arp.responder.ArpResponderInput.ArpReponderInputBuilder;
@@ -374,39 +373,42 @@ public class VpnManagerImpl implements IVpnManager {
 
     @Override
     public void addSubnetMacIntoVpnInstance(String vpnName, String subnetVpnName, String srcMacAddress,
-        BigInteger dpnId, TypedWriteTransaction<Configuration> confTx) {
+            BigInteger dpnId, TypedWriteTransaction<Configuration> confTx)
+            throws ExecutionException, InterruptedException {
         setupSubnetMacInVpnInstance(vpnName, subnetVpnName, srcMacAddress, dpnId,
             (vpnId, dpId, subnetVpnId) -> addGwMac(srcMacAddress, confTx, vpnId, dpId, subnetVpnId));
     }
 
     @Override
     public void addSubnetMacIntoVpnInstance(String vpnName, String subnetVpnName, String srcMacAddress,
-            BigInteger dpnId, WriteTransaction tx) {
+            BigInteger dpnId, WriteTransaction tx) throws ExecutionException, InterruptedException {
         setupSubnetMacInVpnInstance(vpnName, subnetVpnName, srcMacAddress, dpnId,
             (vpnId, dpId, subnetVpnId) -> addGwMac(srcMacAddress, tx, vpnId, dpId, subnetVpnId));
     }
 
     @Override
     public void removeSubnetMacFromVpnInstance(String vpnName, String subnetVpnName, String srcMacAddress,
-        BigInteger dpnId, TypedReadWriteTransaction<Configuration> confTx) {
+            BigInteger dpnId, TypedReadWriteTransaction<Configuration> confTx)
+            throws ExecutionException, InterruptedException {
         setupSubnetMacInVpnInstance(vpnName, subnetVpnName, srcMacAddress, dpnId,
             (vpnId, dpId, subnetVpnId) -> removeGwMac(srcMacAddress, confTx, vpnId, dpId, subnetVpnId));
     }
 
     @Override
     public void removeSubnetMacFromVpnInstance(String vpnName, String subnetVpnName, String srcMacAddress,
-            BigInteger dpnId, WriteTransaction tx) {
+            BigInteger dpnId, WriteTransaction tx) throws ExecutionException, InterruptedException {
         setupSubnetMacInVpnInstance(vpnName, subnetVpnName, srcMacAddress, dpnId,
             (vpnId, dpId, subnetVpnId) -> removeGwMac(srcMacAddress, tx, vpnId, dpId, subnetVpnId));
     }
 
     @FunctionalInterface
     private interface VpnInstanceSubnetMacSetupMethod {
-        void process(long vpnId, BigInteger dpId, long subnetVpnId);
+        void process(long vpnId, BigInteger dpId, long subnetVpnId) throws InterruptedException, ExecutionException;
     }
 
     private void setupSubnetMacInVpnInstance(String vpnName, String subnetVpnName, String srcMacAddress,
-            BigInteger dpnId, VpnInstanceSubnetMacSetupMethod consumer) {
+            BigInteger dpnId, VpnInstanceSubnetMacSetupMethod consumer)
+            throws ExecutionException, InterruptedException {
         if (vpnName == null) {
             LOG.warn("Cannot setup subnet MAC {} on DPN {}, null vpnName", srcMacAddress, dpnId);
             return;
@@ -440,56 +442,51 @@ public class VpnManagerImpl implements IVpnManager {
         mdsalManager.removeFlowToTx(flowEntity, tx);
     }
 
-    // TODO skitt Fix the exception handling here
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
     private void removeGwMac(String srcMacAddress, TypedReadWriteTransaction<Configuration> tx, long vpnId,
-        BigInteger dpId, long subnetVpnId) {
-        try {
-            mdsalManager.removeFlow(tx, dpId,
-                VpnUtil.getL3VpnGatewayFlowRef(NwConstants.L3_GW_MAC_TABLE, dpId, vpnId, srcMacAddress, subnetVpnId),
-                NwConstants.L3_GW_MAC_TABLE);
-        } catch (Exception e) {
-            LOG.error("Error removing flow", e);
-            throw new RuntimeException("Error removing flow", e);
-        }
+            BigInteger dpId, long subnetVpnId) throws ExecutionException, InterruptedException {
+        mdsalManager.removeFlow(tx, dpId,
+            VpnUtil.getL3VpnGatewayFlowRef(NwConstants.L3_GW_MAC_TABLE, dpId, vpnId, srcMacAddress, subnetVpnId),
+            NwConstants.L3_GW_MAC_TABLE);
     }
 
     @Override
     public void addRouterGwMacFlow(String routerName, String routerGwMac, BigInteger dpnId, Uuid extNetworkId,
-        String subnetVpnName, TypedWriteTransaction<Configuration> confTx) {
+            String subnetVpnName, TypedWriteTransaction<Configuration> confTx)
+            throws ExecutionException, InterruptedException {
         setupRouterGwMacFlow(routerName, routerGwMac, dpnId, extNetworkId,
             vpnId -> addSubnetMacIntoVpnInstance(vpnId, subnetVpnName, routerGwMac, dpnId, confTx), "Installing");
     }
 
     @Override
     public void addRouterGwMacFlow(String routerName, String routerGwMac, BigInteger dpnId, Uuid extNetworkId,
-            String subnetVpnName, WriteTransaction writeTx) {
+            String subnetVpnName, WriteTransaction writeTx) throws ExecutionException, InterruptedException {
         setupRouterGwMacFlow(routerName, routerGwMac, dpnId, extNetworkId, writeTx,
             (vpnId, tx) -> addSubnetMacIntoVpnInstance(vpnId, subnetVpnName, routerGwMac, dpnId, tx), "Installing");
     }
 
     @Override
     public void removeRouterGwMacFlow(String routerName, String routerGwMac, BigInteger dpnId, Uuid extNetworkId,
-        String subnetVpnName, TypedReadWriteTransaction<Configuration> confTx) {
+            String subnetVpnName, TypedReadWriteTransaction<Configuration> confTx)
+            throws ExecutionException, InterruptedException {
         setupRouterGwMacFlow(routerName, routerGwMac, dpnId, extNetworkId,
             vpnId -> removeSubnetMacFromVpnInstance(vpnId, subnetVpnName, routerGwMac, dpnId, confTx), "Removing");
     }
 
     @Override
     public void removeRouterGwMacFlow(String routerName, String routerGwMac, BigInteger dpnId, Uuid extNetworkId,
-            String subnetVpnName, WriteTransaction writeTx) {
+            String subnetVpnName, WriteTransaction writeTx) throws ExecutionException, InterruptedException {
         setupRouterGwMacFlow(routerName, routerGwMac, dpnId, extNetworkId, writeTx,
             (vpnId, tx) -> removeSubnetMacFromVpnInstance(vpnId, subnetVpnName, routerGwMac, dpnId, tx), "Removing");
     }
 
     @FunctionalInterface
     private interface RouterGwMacFlowSetupMethod {
-        void process(String vpnId, WriteTransaction tx);
+        void process(String vpnId, WriteTransaction tx) throws InterruptedException, ExecutionException;
     }
 
     private void setupRouterGwMacFlow(String routerName, String routerGwMac, BigInteger dpnId, Uuid extNetworkId,
-            WriteTransaction writeTx, RouterGwMacFlowSetupMethod consumer, String operation) {
+            WriteTransaction writeTx, RouterGwMacFlowSetupMethod consumer, String operation)
+            throws ExecutionException, InterruptedException {
         if (routerGwMac == null) {
             LOG.warn("Failed to handle router GW flow in GW-MAC table. MAC address is missing for router-id {}",
                     routerName);
@@ -518,7 +515,8 @@ public class VpnManagerImpl implements IVpnManager {
     }
 
     private void setupRouterGwMacFlow(String routerName, String routerGwMac, BigInteger dpnId, Uuid extNetworkId,
-        Consumer<String> consumer, String operation) {
+            InterruptibleCheckedConsumer<String, ExecutionException> consumer, String operation)
+            throws ExecutionException, InterruptedException {
         if (routerGwMac == null) {
             LOG.warn("Failed to handle router GW flow in GW-MAC table. MAC address is missing for router-id {}",
                 routerName);