Datastore txes: natservice, part 2 49/73849/2
authorStephen Kitt <skitt@redhat.com>
Mon, 9 Jul 2018 15:15:56 +0000 (17:15 +0200)
committerSam Hague <shague@redhat.com>
Mon, 9 Jul 2018 20:21:02 +0000 (20:21 +0000)
This switches the remaining managed transactions to
datastore-contrained transactions, apart from transactions which
involve VpnManager (which isn’t ready yet).

JIRA: NETVIRT-1342
Change-Id: I560a0b2cf0ca012239a0b1759e6a9706ac4357f1
Signed-off-by: Stephen Kitt <skitt@redhat.com>
19 files changed:
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/ha/WeightedCentralizedSwitchScheduler.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/EvpnDnatFlowProgrammer.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/EvpnNaptSwitchHA.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/EvpnSnatFlowProgrammer.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/ExternalNetworksChangeListener.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/ExternalRoutersListener.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/FloatingIPHandler.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/FloatingIPListener.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NaptSwitchHA.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NatEvpnUtil.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NatInterfaceStateChangeListener.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NatRouterInterfaceListener.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NatTunnelInterfaceStateListener.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/NatUtil.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/RouterDpnChangeListener.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/RouterToVpnListener.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/SNATDefaultRouteProgrammer.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/VpnFloatingIpHandler.java
natservice/impl/src/main/java/org/opendaylight/netvirt/natservice/internal/VxlanGreConntrackBasedSnatService.java

index 5524771ce6424a17c5f4fdd11cdccca8c1bf154f..dd33e2fd660cce5d591e7ca229ee08fb9caec306 100644 (file)
@@ -8,13 +8,18 @@
 
 package org.opendaylight.netvirt.natservice.ha;
 
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+
 import java.math.BigInteger;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -118,26 +123,35 @@ public class WeightedCentralizedSwitchScheduler implements CentralizedSwitchSche
             LOG.debug("addToDpnMaps no subnets associated with {}", routerName);
             return;
         }
-        ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(tx -> {
-            for (Uuid subnetUuid : addedSubnetIds) {
-                String primaryRd = NatUtil.getPrimaryRd(routerName, tx);
-                Subnetmap subnetMapEntry = tx.read(LogicalDatastoreType.CONFIGURATION,
-                        getSubnetMapIdentifier(subnetUuid)).checkedGet().orNull();
-                Uuid routerPortUuid = subnetMapEntry.getRouterInterfacePortId();
-                subnetIdToRouterPortMap.put(subnetUuid.getValue(), routerPortUuid.getValue());
-                vpnFootprintService.updateVpnToDpnMapping(primarySwitchId, routerName, primaryRd,
-                        routerPortUuid.getValue(), null, true);
-                NatUtil.addToNeutronRouterDpnsMap(dataBroker, routerName, routerPortUuid.getValue(),
-                        primarySwitchId, tx);
-                NatUtil.addToDpnRoutersMap(dataBroker, routerName, routerPortUuid.getValue(),
-                        primarySwitchId, tx);
-                if (subnetMapEntry.getNetworkType().equals(NetworkAttributes.NetworkType.VLAN)) {
-                    String elanInstanceName = subnetMapEntry.getNetworkId().getValue();
-                    subnetIdToElanInstanceMap.put(subnetUuid.getValue(), elanInstanceName);
-                    NatUtil.addPseudoPortToElanDpn(elanInstanceName, elanInstanceName, primarySwitchId, dataBroker);
+        Map<Uuid, Subnetmap> subnetMapEntries = new HashMap<>();
+        try {
+            String primaryRd = txRunner.applyWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
+                for (Uuid subnetUuid : addedSubnetIds) {
+                    Subnetmap subnetMapEntry = tx.read(getSubnetMapIdentifier(subnetUuid)).get().orNull();
+                    subnetMapEntries.put(subnetUuid, subnetMapEntry);
+                    Uuid routerPortUuid = subnetMapEntry.getRouterInterfacePortId();
+                    subnetIdToRouterPortMap.put(subnetUuid.getValue(), routerPortUuid.getValue());
                 }
-            }
-        }), LOG, "Error adding subnets to DPN maps for {}", routerName);
+                return NatUtil.getPrimaryRd(routerName, tx);
+            }).get();
+            ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, tx -> {
+                for (Uuid subnetUuid : addedSubnetIds) {
+                    Subnetmap subnetMapEntry = subnetMapEntries.get(subnetUuid);
+                    Uuid routerPortUuid = subnetMapEntry.getRouterInterfacePortId();
+                    vpnFootprintService.updateVpnToDpnMapping(primarySwitchId, routerName, primaryRd,
+                            routerPortUuid.getValue(), null, true);
+                    NatUtil.addToNeutronRouterDpnsMap(routerName, routerPortUuid.getValue(), primarySwitchId, tx);
+                    NatUtil.addToDpnRoutersMap(routerName, routerPortUuid.getValue(), primarySwitchId, tx);
+                    if (subnetMapEntry.getNetworkType().equals(NetworkAttributes.NetworkType.VLAN)) {
+                        String elanInstanceName = subnetMapEntry.getNetworkId().getValue();
+                        subnetIdToElanInstanceMap.put(subnetUuid.getValue(), elanInstanceName);
+                        NatUtil.addPseudoPortToElanDpn(elanInstanceName, elanInstanceName, primarySwitchId, dataBroker);
+                    }
+                }
+            }), LOG, "Error adding subnets to DPN maps for {}", routerName);
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("Error adding subnets to DPN maps for {}", routerName);
+        }
     }
 
 
@@ -147,25 +161,30 @@ public class WeightedCentralizedSwitchScheduler implements CentralizedSwitchSche
             LOG.debug("deleteFromDpnMaps no subnets associated with {}", routerName);
             return;
         }
-        ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(tx -> {
-            String primaryRd = NatUtil.getPrimaryRd(routerName, tx);
-            for (Uuid subnetUuid : deletedSubnetIds) {
-                String routerPort = subnetIdToRouterPortMap.remove(subnetUuid.getValue());
-                if (routerPort == null) {
-                    LOG.error("The router port was not found for {}", subnetUuid.getValue());
-                    continue;
-                }
-                vpnFootprintService.updateVpnToDpnMapping(primarySwitchId, routerName, primaryRd,
-                        routerPort, null, false);
-                NatUtil.removeFromNeutronRouterDpnsMap(dataBroker, routerName, primarySwitchId, tx);
-                NatUtil.removeFromDpnRoutersMap(dataBroker, routerName, routerName, interfaceManager, tx);
-                if (subnetIdToElanInstanceMap.containsKey(subnetUuid.getValue())) {
-                    String elanInstanceName = subnetIdToElanInstanceMap.remove(subnetUuid.getValue());
-                    NatUtil.removePseudoPortFromElanDpn(elanInstanceName, elanInstanceName, primarySwitchId,
-                            dataBroker);
+        try {
+            String primaryRd = txRunner.applyWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
+                tx -> NatUtil.getPrimaryRd(routerName, tx)).get();
+            ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, tx -> {
+                for (Uuid subnetUuid : deletedSubnetIds) {
+                    String routerPort = subnetIdToRouterPortMap.remove(subnetUuid.getValue());
+                    if (routerPort == null) {
+                        LOG.error("The router port was not found for {}", subnetUuid.getValue());
+                        continue;
+                    }
+                    vpnFootprintService.updateVpnToDpnMapping(primarySwitchId, routerName, primaryRd,
+                            routerPort, null, false);
+                    NatUtil.removeFromNeutronRouterDpnsMap(routerName, primarySwitchId, tx);
+                    NatUtil.removeFromDpnRoutersMap(dataBroker, routerName, routerName, interfaceManager, tx);
+                    if (subnetIdToElanInstanceMap.containsKey(subnetUuid.getValue())) {
+                        String elanInstanceName = subnetIdToElanInstanceMap.remove(subnetUuid.getValue());
+                        NatUtil.removePseudoPortFromElanDpn(elanInstanceName, elanInstanceName, primarySwitchId,
+                                dataBroker);
+                    }
                 }
-            }
-        }), LOG, "Error deleting subnets from DPN maps for {}", routerName);
+            }), LOG, "Error deleting subnets from DPN maps for {}", routerName);
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("Error deleting subnets from DPN maps for {}", routerName, e);
+        }
     }
 
     @Override
index 92a1f72f3156badebc874d77a708d9877b08a095..0ad7649db5311767950130af8adcb81535eb4648 100644 (file)
@@ -8,6 +8,10 @@
 
 package org.opendaylight.netvirt.natservice.internal;
 
+import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
@@ -21,11 +25,13 @@ import javax.annotation.Nonnull;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
+import org.opendaylight.genius.infra.Datastore.Configuration;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
 import org.opendaylight.genius.mdsalutil.ActionInfo;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
 import org.opendaylight.genius.mdsalutil.MatchInfo;
@@ -109,7 +115,7 @@ public class EvpnDnatFlowProgrammer {
                                 final String floatingIpInterface,
                                 final String floatingIpPortMacAddress,
                                 final String rd,
-                                final String nextHopIp, final WriteTransaction writeFlowInvTx) {
+                                final String nextHopIp, final TypedReadWriteTransaction<Configuration> confTx) {
     /*
      *  1) Install the flow INTERNAL_TUNNEL_TABLE (table=36)-> PDNAT_TABLE (table=25) (SNAT VM on DPN1 is
      *     responding back to FIP VM on DPN2) {SNAT to DNAT traffic on different Hypervisor}
@@ -138,8 +144,7 @@ public class EvpnDnatFlowProgrammer {
         String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
         //Inform to FIB and BGP
         NatEvpnUtil.addRoutesForVxLanProvType(dataBroker, bgpManager, fibManager, vpnName, rd, fibExternalIp,
-                nextHopIp, l3Vni, floatingIpInterface, floatingIpPortMacAddress,
-                writeFlowInvTx, RouteOrigin.STATIC, dpnId);
+                nextHopIp, l3Vni, floatingIpInterface, floatingIpPortMacAddress, confTx, RouteOrigin.STATIC, dpnId);
 
         /* Install the flow table L3_FIB_TABLE (table=21)-> PDNAT_TABLE (table=25)
          * (SNAT to DNAT reverse traffic: If the DPN has both SNAT and  DNAT configured )
@@ -178,27 +183,34 @@ public class EvpnDnatFlowProgrammer {
             @Override
             public void onSuccess(@Nonnull RpcResult<CreateFibEntryOutput> result) {
                 if (result.isSuccessful()) {
-                    LOG.info("onAddFloatingIp : Successfully installed custom FIB routes for Floating "
-                            + "IP Prefix {} on DPN {}", externalIp, dpnId);
-                    List<Instruction> instructions = new ArrayList<>();
-                    List<ActionInfo> actionsInfos = new ArrayList<>();
-                    List<Instruction> customInstructions = new ArrayList<>();
-                    customInstructions.add(new InstructionGotoTable(NwConstants.PDNAT_TABLE).buildInstruction(0));
-                    actionsInfos.add(new ActionNxResubmit(NwConstants.PDNAT_TABLE));
-                    instructions.add(new InstructionApplyActions(actionsInfos).buildInstruction(0));
-                 /* If more than one floatingIp is available in vpn-to-dpn-list for given dpn id, do not call for
-                  * installing INTERNAL_TUNNEL_TABLE (table=36) -> PDNAT_TABLE (table=25) flow entry with same tunnel_id
-                  * again and again.
-                  */
-                    if (!NatUtil.isFloatingIpPresentForDpn(dataBroker, dpnId, rd, vpnName, externalIp, true)) {
-                        makeTunnelTableEntry(dpnId, finalL3Vni, instructions, writeFlowInvTx);
-                    }
-                 /* Install the flow L3_GW_MAC_TABLE (table=19)-> PDNAT_TABLE (table=25)
-                  * (DNAT reverse traffic: If the traffic is Initiated from DC-GW to FIP VM (DNAT forward traffic))
-                  */
-                    NatEvpnUtil.makeL3GwMacTableEntry(dpnId, vpnId, floatingIpPortMacAddress, customInstructions,
-                            mdsalManager, writeFlowInvTx);
-                    NatUtil.waitForTransactionToComplete(writeFlowInvTx);
+                    ListenableFutures.addErrorLogging(
+                        txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, innerConfTx -> {
+                            LOG.info("onAddFloatingIp : Successfully installed custom FIB routes for Floating "
+                                + "IP Prefix {} on DPN {}", externalIp, dpnId);
+                            List<Instruction> instructions = new ArrayList<>();
+                            List<ActionInfo> actionsInfos = new ArrayList<>();
+                            List<Instruction> customInstructions = new ArrayList<>();
+                            customInstructions.add(
+                                new InstructionGotoTable(NwConstants.PDNAT_TABLE).buildInstruction(0));
+                            actionsInfos.add(new ActionNxResubmit(NwConstants.PDNAT_TABLE));
+                            instructions.add(new InstructionApplyActions(actionsInfos).buildInstruction(0));
+                            /* If more than one floatingIp is available in vpn-to-dpn-list for given dpn id, do not
+                            call for
+                             * installing INTERNAL_TUNNEL_TABLE (table=36) -> PDNAT_TABLE (table=25) flow entry with
+                             * same tunnel_id
+                             * again and again.
+                             */
+                            if (!NatUtil.isFloatingIpPresentForDpn(dataBroker, dpnId, rd, vpnName, externalIp, true)) {
+                                makeTunnelTableEntry(dpnId, finalL3Vni, instructions, innerConfTx);
+                            }
+                            /* Install the flow L3_GW_MAC_TABLE (table=19)-> PDNAT_TABLE (table=25)
+                             * (DNAT reverse traffic: If the traffic is Initiated from DC-GW to FIP VM (DNAT forward
+                             * traffic))
+                             */
+                            NatEvpnUtil.makeL3GwMacTableEntry(dpnId, vpnId, floatingIpPortMacAddress,
+                                customInstructions,
+                                mdsalManager, innerConfTx);
+                        }), LOG, "Error installing DNAT flows");
                 } else {
                     LOG.error("onAddFloatingIp : Error {} in rpc call to create custom Fib entries for Floating "
                             + "IP Prefix {} on DPN {}", result.getErrors(), externalIp, dpnId);
@@ -212,7 +224,7 @@ public class EvpnDnatFlowProgrammer {
                 SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
                         LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
         if (optionalVpnInterface.isPresent()) {
-            ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+            ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> {
                 for (VpnInstanceNames vpnInstance : optionalVpnInterface.get().getVpnInstanceNames()) {
                     if (!vpnName.equals(vpnInstance.getVpnName())) {
                         continue;
@@ -239,8 +251,7 @@ public class EvpnDnatFlowProgrammer {
                             floatingIpInterface);
                     InstanceIdentifier<VpnInterfaceOpDataEntry> vpnIfIdentifierOpDataEntry =
                             NatUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
-                    tx.put(LogicalDatastoreType.OPERATIONAL, vpnIfIdentifierOpDataEntry,
-                            vpnIfOpDataEntryBuilder.build(), WriteTransaction.CREATE_MISSING_PARENTS);
+                    tx.put(vpnIfIdentifierOpDataEntry, vpnIfOpDataEntryBuilder.build(), CREATE_MISSING_PARENTS);
                     break;
                 }
             }), LOG, "onAddFloatingIp : Could not write Interface {}, vpnName {}", interfaceName, vpnName);
@@ -252,7 +263,7 @@ public class EvpnDnatFlowProgrammer {
 
     public void onRemoveFloatingIp(final BigInteger dpnId, final String vpnName, final String externalIp,
                                    final String floatingIpInterface, final String floatingIpPortMacAddress,
-                                   final long routerId, WriteTransaction removeFlowInvTx) {
+                                   final long routerId, TypedReadWriteTransaction<Configuration> confTx) {
     /*
      *  1) Remove the flow INTERNAL_TUNNEL_TABLE (table=36)-> PDNAT_TABLE (table=25) (SNAT VM on DPN1 is
      *     responding back to FIP VM on DPN2) {SNAT to DNAT traffic on different Hypervisor}
@@ -303,20 +314,22 @@ public class EvpnDnatFlowProgrammer {
             @Override
             public void onSuccess(@Nonnull RpcResult<RemoveFibEntryOutput> result) {
                 if (result.isSuccessful()) {
-                    LOG.info("onRemoveFloatingIp : Successfully removed custom FIB routes for Floating "
-                            + "IP Prefix {} on DPN {}", externalIp, dpnId);
-                     /*  check if any floating IP information is available in vpn-to-dpn-list for given dpn id.
-                      *  If exist any floating IP then do not remove
-                      *  INTERNAL_TUNNEL_TABLE (table=36) -> PDNAT_TABLE (table=25) flow entry.
-                      */
-                    if (!NatUtil.isFloatingIpPresentForDpn(dataBroker, dpnId, rd, vpnName, externalIp, false)) {
-                        //Remove the flow for INTERNAL_TUNNEL_TABLE (table=36)-> PDNAT_TABLE (table=25)
-                        removeTunnelTableEntry(dpnId, finalL3Vni, removeFlowInvTx);
-                    }
-                    //Remove the flow for L3_GW_MAC_TABLE (table=19)-> PDNAT_TABLE (table=25)
-                    NatEvpnUtil.removeL3GwMacTableEntry(dpnId, vpnId, floatingIpPortMacAddress, mdsalManager,
-                            removeFlowInvTx);
-                    NatUtil.waitForTransactionToComplete(removeFlowInvTx);
+                    ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
+                        innerConfTx -> {
+                            LOG.info("onRemoveFloatingIp : Successfully removed custom FIB routes for Floating "
+                                + "IP Prefix {} on DPN {}", externalIp, dpnId);
+                            /*  check if any floating IP information is available in vpn-to-dpn-list for given dpn id.
+                             *  If exist any floating IP then do not remove
+                             *  INTERNAL_TUNNEL_TABLE (table=36) -> PDNAT_TABLE (table=25) flow entry.
+                             */
+                            if (!NatUtil.isFloatingIpPresentForDpn(dataBroker, dpnId, rd, vpnName, externalIp, false)) {
+                                //Remove the flow for INTERNAL_TUNNEL_TABLE (table=36)-> PDNAT_TABLE (table=25)
+                                removeTunnelTableEntry(dpnId, finalL3Vni, innerConfTx);
+                            }
+                            //Remove the flow for L3_GW_MAC_TABLE (table=19)-> PDNAT_TABLE (table=25)
+                            NatEvpnUtil.removeL3GwMacTableEntry(dpnId, vpnId, floatingIpPortMacAddress, mdsalManager,
+                                innerConfTx);
+                        }), LOG, "Error removing flows");
                 } else {
                     LOG.error("onRemoveFloatingIp : Error {} in rpc call to remove custom Fib entries for Floating "
                             + "IP Prefix {} on DPN {}", result.getErrors(), externalIp, dpnId);
@@ -329,14 +342,14 @@ public class EvpnDnatFlowProgrammer {
                 SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
                         LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
         if (optionalVpnInterface.isPresent()) {
-            ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+            ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> {
                 for (VpnInstanceNames vpnInstance : optionalVpnInterface.get().getVpnInstanceNames()) {
                     if (!vpnName.equals(vpnInstance.getVpnName())) {
                         continue;
                     }
                     InstanceIdentifier<VpnInterfaceOpDataEntry> vpnOpIfIdentifier = NatUtil
                             .getVpnInterfaceOpDataEntryIdentifier(floatingIpInterface, vpnName);
-                    tx.delete(LogicalDatastoreType.OPERATIONAL, vpnOpIfIdentifier);
+                    tx.delete(vpnOpIfIdentifier);
                     break;
                 }
             }), LOG, "onRemoveFloatingIp : Could not remove vpnInterface {}, vpnName {} from Operational "
@@ -351,7 +364,7 @@ public class EvpnDnatFlowProgrammer {
     }
 
     private void makeTunnelTableEntry(BigInteger dpnId, long l3Vni, List<Instruction> customInstructions,
-                                      WriteTransaction writeFlowInvTx) {
+                                      TypedWriteTransaction<Configuration> confTx) {
         LOG.debug("makeTunnelTableEntry : Create terminating service table {} --> table {} flow on DpnId {} "
                 + "with l3Vni {} as matching parameter", NwConstants.INTERNAL_TUNNEL_TABLE, NwConstants.PDNAT_TABLE,
                 dpnId, l3Vni);
@@ -361,12 +374,12 @@ 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, customInstructions);
-        mdsalManager.addFlowToTx(dpnId, terminatingServiceTableFlowEntity, writeFlowInvTx);
+        mdsalManager.addFlow(confTx, dpnId, terminatingServiceTableFlowEntity);
         LOG.debug("makeTunnelTableEntry : Successfully installed terminating service table flow {} on DpnId {}",
                 terminatingServiceTableFlowEntity, dpnId);
     }
 
-    private void removeTunnelTableEntry(BigInteger dpnId, long l3Vni, WriteTransaction removeFlowInvTx) {
+    private void removeTunnelTableEntry(BigInteger dpnId, long l3Vni, TypedReadWriteTransaction<Configuration> confTx) {
         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);
@@ -376,7 +389,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);
-        mdsalManager.removeFlowToTx(dpnId, flowEntity, removeFlowInvTx);
+        mdsalManager.removeFlow(confTx, dpnId, flowEntity);
         LOG.debug("removeTunnelTableEntry : Successfully removed terminating service table flow {} on DpnId {}",
                 flowEntity, dpnId);
     }
index 9abbbe00e555201633646c43520e9bfcfd91d45b..5c27a1baa3c8a1acd1d5d26bde791cbf79f2c7d5 100644 (file)
@@ -13,7 +13,8 @@ import java.math.BigInteger;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.genius.infra.Datastore.Configuration;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
 import org.opendaylight.genius.mdsalutil.FlowEntity;
 import org.opendaylight.genius.mdsalutil.NwConstants;
 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
@@ -41,7 +42,7 @@ public class EvpnNaptSwitchHA {
     }
 
     public void evpnRemoveSnatFlowsInOldNaptSwitch(String routerName, long routerId, String vpnName,
-                                                   BigInteger naptSwitch, WriteTransaction removeFlowInvTx) {
+            BigInteger naptSwitch, TypedReadWriteTransaction<Configuration> confTx) {
         //Handling VXLAN Provider type flow removal from old NAPT switch
         Long vpnId = NatUtil.getNetworkVpnIdFromRouterId(dataBroker, routerId);
         if (vpnId == NatConstants.INVALID_ID) {
@@ -67,10 +68,10 @@ public class EvpnNaptSwitchHA {
             return;
         }
         //Remove the L3_GW_MAC_TABLE which forwards the packet to Inbound NAPT Table (table19->44)
-        NatEvpnUtil.removeL3GwMacTableEntry(naptSwitch, vpnId, gwMacAddress, mdsalManager, removeFlowInvTx);
+        NatEvpnUtil.removeL3GwMacTableEntry(naptSwitch, vpnId, gwMacAddress, mdsalManager, confTx);
 
         //Remove the PDNAT_TABLE which forwards the packet to Inbound NAPT Table (table25->44)
-        NatUtil.removePreDnatToSnatTableEntry(mdsalManager, naptSwitch, removeFlowInvTx);
+        NatUtil.removePreDnatToSnatTableEntry(confTx, mdsalManager, naptSwitch);
 
         //Remove the PSNAT_TABLE which forwards the packet to Outbound NAPT Table (table26->46)
         String flowRef = getFlowRefSnat(naptSwitch, NwConstants.PSNAT_TABLE, routerName);
@@ -78,13 +79,13 @@ 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);
-        mdsalManager.removeFlowToTx(flowEntity, removeFlowInvTx);
+        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 {} "
                 + "for the old napt switch with the DPN ID {} and router ID {}",
                 NwConstants.INTERNAL_TUNNEL_TABLE, naptSwitch, routerId);
-        evpnSnatFlowProgrammer.removeTunnelTableEntry(naptSwitch, l3Vni, removeFlowInvTx);
+        evpnSnatFlowProgrammer.removeTunnelTableEntry(naptSwitch, l3Vni, confTx);
 
         //Remove the INTERNAL_TUNNEL_TABLE entry which forwards the packet to Outbound NAPT Table (table36->46)
         long tunnelId = NatEvpnUtil.getTunnelIdForRouter(idManager, dataBroker, routerName, routerId);
@@ -93,7 +94,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);
-        mdsalManager.removeFlowToTx(tsNatFlowEntity, removeFlowInvTx);
+        mdsalManager.removeFlow(confTx, tsNatFlowEntity);
 
     }
 
index ebdbe48af3f9594c974c2da9c30e3eedda5cd8f4..a880a9d4fbb0b8f0093027cab35a07a50d86f02a 100644 (file)
@@ -8,6 +8,8 @@
 
 package org.opendaylight.netvirt.natservice.internal;
 
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -19,13 +21,18 @@ import javax.annotation.Nonnull;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.genius.infra.Datastore.Configuration;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
 import org.opendaylight.genius.mdsalutil.MatchInfo;
 import org.opendaylight.genius.mdsalutil.NwConstants;
 import org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable;
 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.genius.mdsalutil.matches.MatchTunnelId;
+import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
 import org.opendaylight.netvirt.bgpmanager.api.IBgpManager;
 import org.opendaylight.netvirt.fibmanager.api.IFibManager;
 import org.opendaylight.netvirt.fibmanager.api.RouteOrigin;
@@ -50,6 +57,7 @@ public class EvpnSnatFlowProgrammer {
     private static final BigInteger COOKIE_TUNNEL = new BigInteger("9000000", 16);
 
     private final DataBroker dataBroker;
+    private final ManagedNewTransactionRunner txRunner;
     private final IMdsalApiManager mdsalManager;
     private final IBgpManager bgpManager;
     private final IFibManager fibManager;
@@ -63,6 +71,7 @@ public class EvpnSnatFlowProgrammer {
                            final FibRpcService fibService,
                            final IdManagerService idManager) {
         this.dataBroker = dataBroker;
+        this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
         this.mdsalManager = mdsalManager;
         this.bgpManager = bgpManager;
         this.fibManager = fibManager;
@@ -71,10 +80,8 @@ public class EvpnSnatFlowProgrammer {
     }
 
     public void evpnAdvToBgpAndInstallFibAndTsFlows(final BigInteger dpnId, final short tableId,
-                                                    final String externalIp, final String vpnName, final String rd,
-                                                    final String nextHopIp, final WriteTransaction writeTx,
-                                                    final long routerId, final String routerName,
-                                                    WriteTransaction writeFlowInvTx) {
+        final String externalIp, final String vpnName, final String rd, final String nextHopIp,
+        final long routerId, final String routerName, TypedWriteTransaction<Configuration> confTx) {
      /*
       * 1) Install the flow INTERNAL_TUNNEL_TABLE (table=36)-> INBOUND_NAPT_TABLE (table=44)
       *    (FIP VM on DPN1 is responding back to external fixed IP on DPN2) {DNAT to SNAT traffic on
@@ -119,7 +126,7 @@ public class EvpnSnatFlowProgrammer {
          */
         //Inform to BGP
         NatEvpnUtil.addRoutesForVxLanProvType(dataBroker, bgpManager, fibManager, vpnName, rd, externalIp,
-                nextHopIp, l3Vni, null /*InterfaceName*/, gwMacAddress, writeTx, RouteOrigin.STATIC, dpnId);
+                nextHopIp, l3Vni, null /*InterfaceName*/, gwMacAddress, confTx, RouteOrigin.STATIC, dpnId);
 
         //Install custom FIB routes - FIB table.
         List<Instruction> customInstructions = new ArrayList<>();
@@ -155,25 +162,24 @@ public class EvpnSnatFlowProgrammer {
                  /* Install the flow INTERNAL_TUNNEL_TABLE (table=36)-> INBOUND_NAPT_TABLE (table=44)
                   * (SNAT to DNAT reverse Traffic: If traffic is Initiated from NAPT to FIP VM on different Hypervisor)
                   */
-                    makeTunnelTableEntry(dpnId, finalL3Vni, customInstructions, tableId, writeFlowInvTx);
+                    makeTunnelTableEntry(dpnId, finalL3Vni, customInstructions, tableId, confTx);
                  /* Install the flow L3_GW_MAC_TABLE (table=19)-> INBOUND_NAPT_TABLE (table=44)
                   * (SNAT reverse traffic: If the traffic is Initiated from DC-GW to VM (SNAT Reverse traffic))
                   */
                     NatEvpnUtil.makeL3GwMacTableEntry(dpnId, vpnId, gwMacAddress, customInstructions, mdsalManager,
-                            writeFlowInvTx);
+                            confTx);
 
                  /* Install the flow PDNAT_TABLE (table=25)-> INBOUND_NAPT_TABLE (table=44)
                   * If there is no FIP Match on table 25 (PDNAT_TABLE)
                   */
-                    NatUtil.makePreDnatToSnatTableEntry(mdsalManager, dpnId, tableId, writeFlowInvTx);
+                    NatUtil.makePreDnatToSnatTableEntry(mdsalManager, dpnId, tableId, confTx);
                 }
             }
         }, MoreExecutors.directExecutor());
     }
 
     public void evpnDelFibTsAndReverseTraffic(final BigInteger dpnId, final long routerId, final String externalIp,
-                                              final String vpnName, String extGwMacAddress,
-                                              WriteTransaction removeFlowInvTx) {
+        final String vpnName, String extGwMacAddress) {
      /*
       * 1) Remove the flow INTERNAL_TUNNEL_TABLE (table=36)-> INBOUND_NAPT_TABLE (table=44)
       *    (FIP VM on DPN1 is responding back to external fixed IP on DPN2) {DNAT to SNAT traffic on
@@ -234,23 +240,27 @@ public class EvpnSnatFlowProgrammer {
             @Override
             public void onSuccess(@Nonnull RpcResult<RemoveFibEntryOutput> result) {
                 if (result.isSuccessful()) {
-                    LOG.info("evpnDelFibTsAndReverseTraffic : Successfully removed custom FIB routes for "
-                            + "External Fixed IP {} on DPN {} with l3Vni {}, ExternalVpnName {} for "
-                            + "RouterId {}", externalIp, dpnId, finalL3Vni, vpnName, routerId);
+                    ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
+                        innerConfTx -> {
+                            LOG.info("evpnDelFibTsAndReverseTraffic : Successfully removed custom FIB routes for "
+                                + "External Fixed IP {} on DPN {} with l3Vni {}, ExternalVpnName {} for "
+                                + "RouterId {}", externalIp, dpnId, finalL3Vni, vpnName, routerId);
 
-                    //remove INTERNAL_TUNNEL_TABLE (table=36)-> INBOUND_NAPT_TABLE (table=44) flow
-                    removeTunnelTableEntry(dpnId, finalL3Vni, removeFlowInvTx);
-                    //remove L3_GW_MAC_TABLE (table=19)-> INBOUND_NAPT_TABLE (table=44) flow
-                    NatUtil.removePreDnatToSnatTableEntry(mdsalManager, dpnId, removeFlowInvTx);
-                    //remove PDNAT_TABLE (table=25)-> INBOUND_NAPT_TABLE (table=44) flow
-                    NatEvpnUtil.removeL3GwMacTableEntry(dpnId, vpnId, extGwMacAddress, mdsalManager, removeFlowInvTx);
+                            //remove INTERNAL_TUNNEL_TABLE (table=36)-> INBOUND_NAPT_TABLE (table=44) flow
+                            removeTunnelTableEntry(dpnId, finalL3Vni, innerConfTx);
+                            //remove L3_GW_MAC_TABLE (table=19)-> INBOUND_NAPT_TABLE (table=44) flow
+                            NatUtil.removePreDnatToSnatTableEntry(innerConfTx, mdsalManager, dpnId);
+                            //remove PDNAT_TABLE (table=25)-> INBOUND_NAPT_TABLE (table=44) flow
+                            NatEvpnUtil.removeL3GwMacTableEntry(dpnId, vpnId, extGwMacAddress, mdsalManager,
+                                innerConfTx);
+                        }), LOG, "Error removing EVPN SNAT table entries");
                 }
             }
         }, MoreExecutors.directExecutor());
     }
 
     public void makeTunnelTableEntry(BigInteger dpnId, long l3Vni, List<Instruction> customInstructions,
-                                     short tableId, WriteTransaction writeFlowTx) {
+                                     short tableId, TypedWriteTransaction<Configuration> confTx) {
         LOG.debug("makeTunnelTableEntry : Create terminating service table {} --> table {} flow on NAPT DpnId {} "
                 + "with l3Vni {} as matching parameter", NwConstants.INTERNAL_TUNNEL_TABLE, tableId, dpnId, l3Vni);
         List<MatchInfo> mkMatches = new ArrayList<>();
@@ -260,12 +270,12 @@ 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, customInstructions);
-        mdsalManager.addFlowToTx(dpnId, terminatingServiceTableFlowEntity, writeFlowTx);
+        mdsalManager.addFlow(confTx, dpnId, terminatingServiceTableFlowEntity);
         LOG.debug("makeTunnelTableEntry : Successfully installed terminating service table flow {} on DpnId {}",
                 terminatingServiceTableFlowEntity, dpnId);
     }
 
-    public void removeTunnelTableEntry(BigInteger dpnId, long l3Vni, WriteTransaction removeFlowInvTx) {
+    public void removeTunnelTableEntry(BigInteger dpnId, long l3Vni, TypedReadWriteTransaction<Configuration> confTx) {
         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);
@@ -276,7 +286,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);
-        mdsalManager.removeFlowToTx(dpnId, flowEntity, removeFlowInvTx);
+        mdsalManager.removeFlow(confTx, dpnId, flowEntity);
         LOG.debug("removeTunnelTableEntry : Successfully removed terminating service table flow {} on DpnId {}",
                 flowEntity, dpnId);
     }
index 1e5e35bd7e2fd12bedd6b1c081cd97897d10c264..844b3878dc7482045bb175797050fc4aec6323c3 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.netvirt.natservice.internal;
 
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
 import com.google.common.base.Optional;
 import java.math.BigInteger;
 import java.util.Collection;
@@ -17,11 +19,12 @@ import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
+import org.opendaylight.genius.infra.Datastore.Configuration;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
 import org.opendaylight.genius.mdsalutil.NwConstants;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
@@ -122,7 +125,7 @@ public class ExternalNetworksChangeListener
         Uuid originalVpn = original.getVpnid();
         Uuid updatedVpn = update.getVpnid();
         coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + update.key(),
-            () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+            () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
                 if (originalVpn == null && updatedVpn != null) {
                     //external network is dis-associated from L3VPN instance
                     associateExternalNetworkWithVPN(update, tx);
@@ -135,7 +138,8 @@ public class ExternalNetworksChangeListener
             })), NatConstants.NAT_DJC_MAX_RETRIES);
     }
 
-    private void removeSnatEntries(Networks original, Uuid networkUuid, WriteTransaction writeFlowInvTx) {
+    private void removeSnatEntries(Networks original, Uuid networkUuid,
+        TypedReadWriteTransaction<Configuration> writeFlowInvTx) {
         List<Uuid> routerUuids = original.getRouterIds();
         for (Uuid routerUuid : routerUuids) {
             Long routerId = NatUtil.getVpnId(dataBroker, routerUuid.getValue());
@@ -151,7 +155,7 @@ public class ExternalNetworksChangeListener
         }
     }
 
-    private void associateExternalNetworkWithVPN(Networks network, WriteTransaction writeFlowInvTx) {
+    private void associateExternalNetworkWithVPN(Networks network, TypedReadWriteTransaction<Configuration> confTx) {
         List<Uuid> routerIds = network.getRouterIds();
         for (Uuid routerId : routerIds) {
             //long router = NatUtil.getVpnId(dataBroker, routerId.getValue());
@@ -178,7 +182,7 @@ public class ExternalNetworksChangeListener
                 for (InternalToExternalPortMap ipMap : intExtPortMapList) {
                     //remove all VPN related entries
                     floatingIpListener.createNATFlowEntries(dpnId, portName, routerId.getValue(), network.getId(),
-                            ipMap, writeFlowInvTx);
+                            ipMap, confTx);
                 }
             }
         }
@@ -235,7 +239,7 @@ public class ExternalNetworksChangeListener
                         externalRouterListener.advToBgpAndInstallFibAndTsFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE,
                                 vpnName, routerIdentifier, routerId.getValue(),
                                 externalIp, network.getId(), null /* external-router */,
-                                writeFlowInvTx);
+                                confTx);
                     }
                 }
             } else {
@@ -246,11 +250,11 @@ public class ExternalNetworksChangeListener
             // Install 47 entry to point to 21
             if (natMode == NatMode.Controller) {
                 externalRouterListener.installNaptPfibEntriesForExternalSubnets(routerId.getValue(), dpnId,
-                        writeFlowInvTx);
+                        confTx);
                 if (vpnId != -1) {
                     LOG.debug("associateExternalNetworkWithVPN : Calling externalRouterListener installNaptPfibEntry "
                             + "for dpnId {} and vpnId {}", dpnId, vpnId);
-                    externalRouterListener.installNaptPfibEntry(dpnId, vpnId, writeFlowInvTx);
+                    externalRouterListener.installNaptPfibEntry(dpnId, vpnId, confTx);
                 }
             }
         }
@@ -272,7 +276,7 @@ public class ExternalNetworksChangeListener
             RouterPorts routerPorts = optRouterPorts.get();
             List<Ports> interfaces = routerPorts.getPorts();
             try {
-                txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+                txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
                     for (Ports port : interfaces) {
                         String portName = port.getPortName();
                         BigInteger dpnId = NatUtil.getDpnForInterface(interfaceManager, portName);
index 0f35b575239296c22058d176f5213b7020630669..b69b69af6105cb0caa04096cd600a1baccdac038 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.netvirt.natservice.internal;
 
+import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
@@ -29,16 +32,19 @@ import java.util.Set;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
+import org.opendaylight.genius.infra.Datastore.Configuration;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
 import org.opendaylight.genius.mdsalutil.ActionInfo;
 import org.opendaylight.genius.mdsalutil.BucketInfo;
@@ -71,7 +77,6 @@ import org.opendaylight.genius.mdsalutil.matches.MatchMetadata;
 import org.opendaylight.genius.mdsalutil.matches.MatchMplsLabel;
 import org.opendaylight.genius.mdsalutil.matches.MatchTunnelId;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
-import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
 import org.opendaylight.netvirt.bgpmanager.api.IBgpManager;
 import org.opendaylight.netvirt.elanmanager.api.IElanService;
 import org.opendaylight.netvirt.fibmanager.api.IFibManager;
@@ -266,26 +271,27 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
         Uuid bgpVpnUuid = NatUtil.getVpnForRouter(dataBroker, routerName);
         try {
             coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + routers.key(),
-                () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
-                    LOG.info("add : Installing NAT default route on all dpns part of router {}", routerName);
-                    long bgpVpnId = NatConstants.INVALID_ID;
-                    if (bgpVpnUuid != null) {
-                        bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnUuid.getValue());
-                    }
-                    addOrDelDefFibRouteToSNAT(routerName, routerId, bgpVpnId, bgpVpnUuid, true, tx);
-                    // Allocate Primary Napt Switch for this router
-                    BigInteger primarySwitchId = getPrimaryNaptSwitch(routerName);
-                    if (primarySwitchId != null && !primarySwitchId.equals(BigInteger.ZERO)) {
-                        if (!routers.isEnableSnat()) {
-                            LOG.info("add : SNAT is disabled for external router {} ", routerName);
-                            /* If SNAT is disabled on ext-router though L3_FIB_TABLE(21) -> PSNAT_TABLE(26) flow
-                             * is required for DNAT. Hence writeFlowInvTx object submit is required.
-                             */
-                            return;
+                () -> Collections.singletonList(
+                    txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> {
+                        LOG.info("add : Installing NAT default route on all dpns part of router {}", routerName);
+                        long bgpVpnId = NatConstants.INVALID_ID;
+                        if (bgpVpnUuid != null) {
+                            bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnUuid.getValue());
                         }
-                        handleEnableSnat(routers, routerId, primarySwitchId, bgpVpnId, tx);
-                    }
-                })), NatConstants.NAT_DJC_MAX_RETRIES);
+                        addOrDelDefFibRouteToSNAT(routerName, routerId, bgpVpnId, bgpVpnUuid, true, confTx);
+                        // Allocate Primary Napt Switch for this router
+                        BigInteger primarySwitchId = getPrimaryNaptSwitch(routerName);
+                        if (primarySwitchId != null && !primarySwitchId.equals(BigInteger.ZERO)) {
+                            if (!routers.isEnableSnat()) {
+                                LOG.info("add : SNAT is disabled for external router {} ", routerName);
+                                /* If SNAT is disabled on ext-router though L3_FIB_TABLE(21) -> PSNAT_TABLE(26) flow
+                                 * is required for DNAT. Hence writeFlowInvTx object submit is required.
+                                 */
+                                return;
+                            }
+                            handleEnableSnat(routers, routerId, primarySwitchId, bgpVpnId, confTx);
+                        }
+                    })), NatConstants.NAT_DJC_MAX_RETRIES);
         } catch (Exception ex) {
             LOG.error("add : Exception while Installing NAT flows on all dpns as part of router {}",
                     routerName, ex);
@@ -293,7 +299,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
     }
 
     public void handleEnableSnat(Routers routers, long routerId, BigInteger primarySwitchId, long bgpVpnId,
-                                 WriteTransaction writeFlowInvTx) {
+                                 TypedWriteTransaction<Configuration> confTx) {
         String routerName = routers.getRouterName();
         LOG.info("handleEnableSnat : Handling SNAT for router {}", routerName);
 
@@ -311,11 +317,11 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
         }
 
         if (bgpVpnId != NatConstants.INVALID_ID) {
-            installFlowsWithUpdatedVpnId(primarySwitchId, routerName, bgpVpnId, routerId, false, writeFlowInvTx,
+            installFlowsWithUpdatedVpnId(primarySwitchId, routerName, bgpVpnId, routerId, false, confTx,
                     extNwProvType);
         } else {
             // write metadata and punt
-            installOutboundMissEntry(routerName, routerId, primarySwitchId, writeFlowInvTx);
+            installOutboundMissEntry(routerName, routerId, primarySwitchId, confTx);
             // Now install entries in SNAT tables to point to Primary for each router
             List<BigInteger> switches = naptSwitchSelector.getDpnsForVpn(routerName);
             for (BigInteger dpnId : switches) {
@@ -325,7 +331,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
                     handleSwitches(dpnId, routerName, routerId, primarySwitchId);
                 } else {
                     LOG.debug("handleEnableSnat : Handle NAPT switch");
-                    handlePrimaryNaptSwitch(dpnId, routerName, routerId, writeFlowInvTx);
+                    handlePrimaryNaptSwitch(dpnId, routerName, routerId, confTx);
                 }
             }
         }
@@ -338,8 +344,8 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
             for (String externalIpAddrPrefix : externalIps) {
                 LOG.debug("handleEnableSnat : Calling handleSnatReverseTraffic for primarySwitchId {}, "
                     + "routerName {} and externalIpAddPrefix {}", primarySwitchId, routerName, externalIpAddrPrefix);
-                handleSnatReverseTraffic(primarySwitchId, routers, routerId, routerName, externalIpAddrPrefix,
-                        writeFlowInvTx);
+                handleSnatReverseTraffic(confTx, primarySwitchId, routers, routerId, routerName, externalIpAddrPrefix
+                );
             }
         }
         LOG.debug("handleEnableSnat : Exit");
@@ -366,7 +372,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
     }
 
     protected void installNaptPfibExternalOutputFlow(String routerName, Long routerId, BigInteger dpnId,
-                                                     WriteTransaction writeFlowInvTx) {
+                                                     TypedWriteTransaction<Configuration> confTx) {
         Long extVpnId = NatUtil.getNetworkVpnIdFromRouterId(dataBroker, routerId);
         if (extVpnId == NatConstants.INVALID_ID) {
             LOG.error("installNaptPfibExternalOutputFlow - not found extVpnId for router {}", routerId);
@@ -388,28 +394,26 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
                 LOG.debug("installNaptPfibExternalOutputFlow - dpnId {} extVpnId {} subnetId {}",
                     dpnId, extVpnId, subnetId);
                 FlowEntity postNaptFlowEntity = buildNaptPfibFlowEntity(dpnId, extVpnId);
-                mdsalManager.addFlowToTx(postNaptFlowEntity, writeFlowInvTx);
+                mdsalManager.addFlow(confTx, postNaptFlowEntity);
             }
         }
     }
 
+    @Nullable
     private Uuid getSubnetIdForFixedIp(String ip) {
         if (ip != null) {
             IpAddress externalIpv4Address = new IpAddress(new Ipv4Address(ip));
             Port port = NatUtil.getNeutronPortForRouterGetewayIp(dataBroker, externalIpv4Address);
-            Uuid subnetId = NatUtil.getSubnetIdForFloatingIp(port, externalIpv4Address);
-            return subnetId;
+            return NatUtil.getSubnetIdForFloatingIp(port, externalIpv4Address);
         }
         LOG.error("getSubnetIdForFixedIp : ip is null");
         return null;
     }
 
     protected void subnetRegisterMapping(Routers routerEntry, Long segmentId) {
-        List<Uuid> subnetList = null;
-        List<String> externalIps = null;
         LOG.debug("subnetRegisterMapping : Fetching values from extRouters model");
-        subnetList = routerEntry.getSubnetIds();
-        externalIps = NatUtil.getIpsListFromExternalIps(routerEntry.getExternalIps());
+        List<Uuid> subnetList = routerEntry.getSubnetIds();
+        List<String> externalIps = NatUtil.getIpsListFromExternalIps(routerEntry.getExternalIps());
         int counter = 0;
         int extIpCounter = externalIps.size();
         LOG.debug("subnetRegisterMapping : counter values before looping counter {} and extIpCounter {}",
@@ -489,7 +493,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
     }
 
     private void addOrDelDefFibRouteToSNAT(String routerName, long routerId, long bgpVpnId,
-            Uuid bgpVpnUuid, boolean create, WriteTransaction writeFlowInvTx) {
+            Uuid bgpVpnUuid, boolean create, TypedReadWriteTransaction<Configuration> confTx) {
         //Check if BGP VPN exists. If exists then invoke the new method.
         if (bgpVpnId != NatConstants.INVALID_ID) {
             if (bgpVpnUuid != null) {
@@ -498,19 +502,22 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
                     bgpVpnId, bgpVpnName);
                 RouterIds rtrs = new RouterIdsBuilder().withKey(new RouterIdsKey(bgpVpnId))
                     .setRouterId(bgpVpnId).setRouterName(bgpVpnName).build();
-                MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
-                    getRoutersIdentifier(bgpVpnId), rtrs);
+                confTx.put(getRoutersIdentifier(bgpVpnId), rtrs, CREATE_MISSING_PARENTS);
+            }
+            if (create) {
+                addDefaultFibRouteForSnatWithBgpVpn(routerName, routerId, bgpVpnId, confTx);
+            } else {
+                removeDefaultFibRouteForSnatWithBgpVpn(routerName, routerId, bgpVpnId, confTx);
             }
-            addOrDelDefaultFibRouteForSnatWithBgpVpn(routerName, routerId, bgpVpnId, create, writeFlowInvTx);
             return;
         }
 
         //Router ID is used as the internal VPN's name, hence the vrf-id in VpnInstance Op DataStore
-        addOrDelDefaultFibRouteForSNAT(routerName, routerId, create, writeFlowInvTx);
+        addOrDelDefaultFibRouteForSNAT(routerName, routerId, create, confTx);
     }
 
     private void addOrDelDefaultFibRouteForSNAT(String routerName, long routerId, boolean create,
-            WriteTransaction writeFlowInvTx) {
+            TypedReadWriteTransaction<Configuration> confTx) {
         List<BigInteger> switches = naptSwitchSelector.getDpnsForVpn(routerName);
         if (switches.isEmpty()) {
             LOG.info("addOrDelDefaultFibRouteForSNAT : No switches found for router {}", routerName);
@@ -525,44 +532,53 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
             if (create) {
                 LOG.debug("addOrDelDefaultFibRouteForSNAT : installing default NAT route for router {} in dpn {} "
                         + "for the internal vpn-id {}", routerId, dpnId, routerId);
-                defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, routerId, writeFlowInvTx);
+                defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, routerId, confTx);
             } else {
                 LOG.debug("addOrDelDefaultFibRouteForSNAT : removing default NAT route for router {} in dpn {} "
                         + "for the internal vpn-id {}", routerId, dpnId, routerId);
-                defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, routerId, writeFlowInvTx);
+                defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, routerId, confTx);
             }
         }
     }
 
-    private void addOrDelDefaultFibRouteForSnatWithBgpVpn(String routerName, long routerId,
-            long bgpVpnId, boolean create,WriteTransaction writeFlowInvTx) {
+    private void addDefaultFibRouteForSnatWithBgpVpn(String routerName, long routerId,
+        long bgpVpnId, TypedWriteTransaction<Configuration> confTx) {
         List<BigInteger> dpnIds = NatUtil.getDpnsForRouter(dataBroker, routerName);
         if (dpnIds.isEmpty()) {
             LOG.error("addOrDelDefaultFibRouteForSNATWIthBgpVpn: No dpns are part of router {} to program "
-                    + "default NAT flows for BGP-VPN {}", routerName, bgpVpnId);
+                + "default NAT flows for BGP-VPN {}", routerName, bgpVpnId);
             return;
         }
         for (BigInteger dpnId : dpnIds) {
-            if (create) {
-                if (bgpVpnId != NatConstants.INVALID_ID) {
-                    LOG.debug("addOrDelDefaultFibRouteForSnatWithBgpVpn : installing default NAT route for router {} "
-                            + "in dpn {} for the BGP vpnID {}", routerId, dpnId, bgpVpnId);
-                    defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, bgpVpnId, routerId, writeFlowInvTx);
-                } else {
-                    LOG.debug("addOrDelDefaultFibRouteForSnatWithBgpVpn : installing default NAT route for router {} "
-                            + "in dpn {} for the internal vpn", routerId, dpnId);
-                    defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, routerId,writeFlowInvTx);
-                }
+            if (bgpVpnId != NatConstants.INVALID_ID) {
+                LOG.debug("addOrDelDefaultFibRouteForSnatWithBgpVpn : installing default NAT route for router {} "
+                    + "in dpn {} for the BGP vpnID {}", routerId, dpnId, bgpVpnId);
+                defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, bgpVpnId, routerId, confTx);
             } else {
-                if (bgpVpnId != NatConstants.INVALID_ID) {
-                    LOG.debug("addOrDelDefaultFibRouteForSnatWithBgpVpn : removing default NAT route for router {} "
-                            + "in dpn {} for the BGP vpnID {}", routerId, dpnId, bgpVpnId);
-                    defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, bgpVpnId, routerId, writeFlowInvTx);
-                } else {
-                    LOG.debug("addOrDelDefaultFibRouteForSnatWithBgpVpn : removing default NAT route for router {} "
-                            + "in dpn {} for the internal vpn", routerId, dpnId);
-                    defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, routerId, writeFlowInvTx);
-                }
+                LOG.debug("addOrDelDefaultFibRouteForSnatWithBgpVpn : installing default NAT route for router {} "
+                    + "in dpn {} for the internal vpn", routerId, dpnId);
+                defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, routerId, confTx);
+            }
+        }
+    }
+
+    private void removeDefaultFibRouteForSnatWithBgpVpn(String routerName, long routerId,
+        long bgpVpnId, TypedReadWriteTransaction<Configuration> confTx) {
+        List<BigInteger> dpnIds = NatUtil.getDpnsForRouter(dataBroker, routerName);
+        if (dpnIds.isEmpty()) {
+            LOG.error("addOrDelDefaultFibRouteForSNATWIthBgpVpn: No dpns are part of router {} to program "
+                + "default NAT flows for BGP-VPN {}", routerName, bgpVpnId);
+            return;
+        }
+        for (BigInteger dpnId : dpnIds) {
+            if (bgpVpnId != NatConstants.INVALID_ID) {
+                LOG.debug("addOrDelDefaultFibRouteForSnatWithBgpVpn : removing default NAT route for router {} "
+                    + "in dpn {} for the BGP vpnID {}", routerId, dpnId, bgpVpnId);
+                defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, bgpVpnId, routerId, confTx);
+            } else {
+                LOG.debug("addOrDelDefaultFibRouteForSnatWithBgpVpn : removing default NAT route for router {} "
+                    + "in dpn {} for the internal vpn", routerId, dpnId);
+                defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, routerId, confTx);
             }
         }
     }
@@ -581,12 +597,12 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
     }
 
     protected void installOutboundMissEntry(String routerName, long routerId, BigInteger primarySwitchId,
-                                            WriteTransaction writeFlowInvTx) {
+        TypedWriteTransaction<Configuration> confTx) {
         LOG.debug("installOutboundMissEntry : Router ID from getVpnId {}", routerId);
         if (routerId != NatConstants.INVALID_ID) {
             LOG.debug("installOutboundMissEntry : Creating miss entry on primary {}, for router {}",
                     primarySwitchId, routerId);
-            createOutboundTblEntry(primarySwitchId, routerId, writeFlowInvTx);
+            createOutboundTblEntry(primarySwitchId, routerId, confTx);
         } else {
             LOG.error("installOutboundMissEntry : Unable to fetch Router Id  for RouterName {}, failed to "
                 + "createAndInstallMissEntry", routerName);
@@ -684,19 +700,19 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
         return flowEntity;
     }
 
-    public void createOutboundTblEntry(BigInteger dpnId, long routerId, WriteTransaction writeFlowInvTx) {
+    public void createOutboundTblEntry(BigInteger dpnId, long routerId, TypedWriteTransaction<Configuration> confTx) {
         LOG.debug("createOutboundTblEntry : called for dpId {} and routerId {}", dpnId, routerId);
         FlowEntity tcpflowEntity = buildOutboundFlowEntity(dpnId, routerId, NwConstants.IP_PROT_TCP);
         LOG.debug("createOutboundTblEntry : Installing tcp flow {}", tcpflowEntity);
-        mdsalManager.addFlowToTx(tcpflowEntity, writeFlowInvTx);
+        mdsalManager.addFlow(confTx, tcpflowEntity);
 
         FlowEntity udpflowEntity = buildOutboundFlowEntity(dpnId, routerId, NwConstants.IP_PROT_UDP);
         LOG.debug("createOutboundTblEntry : Installing udp flow {}", udpflowEntity);
-        mdsalManager.addFlowToTx(udpflowEntity, writeFlowInvTx);
+        mdsalManager.addFlow(confTx, udpflowEntity);
 
         FlowEntity icmpDropFlow = buildIcmpDropFlow(dpnId, routerId, routerId);
         LOG.debug("createOutboundTblEntry: Installing icmp drop flow {}", icmpDropFlow);
-        mdsalManager.addFlowToTx(icmpDropFlow, writeFlowInvTx);
+        mdsalManager.addFlow(confTx, icmpDropFlow);
     }
 
     protected String getTunnelInterfaceName(BigInteger srcDpId, BigInteger dstDpId) {
@@ -738,11 +754,12 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
     }
 
     protected void installSnatMissEntryForPrimrySwch(BigInteger dpnId, String routerName, long routerId,
-                                                    WriteTransaction writeFlowInvTx) {
+        TypedWriteTransaction<Configuration> confTx) {
+
         LOG.debug("installSnatMissEntry : called for for the primary NAPT switch dpnId {} ", dpnId);
         // Install miss entry pointing to group
         FlowEntity flowEntity = buildSnatFlowEntityForPrmrySwtch(dpnId, routerName, routerId);
-        mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
+        mdsalManager.addFlow(confTx, flowEntity);
     }
 
     protected void installSnatMissEntry(BigInteger dpnId, List<BucketInfo> bucketInfo,
@@ -821,7 +838,8 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
 
     // TODO : Replace this with ITM Rpc once its available with full functionality
     protected void installTerminatingServiceTblEntry(BigInteger dpnId, String routerName, long routerId,
-                                                     WriteTransaction writeFlowInvTx) {
+        TypedWriteTransaction<Configuration> confTx) {
+
         LOG.debug("installTerminatingServiceTblEntry : for switch {}, routerName {}",
             dpnId, routerName);
         FlowEntity flowEntity = buildTsFlowEntity(dpnId, routerName, routerId);
@@ -832,7 +850,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
                     dpnId, routerName);
             return;
         }
-        mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
+        mdsalManager.addFlow(confTx, flowEntity);
 
     }
 
@@ -933,7 +951,8 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
     }
 
     protected void handlePrimaryNaptSwitch(BigInteger dpnId, String routerName, long routerId,
-            WriteTransaction writeFlowInvTx) {
+        TypedWriteTransaction<Configuration> confTx) {
+
        /*
         * Primary NAPT Switch Ă˘â‚¬â€ś bucket Should always point back to its own Outbound Table
         */
@@ -948,10 +967,10 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
         listBucketInfo.add(0, bucketPrimary);
 */
 
-        installSnatMissEntryForPrimrySwch(dpnId, routerName, routerId, writeFlowInvTx);
-        installTerminatingServiceTblEntry(dpnId, routerName, routerId, writeFlowInvTx);
+        installSnatMissEntryForPrimrySwch(dpnId, routerName, routerId, confTx);
+        installTerminatingServiceTblEntry(dpnId, routerName, routerId, confTx);
         //Install the NAPT PFIB TABLE which forwards the outgoing packet to FIB Table matching on the router ID.
-        installNaptPfibEntry(dpnId, routerId, writeFlowInvTx);
+        installNaptPfibEntry(dpnId, routerId, confTx);
         Uuid networkId = NatUtil.getNetworkIdFromRouterId(dataBroker, routerId);
         if (networkId != null) {
             Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
@@ -982,11 +1001,11 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
         return listBucketInfo;
     }
 
-    public void installNaptPfibEntry(BigInteger dpnId, long segmentId, WriteTransaction writeFlowInvTx) {
+    public void installNaptPfibEntry(BigInteger dpnId, long segmentId, TypedWriteTransaction<Configuration> confTx) {
         LOG.debug("installNaptPfibEntry : called for dpnId {} and segmentId {} ", dpnId, segmentId);
         FlowEntity naptPfibFlowEntity = buildNaptPfibFlowEntity(dpnId, segmentId);
-        if (writeFlowInvTx != null) {
-            mdsalManager.addFlowToTx(naptPfibFlowEntity, writeFlowInvTx);
+        if (confTx != null) {
+            mdsalManager.addFlow(confTx, naptPfibFlowEntity);
         } else {
             mdsalManager.installFlow(naptPfibFlowEntity);
         }
@@ -1013,8 +1032,8 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
         return flowEntity;
     }
 
-    public void handleSnatReverseTraffic(BigInteger dpnId, Routers router, long routerId, String routerName,
-            String externalIp, WriteTransaction writeFlowInvTx) {
+    public void handleSnatReverseTraffic(TypedWriteTransaction<Configuration> confTx, BigInteger dpnId, Routers router,
+        long routerId, String routerName, String externalIp) {
         LOG.debug("handleSnatReverseTraffic : entry for DPN ID {}, routerId {}, externalIp: {}",
             dpnId, routerId, externalIp);
         Uuid networkId = router.getNetworkId();
@@ -1029,7 +1048,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
             return;
         }
         advToBgpAndInstallFibAndTsFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, vpnName, routerId, routerName,
-            externalIp, networkId, router, writeFlowInvTx);
+            externalIp, networkId, router, confTx);
         LOG.debug("handleSnatReverseTraffic : exit for DPN ID {}, routerId {}, externalIp : {}",
             dpnId, routerId, externalIp);
     }
@@ -1037,7 +1056,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
     public void advToBgpAndInstallFibAndTsFlows(final BigInteger dpnId, final short tableId, final String vpnName,
                                                 final long routerId, final String routerName, final String externalIp,
                                                 final Uuid extNetworkId, final Routers router,
-                                                final WriteTransaction writeFlowInvTx) {
+                                                final TypedWriteTransaction<Configuration> confTx) {
         LOG.debug("advToBgpAndInstallFibAndTsFlows : entry for DPN ID {}, tableId {}, vpnname {} "
                 + "and externalIp {}", dpnId, tableId, vpnName, externalIp);
         String nextHopIp = NatUtil.getEndpointIpAddressForDPN(dataBroker, dpnId);
@@ -1052,10 +1071,8 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
             return;
         }
         if (extNwProvType == ProviderTypes.VXLAN) {
-            ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
-                tx -> evpnSnatFlowProgrammer.evpnAdvToBgpAndInstallFibAndTsFlows(dpnId, tableId, externalIp,
-                        vpnName, rd, nextHopIp, tx, routerId, routerName, writeFlowInvTx)), LOG,
-                "Error installing FIB and TS flows");
+            evpnSnatFlowProgrammer.evpnAdvToBgpAndInstallFibAndTsFlows(dpnId, tableId, externalIp, vpnName, rd,
+                nextHopIp, routerId, routerName, confTx);
             return;
         }
         //Generate VPN label for the external IP
@@ -1117,17 +1134,16 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
                 //Install custom FIB routes
                 List<Instruction> tunnelTableCustomInstructions = new ArrayList<>();
                 tunnelTableCustomInstructions.add(new InstructionGotoTable(tableId).buildInstruction(0));
-                makeTunnelTableEntry(dpnId, label, l3vni, tunnelTableCustomInstructions, writeFlowInvTx,
+                makeTunnelTableEntry(dpnId, label, l3vni, tunnelTableCustomInstructions, confTx,
                         extNwProvType);
-                makeLFibTableEntry(dpnId, label, tableId, writeFlowInvTx);
+                makeLFibTableEntry(dpnId, label, tableId, confTx);
 
                 //Install custom FIB routes - FIB table.
                 List<Instruction> fibTableCustomInstructions = createFibTableCustomInstructions(tableId,
                         routerName, externalIp);
                 if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
                     //Install the flow table 25->44 If there is no FIP Match on table 25 (PDNAT_TABLE)
-                    NatUtil.makePreDnatToSnatTableEntry(mdsalManager, dpnId,
-                            NwConstants.INBOUND_NAPT_TABLE,writeFlowInvTx);
+                    NatUtil.makePreDnatToSnatTableEntry(mdsalManager, dpnId, NwConstants.INBOUND_NAPT_TABLE, confTx);
                 }
                 String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
                 Optional<Subnets> externalSubnet = NatUtil.getOptionalExternalSubnets(dataBroker,
@@ -1188,7 +1204,8 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
         return fibTableCustomInstructions;
     }
 
-    private void makeLFibTableEntry(BigInteger dpId, long serviceId, short tableId, WriteTransaction writeFlowInvTx) {
+    private void makeLFibTableEntry(BigInteger dpId, long serviceId, short tableId,
+        TypedWriteTransaction<Configuration> confTx) {
         List<MatchInfo> matches = new ArrayList<>();
         matches.add(MatchEthernetType.MPLS_UNICAST);
         matches.add(new MatchMplsLabel(serviceId));
@@ -1208,13 +1225,15 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
             10, flowRef, 0, 0,
             COOKIE_VM_LFIB_TABLE, matches, instructions);
 
-        mdsalManager.addFlowToTx(dpId, flowEntity, writeFlowInvTx);
+        mdsalManager.addFlow(confTx, dpId, flowEntity);
 
         LOG.debug("makeLFibTableEntry : LFIB Entry for dpID {} : label : {} modified successfully", dpId, serviceId);
     }
 
     private void makeTunnelTableEntry(BigInteger dpnId, long serviceId, long l3Vni,
-             List<Instruction> customInstructions, WriteTransaction writeFlowInvTx, ProviderTypes extNwProvType) {
+        List<Instruction> customInstructions, TypedWriteTransaction<Configuration> confTx,
+        ProviderTypes extNwProvType) {
+
         List<MatchInfo> mkMatches = new ArrayList<>();
 
         LOG.debug("makeTunnelTableEntry : DpnId = {} and serviceId = {} and actions = {}",
@@ -1231,13 +1250,12 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
             String.format("%s:%d", "TST Flow Entry ", serviceId),
             0, 0, COOKIE_TUNNEL.add(BigInteger.valueOf(serviceId)), mkMatches, customInstructions);
 
-        mdsalManager.addFlowToTx(dpnId, terminatingServiceTableFlowEntity, writeFlowInvTx);
+        mdsalManager.addFlow(confTx, dpnId, terminatingServiceTableFlowEntity);
     }
 
     protected InstanceIdentifier<RouterIds> getRoutersIdentifier(long routerId) {
-        InstanceIdentifier<RouterIds> id = InstanceIdentifier.builder(
-            RouterIdName.class).child(RouterIds.class, new RouterIdsKey(routerId)).build();
-        return id;
+        return InstanceIdentifier.builder(RouterIdName.class).child(RouterIds.class,
+            new RouterIdsKey(routerId)).build();
     }
 
     private String getFlowRef(BigInteger dpnId, short tableId, long id, String ipAddress) {
@@ -1274,8 +1292,8 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
         final long finalBgpVpnId = bgpVpnId;
         coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + update.key(), () -> {
             List<ListenableFuture<Void>> futures = new ArrayList<>();
-            futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeFlowInvTx -> {
-                futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(removeFlowInvTx -> {
+            futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, writeFlowInvTx -> {
+                futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, removeFlowInvTx -> {
                     Uuid networkId = original.getNetworkId();
                     if (originalSNATEnabled != updatedSNATEnabled) {
                         if (originalSNATEnabled) {
@@ -1607,7 +1625,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
     }
 
     private void allocateExternalIp(BigInteger dpnId, Routers router, long routerId, String routerName,
-            Uuid networkId, String subnetIp, WriteTransaction writeFlowInvTx) {
+            Uuid networkId, String subnetIp, TypedWriteTransaction<Configuration> writeFlowInvTx) {
         String[] subnetIpParts = NatUtil.getSubnetIpAndPrefix(subnetIp);
         try {
             InetAddress address = InetAddress.getByName(subnetIpParts[0]);
@@ -1711,10 +1729,9 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
 
         String routerName = router.getRouterName();
         coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + router.key(),
-            () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+            () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
                 LOG.info("remove : Removing default NAT route from FIB on all dpns part of router {} ",
                         routerName);
-                List<ListenableFuture<Void>> futures = new ArrayList<>();
                 Long routerId = NatUtil.getVpnId(dataBroker, routerName);
                 if (routerId == NatConstants.INVALID_ID) {
                     LOG.error("remove : Remove external router event - Invalid routerId for routerName {}",
@@ -1753,7 +1770,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
     @SuppressWarnings("checkstyle:IllegalCatch")
     public void handleDisableSnat(Routers router, Uuid networkUuid, @Nonnull Collection<String> externalIps,
                                   boolean routerFlag, String vpnName, BigInteger naptSwitchDpnId,
-                                  long routerId, WriteTransaction removeFlowInvTx) {
+                                  long routerId, TypedReadWriteTransaction<Configuration> removeFlowInvTx) {
         LOG.info("handleDisableSnat : Entry");
         String routerName = router.getRouterName();
         try {
@@ -1816,7 +1833,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
     @SuppressWarnings("checkstyle:IllegalCatch")
     public void handleDisableSnatInternetVpn(String routerName, long routerId, Uuid networkUuid,
                                              @Nonnull Collection<String> externalIps,
-                                             String vpnId, WriteTransaction writeFlowInvTx) {
+                                             String vpnId, TypedReadWriteTransaction<Configuration> writeFlowInvTx) {
         LOG.debug("handleDisableSnatInternetVpn: Started to process handle disable snat for router {} "
                 + "with internet vpn {}", routerName, vpnId);
         try {
@@ -1888,7 +1905,8 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
                                                 BigInteger dpnId, Uuid networkId, String vpnName,
                                                 @Nonnull Collection<String> externalIps,
                                                 Collection<Uuid> externalSubnetList,
-                                                WriteTransaction removeFlowInvTx, ProviderTypes extNwProvType) {
+                                                TypedReadWriteTransaction<Configuration> confTx,
+                                                ProviderTypes extNwProvType) {
         LOG.debug("removeNaptFlowsFromActiveSwitch : Remove NAPT flows from Active switch");
         BigInteger cookieSnatFlow = NatUtil.getCookieNaptFlow(routerId);
 
@@ -1899,7 +1917,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
 
         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.removeFlowToTx(preSnatFlowEntity, removeFlowInvTx);
+        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)
@@ -1909,11 +1927,11 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
         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.removeFlowToTx(tsNatFlowEntity, removeFlowInvTx);
+        mdsalManager.removeFlow(confTx, tsNatFlowEntity);
 
         //Remove the flow table 25->44 from NAPT Switch
         if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
-            NatUtil.removePreDnatToSnatTableEntry(mdsalManager, dpnId, removeFlowInvTx);
+            NatUtil.removePreDnatToSnatTableEntry(confTx, mdsalManager, dpnId);
         }
 
         //Remove the Outbound flow entry which forwards the packet to FIB Table
@@ -1924,21 +1942,21 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
                 NwConstants.IP_PROT_TCP);
         FlowEntity outboundTcpNatFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.OUTBOUND_NAPT_TABLE,
             outboundTcpNatFlowRef);
-        mdsalManager.removeFlowToTx(outboundTcpNatFlowEntity, removeFlowInvTx);
+        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.removeFlowToTx(outboundUdpNatFlowEntity, removeFlowInvTx);
+        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.removeFlowToTx(icmpDropFlowEntity, removeFlowInvTx);
+        mdsalManager.removeFlow(confTx, icmpDropFlowEntity);
 
-        removeNaptFibExternalOutputFlows(routerId, dpnId, networkId, externalIps, removeFlowInvTx);
+        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) {
@@ -1947,7 +1965,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
                 String natPfibSubnetFlowRef = getFlowRefTs(dpnId, NwConstants.NAPT_PFIB_TABLE, subnetVpnId);
                 FlowEntity natPfibFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.NAPT_PFIB_TABLE,
                         natPfibSubnetFlowRef);
-                mdsalManager.removeFlowToTx(natPfibFlowEntity, removeFlowInvTx);
+                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);
@@ -1960,7 +1978,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
 
         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.removeFlowToTx(natPfibFlowEntity, removeFlowInvTx);
+        mdsalManager.removeFlow(confTx, natPfibFlowEntity);
 
         // Long vpnId = NatUtil.getVpnId(dataBroker, routerId);
         // - This does not work since ext-routers is deleted already - no network info
@@ -1990,7 +2008,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
                 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.removeFlowToTx(natPfibVpnFlowEntity, removeFlowInvTx);
+            mdsalManager.removeFlow(confTx, natPfibVpnFlowEntity);
         }
 
         //For the router ID get the internal IP , internal port and the corresponding external IP and external Port.
@@ -2023,7 +2041,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
 
                 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.removeFlowToTx(outboundNaptFlowEntity, removeFlowInvTx);
+                mdsalManager.removeFlow(confTx, outboundNaptFlowEntity);
 
                 IpPortExternal ipPortExternal = ipPortMap.getIpPortExternal();
                 String externalIp = ipPortExternal.getIpAddress();
@@ -2037,14 +2055,14 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
 
                 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.removeFlowToTx(inboundNaptFlowEntity, removeFlowInvTx);
+                mdsalManager.removeFlow(confTx, inboundNaptFlowEntity);
             }
         }
     }
 
     protected void removeNaptFibExternalOutputFlows(long routerId, BigInteger dpnId, Uuid networkId,
                                                     @Nonnull Collection<String> externalIps,
-                                                    WriteTransaction writeFlowInvTx) {
+                                                    TypedReadWriteTransaction<Configuration> writeFlowInvTx) {
         long extVpnId = NatConstants.INVALID_ID;
         if (networkId != null) {
             Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
@@ -2068,7 +2086,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
                 + " with the DPN ID {} and router ID {} and IP {} flowRef {}",
                 NwConstants.NAPT_PFIB_TABLE, dpnId, routerId, extIp, naptFlowRef);
             FlowEntity natPfibVpnFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.NAPT_PFIB_TABLE, naptFlowRef);
-            mdsalManager.removeFlowToTx(natPfibVpnFlowEntity, writeFlowInvTx);
+            mdsalManager.removeFlow(writeFlowInvTx, natPfibVpnFlowEntity);
         }
     }
 
@@ -2081,7 +2099,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
 
     public void removeNaptFlowsFromActiveSwitchInternetVpn(long routerId, String routerName,
                                                            BigInteger dpnId, Uuid networkId, String vpnName,
-                                                           WriteTransaction writeFlowInvTx) {
+                                                           TypedReadWriteTransaction<Configuration> writeFlowInvTx) {
         LOG.debug("removeNaptFlowsFromActiveSwitchInternetVpn : Remove NAPT flows from Active switch Internet Vpn");
         BigInteger cookieSnatFlow = NatUtil.getCookieNaptFlow(routerId);
 
@@ -2104,7 +2122,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
                 NatUtil.buildFlowEntity(dpnId, NwConstants.NAPT_PFIB_TABLE, natPfibVpnFlowRef);
             LOG.info("removeNaptFlowsFromActiveSwitchInternetVpn : Remove the flow in the {} for the active switch "
                     + "with the DPN ID {} and VPN ID {}", NwConstants.NAPT_PFIB_TABLE, dpnId, vpnId);
-            mdsalManager.removeFlowToTx(natPfibVpnFlowEntity, writeFlowInvTx);
+            mdsalManager.removeFlow(writeFlowInvTx, natPfibVpnFlowEntity);
 
             // Remove IP-PORT active NAPT entries and release port from IdManager
             // For the router ID get the internal IP , internal port and the corresponding
@@ -2139,7 +2157,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
                     LOG.info("removeNaptFlowsFromActiveSwitchInternetVpn : Remove the flow in the {} for the "
                             + "active switch with the DPN ID {} and router ID {}",
                             NwConstants.OUTBOUND_NAPT_TABLE, dpnId, routerId);
-                    mdsalManager.removeFlowToTx(outboundNaptFlowEntity, writeFlowInvTx);
+                    mdsalManager.removeFlow(writeFlowInvTx, outboundNaptFlowEntity);
 
                     IpPortExternal ipPortExternal = ipPortMap.getIpPortExternal();
                     String externalIp = ipPortExternal.getIpAddress();
@@ -2154,7 +2172,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
                     LOG.info("removeNaptFlowsFromActiveSwitchInternetVpn : Remove the flow in the {} for the "
                             + "active active switch with the DPN ID {} and router ID {}",
                             NwConstants.INBOUND_NAPT_TABLE, dpnId, routerId);
-                    mdsalManager.removeFlowToTx(inboundNaptFlowEntity, writeFlowInvTx);
+                    mdsalManager.removeFlow(writeFlowInvTx, inboundNaptFlowEntity);
 
                     // Finally release port from idmanager
                     String internalIpPort = internalIp + ":" + internalPort;
@@ -2171,7 +2189,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
     }
 
     public void removeFlowsFromNonActiveSwitches(long routerId, String routerName,
-            BigInteger naptSwitchDpnId, WriteTransaction removeFlowInvTx) {
+            BigInteger naptSwitchDpnId, TypedReadWriteTransaction<Configuration> removeFlowInvTx) {
         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
@@ -2191,7 +2209,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
 
                 LOG.info("removeFlowsFromNonActiveSwitches : Remove the flow in the {} for the non active switch "
                         + "with the DPN ID {} and router ID {}", NwConstants.PSNAT_TABLE, dpnId, routerId);
-                mdsalManager.removeFlowToTx(preSnatFlowEntity, removeFlowInvTx);
+                mdsalManager.removeFlow(removeFlowInvTx, preSnatFlowEntity);
 
                 //Remove the group entry which forwards the traffic to the out port (VXLAN tunnel).
                 long groupId = createGroupId(getGroupIdKey(routerName));
@@ -2201,7 +2219,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
 
                 LOG.info("removeFlowsFromNonActiveSwitches : Remove the group {} for the non active switch with "
                         + "the DPN ID {} and router ID {}", groupId, dpnId, routerId);
-                mdsalManager.removeGroup(preSnatGroupEntity);
+                mdsalManager.removeGroup(removeFlowInvTx, preSnatGroupEntity);
 
             }
         }
@@ -2209,7 +2227,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
 
     public void clrRtsFromBgpAndDelFibTs(final BigInteger dpnId, Long routerId, Uuid networkUuid,
                                          @Nonnull Collection<String> externalIps, String vpnName,
-                                         String extGwMacAddress, WriteTransaction removeFlowInvTx) {
+                                         String extGwMacAddress, TypedReadWriteTransaction<Configuration> confTx) {
         //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 {},"
@@ -2238,13 +2256,13 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
         //Remove custom FIB routes
         //Future<RpcResult<java.lang.Void>> removeFibEntry(RemoveFibEntryInput input);
         for (String extIp : externalIps) {
-            clrRtsFromBgpAndDelFibTs(dpnId, routerId, extIp, vpnName, networkUuid, extGwMacAddress, removeFlowInvTx);
+            clrRtsFromBgpAndDelFibTs(dpnId, routerId, extIp, vpnName, networkUuid, extGwMacAddress, confTx);
         }
     }
 
     protected void clrRtsFromBgpAndDelFibTs(final BigInteger dpnId, long routerId, String extIp, final String vpnName,
                                             final Uuid networkUuid, String extGwMacAddress,
-                                            WriteTransaction removeFlowInvTx) {
+                                            TypedReadWriteTransaction<Configuration> removeFlowInvTx) {
         clearBgpRoutes(extIp, vpnName);
         delFibTsAndReverseTraffic(dpnId, routerId, extIp, vpnName, networkUuid, extGwMacAddress, false,
                 removeFlowInvTx);
@@ -2253,7 +2271,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
     protected void delFibTsAndReverseTraffic(final BigInteger dpnId, long routerId, String extIp,
                                              final String vpnName, Uuid extNetworkId, long tempLabel,
                                              String gwMacAddress, boolean switchOver,
-                                             WriteTransaction removeFlowInvTx) {
+                                             TypedReadWriteTransaction<Configuration> removeFlowInvTx) {
         LOG.debug("delFibTsAndReverseTraffic : Removing fib entry for externalIp {} in routerId {}", extIp, routerId);
         String routerName = NatUtil.getRouterName(dataBroker,routerId);
         if (routerName == null) {
@@ -2269,8 +2287,8 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
          * external network provided type is VxLAN
          */
         if (extNwProvType == ProviderTypes.VXLAN) {
-            evpnSnatFlowProgrammer.evpnDelFibTsAndReverseTraffic(dpnId, routerId, extIp, vpnName, gwMacAddress,
-                    removeFlowInvTx);
+            evpnSnatFlowProgrammer.evpnDelFibTsAndReverseTraffic(dpnId, routerId, extIp, vpnName, gwMacAddress
+            );
             return;
         }
         if (tempLabel < 0) {
@@ -2290,25 +2308,25 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
         removeLFibTableEntry(dpnId, label, removeFlowInvTx);
         if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
             //Remove the flow table 25->44 If there is no FIP Match on table 25 (PDNAT_TABLE)
-            NatUtil.removePreDnatToSnatTableEntry(mdsalManager, dpnId, removeFlowInvTx);
+            NatUtil.removePreDnatToSnatTableEntry(removeFlowInvTx, mdsalManager, dpnId);
         }
         if (!switchOver) {
             ListenableFuture<RpcResult<RemoveVpnLabelOutput>> labelFuture =
-                    Futures.transformAsync(future, result -> {
-                                //Release label
-                        if (result.isSuccessful()) {
-                            NatUtil.removePreDnatToSnatTableEntry(mdsalManager, dpnId, removeFlowInvTx);
-                            RemoveVpnLabelInput labelInput = new RemoveVpnLabelInputBuilder()
-                                    .setVpnName(vpnName).setIpPrefix(externalIp).build();
-                            return vpnService.removeVpnLabel(labelInput);
-                        } else {
-                            String errMsg =
-                                    String.format("RPC call to remove custom FIB entries on dpn %s for "
-                                            + "prefix %s Failed - %s", dpnId, externalIp, result.getErrors());
-                            LOG.error(errMsg);
-                            return Futures.immediateFailedFuture(new RuntimeException(errMsg));
-                        }
-                    }, MoreExecutors.directExecutor());
+                Futures.transformAsync(future, result -> {
+                    //Release label
+                    if (result.isSuccessful()) {
+                        NatUtil.removePreDnatToSnatTableEntry(removeFlowInvTx, mdsalManager, dpnId);
+                        RemoveVpnLabelInput labelInput = new RemoveVpnLabelInputBuilder()
+                            .setVpnName(vpnName).setIpPrefix(externalIp).build();
+                        return vpnService.removeVpnLabel(labelInput);
+                    } else {
+                        String errMsg =
+                            String.format("RPC call to remove custom FIB entries on dpn %s for "
+                                + "prefix %s Failed - %s", dpnId, externalIp, result.getErrors());
+                        LOG.error(errMsg);
+                        return Futures.immediateFailedFuture(new RuntimeException(errMsg));
+                    }
+                }, MoreExecutors.directExecutor());
 
             Futures.addCallback(labelFuture, new FutureCallback<RpcResult<RemoveVpnLabelOutput>>() {
 
@@ -2337,7 +2355,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
 
     private void delFibTsAndReverseTraffic(final BigInteger dpnId, long routerId, String extIp, final String vpnName,
                                            final Uuid networkUuid, String extGwMacAddress, boolean switchOver,
-                                           WriteTransaction removeFlowInvTx) {
+                                           TypedReadWriteTransaction<Configuration> removeFlowInvTx) {
         LOG.debug("delFibTsAndReverseTraffic : Removing fib entry for externalIp {} in routerId {}", extIp, routerId);
         String routerName = NatUtil.getRouterName(dataBroker,routerId);
         if (routerName == null) {
@@ -2355,8 +2373,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
          *  external network provided type is VxLAN
          */
         if (extNwProvType == ProviderTypes.VXLAN) {
-            evpnSnatFlowProgrammer.evpnDelFibTsAndReverseTraffic(dpnId, routerId, extIp, vpnName, extGwMacAddress,
-                    removeFlowInvTx);
+            evpnSnatFlowProgrammer.evpnDelFibTsAndReverseTraffic(dpnId, routerId, extIp, vpnName, extGwMacAddress);
             return;
         }
         //Get IPMaps from the DB for the router ID
@@ -2395,7 +2412,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
         removeLFibTableEntry(dpnId, label, removeFlowInvTx);
         if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
             //Remove the flow table 25->44 If there is no FIP Match on table 25 (PDNAT_TABLE)
-            NatUtil.removePreDnatToSnatTableEntry(mdsalManager, dpnId, removeFlowInvTx);
+            NatUtil.removePreDnatToSnatTableEntry(removeFlowInvTx, mdsalManager, dpnId);
         }
         if (!switchOver) {
             ListenableFuture<RpcResult<RemoveVpnLabelOutput>> labelFuture =
@@ -2441,7 +2458,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
 
     protected void clearFibTsAndReverseTraffic(final BigInteger dpnId, Long routerId, Uuid networkUuid,
                                                List<String> externalIps, String vpnName, String extGwMacAddress,
-                                               WriteTransaction writeFlowInvTx) {
+                                               TypedReadWriteTransaction<Configuration> writeFlowInvTx) {
         //Withdraw the corresponding routes from the BGP.
         //Get the network ID using the router ID.
         LOG.debug("clearFibTsAndReverseTraffic : for externalIps {} with routerId {},"
@@ -2482,7 +2499,8 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
         NatUtil.removePrefixFromBGP(bgpManager, fibManager, rd, externalIp, vpnName, LOG);
     }
 
-    private void removeTunnelTableEntry(BigInteger dpnId, long serviceId, WriteTransaction writeFlowInvTx) {
+    private void removeTunnelTableEntry(BigInteger dpnId, long serviceId,
+        TypedReadWriteTransaction<Configuration> writeFlowInvTx) {
         LOG.info("removeTunnelTableEntry : called with DpnId = {} and label = {}", dpnId, serviceId);
         List<MatchInfo> mkMatches = new ArrayList<>();
         // Matching metadata
@@ -2491,11 +2509,12 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
             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);
-        mdsalManager.removeFlowToTx(dpnId, flowEntity, writeFlowInvTx);
+        mdsalManager.removeFlow(writeFlowInvTx, dpnId, flowEntity);
         LOG.debug("removeTunnelTableEntry : dpID {} : label : {} removed successfully", dpnId, serviceId);
     }
 
-    private void removeLFibTableEntry(BigInteger dpnId, long serviceId, WriteTransaction writeFlowInvTx) {
+    private void removeLFibTableEntry(BigInteger dpnId, long serviceId,
+        TypedReadWriteTransaction<Configuration> writeFlowInvTx) {
         List<MatchInfo> matches = new ArrayList<>();
         matches.add(MatchEthernetType.MPLS_UNICAST);
         matches.add(new MatchMplsLabel(serviceId));
@@ -2508,7 +2527,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
             10, flowRef, 0, 0,
             COOKIE_VM_LFIB_TABLE, matches, null);
 
-        mdsalManager.removeFlowToTx(dpnId, flowEntity, writeFlowInvTx);
+        mdsalManager.removeFlow(writeFlowInvTx, dpnId, flowEntity);
 
         LOG.debug("removeLFibTableEntry : dpID : {} label : {} removed successfully", dpnId, serviceId);
     }
@@ -2521,7 +2540,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
      * @param bgpVpnName BGP VPN name
      */
     public void changeLocalVpnIdToBgpVpnId(String routerName, long routerId, String bgpVpnName,
-            WriteTransaction writeFlowInvTx, ProviderTypes extNwProvType) {
+            TypedWriteTransaction<Configuration> writeFlowInvTx, ProviderTypes extNwProvType) {
         LOG.debug("changeLocalVpnIdToBgpVpnId : Router associated to BGP VPN");
         if (chkExtRtrAndSnatEnbl(new Uuid(routerName))) {
             long bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnName);
@@ -2541,7 +2560,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
 
                 LOG.debug("changeLocalVpnIdToBgpVpnId : Update the Router ID {} to the BGP VPN ID {} ",
                         routerId, bgpVpnId);
-                addOrDelDefaultFibRouteForSnatWithBgpVpn(routerName, routerId, bgpVpnId, true, writeFlowInvTx);
+                addDefaultFibRouteForSnatWithBgpVpn(routerName, routerId, bgpVpnId, writeFlowInvTx);
 
                 // Get the group ID
                 BigInteger primarySwitchId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
@@ -2560,7 +2579,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
      * @param bgpVpnName BGP VPN name
      */
     public void changeBgpVpnIdToLocalVpnId(String routerName, long routerId, String bgpVpnName,
-            WriteTransaction writeFlowInvTx, ProviderTypes extNwProvType) {
+            TypedWriteTransaction<Configuration> writeFlowInvTx, ProviderTypes extNwProvType) {
         LOG.debug("changeBgpVpnIdToLocalVpnId : Router dissociated from BGP VPN");
         if (chkExtRtrAndSnatEnbl(new Uuid(routerName))) {
             long bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnName);
@@ -2570,8 +2589,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
             LOG.debug("changeBgpVpnIdToLocalVpnId : Router ID value {} ", routerId);
 
             LOG.debug("changeBgpVpnIdToLocalVpnId : Update the BGP VPN ID {} to the Router ID {}", bgpVpnId, routerId);
-            addOrDelDefaultFibRouteForSnatWithBgpVpn(routerName, routerId, NatConstants.INVALID_ID,
-                    true, writeFlowInvTx);
+            addDefaultFibRouteForSnatWithBgpVpn(routerName, routerId, NatConstants.INVALID_ID, writeFlowInvTx);
 
             // Get the group ID
             createGroupId(getGroupIdKey(routerName));
@@ -2590,8 +2608,8 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
     }
 
     public void installFlowsWithUpdatedVpnId(BigInteger primarySwitchId, String routerName, long bgpVpnId,
-                                             long routerId, boolean isSnatCfgd, WriteTransaction writeFlowInvTx,
-                                             ProviderTypes extNwProvType) {
+        long routerId, boolean isSnatCfgd, TypedWriteTransaction<Configuration> confTx, ProviderTypes extNwProvType) {
+
         long changedVpnId = bgpVpnId;
         String idType = "BGP VPN";
         if (bgpVpnId == NatConstants.INVALID_ID) {
@@ -2619,33 +2637,33 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
                         "installFlowsWithUpdatedVpnId : Update the {} ID {} in the SNAT miss entry pointing to group "
                                 + "{} in the non NAPT switch {}", idType, changedVpnId, groupId, dpnId);
                 FlowEntity flowEntity = buildSnatFlowEntityWithUpdatedVpnId(dpnId, routerName, groupId, changedVpnId);
-                mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
+                mdsalManager.addFlow(confTx, flowEntity);
             } else {
                 LOG.debug(
                         "installFlowsWithUpdatedVpnId : Update the {} ID {} in the SNAT miss entry pointing to group "
                                 + "in the primary switch {}", idType, changedVpnId, primarySwitchId);
                 FlowEntity flowEntity =
                     buildSnatFlowEntityWithUpdatedVpnIdForPrimrySwtch(primarySwitchId, routerName, changedVpnId);
-                mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
+                mdsalManager.addFlow(confTx, flowEntity);
 
                 LOG.debug(
                         "installFlowsWithUpdatedVpnId : Update the {} ID {} in the Terminating Service table (table "
                                 + "ID 36) which forwards the packet to the table 46 in the Primary switch {}",
                         idType, changedVpnId, primarySwitchId);
                 installTerminatingServiceTblEntryWithUpdatedVpnId(primarySwitchId, routerName, routerId,
-                        changedVpnId, writeFlowInvTx, extNwProvType);
+                        changedVpnId, confTx, extNwProvType);
 
                 LOG.debug(
                         "installFlowsWithUpdatedVpnId : Update the {} ID {} in the Outbound NAPT table (table ID 46) "
                                 + "which punts the packet to the controller in the Primary switch {}",
                         idType, changedVpnId, primarySwitchId);
-                createOutboundTblEntryWithBgpVpn(primarySwitchId, routerId, changedVpnId, writeFlowInvTx);
+                createOutboundTblEntryWithBgpVpn(primarySwitchId, routerId, changedVpnId, confTx);
 
                 LOG.debug(
                         "installFlowsWithUpdatedVpnId : Update the {} ID {} in the NAPT PFIB TABLE which forwards the"
                                 + " outgoing packet to FIB Table in the Primary switch {}",
                         idType, changedVpnId, primarySwitchId);
-                installNaptPfibEntryWithBgpVpn(primarySwitchId, routerId, changedVpnId, writeFlowInvTx);
+                installNaptPfibEntryWithBgpVpn(primarySwitchId, routerId, changedVpnId, confTx);
 
                 LOG.debug(
                         "installFlowsWithUpdatedVpnId : Update the {} ID {} in the NAPT flows for the Outbound NAPT "
@@ -2658,7 +2676,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
                 Long vpnId = NatUtil.getNetworkVpnIdFromRouterId(dataBroker, routerId);
                 //Install the NAPT PFIB TABLE which forwards the outgoing packet to FIB Table matching on the VPN ID.
                 if (vpnId != NatConstants.INVALID_ID) {
-                    installNaptPfibEntry(primarySwitchId, vpnId, writeFlowInvTx);
+                    installNaptPfibEntry(primarySwitchId, vpnId, confTx);
                 }
             }
         }
@@ -2769,12 +2787,13 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
 
     // TODO : Replace this with ITM Rpc once its available with full functionality
     protected void installTerminatingServiceTblEntryWithUpdatedVpnId(BigInteger dpnId, String routerName,
-            long routerId, long changedVpnId, WriteTransaction writeFlowInvTx, ProviderTypes extNwProvType) {
+        long routerId, long changedVpnId, TypedWriteTransaction<Configuration> confTx, ProviderTypes extNwProvType) {
+
         LOG.debug("installTerminatingServiceTblEntryWithUpdatedVpnId : called for switch {}, "
             + "routerName {}, BGP VPN ID {}", dpnId, routerName, changedVpnId);
         FlowEntity flowEntity = buildTsFlowEntityWithUpdatedVpnId(dpnId, routerName, routerId, changedVpnId,
                 extNwProvType);
-        mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
+        mdsalManager.addFlow(confTx, flowEntity);
     }
 
     private FlowEntity buildTsFlowEntityWithUpdatedVpnId(BigInteger dpId, String routerName,
@@ -2803,22 +2822,22 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
     }
 
     public void createOutboundTblEntryWithBgpVpn(BigInteger dpnId, long routerId, long changedVpnId,
-                                                 WriteTransaction writeFlowInvTx) {
+                                                 TypedWriteTransaction<Configuration> writeFlowInvTx) {
         LOG.debug("createOutboundTblEntryWithBgpVpn : called for dpId {} and routerId {}, BGP VPN ID {}",
             dpnId, routerId, changedVpnId);
         FlowEntity tcpFlowEntity = buildOutboundFlowEntityWithBgpVpn(dpnId, routerId, changedVpnId,
                 NwConstants.IP_PROT_TCP);
         LOG.debug("createOutboundTblEntryWithBgpVpn : Installing tcp flow {}", tcpFlowEntity);
-        mdsalManager.addFlowToTx(tcpFlowEntity, writeFlowInvTx);
+        mdsalManager.addFlow(writeFlowInvTx, tcpFlowEntity);
 
         FlowEntity udpFlowEntity = buildOutboundFlowEntityWithBgpVpn(dpnId, routerId, changedVpnId,
                 NwConstants.IP_PROT_UDP);
         LOG.debug("createOutboundTblEntryWithBgpVpn : Installing udp flow {}", udpFlowEntity);
-        mdsalManager.addFlowToTx(udpFlowEntity, writeFlowInvTx);
+        mdsalManager.addFlow(writeFlowInvTx, udpFlowEntity);
 
         FlowEntity icmpDropFlow = buildIcmpDropFlow(dpnId, routerId, changedVpnId);
         LOG.debug("createOutboundTblEntry: Installing icmp drop flow {}", icmpDropFlow);
-        mdsalManager.addFlowToTx(icmpDropFlow, writeFlowInvTx);
+        mdsalManager.addFlow(writeFlowInvTx, icmpDropFlow);
     }
 
     protected FlowEntity buildOutboundFlowEntityWithBgpVpn(BigInteger dpId, long routerId,
@@ -2847,11 +2866,11 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
     }
 
     public void installNaptPfibEntryWithBgpVpn(BigInteger dpnId, long segmentId, long changedVpnId,
-                                               WriteTransaction writeFlowInvTx) {
+                                               TypedWriteTransaction<Configuration> writeFlowInvTx) {
         LOG.debug("installNaptPfibEntryWithBgpVpn : called for dpnId {} and segmentId {} ,BGP VPN ID {}",
             dpnId, segmentId, changedVpnId);
         FlowEntity naptPfibFlowEntity = buildNaptPfibFlowEntityWithUpdatedVpnId(dpnId, segmentId, changedVpnId);
-        mdsalManager.addFlowToTx(naptPfibFlowEntity, writeFlowInvTx);
+        mdsalManager.addFlow(writeFlowInvTx, naptPfibFlowEntity);
     }
 
     public FlowEntity buildNaptPfibFlowEntityWithUpdatedVpnId(BigInteger dpId, long segmentId, long changedVpnId) {
@@ -2882,7 +2901,7 @@ public class ExternalRoutersListener extends AsyncDataTreeChangeListenerBase<Rou
     }
 
     protected void installNaptPfibEntriesForExternalSubnets(String routerName, BigInteger dpnId,
-                                                            WriteTransaction writeFlowInvTx) {
+                                                            TypedWriteTransaction<Configuration> writeFlowInvTx) {
         Collection<Uuid> externalSubnetIdsForRouter = NatUtil.getExternalSubnetIdsForRouter(dataBroker,
                 routerName);
         for (Uuid externalSubnetId : externalSubnetIdsForRouter) {
index 4da0ded867412936aa486f77fd9791d4d58eb5f4..8fa8118615090424eccc8dd6334c9d1c5940cdea 100644 (file)
@@ -9,7 +9,8 @@ package org.opendaylight.netvirt.natservice.internal;
 
 import java.math.BigInteger;
 
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.genius.infra.Datastore.Configuration;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap;
@@ -17,11 +18,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev16011
 public interface FloatingIPHandler {
 
     void onAddFloatingIp(BigInteger dpnId, String routerUuid, long routerId, Uuid networkId, String interfaceName,
-                         InternalToExternalPortMap mapping, WriteTransaction writeFlowInvTx);
+                         InternalToExternalPortMap mapping, TypedReadWriteTransaction<Configuration> confTx);
 
     void onRemoveFloatingIp(BigInteger dpnId, String routerUuid, long routerId, Uuid networkId,
-                            InternalToExternalPortMap mapping, long label, WriteTransaction removeFlowInvTx);
+                            InternalToExternalPortMap mapping, long label,
+                            TypedReadWriteTransaction<Configuration> confTx);
 
     void cleanupFibEntries(BigInteger dpnId, String vpnName, String externalIp, long label,
-                           WriteTransaction removeFlowInvTx, ProviderTypes provType);
+                           TypedReadWriteTransaction<Configuration> confTx, ProviderTypes provType);
 }
index e943de3a524c76b313cd698286cadc207130d46c..0891ad544d540ac442953915c4f0ae83d5562733 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.netvirt.natservice.internal;
 
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
 import com.google.common.base.Optional;
 import java.math.BigInteger;
 import java.net.InetAddress;
@@ -18,12 +20,13 @@ import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
+import org.opendaylight.genius.infra.Datastore.Configuration;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
 import org.opendaylight.genius.mdsalutil.ActionInfo;
 import org.opendaylight.genius.mdsalutil.FlowEntity;
 import org.opendaylight.genius.mdsalutil.InstructionInfo;
@@ -283,52 +286,52 @@ public class FloatingIPListener extends AsyncDataTreeChangeListenerBase<Internal
     }
 
     private void createDNATTblEntry(BigInteger dpnId, InternalToExternalPortMap mapping, long routerId,
-                                    long associatedVpnId, WriteTransaction writeFlowInvTx) {
+                                    long associatedVpnId, TypedReadWriteTransaction<Configuration> confTx) {
         FlowEntity preFlowEntity = buildPreDNATFlowEntity(dpnId, mapping, routerId, associatedVpnId);
         if (preFlowEntity == null) {
             LOG.error("createDNATTblEntry : Flow entity received as NULL. "
                     + "Cannot proceed with installation of Pre-DNAT flow table {} --> table {} on DpnId {}",
                     NwConstants.PDNAT_TABLE, NwConstants.DNAT_TABLE, dpnId);
         } else {
-            mdsalManager.addFlowToTx(preFlowEntity, writeFlowInvTx);
+            mdsalManager.addFlow(confTx, preFlowEntity);
             FlowEntity flowEntity = buildDNATFlowEntity(dpnId, mapping, routerId, associatedVpnId);
             if (flowEntity != null) {
-                mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
+                mdsalManager.addFlow(confTx, flowEntity);
             }
         }
     }
 
     private void removeDNATTblEntry(BigInteger dpnId, String internalIp, String externalIp, long routerId,
-                                    WriteTransaction removeFlowInvTx) {
+        TypedReadWriteTransaction<Configuration> confTx) {
         FlowEntity preFlowEntity = buildPreDNATDeleteFlowEntity(dpnId, externalIp, routerId);
-        mdsalManager.removeFlowToTx(preFlowEntity, removeFlowInvTx);
+        mdsalManager.removeFlow(confTx, preFlowEntity);
 
         FlowEntity flowEntity = buildDNATDeleteFlowEntity(dpnId, internalIp, routerId);
         if (flowEntity != null) {
-            mdsalManager.removeFlowToTx(flowEntity, removeFlowInvTx);
+            mdsalManager.removeFlow(confTx, flowEntity);
         }
     }
 
     private void createSNATTblEntry(BigInteger dpnId, InternalToExternalPortMap mapping, long vpnId, long routerId,
-                                    long associatedVpnId, Uuid externalNetworkId, WriteTransaction writeFlowInvTx) {
+        long associatedVpnId, Uuid externalNetworkId, TypedReadWriteTransaction<Configuration> confTx) {
         FlowEntity preFlowEntity = buildPreSNATFlowEntity(dpnId, mapping.getInternalIp(), mapping.getExternalIp(),
             vpnId, routerId, associatedVpnId);
-        mdsalManager.addFlowToTx(preFlowEntity, writeFlowInvTx);
+        mdsalManager.addFlow(confTx, preFlowEntity);
 
         FlowEntity flowEntity = buildSNATFlowEntity(dpnId, mapping, vpnId, externalNetworkId);
         if (flowEntity != null) {
-            mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
+            mdsalManager.addFlow(confTx, flowEntity);
         }
     }
 
     private void removeSNATTblEntry(BigInteger dpnId, String internalIp, String externalIp, long routerId, long vpnId,
-                                    WriteTransaction removeFlowInvTx) {
+                                    TypedReadWriteTransaction<Configuration> removeFlowInvTx) {
         FlowEntity preFlowEntity = buildPreSNATDeleteFlowEntity(dpnId, internalIp, routerId);
-        mdsalManager.removeFlowToTx(preFlowEntity, removeFlowInvTx);
+        mdsalManager.removeFlow(removeFlowInvTx, preFlowEntity);
 
         FlowEntity flowEntity = buildSNATDeleteFlowEntity(dpnId, externalIp, vpnId);
         if (flowEntity != null) {
-            mdsalManager.removeFlowToTx(flowEntity, removeFlowInvTx);
+            mdsalManager.removeFlow(removeFlowInvTx, flowEntity);
         }
     }
 
@@ -386,7 +389,7 @@ public class FloatingIPListener extends AsyncDataTreeChangeListenerBase<Internal
 
         InstanceIdentifier<RouterPorts> portIid = identifier.firstIdentifierOf(RouterPorts.class);
         coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + mapping.key(), () -> Collections.singletonList(
-                txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+                txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
                     tx -> createNATFlowEntries(interfaceName, mapping, portIid, routerId, tx))),
                 NatConstants.NAT_DJC_MAX_RETRIES);
     }
@@ -401,7 +404,7 @@ public class FloatingIPListener extends AsyncDataTreeChangeListenerBase<Internal
 
         InstanceIdentifier<RouterPorts> portIid = identifier.firstIdentifierOf(RouterPorts.class);
         coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + mapping.key(), () -> Collections.singletonList(
-                txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+                txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
                     tx -> removeNATFlowEntries(interfaceName, mapping, portIid, routerId, null, tx))),
                 NatConstants.NAT_DJC_MAX_RETRIES);
     }
@@ -422,7 +425,7 @@ public class FloatingIPListener extends AsyncDataTreeChangeListenerBase<Internal
 
     void createNATFlowEntries(String interfaceName, final InternalToExternalPortMap mapping,
                               final InstanceIdentifier<RouterPorts> portIid, final String routerName,
-                              WriteTransaction writeFlowInvTx) {
+        TypedReadWriteTransaction<Configuration> confTx) {
         if (!validateIpMapping(mapping)) {
             LOG.error("createNATFlowEntries : Not a valid ip addresses in the mapping {}", mapping);
             return;
@@ -472,16 +475,16 @@ public class FloatingIPListener extends AsyncDataTreeChangeListenerBase<Internal
         //Install the DNAT default FIB flow L3_FIB_TABLE (21) -> PSNAT_TABLE (26) if SNAT is disabled
         boolean isSnatEnabled = NatUtil.isSnatEnabledForRouterId(dataBroker, routerName);
         if (!isSnatEnabled) {
-            addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, writeFlowInvTx, true);
+            addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, confTx, true);
         }
         //Create the DNAT and SNAT table entries
-        createDNATTblEntry(dpnId, mapping, routerId, associatedVpnId, writeFlowInvTx);
-        createSNATTblEntry(dpnId, mapping, vpnId, routerId, associatedVpnId, extNwId, writeFlowInvTx);
-        floatingIPHandler.onAddFloatingIp(dpnId, routerName, routerId, extNwId, interfaceName, mapping, writeFlowInvTx);
+        createDNATTblEntry(dpnId, mapping, routerId, associatedVpnId, confTx);
+        createSNATTblEntry(dpnId, mapping, vpnId, routerId, associatedVpnId, extNwId, confTx);
+        floatingIPHandler.onAddFloatingIp(dpnId, routerName, routerId, extNwId, interfaceName, mapping, confTx);
     }
 
     void createNATFlowEntries(BigInteger dpnId,  String interfaceName, String routerName, Uuid externalNetworkId,
-                              InternalToExternalPortMap mapping, WriteTransaction writeFlowInvTx) {
+                              InternalToExternalPortMap mapping, TypedReadWriteTransaction<Configuration> confTx) {
         String internalIp = mapping.getInternalIp();
         long routerId = NatUtil.getVpnId(dataBroker, routerName);
         if (routerId == NatConstants.INVALID_ID) {
@@ -507,13 +510,13 @@ public class FloatingIPListener extends AsyncDataTreeChangeListenerBase<Internal
         //Install the DNAT default FIB flow L3_FIB_TABLE (21) -> PSNAT_TABLE (26) if SNAT is disabled
         boolean isSnatEnabled = NatUtil.isSnatEnabledForRouterId(dataBroker, routerName);
         if (!isSnatEnabled) {
-            addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, writeFlowInvTx, true);
+            addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, confTx, true);
         }
         //Create the DNAT and SNAT table entries
-        createDNATTblEntry(dpnId, mapping, routerId, associatedVpnId, writeFlowInvTx);
-        createSNATTblEntry(dpnId, mapping, vpnId, routerId, associatedVpnId, externalNetworkId, writeFlowInvTx);
+        createDNATTblEntry(dpnId, mapping, routerId, associatedVpnId, confTx);
+        createSNATTblEntry(dpnId, mapping, vpnId, routerId, associatedVpnId, externalNetworkId, confTx);
         floatingIPHandler.onAddFloatingIp(dpnId, routerName, routerId, externalNetworkId, interfaceName, mapping,
-                writeFlowInvTx);
+                confTx);
     }
 
     void createNATOnlyFlowEntries(BigInteger dpnId, String routerName, String associatedVPN,
@@ -560,7 +563,7 @@ public class FloatingIPListener extends AsyncDataTreeChangeListenerBase<Internal
 
     void removeNATFlowEntries(String interfaceName, final InternalToExternalPortMap mapping,
                               InstanceIdentifier<RouterPorts> portIid, final String routerName, BigInteger dpnId,
-                              WriteTransaction removeFlowInvTx) {
+                              TypedReadWriteTransaction<Configuration> removeFlowInvTx) {
         String internalIp = mapping.getInternalIp();
         String externalIp = mapping.getExternalIp();
         //Get the DPN on which this interface resides
@@ -624,7 +627,7 @@ public class FloatingIPListener extends AsyncDataTreeChangeListenerBase<Internal
     }
 
     void removeNATFlowEntries(BigInteger dpnId, String interfaceName, String vpnName, String routerName,
-                              InternalToExternalPortMap mapping, WriteTransaction removeFlowInvTx) {
+                              InternalToExternalPortMap mapping, TypedReadWriteTransaction<Configuration> confTx) {
         String internalIp = mapping.getInternalIp();
         String externalIp = mapping.getExternalIp();
         long routerId = NatUtil.getVpnId(dataBroker, routerName);
@@ -641,12 +644,12 @@ public class FloatingIPListener extends AsyncDataTreeChangeListenerBase<Internal
         }
 
         //Delete the DNAT and SNAT table entries
-        removeDNATTblEntry(dpnId, internalIp, externalIp, routerId, removeFlowInvTx);
-        removeSNATTblEntry(dpnId, internalIp, externalIp, routerId, vpnId, removeFlowInvTx);
+        removeDNATTblEntry(dpnId, internalIp, externalIp, routerId, confTx);
+        removeSNATTblEntry(dpnId, internalIp, externalIp, routerId, vpnId, confTx);
         //Remove the DNAT default FIB flow L3_FIB_TABLE (21) -> PSNAT_TABLE (26) if SNAT is disabled
         boolean isSnatEnabled = NatUtil.isSnatEnabledForRouterId(dataBroker, routerName);
         if (!isSnatEnabled) {
-            addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, removeFlowInvTx, false);
+            addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, confTx, false);
         }
         Uuid externalNetworkId = NatUtil.getNetworkIdFromRouterName(dataBroker,routerName);
         ProviderTypes provType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, externalNetworkId);
@@ -656,7 +659,7 @@ public class FloatingIPListener extends AsyncDataTreeChangeListenerBase<Internal
         }
         if (provType == ProviderTypes.VXLAN) {
             floatingIPHandler.cleanupFibEntries(dpnId, vpnName, externalIp, NatConstants.DEFAULT_L3VNI_VALUE,
-                    removeFlowInvTx, provType);
+                    confTx, provType);
             removeOperationalDS(routerName, interfaceName, internalIp);
             return;
         }
@@ -666,7 +669,7 @@ public class FloatingIPListener extends AsyncDataTreeChangeListenerBase<Internal
                     internalIp, routerId);
             return;
         }
-        floatingIPHandler.cleanupFibEntries(dpnId, vpnName, externalIp, label, removeFlowInvTx, provType);
+        floatingIPHandler.cleanupFibEntries(dpnId, vpnName, externalIp, label, confTx, provType);
         removeOperationalDS(routerName, interfaceName, internalIp);
     }
 
@@ -767,10 +770,10 @@ public class FloatingIPListener extends AsyncDataTreeChangeListenerBase<Internal
         return flowEntity;
     }
 
-    private void addOrDelDefaultFibRouteForDnat(BigInteger dpnId, String routerName,
-                                                long routerId, WriteTransaction tx, boolean create) {
-        if (tx == null) {
-            ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+    private void addOrDelDefaultFibRouteForDnat(BigInteger dpnId, String routerName, long routerId,
+        TypedReadWriteTransaction<Configuration> confTx, boolean create) {
+        if (confTx == null) {
+            ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
                 newTx -> addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, newTx, create)), LOG,
                 "Error handling default FIB route for DNAT");
             return;
@@ -785,21 +788,21 @@ public class FloatingIPListener extends AsyncDataTreeChangeListenerBase<Internal
             if (associatedVpnId != NatConstants.INVALID_ID) {
                 LOG.debug("addOrDelDefaultFibRouteForDnat: Install NAT default route on DPN {} for the router {} with "
                         + "vpn-id {}", dpnId, routerName, associatedVpnId);
-                defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, associatedVpnId, routerId, tx);
+                defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, associatedVpnId, routerId, confTx);
             } else {
                 LOG.debug("addOrDelDefaultFibRouteForDnat: Install NAT default route on DPN {} for the router {} with "
                         + "vpn-id {}", dpnId, routerName, routerId);
-                defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, routerId, tx);
+                defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, routerId, confTx);
             }
         } else {
             if (associatedVpnId != NatConstants.INVALID_ID) {
                 LOG.debug("addOrDelDefaultFibRouteForDnat: Remove NAT default route on DPN {} for the router {} "
                         + "with vpn-id {}", dpnId, routerName, associatedVpnId);
-                defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, associatedVpnId, routerId, tx);
+                defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, associatedVpnId, routerId, confTx);
             } else {
                 LOG.debug("addOrDelDefaultFibRouteForDnat: Remove NAT default route on DPN {} for the router {} "
                         + "with vpn-id {}", dpnId, routerName, routerId);
-                defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, routerId, tx);
+                defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, routerId, confTx);
             }
         }
     }
index dca3fc2ab02ebe0d1f11360c7b6104ab5983e7cd..09586499c66d0bd50ed70817b1660bacc4168834 100644 (file)
@@ -22,11 +22,9 @@ import javax.annotation.Nonnull;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
 import org.opendaylight.genius.infra.Datastore.Configuration;
-import org.opendaylight.genius.infra.TransactionAdapter;
 import org.opendaylight.genius.infra.TypedReadWriteTransaction;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
 import org.opendaylight.genius.mdsalutil.ActionInfo;
@@ -181,7 +179,6 @@ public class NaptSwitchHA {
     protected void removeSnatFlowsInOldNaptSwitch(String routerName, Long routerId, BigInteger naptSwitch,
                                                   Map<String, Long> externalIpmap,
                                                   TypedReadWriteTransaction<Configuration> confTx) {
-        WriteTransaction removeFlowInvTx = TransactionAdapter.toWriteTransaction(confTx);
 
         //remove SNAT flows in old NAPT SWITCH
         Uuid networkId = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
@@ -198,8 +195,7 @@ public class NaptSwitchHA {
             return;
         }
         if (extNwProvType == ProviderTypes.VXLAN) {
-            evpnNaptSwitchHA.evpnRemoveSnatFlowsInOldNaptSwitch(routerName, routerId, vpnName, naptSwitch,
-                    removeFlowInvTx);
+            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,
@@ -215,7 +211,7 @@ public class NaptSwitchHA {
         }
         if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
             //Remove the flow table 25->44 If there is no FIP Match on table 25 (PDNAT_TABLE)
-            NatUtil.removePreDnatToSnatTableEntry(mdsalManager, naptSwitch, removeFlowInvTx);
+            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 {}",
@@ -309,7 +305,7 @@ public class NaptSwitchHA {
                 String externalIp = entry.getKey();
                 Long label = entry.getValue();
                 externalRouterListener.delFibTsAndReverseTraffic(naptSwitch, routerId, externalIp, vpnName,
-                        extNetworkId, label, gwMacAddress, true, removeFlowInvTx);
+                        extNetworkId, label, gwMacAddress, true, confTx);
                 LOG.debug("removeSnatFlowsInOldNaptSwitch : Successfully removed fib entries in old naptswitch {} "
                         + "for router {} and externalIps {} label {}", naptSwitch, routerId, externalIp, label);
             }
@@ -317,7 +313,7 @@ public class NaptSwitchHA {
             List<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerName);
             if (networkId != null) {
                 externalRouterListener.clearFibTsAndReverseTraffic(naptSwitch, routerId, networkId,
-                        externalIps, null, gwMacAddress, removeFlowInvTx);
+                        externalIps, null, gwMacAddress, confTx);
                 LOG.debug("removeSnatFlowsInOldNaptSwitch : Successfully removed fib entries in old naptswitch {} for "
                         + "router {} with networkId {} and externalIps {}", naptSwitch, routerId, networkId,
                         externalIps);
@@ -325,7 +321,7 @@ public class NaptSwitchHA {
                 LOG.debug("removeSnatFlowsInOldNaptSwitch : External network not associated to router {}", routerId);
             }
             externalRouterListener.removeNaptFibExternalOutputFlows(routerId, naptSwitch, extNetworkId,
-                    externalIps, removeFlowInvTx);
+                    externalIps, confTx);
         }
 
         //For the router ID get the internal IP , internal port and the corresponding external IP and external Port.
@@ -892,29 +888,28 @@ public class NaptSwitchHA {
 
     protected void installSnatFlows(String routerName, Long routerId, BigInteger naptSwitch, Long routerVpnId,
                                     TypedReadWriteTransaction<Configuration> confTx) {
-        WriteTransaction writeFlowInvTx = TransactionAdapter.toWriteTransaction(confTx);
 
         if (routerId.equals(routerVpnId)) {
             LOG.debug("installSnatFlows : Installing flows for router with internalvpnId");
             //36 -> 46 ..Install flow forwarding packet to table46 from table36
             LOG.debug("installSnatFlows : installTerminatingServiceTblEntry in naptswitch with dpnId {} for "
                 + "routerName {} with routerId {}", naptSwitch, routerName, routerId);
-            externalRouterListener.installTerminatingServiceTblEntry(naptSwitch, routerName, routerId, writeFlowInvTx);
+            externalRouterListener.installTerminatingServiceTblEntry(naptSwitch, routerName, routerId, confTx);
 
             //Install default flows punting to controller in table 46(OutBoundNapt table)
             LOG.debug("installSnatFlows : installOutboundMissEntry in naptswitch with dpnId {} for "
                 + "routerName {} with routerId {}", naptSwitch, routerName, routerId);
-            externalRouterListener.createOutboundTblEntry(naptSwitch, routerId, writeFlowInvTx);
+            externalRouterListener.createOutboundTblEntry(naptSwitch, routerId, confTx);
 
             //Table 47 point to table 21 for inbound traffic
             LOG.debug("installSnatFlows : installNaptPfibEntry in naptswitch with dpnId {} for router {}",
                 naptSwitch, routerId);
-            externalRouterListener.installNaptPfibEntry(naptSwitch, routerId, writeFlowInvTx);
+            externalRouterListener.installNaptPfibEntry(naptSwitch, routerId, confTx);
 
             //Table 47 point to group
             LOG.debug("installSnatFlows : installNaptPfibExternalOutputFlow in naptswitch with dpnId {} for router {}",
                 naptSwitch, routerId);
-            externalRouterListener.installNaptPfibExternalOutputFlow(routerName, routerId, naptSwitch, writeFlowInvTx);
+            externalRouterListener.installNaptPfibExternalOutputFlow(routerName, routerId, naptSwitch, confTx);
         } else {
             Uuid extNetworkUuid = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
             if (extNetworkUuid == null) {
@@ -933,17 +928,17 @@ public class NaptSwitchHA {
                 + "routerName {} with BgpVpnId {}", naptSwitch, routerName, routerVpnId);
             externalRouterListener
                 .installTerminatingServiceTblEntryWithUpdatedVpnId(naptSwitch, routerName, routerId,
-                        routerVpnId, writeFlowInvTx, extNwProvType);
+                        routerVpnId, confTx, extNwProvType);
 
             //Install default flows punting to controller in table 46(OutBoundNapt table)
             LOG.debug("installSnatFlows : installOutboundMissEntry in naptswitch with dpnId {} for "
                 + "routerName {} with BgpVpnId {}", naptSwitch, routerName, routerVpnId);
-            externalRouterListener.createOutboundTblEntryWithBgpVpn(naptSwitch, routerId, routerVpnId, writeFlowInvTx);
+            externalRouterListener.createOutboundTblEntryWithBgpVpn(naptSwitch, routerId, routerVpnId, confTx);
 
             //Table 47 point to table 21 for inbound traffic
             LOG.debug("installSnatFlows : installNaptPfibEntry in naptswitch with dpnId {} for router {} "
                     + "with BgpVpnId {}", naptSwitch, routerId, routerVpnId);
-            externalRouterListener.installNaptPfibEntryWithBgpVpn(naptSwitch, routerId, routerVpnId, writeFlowInvTx);
+            externalRouterListener.installNaptPfibEntryWithBgpVpn(naptSwitch, routerId, routerVpnId, confTx);
         }
 
         Uuid networkId = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
@@ -961,7 +956,7 @@ public class NaptSwitchHA {
                         shouldInstallNaptPfibWithExtNetworkVpnId = false;
                         LOG.debug("installSnatFlows : installNaptPfibEntry fin naptswitch with dpnId {} for "
                                 + "BgpVpnId {}", naptSwitch, externalSubnetVpnId);
-                        externalRouterListener.installNaptPfibEntry(naptSwitch, externalSubnetVpnId, writeFlowInvTx);
+                        externalRouterListener.installNaptPfibEntry(naptSwitch, externalSubnetVpnId, confTx);
                     }
                 }
             }
@@ -969,7 +964,7 @@ public class NaptSwitchHA {
                 //NAPT PFIB table point to FIB table for outbound traffic - using external networkID as vpnID.
                 LOG.debug("installSnatFlows : installNaptPfibEntry fin naptswitch with dpnId {} for "
                     + "BgpVpnId {}", naptSwitch, vpnId);
-                externalRouterListener.installNaptPfibEntry(naptSwitch, vpnId, writeFlowInvTx);
+                externalRouterListener.installNaptPfibEntry(naptSwitch, vpnId, confTx);
             } else if (vpnId != NatConstants.INVALID_ID) {
                 LOG.debug("installSnatFlows : Associated BgpvpnId not found for router {}", routerId);
             }
@@ -982,8 +977,7 @@ public class NaptSwitchHA {
                 LOG.debug("installSnatFlows : advToBgpAndInstallFibAndTsFlows in naptswitch id {} "
                     + "with vpnName {} and externalIp {}", naptSwitch, vpnName, externalIp);
                 externalRouterListener.advToBgpAndInstallFibAndTsFlows(naptSwitch, NwConstants.INBOUND_NAPT_TABLE,
-                    vpnName, routerId, routerName, externalIp, networkId, null /* external-router */,
-                    writeFlowInvTx);
+                    vpnName, routerId, routerName, externalIp, networkId, null /* external-router */, confTx);
                 LOG.debug("installSnatFlows : Successfully added fib entries in naptswitch {} for "
                     + "router {} with external IP {}", naptSwitch, routerId, externalIp);
             }
@@ -1031,8 +1025,7 @@ public class NaptSwitchHA {
                 for (String externalIp : removedExternalIps) {
                     externalRouterListener.clearBgpRoutes(externalIp, vpnName);
                     externalRouterListener.delFibTsAndReverseTraffic(naptSwitch, routerId, externalIp, vpnName,
-                        networkId, NatConstants.DEFAULT_LABEL_VALUE, gwMacAddress, true,
-                        TransactionAdapter.toWriteTransaction(confTx));
+                        networkId, NatConstants.DEFAULT_LABEL_VALUE, gwMacAddress, true, confTx);
                     LOG.debug("bestEffortDeletion : Successfully removed fib entry for externalIp {} for routerId {} "
                                     + "on NAPT switch {} ", externalIp, routerId, naptSwitch);
                 }
@@ -1054,7 +1047,7 @@ public class NaptSwitchHA {
                     }
                     externalRouterListener.clearBgpRoutes(externalIp, vpnName);
                     externalRouterListener.delFibTsAndReverseTraffic(naptSwitch, routerId, externalIp, vpnName,
-                        networkId, label, gwMacAddress, true, TransactionAdapter.toWriteTransaction(confTx));
+                        networkId, label, gwMacAddress, true, confTx);
                     LOG.debug("bestEffortDeletion : Successfully removed fib entries in switch {} for router {} "
                             + "and externalIps {}", naptSwitch, routerId, externalIp);
                 }
index cda0d88804c0001dc0fc24d3c516e85259678cd2..b4f6ad6935190dcc7b85a05d9fe750936812d14e 100644 (file)
@@ -15,9 +15,12 @@ import java.util.List;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
+import org.opendaylight.genius.infra.Datastore.Configuration;
+import org.opendaylight.genius.infra.TransactionAdapter;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
 import org.opendaylight.genius.interfacemanager.globals.IfmConstants;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
 import org.opendaylight.genius.mdsalutil.MatchInfo;
@@ -167,7 +170,7 @@ public final class NatEvpnUtil {
                                                  long l3Vni,
                                                  String interfaceName,
                                                  String gwMacAddress,
-                                                 WriteTransaction writeTx,
+                                                 TypedWriteTransaction<Configuration> writeTx,
                                                  RouteOrigin origin, BigInteger dpId) {
         try {
             LOG.info("addRoutesForVxLanProvType : Adding Fib entry rd {} prefix {} nextHop {} l3Vni {}",
@@ -182,7 +185,7 @@ public final class NatEvpnUtil {
 
             fibManager.addOrUpdateFibEntry(rd, null /*macAddress*/, prefix,
                     Collections.singletonList(nextHopIp), VrfEntry.EncapType.Vxlan, NatConstants.DEFAULT_LABEL_VALUE,
-                    l3Vni, gwMacAddress, null /* parent-vpn-rd */, origin, writeTx);
+                l3Vni, gwMacAddress, null /* parent-vpn-rd */, origin, TransactionAdapter.toWriteTransaction(writeTx));
             /* Publish to Bgp only if its an INTERNET VPN */
             if (rd != null && !rd.equalsIgnoreCase(vpnName)) {
                 bgpManager.advertisePrefix(rd, null /*macAddress*/, prefix, Collections.singletonList(nextHopIp),
@@ -197,8 +200,9 @@ public final class NatEvpnUtil {
     }
 
     static void makeL3GwMacTableEntry(final BigInteger dpnId, final long vpnId, String macAddress,
-                                      List<Instruction> customInstructions, IMdsalApiManager mdsalManager,
-                                      WriteTransaction writeFlowTx) {
+        List<Instruction> customInstructions, IMdsalApiManager mdsalManager,
+        TypedWriteTransaction<Configuration> confTx) {
+
         List<MatchInfo> matchInfo = new ArrayList<>();
         matchInfo.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
         matchInfo.add(new MatchEthernetDestination(new MacAddress(macAddress)));
@@ -210,13 +214,13 @@ 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, customInstructions);
 
-        mdsalManager.addFlowToTx(dpnId, l3GwMacTableFlowEntity, writeFlowTx);
+        mdsalManager.addFlow(confTx, dpnId, l3GwMacTableFlowEntity);
         LOG.debug("makeL3GwMacTableEntry : Successfully created flow entity {} on DPN = {}",
                 l3GwMacTableFlowEntity, dpnId);
     }
 
     static void removeL3GwMacTableEntry(final BigInteger dpnId, final long vpnId, final String macAddress,
-                                        IMdsalApiManager mdsalManager, WriteTransaction removeFlowInvTx) {
+        IMdsalApiManager mdsalManager, TypedReadWriteTransaction<Configuration> confTx) {
         List<MatchInfo> matchInfo = new ArrayList<>();
         matchInfo.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
         matchInfo.add(new MatchEthernetSource(new MacAddress(macAddress)));
@@ -228,7 +232,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);
 
-        mdsalManager.removeFlowToTx(dpnId, l3GwMacTableFlowEntity, removeFlowInvTx);
+        mdsalManager.removeFlow(confTx, dpnId, l3GwMacTableFlowEntity);
         LOG.debug("removeL3GwMacTableEntry : Successfully removed flow entity {} on DPN = {}",
                 l3GwMacTableFlowEntity, dpnId);
     }
index f2d004bf43635cd930a7b7b2e3bd45ad8624ac7e..bfce16cb21d5ebd5ac64eedc4e04025f816910b2 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.netvirt.natservice.internal;
 
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+
 import com.google.common.base.Optional;
 import com.google.common.collect.HashBasedTable;
 import com.google.common.collect.Table;
@@ -22,12 +25,13 @@ import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
+import org.opendaylight.genius.infra.Datastore.Operational;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
 import org.opendaylight.genius.mdsalutil.FlowEntity;
 import org.opendaylight.genius.mdsalutil.NwConstants;
 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
@@ -277,20 +281,21 @@ public class NatInterfaceStateChangeListener
     }
 
     void handleRouterInterfacesUpEvent(String routerName, String interfaceName, BigInteger dpId,
-            WriteTransaction writeOperTxn) {
+            TypedReadWriteTransaction<Operational> operTx) throws ExecutionException, InterruptedException {
         LOG.debug("handleRouterInterfacesUpEvent : Handling UP event for router interface {} in Router {} on Dpn {}",
                 interfaceName, routerName, dpId);
-        NatUtil.addToNeutronRouterDpnsMap(dataBroker, routerName, interfaceName, dpId, writeOperTxn);
-        NatUtil.addToDpnRoutersMap(dataBroker, routerName, interfaceName, dpId, writeOperTxn);
+        NatUtil.addToNeutronRouterDpnsMap(routerName, interfaceName, dpId, operTx);
+        NatUtil.addToDpnRoutersMap(routerName, interfaceName, dpId, operTx);
     }
 
     void handleRouterInterfacesDownEvent(String routerName, String interfaceName, BigInteger dpnId,
-                                         WriteTransaction writeOperTxn) {
+                                         TypedReadWriteTransaction<Operational> operTx)
+        throws ExecutionException, InterruptedException {
         LOG.debug("handleRouterInterfacesDownEvent : Handling DOWN event for router Interface {} in Router {}",
                 interfaceName, routerName);
-        NatUtil.removeFromNeutronRouterDpnsMap(dataBroker, routerName, interfaceName, dpnId, writeOperTxn);
+        NatUtil.removeFromNeutronRouterDpnsMap(routerName, dpnId, operTx);
         NatUtil.removeFromDpnRoutersMap(dataBroker, routerName, interfaceName, dpnId, odlInterfaceRpcService,
-                writeOperTxn);
+                operTx);
     }
 
     private IntfTransitionState getTransitionState(Interface.OperStatus original , Interface.OperStatus updated) {
@@ -319,7 +324,7 @@ public class NatInterfaceStateChangeListener
             List<ListenableFuture<Void>> futures = new ArrayList<>();
             try {
                 LOG.trace("call : Received interface {} PORT UP OR ADD event ", interfaceName);
-                futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
+                futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, tx ->
                     handleRouterInterfacesUpEvent(routerName, interfaceName, intfDpnId, tx)));
             } catch (Exception e) {
                 LOG.error("call : Exception caught in Interface {} Operational State Up event",
@@ -346,7 +351,7 @@ public class NatInterfaceStateChangeListener
             List<ListenableFuture<Void>> futures = new ArrayList<>();
             try {
                 LOG.trace("call : Received interface {} PORT DOWN or REMOVE event", interfaceName);
-                futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
+                futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, tx ->
                         handleRouterInterfacesDownEvent(routerName, interfaceName, intfDpnId, tx)));
             } catch (Exception e) {
                 LOG.error("call : Exception observed in handling deletion of VPN Interface {}.", interfaceName, e);
@@ -382,14 +387,14 @@ public class NatInterfaceStateChangeListener
                             interfaceName, original.getOperStatus(), update.getOperStatus());
                     return futures;
                 }
-                futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+                futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, tx -> {
                     if (state.equals(IntfTransitionState.STATE_DOWN)) {
                         LOG.debug("call : DPN {} connnected to the interface {} has gone down."
                                 + "Hence clearing the dpn-vpninterfaces-list entry from the"
                                 + " neutron-router-dpns model in the ODL:L3VPN", intfDpnId, interfaceName);
                         // If the interface state is unknown, it means that the corresponding DPN has gone down.
                         // So remove the dpn-vpninterfaces-list from the neutron-router-dpns model.
-                        NatUtil.removeFromNeutronRouterDpnsMap(dataBroker, routerName, intfDpnId, tx);
+                        NatUtil.removeFromNeutronRouterDpnsMap(routerName, intfDpnId, tx);
                     } else if (state.equals(IntfTransitionState.STATE_UP)) {
                         LOG.debug("call : DPN {} connnected to the interface {} has come up. Hence adding"
                                 + " the dpn-vpninterfaces-list entry from the neutron-router-dpns model"
@@ -412,7 +417,7 @@ public class NatInterfaceStateChangeListener
             return;
         }
         InstanceIdentifier<RouterPorts> portIid = NatUtil.buildRouterPortsIdentifier(routerId);
-        ListenableFuture<Void> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+        ListenableFuture<Void> future = txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
             for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
                 floatingIPListener.createNATFlowEntries(portName, intExtPortMap, portIid, routerId, tx);
             }
@@ -491,7 +496,7 @@ public class NatInterfaceStateChangeListener
             return;
         }
         InstanceIdentifier<RouterPorts> portIid = NatUtil.buildRouterPortsIdentifier(routerId);
-        ListenableFuture<Void> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+        ListenableFuture<Void> future = txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
             for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
                 LOG.trace("processInterfaceRemoved : Removing DNAT Flow entries for dpnId {} ", dpnId);
                 floatingIPListener.removeNATFlowEntries(portName, intExtPortMap, portIid, routerId, dpnId, tx);
index a9211a030882421b3c2c804dd08a8e92fcfdf410..cfe80912011123d43609bdd1b57088d6d4227eb2 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.netvirt.natservice.internal;
 
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+
 import java.math.BigInteger;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
@@ -88,9 +91,9 @@ public class NatRouterInterfaceListener
                         interfaceName, routerId);
                 return;
             }
-            ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(operTx -> {
-                NatUtil.addToNeutronRouterDpnsMap(dataBroker, routerId, interfaceName, dpId, operTx);
-                NatUtil.addToDpnRoutersMap(dataBroker, routerId, interfaceName, dpId, operTx);
+            ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, operTx -> {
+                NatUtil.addToNeutronRouterDpnsMap(routerId, interfaceName, dpId, operTx);
+                NatUtil.addToDpnRoutersMap(routerId, interfaceName, dpId, operTx);
             }), LOG, "Error processing NAT router interface addition");
         } else {
             LOG.info("add : Interface {} not yet operational to handle router interface add event in router {}",
@@ -105,13 +108,13 @@ public class NatRouterInterfaceListener
         final String interfaceName = interfaceInfo.getInterfaceId();
 
         //Delete the RouterInterfaces maintained in the ODL:L3VPN configuration model
-        ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(confTx -> {
-            confTx.delete(LogicalDatastoreType.CONFIGURATION, NatUtil.getRouterInterfaceId(interfaceName));
-        }), LOG, "Error handling NAT router interface removal");
+        ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+            confTx -> confTx.delete(NatUtil.getRouterInterfaceId(interfaceName))), LOG,
+            "Error handling NAT router interface removal");
 
-        ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(operTx -> {
+        ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, operTx -> {
             //Delete the NeutronRouterDpnMap from the ODL:L3VPN operational model
-            NatUtil.removeFromNeutronRouterDpnsMap(dataBroker, routerId, interfaceName, interfaceManager, operTx);
+            NatUtil.removeFromNeutronRouterDpnsMap(routerId, interfaceName, interfaceManager, operTx);
 
             //Delete the DpnRouterMap from the ODL:L3VPN operational model
             NatUtil.removeFromDpnRoutersMap(dataBroker, routerId, interfaceName, interfaceManager, operTx);
index ecba39adac9b2f00c55743a6309e05ae58aa6df2..06a287c90954370e5fa36980d27dc4e42a2955d9 100644 (file)
@@ -33,7 +33,6 @@ import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
 import org.opendaylight.genius.infra.Datastore.Configuration;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
-import org.opendaylight.genius.infra.TransactionAdapter;
 import org.opendaylight.genius.infra.TypedReadWriteTransaction;
 import org.opendaylight.genius.infra.TypedWriteTransaction;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
@@ -583,8 +582,7 @@ public class NatTunnelInterfaceStateListener
             //Install default entry in FIB to SNAT table
             LOG.debug("hndlTepAddOnNonNaptSwitch : Installing default route in FIB on DPN {} for router {} with"
                 + " vpn {}...", srcDpnId, routerName, vpnId);
-            defaultRouteProgrammer.installDefNATRouteInDPN(srcDpnId, vpnId,
-                TransactionAdapter.toWriteTransaction(confTx));
+            defaultRouteProgrammer.installDefNATRouteInDPN(srcDpnId, vpnId, confTx);
 
             LOG.debug("hndlTepAddOnNonNaptSwitch : SNAT -> Install the group which forward packet to the tunnel port "
                 + "for the NAPT switch {} and the flow 26 which forwards to group", primaryDpnId);
@@ -606,8 +604,7 @@ public class NatTunnelInterfaceStateListener
             //Install default entry in FIB to SNAT table
             LOG.debug("hndlTepAddOnNonNaptSwitch : Installing default route in FIB on dpn {} for routerId {} "
                 + "with vpnId {}...", srcDpnId, routerId, vpnId);
-            defaultRouteProgrammer.installDefNATRouteInDPN(srcDpnId, vpnId, routerId,
-                TransactionAdapter.toWriteTransaction(confTx));
+            defaultRouteProgrammer.installDefNATRouteInDPN(srcDpnId, vpnId, routerId, confTx);
 
             LOG.debug("hndlTepAddOnNonNaptSwitch : Install group in non NAPT switch {} for router {}",
                     srcDpnId, routerName);
@@ -729,8 +726,7 @@ public class NatTunnelInterfaceStateListener
                 LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Advertise the route to the externalIp {} "
                         + "having nextHopIp {}", externalIp, nextHopIp);
                 NatEvpnUtil.addRoutesForVxLanProvType(dataBroker, bgpManager, fibManager, externalVpnName, rd,
-                        externalIp, nextHopIp, l3Vni, tunnelName, gwMacAddress,
-                        TransactionAdapter.toWriteTransaction(confTx), RouteOrigin.STATIC, srcDpnId);
+                        externalIp, nextHopIp, l3Vni, tunnelName, gwMacAddress, confTx, RouteOrigin.STATIC, srcDpnId);
                 serviceId = l3Vni;
             } else {
 
@@ -878,8 +874,8 @@ public class NatTunnelInterfaceStateListener
                     LOG.debug("hndlTepAddForDnatInEachRtr : DNAT -> Advertise the route to the externalIp {} "
                             + "having nextHopIp {}", externalIp, nextHopIp);
                     NatEvpnUtil.addRoutesForVxLanProvType(dataBroker, bgpManager, fibManager, vpnName, rd,
-                            externalIp, nextHopIp, l3Vni, interfaceName, gwMacAddress,
-                            TransactionAdapter.toWriteTransaction(confTx), RouteOrigin.STATIC, fipCfgdDpnId);
+                        externalIp, nextHopIp, l3Vni, interfaceName, gwMacAddress, confTx, RouteOrigin.STATIC,
+                        fipCfgdDpnId);
                     serviceId = l3Vni;
                 } else {
                     long label = floatingIPListener.getOperationalIpMapping(routerName, interfaceName, internalIp);
@@ -996,8 +992,7 @@ public class NatTunnelInterfaceStateListener
                 //Install default entry in FIB to SNAT table
                 LOG.debug("hndlTepDelForSnatInEachRtr : Installing default route in FIB on DPN {} for router {} with"
                         + " vpn {}...", dpnId, routerName, bgpVpnId);
-                defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, bgpVpnId,
-                    TransactionAdapter.toWriteTransaction(confTx));
+                defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, bgpVpnId, confTx);
             } else {
                 bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnUuid.getValue());
                 if (bgpVpnId == NatConstants.INVALID_ID) {
@@ -1010,8 +1005,7 @@ public class NatTunnelInterfaceStateListener
                 //Install default entry in FIB to SNAT table
                 LOG.debug("hndlTepDelForSnatInEachRtr : Installing default route in FIB on dpn {} for routerId {} "
                         + "with vpnId {}...", dpnId, routerId, bgpVpnId);
-                defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, bgpVpnId, routerId,
-                    TransactionAdapter.toWriteTransaction(confTx));
+                defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, bgpVpnId, routerId, confTx);
             }
 
             if (routerData.get().isEnableSnat()) {
index 72e55047f763db9ebe1a3e67d3b48896a9e0b32b..b2fafbf3c5a43ad1fb799528bf911d2414831b3d 100644 (file)
@@ -8,9 +8,10 @@
 
 package org.opendaylight.netvirt.natservice.internal;
 
+import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
+
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.CheckedFuture;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.math.BigInteger;
 import java.net.InetAddress;
@@ -31,15 +32,16 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
 import org.opendaylight.genius.infra.Datastore.Configuration;
+import org.opendaylight.genius.infra.Datastore.Operational;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.TypedReadTransaction;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
 import org.opendaylight.genius.mdsalutil.ActionInfo;
 import org.opendaylight.genius.mdsalutil.FlowEntity;
@@ -232,7 +234,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.ni
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.NxRegLoad;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -1041,8 +1042,8 @@ public final class NatUtil {
                     .RouterInterfaceKey(interfaceName)).build();
     }
 
-    public static void addToNeutronRouterDpnsMap(DataBroker broker, String routerName, String interfaceName,
-            BigInteger dpId , WriteTransaction writeOperTxn) {
+    public static void addToNeutronRouterDpnsMap(String routerName, String interfaceName, BigInteger dpId,
+        TypedReadWriteTransaction<Operational> operTx) throws ExecutionException, InterruptedException {
 
         if (dpId.equals(BigInteger.ZERO)) {
             LOG.warn("addToNeutronRouterDpnsMap : Could not retrieve dp id for interface {} "
@@ -1054,9 +1055,7 @@ public final class NatUtil {
                 + "ODL-L3VPN : NeutronRouterDpn map", routerName, dpId, interfaceName);
         InstanceIdentifier<DpnVpninterfacesList> dpnVpnInterfacesListIdentifier = getRouterDpnId(routerName, dpId);
 
-        Optional<DpnVpninterfacesList> optionalDpnVpninterfacesList =
-                SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                        LogicalDatastoreType.OPERATIONAL, dpnVpnInterfacesListIdentifier);
+        Optional<DpnVpninterfacesList> optionalDpnVpninterfacesList = operTx.read(dpnVpnInterfacesListIdentifier).get();
         org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns
             .router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces routerInterface =
             new RouterInterfacesBuilder().withKey(new RouterInterfacesKey(interfaceName))
@@ -1064,10 +1063,10 @@ public final class NatUtil {
         if (optionalDpnVpninterfacesList.isPresent()) {
             LOG.debug("addToNeutronRouterDpnsMap : RouterDpnList already present for the Router {} and DPN {} for the "
                     + "Interface {} in the ODL-L3VPN : NeutronRouterDpn map", routerName, dpId, interfaceName);
-            writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL, dpnVpnInterfacesListIdentifier
+            operTx.merge(dpnVpnInterfacesListIdentifier
                     .child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router
                             .dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces.class,
-                            new RouterInterfacesKey(interfaceName)), routerInterface, true);
+                            new RouterInterfacesKey(interfaceName)), routerInterface, CREATE_MISSING_PARENTS);
         } else {
             LOG.debug("addToNeutronRouterDpnsMap : Building new RouterDpnList for the Router {} and DPN {} for the "
                     + "Interface {} in the ODL-L3VPN : NeutronRouterDpn map", routerName, dpId, interfaceName);
@@ -1079,14 +1078,12 @@ public final class NatUtil {
             routerInterfaces.add(routerInterface);
             dpnVpnList.setRouterInterfaces(routerInterfaces);
             routerDpnListBuilder.setDpnVpninterfacesList(Collections.singletonList(dpnVpnList.build()));
-            writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL,
-                    getRouterId(routerName),
-                    routerDpnListBuilder.build(), true);
+            operTx.merge(getRouterId(routerName), routerDpnListBuilder.build(), CREATE_MISSING_PARENTS);
         }
     }
 
-    public static void addToDpnRoutersMap(DataBroker broker, String routerName, String interfaceName,
-            BigInteger dpId, WriteTransaction writeOperTxn) {
+    public static void addToDpnRoutersMap(String routerName, String interfaceName, BigInteger dpId,
+        TypedReadWriteTransaction<Operational> operTx) throws ExecutionException, InterruptedException {
         if (dpId.equals(BigInteger.ZERO)) {
             LOG.error("addToDpnRoutersMap : Could not retrieve dp id for interface {} to handle router {} "
                     + "association model", interfaceName, routerName);
@@ -1097,9 +1094,7 @@ public final class NatUtil {
                 + "DPNRouters map", dpId, routerName, interfaceName);
         InstanceIdentifier<DpnRoutersList> dpnRoutersListIdentifier = getDpnRoutersId(dpId);
 
-        Optional<DpnRoutersList> optionalDpnRoutersList =
-                SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                        LogicalDatastoreType.OPERATIONAL, dpnRoutersListIdentifier);
+        Optional<DpnRoutersList> optionalDpnRoutersList = operTx.read(dpnRoutersListIdentifier).get();
 
         if (optionalDpnRoutersList.isPresent()) {
             RoutersList routersList = new RoutersListBuilder().withKey(new RoutersListKey(routerName))
@@ -1108,9 +1103,8 @@ public final class NatUtil {
             if (!routersListFromDs.contains(routersList)) {
                 LOG.debug("addToDpnRoutersMap : Router {} not present for the DPN {}"
                         + " in the ODL-L3VPN : DPNRouters map", routerName, dpId);
-                writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL,
-                        dpnRoutersListIdentifier
-                        .child(RoutersList.class, new RoutersListKey(routerName)), routersList, true);
+                operTx.merge(dpnRoutersListIdentifier
+                        .child(RoutersList.class, new RoutersListKey(routerName)), routersList, CREATE_MISSING_PARENTS);
             } else {
                 LOG.debug("addToDpnRoutersMap : Router {} already mapped to the DPN {} in the ODL-L3VPN : "
                         + "DPNRouters map", routerName, dpId);
@@ -1123,69 +1117,31 @@ public final class NatUtil {
             RoutersListBuilder routersListBuilder = new RoutersListBuilder();
             routersListBuilder.setRouter(routerName);
             dpnRoutersListBuilder.setRoutersList(Collections.singletonList(routersListBuilder.build()));
-            writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL,
-                    getDpnRoutersId(dpId),
-                    dpnRoutersListBuilder.build(), true);
+            operTx.merge(getDpnRoutersId(dpId), dpnRoutersListBuilder.build(), CREATE_MISSING_PARENTS);
         }
     }
 
-
-    public static void removeFromNeutronRouterDpnsMap(DataBroker broker, String routerName, String interfaceName,
-                                               BigInteger dpId, WriteTransaction writeOperTxn) {
-        if (dpId.equals(BigInteger.ZERO)) {
-            LOG.error("removeFromNeutronRouterDpnsMap : Could not retrieve dp id for interface {} to handle router {} "
-                    + "dissociation model", interfaceName, routerName);
-            return;
-        }
-        InstanceIdentifier<DpnVpninterfacesList> routerDpnListIdentifier = getRouterDpnId(routerName, dpId);
-        Optional<DpnVpninterfacesList> optionalRouterDpnList =
-                SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                        LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier);
-        if (optionalRouterDpnList.isPresent()) {
-            List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router
-                .dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces> routerInterfaces =
-                optionalRouterDpnList.get().getRouterInterfaces();
-            org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router
-                .dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces routerInterface =
-                new RouterInterfacesBuilder().withKey(new RouterInterfacesKey(interfaceName))
-                    .setInterface(interfaceName).build();
-            if (routerInterfaces != null && routerInterfaces.remove(routerInterface)) {
-                if (routerInterfaces.isEmpty()) {
-                    writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier);
-                } else {
-                    writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier.child(
-                        org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router
-                            .dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces.class,
-                        new RouterInterfacesKey(interfaceName)));
-                }
-            }
-        }
-    }
-
-    public static void removeFromNeutronRouterDpnsMap(DataBroker broker, String routerName,
-                                               BigInteger dpId, WriteTransaction writeOperTxn) {
+    public static void removeFromNeutronRouterDpnsMap(String routerName, BigInteger dpId,
+        TypedReadWriteTransaction<Operational> operTx) throws ExecutionException, InterruptedException {
         if (dpId.equals(BigInteger.ZERO)) {
             LOG.warn("removeFromNeutronRouterDpnsMap : DPN ID is invalid for the router {} ", routerName);
             return;
         }
 
         InstanceIdentifier<DpnVpninterfacesList> routerDpnListIdentifier = getRouterDpnId(routerName, dpId);
-        Optional<DpnVpninterfacesList> optionalRouterDpnList =
-                SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                        LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier);
+        Optional<DpnVpninterfacesList> optionalRouterDpnList = operTx.read(routerDpnListIdentifier).get();
         if (optionalRouterDpnList.isPresent()) {
             LOG.debug("removeFromNeutronRouterDpnsMap : Removing the dpn-vpninterfaces-list from the "
                     + "odl-l3vpn:neutron-router-dpns model for the router {}", routerName);
-            writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier);
+            operTx.delete(routerDpnListIdentifier);
         } else {
             LOG.debug("removeFromNeutronRouterDpnsMap : dpn-vpninterfaces-list does not exist in the "
                     + "odl-l3vpn:neutron-router-dpns model for the router {}", routerName);
         }
     }
 
-    public static void removeFromNeutronRouterDpnsMap(DataBroker broker, String routerName, String vpnInterfaceName,
-                                               OdlInterfaceRpcService ifaceMgrRpcService,
-                                               WriteTransaction writeOperTxn) {
+    public static void removeFromNeutronRouterDpnsMap(String routerName, String vpnInterfaceName,
+        OdlInterfaceRpcService ifaceMgrRpcService, @Nonnull TypedReadWriteTransaction<Operational> operTx) {
         BigInteger dpId = getDpnForInterface(ifaceMgrRpcService, vpnInterfaceName);
         if (dpId.equals(BigInteger.ZERO)) {
             LOG.debug("removeFromNeutronRouterDpnsMap : Could not retrieve dp id for interface {} to handle router {}"
@@ -1193,9 +1149,13 @@ public final class NatUtil {
             return;
         }
         InstanceIdentifier<DpnVpninterfacesList> routerDpnListIdentifier = getRouterDpnId(routerName, dpId);
-        Optional<DpnVpninterfacesList> optionalRouterDpnList =
-                SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                        LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier);
+        Optional<DpnVpninterfacesList> optionalRouterDpnList;
+        try {
+            optionalRouterDpnList = operTx.read(routerDpnListIdentifier).get();
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("Error reading the router DPN list for {}", routerDpnListIdentifier, e);
+            optionalRouterDpnList = Optional.absent();
+        }
         if (optionalRouterDpnList.isPresent()) {
             List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns
                 .router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces> routerInterfaces =
@@ -1207,30 +1167,20 @@ public final class NatUtil {
 
             if (routerInterfaces != null && routerInterfaces.remove(routerInterface)) {
                 if (routerInterfaces.isEmpty()) {
-                    if (writeOperTxn != null) {
-                        writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier);
-                    } else {
-                        MDSALUtil.syncDelete(broker, LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier);
-                    }
+                    operTx.delete(routerDpnListIdentifier);
                 } else {
-                    if (writeOperTxn != null) {
-                        writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier.child(
-                            org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router
-                                .dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces.class,
-                            new RouterInterfacesKey(vpnInterfaceName)));
-                    } else {
-                        MDSALUtil.syncDelete(broker, LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier.child(
-                            org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron
-                                .router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces.class,
-                            new RouterInterfacesKey(vpnInterfaceName)));
-                    }
+                    operTx.delete(routerDpnListIdentifier.child(
+                        org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router
+                            .dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces.class,
+                        new RouterInterfacesKey(vpnInterfaceName)));
                 }
             }
         }
     }
 
     public static void removeFromDpnRoutersMap(DataBroker broker, String routerName, String vpnInterfaceName,
-                                        OdlInterfaceRpcService ifaceMgrRpcService, WriteTransaction writeOperTxn) {
+        OdlInterfaceRpcService ifaceMgrRpcService, TypedReadWriteTransaction<Operational> operTx)
+        throws ExecutionException, InterruptedException {
         BigInteger dpId = getDpnForInterface(ifaceMgrRpcService, vpnInterfaceName);
         if (dpId.equals(BigInteger.ZERO)) {
             LOG.debug("removeFromDpnRoutersMap : removeFromDpnRoutersMap() : "
@@ -1238,12 +1188,12 @@ public final class NatUtil {
                 vpnInterfaceName, routerName);
             return;
         }
-        removeFromDpnRoutersMap(broker, routerName, vpnInterfaceName, dpId, ifaceMgrRpcService, writeOperTxn);
+        removeFromDpnRoutersMap(broker, routerName, vpnInterfaceName, dpId, ifaceMgrRpcService, operTx);
     }
 
     static void removeFromDpnRoutersMap(DataBroker broker, String routerName, String vpnInterfaceName,
-                                        BigInteger curDpnId,
-                                        OdlInterfaceRpcService ifaceMgrRpcService, WriteTransaction writeOperTxn) {
+        BigInteger curDpnId, OdlInterfaceRpcService ifaceMgrRpcService, TypedReadWriteTransaction<Operational> operTx)
+        throws ExecutionException, InterruptedException {
         /*
             1) Get the DpnRoutersList for the DPN.
             2) Get the RoutersList identifier for the DPN and router.
@@ -1257,9 +1207,7 @@ public final class NatUtil {
 
         //Get the dpn-routers-list instance for the current DPN.
         InstanceIdentifier<DpnRoutersList> dpnRoutersListIdentifier = getDpnRoutersId(curDpnId);
-        Optional<DpnRoutersList> dpnRoutersListData =
-                SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                        LogicalDatastoreType.OPERATIONAL, dpnRoutersListIdentifier);
+        Optional<DpnRoutersList> dpnRoutersListData = operTx.read(dpnRoutersListIdentifier).get();
 
         if (dpnRoutersListData == null || !dpnRoutersListData.isPresent()) {
             LOG.error("removeFromDpnRoutersMap : dpn-routers-list is not present for DPN {} "
@@ -1269,9 +1217,7 @@ public final class NatUtil {
 
         //Get the routers-list instance for the router on the current DPN only
         InstanceIdentifier<RoutersList> routersListIdentifier = getRoutersList(curDpnId, routerName);
-        Optional<RoutersList> routersListData =
-                SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                        LogicalDatastoreType.OPERATIONAL, routersListIdentifier);
+        Optional<RoutersList> routersListData = operTx.read(routersListIdentifier).get();
 
         if (routersListData == null || !routersListData.isPresent()) {
             LOG.error("removeFromDpnRoutersMap : routers-list is not present for the DPN {} "
@@ -1293,7 +1239,7 @@ public final class NatUtil {
             LOG.debug("removeFromDpnRoutersMap : Unable to get the routers list for the DPN {}. Possibly all subnets "
                     + "removed from router {} OR Router {} has been deleted. Hence DPN router model WILL be cleared ",
                 curDpnId, routerName, routerName);
-            writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routersListIdentifier);
+            operTx.delete(routersListIdentifier);
             return;
         }
 
@@ -1327,7 +1273,7 @@ public final class NatUtil {
         LOG.debug("removeFromDpnRoutersMap : Router {} is present in the DPN {} only through the interface {} "
             + "Hence DPN router model WILL be cleared. Possibly last VM for the router "
             + "deleted in the DPN", routerName, curDpnId, vpnInterfaceName);
-        writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routersListIdentifier);
+        operTx.delete(routersListIdentifier);
     }
 
     private static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn
@@ -1593,6 +1539,17 @@ public final class NatUtil {
                 FloatingIpIdToPortMapping::getFloatingIpPortMacAddress).orElse(null);
     }
 
+    protected static String getFloatingIpPortMacFromFloatingIpId(TypedReadTransaction<Configuration> confTx,
+        Uuid floatingIpId) {
+        try {
+            return confTx.read(buildfloatingIpIdToPortMappingIdentifier(floatingIpId)).get().toJavaUtil().map(
+                FloatingIpIdToPortMapping::getFloatingIpPortMacAddress).orElse(null);
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("Error reading the floating IP port MAC for {}", floatingIpId, e);
+            return null;
+        }
+    }
+
     protected static Uuid getFloatingIpPortSubnetIdFromFloatingIpId(DataBroker broker, Uuid floatingIpId) {
         InstanceIdentifier<FloatingIpIdToPortMapping> id = buildfloatingIpIdToPortMappingIdentifier(floatingIpId);
         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
@@ -1600,6 +1557,18 @@ public final class NatUtil {
                 FloatingIpIdToPortMapping::getFloatingIpPortSubnetId).orElse(null);
     }
 
+    @Nullable
+    protected static Uuid getFloatingIpPortSubnetIdFromFloatingIpId(TypedReadTransaction<Configuration> confTx,
+        Uuid floatingIpId) {
+        try {
+            return confTx.read(buildfloatingIpIdToPortMappingIdentifier(floatingIpId)).get().toJavaUtil().map(
+                FloatingIpIdToPortMapping::getFloatingIpPortSubnetId).orElse(null);
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("Error reading the floating IP port subnet for {}", floatingIpId, e);
+            return null;
+        }
+    }
+
     static InstanceIdentifier<FloatingIpIdToPortMapping> buildfloatingIpIdToPortMappingIdentifier(Uuid floatingIpId) {
         return InstanceIdentifier.builder(FloatingIpPortInfo.class).child(FloatingIpIdToPortMapping.class, new
             FloatingIpIdToPortMappingKey(floatingIpId)).build();
@@ -1917,7 +1886,7 @@ public final class NatUtil {
     }
 
     public static void makePreDnatToSnatTableEntry(IMdsalApiManager mdsalManager, BigInteger naptDpnId,
-            short tableId, WriteTransaction writeFlowTx) {
+            short tableId, TypedWriteTransaction<Configuration> confTx) {
         LOG.debug("makePreDnatToSnatTableEntry : Create Pre-DNAT table {} --> table {} flow on NAPT DpnId {} ",
                 NwConstants.PDNAT_TABLE, tableId, naptDpnId);
 
@@ -1930,19 +1899,19 @@ public final class NatUtil {
                 5, flowRef, 0, 0,  NwConstants.COOKIE_DNAT_TABLE,
                 matches, preDnatToSnatInstructions);
 
-        mdsalManager.addFlowToTx(naptDpnId, preDnatToSnatTableFlowEntity, writeFlowTx);
+        mdsalManager.addFlow(confTx, naptDpnId, preDnatToSnatTableFlowEntity);
         LOG.debug("makePreDnatToSnatTableEntry : Successfully installed Pre-DNAT flow {} on NAPT DpnId {} ",
                 preDnatToSnatTableFlowEntity,  naptDpnId);
     }
 
-    public static void removePreDnatToSnatTableEntry(IMdsalApiManager mdsalManager, BigInteger naptDpnId,
-                                                     WriteTransaction removeFlowInvTx) {
+    public static void removePreDnatToSnatTableEntry(TypedReadWriteTransaction<Configuration> confTx,
+        IMdsalApiManager mdsalManager, BigInteger naptDpnId) {
         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);
-        mdsalManager.removeFlowToTx(naptDpnId, preDnatToSnatTableFlowEntity, removeFlowInvTx);
+        mdsalManager.removeFlow(confTx, naptDpnId, preDnatToSnatTableFlowEntity);
         LOG.debug("removePreDnatToSnatTableEntry: Successfully removed Pre-DNAT flow {} on NAPT DpnId = {}",
                 preDnatToSnatTableFlowEntity, naptDpnId);
     }
@@ -1999,9 +1968,9 @@ public final class NatUtil {
     }
 
     @Nullable
-    public static String getPrimaryRd(String vpnName, ReadTransaction tx) throws ReadFailedException {
-        return tx.read(LogicalDatastoreType.CONFIGURATION,
-                getVpnInstanceIdentifier(vpnName)).checkedGet().toJavaUtil().map(NatUtil::getPrimaryRd).orElse(null);
+    public static String getPrimaryRd(String vpnName, TypedReadTransaction<Configuration> tx)
+        throws ExecutionException, InterruptedException {
+        return tx.read(getVpnInstanceIdentifier(vpnName)).get().toJavaUtil().map(NatUtil::getPrimaryRd).orElse(null);
     }
 
     public static String getPrimaryRd(DataBroker dataBroker, String vpnName) {
@@ -2119,17 +2088,6 @@ public final class NatUtil {
         }), LOG, "Error installing router gateway flows");
     }
 
-    public static CheckedFuture<Void, TransactionCommitFailedException> waitForTransactionToComplete(
-            WriteTransaction tx) {
-        CheckedFuture<Void, TransactionCommitFailedException> futures = tx.submit();
-        try {
-            futures.get();
-        } catch (InterruptedException | ExecutionException e) {
-            LOG.error("Error writing to datastore {}", e);
-        }
-        return futures;
-    }
-
     public static Boolean isOpenStackVniSemanticsEnforcedForGreAndVxlan(IElanService elanManager,
                                                                         ProviderTypes extNwProvType) {
         if (elanManager.isOpenStackVniSemanticsEnforced() && (extNwProvType == ProviderTypes.GRE
index 6d1c8aa00624bd09375ed6934885098ffc3c3a75..ff84a60fcdbdca6e1db452573fa0b968960dd076 100644 (file)
@@ -25,7 +25,6 @@ import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
 import org.opendaylight.genius.infra.Datastore.Configuration;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
-import org.opendaylight.genius.infra.TransactionAdapter;
 import org.opendaylight.genius.infra.TypedReadWriteTransaction;
 import org.opendaylight.genius.mdsalutil.BucketInfo;
 import org.opendaylight.genius.mdsalutil.FlowEntity;
@@ -175,8 +174,7 @@ public class RouterDpnChangeListener
                                     LOG.info(
                                         "add : Installing default route in FIB on dpn {} for router {} with vpn {}",
                                         dpnId, routerUuid, vpnId);
-                                    snatDefaultRouteProgrammer.installDefNATRouteInDPN(dpnId, vpnId,
-                                        TransactionAdapter.toWriteTransaction(confTx));
+                                    snatDefaultRouteProgrammer.installDefNATRouteInDPN(dpnId, vpnId, confTx);
                                 } else {
                                     LOG.debug("add : External BGP vpn associated to router {}", routerUuid);
                                     vpnId = NatUtil.getVpnId(dataBroker, vpnName.getValue());
@@ -188,8 +186,7 @@ public class RouterDpnChangeListener
                                     //Install default entry in FIB to SNAT table
                                     LOG.debug("add : Installing default route in FIB on dpn {} for routerId {} with "
                                         + "vpnId {}...", dpnId, routerUuid, vpnId);
-                                    snatDefaultRouteProgrammer.installDefNATRouteInDPN(dpnId, vpnId, routerId,
-                                        TransactionAdapter.toWriteTransaction(confTx));
+                                    snatDefaultRouteProgrammer.installDefNATRouteInDPN(dpnId, vpnId, routerId, confTx);
                                 }
                                 if (router.isEnableSnat()) {
                                     LOG.info("add : SNAT enabled for router {}", routerUuid);
@@ -262,8 +259,7 @@ public class RouterDpnChangeListener
                                     //Remove default entry in FIB
                                     LOG.debug("remove : Removing default route in FIB on dpn {} for vpn {} ...", dpnId,
                                         vpnName);
-                                    snatDefaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, vpnId,
-                                        TransactionAdapter.toWriteTransaction(confTx));
+                                    snatDefaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, vpnId, confTx);
                                 } else {
                                     LOG.debug("remove : External vpn associated to router {}", routerUuid);
                                     vpnId = NatUtil.getVpnId(dataBroker, vpnName.getValue());
@@ -275,8 +271,7 @@ public class RouterDpnChangeListener
                                     //Remove default entry in FIB
                                     LOG.debug("remove : Removing default route in FIB on dpn {} for vpn {} ...", dpnId,
                                         vpnName);
-                                    snatDefaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, vpnId, routerId,
-                                        TransactionAdapter.toWriteTransaction(confTx));
+                                    snatDefaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, vpnId, routerId, confTx);
                                 }
 
                                 if (router.isEnableSnat()) {
index 25ae71b13a41cd5fb3a20b1d1306b7d4396ff156..27f48ebadb006ae8812ba9f2620549d3fc0fb1dc 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.netvirt.natservice.internal;
 
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
 import com.google.common.base.Optional;
 import java.math.BigInteger;
 import java.util.List;
@@ -78,7 +80,7 @@ public class RouterToVpnListener implements NeutronvpnListener {
             }
             long routerId = NatUtil.getVpnId(dataBroker, routerName);
             try {
-                txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+                txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
                     tx -> externalRoutersListener.changeLocalVpnIdToBgpVpnId(routerName, routerId, vpnName, tx,
                             extNwProvType)).get();
             } catch (InterruptedException | ExecutionException e) {
@@ -116,7 +118,7 @@ public class RouterToVpnListener implements NeutronvpnListener {
             }
             long routerId = NatUtil.getVpnId(dataBroker, routerName);
             try {
-                txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+                txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
                     tx -> externalRoutersListener.changeBgpVpnIdToLocalVpnId(routerName, routerId, vpnName, tx,
                             extNwProvType)).get();
             } catch (InterruptedException | ExecutionException e) {
index 418285ce3dab9e93eadb6c9d7b6b661bef2083a5..26adc77f18bc722150bc43d898a07e0b48579be5 100644 (file)
@@ -18,9 +18,11 @@ import javax.inject.Inject;
 import javax.inject.Singleton;
 
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
+import org.opendaylight.genius.infra.Datastore.Configuration;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
 import org.opendaylight.genius.mdsalutil.FlowEntity;
 import org.opendaylight.genius.mdsalutil.InstructionInfo;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
@@ -127,7 +129,7 @@ public class SNATDefaultRouteProgrammer {
 
     }
 
-    void installDefNATRouteInDPN(BigInteger dpnId, long vpnId, WriteTransaction writeFlowInvTx) {
+    void installDefNATRouteInDPN(BigInteger dpnId, long vpnId, TypedWriteTransaction<Configuration> confTx) {
         FlowEntity flowEntity = buildDefNATFlowEntity(dpnId, vpnId);
         if (flowEntity == null) {
             LOG.error("installDefNATRouteInDPN : Flow entity received is NULL."
@@ -135,10 +137,11 @@ public class SNATDefaultRouteProgrammer {
             return;
         }
         natServiceCounters.installDefaultNatFlow();
-        mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
+        mdsalManager.addFlow(confTx, flowEntity);
     }
 
-    void installDefNATRouteInDPN(BigInteger dpnId, long bgpVpnId, long routerId, WriteTransaction writeFlowInvTx) {
+    void installDefNATRouteInDPN(BigInteger dpnId, long bgpVpnId, long routerId,
+        TypedWriteTransaction<Configuration> confTx) {
         FlowEntity flowEntity = buildDefNATFlowEntity(dpnId, bgpVpnId, routerId);
         if (flowEntity == null) {
             LOG.error("installDefNATRouteInDPN : Flow entity received is NULL."
@@ -146,7 +149,7 @@ public class SNATDefaultRouteProgrammer {
             return;
         }
         natServiceCounters.installDefaultNatFlow();
-        mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
+        mdsalManager.addFlow(confTx, flowEntity);
     }
 
     void installDefNATRouteInDPN(BigInteger dpnId, long vpnId, String subnetId) {
@@ -160,7 +163,7 @@ public class SNATDefaultRouteProgrammer {
         mdsalManager.installFlow(flowEntity);
     }
 
-    void removeDefNATRouteInDPN(BigInteger dpnId, long vpnId, WriteTransaction writeFlowInvTx) {
+    void removeDefNATRouteInDPN(BigInteger dpnId, long vpnId, TypedReadWriteTransaction<Configuration> confTx) {
         FlowEntity flowEntity = buildDefNATFlowEntity(dpnId, vpnId);
         if (flowEntity == null) {
             LOG.error("removeDefNATRouteInDPN : Flow entity received is NULL."
@@ -168,10 +171,11 @@ public class SNATDefaultRouteProgrammer {
             return;
         }
         natServiceCounters.removeDefaultNatFlow();
-        mdsalManager.removeFlowToTx(flowEntity, writeFlowInvTx);
+        mdsalManager.removeFlow(confTx, flowEntity);
     }
 
-    void removeDefNATRouteInDPN(BigInteger dpnId, long bgpVpnId, long routerId, WriteTransaction writeFlowInvTx) {
+    void removeDefNATRouteInDPN(BigInteger dpnId, long bgpVpnId, long routerId,
+        TypedReadWriteTransaction<Configuration> confTx) {
         FlowEntity flowEntity = buildDefNATFlowEntity(dpnId, bgpVpnId, routerId);
         if (flowEntity == null) {
             LOG.error("removeDefNATRouteInDPN : Flow entity received is NULL."
@@ -179,7 +183,7 @@ public class SNATDefaultRouteProgrammer {
             return;
         }
         natServiceCounters.removeDefaultNatFlow();
-        mdsalManager.removeFlowToTx(flowEntity, writeFlowInvTx);
+        mdsalManager.removeFlow(confTx, flowEntity);
     }
 
     void addOrDelDefaultFibRouteToSNATForSubnet(Subnets subnet, String networkId, int flowAction, long vpnId) {
index 1506da45321e4e71010e189240d19cb7f25b31f0..3569980f900cc5c5ecb41454a99a47b23aa62736 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.netvirt.natservice.internal;
 
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 import static org.opendaylight.netvirt.natservice.internal.NatUtil.buildfloatingIpIdToPortMappingIdentifier;
 
 import com.google.common.base.Optional;
@@ -22,11 +23,13 @@ import javax.annotation.Nonnull;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
+import org.opendaylight.genius.infra.Datastore.Configuration;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
 import org.opendaylight.genius.mdsalutil.ActionInfo;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
 import org.opendaylight.genius.mdsalutil.MatchInfo;
@@ -53,7 +56,9 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.OdlArputilService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.SendArpRequestInput;
@@ -137,7 +142,8 @@ public class VpnFloatingIpHandler implements FloatingIPHandler {
     @Override
     public void onAddFloatingIp(final BigInteger dpnId, final String routerUuid, final long routerId,
                                 final Uuid networkId, final String interfaceName,
-                                final InternalToExternalPortMap mapping, WriteTransaction writeFlowInvTx) {
+                                final InternalToExternalPortMap mapping,
+                                TypedReadWriteTransaction<Configuration> confTx) {
         String externalIp = mapping.getExternalIp();
         String internalIp = mapping.getInternalIp();
         Uuid floatingIpId = mapping.getExternalId();
@@ -187,7 +193,7 @@ public class VpnFloatingIpHandler implements FloatingIPHandler {
             Uuid floatingIpInterface = NatEvpnUtil.getFloatingIpInterfaceIdFromFloatingIpId(dataBroker, floatingIpId);
             evpnDnatFlowProgrammer.onAddFloatingIp(dpnId, routerUuid, routerId, vpnName, internalIp,
                     externalIp, networkId, interfaceName, floatingIpInterface.getValue(), floatingIpPortMacAddress,
-                    rd, nextHopIp, writeFlowInvTx);
+                    rd, nextHopIp, confTx);
             return;
         }
         /*
@@ -224,16 +230,20 @@ public class VpnFloatingIpHandler implements FloatingIPHandler {
                 List<ActionInfo> actionsInfos = new ArrayList<>();
                 actionsInfos.add(new ActionNxResubmit(NwConstants.PDNAT_TABLE));
                 instructions.add(new InstructionApplyActions(actionsInfos).buildInstruction(0));
-                makeTunnelTableEntry(vpnName, dpnId, label, instructions, writeFlowInvTx, provType);
 
-                //Install custom FIB routes
                 List<ActionInfo> actionInfoFib = new ArrayList<>();
                 List<Instruction> customInstructions = new ArrayList<>();
                 actionInfoFib.add(new ActionSetFieldEthernetDestination(new MacAddress(floatingIpPortMacAddress)));
                 customInstructions.add(new InstructionApplyActions(actionInfoFib).buildInstruction(0));
                 customInstructions.add(new InstructionGotoTable(NwConstants.PDNAT_TABLE).buildInstruction(1));
 
-                makeLFibTableEntry(dpnId, label, floatingIpPortMacAddress, NwConstants.PDNAT_TABLE, writeFlowInvTx);
+                ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
+                    innerConfTx -> {
+                        makeTunnelTableEntry(vpnName, dpnId, label, instructions, innerConfTx, provType);
+                        makeLFibTableEntry(dpnId, label, floatingIpPortMacAddress, NwConstants.PDNAT_TABLE,
+                            innerConfTx);
+                    }), LOG, "Error adding tunnel or FIB table entries");
+
                 CreateFibEntryInput input = new CreateFibEntryInputBuilder().setVpnName(vpnName)
                         .setSourceDpid(dpnId).setInstruction(customInstructions)
                         .setIpAddress(fibExternalIp).setServiceId(label)
@@ -287,11 +297,11 @@ public class VpnFloatingIpHandler implements FloatingIPHandler {
     @Override
     public void onRemoveFloatingIp(final BigInteger dpnId, String routerUuid, long routerId, final Uuid networkId,
                                    InternalToExternalPortMap mapping, final long label,
-                                   WriteTransaction removeFlowInvTx) {
+                                   TypedReadWriteTransaction<Configuration> confTx) {
         String externalIp = mapping.getExternalIp();
         Uuid floatingIpId = mapping.getExternalId();
-        Uuid subnetId = NatUtil.getFloatingIpPortSubnetIdFromFloatingIpId(dataBroker, floatingIpId);
-        Optional<Subnets> externalSubnet = NatUtil.getOptionalExternalSubnets(dataBroker, subnetId);
+        Uuid subnetId = NatUtil.getFloatingIpPortSubnetIdFromFloatingIpId(confTx, floatingIpId);
+        Optional<Subnets> externalSubnet = NatUtil.getOptionalExternalSubnets(confTx, subnetId);
         final String vpnName = externalSubnet.isPresent() ? subnetId.getValue() :
             NatUtil.getAssociatedVPN(dataBroker, networkId);
         if (vpnName == null) {
@@ -302,7 +312,7 @@ public class VpnFloatingIpHandler implements FloatingIPHandler {
 
         //Remove floating mac from mymac table
         LOG.debug("onRemoveFloatingIp: Removing FloatingIp {}", externalIp);
-        String floatingIpPortMacAddress = NatUtil.getFloatingIpPortMacFromFloatingIpId(dataBroker, floatingIpId);
+        String floatingIpPortMacAddress = NatUtil.getFloatingIpPortMacFromFloatingIpId(confTx, floatingIpId);
         if (floatingIpPortMacAddress == null) {
             LOG.error("onRemoveFloatingIp: Unable to retrieve floatingIp port MAC address from floatingIpId {} for "
                     + "router {} to remove floatingIp {}", floatingIpId, routerUuid, externalIp);
@@ -325,17 +335,17 @@ public class VpnFloatingIpHandler implements FloatingIPHandler {
         if (provType == ProviderTypes.VXLAN) {
             Uuid floatingIpInterface = NatEvpnUtil.getFloatingIpInterfaceIdFromFloatingIpId(dataBroker, floatingIpId);
             evpnDnatFlowProgrammer.onRemoveFloatingIp(dpnId, vpnName, externalIp, floatingIpInterface.getValue(),
-                    floatingIpPortMacAddress, routerId, removeFlowInvTx);
+                    floatingIpPortMacAddress, routerId, confTx);
             return;
         }
-        cleanupFibEntries(dpnId, vpnName, externalIp, label, removeFlowInvTx, provType);
+        cleanupFibEntries(dpnId, vpnName, externalIp, label, confTx, provType);
     }
 
     @Override
-    public void cleanupFibEntries(final BigInteger dpnId, final String vpnName, final String externalIp,
-                                  final long label, WriteTransaction removeFlowInvTx, ProviderTypes provType) {
+    public void cleanupFibEntries(BigInteger dpnId, String vpnName, String externalIp,
+                                  long label, TypedReadWriteTransaction<Configuration> confTx, ProviderTypes provType) {
         //Remove Prefix from BGP
-        String rd = NatUtil.getVpnRd(dataBroker, vpnName);
+        String rd = NatUtil.getVpnRd(confTx, vpnName);
         String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
         NatUtil.removePrefixFromBGP(bgpManager, fibManager, rd, fibExternalIp, vpnName, LOG);
 
@@ -360,9 +370,9 @@ public class VpnFloatingIpHandler implements FloatingIPHandler {
                     }
                 }
                 if (removeTunnelFlow) {
-                    removeTunnelTableEntry(dpnId, label, removeFlowInvTx);
+                    removeTunnelTableEntry(dpnId, label, confTx);
                 }
-                removeLFibTableEntry(dpnId, label, removeFlowInvTx);
+                removeLFibTableEntry(dpnId, label, confTx);
                 RemoveVpnLabelInput labelInput = new RemoveVpnLabelInputBuilder()
                         .setVpnName(vpnName).setIpPrefix(externalIp).build();
                 return vpnService.removeVpnLabel(labelInput);
@@ -399,22 +409,19 @@ public class VpnFloatingIpHandler implements FloatingIPHandler {
                 + NwConstants.FLOWID_SEPARATOR + ipAddress;
     }
 
-    private void removeTunnelTableEntry(BigInteger dpnId, long serviceId, WriteTransaction removeFlowInvTx) {
+    private void removeTunnelTableEntry(BigInteger dpnId, long serviceId,
+        TypedReadWriteTransaction<Configuration> confTx) {
+
         LOG.debug("removeTunnelTableEntry : called with DpnId = {} and label = {}", dpnId, serviceId);
-        List<MatchInfo> mkMatches = new ArrayList<>();
-        // Matching metadata
-        mkMatches.add(new MatchTunnelId(BigInteger.valueOf(serviceId)));
-        Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.INTERNAL_TUNNEL_TABLE,
-            getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, serviceId, ""),
-            5, String.format("%s:%d", "TST Flow Entry ", serviceId), 0, 0,
-            COOKIE_TUNNEL.add(BigInteger.valueOf(serviceId)), mkMatches, null);
-        mdsalManager.removeFlowToTx(dpnId, flowEntity, removeFlowInvTx);
+        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);
     }
 
     private void makeTunnelTableEntry(String vpnName, BigInteger dpnId, long serviceId,
-            List<Instruction> customInstructions, WriteTransaction writeFlowInvTx, ProviderTypes provType) {
+            List<Instruction> customInstructions, TypedWriteTransaction<Configuration> confTx, ProviderTypes provType) {
         List<MatchInfo> mkMatches = new ArrayList<>();
 
         LOG.info("makeTunnelTableEntry on DpnId = {} and serviceId = {}", dpnId, serviceId);
@@ -434,11 +441,11 @@ public class VpnFloatingIpHandler implements FloatingIPHandler {
             String.format("%s:%d", "TST Flow Entry ", serviceId),
             0, 0, COOKIE_TUNNEL.add(BigInteger.valueOf(serviceId)), mkMatches, customInstructions);
 
-        mdsalManager.addFlowToTx(dpnId, terminatingServiceTableFlowEntity, writeFlowInvTx);
+        mdsalManager.addFlow(confTx, dpnId, terminatingServiceTableFlowEntity);
     }
 
     private void makeLFibTableEntry(BigInteger dpId, long serviceId, String floatingIpPortMacAddress, short tableId,
-                                    WriteTransaction writeFlowInvTx) {
+                                    TypedWriteTransaction<Configuration> confTx) {
         List<MatchInfo> matches = new ArrayList<>();
         matches.add(MatchEthernetType.MPLS_UNICAST);
         matches.add(new MatchMplsLabel(serviceId));
@@ -459,25 +466,19 @@ public class VpnFloatingIpHandler implements FloatingIPHandler {
             10, flowRef, 0, 0,
             NwConstants.COOKIE_VM_LFIB_TABLE, matches, instructions);
 
-        mdsalManager.addFlowToTx(dpId, flowEntity, writeFlowInvTx);
+        mdsalManager.addFlow(confTx, dpId, flowEntity);
 
         LOG.debug("makeLFibTableEntry : LFIB Entry for dpID {} : label : {} modified successfully", dpId, serviceId);
     }
 
-    private void removeLFibTableEntry(BigInteger dpnId, long serviceId, WriteTransaction removeFlowInvTx) {
-        List<MatchInfo> matches = new ArrayList<>();
-        matches.add(MatchEthernetType.MPLS_UNICAST);
-        matches.add(new MatchMplsLabel(serviceId));
+    private void removeLFibTableEntry(BigInteger dpnId, long serviceId,
+        TypedReadWriteTransaction<Configuration> confTx) {
 
         String flowRef = getFlowRef(dpnId, NwConstants.L3_LFIB_TABLE, serviceId, "");
 
         LOG.debug("removeLFibTableEntry : removing LFib entry with flow ref {}", flowRef);
 
-        Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_LFIB_TABLE, flowRef,
-            10, flowRef, 0, 0,
-            NwConstants.COOKIE_VM_LFIB_TABLE, matches, null);
-
-        mdsalManager.removeFlowToTx(dpnId, flowEntity, removeFlowInvTx);
+        mdsalManager.removeFlow(confTx, dpnId, new FlowKey(new FlowId(flowRef)), NwConstants.L3_LFIB_TABLE);
 
         LOG.debug("removeLFibTableEntry : LFIB Entry for dpID : {} label : {} removed successfully",
                 dpnId, serviceId);
index 253490f610119d5ecc4f917905621be0078fadb3..672ad4407f479295db00067069587368a7d77082 100644 (file)
@@ -14,7 +14,6 @@ import java.util.List;
 
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.genius.infra.Datastore.Configuration;
-import org.opendaylight.genius.infra.TransactionAdapter;
 import org.opendaylight.genius.infra.TypedReadWriteTransaction;
 import org.opendaylight.genius.infra.TypedWriteTransaction;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
@@ -165,8 +164,7 @@ public class VxlanGreConntrackBasedSnatService extends ConntrackBasedSnatService
         }
         //The logic now handle only one external IP per router, others if present will be ignored.
         String externalIp = NatUtil.validateAndAddNetworkMask(externalIps.get(0).getIpAddress());
-        externalRouterListener.handleSnatReverseTraffic(dpnId, routers, routerId, routerName, externalIp,
-            TransactionAdapter.toWriteTransaction(confTx));
+        externalRouterListener.handleSnatReverseTraffic(confTx, dpnId, routers, routerId, routerName, externalIp);
     }
 
     @Override
@@ -207,8 +205,7 @@ public class VxlanGreConntrackBasedSnatService extends ConntrackBasedSnatService
         //The logic now handle only one external IP per router, others if present will be ignored.
         String externalIp = NatUtil.validateAndAddNetworkMask(externalIps.get(0).getIpAddress());
         externalRouterListener.clearFibTsAndReverseTraffic(dpnId, routerId, routers.getNetworkId(),
-            Collections.singletonList(externalIp), null, routers.getExtGwMacAddress(),
-            TransactionAdapter.toWriteTransaction(confTx));
+            Collections.singletonList(externalIp), null, routers.getExtGwMacAddress(), confTx);
     }
 
     protected void addOutboundTblTrackEntryForVxlanGre(TypedWriteTransaction<Configuration> confTx, BigInteger dpnId,