Migrate ListenableFutures.addErrorLogging() users
[netvirt.git] / vpnmanager / impl / src / main / java / org / opendaylight / netvirt / vpnmanager / VpnUtil.java
index e0979ae7cd5b50e328cab29206a70f4bbe73326d..bce704258b53020985e14dbfa188d46ff0f65447 100644 (file)
@@ -11,7 +11,6 @@ package org.opendaylight.netvirt.vpnmanager;
 import static java.util.Collections.emptyList;
 import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
 
-import com.google.common.base.Optional;
 import com.google.common.collect.Iterators;
 import com.google.common.net.InetAddresses;
 import com.google.common.util.concurrent.FutureCallback;
@@ -33,6 +32,7 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Objects;
+import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
@@ -42,11 +42,6 @@ import java.util.stream.Collectors;
 import javax.inject.Singleton;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
 import org.opendaylight.genius.infra.Datastore;
 import org.opendaylight.genius.infra.Datastore.Configuration;
@@ -76,7 +71,11 @@ import org.opendaylight.genius.utils.JvmGlobalLocks;
 import org.opendaylight.genius.utils.ServiceIndex;
 import org.opendaylight.genius.utils.SystemPropertyReader;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
-import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
+import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.WriteTransaction;
+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.ElanHelper;
 import org.opendaylight.netvirt.fibmanager.api.IFibManager;
@@ -87,15 +86,6 @@ import org.opendaylight.netvirt.vpnmanager.api.InterfaceUtils;
 import org.opendaylight.netvirt.vpnmanager.api.VpnExtraRouteHelper;
 import org.opendaylight.netvirt.vpnmanager.api.VpnHelper;
 import org.opendaylight.netvirt.vpnmanager.iplearn.model.MacEntry;
-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.VpnInterfaceBuilder;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames;
 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.IpAddressBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
@@ -158,8 +148,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev15033
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.L3nexthop;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.VpnNexthops;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.VpnNexthopsKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.Adjacencies;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOpBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.LearntVpnVipToPortData;
@@ -172,9 +160,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.Vpn
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.VpnInstanceOpData;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.VpnInterfaceOpData;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.VpnToExtraroutes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency.AdjacencyType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.AdjacencyKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPortBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPortKey;
@@ -203,7 +188,9 @@ 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.VpnInstanceOpDataEntryKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnTargets;
 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.vpntargets.VpnTarget;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpntargets.VpnTargetKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstanceBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.Vpn;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.VpnKey;
@@ -216,11 +203,25 @@ 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.networks.Networks;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.SubnetsKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitch;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitchKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.Adjacencies;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.AdjacenciesBuilder;
+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.adjacency.list.Adjacency;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency.AdjacencyType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyKey;
+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.VpnInterfaceBuilder;
+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.l3vpn.rev200204.vpn.interfaces.vpn._interface.VpnInstanceNames;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NetworkAttributes.NetworkType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NetworkMaps;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronVpnPortipPortData;
@@ -337,11 +338,11 @@ public final class VpnUtil {
     }
 
     static VpnInterfaceOpDataEntry getVpnInterfaceOpDataEntry(String intfName, String vpnName, AdjacenciesOp aug,
-                                                       Uint64 dpnId, long lportTag,
-                                                       String gwMac) {
+                                                              Uint64 dpnId, long lportTag,
+                                                              String gwMac, String gwIp) {
         return new VpnInterfaceOpDataEntryBuilder().withKey(new VpnInterfaceOpDataEntryKey(intfName, vpnName))
-            .setDpnId(dpnId).addAugmentation(AdjacenciesOp.class, aug)
-                .setLportTag(lportTag).setGatewayMacAddress(gwMac).build();
+                .setDpnId(dpnId).addAugmentation(AdjacenciesOp.class, aug)
+                .setLportTag(lportTag).setGatewayMacAddress(gwMac).setGatewayIpAddress(gwIp).build();
     }
 
     Optional<VpnInterfaceOpDataEntry> getVpnInterfaceOpDataEntry(String vpnInterfaceName, String vpnName) {
@@ -422,7 +423,7 @@ public final class VpnUtil {
     public List<VrfEntry> getAllVrfEntries(String rd) {
         VrfTables vrfTables = getVrfTable(rd);
         if (vrfTables != null && vrfTables.getVrfEntry() != null) {
-            return vrfTables.getVrfEntry();
+            return new ArrayList<VrfEntry>(vrfTables.getVrfEntry().values());
         }
         return emptyList();
     }
@@ -437,13 +438,20 @@ public final class VpnUtil {
     }
 
     @NonNull
+    @SuppressWarnings("checkstyle:IllegalCatch")
     List<VpnInstanceOpDataEntry> getAllVpnInstanceOpData() {
-        InstanceIdentifier<VpnInstanceOpData> id = InstanceIdentifier.builder(VpnInstanceOpData.class).build();
-        Optional<VpnInstanceOpData> vpnInstanceOpDataOptional = read(LogicalDatastoreType.OPERATIONAL, id);
-        return
-            vpnInstanceOpDataOptional.isPresent() && vpnInstanceOpDataOptional.get().getVpnInstanceOpDataEntry() != null
-                ? vpnInstanceOpDataOptional.get().getVpnInstanceOpDataEntry()
-                : emptyList();
+        try {
+            InstanceIdentifier<VpnInstanceOpData> id = InstanceIdentifier.builder(VpnInstanceOpData.class).build();
+            Optional<VpnInstanceOpData> vpnInstanceOpDataOptional = read(LogicalDatastoreType.OPERATIONAL, id);
+            return
+                    vpnInstanceOpDataOptional.isPresent() && vpnInstanceOpDataOptional.get()
+                            .getVpnInstanceOpDataEntry() != null
+                            ? new ArrayList<VpnInstanceOpDataEntry>(vpnInstanceOpDataOptional.get()
+                            .getVpnInstanceOpDataEntry().values()) : emptyList();
+        } catch (Exception e) {
+            LOG.error("getAllVpnInstanceOpData: Could not retrieve all vpn instance op data subtree...", e);
+            return emptyList();
+        }
     }
 
     @NonNull
@@ -453,16 +461,17 @@ public final class VpnUtil {
         String primaryRd = getPrimaryRd(vpnInstance);
         InstanceIdentifier<VpnToDpnList> dpnToVpnId = VpnHelper.getVpnToDpnListIdentifier(primaryRd, dpnId);
         Optional<VpnToDpnList> dpnInVpn = read(LogicalDatastoreType.OPERATIONAL, dpnToVpnId);
-        return dpnInVpn.isPresent() && dpnInVpn.get().getVpnInterfaces() != null ? dpnInVpn.get().getVpnInterfaces()
+        return dpnInVpn.isPresent() && dpnInVpn.get().getVpnInterfaces() != null
+                ? new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op
+                        .data.vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfaces>(dpnInVpn.get()
+                        .getVpnInterfaces().values())
             : emptyList();
     }
 
     @NonNull
     static List<String> getListOfRdsFromVpnInstance(VpnInstance vpnInstance) {
-        VpnAfConfig vpnConfig = vpnInstance.getIpv4Family();
-        LOG.trace("vpnConfig {}", vpnConfig);
-        return vpnConfig.getRouteDistinguisher() != null && vpnConfig.getRouteDistinguisher() != null
-            ? vpnConfig.getRouteDistinguisher() : emptyList();
+        return vpnInstance.getRouteDistinguisher() != null ? new ArrayList<>(
+                vpnInstance.getRouteDistinguisher()) : new ArrayList<>();
     }
 
     @Nullable
@@ -487,7 +496,7 @@ public final class VpnUtil {
         InstanceIdentifier<Adjacencies> path = identifier.augmentation(Adjacencies.class);
         Optional<Adjacencies> adjacencies = read(LogicalDatastoreType.CONFIGURATION, path);
         if (adjacencies.isPresent()) {
-            return adjacencies.get().getAdjacency();
+            return new ArrayList<Adjacency>(adjacencies.get().nonnullAdjacency().values());
         }
         return null;
     }
@@ -582,7 +591,7 @@ public final class VpnUtil {
         }
 
         return read(LogicalDatastoreType.CONFIGURATION, VpnOperDsUtils.getVpnInstanceToVpnIdIdentifier(vpnName))
-                .toJavaUtil().map(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911
+                .map(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911
                         .vpn.instance.to.vpn.id.VpnInstance::getVpnId)
                         .orElse(VpnConstants.INVALID_ID);
     }
@@ -606,7 +615,7 @@ public final class VpnUtil {
 
     public static String getVpnRd(TypedReadTransaction<Configuration> confTx, String vpnName) {
         try {
-            return confTx.read(VpnOperDsUtils.getVpnInstanceToVpnIdIdentifier(vpnName)).get().toJavaUtil().map(
+            return confTx.read(VpnOperDsUtils.getVpnInstanceToVpnIdIdentifier(vpnName)).get().map(
                 vpnInstance -> vpnInstance.getVrfId()).orElse(null);
         } catch (InterruptedException | ExecutionException e) {
             throw new RuntimeException(e);
@@ -632,10 +641,10 @@ public final class VpnUtil {
         Optional<VrfTables> vrfTablesOpc = read(LogicalDatastoreType.CONFIGURATION, vpnVrfTableIid);
         if (vrfTablesOpc.isPresent()) {
             VrfTables vrfTables = vrfTablesOpc.get();
-            ListenableFutures.addErrorLogging(
+            LoggingFutures.addErrorLogging(
                     new ManagedNewTransactionRunnerImpl(dataBroker).callWithNewWriteOnlyTransactionAndSubmit(
                                                                             Datastore.CONFIGURATION, tx -> {
-                            for (VrfEntry vrfEntry : vrfTables.nonnullVrfEntry()) {
+                            for (VrfEntry vrfEntry : vrfTables.nonnullVrfEntry().values()) {
                                 if (origin == RouteOrigin.value(vrfEntry.getOrigin())) {
                                     tx.delete(vpnVrfTableIid.child(VrfEntry.class, vrfEntry.key()));
                                 }
@@ -651,8 +660,8 @@ public final class VpnUtil {
         List<VrfEntry> matches = new ArrayList<>();
         if (vrfTablesOpc.isPresent()) {
             VrfTables vrfTables = vrfTablesOpc.get();
-            for (VrfEntry vrfEntry : vrfTables.nonnullVrfEntry()) {
-                vrfEntry.nonnullRoutePaths().stream()
+            for (VrfEntry vrfEntry : vrfTables.nonnullVrfEntry().values()) {
+                vrfEntry.nonnullRoutePaths().values().stream()
                         .filter(routePath -> routePath.getNexthopAddress() != null && routePath.getNexthopAddress()
                                 .equals(nexthop)).findFirst().ifPresent(routePath -> matches.add(vrfEntry));
             }
@@ -663,7 +672,7 @@ public final class VpnUtil {
     public void removeVrfEntries(String rd, List<VrfEntry> vrfEntries) {
         InstanceIdentifier<VrfTables> vpnVrfTableIid =
             InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd)).build();
-        ListenableFutures.addErrorLogging(
+        LoggingFutures.addErrorLogging(
                 new ManagedNewTransactionRunnerImpl(dataBroker).callWithNewWriteOnlyTransactionAndSubmit(
                                                                             Datastore.CONFIGURATION, tx -> {
                         for (VrfEntry vrfEntry : vrfEntries) {
@@ -767,7 +776,7 @@ public final class VpnUtil {
 
     @Nullable
     public VpnInstanceOpDataEntry getVpnInstanceOpData(String rd) {
-        return read(LogicalDatastoreType.OPERATIONAL, getVpnInstanceOpDataIdentifier(rd)).orNull();
+        return read(LogicalDatastoreType.OPERATIONAL, getVpnInstanceOpDataIdentifier(rd)).orElse(null);
     }
 
     @Nullable
@@ -787,12 +796,13 @@ public final class VpnUtil {
 
     public Optional<List<String>> getVpnHandlingIpv4AssociatedWithInterface(String interfaceName) {
         InstanceIdentifier<VpnInterface> interfaceId = getVpnInterfaceIdentifier(interfaceName);
-        Optional<List<String>> vpnOptional = Optional.absent();
+        Optional<List<String>> vpnOptional = Optional.empty();
         Optional<VpnInterface> optConfiguredVpnInterface = read(LogicalDatastoreType.CONFIGURATION, interfaceId);
         if (optConfiguredVpnInterface.isPresent()) {
             VpnInterface cfgVpnInterface = optConfiguredVpnInterface.get();
             java.util.Optional<List<VpnInstanceNames>> optVpnInstanceList =
-                 java.util.Optional.ofNullable(cfgVpnInterface.getVpnInstanceNames());
+                 java.util.Optional.ofNullable(
+                         new ArrayList<VpnInstanceNames>(cfgVpnInterface.nonnullVpnInstanceNames().values()));
             if (optVpnInstanceList.isPresent()) {
                 List<String> vpnList = new ArrayList<>();
                 for (VpnInstanceNames vpnInstance : optVpnInstanceList.get()) {
@@ -826,7 +836,7 @@ public final class VpnUtil {
     private <T extends DataObject> Optional<T> read(LogicalDatastoreType datastoreType, InstanceIdentifier<T> path) {
         try {
             return SingleTransactionDataBroker.syncReadOptional(dataBroker, datastoreType, path);
-        } catch (ReadFailedException e) {
+        } catch (InterruptedException | ExecutionException e) {
             throw new RuntimeException(e);
         }
     }
@@ -928,7 +938,7 @@ public final class VpnUtil {
             vpnInstanceName)).setName(interfaceName).setDpnId(dpnId).setVpnInstanceName(vpnInstanceName)
             .build();
         if (writeOperTxn != null) {
-            writeOperTxn.merge(interfaceId, interfaceToUpdate, true);
+            writeOperTxn.mergeParentStructureMerge(interfaceId, interfaceToUpdate);
         } else {
             syncUpdate(LogicalDatastoreType.OPERATIONAL, interfaceId, interfaceToUpdate);
         }
@@ -946,7 +956,7 @@ public final class VpnUtil {
                             .setMacAddress(macAddress.toLowerCase(Locale.getDefault()))
                             .setCreationTime(new SimpleDateFormat("MM/dd/yyyy h:mm:ss a").format(new Date()));
             if (writeOperTxn != null) {
-                writeOperTxn.put(id, builder.build(), true);
+                writeOperTxn.mergeParentStructurePut(id, builder.build());
             } else {
                 syncWrite(LogicalDatastoreType.OPERATIONAL, id, builder.build());
             }
@@ -963,8 +973,8 @@ public final class VpnUtil {
                 new LearntVpnVipToPortKey(fixedIp, vpnName)).build();
     }
 
-    void removeLearntVpnVipToPort(String vpnName, String fixedIp,
-                                  @Nullable TypedWriteTransaction<Operational> writeOperTxn) {
+    public void removeLearntVpnVipToPort(String vpnName, String fixedIp,
+                                         @Nullable TypedWriteTransaction<Operational> writeOperTxn) {
         final InstanceIdentifier<LearntVpnVipToPort> id = buildLearntVpnVipToPortIdentifier(vpnName, fixedIp);
         final ReentrantLock lock = lockFor(vpnName, fixedIp);
         lock.lock();
@@ -981,7 +991,7 @@ public final class VpnUtil {
         }
     }
 
-    protected static void removeVpnPortFixedIpToPort(DataBroker broker, String vpnName, String fixedIp,
+    public static void removeVpnPortFixedIpToPort(DataBroker broker, String vpnName, String fixedIp,
                                                      @Nullable TypedWriteTransaction<Configuration> writeConfigTxn) {
         final InstanceIdentifier<VpnPortipToPort> id = buildVpnPortipToPortIdentifier(vpnName, fixedIp);
         final ReentrantLock lock = lockFor(vpnName, fixedIp);
@@ -1068,11 +1078,29 @@ public final class VpnUtil {
         VpnUtil.removeVpnPortFixedIpToPort(dataBroker, vpnName, prefix, null);
     }
 
+    public void removeMipAdjacency(String vpnName, String vpnInterface, String prefix,
+                                   TypedWriteTransaction<Configuration> writeConfigTxn) {
+        String ip = VpnUtil.getIpPrefix(prefix);
+        LOG.trace("Removing {} adjacency from Old VPN Interface {} ", ip, vpnInterface);
+        InstanceIdentifier<VpnInterface> vpnIfId = VpnUtil.getVpnInterfaceIdentifier(vpnInterface);
+        InstanceIdentifier<Adjacencies> path = vpnIfId.augmentation(Adjacencies.class);
+        //TODO: Remove synchronized?
+
+        Optional<Adjacencies> adjacencies = read(LogicalDatastoreType.OPERATIONAL, path);
+        if (adjacencies.isPresent()) {
+            InstanceIdentifier<Adjacency> adjacencyIdentifier = getAdjacencyIdentifier(vpnInterface, prefix);
+            writeConfigTxn.delete(adjacencyIdentifier);
+            LOG.error("removeMipAdjacency: Successfully Deleted Adjacency {} from interface {} vpn {}", ip,
+                    vpnInterface, vpnName);
+        }
+    }
+
     public void removeMipAdjacency(String vpnInterface, String ipAddress) {
         String prefix = VpnUtil.getIpPrefix(ipAddress);
         InstanceIdentifier<Adjacency> adjacencyIdentifier = getAdjacencyIdentifier(vpnInterface, prefix);
         try {
-            SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, adjacencyIdentifier);
+            SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
+                    adjacencyIdentifier);
         } catch (TransactionCommitFailedException e) {
             if (e.getCause() instanceof ModifiedNodeDoesNotExistException) {
                 LOG.debug("vpnInterface {} is already deleted. prefix={}", vpnInterface, prefix);
@@ -1112,7 +1140,7 @@ public final class VpnUtil {
             String vpnName, String fixedIp) {
         InstanceIdentifier<VpnPortipToPort> id = buildVpnPortipToPortIdentifier(vpnName, fixedIp);
         try {
-            return confTx.read(id).get().orNull();
+            return confTx.read(id).get().orElse(null);
         } catch (InterruptedException | ExecutionException e) {
             throw new RuntimeException(e);
         }
@@ -1141,12 +1169,12 @@ public final class VpnUtil {
             LOG.debug("getDpnsOnVpn: Could not find OpState for VpnName={}", vpnInstanceName);
             return result;
         }
-        List<VpnToDpnList> vpnToDpnList = vpnInstanceOpData.getVpnToDpnList();
-        if (vpnToDpnList == null) {
+        Map<VpnToDpnListKey, VpnToDpnList> vpnToDpnListKeyVpnToDpnListMap = vpnInstanceOpData.getVpnToDpnList();
+        if (vpnToDpnListKeyVpnToDpnListMap == null) {
             LOG.debug("getDpnsOnVpn: Could not find DPN footprint for VpnName={}", vpnInstanceName);
             return result;
         }
-        for (VpnToDpnList vpnToDpn : vpnToDpnList) {
+        for (VpnToDpnList vpnToDpn : vpnToDpnListKeyVpnToDpnListMap.values()) {
             result.add(vpnToDpn.getDpnId());
         }
         return result;
@@ -1170,9 +1198,9 @@ public final class VpnUtil {
 
         String routerName = null;
 
-        for (Routers routerData : extRouterData.get().nonnullRouters()) {
-            List<ExternalIps> externalIps = routerData.nonnullExternalIps();
-            for (ExternalIps externalIp : externalIps) {
+        for (Routers routerData : extRouterData.get().nonnullRouters().values()) {
+            Map<ExternalIpsKey, ExternalIps> keyExternalIpsMap = routerData.nonnullExternalIps();
+            for (ExternalIps externalIp : keyExternalIpsMap.values()) {
                 if (Objects.equals(externalIp.getIpAddress(), extIp)) {
                     routerName = routerData.getRouterName();
                     break;
@@ -1184,9 +1212,9 @@ public final class VpnUtil {
             return routerName;
         }
 
-        for (Routers routerData : extRouterData.get().nonnullRouters()) {
-            List<ExternalIps> externalIps = routerData.nonnullExternalIps();
-            for (ExternalIps externalIp : externalIps) {
+        for (Routers routerData : extRouterData.get().nonnullRouters().values()) {
+            Map<ExternalIpsKey, ExternalIps> keyExternalIpsMap = routerData.nonnullExternalIps();
+            for (ExternalIps externalIp : keyExternalIpsMap.values()) {
                 Subnet neutronSubnet = neutronVpnService.getNeutronSubnet(externalIp.getSubnetId());
                 if (neutronSubnet == null) {
                     LOG.warn("Failed to retrieve subnet {} referenced by router {}",
@@ -1211,10 +1239,10 @@ public final class VpnUtil {
         if (!extRouterData.isPresent() || extRouterData.get().getRouters() == null) {
             return null;
         }
-        for (Routers routerData : extRouterData.get().getRouters()) {
-            List<ExternalIps> externalIps = routerData.getExternalIps();
-            if (externalIps != null) {
-                for (ExternalIps externalIp : externalIps) {
+        for (Routers routerData : extRouterData.get().getRouters().values()) {
+            Map<ExternalIpsKey, ExternalIps> keyExternalIpsMap = routerData.getExternalIps();
+            if (keyExternalIpsMap != null) {
+                for (ExternalIps externalIp : keyExternalIpsMap.values()) {
                     Subnet neutronSubnet = neutronVpnService.getNeutronSubnet(externalIp.getSubnetId());
                     if (neutronSubnet == null) {
                         LOG.warn("Failed to retrieve subnet {} referenced by router {}",
@@ -1268,7 +1296,7 @@ public final class VpnUtil {
             throws ExecutionException, InterruptedException {
         InstanceIdentifier<Routers> id = InstanceIdentifier.builder(ExtRouters.class).child(Routers.class,
             new RoutersKey(routerId)).build();
-        return tx.read(id).get().orNull();
+        return tx.read(id).get().orElse(null);
     }
 
     static InstanceIdentifier<Subnetmaps> buildSubnetMapsWildCardPath() {
@@ -1313,8 +1341,10 @@ public final class VpnUtil {
     }
 
     void lockSubnet(String subnetId) {
+        //  We set the total wait time for lock to be obtained at 9 seconds since GC pauses can be upto 8 seconds
+        //in scale setups.
         TryLockInput input =
-            new TryLockInputBuilder().setLockName(subnetId).setTime(3000L).setTimeUnit(TimeUnits.Milliseconds).build();
+            new TryLockInputBuilder().setLockName(subnetId).setTime(9000L).setTimeUnit(TimeUnits.Milliseconds).build();
         Future<RpcResult<TryLockOutput>> result = lockManager.tryLock(input);
         try {
             if (result != null && result.get().isSuccessful()) {
@@ -1347,14 +1377,14 @@ public final class VpnUtil {
     }
 
     public Optional<IpAddress> getGatewayIpAddressFromInterface(MacEntry macEntry) {
-        Optional<IpAddress> gatewayIp = Optional.absent();
+        Optional<IpAddress> gatewayIp = Optional.empty();
         String srcInterface = macEntry.getInterfaceName();
         InetAddress hiddenIp = macEntry.getIpAddress();
         if (neutronVpnService != null) {
             //TODO(Gobinath): Need to fix this as assuming port will belong to only one Subnet would be incorrect"
             Port port = neutronVpnService.getNeutronPort(srcInterface);
             if (port != null && port.getFixedIps() != null) {
-                for (FixedIps portIp : port.getFixedIps()) {
+                for (FixedIps portIp : port.getFixedIps().values()) {
                     if (doesInterfaceAndHiddenIpAddressTypeMatch(hiddenIp, portIp)) {
                         gatewayIp =
                                 Optional.of(neutronVpnService.getNeutronSubnet(portIp.getSubnetId()).getGatewayIp());
@@ -1375,7 +1405,7 @@ public final class VpnUtil {
     }
 
     public Optional<String> getGWMacAddressFromInterface(MacEntry macEntry, IpAddress gatewayIp) {
-        Optional<String> gatewayMac = Optional.absent();
+        Optional<String> gatewayMac = Optional.empty();
         Uint32 vpnId = getVpnId(macEntry.getVpnName());
         InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.id.to.vpn
             .instance.VpnIds>
@@ -1423,7 +1453,7 @@ public final class VpnUtil {
     }
 
     public Optional<String> getVpnSubnetGatewayIp(final Uuid subnetUuid) {
-        Optional<String> gwIpAddress = Optional.absent();
+        Optional<String> gwIpAddress = Optional.empty();
         final SubnetKey subnetkey = new SubnetKey(subnetUuid);
         final InstanceIdentifier<Subnet> subnetidentifier = InstanceIdentifier.create(Neutron.class)
                 .child(Subnets.class)
@@ -1607,10 +1637,10 @@ public final class VpnUtil {
                     BoundServices serviceInfo = isTunnelInterface
                             ? VpnUtil.getBoundServicesForTunnelInterface(vpnInstanceName, interfaceName)
                             : getBoundServicesForVpnInterface(vpnInstanceName, interfaceName);
-                    tx.put(InterfaceUtils.buildServiceId(interfaceName,
+                    tx.mergeParentStructurePut(InterfaceUtils.buildServiceId(interfaceName,
                             ServiceIndex.getIndex(NwConstants.L3VPN_SERVICE_NAME,
                                     NwConstants.L3VPN_SERVICE_INDEX)),
-                            serviceInfo, WriteTransaction.CREATE_MISSING_PARENTS);
+                            serviceInfo);
                 })), SystemPropertyReader.getDataStoreJobCoordinatorMaxRetries());
     }
 
@@ -1682,7 +1712,7 @@ public final class VpnUtil {
     public Uuid getSubnetFromExternalRouterByIp(Uuid routerId, String ip) {
         Routers externalRouter = getExternalRouter(routerId.getValue());
         if (externalRouter != null && externalRouter.getExternalIps() != null) {
-            for (ExternalIps externalIp : externalRouter.getExternalIps()) {
+            for (ExternalIps externalIp : externalRouter.getExternalIps().values()) {
                 if (Objects.equals(externalIp.getIpAddress(), ip)) {
                     return externalIp.getSubnetId();
                 }
@@ -1707,7 +1737,7 @@ public final class VpnUtil {
         InstanceIdentifier<Network> inst = InstanceIdentifier.create(Neutron.class).child(
                 org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.Networks.class).child(
                 Network.class, new NetworkKey(networkId));
-        return read(LogicalDatastoreType.CONFIGURATION, inst).orNull();
+        return read(LogicalDatastoreType.CONFIGURATION, inst).orElse(null);
     }
 
     public static boolean isEligibleForBgp(@Nullable String rd, @Nullable String vpnName, @Nullable Uint64 dpnId,
@@ -1734,13 +1764,18 @@ public final class VpnUtil {
 
     void removeExternalTunnelDemuxFlows(String vpnName) {
         LOG.info("Removing external tunnel flows for vpn {}", vpnName);
-        for (Uint64 dpnId: NWUtil.getOperativeDPNs(dataBroker)) {
-            LOG.debug("Removing external tunnel flows for vpn {} from dpn {}", vpnName, dpnId);
-            String flowRef = getFibFlowRef(dpnId, NwConstants.L3VNI_EXTERNAL_TUNNEL_DEMUX_TABLE,
-                    vpnName, VpnConstants.DEFAULT_FLOW_PRIORITY);
-            FlowEntity flowEntity = VpnUtil.buildFlowEntity(dpnId,
-                    NwConstants.L3VNI_EXTERNAL_TUNNEL_DEMUX_TABLE, flowRef);
-            mdsalManager.removeFlow(flowEntity);
+        try {
+            for (Uint64 dpnId: NWUtil.getOperativeDPNs(dataBroker)) {
+                LOG.debug("Removing external tunnel flows for vpn {} from dpn {}", vpnName, dpnId);
+                String flowRef = getFibFlowRef(dpnId, NwConstants.L3VNI_EXTERNAL_TUNNEL_DEMUX_TABLE,
+                        vpnName, VpnConstants.DEFAULT_FLOW_PRIORITY);
+                FlowEntity flowEntity = VpnUtil.buildFlowEntity(dpnId,
+                        NwConstants.L3VNI_EXTERNAL_TUNNEL_DEMUX_TABLE, flowRef);
+                mdsalManager.removeFlow(flowEntity);
+            }
+        } catch (ExecutionException | InterruptedException e) {
+            LOG.error("removeExternalTunnelDemuxFlows: Exception while removing external tunnel flows for vpn {}",
+                    vpnName, e);
         }
     }
 
@@ -1757,17 +1792,30 @@ public final class VpnUtil {
         return isVpnPendingDelete;
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public List<VpnInstanceOpDataEntry> getVpnsImportingMyRoute(final String vpnName) {
         List<VpnInstanceOpDataEntry> vpnsToImportRoute = new ArrayList<>();
+        final VpnInstanceOpDataEntry vpnInstanceOpDataEntry;
         final String vpnRd = getVpnRd(vpnName);
         if (vpnRd == null) {
             LOG.error("getVpnsImportingMyRoute: vpn {} not present in config DS.", vpnName);
             return vpnsToImportRoute;
         }
-        final VpnInstanceOpDataEntry vpnInstanceOpDataEntry = getVpnInstanceOpData(vpnRd);
-        if (vpnInstanceOpDataEntry == null) {
-            LOG.error("getVpnsImportingMyRoute: Could not retrieve vpn instance op data for {}"
-                    + " to check for vpns importing the routes", vpnName);
+        if (vpnRd.equals(vpnName)) {
+            LOG.error("getVpnsImportingMyRoute: Internal vpn {} do not export/import routes", vpnName);
+            return vpnsToImportRoute;
+        }
+        try {
+            final VpnInstanceOpDataEntry opDataEntry = getVpnInstanceOpData(vpnRd);
+            if (opDataEntry == null) {
+                LOG.error("getVpnsImportingMyRoute: Could not retrieve vpn instance op data for vpn {} rd {}"
+                        + " to check for vpns importing the routes", vpnName, vpnRd);
+                return vpnsToImportRoute;
+            }
+            vpnInstanceOpDataEntry = opDataEntry;
+        } catch (Exception e) {
+            LOG.error("getVpnsImportingMyRoute: DSException when retrieving vpn instance op data for vpn {} rd {}"
+                    + " to check for vpns importing the routes", vpnName, vpnRd);
             return vpnsToImportRoute;
         }
         Predicate<VpnInstanceOpDataEntry> excludeVpn = input -> {
@@ -1797,12 +1845,12 @@ public final class VpnUtil {
             LOG.debug("getRts: vpn targets not available for {}", name);
             return rts;
         }
-        List<VpnTarget> vpnTargets = targets.getVpnTarget();
-        if (vpnTargets == null) {
+        Map<VpnTargetKey, VpnTarget> keyVpnTargetMap = targets.getVpnTarget();
+        if (keyVpnTargetMap == null) {
             LOG.debug("getRts: vpnTarget values not available for {}", name);
             return rts;
         }
-        for (VpnTarget target : vpnTargets) {
+        for (VpnTarget target : keyVpnTargetMap.values()) {
             //TODO: Check for RT type is Both
             if (target.getVrfRTType().equals(rtType) || target.getVrfRTType().equals(VpnTarget.VrfRTType.Both)) {
                 String rtValue = target.getVrfRTValue();
@@ -1825,7 +1873,7 @@ public final class VpnUtil {
     @Nullable
     public Subnetmap getSubnetmapFromItsUuid(Uuid subnetUuid) {
         InstanceIdentifier<Subnetmap> id = buildSubnetmapIdentifier(subnetUuid);
-        return read(LogicalDatastoreType.CONFIGURATION, id).orNull();
+        return read(LogicalDatastoreType.CONFIGURATION, id).orElse(null);
     }
 
     boolean isAdjacencyEligibleToVpnInternet(Adjacency adjacency) {
@@ -1916,9 +1964,8 @@ public final class VpnUtil {
 
     ListenableFuture<Void> unsetScheduledToRemoveForVpnInterface(String interfaceName) {
         VpnInterfaceBuilder builder = new VpnInterfaceBuilder().withKey(new VpnInterfaceKey(interfaceName));
-        return txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> tx.merge(
-                VpnUtil.getVpnInterfaceIdentifier(interfaceName), builder.build(),
-                WriteTransaction.CREATE_MISSING_PARENTS));
+        return txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> tx.mergeParentStructureMerge(
+                VpnUtil.getVpnInterfaceIdentifier(interfaceName), builder.build()));
     }
 
     /**
@@ -1995,8 +2042,9 @@ public final class VpnUtil {
             Optional<ElanDpnInterfacesList> dpnInElanInterfaces = read(LogicalDatastoreType.OPERATIONAL,
                     elanDpnInterfaceId);
             if (dpnInElanInterfaces.isPresent()) {
-                List<DpnInterfaces> dpnInterfaces = dpnInElanInterfaces.get().nonnullDpnInterfaces();
-                for (DpnInterfaces dpnInterface : dpnInterfaces) {
+                Map<DpnInterfacesKey, DpnInterfaces> dpnInterfacesMap
+                        = dpnInElanInterfaces.get().nonnullDpnInterfaces();
+                for (DpnInterfaces dpnInterface : dpnInterfacesMap.values()) {
                     dpnIdSet.add(dpnInterface.getDpId());
                 }
             }
@@ -2066,7 +2114,7 @@ public final class VpnUtil {
     @Nullable
     ElanInterface getElanInterfaceByElanInterfaceName(String elanInterfaceName) {
         InstanceIdentifier<ElanInterface> elanInterfaceId = getElanInterfaceConfigurationDataPathId(elanInterfaceName);
-        return read(LogicalDatastoreType.CONFIGURATION, elanInterfaceId).orNull();
+        return read(LogicalDatastoreType.CONFIGURATION, elanInterfaceId).orElse(null);
     }
 
     static InstanceIdentifier<ElanInterface> getElanInterfaceConfigurationDataPathId(String interfaceName) {
@@ -2078,7 +2126,7 @@ public final class VpnUtil {
     DpnInterfaces getElanInterfaceInfoByElanDpn(String elanInstanceName, Uint64 dpId) {
         InstanceIdentifier<DpnInterfaces> elanDpnInterfacesId = getElanDpnInterfaceOperationalDataPath(elanInstanceName,
                 dpId);
-        return read(LogicalDatastoreType.OPERATIONAL, elanDpnInterfacesId).orNull();
+        return read(LogicalDatastoreType.OPERATIONAL, elanDpnInterfacesId).orElse(null);
     }
 
     @Nullable
@@ -2116,16 +2164,16 @@ public final class VpnUtil {
     ElanInstance getElanInstanceByName(String elanInstanceName) {
         InstanceIdentifier<ElanInstance> elanIdentifierId =
                 ElanHelper.getElanInstanceConfigurationDataPath(elanInstanceName);
-        return read(LogicalDatastoreType.CONFIGURATION, elanIdentifierId).orNull();
+        return read(LogicalDatastoreType.CONFIGURATION, elanIdentifierId).orElse(null);
     }
 
     @Nullable
     String getVpnNameFromElanIntanceName(String elanInstanceName) {
         Optional<Subnetmaps> subnetMapsData = read(LogicalDatastoreType.CONFIGURATION, buildSubnetMapsWildCardPath());
         if (subnetMapsData.isPresent()) {
-            List<Subnetmap> subnetMapList = subnetMapsData.get().getSubnetmap();
-            if (subnetMapList != null && !subnetMapList.isEmpty()) {
-                for (Subnetmap subnet : subnetMapList) {
+            Map<SubnetmapKey, Subnetmap> keySubnetmapMap = subnetMapsData.get().getSubnetmap();
+            if (keySubnetmapMap != null && !keySubnetmapMap.isEmpty()) {
+                for (Subnetmap subnet : keySubnetmapMap.values()) {
                     if (subnet.getNetworkId().getValue().equals(elanInstanceName)) {
                         if (subnet.getVpnId() != null) {
                             return subnet.getVpnId().getValue();
@@ -2144,7 +2192,7 @@ public final class VpnUtil {
             List<Subnetmap> subnetMapList = new ArrayList<>();
             Subnetmaps subnetMaps = subnetMapsData.get();
             subnetMapList = (subnetMaps.getSubnetmap() != null && !subnetMaps.getSubnetmap().isEmpty())
-                    ? new ArrayList<>(subnetMaps.getSubnetmap()) : subnetMapList;
+                    ? new ArrayList<>(subnetMaps.getSubnetmap().values()) : subnetMapList;
 
             if (subnetMapList != null && !subnetMapList.isEmpty()) {
                 for (Subnetmap subnet : subnetMapList) {
@@ -2169,9 +2217,9 @@ public final class VpnUtil {
     String getRouterPordIdFromElanInstance(String elanInstanceName) {
         Optional<Subnetmaps> subnetMapsData = read(LogicalDatastoreType.CONFIGURATION, buildSubnetMapsWildCardPath());
         if (subnetMapsData.isPresent()) {
-            List<Subnetmap> subnetMapList = subnetMapsData.get().getSubnetmap();
-            if (subnetMapList != null && !subnetMapList.isEmpty()) {
-                for (Subnetmap subnet : subnetMapList) {
+            Map<SubnetmapKey, Subnetmap> keySubnetmapMap = subnetMapsData.get().getSubnetmap();
+            if (keySubnetmapMap != null && !keySubnetmapMap.isEmpty()) {
+                for (Subnetmap subnet : keySubnetmapMap.values()) {
                     if (subnet.getNetworkId().getValue().equals(elanInstanceName)) {
                         if (subnet.getRouterInterfacePortId() != null) {
                             return subnet.getRouterInterfacePortId().getValue();
@@ -2247,26 +2295,73 @@ public final class VpnUtil {
         }
     }
 
-    Set<org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.vpntargets.VpnTarget>
-        getRtListForVpn(String vpnName) {
-        Set<org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.vpntargets
-                .VpnTarget> rtList = new HashSet<>();
-        InstanceIdentifier<VpnInstance> vpnInstanceId = InstanceIdentifier.builder(VpnInstances.class)
-                .child(VpnInstance.class, new VpnInstanceKey(vpnName)).build();
-        Optional<VpnInstance> vpnInstanceOptional = read(LogicalDatastoreType.CONFIGURATION, vpnInstanceId);
-        if (vpnInstanceOptional.isPresent()) {
-            org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.VpnTargets
-                    vpnTargets = vpnInstanceOptional.get().getIpv4Family().getVpnTargets();
-            if (vpnTargets != null && vpnTargets.getVpnTarget() != null) {
-                rtList.addAll(vpnTargets.getVpnTarget());
+    static Set<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.vpn
+            .instance.vpntargets.VpnTarget> getRtListForVpn(DataBroker dataBroker, String vpnName) {
+        Set<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.vpn
+                .instance.vpntargets.VpnTarget> rtList = new HashSet<>();
+        try {
+            InstanceIdentifier<VpnInstance> vpnInstanceId = InstanceIdentifier.builder(VpnInstances.class)
+                    .child(VpnInstance.class, new VpnInstanceKey(vpnName)).build();
+            Optional<VpnInstance> vpnInstanceOptional = SingleTransactionDataBroker.syncReadOptional(dataBroker,
+                    LogicalDatastoreType.CONFIGURATION, vpnInstanceId);
+            if (vpnInstanceOptional.isPresent()) {
+                org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances
+                        .vpn.instance.VpnTargets vpnTargets = vpnInstanceOptional.get().getVpnTargets();
+                if (vpnTargets != null && vpnTargets.getVpnTarget() != null) {
+                    rtList.addAll(vpnTargets.getVpnTarget().values());
+                }
+            } else {
+                LOG.error("getRtListForVpn: Vpn Instance {} not present in config DS", vpnName);
             }
-        }
-        else {
-            LOG.error("getRtListForVpn: Vpn Instance {} not present in config DS", vpnName);
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("getRtListForVpn: Read failed for Vpn Instance {}", vpnName);
         }
         return rtList;
     }
 
+    /*
+    if (update == 0) {
+    removedFamily = original
+    4 removed = 4
+    6 removed = 6
+    10 removed
+    } else if (update < original) {
+    removedFamily = original - update
+    10 was there 4 removed = 6
+    10 was there 6 removed  = 4
+    } else {
+   return;
+    }
+    */
+    public static int getIpFamilyValueToRemove(VpnInstanceOpDataEntry original, VpnInstanceOpDataEntry update) {
+        int originalValue = original.getIpAddressFamilyConfigured().getIntValue();
+        int updatedValue = update.getIpAddressFamilyConfigured().getIntValue();
+
+        if (originalValue == updatedValue) {
+            return 0;
+        }
+        int removedFamily;
+        if (updatedValue == 0) {
+            removedFamily = originalValue;
+        } else if (updatedValue < originalValue) {
+            removedFamily = originalValue - updatedValue;
+        } else {
+            return 0;
+        }
+        return removedFamily;
+    }
+
+    public static int getIpFamilyValueToAdd(VpnInstanceOpDataEntry original, VpnInstanceOpDataEntry update) {
+        int originalValue = original.getIpAddressFamilyConfigured().getIntValue();
+        int updatedValue = update.getIpAddressFamilyConfigured().getIntValue();
+
+        if (originalValue != updatedValue) {
+            return updatedValue;
+        } else {
+            return originalValue;
+        }
+    }
+
     static InstanceIdentifier<AssociatedVpn> getAssociatedSubnetAndVpnIdentifier(String rt, RouteTarget.RtType rtType,
                                                                                  String cidr, String vpnName) {
         return InstanceIdentifier.builder(SubnetsAssociatedToRouteTargets.class).child(RouteTarget.class,
@@ -2289,11 +2384,11 @@ public final class VpnUtil {
                 .child(RouteTarget.class, new RouteTargetKey(rt, rtType)).build();
     }
 
-    Set<RouteTarget> getRouteTargetSet(Set<org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815
-            .vpn.af.config.vpntargets.VpnTarget> vpnTargets) {
+    Set<RouteTarget> getRouteTargetSet(Set<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn
+            .rev200204.vpn.instances.vpn.instance.vpntargets.VpnTarget> vpnTargets) {
         Set<RouteTarget> routeTargetSet = new HashSet<>();
-        for (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.vpntargets
-                .VpnTarget rt : vpnTargets) {
+        for (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.vpn
+                .instance.vpntargets.VpnTarget rt : vpnTargets) {
             String rtValue = rt.getVrfRTValue();
             switch (rt.getVrfRTType()) {
                 case ImportExtcommunity: {
@@ -2377,7 +2472,7 @@ public final class VpnUtil {
     }
 
     public static List<String> getVpnListForVpnInterface(VpnInterface vpnInter) {
-        return vpnInter.nonnullVpnInstanceNames().stream()
+        return vpnInter.nonnullVpnInstanceNames().values().stream()
                 .map(VpnInstanceNames::getVpnName).collect(Collectors.toList());
     }
 
@@ -2396,7 +2491,7 @@ public final class VpnUtil {
                     InstanceIdentifier<VpnInstanceOpDataEntry> id = InstanceIdentifier
                             .builder(VpnInstanceOpData.class).child(VpnInstanceOpDataEntry.class,
                                     new VpnInstanceOpDataEntryKey(primaryRd)).build();
-                    tx.merge(id, builder.build(), false);
+                    tx.merge(id, builder.build());
                     LOG.debug("updateVpnInstanceWithRdList: Successfully updated the VPN {} with list of RDs {}",
                             vpnName, updatedRdList);
                 }));