Bump upstreams for Silicon
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / l2gw / utils / ElanL2GatewayUtils.java
index 89a1a54d4a80d83fde9e5911a078883a1e765beb..869543eb59737184782f8c2228fd213819895630 100644 (file)
@@ -7,10 +7,10 @@
  */
 package org.opendaylight.netvirt.elan.l2gw.utils;
 
-import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION;
 
-import com.google.common.base.Optional;
 import com.google.common.collect.Lists;
+import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -23,6 +23,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Locale;
 import java.util.Objects;
+import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
@@ -32,26 +33,30 @@ import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
 import java.util.stream.Collectors;
-import javax.annotation.Nonnull;
 import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
-import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
-import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
+import org.opendaylight.genius.mdsalutil.cache.InstanceIdDataObjectCache;
 import org.opendaylight.genius.utils.SystemPropertyReader;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
 import org.opendaylight.genius.utils.hwvtep.HwvtepUtils;
+import org.opendaylight.infrautils.caches.CacheProvider;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
-import org.opendaylight.infrautils.utils.concurrent.JdkFutures;
-import org.opendaylight.netvirt.elan.ElanException;
+import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner;
+import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.mdsal.binding.util.TypedWriteTransaction;
+import org.opendaylight.mdsal.common.api.CommitInfo;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.common.api.ReadFailedException;
 import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.cache.ElanInstanceDpnsCache;
 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
@@ -69,19 +74,19 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.IetfYangUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetDpidFromInterfaceInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetDpidFromInterfaceOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVteps;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.DeviceVteps;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.AddL2GwDeviceInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.AddL2GwDeviceOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.config.rev150710.ElanConfig;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInstances;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan._interface.forwarding.entries.ElanInterfaceMac;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.elan.dpn.interfaces.list.DpnInterfaces;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.forwarding.tables.MacTable;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
@@ -94,6 +99,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hw
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalPortAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalPortAugmentationBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacs;
@@ -101,10 +108,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hw
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.locator.set.attributes.LocatorSet;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.port.attributes.VlanBindings;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
+import org.opendaylight.yangtools.util.concurrent.FluentFutures;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.Uint64;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -138,13 +155,17 @@ public class ElanL2GatewayUtils {
     private final ConcurrentMap<Pair<NodeId, String>, DeleteLogicalSwitchJob> deleteJobs = new ConcurrentHashMap<>();
     private final Scheduler scheduler;
     private final ElanConfig elanConfig;
+    private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
+    private final InstanceIdDataObjectCache<TerminationPoint> portsCache;
 
     @Inject
     public ElanL2GatewayUtils(DataBroker broker, ElanDmacUtils elanDmacUtils, ElanItmUtils elanItmUtils,
-            ElanClusterUtils elanClusterUtils, OdlInterfaceRpcService interfaceManagerRpcService,
-            JobCoordinator jobCoordinator, ElanUtils elanUtils,
-            Scheduler scheduler, ElanConfig elanConfig, ElanInstanceCache elanInstanceCache,
-            ElanInstanceDpnsCache elanInstanceDpnsCache) {
+                              ElanClusterUtils elanClusterUtils, OdlInterfaceRpcService interfaceManagerRpcService,
+                              JobCoordinator jobCoordinator, ElanUtils elanUtils,
+                              Scheduler scheduler, ElanConfig elanConfig, ElanInstanceCache elanInstanceCache,
+                              ElanInstanceDpnsCache elanInstanceDpnsCache,
+                              ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils,
+                              CacheProvider cacheProvider) {
         this.broker = broker;
         this.txRunner = new ManagedNewTransactionRunnerImpl(broker);
         this.elanDmacUtils = elanDmacUtils;
@@ -157,6 +178,13 @@ public class ElanL2GatewayUtils {
         this.elanConfig = elanConfig;
         this.elanInstanceCache = elanInstanceCache;
         this.elanInstanceDpnsCache = elanInstanceDpnsCache;
+        this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
+        InstanceIdentifier<TerminationPoint> iid = InstanceIdentifier.create(NetworkTopology.class)
+                .child(Topology.class, new TopologyKey(HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID))
+                .child(Node.class).child(TerminationPoint.class);
+        LOG.info("termination point iid: {}", iid);
+        portsCache = new InstanceIdDataObjectCache<>(TerminationPoint.class, broker,
+                LogicalDatastoreType.CONFIGURATION, iid, cacheProvider);
     }
 
     @PreDestroy
@@ -165,7 +193,7 @@ public class ElanL2GatewayUtils {
 
     public long getLogicalSwitchDeleteDelaySecs() {
         return elanConfig.getL2gwLogicalSwitchDelaySecs() != null
-                ? elanConfig.getL2gwLogicalSwitchDelaySecs() : DEFAULT_LOGICAL_SWITCH_DELETE_DELAY_SECS;
+                ? elanConfig.getL2gwLogicalSwitchDelaySecs().toJava() : DEFAULT_LOGICAL_SWITCH_DELETE_DELAY_SECS;
     }
 
     /**
@@ -175,6 +203,7 @@ public class ElanL2GatewayUtils {
      *            the lst elan interface names
      * @return the list
      */
+    /*
     public List<PhysAddress> getElanDpnMacsFromInterfaces(Set<String> lstElanInterfaceNames) {
         List<PhysAddress> result = new ArrayList<>();
         for (String interfaceName : lstElanInterfaceNames) {
@@ -186,7 +215,7 @@ public class ElanL2GatewayUtils {
             }
         }
         return result;
-    }
+    }*/
 
     /**
      * Check if phy locator already exists in remote mcast entry.
@@ -203,12 +232,12 @@ public class ElanL2GatewayUtils {
             RemoteMcastMacs remoteMcastMac, IpAddress expectedPhyLocatorIp) {
         if (remoteMcastMac != null) {
             HwvtepPhysicalLocatorAugmentation expectedPhyLocatorAug = HwvtepSouthboundUtils
-                    .createHwvtepPhysicalLocatorAugmentation(expectedPhyLocatorIp.stringValue());
+                    .createHwvtepPhysicalLocatorAugmentation(expectedPhyLocatorIp);
             HwvtepPhysicalLocatorRef expectedPhyLocRef = new HwvtepPhysicalLocatorRef(
                     HwvtepSouthboundUtils.createPhysicalLocatorInstanceIdentifier(nodeId, expectedPhyLocatorAug));
             if (remoteMcastMac.getLocatorSet() != null) {
                 for (LocatorSet locatorSet : remoteMcastMac.getLocatorSet()) {
-                    if (locatorSet.getLocatorRef().equals(expectedPhyLocRef)) {
+                    if (Objects.equals(locatorSet.getLocatorRef(), expectedPhyLocRef)) {
                         LOG.trace("matched phyLocRef: {}", expectedPhyLocRef);
                         return true;
                     }
@@ -235,7 +264,13 @@ public class ElanL2GatewayUtils {
                 .createLogicalSwitchesInstanceIdentifier(nodeId, new HwvtepNodeName(logicalSwitchName));
         RemoteMcastMacsKey remoteMcastMacsKey = new RemoteMcastMacsKey(new HwvtepLogicalSwitchRef(logicalSwitch),
                 new MacAddress(ElanConstants.UNKNOWN_DMAC));
-        return HwvtepUtils.getRemoteMcastMac(broker, datastoreType, nodeId, remoteMcastMacsKey);
+        try {
+            return HwvtepUtils.getRemoteMcastMac(broker, datastoreType, nodeId, remoteMcastMacsKey);
+        } catch (ExecutionException | InterruptedException e) {
+            LOG.error("readRemoteMcastMac: Exception while reading LogicalSwitches DS for the nodeId {}, "
+                    + "logicalSwitchName {}", nodeId.getValue(), logicalSwitch, e);
+        }
+        return null;
     }
 
     /**
@@ -265,16 +300,18 @@ public class ElanL2GatewayUtils {
      *            the mac addresses
      * @return the listenable future
      */
-    private ListenableFuture<Void> removeRemoteUcastMacsFromExternalDevice(String deviceNodeId,
+    private FluentFuture<? extends @NonNull CommitInfo> removeRemoteUcastMacsFromExternalDevice(String deviceNodeId,
             String logicalSwitchName, List<PhysAddress> macAddresses) {
         NodeId nodeId = new NodeId(deviceNodeId);
 
         // TODO (eperefr)
         List<MacAddress> lstMac = macAddresses.stream().filter(Objects::nonNull).map(
-            physAddress -> new MacAddress(physAddress.getValue())).collect(Collectors.toList());
+            physAddress -> new MacAddress(physAddress.getValue().toLowerCase(Locale.getDefault())))
+            .collect(Collectors.toList());
         return HwvtepUtils.deleteRemoteUcastMacs(broker, nodeId, logicalSwitchName, lstMac);
     }
 
+    @Nullable
     public ElanInstance getElanInstanceForUcastLocalMac(LocalUcastMacs localUcastMac) {
         Optional<LogicalSwitches> lsOpc = ElanUtils.read(broker, LogicalDatastoreType.OPERATIONAL,
                 (InstanceIdentifier<LogicalSwitches>) localUcastMac.getLogicalSwitchRef().getValue());
@@ -282,7 +319,7 @@ public class ElanL2GatewayUtils {
             LogicalSwitches ls = lsOpc.get();
             // Logical switch name is Elan name
             String elanName = getElanFromLogicalSwitch(ls.getHwvtepNodeName().getValue());
-            return elanInstanceCache.get(elanName).orNull();
+            return elanInstanceCache.get(elanName).orElse(null);
         }
         return null;
     }
@@ -298,10 +335,9 @@ public class ElanL2GatewayUtils {
      *            the elan
      * @param interfaceName
      *            the interface name
-     * @throws ElanException in case of issues creating the flow objects
      */
-    public void installL2gwDeviceMacsInDpn(BigInteger dpnId, NodeId l2gwDeviceNodeId, ElanInstance elan,
-            String interfaceName) throws ElanException {
+    public void installL2gwDeviceMacsInDpn(Uint64 dpnId, NodeId l2gwDeviceNodeId, ElanInstance elan,
+            String interfaceName) {
         L2GatewayDevice l2gwDevice = ElanL2GwCacheUtils.getL2GatewayDeviceFromCache(elan.getElanInstanceName(),
                 l2gwDeviceNodeId.getValue());
         if (l2gwDevice == null) {
@@ -323,22 +359,22 @@ public class ElanL2GatewayUtils {
      *            the elan
      * @param interfaceName
      *            the interface name
-     * @throws ElanException in case of issues creating the flow objects
      */
-    public void installDmacFlowsOnDpn(BigInteger dpnId, L2GatewayDevice l2gwDevice, ElanInstance elan,
-            String interfaceName) throws ElanException {
+    public List<ListenableFuture<Void>> installDmacFlowsOnDpn(Uint64 dpnId, L2GatewayDevice l2gwDevice,
+                                                              ElanInstance elan, String interfaceName) {
         String elanName = elan.getElanInstanceName();
-
+        List<ListenableFuture<Void>> fts = new ArrayList<>();
         Collection<LocalUcastMacs> l2gwDeviceLocalMacs = l2gwDevice.getUcastLocalMacs();
-        if (!l2gwDeviceLocalMacs.isEmpty()) {
+        if (l2gwDeviceLocalMacs != null && !l2gwDeviceLocalMacs.isEmpty()) {
             for (LocalUcastMacs localUcastMac : l2gwDeviceLocalMacs) {
-                elanDmacUtils.installDmacFlowsToExternalRemoteMacInBatch(dpnId, l2gwDevice.getHwvtepNodeId(),
-                        elan.getElanTag(), ElanUtils.getVxlanSegmentationId(elan),
-                        localUcastMac.getMacEntryKey().getValue(), elanName, interfaceName);
+                fts.addAll(elanDmacUtils.installDmacFlowsToExternalRemoteMacInBatch(dpnId, l2gwDevice.getHwvtepNodeId(),
+                        elan.getElanTag().toJava(), ElanUtils.getVxlanSegmentationId(elan).longValue(),
+                        localUcastMac.getMacEntryKey().getValue(), elanName, interfaceName));
             }
             LOG.debug("Installing L2gw device [{}] local macs [size: {}] in dpn [{}] for elan [{}]",
                     l2gwDevice.getHwvtepNodeId(), l2gwDeviceLocalMacs.size(), dpnId, elanName);
         }
+        return fts;
     }
 
     /**
@@ -350,10 +386,8 @@ public class ElanL2GatewayUtils {
      *            the elan
      * @param interfaceName
      *            the interface name
-     * @throws ElanException in case of issues creating the flow objects
      */
-    public void installElanL2gwDevicesLocalMacsInDpn(BigInteger dpnId, ElanInstance elan, String interfaceName)
-            throws ElanException {
+    public void installElanL2gwDevicesLocalMacsInDpn(Uint64 dpnId, ElanInstance elan, String interfaceName) {
         ConcurrentMap<String, L2GatewayDevice> elanL2GwDevicesFromCache = ElanL2GwCacheUtils
                 .getInvolvedL2GwDevices(elan.getElanInstanceName());
         if (elanL2GwDevicesFromCache != null) {
@@ -366,7 +400,7 @@ public class ElanL2GatewayUtils {
     }
 
     public void installL2GwUcastMacInElan(final ElanInstance elan, final L2GatewayDevice extL2GwDevice,
-            final String macToBeAdded, final LocalUcastMacs localUcastMacs, String interfaceName) {
+            final String macToBeAdded, final LocalUcastMacs localUcastMacs, @Nullable String interfaceName) {
         final String extDeviceNodeId = extL2GwDevice.getHwvtepNodeId();
         final String elanInstanceName = elan.getElanInstanceName();
         final Collection<DpnInterfaces> elanDpns = getElanDpns(elanInstanceName);
@@ -384,10 +418,11 @@ public class ElanL2GatewayUtils {
 
             elanClusterUtils.runOnlyInOwnerNode(jobKey, "install l2gw macs in dmac table", () -> {
                 if (doesLocalUcastMacExistsInCache(extL2GwDevice, localUcastMacs)) {
-                    List<ListenableFuture<Void>> futures = new ArrayList<>();
+                    List<ListenableFuture<?>> futures = new ArrayList<>();
                     for (DpnInterfaces elanDpn : elanDpns) {
                         futures.addAll(elanDmacUtils.installDmacFlowsToExternalRemoteMacInBatch(elanDpn.getDpId(),
-                                extDeviceNodeId, elan.getElanTag(), ElanUtils.getVxlanSegmentationId(elan),
+                                extDeviceNodeId, elan.getElanTag().toJava(),
+                                ElanUtils.getVxlanSegmentationId(elan).longValue(),
                                 macToBeAdded, elanInstanceName, interfaceName));
                     }
                     for (L2GatewayDevice otherDevice : elanL2GwDevices.values()) {
@@ -395,8 +430,8 @@ public class ElanL2GatewayUtils {
                                 && !areMLAGDevices(extL2GwDevice, otherDevice)) {
                             final String hwvtepId = otherDevice.getHwvtepNodeId();
                             final String logicalSwitchName = elanInstanceName;
-                            futures.add(HwvtepUtils.installUcastMacs(
-                                    broker, hwvtepId, macList, logicalSwitchName, extL2GwDeviceTepIp));
+                            HwvtepUtils.installUcastMacs(
+                                    broker, hwvtepId, macList, logicalSwitchName, extL2GwDeviceTepIp);
                         }
                     }
                     return futures;
@@ -471,9 +506,10 @@ public class ElanL2GatewayUtils {
             elanClusterUtils.runOnlyInOwnerNode(elan.getElanInstanceName() + ":" + mac.getValue(),
                     "delete remote ucast macs in elan DPNs", () -> {
                     for (DpnInterfaces elanDpn : elanDpns) {
-                        BigInteger dpnId = elanDpn.getDpId();
-                        result.addAll(elanDmacUtils.deleteDmacFlowsToExternalMac(elan.getElanTag(), dpnId,
-                                l2GwDevice.getHwvtepNodeId(), mac.getValue().toLowerCase(Locale.getDefault())));
+                        Uint64 dpnId = elanDpn.getDpId();
+                        result.addAll(elanDmacUtils.deleteDmacFlowsToExternalMac(elan.getElanTag().toJava(), dpnId,
+                            l2GwDevice.getHwvtepNodeId(),
+                            IetfYangUtil.INSTANCE.canonizeMacAddress(mac).getValue()));
                     }
                     return result;
                 });
@@ -488,20 +524,20 @@ public class ElanL2GatewayUtils {
      * @param dpnId
      *            the dpn id
      */
-    public void deleteElanL2GwDevicesUcastLocalMacsFromDpn(final String elanName, final BigInteger dpnId) {
+    public void deleteElanL2GwDevicesUcastLocalMacsFromDpn(final String elanName, final Uint64 dpnId) {
         ConcurrentMap<String, L2GatewayDevice> elanL2GwDevices = ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName);
         if (elanL2GwDevices == null || elanL2GwDevices.isEmpty()) {
             LOG.trace("No L2 gateway devices in Elan [{}] cache.", elanName);
             return;
         }
-        final ElanInstance elan = elanInstanceCache.get(elanName).orNull();
+        final ElanInstance elan = elanInstanceCache.get(elanName).orElse(null);
         if (elan == null) {
             LOG.error("Could not find Elan by name: {}", elanName);
             return;
         }
         LOG.info("Deleting Elan [{}] L2GatewayDevices UcastLocalMacs from Dpn [{}]", elanName, dpnId);
 
-        final Long elanTag = elan.getElanTag();
+        final Long elanTag = elan.getElanTag().toJava();
         for (final L2GatewayDevice l2GwDevice : elanL2GwDevices.values()) {
             getL2GwDeviceLocalMacsAndRunCallback(elan.getElanInstanceName(), l2GwDevice, (localMacs) -> {
                 for (MacAddress mac : localMacs) {
@@ -524,7 +560,7 @@ public class ElanL2GatewayUtils {
         Collection<LocalUcastMacs> lstUcastLocalMacs = l2gwDevice.getUcastLocalMacs();
         if (!lstUcastLocalMacs.isEmpty()) {
             macs.addAll(lstUcastLocalMacs.stream().filter(Objects::nonNull)
-                    .map(mac -> new MacAddress(mac.getMacEntryKey().getValue().toLowerCase()))
+                    .map(mac -> new MacAddress(mac.getMacEntryKey().getValue().toLowerCase(Locale.getDefault())))
                     .collect(Collectors.toList()));
         }
 
@@ -537,10 +573,10 @@ public class ElanL2GatewayUtils {
                         if (configNode != null && configNode.isPresent()) {
                             HwvtepGlobalAugmentation augmentation = configNode.get().augmentation(
                                     HwvtepGlobalAugmentation.class);
-                            if (augmentation != null && augmentation.getLocalUcastMacs() != null) {
-                                macs.addAll(augmentation.getLocalUcastMacs().stream()
+                            if (augmentation != null && augmentation.nonnullLocalUcastMacs() != null) {
+                                macs.addAll(augmentation.nonnullLocalUcastMacs().values().stream()
                                         .filter(mac -> getLogicalSwitchName(mac).equals(elanName))
-                                        .map(HwvtepMacTableGenericAttributes::getMacEntryKey)
+                                        .map(mac -> mac.getMacEntryKey())
                                         .collect(Collectors.toSet()));
                             }
                             function.apply(macs);
@@ -570,38 +606,18 @@ public class ElanL2GatewayUtils {
      *            the elan name
      * @return the listenable future
      */
-    public ListenableFuture<Void> deleteElanMacsFromL2GatewayDevice(String hwvtepNodeId, String elanName) {
-        String logicalSwitch = getLogicalSwitchFromElan(elanName);
+    public FluentFuture<? extends @NonNull CommitInfo> deleteElanMacsFromL2GatewayDevice(String hwvtepNodeId,
+        String elanName) {
 
+        String logicalSwitch = getLogicalSwitchFromElan(elanName);
         List<MacAddress> lstElanMacs = getRemoteUcastMacs(new NodeId(hwvtepNodeId), logicalSwitch,
                 LogicalDatastoreType.CONFIGURATION);
-        ListenableFuture<Void> future = HwvtepUtils.deleteRemoteUcastMacs(broker, new NodeId(hwvtepNodeId),
-                logicalSwitch, lstElanMacs);
-
-        Futures.addCallback(future, new FutureCallback<Void>() {
-            @Override
-            public void onSuccess(Void noarg) {
-                LOG.trace("Successful in batch deletion of elan [{}] macs from l2gw device [{}]", elanName,
-                        hwvtepNodeId);
-            }
-
-            @Override
-            public void onFailure(Throwable error) {
-                LOG.warn("Failed during batch delete of elan {} macs from l2gw device {}. "
-                        + "Retrying with sequential deletes.", elanName, hwvtepNodeId, error);
-                if (lstElanMacs != null && !lstElanMacs.isEmpty()) {
-                    for (MacAddress mac : lstElanMacs) {
-                        HwvtepUtils.deleteRemoteUcastMac(broker, new NodeId(hwvtepNodeId), logicalSwitch, mac);
-                    }
-                }
-            }
-        }, MoreExecutors.directExecutor());
-
         if (LOG.isDebugEnabled()) {
             List<String> elanMacs = lstElanMacs.stream().map(MacAddress::getValue).collect(Collectors.toList());
             LOG.debug("Deleting elan [{}] macs from node [{}]. Deleted macs = {}", elanName, hwvtepNodeId, elanMacs);
         }
-        return future;
+        return HwvtepUtils.deleteRemoteUcastMacs(broker, new NodeId(hwvtepNodeId),
+                logicalSwitch, lstElanMacs);
     }
 
     /**
@@ -619,10 +635,15 @@ public class ElanL2GatewayUtils {
     public List<MacAddress> getRemoteUcastMacs(NodeId hwvtepNodeId, String logicalSwitch,
             LogicalDatastoreType datastoreType) {
         List<MacAddress> lstMacs = Collections.emptyList();
-        Node hwvtepNode = HwvtepUtils.getHwVtepNode(broker, datastoreType, hwvtepNodeId);
+        Node hwvtepNode = null;
+        try {
+            hwvtepNode = HwvtepUtils.getHwVtepNode(broker, datastoreType, hwvtepNodeId);
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("Exception While Reading Node {}", hwvtepNodeId, e);
+        }
         if (hwvtepNode != null) {
-            List<RemoteUcastMacs> remoteUcastMacs = hwvtepNode.augmentation(HwvtepGlobalAugmentation.class)
-                    .getRemoteUcastMacs();
+            Collection<RemoteUcastMacs> remoteUcastMacs = hwvtepNode.augmentation(HwvtepGlobalAugmentation.class)
+                .nonnullRemoteUcastMacs().values();
             if (remoteUcastMacs != null && !remoteUcastMacs.isEmpty()) {
                 // Filtering remoteUcastMacs based on the logical switch and
                 // forming a list of MacAddress
@@ -646,7 +667,7 @@ public class ElanL2GatewayUtils {
      *            the l2 gateway device which has to be configured
      * @return the listenable future
      */
-    public ListenableFuture<Void> installElanMacsInL2GatewayDevice(String elanName,
+    public FluentFuture<? extends CommitInfo> installElanMacsInL2GatewayDevice(String elanName,
             L2GatewayDevice l2GatewayDevice) {
         String logicalSwitchName = getLogicalSwitchFromElan(elanName);
         NodeId hwVtepNodeId = new NodeId(l2GatewayDevice.getHwvtepNodeId());
@@ -659,7 +680,8 @@ public class ElanL2GatewayUtils {
         List<RemoteUcastMacs> lstRemoteUcastMacs = new ArrayList<>(lstL2GatewayDevicesMacs);
         lstRemoteUcastMacs.addAll(lstElanMacTableEntries);
 
-        ListenableFuture<Void> future = HwvtepUtils.addRemoteUcastMacs(broker, hwVtepNodeId, lstRemoteUcastMacs);
+        FluentFuture<? extends CommitInfo> future = HwvtepUtils.addRemoteUcastMacs(broker, hwVtepNodeId,
+            lstRemoteUcastMacs);
 
         LOG.info("Added RemoteUcastMacs entries [{}] in config DS. NodeID: {}, LogicalSwitch: {}",
                 lstRemoteUcastMacs.size(), hwVtepNodeId.getValue(), logicalSwitchName);
@@ -743,8 +765,8 @@ public class ElanL2GatewayUtils {
             return lstRemoteUcastMacs;
         }
 
-        for (MacEntry macEntry : macTable.getMacEntry()) {
-            BigInteger dpnId = getDpidFromInterface(macEntry.getInterface());
+        for (MacEntry macEntry : macTable.nonnullMacEntry().values()) {
+            Uint64 dpnId = getDpidFromInterface(macEntry.getInterface());
             if (dpnId == null) {
                 LOG.error("DPN ID not found for interface {}", macEntry.getInterface());
                 continue;
@@ -757,11 +779,11 @@ public class ElanL2GatewayUtils {
                 continue;
             }
             HwvtepPhysicalLocatorAugmentation physLocatorAug = HwvtepSouthboundUtils
-                    .createHwvtepPhysicalLocatorAugmentation(dpnTepIp.stringValue());
+                    .createHwvtepPhysicalLocatorAugmentation(dpnTepIp);
             // TODO: Query ARP cache to get IP address corresponding to the
             // MAC
             RemoteUcastMacs remoteUcastMac = HwvtepSouthboundUtils.createRemoteUcastMac(hwVtepNodeId,
-                    macEntry.getMacAddress().getValue().toLowerCase(Locale.getDefault()), null /*IpAddress*/,
+                    IetfYangUtil.INSTANCE.canonizePhysAddress(macEntry.getMacAddress()).getValue(), null /*IpAddress*/,
                     logicalSwitchName, physLocatorAug);
             lstRemoteUcastMacs.add(remoteUcastMac);
         }
@@ -775,8 +797,8 @@ public class ElanL2GatewayUtils {
      *            the interface name
      * @return the dpid from interface
      */
-    public BigInteger getDpidFromInterface(String interfaceName) {
-        BigInteger dpId = null;
+    public Uint64 getDpidFromInterface(String interfaceName) {
+        Uint64 dpId = null;
         Future<RpcResult<GetDpidFromInterfaceOutput>> output = interfaceManagerRpcService
                 .getDpidFromInterface(new GetDpidFromInterfaceInputBuilder().setIntfName(interfaceName).build());
         try {
@@ -785,11 +807,33 @@ public class ElanL2GatewayUtils {
                 dpId = rpcResult.getResult().getDpid();
             }
         } catch (InterruptedException | ExecutionException e) {
-            LOG.error("Failed to get the DPN ID for interface {}", interfaceName, e);
+            LOG.error("Failed to get the DPN ID for interface: {} ", interfaceName, e);
         }
         return dpId;
     }
 
+    /**
+     * Update vlan bindings in l2 gateway device.
+     *
+     * @param nodeId
+     *            the node id
+     * @param psName
+     *            the physical switch name
+     * @param interfaceName
+     *            the interface in physical switch
+     * @param vlanBindings
+     *            the vlan bindings to be configured
+     * @return the listenable future
+     */
+    public FluentFuture<?> updateVlanBindingsInL2GatewayDevice(NodeId nodeId, String psName,
+                                                                      String interfaceName,
+                                                                      List<VlanBindings> vlanBindings) {
+        return txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
+            mergeVlanBindings(tx, nodeId, psName, interfaceName, vlanBindings, false);
+            LOG.info("Updated Hwvtep VlanBindings in config DS. NodeID: {}", nodeId.getValue());
+        });
+    }
+
     /**
      * Update vlan bindings in l2 gateway device.
      *
@@ -803,58 +847,93 @@ public class ElanL2GatewayUtils {
      *            the default vlan id
      * @return the listenable future
      */
-    public ListenableFuture<Void> updateVlanBindingsInL2GatewayDevice(NodeId nodeId, String logicalSwitchName,
+    public FluentFuture<?> updateVlanBindingsInL2GatewayDevice(NodeId nodeId, String logicalSwitchName,
             Devices hwVtepDevice, Integer defaultVlanId) {
         if (hwVtepDevice == null || hwVtepDevice.getInterfaces() == null || hwVtepDevice.getInterfaces().isEmpty()) {
             String errMsg = "HwVtepDevice is null or interfaces are empty.";
             LOG.error(errMsg);
-            return Futures.immediateFailedFuture(new RuntimeException(errMsg));
+            return FluentFutures.immediateFailedFluentFuture(new RuntimeException(errMsg));
         }
-
-        return txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+        return txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
             for (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712
-                    .l2gateway.attributes.devices.Interfaces deviceInterface : hwVtepDevice.getInterfaces()) {
+                .l2gateway.attributes.devices.Interfaces deviceInterface : hwVtepDevice
+                .nonnullInterfaces().values()) {
                 //Removed the check for checking terminationPoint present in OP or not
                 //for coniguring vlan bindings
                 //As we are not any more dependent on it , plugin takes care of this
                 // with port reconcilation.
                 List<VlanBindings> vlanBindings = new ArrayList<>();
-                if (deviceInterface.getSegmentationIds() != null && !deviceInterface.getSegmentationIds().isEmpty()) {
+                if (deviceInterface.getSegmentationIds() != null && !deviceInterface
+                    .getSegmentationIds().isEmpty()) {
                     for (Integer vlanId : deviceInterface.getSegmentationIds()) {
-                        vlanBindings.add(HwvtepSouthboundUtils.createVlanBinding(nodeId, vlanId, logicalSwitchName));
+                        vlanBindings.add(HwvtepSouthboundUtils
+                            .createVlanBinding(nodeId, vlanId, logicalSwitchName));
                     }
                 } else {
                     // Use defaultVlanId (specified in L2GatewayConnection) if Vlan
                     // ID not specified at interface level.
-                    vlanBindings.add(HwvtepSouthboundUtils.createVlanBinding(nodeId, defaultVlanId, logicalSwitchName));
+                    vlanBindings.add(HwvtepSouthboundUtils
+                        .createVlanBinding(nodeId, defaultVlanId, logicalSwitchName));
+                }
+
+                TerminationPointKey tpKey = new TerminationPointKey(
+                    new TpId(deviceInterface.getInterfaceName()));
+                InstanceIdentifier<TerminationPoint> portIid = HwvtepSouthboundUtils
+                    .createTerminationPointId(HwvtepSouthboundUtils.createManagedNodeId(nodeId,
+                        hwVtepDevice.getDeviceName()), tpKey);
+
+                try {
+                    boolean createParent = false;
+                    if (!portsCache.get(portIid).isPresent()) {
+                        //create port
+                        //pass additional flag
+                        createParent = true;
+                    }
+                    mergeVlanBindings(tx, nodeId, hwVtepDevice.getDeviceName(),
+                        deviceInterface.getInterfaceName(), vlanBindings, createParent);
+                } catch (ReadFailedException e) {
+                    LOG.error("Read Failed for PortIid {} {}", portIid, e.getMessage());
                 }
-                HwvtepUtils.mergeVlanBindings(tx, nodeId, hwVtepDevice.getDeviceName(),
-                        deviceInterface.getInterfaceName(), vlanBindings);
             }
-            LOG.info("Updated Hwvtep VlanBindings in config DS. NodeID: {}, LogicalSwitch: {}", nodeId.getValue(),
-                    logicalSwitchName);
+            LOG.info("Updated Hwvtep VlanBindings in config DS. NodeID: {}, LogicalSwitch: {}",
+                nodeId.getValue(),logicalSwitchName);
         });
     }
 
-    /**
-     * Update vlan bindings in l2 gateway device.
-     *
-     * @param nodeId
-     *            the node id
-     * @param psName
-     *            the physical switch name
-     * @param interfaceName
-     *            the interface in physical switch
-     * @param vlanBindings
-     *            the vlan bindings to be configured
-     * @return the listenable future
-     */
-    public ListenableFuture<Void> updateVlanBindingsInL2GatewayDevice(NodeId nodeId, String psName,
-            String interfaceName, List<VlanBindings> vlanBindings) {
-        return txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
-            HwvtepUtils.mergeVlanBindings(tx, nodeId, psName, interfaceName, vlanBindings);
-            LOG.info("Updated Hwvtep VlanBindings in config DS. NodeID: {}", nodeId.getValue());
-        });
+    private static void mergeVlanBindings(TypedWriteTransaction tx, NodeId nodeId, String phySwitchName,
+                                         String phyPortName, List<VlanBindings> vlanBindings,
+                                         boolean createParent) {
+        NodeId physicalSwitchNodeId = HwvtepSouthboundUtils.createManagedNodeId(nodeId, phySwitchName);
+        mergeVlanBindings(tx, physicalSwitchNodeId, phyPortName, vlanBindings, createParent);
+    }
+
+    private static void mergeVlanBindings(TypedWriteTransaction tx, NodeId physicalSwitchNodeId,
+                                         String phyPortName, List<VlanBindings> vlanBindings,
+                                         boolean createParent) {
+        HwvtepPhysicalPortAugmentation phyPortAug = (new HwvtepPhysicalPortAugmentationBuilder())
+                .setHwvtepNodeName(new HwvtepNodeName(phyPortName)).setVlanBindings(vlanBindings).build();
+        InstanceIdentifier<HwvtepPhysicalPortAugmentation> iid = HwvtepSouthboundUtils
+                .createPhysicalPortInstanceIdentifier(physicalSwitchNodeId, phyPortName);
+        if (createParent) {
+            InstanceIdentifier<TerminationPoint> iid2 =
+                    createPhysicalPortInstanceIdentifier(physicalSwitchNodeId, phyPortName);
+            TerminationPointBuilder tpBuilder = new TerminationPointBuilder().setTpId(new TpId(phyPortName))
+                    .addAugmentation(phyPortAug);
+            tx.merge(iid2, tpBuilder.build());
+        } else {
+            tx.merge(iid, phyPortAug);
+        }
+    }
+
+    public static InstanceIdentifier<TerminationPoint> createPhysicalPortInstanceIdentifier(
+            NodeId physicalSwitchNodeId, String phyPortName) {
+        return createInstanceIdentifier(physicalSwitchNodeId).child(TerminationPoint.class,
+                new TerminationPointKey(new TpId(phyPortName)));
+    }
+
+    public static InstanceIdentifier<Node> createInstanceIdentifier(NodeId nodeId) {
+        return InstanceIdentifier.create(NetworkTopology.class).child(Topology.class,
+                new TopologyKey(HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID)).child(Node.class, new NodeKey(nodeId));
     }
 
     /**
@@ -868,7 +947,7 @@ public class ElanL2GatewayUtils {
      *            the default vlan id
      * @return the listenable future
      */
-    public ListenableFuture<Void> deleteVlanBindingsFromL2GatewayDevice(NodeId nodeId, Devices hwVtepDevice,
+    public ListenableFuture<?> deleteVlanBindingsFromL2GatewayDevice(NodeId nodeId, Devices hwVtepDevice,
             Integer defaultVlanId) {
         if (hwVtepDevice == null || hwVtepDevice.getInterfaces() == null || hwVtepDevice.getInterfaces().isEmpty()) {
             String errMsg = "HwVtepDevice is null or interfaces are empty.";
@@ -877,9 +956,9 @@ public class ElanL2GatewayUtils {
         }
         NodeId physicalSwitchNodeId = HwvtepSouthboundUtils.createManagedNodeId(nodeId, hwVtepDevice.getDeviceName());
 
-        return txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+        return txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
             for (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712
-                    .l2gateway.attributes.devices.Interfaces deviceInterface : hwVtepDevice.getInterfaces()) {
+                .l2gateway.attributes.devices.Interfaces deviceInterface : hwVtepDevice.nonnullInterfaces().values()) {
                 String phyPortName = deviceInterface.getInterfaceName();
                 if (deviceInterface.getSegmentationIds() != null && !deviceInterface.getSegmentationIds().isEmpty()) {
                     for (Integer vlanId : deviceInterface.getSegmentationIds()) {
@@ -939,12 +1018,13 @@ public class ElanL2GatewayUtils {
         return interfaceInstanceIdentifierBuilder.build();
     }
 
+    @Nullable
     public static Interface getInterfaceFromConfigDS(InterfaceKey interfaceKey, DataBroker dataBroker) {
         InstanceIdentifier<Interface> interfaceId = getInterfaceIdentifier(interfaceKey);
         try {
             return SingleTransactionDataBroker
-                    .syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, interfaceId).orNull();
-        } catch (ReadFailedException e) {
+                    .syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, interfaceId).orElse(null);
+        } catch (InterruptedException | ExecutionException e) {
             // TODO remove this, and propagate ReadFailedException instead of re-throw RuntimeException
             LOG.error("getInterfaceFromConfigDS({}) failed", interfaceKey, e);
             throw new RuntimeException(e);
@@ -967,7 +1047,7 @@ public class ElanL2GatewayUtils {
         LOG.info("Deleting L2GatewayDevice [{}] UcastLocalMacs from elan [{}]", l2GatewayDevice.getHwvtepNodeId(),
                 elanName);
 
-        ElanInstance elan = elanInstanceCache.get(elanName).orNull();
+        ElanInstance elan = elanInstanceCache.get(elanName).orElse(null);
         if (elan == null) {
             LOG.error("Could not find Elan by name: {}", elanName);
             return;
@@ -1008,28 +1088,22 @@ public class ElanL2GatewayUtils {
                 return;
             }
             String psNodeId = globalNodeId + HwvtepHAUtil.PHYSICALSWITCH + psName;
-            tzonesoptional.get().getTransportZone().stream()
-                .filter(transportZone -> transportZone.getSubnets() != null)
-                .flatMap(transportZone -> transportZone.getSubnets().stream())
-                .filter(subnet -> subnet.getDeviceVteps() != null)
-                .flatMap(subnet -> subnet.getDeviceVteps().stream())
+            tzonesoptional.get().nonnullTransportZone().stream()
+                .filter(zone -> zone.getDeviceVteps() != null)
+                .flatMap(zone -> new ArrayList<>(zone.nonnullDeviceVteps().values()).stream())
                 .filter(deviceVteps -> Objects.equals(getPsName(deviceVteps), psName)) //get device with same ps name
                 .filter(deviceVteps -> !Objects.equals(psNodeId, deviceVteps.getNodeId())
                         || !Objects.equals(tunnelIp, deviceVteps.getIpAddress()))//node id or tunnel ip is changed
                 .forEach(deviceVteps -> deleteStaleL2gwTep(dataBroker, itmRpcService, deviceVteps));
-        } catch (ReadFailedException e) {
+        } catch (ExecutionException | InterruptedException e) {
             LOG.error("Failed delete stale tunnels for {}", globalNodeId);
         }
     }
 
-    private static Optional<TransportZones> readTransportZone(DataBroker dataBroker) throws ReadFailedException {
-        return new SingleTransactionDataBroker(dataBroker).syncReadOptional(LogicalDatastoreType.CONFIGURATION,
-                InstanceIdentifier.builder(TransportZones.class).build());
-    }
-
-    private static Optional<ElanInstances> readElanInstances(DataBroker dataBroker) throws ReadFailedException {
+    private static Optional<TransportZones> readTransportZone(DataBroker dataBroker) throws ExecutionException,
+            InterruptedException {
         return new SingleTransactionDataBroker(dataBroker).syncReadOptional(LogicalDatastoreType.CONFIGURATION,
-                InstanceIdentifier.builder(ElanInstances.class).build());
+            InstanceIdentifier.builder(TransportZones.class).build());
     }
 
     private static String getPsName(DeviceVteps deviceVteps) {
@@ -1037,8 +1111,8 @@ public class ElanL2GatewayUtils {
     }
 
     private static void deleteStaleL2gwTep(DataBroker dataBroker,
-                                           ItmRpcService itmRpcService,
-                                           DeviceVteps deviceVteps) {
+                                            ItmRpcService itmRpcService,
+                                            DeviceVteps deviceVteps) {
         String psName = HwvtepHAUtil.getPsName(HwvtepHAUtil.convertToInstanceIdentifier(deviceVteps.getNodeId()));
         String globalNodeId = HwvtepHAUtil.convertToGlobalNodeId(deviceVteps.getNodeId());
         try {
@@ -1048,29 +1122,56 @@ public class ElanL2GatewayUtils {
             if (!optionalElan.isPresent()) {
                 return;
             }
-            JdkFutures.addErrorLogging(
+            LoggingFutures.addErrorLogging(
                 new ManagedNewTransactionRunnerImpl(dataBroker).callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
-                    tx -> {
-                        optionalElan.get().getElanInstance().stream()
-                        .flatMap(elan -> elan.getExternalTeps().stream()
-                                .map(externalTep -> ElanL2GatewayMulticastUtils.buildExternalTepPath(
-                                        elan.getElanInstanceName(), externalTep.getTepIp())))
+                    tx -> optionalElan.get().nonnullElanInstance().values().stream()
+                        .flatMap(elan -> elan.nonnullExternalTeps().values().stream()
+                            .map(externalTep -> ElanL2GatewayMulticastUtils.buildExternalTepPath(
+                                elan.getElanInstanceName(), externalTep.getTepIp())))
                         .filter(externalTepIid -> Objects.equals(
-                                deviceVteps.getIpAddress(), externalTepIid.firstKeyOf(ExternalTeps.class).getTepIp()))
+                            deviceVteps.getIpAddress(), externalTepIid.firstKeyOf(ExternalTeps.class).getTepIp()))
                         .peek(externalTepIid -> LOG.info("Deleting stale external tep {}", externalTepIid))
-                        .forEach(externalTepIid -> tx.delete(externalTepIid));
-                    }), LOG, "Failed to delete stale external teps {}", deviceVteps);
+                        .forEach(tx::delete)), LOG,
+                "Failed to delete stale external teps {}", deviceVteps);
             Thread.sleep(10000);//TODO remove the sleep currently it waits for interfacemgr to finish the cleanup
-        } catch (ReadFailedException | InterruptedException e) {
+        } catch (ExecutionException | InterruptedException e) {
             LOG.error("Failed to delete stale l2gw tep {}", deviceVteps, e);
         }
     }
 
+    private static Optional<ElanInstances> readElanInstances(DataBroker dataBroker) throws ExecutionException,
+        InterruptedException {
+        return new SingleTransactionDataBroker(dataBroker).syncReadOptional(LogicalDatastoreType.CONFIGURATION,
+            InstanceIdentifier.builder(ElanInstances.class).build());
+    }
+    /*public static void createItmTunnels(IpAddress tunnelIp, DataBroker dataBroker) {
+        ManagedNewTransactionRunner txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
+        txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
+            InstanceIdentifier<L2GatewayIp> iid = InstanceIdentifier
+                .builder(L2GatewayIpList.class)
+                .child(L2GatewayIp.class, new L2GatewayIpKey(tunnelIp))
+                .build();
+            tx.put(iid, new L2GatewayIpBuilder().setIpAddress(tunnelIp).build());
+        });
+    }
+
+    public static FluentFuture<? extends CommitInfo> deleteItmTunnels(
+            IpAddress tunnelIp, DataBroker dataBroker) {
+        ManagedNewTransactionRunner txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
+        return txRunner.callWithNewWriteOnlyTransactionAndSubmit(LogicalDatastoreType.CONFIGURATION, tx -> {
+            InstanceIdentifier<L2GatewayIp> iid = InstanceIdentifier
+                .builder(L2GatewayIpList.class)
+                .child(L2GatewayIp.class, new L2GatewayIpKey(tunnelIp))
+                .build();
+            tx.delete(iid);
+        });
+    }*/
+
     public static String getNodeIdFromDpnId(BigInteger dpnId) {
         return MDSALUtil.NODE_PREFIX + MDSALUtil.SEPARATOR + dpnId.toString();
     }
 
-    public void scheduleAddDpnMacInExtDevices(String elanName, BigInteger dpId,
+    public void scheduleAddDpnMacInExtDevices(String elanName, Uint64 dpId,
             List<PhysAddress> staticMacAddresses) {
         ConcurrentMap<String, L2GatewayDevice> elanDevices = ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName);
         for (final L2GatewayDevice externalDevice : elanDevices.values()) {
@@ -1078,18 +1179,23 @@ public class ElanL2GatewayUtils {
         }
     }
 
-    public void scheduleAddDpnMacsInExtDevice(final String elanName, BigInteger dpId,
-            final List<PhysAddress> staticMacAddresses, final L2GatewayDevice externalDevice) {
+    public FluentFuture<? extends @NonNull CommitInfo> scheduleAddDpnMacsInExtDevice(final String elanName, Uint64 dpId,
+                                                                      final List<PhysAddress> staticMacAddresses,
+                                                                      final L2GatewayDevice externalDevice) {
         NodeId nodeId = new NodeId(externalDevice.getHwvtepNodeId());
         final IpAddress dpnTepIp = elanItmUtils.getSourceDpnTepIp(dpId, nodeId);
         LOG.trace("Dpn Tep IP: {} for dpnId: {} and nodeId: {}", dpnTepIp, dpId, nodeId);
         if (dpnTepIp == null) {
             LOG.error("could not install dpn mac in l2gw TEP IP not found for dpnId {} and nodeId {}", dpId, nodeId);
-            return;
+            return null;
         }
-
+        //TerminationPointKey tpKey = HwvtepSouthboundUtils.getTerminationPointKey(dpnTepIp
+        // .getIpv4Address().getValue());
+        //InstanceIdentifier<TerminationPoint> tpPath = HwvtepSouthboundUtils.createTerminationPointId(nodeId, tpKey);
         //TODO: to  be batched in genius
-        HwvtepUtils.installUcastMacs(broker, externalDevice.getHwvtepNodeId(), staticMacAddresses, elanName, dpnTepIp);
+        return HwvtepUtils.installUcastMacs(broker, externalDevice.getHwvtepNodeId(), staticMacAddresses,
+                elanName, dpnTepIp);
+
     }
 
     public void scheduleDeleteLogicalSwitch(NodeId hwvtepNodeId, String lsName) {
@@ -1122,7 +1228,7 @@ public class ElanL2GatewayUtils {
         }
     }
 
-    @Nonnull
+    @NonNull
     public Collection<DpnInterfaces> getElanDpns(String elanName) {
         Collection<DpnInterfaces> dpnInterfaces = elanInstanceDpnsCache.get(elanName);
         if (!dpnInterfaces.isEmpty()) {
@@ -1140,28 +1246,36 @@ public class ElanL2GatewayUtils {
      *            the l2gw device
      * @return the l2 gw device local macs
      */
-    public Collection<MacAddress> getL2GwDeviceLocalMacs(String elanName, L2GatewayDevice l2gwDevice) {
+    public List<MacAddress> getL2GwDeviceLocalMacs(String elanName, L2GatewayDevice l2gwDevice) {
+        Set<MacAddress> macs = new HashSet<>();
         if (l2gwDevice == null) {
             return Collections.emptyList();
         }
         Collection<LocalUcastMacs> lstUcastLocalMacs = l2gwDevice.getUcastLocalMacs();
-        Set<MacAddress> macs = new HashSet<>();
-        if (!lstUcastLocalMacs.isEmpty()) {
+        if (lstUcastLocalMacs != null && !lstUcastLocalMacs.isEmpty()) {
             macs.addAll(lstUcastLocalMacs.stream().filter(Objects::nonNull)
-                    .map(mac -> new MacAddress(mac.getMacEntryKey().getValue().toLowerCase()))
+                    .map(mac -> new MacAddress(mac.getMacEntryKey().getValue().toLowerCase(Locale.getDefault())))
                     .collect(Collectors.toList()));
         }
-        Optional<Node> configNode = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION,
+        Optional<Node> configNode = null;
+        try {
+            configNode = SingleTransactionDataBroker.syncReadOptional(broker, LogicalDatastoreType.CONFIGURATION,
                 HwvtepSouthboundUtils.createInstanceIdentifier(new NodeId(l2gwDevice.getHwvtepNodeId())));
+        } catch (ExecutionException | InterruptedException e) {
+            LOG.error("getL2GwDeviceLocalMacs: Exception while reading l2gwDevice DS for the elan {}, l2gwDevice {}",
+                elanName, l2gwDevice, e);
+            return Collections.emptyList();
+        }
+
         if (configNode.isPresent()) {
             HwvtepGlobalAugmentation augmentation = configNode.get().augmentation(HwvtepGlobalAugmentation.class);
             if (augmentation != null && augmentation.getLocalUcastMacs() != null) {
-                macs.addAll(augmentation.getLocalUcastMacs().stream()
+                macs.addAll(augmentation.nonnullLocalUcastMacs().values().stream()
                         .filter(mac -> getLogicalSwitchName(mac).equals(elanName))
-                        .map(HwvtepMacTableGenericAttributes::getMacEntryKey)
+                        .map(mac -> mac.getMacEntryKey())
                         .collect(Collectors.toSet()));
             }
         }
-        return macs;
+        return new ArrayList<>(macs);
     }
 }