Migrate ListenableFutures.addErrorLogging() users
[netvirt.git] / natservice / impl / src / main / java / org / opendaylight / netvirt / natservice / internal / NatUtil.java
index 7a892907b553db530078a423e0753fe71e91f662..76f4315ae875babf0689b46572f7dafbeebcbdd3 100644 (file)
@@ -5,19 +5,15 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netvirt.natservice.internal;
 
 import static java.util.Collections.emptyList;
-import static java.util.Objects.requireNonNull;
-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.base.Preconditions;
 import com.google.common.base.Splitter;
 import com.google.common.base.Strings;
-
+import com.google.common.collect.Iterables;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.math.BigInteger;
 import java.net.InetAddress;
@@ -30,18 +26,17 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
+import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
+import java.util.concurrent.locks.ReentrantLock;
 import java.util.stream.Collectors;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
 import org.apache.commons.net.util.SubnetUtils;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-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.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.controller.sal.common.util.Arguments;
+import org.opendaylight.genius.datastoreutils.ExpectedDataObjectNotFoundException;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
 import org.opendaylight.genius.infra.Datastore.Configuration;
 import org.opendaylight.genius.infra.Datastore.Operational;
@@ -51,6 +46,7 @@ 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;
 import org.opendaylight.genius.mdsalutil.FlowEntity;
 import org.opendaylight.genius.mdsalutil.FlowEntityBuilder;
 import org.opendaylight.genius.mdsalutil.GroupEntity;
@@ -71,7 +67,11 @@ import org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable;
 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.genius.mdsalutil.matches.MatchEthernetType;
 import org.opendaylight.genius.mdsalutil.matches.MatchMetadata;
-import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
+import org.opendaylight.genius.utils.JvmGlobalLocks;
+import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
 import org.opendaylight.netvirt.bgpmanager.api.IBgpManager;
 import org.opendaylight.netvirt.elanmanager.api.IElanService;
 import org.opendaylight.netvirt.fibmanager.api.IFibManager;
@@ -80,13 +80,7 @@ import org.opendaylight.netvirt.natservice.ha.NatDataUtil;
 import org.opendaylight.netvirt.neutronvpn.api.utils.NeutronConstants;
 import org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils;
 import org.opendaylight.netvirt.vpnmanager.api.IVpnManager;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnAfConfig;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInstances;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInterfaces;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstanceKey;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey;
+import org.opendaylight.serviceutils.upgrade.UpgradeState;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefixBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
@@ -98,6 +92,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.acti
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput;
@@ -105,6 +100,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.BridgeRefInfo;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.bridge.ref.info.BridgeRefEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.bridge.ref.info.BridgeRefEntryKey;
@@ -132,6 +130,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanDpnInterfaces;
@@ -180,6 +179,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnListKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.IpAddresses;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.IpAddressesKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalIpsCounter;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks;
@@ -197,6 +197,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev16011
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIpsKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.ExternalCounters;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.ExternalCountersKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounter;
@@ -232,14 +233,25 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev16011
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.snatint.ip.port.map.intip.port.map.IpPortKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.snatint.ip.port.map.intip.port.map.ip.port.IntIpProtoType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.snatint.ip.port.map.intip.port.map.ip.port.IntIpProtoTypeKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.VpnInstances;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.VpnInterfaces;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstanceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetFixedIPsForNeutronPortInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetFixedIPsForNeutronPortOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NetworkMaps;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronVpnPortipPortData;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronvpnService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.VpnMaps;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMap;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMapKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPort;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPortKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.router.interfaces.Interfaces;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.router.interfaces.InterfacesKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap;
@@ -248,6 +260,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.router
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.RouterKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.PortKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet;
@@ -260,9 +273,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.re
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchOtherConfigs;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
-import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -274,30 +290,32 @@ public final class NatUtil {
     private static final String OTHER_CONFIG_KEY_VALUE_DELIMITER = ":";
     private static final String PROVIDER_MAPPINGS = "provider_mappings";
 
-    private NatUtil() { }
+    private NatUtil() {
+
+    }
 
     /*
      getCookieSnatFlow() computes and returns a unique cookie value for the NAT flows using the router ID as the
       reference value.
      */
-    public static BigInteger getCookieSnatFlow(long routerId) {
-        return NatConstants.COOKIE_NAPT_BASE.add(new BigInteger("0110000", 16)).add(
-            BigInteger.valueOf(routerId));
+    public static Uint64 getCookieSnatFlow(long routerId) {
+        return Uint64.valueOf(NatConstants.COOKIE_NAPT_BASE.toJava().add(new BigInteger("0110000", 16)).add(
+            BigInteger.valueOf(routerId)));
     }
 
     /*
       getCookieNaptFlow() computes and returns a unique cookie value for the NAPT flows using the router ID as the
        reference value.
     */
-    public static BigInteger getCookieNaptFlow(long routerId) {
-        return NatConstants.COOKIE_NAPT_BASE.add(new BigInteger("0111000", 16)).add(
-            BigInteger.valueOf(routerId));
+    public static Uint64 getCookieNaptFlow(Uint32 routerId) {
+        return Uint64.valueOf(NatConstants.COOKIE_NAPT_BASE.toJava().add(new BigInteger("0111000", 16)).add(
+            BigInteger.valueOf(routerId.longValue())));
     }
 
     /*
         getVpnId() returns the VPN ID from the VPN name
      */
-    public static long getVpnId(DataBroker broker, @Nullable String vpnName) {
+    public static Uint32 getVpnId(DataBroker broker, @Nullable String vpnName) {
         if (vpnName == null) {
             return NatConstants.INVALID_ID;
         }
@@ -309,9 +327,9 @@ public final class NatUtil {
                 SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
                         LogicalDatastoreType.CONFIGURATION, id);
 
-        long vpnId = NatConstants.INVALID_ID;
+        Uint32 vpnId = NatConstants.INVALID_ID;
         if (vpnInstance.isPresent()) {
-            Long vpnIdAsLong = vpnInstance.get().getVpnId();
+            Uint32 vpnIdAsLong = vpnInstance.get().getVpnId();
             if (vpnIdAsLong != null) {
                 vpnId = vpnIdAsLong;
             }
@@ -319,13 +337,13 @@ public final class NatUtil {
         return vpnId;
     }
 
-    public static long getVpnId(TypedReadTransaction<Configuration> confTx, String vpnName) {
+    public static Uint32 getVpnId(TypedReadTransaction<Configuration> confTx, String vpnName) {
         if (vpnName == null) {
             return NatConstants.INVALID_ID;
         }
 
         try {
-            return confTx.read(getVpnInstanceToVpnIdIdentifier(vpnName)).get().toJavaUtil().map(
+            return confTx.read(getVpnInstanceToVpnIdIdentifier(vpnName)).get().map(
                 org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id
                     .VpnInstance::getVpnId).orElse(NatConstants.INVALID_ID);
         } catch (InterruptedException | ExecutionException e) {
@@ -335,7 +353,7 @@ public final class NatUtil {
         return NatConstants.INVALID_ID;
     }
 
-    public static Long getNetworkVpnIdFromRouterId(DataBroker broker, long routerId) {
+    public static Uint32 getNetworkVpnIdFromRouterId(DataBroker broker, Uint32 routerId) {
         //Get the external network ID from the ExternalRouter model
         Uuid networkId = NatUtil.getNetworkIdFromRouterId(broker, routerId);
         if (networkId == null) {
@@ -349,10 +367,56 @@ public final class NatUtil {
             LOG.error("getNetworkVpnIdFromRouterId : vpnUuid is null");
             return NatConstants.INVALID_ID;
         }
-        Long vpnId = NatUtil.getVpnId(broker, vpnUuid.getValue());
+        Uint32 vpnId = NatUtil.getVpnId(broker, vpnUuid.getValue());
         return vpnId;
     }
 
+    public static Boolean validateIsIntefacePartofRouter(DataBroker broker, String routerName, String interfaceName) {
+        InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces
+            .map.router.interfaces.Interfaces> vmInterfaceIdentifier = getRoutersInterfacesIdentifier(routerName,
+            interfaceName);
+
+        Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces
+            .map.router.interfaces.Interfaces> routerInterfacesData;
+        try {
+            routerInterfacesData = SingleTransactionDataBroker.syncReadOptional(broker,
+                LogicalDatastoreType.CONFIGURATION, vmInterfaceIdentifier);
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("Read Failed Exception While read RouterInterface data for router {}", routerName, e);
+            routerInterfacesData = Optional.empty();
+        }
+        if (routerInterfacesData.isPresent()) {
+            return Boolean.TRUE;
+        } else {
+            return Boolean.FALSE;
+        }
+    }
+
+    private static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn
+        .rev150602.router.interfaces
+        .map.router.interfaces.Interfaces> getRoutersInterfacesIdentifier(String routerName, String interfaceName) {
+        return InstanceIdentifier.builder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn
+            .rev150602.RouterInterfacesMap.class)
+            .child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router
+                    .interfaces.map.RouterInterfaces.class,
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router
+                    .interfaces.map.RouterInterfacesKey(new Uuid(routerName)))
+            .child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces
+                    .map.router.interfaces.Interfaces.class,
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces
+                    .map.router.interfaces.InterfacesKey(interfaceName)).build();
+    }
+
+    private static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn
+        .rev150602.router.interfaces.map.RouterInterfaces> getRoutersInterfacesIdentifier(String routerName) {
+        return InstanceIdentifier.builder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn
+            .rev150602.RouterInterfacesMap.class)
+            .child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router
+                    .interfaces.map.RouterInterfaces.class,
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router
+                    .interfaces.map.RouterInterfacesKey(new Uuid(routerName))).build();
+    }
+
     static InstanceIdentifier<RouterPorts> getRouterPortsId(String routerId) {
         return InstanceIdentifier.builder(FloatingIpInfo.class)
             .child(RouterPorts.class, new RouterPortsKey(routerId)).build();
@@ -385,34 +449,38 @@ public final class NatUtil {
     }
 
     @Nullable
-    static String getVpnInstanceFromVpnIdentifier(DataBroker broker, long vpnId) {
+    static String getVpnInstanceFromVpnIdentifier(DataBroker broker, Uint32 vpnId) {
         InstanceIdentifier<VpnIds> id = InstanceIdentifier.builder(VpnIdToVpnInstance.class)
             .child(VpnIds.class, new VpnIdsKey(vpnId)).build();
         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                LogicalDatastoreType.CONFIGURATION, id).toJavaUtil().map(VpnIds::getVpnInstanceName).orElse(null);
+                LogicalDatastoreType.CONFIGURATION, id).map(VpnIds::getVpnInstanceName).orElse(null);
     }
 
     /*
        getFlowRef() returns a string identfier for the SNAT flows using the router ID as the reference.
     */
-    public static String getFlowRef(BigInteger dpnId, short tableId, long routerID, String ip) {
-        return NatConstants.NAPT_FLOWID_PREFIX + dpnId + NatConstants.FLOWID_SEPARATOR + tableId + NatConstants
-                .FLOWID_SEPARATOR + routerID + NatConstants.FLOWID_SEPARATOR + ip;
+    public static String getFlowRef(Uint64 dpnId, short tableId, Uint32 routerID, String ip) {
+        return new StringBuilder().append(NatConstants.NAPT_FLOWID_PREFIX).append(dpnId)
+            .append(NatConstants.FLOWID_SEPARATOR).append(tableId).append(NatConstants.FLOWID_SEPARATOR)
+            .append(routerID).append(NatConstants.FLOWID_SEPARATOR).append(ip).toString();
     }
 
-    public static String getFlowRef(BigInteger dpnId, short tableId, InetAddress destPrefix, long vpnId) {
-        return NatConstants.NAPT_FLOWID_PREFIX + dpnId + NatConstants.FLOWID_SEPARATOR + tableId + NatConstants
-                .FLOWID_SEPARATOR + destPrefix.getHostAddress() + NatConstants.FLOWID_SEPARATOR + vpnId;
+    public static String getFlowRef(Uint64 dpnId, short tableId, InetAddress destPrefix, Uint32 vpnId) {
+        return new StringBuilder().append(NatConstants.NAPT_FLOWID_PREFIX).append(dpnId)
+            .append(NatConstants.FLOWID_SEPARATOR).append(tableId).append(NatConstants.FLOWID_SEPARATOR)
+            .append(destPrefix.getHostAddress()).append(NatConstants.FLOWID_SEPARATOR).append(vpnId).toString();
     }
 
-    public static String getNaptFlowRef(BigInteger dpnId, short tableId, String routerID, String ip, int port) {
-        return NatConstants.NAPT_FLOWID_PREFIX + dpnId + NatConstants.FLOWID_SEPARATOR + tableId + NatConstants
-                .FLOWID_SEPARATOR + routerID + NatConstants.FLOWID_SEPARATOR + ip + NatConstants.FLOWID_SEPARATOR
-                + port;
+    public static String getNaptFlowRef(Uint64 dpnId, short tableId, String routerID, String ip,
+        int port, String protocol) {
+        return new StringBuilder().append(NatConstants.NAPT_FLOWID_PREFIX).append(dpnId)
+            .append(NatConstants.FLOWID_SEPARATOR).append(tableId).append(NatConstants.FLOWID_SEPARATOR)
+            .append(routerID).append(NatConstants.FLOWID_SEPARATOR).append(ip).append(NatConstants.FLOWID_SEPARATOR)
+            .append(port).append(NatConstants.FLOWID_SEPARATOR).append(protocol).toString();
     }
 
     @Nullable
-    static Uuid getNetworkIdFromRouterId(DataBroker broker, long routerId) {
+    static Uuid getNetworkIdFromRouterId(DataBroker broker, Uint32 routerId) {
         String routerName = getRouterName(broker, routerId);
         if (routerName == null) {
             LOG.error("getNetworkIdFromRouterId - empty routerName received");
@@ -429,7 +497,7 @@ public final class NatUtil {
         }
         InstanceIdentifier<Routers> id = buildRouterIdentifier(routerName);
         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                LogicalDatastoreType.CONFIGURATION, id).toJavaUtil().map(Routers::getNetworkId).orElse(null);
+                LogicalDatastoreType.CONFIGURATION, id).map(Routers::getNetworkId).orElse(null);
     }
 
     static InstanceIdentifier<Routers> buildRouterIdentifier(String routerId) {
@@ -438,7 +506,7 @@ public final class NatUtil {
         return routerInstanceIndentifier;
     }
 
-    private static InstanceIdentifier<RouterIds> buildRouterIdentifier(Long routerId) {
+    private static InstanceIdentifier<RouterIds> buildRouterIdentifier(Uint32 routerId) {
         InstanceIdentifier<RouterIds> routerIds = InstanceIdentifier.builder(RouterIdName.class)
             .child(RouterIds.class, new RouterIdsKey(routerId)).build();
         return routerIds;
@@ -454,20 +522,20 @@ public final class NatUtil {
     static boolean isSnatEnabledForRouterId(DataBroker broker, String routerId) {
         InstanceIdentifier<Routers> id = buildRouterIdentifier(routerId);
         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                LogicalDatastoreType.CONFIGURATION, id).toJavaUtil().map(Routers::isEnableSnat).orElse(false);
+                LogicalDatastoreType.CONFIGURATION, id).map(Routers::isEnableSnat).orElse(false);
     }
 
     @Nullable
     public static Uuid getVpnIdfromNetworkId(DataBroker broker, Uuid networkId) {
         InstanceIdentifier<Networks> id = buildNetworkIdentifier(networkId);
         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                LogicalDatastoreType.CONFIGURATION, id).toJavaUtil().map(Networks::getVpnid).orElse(null);
+                LogicalDatastoreType.CONFIGURATION, id).map(Networks::getVpnid).orElse(null);
     }
 
     @Nullable
     public static Uuid getVpnIdfromNetworkId(TypedReadTransaction<Configuration> tx, Uuid networkId) {
         try {
-            return tx.read(buildNetworkIdentifier(networkId)).get().toJavaUtil().map(Networks::getVpnid).orElse(null);
+            return tx.read(buildNetworkIdentifier(networkId)).get().map(Networks::getVpnid).orElse(null);
         } catch (InterruptedException | ExecutionException e) {
             LOG.error("Error reading network VPN id for {}", networkId, e);
             return null;
@@ -478,28 +546,20 @@ public final class NatUtil {
     public static ProviderTypes getProviderTypefromNetworkId(DataBroker broker, Uuid networkId) {
         InstanceIdentifier<Networks> id = buildNetworkIdentifier(networkId);
         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                LogicalDatastoreType.CONFIGURATION, id).toJavaUtil().map(Networks::getProviderNetworkType).orElse(null);
+                LogicalDatastoreType.CONFIGURATION, id).map(Networks::getProviderNetworkType).orElse(null);
     }
 
     @Nullable
     public static ProviderTypes getProviderTypefromNetworkId(TypedReadTransaction<Configuration> tx, Uuid networkId) {
         InstanceIdentifier<Networks> id = buildNetworkIdentifier(networkId);
         try {
-            return tx.read(id).get().toJavaUtil().map(Networks::getProviderNetworkType).orElse(null);
+            return tx.read(id).get().map(Networks::getProviderNetworkType).orElse(null);
         } catch (InterruptedException | ExecutionException e) {
             LOG.error("Error retrieving provider type for {}", networkId, e);
             return null;
         }
     }
 
-    @Nonnull
-    public static List<Uuid> getRouterIdsfromNetworkId(DataBroker broker, Uuid networkId) {
-        InstanceIdentifier<Networks> id = buildNetworkIdentifier(networkId);
-        return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                LogicalDatastoreType.CONFIGURATION, id).toJavaUtil().map(Networks::getRouterIds).orElse(
-                emptyList());
-    }
-
     @Nullable
     static String getAssociatedExternalNetwork(DataBroker dataBroker, String routerId) {
         InstanceIdentifier<Routers> id = NatUtil.buildRouterIdentifier(routerId);
@@ -522,7 +582,7 @@ public final class NatUtil {
     }
 
     @Nullable
-    public static BigInteger getPrimaryNaptfromRouterId(DataBroker broker, Long routerId) {
+    public static Uint64 getPrimaryNaptfromRouterId(DataBroker broker, Uint32 routerId) {
         // convert routerId to Name
         String routerName = getRouterName(broker, routerId);
         if (routerName == null) {
@@ -533,15 +593,15 @@ public final class NatUtil {
     }
 
     @Nullable
-    public static BigInteger getPrimaryNaptfromRouterName(DataBroker broker, String routerName) {
+    public static Uint64 getPrimaryNaptfromRouterName(DataBroker broker, String routerName) {
         if (routerName == null) {
             LOG.error("getPrimaryNaptfromRouterName - empty routerName received");
             return null;
         }
         InstanceIdentifier<RouterToNaptSwitch> id = buildNaptSwitchIdentifier(routerName);
-        return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                LogicalDatastoreType.CONFIGURATION, id).toJavaUtil().map(RouterToNaptSwitch::getPrimarySwitchId).orElse(
-                null);
+        return (SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
+                LogicalDatastoreType.CONFIGURATION, id).map(RouterToNaptSwitch::getPrimarySwitchId).orElse(
+                Uint64.valueOf(0L)));
     }
 
     public static InstanceIdentifier<RouterToNaptSwitch> buildNaptSwitchIdentifier(String routerId) {
@@ -555,7 +615,7 @@ public final class NatUtil {
     }
 
     @Nullable
-    public static String getRouterName(DataBroker broker, Long routerId) {
+    public static String getRouterName(DataBroker broker, Uint32 routerId) {
         return getVpnInstanceFromVpnIdentifier(broker, routerId);
     }
 
@@ -564,7 +624,7 @@ public final class NatUtil {
             .child(VpnInstanceOpDataEntry.class, new VpnInstanceOpDataEntryKey(vrfId)).build();
     }
 
-    public static FlowEntity buildFlowEntity(BigInteger dpnId, short tableId, BigInteger cookie, String flowId) {
+    public static FlowEntity buildFlowEntity(Uint64 dpnId, short tableId, Uint64 cookie, String flowId) {
         return new FlowEntityBuilder()
                 .setDpnId(dpnId)
                 .setTableId(tableId)
@@ -573,7 +633,7 @@ public final class NatUtil {
                 .build();
     }
 
-    public static FlowEntity buildFlowEntity(BigInteger dpnId, short tableId, String flowId) {
+    public static FlowEntity buildFlowEntity(Uint64 dpnId, short tableId, String flowId) {
         return new FlowEntityBuilder()
                 .setDpnId(dpnId)
                 .setTableId(tableId)
@@ -581,13 +641,8 @@ public final class NatUtil {
                 .build();
     }
 
-    public static long getIpAddress(byte[] rawIpAddress) {
-        return ((rawIpAddress[0] & 0xFF) << 3 * 8) + ((rawIpAddress[1] & 0xFF) << 2 * 8)
-            + ((rawIpAddress[2] & 0xFF) << 1 * 8) + (rawIpAddress[3] & 0xFF) & 0xffffffffL;
-    }
-
     @Nullable
-    public static String getEndpointIpAddressForDPN(DataBroker broker, BigInteger dpnId) {
+    public static String getEndpointIpAddressForDPN(DataBroker broker, Uint64 dpnId) {
         String nextHopIp = null;
         InstanceIdentifier<DPNTEPsInfo> tunnelInfoId =
             InstanceIdentifier.builder(DpnEndpoints.class)
@@ -609,7 +664,7 @@ public final class NatUtil {
         InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn
             .instance.to.vpn.id.VpnInstance> id = getVpnInstanceToVpnIdIdentifier(vpnName);
         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                LogicalDatastoreType.CONFIGURATION, id).toJavaUtil().map(
+                LogicalDatastoreType.CONFIGURATION, id).map(
                 org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id
                         .VpnInstance::getVrfId).orElse(null);
     }
@@ -617,7 +672,7 @@ public final class NatUtil {
     @Nullable
     public static String getVpnRd(TypedReadTransaction<Configuration> tx, String vpnName) {
         try {
-            return tx.read(getVpnInstanceToVpnIdIdentifier(vpnName)).get().toJavaUtil().map(
+            return tx.read(getVpnInstanceToVpnIdIdentifier(vpnName)).get().map(
                 org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id
                     .VpnInstance::getVrfId).orElse(null);
         } catch (InterruptedException | ExecutionException e) {
@@ -627,17 +682,17 @@ public final class NatUtil {
     }
 
     @Nullable
-    public static IpPortExternal getExternalIpPortMap(DataBroker broker, Long routerId, String internalIpAddress,
+    public static IpPortExternal getExternalIpPortMap(DataBroker broker, Uint32 routerId, String internalIpAddress,
                                                       String internalPort, NAPTEntryEvent.Protocol protocol) {
         ProtocolTypes protocolType = NatUtil.getProtocolType(protocol);
         InstanceIdentifier<IpPortMap> ipPortMapId =
             buildIpToPortMapIdentifier(routerId, internalIpAddress, internalPort, protocolType);
         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                LogicalDatastoreType.CONFIGURATION, ipPortMapId).toJavaUtil().map(IpPortMap::getIpPortExternal).orElse(
+                LogicalDatastoreType.CONFIGURATION, ipPortMapId).map(IpPortMap::getIpPortExternal).orElse(
                 null);
     }
 
-    private static InstanceIdentifier<IpPortMap> buildIpToPortMapIdentifier(Long routerId, String internalIpAddress,
+    private static InstanceIdentifier<IpPortMap> buildIpToPortMapIdentifier(Uint32 routerId, String internalIpAddress,
                                                                             String internalPort,
                                                                             ProtocolTypes protocolType) {
         return InstanceIdentifier.builder(IntextIpPortMap.class)
@@ -651,13 +706,6 @@ public final class NatUtil {
             .child(VpnInterface.class, new VpnInterfaceKey(vpnInterfaceName)).build();
     }
 
-    @Nullable
-    static VpnInterface getConfiguredVpnInterface(DataBroker broker, String interfaceName) {
-        InstanceIdentifier<VpnInterface> interfaceId = getVpnInterfaceIdentifier(interfaceName);
-        return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                LogicalDatastoreType.CONFIGURATION, interfaceId).orNull();
-    }
-
     @Nullable
     public static String getDpnFromNodeConnectorId(NodeConnectorId portId) {
         /*
@@ -671,12 +719,12 @@ public final class NatUtil {
         return split[1];
     }
 
-    public static BigInteger getDpIdFromInterface(
+    public static Uint64 getDpIdFromInterface(
         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces
             .state.Interface ifState) {
         String lowerLayerIf = ifState.getLowerLayerIf().get(0);
         NodeConnectorId nodeConnectorId = new NodeConnectorId(lowerLayerIf);
-        return new BigInteger(getDpnFromNodeConnectorId(nodeConnectorId));
+        return Uint64.valueOf(getDpnFromNodeConnectorId(nodeConnectorId));
     }
 
 
@@ -692,7 +740,9 @@ public final class NatUtil {
             LOG.error("getRouterIdfromVpnInstance : Router not found for vpn : {}", vpnName);
             return null;
         }
-        List<Uuid> routerIdsList = NeutronUtils.getVpnMapRouterIdsListUuid(optionalVpnMap.get().getRouterIds());
+        List<Uuid> routerIdsList = NeutronUtils.getVpnMapRouterIdsListUuid(
+                new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602
+                        .vpnmaps.vpnmap.RouterIds>(optionalVpnMap.get().nonnullRouterIds().values()));
         if (routerIdsList != null && !routerIdsList.isEmpty()) {
             for (Uuid routerUuid : routerIdsList) {
                 InstanceIdentifier<Routers> id = buildRouterIdentifier(routerUuid.getValue());
@@ -717,18 +767,19 @@ public final class NatUtil {
 
     @Nullable
     static Uuid getVpnForRouter(DataBroker broker, String routerId) {
-        Preconditions.checkNotNull(routerId, "dissociateRouter: routerId not found!");
+        Preconditions.checkNotNull(routerId, "getVpnForRouter: routerId not found!");
         InstanceIdentifier<VpnMaps> vpnMapsIdentifier = InstanceIdentifier.builder(VpnMaps.class).build();
         Optional<VpnMaps> optionalVpnMaps =
                 SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
                         LogicalDatastoreType.CONFIGURATION, vpnMapsIdentifier);
         if (optionalVpnMaps.isPresent() && optionalVpnMaps.get().getVpnMap() != null) {
-            for (VpnMap vpnMap : requireNonNullElse(optionalVpnMaps.get().getVpnMap(),
-                    Collections.<VpnMap>emptyList())) {
+            for (VpnMap vpnMap : optionalVpnMaps.get().nonnullVpnMap().values()) {
                 if (routerId.equals(vpnMap.getVpnId().getValue())) {
                     continue;
                 }
-                List<Uuid> routerIdsList = NeutronUtils.getVpnMapRouterIdsListUuid(vpnMap.getRouterIds());
+                List<Uuid> routerIdsList = NeutronUtils.getVpnMapRouterIdsListUuid(
+                        new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602
+                                .vpnmaps.vpnmap.RouterIds>(vpnMap.nonnullRouterIds().values()));
                 if (routerIdsList.isEmpty()) {
                     continue;
                 }
@@ -749,10 +800,10 @@ public final class NatUtil {
         return null;
     }
 
-    static long getAssociatedVpn(DataBroker broker, String routerName) {
+    static Uint32 getAssociatedVpn(DataBroker broker, String routerName) {
         InstanceIdentifier<Routermapping> routerMappingId = NatUtil.getRouterVpnMappingId(routerName);
         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                LogicalDatastoreType.OPERATIONAL, routerMappingId).toJavaUtil().map(Routermapping::getVpnId).orElse(
+                LogicalDatastoreType.OPERATIONAL, routerMappingId).map(Routermapping::getVpnId).orElse(
                 NatConstants.INVALID_ID);
     }
 
@@ -787,10 +838,10 @@ public final class NatUtil {
                                       String nextHopIp,
                                       @Nullable String parentVpnRd,
                                       @Nullable String macAddress,
-                                      long label,
-                                      long l3vni,
+                                      Uint32 label,
+                                      Uint32 l3vni,
                                       RouteOrigin origin,
-                                      BigInteger dpId) {
+                                      Uint64 dpId) {
         try {
             LOG.info("addPrefixToBGP : Adding Fib entry rd {} prefix {} nextHop {} label {}", rd,
                     prefix, nextHopIp, label);
@@ -802,13 +853,14 @@ public final class NatUtil {
 
             addPrefixToInterface(broker, getVpnId(broker, vpnName), null /*interfaceName*/,prefix, parentVpnRd,
                 dpId, Prefixes.PrefixCue.Nat);
+
             fibManager.addOrUpdateFibEntry(rd, macAddress, prefix,
-                    Collections.singletonList(nextHopIp), VrfEntry.EncapType.Mplsgre, (int)label, l3vni /*l3vni*/,
+                    Collections.singletonList(nextHopIp), VrfEntry.EncapType.Mplsgre, label, l3vni /*l3vni*/,
                     null /*gatewayMacAddress*/, parentVpnRd, origin, null /*writeTxn*/);
             if (rd != null && !rd.equalsIgnoreCase(vpnName)) {
             /* Publish to Bgp only if its an INTERNET VPN */
                 bgpManager.advertisePrefix(rd, null /*macAddress*/, prefix, Collections.singletonList(nextHopIp),
-                        VrfEntry.EncapType.Mplsgre, (int) label, 0 /*l3vni*/, 0 /*l2vni*/,
+                        VrfEntry.EncapType.Mplsgre, label, Uint32.ZERO /*l3vni*/, Uint32.ZERO  /*l2vni*/,
                         null /*gatewayMac*/);
             }
             LOG.info("addPrefixToBGP : Added Fib entry rd {} prefix {} nextHop {} label {}", rd,
@@ -819,8 +871,8 @@ public final class NatUtil {
         }
     }
 
-    static void addPrefixToInterface(DataBroker broker, long vpnId, @Nullable String interfaceName, String ipPrefix,
-                                     String networkId, BigInteger dpId, Prefixes.PrefixCue prefixCue) {
+    static void addPrefixToInterface(DataBroker broker, Uint32 vpnId, @Nullable String interfaceName, String ipPrefix,
+                                     String networkId, Uint64 dpId, Prefixes.PrefixCue prefixCue) {
         InstanceIdentifier<Prefixes> prefixId = InstanceIdentifier.builder(PrefixToInterface.class)
                 .child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface
                         .VpnIds.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix
@@ -838,7 +890,7 @@ public final class NatUtil {
         }
     }
 
-    public static void deletePrefixToInterface(DataBroker broker, long vpnId, String ipPrefix) {
+    public static void deletePrefixToInterface(DataBroker broker, Uint32 vpnId, String ipPrefix) {
         try {
             SingleTransactionDataBroker.syncDelete(broker, LogicalDatastoreType.OPERATIONAL,
                     InstanceIdentifier.builder(PrefixToInterface.class)
@@ -847,7 +899,7 @@ public final class NatUtil {
                             .prefix.to._interface.VpnIdsKey(vpnId)).child(Prefixes.class, new PrefixesKey(ipPrefix))
                     .build());
         } catch (TransactionCommitFailedException e) {
-            LOG.error("addPrefixToInterface : Failed to write prefxi-to-interface for vpn-id {}",
+            LOG.error("deletePrefixToInterface : Failed to delete prefxi-to-interface for vpn-id {}",
                     vpnId, e);
         }
     }
@@ -864,16 +916,22 @@ public final class NatUtil {
         return routerInstanceIndentifier;
     }
 
-    @Nonnull
-    public static List<Integer> getInternalIpPortListInfo(DataBroker dataBroker, Long routerId,
+    @NonNull
+    public static List<Uint16> getInternalIpPortListInfo(DataBroker dataBroker, Uint32 routerId,
                                                           String internalIpAddress, ProtocolTypes protocolType) {
-        return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
+        List<Uint16> portList = SingleTransactionDataBroker
+                .syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
                 LogicalDatastoreType.CONFIGURATION,
-                buildSnatIntIpPortIdentifier(routerId, internalIpAddress, protocolType)).toJavaUtil().map(
+                        buildSnatIntIpPortIdentifier(routerId, internalIpAddress, protocolType)).map(
                 IntIpProtoType::getPorts).orElse(emptyList());
+
+        if (!portList.isEmpty()) {
+            portList = new ArrayList<>(portList);
+        }
+        return portList;
     }
 
-    public static InstanceIdentifier<IntIpProtoType> buildSnatIntIpPortIdentifier(Long routerId,
+    public static InstanceIdentifier<IntIpProtoType> buildSnatIntIpPortIdentifier(Uint32 routerId,
                                                                                   String internalIpAddress,
                                                                                   ProtocolTypes protocolType) {
         InstanceIdentifier<IntIpProtoType> intIpProtocolTypeId =
@@ -898,7 +956,7 @@ public final class NatUtil {
                                                           String internalIpAddress) {
         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
                 LogicalDatastoreType.CONFIGURATION,
-                buildSnatIntIpPortIdentifier(routerId, internalIpAddress)).orNull();
+                buildSnatIntIpPortIdentifier(routerId, internalIpAddress)).orElse(null);
     }
 
     public static ProtocolTypes getProtocolType(NAPTEntryEvent.Protocol protocol) {
@@ -920,50 +978,67 @@ public final class NatUtil {
         return "snatmiss." + routerName;
     }
 
-    public static long createGroupId(String groupIdKey, IdManagerService idManager) {
-        AllocateIdInput getIdInput = new AllocateIdInputBuilder()
-            .setPoolName(NatConstants.SNAT_IDPOOL_NAME).setIdKey(groupIdKey)
-            .build();
+    public static Uint32 getUniqueId(IdManagerService idManager, String poolName, String idKey) {
+
+        AllocateIdInput getIdInput = (new AllocateIdInputBuilder()).setPoolName(poolName).setIdKey(idKey).build();
         try {
             Future<RpcResult<AllocateIdOutput>> result = idManager.allocateId(getIdInput);
-            RpcResult<AllocateIdOutput> rpcResult = result.get();
-            return rpcResult.getResult().getIdValue();
-        } catch (NullPointerException | InterruptedException | ExecutionException e) {
-            LOG.error("createGroupId : Creating Group with Key: {} failed", groupIdKey, e);
+            RpcResult<AllocateIdOutput> rpcResult = (RpcResult)result.get();
+            return rpcResult.isSuccessful() ? rpcResult.getResult().getIdValue()
+                    : NatConstants.INVALID_ID;
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("releaseId: Exception when releasing Id for key {} from pool {}", idKey, poolName, e);
+        }
+        return NatConstants.INVALID_ID;
+    }
+
+    public static Uint32 releaseId(IdManagerService idManager, String poolName, String idKey) {
+        ReleaseIdInput idInput = new ReleaseIdInputBuilder().setPoolName(poolName).setIdKey(idKey).build();
+        try {
+            Future<RpcResult<ReleaseIdOutput>> result = idManager.releaseId(idInput);
+            if (result == null || result.get() == null || !result.get().isSuccessful()) {
+                LOG.error("releaseId: RPC Call to release Id from pool {} with key {} returned with Errors {}",
+                    poolName, idKey,
+                    (result != null && result.get() != null) ? result.get().getErrors() : "RpcResult is null");
+            } else {
+                return Uint32.ONE;
+            }
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("releaseId: Exception when releasing Id for key {} from pool {}", idKey, poolName, e);
         }
-        return 0;
+        return NatConstants.INVALID_ID;
     }
 
     // TODO Clean up the exception handling
     @SuppressWarnings("checkstyle:IllegalCatch")
     public static void removePrefixFromBGP(IBgpManager bgpManager, IFibManager fibManager,
-                                           String rd, String prefix, String vpnName, Logger log) {
+                                           String rd, String prefix, String vpnName) {
         try {
             LOG.debug("removePrefixFromBGP: Removing Fib entry rd {} prefix {}", rd, prefix);
-            fibManager.removeFibEntry(rd, prefix, null);
+            fibManager.removeFibEntry(rd, prefix, null, null);
             if (rd != null && !rd.equalsIgnoreCase(vpnName)) {
                 bgpManager.withdrawPrefix(rd, prefix);
             }
             LOG.info("removePrefixFromBGP: Removed Fib entry rd {} prefix {}", rd, prefix);
         } catch (Exception e) {
-            log.error("removePrefixFromBGP : Delete prefix for rd {} prefix {} vpnName {} failed",
+            LOG.error("removePrefixFromBGP : Delete prefix for rd {} prefix {} vpnName {} failed",
                     rd, prefix, vpnName, e);
         }
     }
 
     @Nullable
-    public static IpPortMapping getIportMapping(DataBroker broker, long routerId) {
+    public static IpPortMapping getIportMapping(DataBroker broker, Uint32 routerId) {
         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                LogicalDatastoreType.CONFIGURATION, getIportMappingIdentifier(routerId)).orNull();
+                LogicalDatastoreType.CONFIGURATION, getIportMappingIdentifier(routerId)).orElse(null);
     }
 
-    public static InstanceIdentifier<IpPortMapping> getIportMappingIdentifier(long routerId) {
+    public static InstanceIdentifier<IpPortMapping> getIportMappingIdentifier(Uint32 routerId) {
         return InstanceIdentifier.builder(IntextIpPortMap.class)
             .child(IpPortMapping.class, new IpPortMappingKey(routerId)).build();
     }
 
     public static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt
-        .natservice.rev160111.intext.ip.map.IpMapping> getIpMappingBuilder(Long routerId) {
+        .natservice.rev160111.intext.ip.map.IpMapping> getIpMappingBuilder(Uint32 routerId) {
         return InstanceIdentifier.builder(IntextIpMap.class)
             .child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map
                 .IpMapping.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111
@@ -971,8 +1046,8 @@ public final class NatUtil {
             .build();
     }
 
-    @Nonnull
-    public static Collection<String> getExternalIpsForRouter(DataBroker dataBroker, Long routerId) {
+    @NonNull
+    public static Collection<String> getExternalIpsForRouter(DataBroker dataBroker, Uint32 routerId) {
         Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext
             .ip.map.IpMapping> ipMappingOptional =
                 SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
@@ -980,32 +1055,33 @@ public final class NatUtil {
         // Ensure there are no duplicates
         Collection<String> externalIps = new HashSet<>();
         if (ipMappingOptional.isPresent()) {
-            for (IpMap ipMap : requireNonNullElse(ipMappingOptional.get().getIpMap(), Collections.<IpMap>emptyList())) {
+            for (IpMap ipMap : ipMappingOptional.get().nonnullIpMap().values()) {
                 externalIps.add(ipMap.getExternalIp());
             }
         }
         return externalIps;
     }
 
-    @Nonnull
+    @NonNull
     public static List<String> getExternalIpsForRouter(DataBroker dataBroker, String routerName) {
         Routers routerData = NatUtil.getRoutersFromConfigDS(dataBroker, routerName);
         if (routerData != null) {
-            return NatUtil.getIpsListFromExternalIps(routerData.getExternalIps());
+            return NatUtil.getIpsListFromExternalIps(
+                    new ArrayList<ExternalIps>(routerData.nonnullExternalIps().values()));
         }
 
         return emptyList();
     }
 
-    @Nonnull
-    public static Map<String, Long> getExternalIpsLabelForRouter(DataBroker dataBroker, Long routerId) {
+    @NonNull
+    public static Map<String, Uint32> getExternalIpsLabelForRouter(DataBroker dataBroker, Uint32 routerId) {
         Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext
             .ip.map.IpMapping> ipMappingOptional =
                 SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
                         LogicalDatastoreType.OPERATIONAL, getIpMappingBuilder(routerId));
-        Map<String, Long> externalIpsLabel = new HashMap<>();
+        Map<String, Uint32> externalIpsLabel = new HashMap<>();
         if (ipMappingOptional.isPresent()) {
-            for (IpMap ipMap : requireNonNullElse(ipMappingOptional.get().getIpMap(), Collections.<IpMap>emptyList())) {
+            for (IpMap ipMap : ipMappingOptional.get().nonnullIpMap().values()) {
                 externalIpsLabel.put(ipMap.getExternalIp(), ipMap.getLabel());
             }
         }
@@ -1013,20 +1089,26 @@ public final class NatUtil {
     }
 
     @Nullable
-    public static String getLeastLoadedExternalIp(DataBroker dataBroker, long segmentId) {
+    public static String getLeastLoadedExternalIp(DataBroker dataBroker, Uint32 segmentId) {
         String leastLoadedExternalIp = null;
         InstanceIdentifier<ExternalCounters> id =
             InstanceIdentifier.builder(ExternalIpsCounter.class)
                 .child(ExternalCounters.class, new ExternalCountersKey(segmentId)).build();
-        Optional<ExternalCounters> externalCountersData =
-            MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
+        Optional<ExternalCounters> externalCountersData;
+        try {
+            externalCountersData = SingleTransactionDataBroker.syncReadOptional(dataBroker,
+                    LogicalDatastoreType.OPERATIONAL, id);
+        } catch (ExecutionException | InterruptedException e) {
+            LOG.error("getLeastLoadedExternalIp: Exception while reading ExternalCounters DS for the segmentId {}",
+                    segmentId, e);
+            return leastLoadedExternalIp;
+        }
         if (externalCountersData.isPresent()) {
             ExternalCounters externalCounter = externalCountersData.get();
             short countOfLstLoadExtIp = 32767;
-            for (ExternalIpCounter externalIpCounter : requireNonNullElse(externalCounter.getExternalIpCounter(),
-                    Collections.<ExternalIpCounter>emptyList())) {
+            for (ExternalIpCounter externalIpCounter : externalCounter.nonnullExternalIpCounter().values()) {
                 String curExternalIp = externalIpCounter.getExternalIp();
-                short countOfCurExtIp = externalIpCounter.getCounter();
+                short countOfCurExtIp = externalIpCounter.getCounter().toJava();
                 if (countOfCurExtIp < countOfLstLoadExtIp) {
                     countOfLstLoadExtIp = countOfCurExtIp;
                     leastLoadedExternalIp = curExternalIp;
@@ -1047,7 +1129,7 @@ public final class NatUtil {
         return null;
     }
 
-    @Nonnull
+    @NonNull
     public static String[] getSubnetIpAndPrefix(String subnetString) {
         String[] subnetSplit = subnetString.split("/");
         String subnetIp = subnetSplit[0];
@@ -1065,7 +1147,7 @@ public final class NatUtil {
             .child(Subnetmap.class, new SubnetmapKey(subnetId))
             .build();
         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
-                LogicalDatastoreType.CONFIGURATION, subnetmapId).toJavaUtil().map(Subnetmap::getSubnetIp).orElse(null);
+                LogicalDatastoreType.CONFIGURATION, subnetmapId).map(Subnetmap::getSubnetIp).orElse(null);
     }
 
     public static String[] getExternalIpAndPrefix(String leastLoadedExtIpAddr) {
@@ -1078,25 +1160,25 @@ public final class NatUtil {
         return new String[] {leastLoadedExtIp, leastLoadedExtIpPrefix};
     }
 
-    @Nonnull
-    public static List<BigInteger> getDpnsForRouter(DataBroker dataBroker, String routerUuid) {
+    @NonNull
+    public static List<Uint64> getDpnsForRouter(DataBroker dataBroker, String routerUuid) {
         InstanceIdentifier id = InstanceIdentifier.builder(NeutronRouterDpns.class)
             .child(RouterDpnList.class, new RouterDpnListKey(routerUuid)).build();
         Optional<RouterDpnList> routerDpnListData =
                 SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
                         LogicalDatastoreType.OPERATIONAL, id);
-        List<BigInteger> dpns = new ArrayList<>();
+        List<Uint64> dpns = new ArrayList<>();
         if (routerDpnListData.isPresent()) {
-            for (DpnVpninterfacesList dpnVpnInterface : requireNonNullElse(
-                    routerDpnListData.get().getDpnVpninterfacesList(), Collections.<DpnVpninterfacesList>emptyList())) {
+            for (DpnVpninterfacesList dpnVpnInterface
+                    : routerDpnListData.get().nonnullDpnVpninterfacesList().values()) {
                 dpns.add(dpnVpnInterface.getDpnId());
             }
         }
         return dpns;
     }
 
-    public static long getBgpVpnId(DataBroker dataBroker, String routerName) {
-        long bgpVpnId = NatConstants.INVALID_ID;
+    public static Uint32 getBgpVpnId(DataBroker dataBroker, String routerName) {
+        Uint32 bgpVpnId = NatConstants.INVALID_ID;
         Uuid bgpVpnUuid = NatUtil.getVpnForRouter(dataBroker, routerName);
         if (bgpVpnUuid != null) {
             bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnUuid.getValue());
@@ -1104,11 +1186,10 @@ public final class NatUtil {
         return bgpVpnId;
     }
 
-    @Nullable
     static org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.router.interfaces
-        .RouterInterface getConfiguredRouterInterface(DataBroker broker, String interfaceName) {
+            .@Nullable RouterInterface getConfiguredRouterInterface(DataBroker broker, String interfaceName) {
         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                LogicalDatastoreType.CONFIGURATION, NatUtil.getRouterInterfaceId(interfaceName)).orNull();
+                LogicalDatastoreType.CONFIGURATION, NatUtil.getRouterInterfaceId(interfaceName)).orElse(null);
     }
 
     static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911
@@ -1121,10 +1202,10 @@ public final class NatUtil {
                     .RouterInterfaceKey(interfaceName)).build();
     }
 
-    public static void addToNeutronRouterDpnsMap(String routerName, String interfaceName, BigInteger dpId,
+    public static void addToNeutronRouterDpnsMap(String routerName, String interfaceName, Uint64 dpId,
         TypedReadWriteTransaction<Operational> operTx) throws ExecutionException, InterruptedException {
 
-        if (dpId.equals(BigInteger.ZERO)) {
+        if (dpId.equals(Uint64.ZERO)) {
             LOG.warn("addToNeutronRouterDpnsMap : Could not retrieve dp id for interface {} "
                     + "to handle router {} association model", interfaceName, routerName);
             return;
@@ -1142,10 +1223,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);
-            operTx.merge(dpnVpnInterfacesListIdentifier
+            operTx.mergeParentStructureMerge(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, CREATE_MISSING_PARENTS);
+                            new RouterInterfacesKey(interfaceName)), routerInterface);
         } else {
             LOG.debug("addToNeutronRouterDpnsMap : Building new RouterDpnList for the Router {} and DPN {} for the "
                     + "Interface {} in the ODL-L3VPN : NeutronRouterDpn map", routerName, dpId, interfaceName);
@@ -1157,13 +1238,13 @@ public final class NatUtil {
             routerInterfaces.add(routerInterface);
             dpnVpnList.setRouterInterfaces(routerInterfaces);
             routerDpnListBuilder.setDpnVpninterfacesList(Collections.singletonList(dpnVpnList.build()));
-            operTx.merge(getRouterId(routerName), routerDpnListBuilder.build(), CREATE_MISSING_PARENTS);
+            operTx.mergeParentStructureMerge(getRouterId(routerName), routerDpnListBuilder.build());
         }
     }
 
-    public static void addToDpnRoutersMap(String routerName, String interfaceName, BigInteger dpId,
+    public static void addToDpnRoutersMap(String routerName, String interfaceName, Uint64 dpId,
         TypedReadWriteTransaction<Operational> operTx) throws ExecutionException, InterruptedException {
-        if (dpId.equals(BigInteger.ZERO)) {
+        if (dpId.equals(Uint64.ZERO)) {
             LOG.error("addToDpnRoutersMap : Could not retrieve dp id for interface {} to handle router {} "
                     + "association model", interfaceName, routerName);
             return;
@@ -1178,13 +1259,12 @@ public final class NatUtil {
         if (optionalDpnRoutersList.isPresent()) {
             RoutersList routersList = new RoutersListBuilder().withKey(new RoutersListKey(routerName))
                     .setRouter(routerName).build();
-            List<RoutersList> routersListFromDs = requireNonNullElse(optionalDpnRoutersList.get().getRoutersList(),
-                emptyList());
-            if (!routersListFromDs.contains(routersList)) {
+            Map<RoutersListKey, RoutersList> keyroutersMapFromDs = optionalDpnRoutersList.get().nonnullRoutersList();
+            if (!keyroutersMapFromDs.values().contains(routersList)) {
                 LOG.debug("addToDpnRoutersMap : Router {} not present for the DPN {}"
                         + " in the ODL-L3VPN : DPNRouters map", routerName, dpId);
-                operTx.merge(dpnRoutersListIdentifier
-                        .child(RoutersList.class, new RoutersListKey(routerName)), routersList, CREATE_MISSING_PARENTS);
+                operTx.mergeParentStructureMerge(dpnRoutersListIdentifier
+                        .child(RoutersList.class, new RoutersListKey(routerName)), routersList);
             } else {
                 LOG.debug("addToDpnRoutersMap : Router {} already mapped to the DPN {} in the ODL-L3VPN : "
                         + "DPNRouters map", routerName, dpId);
@@ -1197,13 +1277,13 @@ public final class NatUtil {
             RoutersListBuilder routersListBuilder = new RoutersListBuilder();
             routersListBuilder.setRouter(routerName);
             dpnRoutersListBuilder.setRoutersList(Collections.singletonList(routersListBuilder.build()));
-            operTx.merge(getDpnRoutersId(dpId), dpnRoutersListBuilder.build(), CREATE_MISSING_PARENTS);
+            operTx.mergeParentStructureMerge(getDpnRoutersId(dpId), dpnRoutersListBuilder.build());
         }
     }
 
-    public static void removeFromNeutronRouterDpnsMap(String routerName, BigInteger dpId,
+    public static void removeFromNeutronRouterDpnsMap(String routerName, Uint64 dpId,
         TypedReadWriteTransaction<Operational> operTx) throws ExecutionException, InterruptedException {
-        if (dpId.equals(BigInteger.ZERO)) {
+        if (dpId.equals(Uint64.ZERO)) {
             LOG.warn("removeFromNeutronRouterDpnsMap : DPN ID is invalid for the router {} ", routerName);
             return;
         }
@@ -1221,19 +1301,19 @@ public final class NatUtil {
     }
 
     public static void removeFromNeutronRouterDpnsMap(String routerName, String vpnInterfaceName,
-         BigInteger dpId, @Nonnull TypedReadWriteTransaction<Operational> operTx) {
+         Uint64 dpId, @NonNull TypedReadWriteTransaction<Operational> operTx) {
         InstanceIdentifier<DpnVpninterfacesList> routerDpnListIdentifier = getRouterDpnId(routerName, dpId);
         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();
+            optionalRouterDpnList = Optional.empty();
         }
         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();
+                    new ArrayList<>(optionalRouterDpnList.get().nonnullRouterInterfaces().values());
             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(vpnInterfaceName))
@@ -1253,7 +1333,7 @@ public final class NatUtil {
     }
 
     public static void removeFromDpnRoutersMap(DataBroker broker, String routerName, String vpnInterfaceName,
-        BigInteger curDpnId, OdlInterfaceRpcService ifaceMgrRpcService, TypedReadWriteTransaction<Operational> operTx)
+        Uint64 curDpnId, OdlInterfaceRpcService ifaceMgrRpcService, TypedReadWriteTransaction<Operational> operTx)
         throws ExecutionException, InterruptedException {
         /*
             1) Get the DpnRoutersList for the DPN.
@@ -1305,9 +1385,9 @@ public final class NatUtil {
         }
 
         //Get the VM interfaces for the router on the current DPN only.
-        List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces
-            .map.router.interfaces.Interfaces> vmInterfaces = routerInterfacesData.get().getInterfaces();
-        if (vmInterfaces == null) {
+        Map<InterfacesKey, Interfaces> vmInterfacesMap
+                = routerInterfacesData.get().nonnullInterfaces();
+        if (vmInterfacesMap == null) {
             LOG.debug("removeFromDpnRoutersMap : VM interfaces are not present for the router {} in the "
                 + "NeutronVPN - router-interfaces-map", routerName);
             return;
@@ -1316,10 +1396,10 @@ public final class NatUtil {
         // If the removed VPN interface is the only interface through which the router is connected to the DPN,
         // then remove RouterList.
         for (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map
-                 .router.interfaces.Interfaces vmInterface : vmInterfaces) {
+                 .router.interfaces.Interfaces vmInterface : vmInterfacesMap.values()) {
             String vmInterfaceName = vmInterface.getInterfaceId();
-            BigInteger vmDpnId = getDpnForInterface(ifaceMgrRpcService, vmInterfaceName);
-            if (vmDpnId.equals(BigInteger.ZERO) || !vmDpnId.equals(curDpnId)) {
+            Uint64 vmDpnId = getDpnForInterface(ifaceMgrRpcService, vmInterfaceName);
+            if (vmDpnId.equals(Uint64.ZERO) || !vmDpnId.equals(curDpnId)) {
                 LOG.debug("removeFromDpnRoutersMap : DPN ID {} for the removed interface {} is not the same as that of "
                         + "the DPN ID {} for the checked interface {}",
                     curDpnId, vpnInterfaceName, vmDpnId, vmInterfaceName);
@@ -1337,24 +1417,14 @@ public final class NatUtil {
         operTx.delete(routersListIdentifier);
     }
 
-    private static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn
-        .rev150602.router.interfaces.map.RouterInterfaces> getRoutersInterfacesIdentifier(String routerName) {
-        return InstanceIdentifier.builder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn
-            .rev150602.RouterInterfacesMap.class)
-            .child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router
-                    .interfaces.map.RouterInterfaces.class,
-                new org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router
-                    .interfaces.map.RouterInterfacesKey(new Uuid(routerName))).build();
-    }
-
-    private static InstanceIdentifier<RoutersList> getRoutersList(BigInteger dpnId, String routerName) {
+    private static InstanceIdentifier<RoutersList> getRoutersList(Uint64 dpnId, String routerName) {
         return InstanceIdentifier.builder(DpnRouters.class)
             .child(DpnRoutersList.class, new DpnRoutersListKey(dpnId))
             .child(RoutersList.class, new RoutersListKey(routerName)).build();
     }
 
-    public static BigInteger getDpnForInterface(OdlInterfaceRpcService interfaceManagerRpcService, String ifName) {
-        BigInteger nodeId = BigInteger.ZERO;
+    public static Uint64 getDpnForInterface(OdlInterfaceRpcService interfaceManagerRpcService, String ifName) {
+        Uint64 nodeId = Uint64.ZERO;
         try {
             GetDpidFromInterfaceInput
                 dpIdInput =
@@ -1374,20 +1444,20 @@ public final class NatUtil {
         return nodeId;
     }
 
-    @Nonnull
+    @NonNull
     public static List<ActionInfo> getEgressActionsForInterface(OdlInterfaceRpcService odlInterfaceRpcService,
                                                                 ItmRpcService itmRpcService,
                                                                 IInterfaceManager interfaceManager, String ifName,
-                                                                Long tunnelKey, boolean internalTunnelInterface) {
+                                                                Uint32 tunnelKey, boolean internalTunnelInterface) {
         return getEgressActionsForInterface(odlInterfaceRpcService, itmRpcService, interfaceManager,
                 ifName, tunnelKey, 0, internalTunnelInterface);
     }
 
-    @Nonnull
+    @NonNull
     public static List<ActionInfo> getEgressActionsForInterface(OdlInterfaceRpcService odlInterfaceRpcService,
                                                                 ItmRpcService itmRpcService,
                                                                 IInterfaceManager interfaceManager,
-                                                                String ifName, @Nullable Long tunnelKey, int pos,
+                                                                String ifName, @Nullable Uint32 tunnelKey, int pos,
                                                                 boolean internalTunnelInterface) {
         LOG.debug("getEgressActionsForInterface : called for interface {}", ifName);
         GetEgressActionsForInterfaceInputBuilder egressActionsIfmBuilder =
@@ -1408,7 +1478,7 @@ public final class NatUtil {
                     LOG.error("getEgressActionsForTunnels : RPC Call to Get egress actions for Tunnels {} "
                             + "returned with Errors {}", ifName, rpcResult.getErrors());
                 } else {
-                    actions = rpcResult.getResult().getAction();
+                    actions = new ArrayList<Action>(rpcResult.getResult().nonnullAction().values());
                 }
             } else {
                 RpcResult<GetEgressActionsForInterfaceOutput> rpcResult =
@@ -1417,11 +1487,11 @@ public final class NatUtil {
                     LOG.error("getEgressActionsForInterface : RPC Call to Get egress actions for interface {} "
                             + "returned with Errors {}", ifName, rpcResult.getErrors());
                 } else {
-                    actions = rpcResult.getResult().getAction();
+                    actions = new ArrayList<Action>(rpcResult.getResult().nonnullAction().values());
                 }
             }
             List<ActionInfo> listActionInfo = new ArrayList<>();
-            for (Action action : requireNonNullElse(actions, Collections.<Action>emptyList())) {
+            for (Action action : actions) {
                 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action
                     actionClass = action.getAction();
                 if (actionClass instanceof OutputActionCase) {
@@ -1432,17 +1502,17 @@ public final class NatUtil {
                 } else if (actionClass instanceof SetFieldCase) {
                     if (((SetFieldCase) actionClass).getSetField().getVlanMatch() != null) {
                         int vlanVid = ((SetFieldCase) actionClass).getSetField().getVlanMatch().getVlanId()
-                            .getVlanId().getValue();
+                            .getVlanId().getValue().toJava();
                         listActionInfo.add(new ActionSetFieldVlanVid(pos++, vlanVid));
                     }
                 } else if (actionClass instanceof NxActionResubmitRpcAddGroupCase) {
-                    Short tableId = ((NxActionResubmitRpcAddGroupCase) actionClass).getNxResubmit().getTable();
+                    Short tableId = ((NxActionResubmitRpcAddGroupCase) actionClass).getNxResubmit().getTable().toJava();
                     listActionInfo.add(new ActionNxResubmit(pos++, tableId));
                 } else if (actionClass instanceof NxActionRegLoadNodesNodeTableFlowApplyActionsCase) {
                     NxRegLoad nxRegLoad =
                         ((NxActionRegLoadNodesNodeTableFlowApplyActionsCase) actionClass).getNxRegLoad();
-                    listActionInfo.add(new ActionRegLoad(pos++, NxmNxReg6.class, nxRegLoad.getDst().getStart(),
-                        nxRegLoad.getDst().getEnd(), nxRegLoad.getValue().longValue()));
+                    listActionInfo.add(new ActionRegLoad(pos++, NxmNxReg6.class, nxRegLoad.getDst().getStart().toJava(),
+                        nxRegLoad.getDst().getEnd().toJava(), nxRegLoad.getValue().longValue()));
                 }
             }
             return listActionInfo;
@@ -1458,7 +1528,7 @@ public final class NatUtil {
         return getNeutronPortForIp(broker, targetIP, NeutronConstants.DEVICE_OWNER_GATEWAY_INF);
     }
 
-    @Nonnull
+    @NonNull
     public static List<Port> getNeutronPorts(DataBroker broker) {
         InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports>
             portsIdentifier = InstanceIdentifier.create(Neutron.class)
@@ -1473,7 +1543,7 @@ public final class NatUtil {
             return emptyList();
         }
 
-        return portsOptional.get().getPort();
+        return new ArrayList<Port>(portsOptional.get().nonnullPort().values());
     }
 
     @Nullable
@@ -1483,7 +1553,7 @@ public final class NatUtil {
 
         for (Port port : ports) {
             if (deviceType.equals(port.getDeviceOwner()) && port.getFixedIps() != null) {
-                for (FixedIps ip : port.getFixedIps()) {
+                for (FixedIps ip : port.nonnullFixedIps().values()) {
                     if (Objects.equals(ip.getIpAddress(), targetIP)) {
                         return port;
                     }
@@ -1500,7 +1570,7 @@ public final class NatUtil {
             LOG.error("getSubnetIdForFloatingIp : port is null");
             return null;
         }
-        for (FixedIps ip : requireNonNullElse(port.getFixedIps(), Collections.<FixedIps>emptyList())) {
+        for (FixedIps ip : port.nonnullFixedIps().values()) {
             if (Objects.equals(ip.getIpAddress(), targetIP)) {
                 return ip.getSubnetId();
             }
@@ -1514,16 +1584,22 @@ public final class NatUtil {
         InstanceIdentifier<Subnetmap> subnetmapId = InstanceIdentifier.builder(Subnetmaps.class)
             .child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                LogicalDatastoreType.CONFIGURATION, subnetmapId).orNull();
+                LogicalDatastoreType.CONFIGURATION, subnetmapId).orElse(null);
     }
 
-    @Nonnull
+    @NonNull
     public static List<Uuid> getSubnetIdsFromNetworkId(DataBroker broker, Uuid networkId) {
         InstanceIdentifier<NetworkMap> id = InstanceIdentifier.builder(NetworkMaps.class)
             .child(NetworkMap.class, new NetworkMapKey(networkId)).build();
-        return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                LogicalDatastoreType.CONFIGURATION, id).toJavaUtil().map(NetworkMap::getSubnetIdList).orElse(
+        List<Uuid> subnetIdList = SingleTransactionDataBroker
+                .syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
+                        LogicalDatastoreType.CONFIGURATION, id).map(NetworkMap::getSubnetIdList).orElse(
                 emptyList());
+        if (!subnetIdList.isEmpty()) {
+            subnetIdList = new ArrayList<>(subnetIdList);
+        }
+
+        return subnetIdList;
     }
 
     @Nullable
@@ -1581,12 +1657,12 @@ public final class NatUtil {
         return IpPrefixBuilder.getDefaultInstance(prefix).getIpv6Prefix() != null;
     }
 
-    static InstanceIdentifier<DpnRoutersList> getDpnRoutersId(BigInteger dpnId) {
+    static InstanceIdentifier<DpnRoutersList> getDpnRoutersId(Uint64 dpnId) {
         return InstanceIdentifier.builder(DpnRouters.class)
             .child(DpnRoutersList.class, new DpnRoutersListKey(dpnId)).build();
     }
 
-    static InstanceIdentifier<DpnVpninterfacesList> getRouterDpnId(String routerName, BigInteger dpnId) {
+    static InstanceIdentifier<DpnVpninterfacesList> getRouterDpnId(String routerName, Uint64 dpnId) {
         return InstanceIdentifier.builder(NeutronRouterDpns.class)
             .child(RouterDpnList.class, new RouterDpnListKey(routerName))
             .child(DpnVpninterfacesList.class, new DpnVpninterfacesListKey(dpnId)).build();
@@ -1601,7 +1677,7 @@ public final class NatUtil {
     protected static String getFloatingIpPortMacFromFloatingIpId(DataBroker broker, Uuid floatingIpId) {
         InstanceIdentifier<FloatingIpIdToPortMapping> id = buildfloatingIpIdToPortMappingIdentifier(floatingIpId);
         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                LogicalDatastoreType.CONFIGURATION, id).toJavaUtil().map(
+                LogicalDatastoreType.CONFIGURATION, id).map(
                 FloatingIpIdToPortMapping::getFloatingIpPortMacAddress).orElse(null);
     }
 
@@ -1609,7 +1685,7 @@ public final class NatUtil {
     protected static String getFloatingIpPortMacFromFloatingIpId(TypedReadTransaction<Configuration> confTx,
         Uuid floatingIpId) {
         try {
-            return confTx.read(buildfloatingIpIdToPortMappingIdentifier(floatingIpId)).get().toJavaUtil().map(
+            return confTx.read(buildfloatingIpIdToPortMappingIdentifier(floatingIpId)).get().map(
                 FloatingIpIdToPortMapping::getFloatingIpPortMacAddress).orElse(null);
         } catch (InterruptedException | ExecutionException e) {
             LOG.error("Error reading the floating IP port MAC for {}", floatingIpId, e);
@@ -1621,7 +1697,7 @@ public final class NatUtil {
     protected static Uuid getFloatingIpPortSubnetIdFromFloatingIpId(DataBroker broker, Uuid floatingIpId) {
         InstanceIdentifier<FloatingIpIdToPortMapping> id = buildfloatingIpIdToPortMappingIdentifier(floatingIpId);
         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                LogicalDatastoreType.CONFIGURATION, id).toJavaUtil().map(
+                LogicalDatastoreType.CONFIGURATION, id).map(
                 FloatingIpIdToPortMapping::getFloatingIpPortSubnetId).orElse(null);
     }
 
@@ -1629,7 +1705,7 @@ public final class NatUtil {
     protected static Uuid getFloatingIpPortSubnetIdFromFloatingIpId(TypedReadTransaction<Configuration> confTx,
         Uuid floatingIpId) {
         try {
-            return confTx.read(buildfloatingIpIdToPortMappingIdentifier(floatingIpId)).get().toJavaUtil().map(
+            return confTx.read(buildfloatingIpIdToPortMappingIdentifier(floatingIpId)).get().map(
                 FloatingIpIdToPortMapping::getFloatingIpPortSubnetId).orElse(null);
         } catch (InterruptedException | ExecutionException e) {
             LOG.error("Error reading the floating IP port subnet for {}", floatingIpId, e);
@@ -1647,7 +1723,7 @@ public final class NatUtil {
         InstanceIdentifier<Interface> ifStateId =
             buildStateInterfaceId(interfaceName);
         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
-                LogicalDatastoreType.OPERATIONAL, ifStateId).orNull();
+                LogicalDatastoreType.OPERATIONAL, ifStateId).orElse(null);
     }
 
     static InstanceIdentifier<Interface> buildStateInterfaceId(String interfaceName) {
@@ -1664,20 +1740,20 @@ public final class NatUtil {
     public static Routers getRoutersFromConfigDS(DataBroker dataBroker, String routerName) {
         InstanceIdentifier<Routers> routerIdentifier = NatUtil.buildRouterIdentifier(routerName);
         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
-                LogicalDatastoreType.CONFIGURATION, routerIdentifier).orNull();
+                LogicalDatastoreType.CONFIGURATION, routerIdentifier).orElse(null);
     }
 
     @Nullable
     public static Routers getRoutersFromConfigDS(TypedReadTransaction<Configuration> confTx, String routerName) {
         try {
-            return confTx.read(NatUtil.buildRouterIdentifier(routerName)).get().orNull();
+            return confTx.read(NatUtil.buildRouterIdentifier(routerName)).get().orElse(null);
         } catch (InterruptedException | ExecutionException e) {
             LOG.error("Error reading router {}", routerName, e);
             return null;
         }
     }
 
-    static void createRouterIdsConfigDS(DataBroker dataBroker, long routerId, String routerName) {
+    static void createRouterIdsConfigDS(DataBroker dataBroker, Uint32 routerId, String routerName) {
         if (routerId == NatConstants.INVALID_ID) {
             LOG.error("createRouterIdsConfigDS : invalid routerId for routerName {}", routerName);
             return;
@@ -1688,7 +1764,7 @@ public final class NatUtil {
     }
 
     @Nullable
-    static FlowEntity buildDefaultNATFlowEntityForExternalSubnet(BigInteger dpId, long vpnId, String subnetId,
+    static FlowEntity buildDefaultNATFlowEntityForExternalSubnet(Uint64 dpId, Uint32 vpnId, String subnetId,
             IdManagerService idManager) {
         InetAddress defaultIP = null;
         try {
@@ -1702,12 +1778,17 @@ public final class NatUtil {
         List<MatchInfo> matches = new ArrayList<>();
         matches.add(MatchEthernetType.IPV4);
         //add match for vrfid
-        matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
+        matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId.longValue()),
+                MetaDataUtil.METADATA_MASK_VRFID));
 
         List<InstructionInfo> instructions = new ArrayList<>();
         List<ActionInfo> actionsInfo = new ArrayList<>();
-        long groupId = createGroupId(NatUtil.getGroupIdKey(subnetId), idManager);
-        actionsInfo.add(new ActionGroup(groupId));
+        Uint32 groupId = getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME, NatUtil.getGroupIdKey(subnetId));
+        if (groupId == NatConstants.INVALID_ID) {
+            LOG.error("Unable to get groupId for subnet {} while building defauly flow entity", subnetId);
+            return null;
+        }
+        actionsInfo.add(new ActionGroup(groupId.longValue()));
         String flowRef = getFlowRef(dpId, NwConstants.L3_FIB_TABLE, defaultIP, vpnId);
         instructions.add(new InstructionApplyActions(actionsInfo));
         return MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_FIB_TABLE, flowRef,
@@ -1716,7 +1797,7 @@ public final class NatUtil {
     }
 
     @Nullable
-    static String getExtGwMacAddFromRouterId(DataBroker broker, long routerId) {
+    static String getExtGwMacAddFromRouterId(DataBroker broker, Uint32 routerId) {
         String routerName = getRouterName(broker, routerId);
         if (routerName == null) {
             LOG.error("getExtGwMacAddFromRouterId : empty routerName received");
@@ -1729,13 +1810,13 @@ public final class NatUtil {
     static String getExtGwMacAddFromRouterName(DataBroker broker, String routerName) {
         InstanceIdentifier<Routers> id = buildRouterIdentifier(routerName);
         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                LogicalDatastoreType.CONFIGURATION, id).toJavaUtil().map(Routers::getExtGwMacAddress).orElse(null);
+                LogicalDatastoreType.CONFIGURATION, id).map(Routers::getExtGwMacAddress).orElse(null);
     }
 
     @Nullable
     static String getExtGwMacAddFromRouterName(TypedReadTransaction<Configuration> tx, String routerName) {
         try {
-            return tx.read(buildRouterIdentifier(routerName)).get().toJavaUtil().map(
+            return tx.read(buildRouterIdentifier(routerName)).get().map(
                 Routers::getExtGwMacAddress).orElse(null);
         } catch (InterruptedException | ExecutionException e) {
             LOG.error("Error retrieving external gateway MAC address for router {}", routerName, e);
@@ -1754,29 +1835,34 @@ public final class NatUtil {
     public static String getNeutronRouterNamebyUuid(DataBroker broker, Uuid routerUuid) {
         InstanceIdentifier<Router> neutronRouterIdentifier = NatUtil.buildNeutronRouterIdentifier(routerUuid);
         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                LogicalDatastoreType.CONFIGURATION, neutronRouterIdentifier).toJavaUtil().map(Router::getName).orElse(
+                LogicalDatastoreType.CONFIGURATION, neutronRouterIdentifier).map(Router::getName).orElse(
                 null);
     }
 
-    @Nonnull
+    @NonNull
     public static List<Ports> getFloatingIpPortsForRouter(DataBroker broker, Uuid routerUuid) {
         InstanceIdentifier<RouterPorts> routerPortsIdentifier = getRouterPortsId(routerUuid.getValue());
-        return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                LogicalDatastoreType.CONFIGURATION,
-                routerPortsIdentifier).toJavaUtil().map(RouterPorts::getPorts).orElse(emptyList());
+        List<Ports> portsList = new ArrayList<Ports>(SingleTransactionDataBroker
+                .syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.CONFIGURATION,
+                        routerPortsIdentifier).map(RouterPorts::nonnullPorts).orElse(Collections.emptyMap()).values());
+
+        if (!portsList.isEmpty()) {
+            portsList = new ArrayList<>(portsList);
+        }
+        return portsList;
     }
 
-    @Nonnull
+    @NonNull
     public static List<Uuid> getRouterUuIdsForVpn(DataBroker broker, Uuid vpnUuid) {
         InstanceIdentifier<ExternalNetworks> externalNwIdentifier = InstanceIdentifier.create(ExternalNetworks.class);
         Optional<ExternalNetworks> externalNwData =
                 SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
                         LogicalDatastoreType.CONFIGURATION, externalNwIdentifier);
         if (externalNwData.isPresent()) {
-            for (Networks externalNw : requireNonNullElse(externalNwData.get().getNetworks(),
-                    Collections.<Networks>emptyList())) {
+            for (Networks externalNw : externalNwData.get().nonnullNetworks().values()) {
                 if (externalNw.getVpnid() != null && externalNw.getVpnid().equals(vpnUuid)) {
-                    return requireNonNullElse(externalNw.getRouterIds(), emptyList());
+                    @Nullable List<Uuid> routerIds = externalNw.getRouterIds();
+                    return routerIds != null ? new ArrayList<>(routerIds) : emptyList();
                 }
             }
         }
@@ -1796,7 +1882,7 @@ public final class NatUtil {
         }
     }
 
-    @Nonnull
+    @NonNull
     public static Collection<Uuid> getExternalSubnetIdsFromExternalIps(@Nullable List<ExternalIps> externalIps) {
         if (externalIps == null) {
             return Collections.emptySet();
@@ -1805,7 +1891,7 @@ public final class NatUtil {
         return externalIps.stream().map(ExternalIps::getSubnetId).collect(Collectors.toSet());
     }
 
-    @Nonnull
+    @NonNull
     public static Collection<Uuid> getExternalSubnetIdsForRouter(DataBroker dataBroker, @Nullable String routerName) {
         if (routerName == null) {
             LOG.error("getExternalSubnetIdsForRouter : empty routerName received");
@@ -1817,19 +1903,20 @@ public final class NatUtil {
                 SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
                         LogicalDatastoreType.CONFIGURATION, id);
         if (routerData.isPresent()) {
-            return NatUtil.getExternalSubnetIdsFromExternalIps(routerData.get().getExternalIps());
+            return NatUtil.getExternalSubnetIdsFromExternalIps(
+                    new ArrayList<ExternalIps>(routerData.get().nonnullExternalIps().values()));
         } else {
             LOG.warn("getExternalSubnetIdsForRouter : No external router data for router {}", routerName);
             return Collections.emptySet();
         }
     }
 
-    @Nonnull
+    @NonNull
     protected static Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external
         .subnets.Subnets> getOptionalExternalSubnets(DataBroker dataBroker, Uuid subnetId) {
         if (subnetId == null) {
             LOG.warn("getOptionalExternalSubnets : subnetId is null");
-            return Optional.absent();
+            return Optional.empty();
         }
 
         InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice
@@ -1841,12 +1928,12 @@ public final class NatUtil {
                 LogicalDatastoreType.CONFIGURATION, subnetsIdentifier);
     }
 
-    @Nonnull
+    @NonNull
     protected static Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external
         .subnets.Subnets> getOptionalExternalSubnets(TypedReadTransaction<Configuration> tx, Uuid subnetId) {
         if (subnetId == null) {
             LOG.warn("getOptionalExternalSubnets : subnetId is null");
-            return Optional.absent();
+            return Optional.empty();
         }
 
         InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice
@@ -1858,11 +1945,11 @@ public final class NatUtil {
             return tx.read(subnetsIdentifier).get();
         } catch (InterruptedException | ExecutionException e) {
             LOG.error("Error retrieving external subnets on {}", subnetId, e);
-            return Optional.absent();
+            return Optional.empty();
         }
     }
 
-    protected static long getExternalSubnetVpnId(DataBroker dataBroker, Uuid subnetId) {
+    protected static Uint32 getExternalSubnetVpnId(DataBroker dataBroker, Uuid subnetId) {
         Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external
             .subnets.Subnets> optionalExternalSubnets = NatUtil.getOptionalExternalSubnets(dataBroker,
                    subnetId);
@@ -1873,7 +1960,7 @@ public final class NatUtil {
         return NatConstants.INVALID_ID;
     }
 
-    protected static long getExternalSubnetVpnId(TypedReadTransaction<Configuration> tx, Uuid subnetId) {
+    protected static Uint32 getExternalSubnetVpnId(TypedReadTransaction<Configuration> tx, Uuid subnetId) {
         Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external
             .subnets.Subnets> optionalExternalSubnets = NatUtil.getOptionalExternalSubnets(tx,
             subnetId);
@@ -1884,7 +1971,7 @@ public final class NatUtil {
         return NatConstants.INVALID_ID;
     }
 
-    protected static long getExternalSubnetVpnIdForRouterExternalIp(DataBroker dataBroker, String externalIpAddress,
+    protected static Uint32 getExternalSubnetVpnIdForRouterExternalIp(DataBroker dataBroker, String externalIpAddress,
             Routers router) {
         Uuid externalSubnetId = NatUtil.getExternalSubnetForRouterExternalIp(externalIpAddress, router);
         if (externalSubnetId != null) {
@@ -1897,7 +1984,7 @@ public final class NatUtil {
     @Nullable
     protected static Uuid getExternalSubnetForRouterExternalIp(String externalIpAddress, Routers router) {
         externalIpAddress = validateAndAddNetworkMask(externalIpAddress);
-        for (ExternalIps extIp : requireNonNullElse(router.getExternalIps(), Collections.<ExternalIps>emptyList())) {
+        for (ExternalIps extIp : router.nonnullExternalIps().values()) {
             String extIpString = validateAndAddNetworkMask(extIp.getIpAddress());
             if (extIpString.equals(externalIpAddress)) {
                 return extIp.getSubnetId();
@@ -1917,7 +2004,7 @@ public final class NatUtil {
         return result;
     }
 
-    @Nonnull
+    @NonNull
     static List<String> getIpsListFromExternalIps(@Nullable List<ExternalIps> externalIps) {
         if (externalIps == null) {
             return emptyList();
@@ -1931,13 +2018,13 @@ public final class NatUtil {
     public static ElanInstance getElanInstanceByName(String elanInstanceName, DataBroker broker) {
         InstanceIdentifier<ElanInstance> elanIdentifierId = getElanInstanceConfigurationDataPath(elanInstanceName);
         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                LogicalDatastoreType.CONFIGURATION, elanIdentifierId).orNull();
+                LogicalDatastoreType.CONFIGURATION, elanIdentifierId).orElse(null);
     }
 
     @Nullable
     public static ElanInstance getElanInstanceByName(TypedReadTransaction<Configuration> tx, String elanInstanceName) {
         try {
-            return tx.read(getElanInstanceConfigurationDataPath(elanInstanceName)).get().orNull();
+            return tx.read(getElanInstanceConfigurationDataPath(elanInstanceName)).get().orElse(null);
         } catch (InterruptedException | ExecutionException e) {
             LOG.error("Error retrieving ELAN instance by name {}", elanInstanceName, e);
             return null;
@@ -1949,30 +2036,31 @@ public final class NatUtil {
                 .child(ElanInstance.class, new ElanInstanceKey(elanInstanceName)).build();
     }
 
-    public static long getTunnelIdForNonNaptToNaptFlow(DataBroker dataBroker, NatOverVxlanUtil natOverVxlanUtil,
+    public static Uint64 getTunnelIdForNonNaptToNaptFlow(DataBroker dataBroker, NatOverVxlanUtil natOverVxlanUtil,
                                                        IElanService elanManager, IdManagerService idManager,
-                                                       long routerId, String routerName) {
+                                                       Uint32 routerId, String routerName) {
         if (elanManager.isOpenStackVniSemanticsEnforced()) {
             // Router VNI will be set as tun_id if OpenStackSemantics is enabled
-            return natOverVxlanUtil.getRouterVni(routerName, routerId).longValue();
+            return natOverVxlanUtil.getRouterVni(routerName, routerId);
         } else {
             return NatEvpnUtil.getTunnelIdForRouter(idManager, dataBroker, routerName, routerId);
         }
     }
 
-    public static void makePreDnatToSnatTableEntry(IMdsalApiManager mdsalManager, BigInteger naptDpnId,
+    public static void makePreDnatToSnatTableEntry(IMdsalApiManager mdsalManager, Uint64 naptDpnId,
             short tableId, TypedWriteTransaction<Configuration> confTx) {
         LOG.debug("makePreDnatToSnatTableEntry : Create Pre-DNAT table {} --> table {} flow on NAPT DpnId {} ",
                 NwConstants.PDNAT_TABLE, tableId, naptDpnId);
 
-        List<Instruction> preDnatToSnatInstructions = new ArrayList<>();
-        preDnatToSnatInstructions.add(new InstructionGotoTable(tableId).buildInstruction(0));
+        Map<InstructionKey, Instruction> preDnatToSnatInstructionsMap = new HashMap<InstructionKey, Instruction>();
+        preDnatToSnatInstructionsMap.put(new InstructionKey(0),
+                new InstructionGotoTable(tableId).buildInstruction(0));
         List<MatchInfo> matches = new ArrayList<>();
         matches.add(MatchEthernetType.IPV4);
         String flowRef = getFlowRefPreDnatToSnat(naptDpnId, NwConstants.PDNAT_TABLE, "PreDNATToSNAT");
         Flow preDnatToSnatTableFlowEntity = MDSALUtil.buildFlowNew(NwConstants.PDNAT_TABLE,flowRef,
                 5, flowRef, 0, 0,  NwConstants.COOKIE_DNAT_TABLE,
-                matches, preDnatToSnatInstructions);
+                matches, preDnatToSnatInstructionsMap);
 
         mdsalManager.addFlow(confTx, naptDpnId, preDnatToSnatTableFlowEntity);
         LOG.debug("makePreDnatToSnatTableEntry : Successfully installed Pre-DNAT flow {} on NAPT DpnId {} ",
@@ -1980,7 +2068,7 @@ public final class NatUtil {
     }
 
     public static void removePreDnatToSnatTableEntry(TypedReadWriteTransaction<Configuration> confTx,
-            IMdsalApiManager mdsalManager, BigInteger naptDpnId) throws ExecutionException, InterruptedException {
+            IMdsalApiManager mdsalManager, Uint64 naptDpnId) throws ExecutionException, InterruptedException {
         LOG.debug("removePreDnatToSnatTableEntry : Remove Pre-DNAT table {} --> table {} flow on NAPT DpnId {} ",
                 NwConstants.PDNAT_TABLE, NwConstants.INBOUND_NAPT_TABLE, naptDpnId);
         String flowRef = getFlowRefPreDnatToSnat(naptDpnId, NwConstants.PDNAT_TABLE, "PreDNATToSNAT");
@@ -1989,24 +2077,32 @@ public final class NatUtil {
                 flowRef, naptDpnId);
     }
 
-    private static String getFlowRefPreDnatToSnat(BigInteger dpnId, short tableId, String uniqueId) {
+    private static String getFlowRefPreDnatToSnat(Uint64 dpnId, short tableId, String uniqueId) {
         return NatConstants.NAPT_FLOWID_PREFIX + dpnId + NwConstants.FLOWID_SEPARATOR + tableId
                 + NwConstants.FLOWID_SEPARATOR + uniqueId;
     }
 
-    public static boolean isFloatingIpPresentForDpn(DataBroker dataBroker, BigInteger dpnId, String rd,
+    public static boolean isFloatingIpPresentForDpn(DataBroker dataBroker, Uint64 dpnId, String rd,
                                                     String vpnName, String externalIp,
                                                     Boolean isMoreThanOneFipCheckOnDpn) {
         InstanceIdentifier<VpnToDpnList> id = getVpnToDpnListIdentifier(rd, dpnId);
-        Optional<VpnToDpnList> dpnInVpn = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
+        Optional<VpnToDpnList> dpnInVpn;
+        try {
+            dpnInVpn = SingleTransactionDataBroker.syncReadOptional(dataBroker,
+                    LogicalDatastoreType.OPERATIONAL, id);
+        } catch (ExecutionException | InterruptedException e) {
+            LOG.error("isFloatingIpPresentForDpn: Exception while reading VpnToDpnList DS for the rd {} dpnId {}",
+                    rd, dpnId, e);
+            return false;
+        }
         if (dpnInVpn.isPresent()) {
             LOG.debug("isFloatingIpPresentForDpn : vpn-to-dpn-list is not empty for vpnName {}, dpn id {}, "
                     + "rd {} and floatingIp {}", vpnName, dpnId, rd, externalIp);
             try {
-                List<IpAddresses> ipAddressList = dpnInVpn.get().getIpAddresses();
-                if (ipAddressList != null && !ipAddressList.isEmpty()) {
+                Map<IpAddressesKey, IpAddresses> keyIpAddressesMap = dpnInVpn.get().getIpAddresses();
+                if (keyIpAddressesMap != null && !keyIpAddressesMap.isEmpty()) {
                     int floatingIpPresentCount = 0;
-                    for (IpAddresses ipAddress: ipAddressList) {
+                    for (IpAddresses ipAddress: keyIpAddressesMap.values()) {
                         if (!Objects.equals(ipAddress.getIpAddress(), externalIp)
                                 && IpAddresses.IpAddressSource.FloatingIP.equals(ipAddress.getIpAddressSource())) {
                             floatingIpPresentCount++;
@@ -2034,7 +2130,7 @@ public final class NatUtil {
         return false;
     }
 
-    private static InstanceIdentifier<VpnToDpnList> getVpnToDpnListIdentifier(String rd, BigInteger dpnId) {
+    private static InstanceIdentifier<VpnToDpnList> getVpnToDpnListIdentifier(String rd, Uint64 dpnId) {
         return InstanceIdentifier.builder(VpnInstanceOpData.class)
                 .child(VpnInstanceOpDataEntry.class, new VpnInstanceOpDataEntryKey(rd))
                 .child(VpnToDpnList.class, new VpnToDpnListKey(dpnId)).build();
@@ -2043,18 +2139,7 @@ public final class NatUtil {
     @Nullable
     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) {
-        InstanceIdentifier<VpnInstance> id  = getVpnInstanceIdentifier(vpnName);
-        Optional<VpnInstance> vpnInstance =
-                SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
-                        LogicalDatastoreType.CONFIGURATION, id);
-        if (vpnInstance.isPresent()) {
-            return getPrimaryRd(vpnInstance.get());
-        }
-        return vpnName;
+        return tx.read(getVpnInstanceIdentifier(vpnName)).get().map(NatUtil::getPrimaryRd).orElse(null);
     }
 
     @Nullable
@@ -2071,22 +2156,10 @@ public final class NatUtil {
             .child(VpnInstance.class, new VpnInstanceKey(vpnName)).build();
     }
 
-    @Nonnull
+    @NonNull
     public static List<String> getListOfRdsFromVpnInstance(VpnInstance vpnInstance) {
-        VpnAfConfig vpnConfig = vpnInstance.getIpv4Family();
-        return vpnConfig.getRouteDistinguisher() != null ? new ArrayList<>(
-                vpnConfig.getRouteDistinguisher()) : new ArrayList<>();
-    }
-
-    public static long getVpnIdFromExternalSubnet(DataBroker dataBroker, String routerName, String externalIpAddress) {
-        if (routerName != null) {
-            Routers extRouter = NatUtil.getRoutersFromConfigDS(dataBroker, routerName);
-            if (extRouter != null) {
-                return getExternalSubnetVpnIdForRouterExternalIp(dataBroker, externalIpAddress, extRouter);
-            }
-        }
-
-        return NatConstants.INVALID_ID;
+        return vpnInstance.getRouteDistinguisher() != null ? new ArrayList<>(
+                vpnInstance.getRouteDistinguisher()) : new ArrayList<>();
     }
 
     public static String validateAndAddNetworkMask(String ipAddress) {
@@ -2099,25 +2172,25 @@ public final class NatUtil {
         new VpnInterfaceOpDataEntryKey(vpnInterfaceName, vpnName)).build();
     }
 
-    @Nullable
-    public static VpnInstanceOpDataEntry getVpnInstanceOpData(DataBroker broker, String rd) {
-        InstanceIdentifier<VpnInstanceOpDataEntry> id = NatUtil.getVpnInstanceOpDataIdentifier(rd);
-        return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(
-                 broker, LogicalDatastoreType.OPERATIONAL, id).orNull();
-    }
-
     public static boolean checkForRoutersWithSameExtNetAndNaptSwitch(DataBroker broker, Uuid networkId,
-                                                                     String routerName, BigInteger dpnId) {
+                                                                     String routerName, Uint64 dpnId) {
         InstanceIdentifier<Networks> id = buildNetworkIdentifier(networkId);
-        Optional<Networks> networkData = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, id);
-
+        Optional<Networks> networkData = null;
+        try {
+            networkData = SingleTransactionDataBroker.syncReadOptional(broker,
+                    LogicalDatastoreType.CONFIGURATION, id);
+        } catch (ExecutionException | InterruptedException e) {
+            LOG.error("checkForRoutersWithSameExtNetAndNaptSwitch: Exception while reading Networks DS for the "
+                            + "network {} router {} dpnId {}", networkId.getValue(), routerName, dpnId, e);
+            return false;
+        }
         if (networkData != null && networkData.isPresent()) {
             List<Uuid> routerUuidList = networkData.get().getRouterIds();
             if (routerUuidList != null && !routerUuidList.isEmpty()) {
                 for (Uuid routerUuid : routerUuidList) {
                     String sharedRouterName = routerUuid.getValue();
                     if (!routerName.equals(sharedRouterName)) {
-                        BigInteger switchDpnId = NatUtil.getPrimaryNaptfromRouterName(broker, sharedRouterName);
+                        Uint64 switchDpnId = NatUtil.getPrimaryNaptfromRouterName(broker, sharedRouterName);
                         if (switchDpnId != null && switchDpnId.equals(dpnId)) {
                             LOG.debug("checkForRoutersWithSameExtNetAndNaptSwitch: external-network {} is "
                                     + "associated with other active router {} on NAPT switch {}", networkId,
@@ -2132,15 +2205,15 @@ public final class NatUtil {
     }
 
     public static boolean checkForRoutersWithSameExtSubnetAndNaptSwitch(DataBroker broker, Uuid externalSubnetId,
-                                                                        String routerName, BigInteger dpnId) {
-        List<Uuid> routerUuidList = getOptionalExternalSubnets(broker, externalSubnetId).toJavaUtil()
-            .map(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external
+                                                                        String routerName, Uint64 dpnId) {
+        List<Uuid> routerUuidList = getOptionalExternalSubnets(broker, externalSubnetId)
+                .map(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external
                 .subnets.Subnets::getRouterIds).orElse(emptyList());
         if (!routerUuidList.isEmpty()) {
             for (Uuid routerUuid : routerUuidList) {
                 String sharedRouterName = routerUuid.getValue();
                 if (!routerName.equals(sharedRouterName)) {
-                    BigInteger switchDpnId = NatUtil.getPrimaryNaptfromRouterName(broker, sharedRouterName);
+                    Uint64 switchDpnId = NatUtil.getPrimaryNaptfromRouterName(broker, sharedRouterName);
                     if (switchDpnId != null && switchDpnId.equals(dpnId)) {
                         LOG.debug("checkForRoutersWithSameExtSubnetAndNaptSwitch: external-subnetwork {} is "
                                   + "associated with other active router {} on NAPT switch {}", externalSubnetId,
@@ -2154,19 +2227,19 @@ public final class NatUtil {
     }
 
     public static void installRouterGwFlows(ManagedNewTransactionRunner txRunner, IVpnManager vpnManager,
-            Routers router, BigInteger primarySwitchId, int addOrRemove) {
-        ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
-            List<ExternalIps> externalIps = router.getExternalIps();
+            Routers router, Uint64 primarySwitchId, int addOrRemove) {
+        LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
+            Map<ExternalIpsKey, ExternalIps> keyExternalIpsMap = router.getExternalIps();
             List<String> externalIpsSting = new ArrayList<>();
 
-            if (externalIps == null || externalIps.isEmpty()) {
+            if (keyExternalIpsMap == null || keyExternalIpsMap.isEmpty()) {
                 LOG.error("installRouterGwFlows: setupRouterGwFlows no externalIP present");
                 return;
             }
-            for (ExternalIps externalIp : externalIps) {
+            for (ExternalIps externalIp : keyExternalIpsMap.values()) {
                 externalIpsSting.add(externalIp.getIpAddress());
             }
-            Uuid subnetVpnName = externalIps.get(0).getSubnetId();
+            Uuid subnetVpnName = keyExternalIpsMap.get(0).getSubnetId();
             if (addOrRemove == NwConstants.ADD_FLOW) {
                 vpnManager.addRouterGwMacFlow(router.getRouterName(), router.getExtGwMacAddress(), primarySwitchId,
                         router.getNetworkId(), subnetVpnName.getValue(), tx);
@@ -2183,10 +2256,103 @@ public final class NatUtil {
         }), LOG, "Error installing router gateway flows");
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    public static void handleSNATForDPN(DataBroker dataBroker, IMdsalApiManager mdsalManager,
+        IdManagerService idManager, NaptSwitchHA naptSwitchHA,
+        Uint64 dpnId, Routers extRouters, Uint32 routerId, Uint32 routerVpnId,
+        TypedReadWriteTransaction<Configuration> confTx,
+        ProviderTypes extNwProvType, UpgradeState upgradeState) {
+        //Check if primary and secondary switch are selected, If not select the role
+        //Install select group to NAPT switch
+        //Install default miss entry to NAPT switch
+        Uint64 naptSwitch;
+        String routerName = extRouters.getRouterName();
+        Boolean upgradeInProgress = false;
+        if (upgradeState != null) {
+            upgradeInProgress = upgradeState.isUpgradeInProgress();
+        }
+        Uint64 naptId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
+        if (naptId == null || naptId.equals(Uint64.ZERO)
+            || (!NatUtil.getSwitchStatus(dataBroker, naptId) && (upgradeInProgress == false))) {
+            LOG.debug("handleSNATForDPN : NaptSwitch is down or not selected for router {},naptId {}",
+                routerName, naptId);
+            naptSwitch = dpnId;
+            boolean naptstatus = naptSwitchHA.updateNaptSwitch(routerName, naptSwitch);
+            if (!naptstatus) {
+                LOG.error("handleSNATForDPN : Failed to update newNaptSwitch {} for routername {}",
+                    naptSwitch, routerName);
+                return;
+            }
+            LOG.debug("handleSNATForDPN : Switch {} is elected as NaptSwitch for router {}", dpnId, routerName);
+
+            String externalVpnName = null;
+            NatUtil.createRouterIdsConfigDS(dataBroker, routerId, routerName);
+            naptSwitchHA.subnetRegisterMapping(extRouters, routerId);
+            Uuid extNwUuid = extRouters.getNetworkId();
+            externalVpnName = NatUtil.getAssociatedVPN(dataBroker, extNwUuid);
+            if (externalVpnName != null) {
+                naptSwitchHA.installSnatFlows(routerName, routerId, naptSwitch, routerVpnId, extNwUuid,
+                    externalVpnName, confTx);
+            }
+            // Install miss entry (table 26) pointing to table 46
+            FlowEntity flowEntity = naptSwitchHA.buildSnatFlowEntityForNaptSwitch(dpnId, routerName,
+                routerVpnId, NatConstants.ADD_FLOW);
+            if (flowEntity == null) {
+                LOG.error("handleSNATForDPN : Failed to populate flowentity for router {} with dpnId {}",
+                    routerName, dpnId);
+                return;
+            }
+            LOG.debug("handleSNATForDPN : Successfully installed flow for dpnId {} router {}", dpnId, routerName);
+            mdsalManager.addFlow(confTx, flowEntity);
+            //Removing primary flows from old napt switch
+            if (naptId != null && !naptId.equals(Uint64.ZERO)) {
+                LOG.debug("handleSNATForDPN : Removing primary flows from old napt switch {} for router {}",
+                    naptId, routerName);
+                try {
+                    naptSwitchHA.removeSnatFlowsInOldNaptSwitch(extRouters, routerId, naptId, null,
+                        externalVpnName, confTx);
+                } catch (Exception e) {
+                    LOG.error("Exception while removing SnatFlows form OldNaptSwitch {}", naptId, e);
+                }
+            }
+            naptSwitchHA.updateNaptSwitchBucketStatus(routerName, routerId, naptSwitch);
+        } else if (naptId.equals(dpnId)) {
+            LOG.error("handleSNATForDPN : NaptSwitch {} gone down during cluster reboot came alive", naptId);
+        } else {
+            naptSwitch = naptId;
+            LOG.debug("handleSNATForDPN : Napt switch with Id {} is already elected for router {}",
+                naptId, routerName);
+
+            //installing group
+            List<BucketInfo> bucketInfo = naptSwitchHA.handleGroupInNeighborSwitches(dpnId,
+                routerName, routerId, naptSwitch);
+            naptSwitchHA.installSnatGroupEntry(dpnId, bucketInfo, routerName);
+
+            // Install miss entry (table 26) pointing to group
+            Uint32 groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME,
+                NatUtil.getGroupIdKey(routerName));
+            if (groupId != NatConstants.INVALID_ID) {
+                FlowEntity flowEntity =
+                    naptSwitchHA.buildSnatFlowEntity(dpnId, routerName, groupId.longValue(),
+                        routerVpnId, NatConstants.ADD_FLOW);
+                if (flowEntity == null) {
+                    LOG.error("handleSNATForDPN : Failed to populate flowentity for router {} with dpnId {}"
+                        + " groupId {}", routerName, dpnId, groupId);
+                    return;
+                }
+                LOG.debug("handleSNATForDPN : Successfully installed flow for dpnId {} router {} group {}",
+                    dpnId, routerName, groupId);
+                mdsalManager.addFlow(confTx, flowEntity);
+            } else {
+                LOG.error("handleSNATForDPN: Unable to get groupId for router:{}", routerName);
+            }
+        }
+    }
+
     @SuppressWarnings("checkstyle:IllegalCatch")
     public static void removeSNATFromDPN(DataBroker dataBroker, IMdsalApiManager mdsalManager,
-            IdManagerService idManager, NaptSwitchHA naptSwitchHA, BigInteger dpnId,
-            String routerName, long routerId, long routerVpnId,
+            IdManagerService idManager, NaptSwitchHA naptSwitchHA, Uint64 dpnId,
+            Routers extRouter, Uint32 routerId, Uint32 routerVpnId, String externalVpnName,
             ProviderTypes extNwProvType, TypedReadWriteTransaction<Configuration> confTx)
                     throws ExecutionException, InterruptedException {
         //irrespective of naptswitch or non-naptswitch, SNAT default miss entry need to be removed
@@ -2195,37 +2361,44 @@ public final class NatUtil {
         if (extNwProvType == null) {
             return;
         }
+        String routerName = extRouter.getRouterName();
         //Get the external IP labels other than VXLAN provider type. Since label is not applicable for VXLAN
-        Map<String, Long> externalIpLabel;
+        Map<String, Uint32> externalIpLabel;
         if (extNwProvType == ProviderTypes.VXLAN) {
             externalIpLabel = null;
         } else {
             externalIpLabel = NatUtil.getExternalIpsLabelForRouter(dataBroker, routerId);
         }
-        BigInteger naptSwitch = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
-        if (naptSwitch == null || naptSwitch.equals(BigInteger.ZERO)) {
+        Uint64 naptSwitch = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
+        if (naptSwitch == null || naptSwitch.equals(Uint64.ZERO)) {
             LOG.error("removeSNATFromDPN : No naptSwitch is selected for router {}", routerName);
             return;
         }
         Collection<String> externalIpCache = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
         boolean naptStatus =
-            naptSwitchHA.isNaptSwitchDown(routerName, routerId, dpnId, naptSwitch, routerVpnId,
+            naptSwitchHA.isNaptSwitchDown(extRouter, routerId, dpnId, naptSwitch, routerVpnId,
                     externalIpCache, confTx);
         if (!naptStatus) {
             LOG.debug("removeSNATFromDPN: Switch with DpnId {} is not naptSwitch for router {}",
                 dpnId, routerName);
-            long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(routerName), idManager);
+            Uint32 groupId = getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME, NatUtil.getGroupIdKey(routerName));
             FlowEntity flowEntity = null;
             try {
-                flowEntity = naptSwitchHA.buildSnatFlowEntity(dpnId, routerName, groupId, routerVpnId,
-                    NatConstants.DEL_FLOW);
-                if (flowEntity == null) {
-                    LOG.error("removeSNATFromDPN : Failed to populate flowentity for router:{} "
+                if (groupId != NatConstants.INVALID_ID) {
+                    flowEntity = naptSwitchHA
+                        .buildSnatFlowEntity(dpnId, routerName, groupId.longValue(), routerVpnId,
+                            NatConstants.DEL_FLOW);
+                    if (flowEntity == null) {
+                        LOG.error("removeSNATFromDPN : Failed to populate flowentity for router:{} "
                             + "with dpnId:{} groupId:{}", routerName, dpnId, groupId);
-                    return;
+                        return;
+                    }
+                    LOG.debug("removeSNATFromDPN : Removing default SNAT miss entry flow entity {}",
+                        flowEntity);
+                    mdsalManager.removeFlow(confTx, flowEntity);
+                } else {
+                    LOG.error("removeSNATFromDPN: Unable to get groupId for router:{}", routerName);
                 }
-                LOG.debug("removeSNATFromDPN : Removing default SNAT miss entry flow entity {}", flowEntity);
-                mdsalManager.removeFlow(confTx, flowEntity);
 
             } catch (Exception ex) {
                 LOG.error("removeSNATFromDPN : Failed to remove default SNAT miss entry flow entity {}",
@@ -2238,10 +2411,14 @@ public final class NatUtil {
             //remove group
             GroupEntity groupEntity = null;
             try {
-                groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName,
-                    GroupTypes.GroupAll, emptyList() /*listBucketInfo*/);
-                LOG.info("removeSNATFromDPN : Removing NAPT GroupEntity:{}", groupEntity);
-                mdsalManager.removeGroup(groupEntity);
+                if (groupId != NatConstants.INVALID_ID) {
+                    groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId.longValue(), routerName,
+                        GroupTypes.GroupAll, emptyList() /*listBucketInfo*/);
+                    LOG.info("removeSNATFromDPN : Removing NAPT GroupEntity:{}", groupEntity);
+                    mdsalManager.removeGroup(groupEntity);
+                } else {
+                    LOG.error("removeSNATFromDPN: Unable to get groupId for router:{}", routerName);
+                }
             } catch (Exception ex) {
                 LOG.error("removeSNATFromDPN : Failed to remove group entity {}", groupEntity, ex);
                 return;
@@ -2249,8 +2426,8 @@ public final class NatUtil {
             LOG.debug("removeSNATFromDPN : Removed default SNAT miss entry flow for dpnID {} with routerName {}",
                 dpnId, routerName);
         } else {
-            naptSwitchHA.removeSnatFlowsInOldNaptSwitch(routerName, routerId, naptSwitch,
-                    externalIpLabel, confTx);
+            naptSwitchHA.removeSnatFlowsInOldNaptSwitch(extRouter, routerId, naptSwitch,
+                    externalIpLabel, externalVpnName, confTx);
             //remove table 26 flow ppointing to table46
             FlowEntity flowEntity = null;
             try {
@@ -2288,92 +2465,74 @@ public final class NatUtil {
     }
 
     public static void addPseudoPortToElanDpn(String elanInstanceName, String pseudoPortId,
-            BigInteger dpnId, DataBroker dataBroker) {
+            Uint64 dpnId, DataBroker dataBroker) {
         InstanceIdentifier<DpnInterfaces> elanDpnInterfaceId = getElanDpnInterfaceOperationalDataPath(
-                elanInstanceName,dpnId);
+                elanInstanceName, dpnId);
+        // FIXME: separate this out?
+        final ReentrantLock lock = JvmGlobalLocks.getLockForString(elanInstanceName);
+        lock.lock();
         try {
-            synchronized (elanInstanceName.intern()) {
-                Optional<DpnInterfaces> dpnInElanInterfaces = SingleTransactionDataBroker.syncReadOptional(dataBroker,
-                        LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId);
-                List<String> elanInterfaceList;
-                DpnInterfaces dpnInterface;
-                if (!dpnInElanInterfaces.isPresent()) {
-                    elanInterfaceList = new ArrayList<>();
-                } else {
-                    dpnInterface = dpnInElanInterfaces.get();
-                    elanInterfaceList = dpnInterface.getInterfaces();
-                }
-                if (!elanInterfaceList.contains(pseudoPortId)) {
-                    elanInterfaceList.add(pseudoPortId);
-                    dpnInterface = new DpnInterfacesBuilder().setDpId(dpnId).setInterfaces(elanInterfaceList)
-                            .withKey(new DpnInterfacesKey(dpnId)).build();
-                    SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL,
-                            elanDpnInterfaceId, dpnInterface);
-                }
+            Optional<DpnInterfaces> dpnInElanInterfaces = SingleTransactionDataBroker.syncReadOptional(dataBroker,
+                LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId);
+            List<String> elanInterfaceList = new ArrayList<>();
+            DpnInterfaces dpnInterface;
+            if (dpnInElanInterfaces.isPresent()) {
+                dpnInterface = dpnInElanInterfaces.get();
+
+                elanInterfaceList = (dpnInterface.getInterfaces() != null && !dpnInterface.getInterfaces().isEmpty())
+                        ? new ArrayList<>(dpnInterface.getInterfaces()) : elanInterfaceList;
             }
-        } catch (ReadFailedException e) {
+            if (!elanInterfaceList.contains(pseudoPortId)) {
+                elanInterfaceList.add(pseudoPortId);
+                dpnInterface = new DpnInterfacesBuilder().setDpId(dpnId).setInterfaces(elanInterfaceList)
+                        .withKey(new DpnInterfacesKey(dpnId)).build();
+                SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL,
+                    elanDpnInterfaceId, dpnInterface);
+            }
+        } catch (InterruptedException | ExecutionException e) {
             LOG.warn("Failed to read elanDpnInterface with error {}", e.getMessage());
         } catch (TransactionCommitFailedException e) {
             LOG.warn("Failed to add elanDpnInterface with error {}", e.getMessage());
+        } finally {
+            lock.unlock();
         }
     }
 
     public static void removePseudoPortFromElanDpn(String elanInstanceName, String pseudoPortId,
-            BigInteger dpnId, DataBroker dataBroker) {
+            Uint64 dpnId, DataBroker dataBroker) {
         InstanceIdentifier<DpnInterfaces> elanDpnInterfaceId = getElanDpnInterfaceOperationalDataPath(
-                elanInstanceName,dpnId);
+                elanInstanceName, dpnId);
+        // FIXME: separate this out?
+        final ReentrantLock lock = JvmGlobalLocks.getLockForString(elanInstanceName);
+        lock.lock();
         try {
-            synchronized (elanInstanceName.intern()) {
-                Optional<DpnInterfaces> dpnInElanInterfaces = SingleTransactionDataBroker.syncReadOptional(dataBroker,
-                        LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId);
-                List<String> elanInterfaceList;
-                DpnInterfaces dpnInterface;
-                if (!dpnInElanInterfaces.isPresent()) {
-                    LOG.info("No interface in any dpn for {}", elanInstanceName);
-                    return;
-                } else {
-                    dpnInterface = dpnInElanInterfaces.get();
-                    elanInterfaceList = dpnInterface.getInterfaces();
-                }
-                if (!elanInterfaceList.contains(pseudoPortId)) {
-                    LOG.info("Router port not present in DPN {} for VPN {}", dpnId, elanInstanceName);
-                    return;
-                }
-                elanInterfaceList.remove(pseudoPortId);
-                dpnInterface = new DpnInterfacesBuilder().setDpId(dpnId).setInterfaces(elanInterfaceList)
-                        .withKey(new DpnInterfacesKey(dpnId)).build();
-                SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL,
-                        elanDpnInterfaceId, dpnInterface);
+            Optional<DpnInterfaces> dpnInElanInterfaces = SingleTransactionDataBroker.syncReadOptional(dataBroker,
+                    LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId);
+            List<String> elanInterfaceList = new ArrayList<>();
+            DpnInterfaces dpnInterface;
+            if (!dpnInElanInterfaces.isPresent()) {
+                LOG.info("No interface in any dpn for {}", elanInstanceName);
+                return;
             }
-        } catch (ReadFailedException e) {
+
+            dpnInterface = dpnInElanInterfaces.get();
+            elanInterfaceList = (dpnInterface.getInterfaces() != null && !dpnInterface.getInterfaces().isEmpty())
+                    ? new ArrayList<>(dpnInterface.getInterfaces()) : elanInterfaceList;
+            if (!elanInterfaceList.contains(pseudoPortId)) {
+                LOG.info("Router port not present in DPN {} for VPN {}", dpnId, elanInstanceName);
+                return;
+            }
+            elanInterfaceList.remove(pseudoPortId);
+            dpnInterface = new DpnInterfacesBuilder().setDpId(dpnId).setInterfaces(elanInterfaceList)
+                    .withKey(new DpnInterfacesKey(dpnId)).build();
+            SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL,
+                    elanDpnInterfaceId, dpnInterface);
+        } catch (InterruptedException | ExecutionException e) {
             LOG.warn("Failed to read elanDpnInterface with error {}", e.getMessage());
         } catch (TransactionCommitFailedException e) {
             LOG.warn("Failed to remove elanDpnInterface with error {}", e.getMessage());
-        }
-
-    }
-
-    public static DpnInterfaces getElanInterfaceInfoByElanDpn(String elanInstanceName, BigInteger dpId,
-            DataBroker broker) {
-        InstanceIdentifier<DpnInterfaces> elanDpnInterfacesId =
-                getElanDpnInterfaceOperationalDataPath(elanInstanceName, dpId);
-        DpnInterfaces dpnInterfaces = null;
-        try {
-            dpnInterfaces = SingleTransactionDataBroker.syncRead(broker, LogicalDatastoreType.OPERATIONAL,
-                    elanDpnInterfacesId);
-        }
-        catch (ReadFailedException e) {
-            LOG.warn("Failed to read ElanDpnInterfacesList with error {}", e.getMessage());
-        }
-        return dpnInterfaces;
-    }
-
-    public static <T extends DataObject> Optional<T> read(DataBroker broker, LogicalDatastoreType datastoreType,
-            InstanceIdentifier<T> path) {
-        try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
-            return tx.read(datastoreType, path).get();
-        } catch (InterruptedException | ExecutionException e) {
-            throw new RuntimeException(e);
+        } finally {
+            lock.unlock();
         }
     }
 
@@ -2388,19 +2547,13 @@ public final class NatUtil {
         return true;
     }
 
-    public static InstanceIdentifier<ExtRouters> buildExtRouters() {
-        InstanceIdentifier<ExtRouters> extRouterInstanceIndentifier = InstanceIdentifier.builder(ExtRouters.class)
-                .build();
-        return extRouterInstanceIndentifier;
-    }
-
     @Nullable
     public static LearntVpnVipToPortData getLearntVpnVipToPortData(DataBroker dataBroker) {
         try {
             return SingleTransactionDataBroker.syncRead(dataBroker,
                     LogicalDatastoreType.OPERATIONAL, getLearntVpnVipToPortDataId());
         }
-        catch (ReadFailedException e) {
+        catch (ExpectedDataObjectNotFoundException e) {
             LOG.warn("Failed to read LearntVpnVipToPortData with error {}", e.getMessage());
             return null;
         }
@@ -2413,13 +2566,13 @@ public final class NatUtil {
     }
 
     public static InstanceIdentifier<DpnInterfaces> getElanDpnInterfaceOperationalDataPath(String elanInstanceName,
-            BigInteger dpId) {
+            Uint64 dpId) {
         return InstanceIdentifier.builder(ElanDpnInterfaces.class)
                 .child(ElanDpnInterfacesList.class, new ElanDpnInterfacesListKey(elanInstanceName))
                 .child(DpnInterfaces.class, new DpnInterfacesKey(dpId)).build();
     }
 
-    public static InstanceIdentifier<Group> getGroupInstanceId(BigInteger dpnId, long groupId) {
+    public static InstanceIdentifier<Group> getGroupInstanceId(Uint64 dpnId, Uint32 groupId) {
         return InstanceIdentifier.builder(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight
                 .inventory.rev130819.nodes.Node.class, new NodeKey(new NodeId("openflow:" + dpnId)))
                 .augmentation(FlowCapableNode.class).child(Group.class, new GroupKey(new GroupId(groupId))).build();
@@ -2443,7 +2596,7 @@ public final class NatUtil {
         }
     }
 
-    public static boolean getSwitchStatus(DataBroker broker, BigInteger switchId) {
+    public static boolean getSwitchStatus(DataBroker broker, Uint64 switchId) {
         NodeId nodeId = new NodeId("openflow:" + switchId);
         LOG.debug("getSwitchStatus : Querying switch with dpnId {} is up/down", nodeId);
         InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> nodeInstanceId
@@ -2478,7 +2631,7 @@ public final class NatUtil {
 
     }
 
-    public static Map<String, String> getOpenvswitchOtherConfigMap(BigInteger dpnId, DataBroker dataBroker) {
+    public static Map<String, String> getOpenvswitchOtherConfigMap(Uint64 dpnId, DataBroker dataBroker) {
         String otherConfigVal = getProviderMappings(dpnId, dataBroker);
         return getMultiValueMap(otherConfigVal);
     }
@@ -2500,7 +2653,7 @@ public final class NatUtil {
         return valueMap;
     }
 
-    public static Optional<Node> getBridgeRefInfo(BigInteger dpnId, DataBroker dataBroker) {
+    public static Optional<Node> getBridgeRefInfo(Uint64 dpnId, DataBroker dataBroker) {
         InstanceIdentifier<BridgeRefEntry> bridgeRefInfoPath = InstanceIdentifier.create(BridgeRefInfo.class)
                 .child(BridgeRefEntry.class, new BridgeRefEntryKey(dpnId));
 
@@ -2509,7 +2662,7 @@ public final class NatUtil {
                         LogicalDatastoreType.OPERATIONAL, bridgeRefInfoPath);
         if (!bridgeRefEntry.isPresent()) {
             LOG.info("getBridgeRefInfo : bridgeRefEntry is not present for {}", dpnId);
-            return Optional.absent();
+            return Optional.empty();
         }
 
         InstanceIdentifier<Node> nodeId =
@@ -2520,8 +2673,8 @@ public final class NatUtil {
     }
 
     @Nullable
-    public static String getProviderMappings(BigInteger dpId, DataBroker dataBroker) {
-        return getBridgeRefInfo(dpId, dataBroker).toJavaUtil().map(node -> getOpenvswitchOtherConfigs(node,
+    public static String getProviderMappings(Uint64 dpId, DataBroker dataBroker) {
+        return getBridgeRefInfo(dpId, dataBroker).map(node -> getOpenvswitchOtherConfigs(node,
                 PROVIDER_MAPPINGS, dataBroker)).orElse(null);
     }
 
@@ -2536,7 +2689,8 @@ public final class NatUtil {
         }
 
         if (ovsdbNode != null && ovsdbNode.getOpenvswitchOtherConfigs() != null) {
-            for (OpenvswitchOtherConfigs openvswitchOtherConfigs : ovsdbNode.getOpenvswitchOtherConfigs()) {
+            for (OpenvswitchOtherConfigs openvswitchOtherConfigs
+                    : ovsdbNode.nonnullOpenvswitchOtherConfigs().values()) {
                 if (Objects.equals(openvswitchOtherConfigs.getOtherConfigKey(), key)) {
                     return openvswitchOtherConfigs.getOtherConfigValue();
                 }
@@ -2546,7 +2700,7 @@ public final class NatUtil {
         return null;
     }
 
-    @Nonnull
+    @NonNull
     public static Optional<Node> readOvsdbNode(Node bridgeNode, DataBroker dataBroker) {
         OvsdbBridgeAugmentation bridgeAugmentation = extractBridgeAugmentation(bridgeNode);
         if (bridgeAugmentation != null) {
@@ -2555,7 +2709,7 @@ public final class NatUtil {
             return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
                     LogicalDatastoreType.OPERATIONAL, ovsdbNodeIid);
         }
-        return Optional.absent();
+        return Optional.empty();
 
     }
 
@@ -2567,13 +2721,7 @@ public final class NatUtil {
         return node.augmentation(OvsdbBridgeAugmentation.class);
     }
 
-    // Use Objects.requireNonNullElse instead with JDK9+
-    @Nonnull
-    public static <T> T requireNonNullElse(@Nullable T obj, @Nonnull T defaultObj) {
-        return obj != null ? obj : requireNonNull(defaultObj);
-    }
-
-    public static String getDefaultFibRouteToSNATForSubnetJobKey(String subnetName, BigInteger dpnId) {
+    public static String getDefaultFibRouteToSNATForSubnetJobKey(String subnetName, Uint64 dpnId) {
         return NatConstants.NAT_DJC_PREFIX + subnetName + dpnId;
     }
 
@@ -2587,7 +2735,7 @@ public final class NatUtil {
             if (optionalExternalSubnets.isPresent()) {
                 return optionalExternalSubnets.get();
             }
-        } catch (ReadFailedException e) {
+        } catch (InterruptedException | ExecutionException e) {
             LOG.error("Failed to read the subnets from the datastore.");
         }
         return null;
@@ -2595,7 +2743,7 @@ public final class NatUtil {
     }
 
     public static void addFlow(TypedWriteTransaction<Configuration> confTx, IMdsalApiManager mdsalManager,
-            BigInteger dpId, short tableId, String flowId, int priority, String flowName, BigInteger cookie,
+            Uint64 dpId, short tableId, String flowId, int priority, String flowName, Uint64 cookie,
             List<? extends MatchInfoBase> matches, List<InstructionInfo> instructions) {
         FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, tableId, flowId, priority, flowName,
                 NatConstants.DEFAULT_IDLE_TIMEOUT, NatConstants.DEFAULT_IDLE_TIMEOUT, cookie, matches,
@@ -2605,17 +2753,17 @@ public final class NatUtil {
     }
 
     public static void removeFlow(TypedReadWriteTransaction<Configuration> confTx, IMdsalApiManager mdsalManager,
-            BigInteger dpId, short tableId, String flowId) throws ExecutionException, InterruptedException {
+            Uint64 dpId, short tableId, String flowId) throws ExecutionException, InterruptedException {
         LOG.trace("syncFlow : Removing Acl Flow DpnId {}, flowId {}", dpId, flowId);
         mdsalManager.removeFlow(confTx, dpId, flowId, tableId);
     }
 
-    public static String getIpv6FlowRef(BigInteger dpnId, short tableId, long routerID) {
+    public static String getIpv6FlowRef(Uint64 dpnId, short tableId, Uint32 routerID) {
         return new StringBuilder().append(NatConstants.IPV6_FLOWID_PREFIX).append(dpnId).append(NatConstants
                 .FLOWID_SEPARATOR).append(tableId).append(NatConstants.FLOWID_SEPARATOR).append(routerID).toString();
     }
 
-    public static String getTunnelInterfaceName(BigInteger srcDpId, BigInteger dstDpId,
+    public static String getTunnelInterfaceName(Uint64 srcDpId, Uint64 dstDpId,
                                                 ItmRpcService itmManager) {
         Class<? extends TunnelTypeBase> tunType = TunnelTypeVxlan.class;
         RpcResult<GetTunnelInterfaceNameOutput> rpcResult;
@@ -2650,7 +2798,199 @@ public final class NatUtil {
         return null;
     }
 
-    public static String getIpv6JobKey(String routerName) {
-        return "Ipv6." + routerName;
+    public static Boolean isRouterInterfacePort(DataBroker broker, String ifaceName) {
+        Port neutronPort = getNeutronPort(broker, ifaceName);
+        if (neutronPort == null) {
+            return Boolean.TRUE;
+        } else {
+            return (NatConstants.NETWORK_ROUTER_INTERFACE.equalsIgnoreCase(neutronPort.getDeviceOwner()) ? Boolean.TRUE
+                : Boolean.FALSE);
+        }
+    }
+
+    private static Port getNeutronPort(DataBroker broker, String ifaceName) {
+        InstanceIdentifier<Port>
+            portsIdentifier = InstanceIdentifier.create(Neutron.class)
+            .child(
+                org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports.class)
+            .child(Port.class, new PortKey(new Uuid(ifaceName)));
+        Optional<Port> portsOptional;
+        try {
+            portsOptional = SingleTransactionDataBroker
+                .syncReadOptional(broker, LogicalDatastoreType.CONFIGURATION, portsIdentifier);
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("Read Failed Exception While Reading Neutron Port for {}", ifaceName, e);
+            portsOptional = Optional.empty();
+        }
+        if (!portsOptional.isPresent()) {
+            LOG.error("getNeutronPort : No neutron ports found for interface {}", ifaceName);
+            return null;
+        }
+        return portsOptional.get();
+    }
+
+    public static org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn
+        .instance.to.vpn.id.VpnInstance getVpnIdToVpnInstance(DataBroker broker, String vpnName) {
+        if (vpnName == null) {
+            return null;
+        }
+
+        InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911
+            .vpn.instance.to.vpn.id.VpnInstance> id = getVpnInstanceToVpnIdIdentifier(vpnName);
+        Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911
+            .vpn.instance.to.vpn.id.VpnInstance> vpnInstance = Optional.empty();
+        try {
+            vpnInstance = SingleTransactionDataBroker.syncReadOptional(broker, LogicalDatastoreType.CONFIGURATION, id);
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("Failed to read VpnInstance {}", vpnInstance, e);
+        }
+        if (vpnInstance.isPresent()) {
+            return vpnInstance.get();
+        } else {
+            return null;
+        }
+    }
+
+    public static Uint32 getExternalVpnIdForExtNetwork(DataBroker broker, Uuid externalNwUuid) {
+        //Get the VPN ID from the ExternalNetworks model
+        if (externalNwUuid == null) {
+            LOG.error("getExternalVpnIdForExtNetwork : externalNwUuid is null");
+            return null;
+        }
+        Uuid vpnUuid = getVpnIdfromNetworkId(broker, externalNwUuid);
+        if (vpnUuid == null) {
+            LOG.error("NAT Service : vpnUuid is null");
+            return null;
+        }
+        Uint32 vpnId = getVpnId(broker, vpnUuid.getValue());
+        return vpnId;
+    }
+
+    static ReentrantLock lockForNat(final Uint64 dataPath) {
+        // FIXME: wrap this in an Identifier
+        return JvmGlobalLocks.getLockForString(NatConstants.NAT_DJC_PREFIX + dataPath);
+    }
+
+    public static void removeSnatEntriesForPort(DataBroker dataBroker, NaptManager naptManager,
+        IMdsalApiManager mdsalManager, NeutronvpnService neutronVpnService,
+        String interfaceName, String routerName) {
+        Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
+        if (routerId == NatConstants.INVALID_ID) {
+            LOG.error("removeSnatEntriesForPort: routerId not found for routername {}", routerName);
+            return;
+        }
+        Uint64 naptSwitch = getPrimaryNaptfromRouterName(dataBroker, routerName);
+        if (naptSwitch == null || naptSwitch.equals(Uint64.ZERO)) {
+            LOG.error("removeSnatEntriesForPort: NaptSwitch is not elected for router {}"
+                + "with Id {}", routerName, routerId);
+            return;
+        }
+        //getInternalIp for port
+        List<String> fixedIps = getFixedIpsForPort(neutronVpnService, interfaceName);
+        if (fixedIps == null) {
+            LOG.error("removeSnatEntriesForPort: Internal Ips not found for InterfaceName {} in router {} with id {}",
+                interfaceName, routerName, routerId);
+            return;
+        }
+        List<ProtocolTypes> protocolTypesList = getPortocolList();
+        for (String internalIp : fixedIps) {
+            LOG.debug("removeSnatEntriesForPort: Internal Ip retrieved for interface {} is {} in router with Id {}",
+                interfaceName, internalIp, routerId);
+            for (ProtocolTypes protocol : protocolTypesList) {
+                List<Uint16> portList = NatUtil.getInternalIpPortListInfo(dataBroker, routerId, internalIp, protocol);
+                if (portList != null) {
+                    for (Uint16 portnum : portList) {
+                        //build and remove the flow in outbound table
+                        removeNatFlow(mdsalManager, naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE,
+                            routerId, internalIp, portnum.toJava(), protocol.getName());
+
+                        //build and remove the flow in inboundtable
+
+                        removeNatFlow(mdsalManager, naptSwitch, NwConstants.INBOUND_NAPT_TABLE, routerId,
+                            internalIp, portnum.toJava(), protocol.getName());
+
+                        //Get the external IP address and the port from the model
+
+                        NAPTEntryEvent.Protocol proto = protocol.toString().equals(ProtocolTypes.TCP.toString())
+                            ? NAPTEntryEvent.Protocol.TCP : NAPTEntryEvent.Protocol.UDP;
+                        IpPortExternal ipPortExternal = NatUtil.getExternalIpPortMap(dataBroker, routerId,
+                            internalIp, String.valueOf(portnum.toJava()), proto);
+                        if (ipPortExternal == null) {
+                            LOG.error("removeSnatEntriesForPort: Mapping for internalIp {} "
+                                + "with port {} is not found in "
+                                + "router with Id {}", internalIp, portnum, routerId);
+                            return;
+                        }
+                        String externalIpAddress = ipPortExternal.getIpAddress();
+                        String internalIpPort = internalIp + ":" + portnum.toJava();
+                        // delete the entry from IntExtIpPortMap DS
+
+                        naptManager.removeFromIpPortMapDS(routerId, internalIpPort, proto);
+                        naptManager.removePortFromPool(internalIpPort, externalIpAddress);
+
+                    }
+                } else {
+                    LOG.debug("removeSnatEntriesForPort: No {} session for interface {} with internalIP {} "
+                            + "in router with id {}",
+                        protocol, interfaceName, internalIp, routerId);
+                }
+            }
+            // delete the entry from SnatIntIpPortMap DS
+            LOG.debug("removeSnatEntriesForPort: Removing InternalIp :{} of router {} from snatint-ip-port-map",
+                internalIp, routerId);
+            naptManager.removeFromSnatIpPortDS(routerId, internalIp);
+        }
+    }
+
+    private static List<String> getFixedIpsForPort(NeutronvpnService neutronVpnService, String interfname) {
+        LOG.debug("getFixedIpsForPort: getFixedIpsForPort method is called for interface {}", interfname);
+        try {
+            Future<RpcResult<GetFixedIPsForNeutronPortOutput>> result =
+                neutronVpnService.getFixedIPsForNeutronPort(new GetFixedIPsForNeutronPortInputBuilder()
+                    .setPortId(new Uuid(interfname)).build());
+
+            RpcResult<GetFixedIPsForNeutronPortOutput> rpcResult = result.get();
+            if (!rpcResult.isSuccessful()) {
+                LOG.error("getFixedIpsForPort: RPC Call to GetFixedIPsForNeutronPortOutput returned with Errors {}",
+                    rpcResult.getErrors());
+            } else {
+                return rpcResult.getResult().getFixedIPs();
+            }
+        } catch (InterruptedException | ExecutionException | NullPointerException ex) {
+            LOG.error("getFixedIpsForPort: Exception while receiving fixedIps for port {}", interfname, ex);
+        }
+        return null;
+    }
+
+    private static List<ProtocolTypes> getPortocolList() {
+        List<ProtocolTypes> protocollist = new ArrayList<>();
+        protocollist.add(ProtocolTypes.TCP);
+        protocollist.add(ProtocolTypes.UDP);
+        return protocollist;
+    }
+
+    private static void removeNatFlow(IMdsalApiManager mdsalManager, Uint64 dpnId, short tableId, Uint32 routerId,
+        String ipAddress, int ipPort, String protocol) {
+
+        String switchFlowRef = NatUtil.getNaptFlowRef(dpnId, tableId, String.valueOf(routerId), ipAddress, ipPort,
+            protocol);
+        FlowEntity snatFlowEntity = NatUtil.buildFlowEntity(dpnId, tableId, switchFlowRef);
+
+        mdsalManager.removeFlow(snatFlowEntity);
+        LOG.debug("removeNatFlow: Removed the flow in table {} for the switch with the DPN ID {} for "
+            + "router {} ip {} port {}", tableId, dpnId, routerId, ipAddress, ipPort);
+    }
+
+    public static String getDpnFromNodeRef(NodeRef node) {
+        PathArgument pathArgument = Iterables.get(node.getValue().getPathArguments(), 1);
+        InstanceIdentifier.IdentifiableItem<?, ?> item = Arguments.checkInstanceOf(pathArgument,
+            InstanceIdentifier.IdentifiableItem.class);
+        NodeKey key = Arguments.checkInstanceOf(item.getKey(), NodeKey.class);
+        String dpnKey = key.getId().getValue();
+        String dpnID = null;
+        if (dpnKey.contains(NatConstants.COLON_SEPARATOR)) {
+            dpnID = Uint64.valueOf(dpnKey.split(NatConstants.COLON_SEPARATOR)[1]).toString();
+        }
+        return dpnID;
     }
 }