"neutronvpn:createL3VPN" fails to create L3VPN for IPv6 use case.
[netvirt.git] / natservice / impl / src / main / java / org / opendaylight / netvirt / natservice / internal / NatUtil.java
index 7c8a707ce97b54c5147c8c90d42279b7be900d37..5d99bb22fd75ff459732619e6a0640a579f1be89 100644 (file)
@@ -50,6 +50,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;
@@ -80,13 +81,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;
@@ -236,6 +231,12 @@ 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;
@@ -271,6 +272,9 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 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;
 
@@ -290,24 +294,24 @@ public final class 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;
         }
@@ -319,9 +323,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;
             }
@@ -329,7 +333,7 @@ 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;
         }
@@ -337,7 +341,7 @@ public final class NatUtil {
         try {
             return confTx.read(getVpnInstanceToVpnIdIdentifier(vpnName)).get().toJavaUtil().map(
                 org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id
-                    .VpnInstance::getVpnId).orElse(Long.valueOf(NatConstants.INVALID_ID));
+                    .VpnInstance::getVpnId).orElse(NatConstants.INVALID_ID);
         } catch (InterruptedException | ExecutionException e) {
             LOG.error("Error retrieving VPN id for {}", vpnName, e);
         }
@@ -345,21 +349,21 @@ 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) {
             LOG.error("getNetworkVpnIdFromRouterId : networkId is null");
-            return Long.valueOf(NatConstants.INVALID_ID);
+            return NatConstants.INVALID_ID;
         }
 
         //Get the VPN ID from the ExternalNetworks model
         Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(broker, networkId);
         if (vpnUuid == null) {
             LOG.error("getNetworkVpnIdFromRouterId : vpnUuid is null");
-            return Long.valueOf(NatConstants.INVALID_ID);
+            return NatConstants.INVALID_ID;
         }
-        Long vpnId = NatUtil.getVpnId(broker, vpnUuid.getValue());
+        Uint32 vpnId = NatUtil.getVpnId(broker, vpnUuid.getValue());
         return vpnId;
     }
 
@@ -441,7 +445,7 @@ 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,
@@ -451,19 +455,19 @@ public final class NatUtil {
     /*
        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) {
+    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) {
+    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,
+    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)
@@ -472,7 +476,7 @@ public final class NatUtil {
     }
 
     @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");
@@ -498,7 +502,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;
@@ -574,7 +578,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) {
@@ -585,15 +589,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,
+        return (SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
                 LogicalDatastoreType.CONFIGURATION, id).toJavaUtil().map(RouterToNaptSwitch::getPrimarySwitchId).orElse(
-                null);
+                Uint64.valueOf(0L)));
     }
 
     public static InstanceIdentifier<RouterToNaptSwitch> buildNaptSwitchIdentifier(String routerId) {
@@ -607,7 +611,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);
     }
 
@@ -616,7 +620,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)
@@ -625,7 +629,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)
@@ -634,7 +638,7 @@ public final class NatUtil {
     }
 
     @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)
@@ -674,7 +678,7 @@ 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 =
@@ -684,7 +688,7 @@ public final class NatUtil {
                 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)
@@ -711,12 +715,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));
     }
 
 
@@ -757,7 +761,7 @@ 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,
@@ -788,11 +792,11 @@ 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(
-                Long.valueOf(NatConstants.INVALID_ID));
+                NatConstants.INVALID_ID);
     }
 
     @Nullable
@@ -826,10 +830,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);
@@ -841,13 +845,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,
@@ -858,8 +863,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
@@ -877,7 +882,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)
@@ -886,7 +891,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);
         }
     }
@@ -904,15 +909,21 @@ public final class NatUtil {
     }
 
     @NonNull
-    public static List<Integer> getInternalIpPortListInfo(DataBroker dataBroker, Long routerId,
+    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)).toJavaUtil().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 =
@@ -959,20 +970,21 @@ public final class NatUtil {
         return "snatmiss." + routerName;
     }
 
-    public static int getUniqueId(IdManagerService idManager, String poolName, String idKey) {
+    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 = (RpcResult)result.get();
-            return rpcResult.isSuccessful() ? rpcResult.getResult().getIdValue().intValue() : NatConstants.INVALID_ID;
+            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 Integer releaseId(IdManagerService idManager, String poolName, String idKey) {
+    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);
@@ -981,7 +993,7 @@ public final class NatUtil {
                     poolName, idKey,
                     (result != null && result.get() != null) ? result.get().getErrors() : "RpcResult is null");
             } else {
-                return 1;
+                return Uint32.ONE;
             }
         } catch (InterruptedException | ExecutionException e) {
             LOG.error("releaseId: Exception when releasing Id for key {} from pool {}", idKey, poolName, e);
@@ -992,33 +1004,33 @@ public final class NatUtil {
     // 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();
     }
 
-    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
@@ -1027,7 +1039,7 @@ public final class NatUtil {
     }
 
     @NonNull
-    public static Collection<String> getExternalIpsForRouter(DataBroker dataBroker, Long routerId) {
+    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,
@@ -1053,12 +1065,12 @@ public final class NatUtil {
     }
 
     @NonNull
-    public static Map<String, Long> getExternalIpsLabelForRouter(DataBroker dataBroker, Long routerId) {
+    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 : ipMappingOptional.get().nonnullIpMap()) {
                 externalIpsLabel.put(ipMap.getExternalIp(), ipMap.getLabel());
@@ -1068,7 +1080,7 @@ 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)
@@ -1080,7 +1092,7 @@ public final class NatUtil {
             short countOfLstLoadExtIp = 32767;
             for (ExternalIpCounter externalIpCounter : externalCounter.nonnullExternalIpCounter()) {
                 String curExternalIp = externalIpCounter.getExternalIp();
-                short countOfCurExtIp = externalIpCounter.getCounter();
+                short countOfCurExtIp = externalIpCounter.getCounter().toJava();
                 if (countOfCurExtIp < countOfLstLoadExtIp) {
                     countOfLstLoadExtIp = countOfCurExtIp;
                     leastLoadedExternalIp = curExternalIp;
@@ -1133,13 +1145,13 @@ public final class NatUtil {
     }
 
     @NonNull
-    public static List<BigInteger> getDpnsForRouter(DataBroker dataBroker, String routerUuid) {
+    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 : routerDpnListData.get().nonnullDpnVpninterfacesList()) {
                 dpns.add(dpnVpnInterface.getDpnId());
@@ -1148,8 +1160,8 @@ public final class NatUtil {
         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());
@@ -1173,10 +1185,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;
@@ -1213,9 +1225,9 @@ public final class NatUtil {
         }
     }
 
-    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;
@@ -1252,9 +1264,9 @@ public final class NatUtil {
         }
     }
 
-    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;
         }
@@ -1272,7 +1284,7 @@ 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 {
@@ -1284,7 +1296,7 @@ public final class NatUtil {
         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());
             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))
@@ -1304,7 +1316,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.
@@ -1369,8 +1381,8 @@ public final class NatUtil {
         for (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map
                  .router.interfaces.Interfaces vmInterface : vmInterfaces) {
             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);
@@ -1388,14 +1400,14 @@ public final class NatUtil {
         operTx.delete(routersListIdentifier);
     }
 
-    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 =
@@ -1419,7 +1431,7 @@ public final class NatUtil {
     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);
     }
@@ -1428,7 +1440,7 @@ public final class NatUtil {
     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 =
@@ -1473,17 +1485,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;
@@ -1562,9 +1574,15 @@ public final class NatUtil {
     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).toJavaUtil().map(NetworkMap::getSubnetIdList).orElse(
                 emptyList());
+        if (!subnetIdList.isEmpty()) {
+            subnetIdList = new ArrayList<>(subnetIdList);
+        }
+
+        return subnetIdList;
     }
 
     @Nullable
@@ -1622,12 +1640,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();
@@ -1718,7 +1736,7 @@ public final class NatUtil {
         }
     }
 
-    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;
@@ -1729,7 +1747,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 {
@@ -1743,16 +1761,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 = getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME, NatUtil.getGroupIdKey(subnetId));
+        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));
+        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,
@@ -1761,7 +1780,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");
@@ -1806,9 +1825,13 @@ public final class NatUtil {
     @NonNull
     public static List<Ports> getFloatingIpPortsForRouter(DataBroker broker, Uuid routerUuid) {
         InstanceIdentifier<RouterPorts> routerPortsIdentifier = getRouterPortsId(routerUuid.getValue());
-        return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
-                LogicalDatastoreType.CONFIGURATION,
+        List<Ports> portsList = SingleTransactionDataBroker
+                .syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.CONFIGURATION,
                 routerPortsIdentifier).toJavaUtil().map(RouterPorts::getPorts).orElse(emptyList());
+        if (!portsList.isEmpty()) {
+            portsList = new ArrayList<>(portsList);
+        }
+        return portsList;
     }
 
     @NonNull
@@ -1821,7 +1844,7 @@ public final class NatUtil {
             for (Networks externalNw : externalNwData.get().nonnullNetworks()) {
                 if (externalNw.getVpnid() != null && externalNw.getVpnid().equals(vpnUuid)) {
                     @Nullable List<Uuid> routerIds = externalNw.getRouterIds();
-                    return routerIds != null ? routerIds : emptyList();
+                    return routerIds != null ? new ArrayList<>(routerIds) : emptyList();
                 }
             }
         }
@@ -1907,7 +1930,7 @@ public final class NatUtil {
         }
     }
 
-    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);
@@ -1918,7 +1941,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);
@@ -1929,7 +1952,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) {
@@ -1994,18 +2017,18 @@ 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);
@@ -2025,7 +2048,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");
@@ -2034,12 +2057,12 @@ 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);
@@ -2079,7 +2102,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();
@@ -2107,9 +2130,8 @@ public final class NatUtil {
 
     @NonNull
     public static List<String> getListOfRdsFromVpnInstance(VpnInstance vpnInstance) {
-        VpnAfConfig vpnConfig = vpnInstance.getIpv4Family();
-        return vpnConfig.getRouteDistinguisher() != null ? new ArrayList<>(
-                vpnConfig.getRouteDistinguisher()) : new ArrayList<>();
+        return vpnInstance.getRouteDistinguisher() != null ? new ArrayList<>(
+                vpnInstance.getRouteDistinguisher()) : new ArrayList<>();
     }
 
     public static String validateAndAddNetworkMask(String ipAddress) {
@@ -2123,7 +2145,7 @@ public final class NatUtil {
     }
 
     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);
 
@@ -2133,7 +2155,7 @@ public final class NatUtil {
                 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,
@@ -2148,7 +2170,7 @@ public final class NatUtil {
     }
 
     public static boolean checkForRoutersWithSameExtSubnetAndNaptSwitch(DataBroker broker, Uuid externalSubnetId,
-                                                                        String routerName, BigInteger dpnId) {
+                                                                        String routerName, Uint64 dpnId) {
         List<Uuid> routerUuidList = getOptionalExternalSubnets(broker, externalSubnetId).toJavaUtil()
             .map(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external
                 .subnets.Subnets::getRouterIds).orElse(emptyList());
@@ -2156,7 +2178,7 @@ public final class NatUtil {
             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,
@@ -2170,7 +2192,7 @@ public final class NatUtil {
     }
 
     public static void installRouterGwFlows(ManagedNewTransactionRunner txRunner, IVpnManager vpnManager,
-            Routers router, BigInteger primarySwitchId, int addOrRemove) {
+            Routers router, Uint64 primarySwitchId, int addOrRemove) {
         ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
             List<ExternalIps> externalIps = router.getExternalIps();
             List<String> externalIpsSting = new ArrayList<>();
@@ -2199,10 +2221,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
@@ -2211,31 +2326,32 @@ 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 = getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME, NatUtil.getGroupIdKey(routerName));
+            Uint32 groupId = getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME, NatUtil.getGroupIdKey(routerName));
             FlowEntity flowEntity = null;
             try {
                 if (groupId != NatConstants.INVALID_ID) {
                     flowEntity = naptSwitchHA
-                        .buildSnatFlowEntity(dpnId, routerName, groupId, routerVpnId,
+                        .buildSnatFlowEntity(dpnId, routerName, groupId.longValue(), routerVpnId,
                             NatConstants.DEL_FLOW);
                     if (flowEntity == null) {
                         LOG.error("removeSNATFromDPN : Failed to populate flowentity for router:{} "
@@ -2261,7 +2377,7 @@ public final class NatUtil {
             GroupEntity groupEntity = null;
             try {
                 if (groupId != NatConstants.INVALID_ID) {
-                    groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName,
+                    groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId.longValue(), routerName,
                         GroupTypes.GroupAll, emptyList() /*listBucketInfo*/);
                     LOG.info("removeSNATFromDPN : Removing NAPT GroupEntity:{}", groupEntity);
                     mdsalManager.removeGroup(groupEntity);
@@ -2275,8 +2391,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 {
@@ -2314,7 +2430,7 @@ 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);
         // FIXME: separate this out?
@@ -2323,13 +2439,13 @@ public final class NatUtil {
         try {
             Optional<DpnInterfaces> dpnInElanInterfaces = SingleTransactionDataBroker.syncReadOptional(dataBroker,
                 LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId);
-            List<String> elanInterfaceList;
+            List<String> elanInterfaceList = new ArrayList<>();
             DpnInterfaces dpnInterface;
-            if (!dpnInElanInterfaces.isPresent()) {
-                elanInterfaceList = new ArrayList<>();
-            } else {
+            if (dpnInElanInterfaces.isPresent()) {
                 dpnInterface = dpnInElanInterfaces.get();
-                elanInterfaceList = dpnInterface.getInterfaces();
+
+                elanInterfaceList = (dpnInterface.getInterfaces() != null && !dpnInterface.getInterfaces().isEmpty())
+                        ? new ArrayList<>(dpnInterface.getInterfaces()) : elanInterfaceList;
             }
             if (!elanInterfaceList.contains(pseudoPortId)) {
                 elanInterfaceList.add(pseudoPortId);
@@ -2348,7 +2464,7 @@ public final class NatUtil {
     }
 
     public static void removePseudoPortFromElanDpn(String elanInstanceName, String pseudoPortId,
-            BigInteger dpnId, DataBroker dataBroker) {
+            Uint64 dpnId, DataBroker dataBroker) {
         InstanceIdentifier<DpnInterfaces> elanDpnInterfaceId = getElanDpnInterfaceOperationalDataPath(
                 elanInstanceName, dpnId);
         // FIXME: separate this out?
@@ -2357,7 +2473,7 @@ public final class NatUtil {
         try {
             Optional<DpnInterfaces> dpnInElanInterfaces = SingleTransactionDataBroker.syncReadOptional(dataBroker,
                     LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId);
-            List<String> elanInterfaceList;
+            List<String> elanInterfaceList = new ArrayList<>();
             DpnInterfaces dpnInterface;
             if (!dpnInElanInterfaces.isPresent()) {
                 LOG.info("No interface in any dpn for {}", elanInstanceName);
@@ -2365,7 +2481,8 @@ public final class NatUtil {
             }
 
             dpnInterface = dpnInElanInterfaces.get();
-            elanInterfaceList = dpnInterface.getInterfaces();
+            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;
@@ -2414,13 +2531,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();
@@ -2444,7 +2561,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
@@ -2479,7 +2596,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);
     }
@@ -2501,7 +2618,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));
 
@@ -2521,7 +2638,7 @@ public final class NatUtil {
     }
 
     @Nullable
-    public static String getProviderMappings(BigInteger dpId, DataBroker dataBroker) {
+    public static String getProviderMappings(Uint64 dpId, DataBroker dataBroker) {
         return getBridgeRefInfo(dpId, dataBroker).toJavaUtil().map(node -> getOpenvswitchOtherConfigs(node,
                 PROVIDER_MAPPINGS, dataBroker)).orElse(null);
     }
@@ -2568,7 +2685,7 @@ public final class NatUtil {
         return node.augmentation(OvsdbBridgeAugmentation.class);
     }
 
-    public static String getDefaultFibRouteToSNATForSubnetJobKey(String subnetName, BigInteger dpnId) {
+    public static String getDefaultFibRouteToSNATForSubnetJobKey(String subnetName, Uint64 dpnId) {
         return NatConstants.NAT_DJC_PREFIX + subnetName + dpnId;
     }
 
@@ -2590,7 +2707,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,
@@ -2600,17 +2717,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;
@@ -2658,7 +2775,8 @@ public final class NatUtil {
     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(
+                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 {
@@ -2675,7 +2793,44 @@ public final class NatUtil {
         return portsOptional.get();
     }
 
-    static ReentrantLock lockForNat(final BigInteger dataPath) {
+    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.absent();
+        try {
+            vpnInstance = SingleTransactionDataBroker.syncReadOptional(broker, LogicalDatastoreType.CONFIGURATION, id);
+        } catch (ReadFailedException 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);
     }
@@ -2683,13 +2838,13 @@ public final class NatUtil {
     public static void removeSnatEntriesForPort(DataBroker dataBroker, NaptManager naptManager,
         IMdsalApiManager mdsalManager, NeutronvpnService neutronVpnService,
         String interfaceName, String routerName) {
-        Long routerId = NatUtil.getVpnId(dataBroker, routerName);
+        Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
         if (routerId == NatConstants.INVALID_ID) {
             LOG.error("removeSnatEntriesForPort: routerId not found for routername {}", routerName);
             return;
         }
-        BigInteger naptSwitch = getPrimaryNaptfromRouterName(dataBroker, routerName);
-        if (naptSwitch == null || naptSwitch.equals(BigInteger.ZERO)) {
+        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;
@@ -2706,24 +2861,24 @@ public final class NatUtil {
             LOG.debug("removeSnatEntriesForPort: Internal Ip retrieved for interface {} is {} in router with Id {}",
                 interfaceName, internalIp, routerId);
             for (ProtocolTypes protocol : protocolTypesList) {
-                List<Integer> portList = NatUtil.getInternalIpPortListInfo(dataBroker, routerId, internalIp, protocol);
+                List<Uint16> portList = NatUtil.getInternalIpPortListInfo(dataBroker, routerId, internalIp, protocol);
                 if (portList != null) {
-                    for (Integer portnum : portList) {
+                    for (Uint16 portnum : portList) {
                         //build and remove the flow in outbound table
                         removeNatFlow(mdsalManager, naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE,
-                            routerId, internalIp, portnum, protocol.getName());
+                            routerId, internalIp, portnum.toJava(), protocol.getName());
 
                         //build and remove the flow in inboundtable
 
                         removeNatFlow(mdsalManager, naptSwitch, NwConstants.INBOUND_NAPT_TABLE, routerId,
-                            internalIp, portnum, protocol.getName());
+                            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), proto);
+                            internalIp, String.valueOf(portnum.toJava()), proto);
                         if (ipPortExternal == null) {
                             LOG.error("removeSnatEntriesForPort: Mapping for internalIp {} "
                                 + "with port {} is not found in "
@@ -2731,7 +2886,7 @@ public final class NatUtil {
                             return;
                         }
                         String externalIpAddress = ipPortExternal.getIpAddress();
-                        String internalIpPort = internalIp + ":" + portnum;
+                        String internalIpPort = internalIp + ":" + portnum.toJava();
                         // delete the entry from IntExtIpPortMap DS
 
                         naptManager.removeFromIpPortMapDS(routerId, internalIpPort, proto);
@@ -2778,7 +2933,7 @@ public final class NatUtil {
         return protocollist;
     }
 
-    private static void removeNatFlow(IMdsalApiManager mdsalManager, BigInteger dpnId, short tableId, Long routerId,
+    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,
@@ -2798,7 +2953,7 @@ public final class NatUtil {
         String dpnKey = key.getId().getValue();
         String dpnID = null;
         if (dpnKey.contains(NatConstants.COLON_SEPARATOR)) {
-            dpnID = new BigInteger(dpnKey.split(NatConstants.COLON_SEPARATOR)[1]).toString();
+            dpnID = Uint64.valueOf(dpnKey.split(NatConstants.COLON_SEPARATOR)[1]).toString();
         }
         return dpnID;
     }