From e98d6e9c8d40490cbd2c4defb75e715ac09c4165 Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Wed, 18 Jul 2018 18:24:34 +0200 Subject: [PATCH] Clean up MDSALManager exception handling 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 --- .../DhcpExternalTunnelManager.java | 13 +- .../netvirt/dhcpservice/DhcpManager.java | 5 +- .../netvirt/dhcpservice/DhcpServiceUtils.java | 28 +- .../elan/internal/ElanInterfaceManager.java | 30 +- .../ElanLearntVpnVipToPortListener.java | 4 +- .../netvirt/elan/utils/ElanUtils.java | 54 +- .../natservice/api/SnatServiceListener.java | 5 +- .../natservice/api/SnatServiceManager.java | 4 +- .../SnatCentralizedSwitchChangeListener.java | 4 +- .../internal/AbstractSnatService.java | 58 +- .../internal/ConntrackBasedSnatService.java | 17 +- .../internal/EvpnDnatFlowProgrammer.java | 15 +- .../natservice/internal/EvpnNaptSwitchHA.java | 23 +- .../internal/EvpnSnatFlowProgrammer.java | 15 +- .../ExternalNetworksChangeListener.java | 3 +- .../internal/ExternalRoutersListener.java | 495 ++++++++---------- .../FlatVlanConntrackBasedSnatService.java | 5 +- .../internal/FloatingIPListener.java | 60 +-- .../natservice/internal/NaptSwitchHA.java | 451 ++++++++-------- .../natservice/internal/NatEvpnUtil.java | 14 +- .../NatTunnelInterfaceStateListener.java | 17 +- .../netvirt/natservice/internal/NatUtil.java | 16 +- .../internal/RouterDpnChangeListener.java | 11 +- .../internal/RouterToVpnListener.java | 65 +-- .../internal/SNATDefaultRouteProgrammer.java | 27 +- .../internal/SnatServiceManagerImpl.java | 4 +- .../internal/VpnFloatingIpHandler.java | 30 +- .../VxlanGreConntrackBasedSnatService.java | 19 +- .../netvirt/vpnmanager/api/IVpnManager.java | 20 +- .../CentralizedSwitchChangeListener.java | 4 +- .../netvirt/vpnmanager/VpnManagerImpl.java | 52 +- 31 files changed, 661 insertions(+), 907 deletions(-) diff --git a/dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpExternalTunnelManager.java b/dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpExternalTunnelManager.java index 002999482e..07d590a0a9 100644 --- a/dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpExternalTunnelManager.java +++ b/dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpExternalTunnelManager.java @@ -248,7 +248,7 @@ public class DhcpExternalTunnelManager implements IDhcpExternalTunnelManager { } public void installDhcpFlowsForVms(BigInteger designatedDpnId, Set listVmMacAddress, - TypedReadWriteTransaction tx) { + TypedReadWriteTransaction 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 listOfDpns, Pair pair, - TypedReadWriteTransaction tx) { + TypedReadWriteTransaction 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 tunnelIpElanNamePair, BigInteger dpnId, - TypedReadWriteTransaction tx) { + TypedReadWriteTransaction tx) + throws ExecutionException, InterruptedException { Set 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 tx) { + TypedReadWriteTransaction 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 tx) { + TypedReadWriteTransaction 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 tx) { + TypedReadWriteTransaction tx) throws ExecutionException, InterruptedException { DhcpServiceUtils.setupDhcpDropAction(dpn, NwConstants.DHCP_TABLE_EXTERNAL_TUNNEL, vmMacAddress, NwConstants.ADD_FLOW, mdsalUtil, dhcpServiceCounters, tx); } diff --git a/dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpManager.java b/dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpManager.java index f5b049a70e..62961362ab 100644 --- a/dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpManager.java +++ b/dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpManager.java @@ -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 tx) { + TypedReadWriteTransaction 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 tx) { + TypedReadWriteTransaction tx) throws ExecutionException, InterruptedException { DhcpServiceUtils.setupDhcpFlowEntry(dpId, NwConstants.DHCP_TABLE, vmMacAddress, NwConstants.DEL_FLOW, mdsalUtil, dhcpServiceCounters, tx); } diff --git a/dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpServiceUtils.java b/dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpServiceUtils.java index 0ffdce200d..fcb394ced4 100644 --- a/dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpServiceUtils.java +++ b/dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpServiceUtils.java @@ -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 tx) { + TypedReadWriteTransaction 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 tx) { + TypedReadWriteTransaction 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 matches = getDhcpArpMatch(vni, dhcpIpAddress); diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanInterfaceManager.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanInterfaceManager.java index 83b04cfcde..114566c358 100644 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanInterfaceManager.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanInterfaceManager.java @@ -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 flowTx) { - try { - int ifTag = interfaceInfo.getInterfaceTag(); - Flow flow = MDSALUtil.buildFlow(NwConstants.ELAN_FILTER_EQUALS_TABLE, - getFlowRef(NwConstants.ELAN_FILTER_EQUALS_TABLE, ifTag, "group")); + TypedReadWriteTransaction 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 getRemoteBCGroupBucketInfos(ElanInstance elanInfo, int bucketKeyStart, diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanLearntVpnVipToPortListener.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanLearntVpnVipToPortListener.java index 84b863a875..912558c1be 100644 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanLearntVpnVipToPortListener.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanLearntVpnVipToPortListener.java @@ -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 interfaceTx, TypedReadWriteTransaction flowTx) { + TypedWriteTransaction interfaceTx, TypedReadWriteTransaction flowTx) + throws ExecutionException, InterruptedException { LOG.trace("Deleting mac address {} and interface name {} from ElanInterfaceForwardingEntries " + "and ElanForwardingTables DS", macAddress, interfaceName); PhysAddress physAddress = new PhysAddress(macAddress); diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanUtils.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanUtils.java index a2aaacfb8d..aaeb5d416e 100755 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanUtils.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanUtils.java @@ -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 flowTx) { + MacEntry macEntry, TypedReadWriteTransaction 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 flowTx) { + boolean deleteSmac, TypedReadWriteTransaction flowTx) + throws ExecutionException, InterruptedException { String elanInstanceName = elanInfo.getElanInstanceName(); List 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 flowTx) { + TypedReadWriteTransaction 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 flowTx) { + TypedReadWriteTransaction 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 flowTx) { + boolean deleteSmac, TypedReadWriteTransaction 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); } diff --git a/natservice/api/src/main/java/org/opendaylight/netvirt/natservice/api/SnatServiceListener.java b/natservice/api/src/main/java/org/opendaylight/netvirt/natservice/api/SnatServiceListener.java index 1fbfc0a2d7..8fed4756fa 100644 --- a/natservice/api/src/main/java/org/opendaylight/netvirt/natservice/api/SnatServiceListener.java +++ b/natservice/api/src/main/java/org/opendaylight/netvirt/natservice/api/SnatServiceListener.java @@ -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 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 confTx, Routers routers, BigInteger primarySwitchId, - BigInteger dpnId); + BigInteger dpnId) throws ExecutionException, InterruptedException; } diff --git a/natservice/api/src/main/java/org/opendaylight/netvirt/natservice/api/SnatServiceManager.java b/natservice/api/src/main/java/org/opendaylight/netvirt/natservice/api/SnatServiceManager.java index abc1aac47d..0154516c59 100644 --- a/natservice/api/src/main/java/org/opendaylight/netvirt/natservice/api/SnatServiceManager.java +++ b/natservice/api/src/main/java/org/opendaylight/netvirt/natservice/api/SnatServiceManager.java @@ -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 confTx, - Routers router, BigInteger primarySwitchId, BigInteger dpnId, Action action); + Routers router, BigInteger primarySwitchId, BigInteger dpnId, Action action) + throws ExecutionException, InterruptedException; } diff --git a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/ha/SnatCentralizedSwitchChangeListener.java b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/ha/SnatCentralizedSwitchChangeListener.java index cdf598d4a8..aa6940248c 100644 --- a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/ha/SnatCentralizedSwitchChangeListener.java +++ b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/ha/SnatCentralizedSwitchChangeListener.java @@ -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 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, diff --git a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/AbstractSnatService.java b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/AbstractSnatService.java index 3615ccb4a6..6358b14034 100644 --- a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/AbstractSnatService.java +++ b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/AbstractSnatService.java @@ -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 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 switches = naptSwitchSelector.getDpnsForVpn(routerName); @@ -209,7 +208,7 @@ public abstract class AbstractSnatService implements SnatServiceListener { @Override public boolean removeSnat(TypedReadWriteTransaction 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 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 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 confTx, - Routers routers, BigInteger dpnId); + Routers routers, BigInteger dpnId) throws ExecutionException, InterruptedException; protected abstract void addSnatSpecificEntriesForNonNaptSwitch(TypedReadWriteTransaction confTx, Routers routers, BigInteger dpnId); @@ -325,8 +324,7 @@ public abstract class AbstractSnatService implements SnatServiceListener { } protected void removeInboundFibEntry(TypedReadWriteTransaction 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 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 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 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 confTx, BigInteger dpId, short tableId, - String flowId, int priority, String flowName, BigInteger cookie, List matches, - List 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 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 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) { diff --git a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/ConntrackBasedSnatService.java b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/ConntrackBasedSnatService.java index 85b5361eb9..3a66f86828 100644 --- a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/ConntrackBasedSnatService.java +++ b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/ConntrackBasedSnatService.java @@ -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 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 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 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 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 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 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 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 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); diff --git a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/EvpnDnatFlowProgrammer.java b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/EvpnDnatFlowProgrammer.java index 3b0cec734e..de5bab6bca 100644 --- a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/EvpnDnatFlowProgrammer.java +++ b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/EvpnDnatFlowProgrammer.java @@ -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 confTx) { + private void removeTunnelTableEntry(BigInteger dpnId, long l3Vni, TypedReadWriteTransaction 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); } diff --git a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/EvpnNaptSwitchHA.java b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/EvpnNaptSwitchHA.java index 8032f5ddb7..9ce1fe8835 100644 --- a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/EvpnNaptSwitchHA.java +++ b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/EvpnNaptSwitchHA.java @@ -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 confTx) { + BigInteger naptSwitch, TypedReadWriteTransaction 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) { diff --git a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/EvpnSnatFlowProgrammer.java b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/EvpnSnatFlowProgrammer.java index a283d45d31..d06176485c 100644 --- a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/EvpnSnatFlowProgrammer.java +++ b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/EvpnSnatFlowProgrammer.java @@ -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 confTx) { + public void removeTunnelTableEntry(BigInteger dpnId, long l3Vni, TypedReadWriteTransaction 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); } diff --git a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/ExternalNetworksChangeListener.java b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/ExternalNetworksChangeListener.java index 844b3878dc..d6421e2e3a 100644 --- a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/ExternalNetworksChangeListener.java +++ b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/ExternalNetworksChangeListener.java @@ -155,7 +155,8 @@ public class ExternalNetworksChangeListener } } - private void associateExternalNetworkWithVPN(Networks network, TypedReadWriteTransaction confTx) { + private void associateExternalNetworkWithVPN(Networks network, TypedReadWriteTransaction confTx) + throws ExecutionException, InterruptedException { List routerIds = network.getRouterIds(); for (Uuid routerId : routerIds) { //long router = NatUtil.getVpnId(dataBroker, routerId.getValue()); diff --git a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/ExternalRoutersListener.java b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/ExternalRoutersListener.java index b26a36d6c9..bf52adda1b 100644 --- a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/ExternalRoutersListener.java +++ b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/ExternalRoutersListener.java @@ -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 confTx) { + Uuid bgpVpnUuid, boolean create, TypedReadWriteTransaction 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 confTx) { + TypedReadWriteTransaction confTx) throws ExecutionException, InterruptedException { List 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 confTx) { + long bgpVpnId, TypedReadWriteTransaction confTx) + throws ExecutionException, InterruptedException { List 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 externalIps, boolean routerFlag, String vpnName, BigInteger naptSwitchDpnId, long routerId, TypedReadWriteTransaction removeFlowInvTx) { @@ -1800,32 +1799,27 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase 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 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 externalIps, Collection externalSubnetList, TypedReadWriteTransaction 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 intextIpProtocolTypes = ipPortMapping.getIntextIpProtocolType(); - for (IntextIpProtocolType intextIpProtocolType : intextIpProtocolTypes) { - List 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 intextIpProtocolTypes = ipPortMapping.getIntextIpProtocolType(); + for (IntextIpProtocolType intextIpProtocolType : intextIpProtocolTypes) { + List 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 externalIps, - TypedReadWriteTransaction writeFlowInvTx) { + TypedReadWriteTransaction 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 writeFlowInvTx) { + TypedReadWriteTransaction 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 removeFlowInvTx) { + BigInteger naptSwitchDpnId, TypedReadWriteTransaction 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 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 externalIps, String vpnName, - String extGwMacAddress, TypedReadWriteTransaction confTx) { + String extGwMacAddress, TypedReadWriteTransaction 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 removeFlowInvTx) { + TypedReadWriteTransaction 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 removeFlowInvTx) { + TypedReadWriteTransaction 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 removeFlowInvTx) { + TypedReadWriteTransaction 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 externalIps, String vpnName, String extGwMacAddress, - TypedReadWriteTransaction writeFlowInvTx) { + TypedReadWriteTransaction 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 writeFlowInvTx) { + TypedReadWriteTransaction writeFlowInvTx) throws ExecutionException, InterruptedException { LOG.info("removeTunnelTableEntry : called with DpnId = {} and label = {}", dpnId, serviceId); - List 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 writeFlowInvTx) { - List matches = new ArrayList<>(); - matches.add(MatchEthernetType.MPLS_UNICAST); - matches.add(new MatchMplsLabel(serviceId)); - + TypedReadWriteTransaction 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); } diff --git a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/FlatVlanConntrackBasedSnatService.java b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/FlatVlanConntrackBasedSnatService.java index 887788f475..cb0b7f2d69 100644 --- a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/FlatVlanConntrackBasedSnatService.java +++ b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/FlatVlanConntrackBasedSnatService.java @@ -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 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 confTx, Routers routers, - BigInteger primarySwitchId, BigInteger dpnId) { + BigInteger primarySwitchId, BigInteger dpnId) throws ExecutionException, InterruptedException { return !checkProviderType(confTx, routers) && super.removeSnat(confTx, routers, primarySwitchId, dpnId); } diff --git a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/FloatingIPListener.java b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/FloatingIPListener.java index c0b45ecfce..2909fac1b7 100644 --- a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/FloatingIPListener.java +++ b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/FloatingIPListener.java @@ -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 confTx) { - try { - FlowEntity preFlowEntity = buildPreDNATDeleteFlowEntity(dpnId, externalIp, routerId); - mdsalManager.removeFlow(confTx, preFlowEntity); + TypedReadWriteTransaction 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 removeFlowInvTx) { - try { - FlowEntity preFlowEntity = buildPreSNATDeleteFlowEntity(dpnId, internalIp, routerId); - mdsalManager.removeFlow(removeFlowInvTx, preFlowEntity); + TypedReadWriteTransaction 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 portIid, final String routerName, - TypedReadWriteTransaction confTx) { + TypedReadWriteTransaction 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 confTx) { + InternalToExternalPortMap mapping, TypedReadWriteTransaction 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 portIid, final String routerName, BigInteger dpnId, - TypedReadWriteTransaction removeFlowInvTx) { + TypedReadWriteTransaction 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 confTx) { + InternalToExternalPortMap mapping, TypedReadWriteTransaction 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 confTx, boolean create) { + TypedReadWriteTransaction confTx, boolean create) + throws ExecutionException, InterruptedException { if (confTx == null) { ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, newTx -> addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, newTx, create)), LOG, diff --git a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NaptSwitchHA.java b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NaptSwitchHA.java index f0fe1d71e1..1a052370de 100644 --- a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NaptSwitchHA.java +++ b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NaptSwitchHA.java @@ -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 externalIpmap, - TypedReadWriteTransaction confTx) { + TypedReadWriteTransaction 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 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 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 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 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 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 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 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 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 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 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 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 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 externalIpCache, - TypedReadWriteTransaction confTx) { + TypedReadWriteTransaction 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 externalIpCache, boolean isClearBgpRts, - TypedReadWriteTransaction confTx) { + TypedReadWriteTransaction 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 externalIpLabel, - TypedReadWriteTransaction confTx) { + TypedReadWriteTransaction confTx) + throws ExecutionException, InterruptedException { Collection newExternalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerId); if (externalIpsCache != null) { Set removedExternalIps = new HashSet<>(externalIpsCache); diff --git a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NatEvpnUtil.java b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NatEvpnUtil.java index 5cdaa7bf27..0044863561 100644 --- a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NatEvpnUtil.java +++ b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NatEvpnUtil.java @@ -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 confTx) { + IMdsalApiManager mdsalManager, TypedReadWriteTransaction confTx) + throws ExecutionException, InterruptedException { List 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); } diff --git a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NatTunnelInterfaceStateListener.java b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NatTunnelInterfaceStateListener.java index 5df13fae32..915eaa0950 100644 --- a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NatTunnelInterfaceStateListener.java +++ b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NatTunnelInterfaceStateListener.java @@ -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 writeFlowInvTx) { + String destTepIp, TypedReadWriteTransaction 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 writeFlowInvTx) { + String destTepIp, TypedReadWriteTransaction 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 writeFlowInvTx) { + ProviderTypes extNwProvType, TypedReadWriteTransaction 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 confTx) { + String srcTepIp, String destTepIp, String tunnelName, ProviderTypes extNwProvType, + TypedReadWriteTransaction 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 diff --git a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NatUtil.java b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NatUtil.java index 7690c0c7ae..c5dcdef7e4 100644 --- a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NatUtil.java +++ b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NatUtil.java @@ -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 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) { diff --git a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/RouterDpnChangeListener.java b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/RouterDpnChangeListener.java index ff84a60fcd..3e7131a47d 100644 --- a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/RouterDpnChangeListener.java +++ b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/RouterDpnChangeListener.java @@ -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 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); } } diff --git a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/RouterToVpnListener.java b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/RouterToVpnListener.java index 27f48ebadb..68341c7466 100644 --- a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/RouterToVpnListener.java +++ b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/RouterToVpnListener.java @@ -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 routerPortsId = NatUtil.getRouterPortsId(routerName); Optional 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 routerPortsId = NatUtil.getRouterPortsId(routerName); Optional optRouterPorts = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId); diff --git a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/SNATDefaultRouteProgrammer.java b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/SNATDefaultRouteProgrammer.java index c5da04cd17..be6a548e96 100644 --- a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/SNATDefaultRouteProgrammer.java +++ b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/SNATDefaultRouteProgrammer.java @@ -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 confTx) { + void removeDefNATRouteInDPN(BigInteger dpnId, long vpnId, TypedReadWriteTransaction 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 confTx) { + TypedReadWriteTransaction 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) { diff --git a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/SnatServiceManagerImpl.java b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/SnatServiceManagerImpl.java index 2e90cb1d34..a0275b1d7c 100644 --- a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/SnatServiceManagerImpl.java +++ b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/SnatServiceManagerImpl.java @@ -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 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) { diff --git a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/VpnFloatingIpHandler.java b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/VpnFloatingIpHandler.java index 30f2b3ecf2..8faf3ae21e 100644 --- a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/VpnFloatingIpHandler.java +++ b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/VpnFloatingIpHandler.java @@ -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 confTx) { + TypedReadWriteTransaction 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 confTx) { + TypedReadWriteTransaction 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); diff --git a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/VxlanGreConntrackBasedSnatService.java b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/VxlanGreConntrackBasedSnatService.java index 9cc0298dc9..e58a8ca9e6 100644 --- a/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/VxlanGreConntrackBasedSnatService.java +++ b/natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/VxlanGreConntrackBasedSnatService.java @@ -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 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 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 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 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 confTx, BigInteger dpnId, - long routerId, List externalIps) { + long routerId, List 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 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 confTx, BigInteger dpnId, - long routerId, List externalIps) { + long routerId, List 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 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 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); diff --git a/vpnmanager/api/src/main/java/org/opendaylight/netvirt/vpnmanager/api/IVpnManager.java b/vpnmanager/api/src/main/java/org/opendaylight/netvirt/vpnmanager/api/IVpnManager.java index 83413493c6..52a6815e86 100644 --- a/vpnmanager/api/src/main/java/org/opendaylight/netvirt/vpnmanager/api/IVpnManager.java +++ b/vpnmanager/api/src/main/java/org/opendaylight/netvirt/vpnmanager/api/IVpnManager.java @@ -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 confTx); + BigInteger dpnId, TypedWriteTransaction 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 confTx); + BigInteger dpnId, TypedReadWriteTransaction 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 confTx); + String subnetVpnName, TypedWriteTransaction 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 confTx); + String subnetVpnName, TypedReadWriteTransaction confTx) + throws ExecutionException, InterruptedException; @Deprecated void addArpResponderFlowsToExternalNetworkIps(String id, Collection fixedIps, String macAddress, diff --git a/vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/CentralizedSwitchChangeListener.java b/vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/CentralizedSwitchChangeListener.java index 689096940d..c8367f09a1 100644 --- a/vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/CentralizedSwitchChangeListener.java +++ b/vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/CentralizedSwitchChangeListener.java @@ -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()); diff --git a/vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnManagerImpl.java b/vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnManagerImpl.java index 43e55e2897..aa5bb32e17 100644 --- a/vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnManagerImpl.java +++ b/vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnManagerImpl.java @@ -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 confTx) { + BigInteger dpnId, TypedWriteTransaction 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 confTx) { + BigInteger dpnId, TypedReadWriteTransaction 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 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 confTx) { + String subnetVpnName, TypedWriteTransaction 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 confTx) { + String subnetVpnName, TypedReadWriteTransaction 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 consumer, String operation) { + InterruptibleCheckedConsumer 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); -- 2.36.6