Bulk merge of l2gw changes
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / internal / ElanInterfaceManager.java
index 80c981833d96cbaa2f91ca021e76ea60bfade092..e76b4f763c9b877672f7da401dc3318ed6fe69fb 100644 (file)
@@ -8,44 +8,34 @@
 package org.opendaylight.netvirt.elan.internal;
 
 import static java.util.Collections.emptyList;
-import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
-import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
-import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
 import static org.opendaylight.infrautils.utils.concurrent.LoggingFutures.addErrorLogging;
+import static org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION;
+import static org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL;
 import static org.opendaylight.netvirt.elan.utils.ElanUtils.isVxlanNetworkOrVxlanSegment;
 
-import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
+import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
+import java.util.Optional;
 import java.util.Queue;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.locks.ReentrantLock;
-import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.apache.commons.lang3.StringUtils;
-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.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
-import org.opendaylight.genius.infra.Datastore.Configuration;
-import org.opendaylight.genius.infra.Datastore.Operational;
-import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
-import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
-import org.opendaylight.genius.infra.TransactionAdapter;
-import org.opendaylight.genius.infra.TypedReadWriteTransaction;
-import org.opendaylight.genius.infra.TypedWriteTransaction;
 import org.opendaylight.genius.interfacemanager.globals.InterfaceInfo;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
 import org.opendaylight.genius.itm.globals.ITMConstants;
@@ -71,8 +61,17 @@ import org.opendaylight.genius.mdsalutil.matches.MatchTunnelId;
 import org.opendaylight.genius.utils.JvmGlobalLocks;
 import org.opendaylight.genius.utils.ServiceIndex;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
+import org.opendaylight.infrautils.utils.concurrent.Executors;
 import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
 import org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.Acquired;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.util.Datastore.Configuration;
+import org.opendaylight.mdsal.binding.util.Datastore.Operational;
+import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner;
+import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction;
+import org.opendaylight.mdsal.binding.util.TypedWriteTransaction;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.cache.ElanInterfaceCache;
 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
@@ -90,6 +89,7 @@ import org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils;
 import org.opendaylight.netvirt.neutronvpn.interfaces.INeutronVpnManager;
 import org.opendaylight.serviceutils.srm.RecoverableListener;
 import org.opendaylight.serviceutils.srm.ServiceRecoveryRegistry;
+import org.opendaylight.serviceutils.tools.listener.AbstractAsyncDataTreeChangeListener;
 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.interfaces.rev140508.interfaces.state.Interface;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
@@ -99,6 +99,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.Fl
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServices;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.external.tunnel.list.ExternalTunnel;
@@ -118,9 +119,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.Elan
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanForwardingTables;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInterfaces;
 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._interface.forwarding.entries.ElanInterfaceMacBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan._interface.forwarding.entries.ElanInterfaceMacKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.ElanDpnInterfacesList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.ElanDpnInterfacesListKey;
 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.dpn.interfaces.elan.dpn.interfaces.list.DpnInterfacesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.elan.dpn.interfaces.list.DpnInterfacesKey;
@@ -130,6 +130,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstanceBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterface;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.elan._interface.StaticMacEntries;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.elan._interface.StaticMacEntriesKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.state.Elan;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.state.ElanBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.state.ElanKey;
@@ -153,7 +154,7 @@ import org.slf4j.LoggerFactory;
  * @see org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterface
  */
 @Singleton
-public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanInterface, ElanInterfaceManager>
+public class ElanInterfaceManager extends AbstractAsyncDataTreeChangeListener<ElanInterface>
         implements RecoverableListener {
     private static final Logger LOG = LoggerFactory.getLogger(ElanInterfaceManager.class);
     private static final Logger EVENT_LOGGER = LoggerFactory.getLogger("NetvirtEventLogger");
@@ -194,7 +195,9 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                                 final ElanServiceRecoveryHandler elanServiceRecoveryHandler,
                                 ElanGroupCache elanGroupCache,
                                 final ServiceRecoveryRegistry serviceRecoveryRegistry) {
-        super(ElanInterface.class, ElanInterfaceManager.class);
+        super(dataBroker, LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(ElanInterfaces.class)
+                .child(ElanInterface.class),
+                Executors.newListeningSingleThreadExecutor("ElanInterfaceManager", LOG));
         this.broker = dataBroker;
         this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
         this.idManager = managerService;
@@ -214,24 +217,31 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         serviceRecoveryRegistry.addRecoverableListener(elanServiceRecoveryHandler.buildServiceRegistryKey(), this);
     }
 
-    @Override
-    @PostConstruct
     public void init() {
-        registerListener();
+        LOG.info("{} registered", getClass().getSimpleName());
     }
 
     @Override
     public void registerListener() {
-        registerListener(LogicalDatastoreType.CONFIGURATION, broker);
+        super.register();
+        LOG.info("Registering ElanInterfaceManager");
+    }
+
+    @Override
+    public void deregisterListener() {
+        super.close();
+        LOG.info("Deregistering ElanInterfaceManager");
     }
 
     @Override
-    protected InstanceIdentifier<ElanInterface> getWildCardPath() {
-        return InstanceIdentifier.create(ElanInterfaces.class).child(ElanInterface.class);
+    @PreDestroy
+    public void close() {
+        super.close();
+        Executors.shutdownAndAwaitTermination(getExecutorService());
     }
 
     @Override
-    protected void remove(InstanceIdentifier<ElanInterface> identifier, ElanInterface del) {
+    public void remove(InstanceIdentifier<ElanInterface> identifier, ElanInterface del) {
         String interfaceName = del.getName();
         String elanInstanceName = del.getElanInstanceName();
         EVENT_LOGGER.debug("ELAN-Interface, REMOVE {} Instance {}", interfaceName, elanInstanceName);
@@ -242,7 +252,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                 unProcessedElanInterfaces.remove(elanInstanceName);
             }
         }
-        ElanInstance elanInfo = elanInstanceCache.get(elanInstanceName).orNull();
+        ElanInstance elanInfo = elanInstanceCache.get(elanInstanceName).orElse(null);
         /*
          * Handling in case the elan instance is deleted.If the Elan instance is
          * deleted, there is no need to explicitly delete the elan interfaces
@@ -268,13 +278,13 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
     }
 
     @SuppressWarnings("checkstyle:ForbidCertainMethod")
-    public List<ListenableFuture<Void>> removeElanInterface(ElanInstance elanInfo, String interfaceName,
+    public List<ListenableFuture<?>> removeElanInterface(ElanInstance elanInfo, String interfaceName,
             InterfaceInfo interfaceInfo) {
         String elanName = elanInfo.getElanInstanceName();
         EVENT_LOGGER.debug("ELAN-InterfaceState, REMOVE {} Instance {}", interfaceName, elanName);
         Uint32 elanTag = elanInfo.getElanTag();
         // We use two transaction so we don't suffer on multiple shards (interfaces and flows)
-        List<ListenableFuture<Void>> futures = new ArrayList<>();
+        List<ListenableFuture<?>> futures = new ArrayList<>();
         RemoveElanInterfaceHolder holder = new RemoveElanInterfaceHolder();
         futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, interfaceTx -> {
             Elan elanState = removeElanStateForInterface(elanInfo, interfaceName, interfaceTx);
@@ -404,21 +414,22 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
     }
 
     private void deleteElanInterfaceFromConfigDS(String interfaceName, TypedReadWriteTransaction<Configuration> tx)
-            throws ReadFailedException {
+            throws ExecutionException, InterruptedException {
         // removing the ElanInterface from the config data_store if interface is
         // not present in Interface config DS
-        if (interfaceManager.getInterfaceInfoFromConfigDataStore(TransactionAdapter.toReadWriteTransaction(tx),
-            interfaceName) == null
-                && elanInterfaceCache.get(interfaceName).isPresent()) {
+        InstanceIdentifier<ElanInterface> elanInterfaceId = ElanUtils
+                .getElanInterfaceConfigurationDataPathId(interfaceName);
+        FluentFuture<Optional<ElanInterface>> interfaceOptional = tx.read(elanInterfaceId);
+        if (!interfaceOptional.get().isPresent() && elanInterfaceCache.get(interfaceName).isPresent()) {
             tx.delete(ElanUtils.getElanInterfaceConfigurationDataPathId(interfaceName));
         }
     }
 
-    List<ListenableFuture<Void>> removeEntriesForElanInterface(ElanInstance elanInfo, InterfaceInfo
+    List<ListenableFuture<?>> removeEntriesForElanInterface(ElanInstance elanInfo, InterfaceInfo
             interfaceInfo, String interfaceName, boolean isLastElanInterface) {
         String elanName = elanInfo.getElanInstanceName();
         EVENT_LOGGER.debug("ELAN-InterfaceEntries, REMOVE {} Instance {}", interfaceName, elanName);
-        List<ListenableFuture<Void>> futures = new ArrayList<>();
+        List<ListenableFuture<?>> futures = new ArrayList<>();
         futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, flowTx -> {
             futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, interfaceTx -> {
                 InstanceIdentifier<ElanInterfaceMac> elanInterfaceId = ElanUtils
@@ -427,10 +438,11 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                 LOG.debug("Removing the Interface:{} from elan:{}", interfaceName, elanName);
                 if (interfaceInfo != null) {
                     if (existingElanInterfaceMac.isPresent()) {
-                        List<MacEntry> existingMacEntries = existingElanInterfaceMac.get().getMacEntry();
+                        Map<MacEntryKey, MacEntry> existingMacEntries =
+                            existingElanInterfaceMac.get().nonnullMacEntry();
                         if (existingMacEntries != null) {
                             List<PhysAddress> macAddresses = new ArrayList<>();
-                            for (MacEntry macEntry : existingMacEntries) {
+                            for (MacEntry macEntry : existingMacEntries.values()) {
                                 PhysAddress macAddress = macEntry.getMacAddress();
                                 LOG.debug("removing the  mac-entry:{} present on elanInterface:{}",
                                         macAddress.getValue(), interfaceName);
@@ -457,9 +469,9 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                 } else if (existingElanInterfaceMac.isPresent()) {
                     // Interface does not exist in ConfigDS, so lets remove everything
                     // about that interface related to Elan
-                    List<MacEntry> macEntries = existingElanInterfaceMac.get().getMacEntry();
+                    Map<MacEntryKey, MacEntry> macEntries = existingElanInterfaceMac.get().nonnullMacEntry();
                     if (macEntries != null) {
-                        for (MacEntry macEntry : macEntries) {
+                        for (MacEntry macEntry : macEntries.values()) {
                             PhysAddress macAddress = macEntry.getMacAddress();
                             if (elanUtils.getMacEntryForElanInstance(elanName, macAddress).isPresent()) {
                                 interfaceTx.delete(ElanUtils.getMacEntryOperationalDataPath(elanName, macAddress));
@@ -519,7 +531,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                         if (macs == null || macs.getMacEntry() == null) {
                             continue;
                         }
-                        for (MacEntry mac : macs.getMacEntry()) {
+                        for (MacEntry mac : new ArrayList<MacEntry>(macs.nonnullMacEntry().values())) {
                             removeTheMacFlowInTheDPN(dpId, elanTag, mac, confTx);
                             removeEtreeMacFlowInTheDPN(dpId, elanTag, mac, confTx);
                         }
@@ -564,15 +576,17 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
     * */
     @SuppressWarnings("checkstyle:ForbidCertainMethod")
     @Override
-    protected void update(InstanceIdentifier<ElanInterface> identifier, ElanInterface original, ElanInterface update) {
+    public void update(InstanceIdentifier<ElanInterface> identifier, ElanInterface original, ElanInterface update) {
         // updating the static-Mac Entries for the existing elanInterface
         String elanName = update.getElanInstanceName();
         String interfaceName = update.getName();
         LOG.info("Update static mac entries for elan interface {} in elan instance {}", interfaceName, elanName);
         EVENT_LOGGER.debug("ELAN-Interface, UPDATE {} Instance {}", original.getName(), elanName);
 
-        List<StaticMacEntries> originalStaticMacEntries = original.getStaticMacEntries();
-        List<StaticMacEntries> updatedStaticMacEntries = update.getStaticMacEntries();
+        List<StaticMacEntries> originalStaticMacEntries = new ArrayList<StaticMacEntries>(original
+                .nonnullStaticMacEntries().values());
+        List<StaticMacEntries> updatedStaticMacEntries = new ArrayList<StaticMacEntries>(update
+                .nonnullStaticMacEntries().values());
         List<StaticMacEntries> deletedEntries = ElanUtils.diffOf(originalStaticMacEntries, updatedStaticMacEntries);
         List<StaticMacEntries> updatedEntries = ElanUtils.diffOf(updatedStaticMacEntries, originalStaticMacEntries);
 
@@ -604,7 +618,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
     }
 
     @Override
-    protected void add(InstanceIdentifier<ElanInterface> identifier, ElanInterface elanInterfaceAdded) {
+    public void add(InstanceIdentifier<ElanInterface> identifier, ElanInterface elanInterfaceAdded) {
         LOG.info("Init for ELAN interface Add {}", elanInterfaceAdded);
         addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, operTx -> {
             String elanInstanceName = elanInterfaceAdded.getElanInstanceName();
@@ -615,7 +629,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                 LOG.info("Interface {} is removed from Interface Oper DS due to port down ", interfaceName);
                 return;
             }
-            ElanInstance elanInstance = elanInstanceCache.get(elanInstanceName).orNull();
+            ElanInstance elanInstance = elanInstanceCache.get(elanInstanceName).orElse(null);
 
             if (elanInstance == null) {
                 // Add the ElanInstance in the Configuration data-store
@@ -639,6 +653,8 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                 if (!elanInterfaces.contains(elanInterfaceAdded)) {
                     elanInterfaces.add(elanInterfaceAdded);
                 }
+                LOG.error("ELAN tag for instance {} is not created. Adding it to unprocessed list."
+                        + " Recreate the network if this message is seen multiple times", elanInstanceName);
                 unProcessedElanInterfaces.put(elanInstanceName, elanInterfaces);
                 return;
             }
@@ -648,9 +664,9 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         }), LOG, "Error processing added ELAN interface");
     }
 
-    List<ListenableFuture<Void>> handleunprocessedElanInterfaces(ElanInstance elanInstance) {
+    List<ListenableFuture<?>> handleunprocessedElanInterfaces(ElanInstance elanInstance) {
         LOG.trace("Handling unprocessed elan interfaces for elan instance {}", elanInstance.getElanInstanceName());
-        List<ListenableFuture<Void>> futures = new ArrayList<>();
+        List<ListenableFuture<?>> futures = new ArrayList<>();
         Queue<ElanInterface> elanInterfaces = unProcessedElanInterfaces.get(elanInstance.getElanInstanceName());
         if (elanInterfaces == null || elanInterfaces.isEmpty()) {
             return futures;
@@ -672,33 +688,38 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                 .getElanDpnInterfacesList(elanInstance.getElanInstanceName());
         List<DpnInterfaces> dpnInterfaceLists = null;
         if (elanDpnInterfacesList != null) {
-            dpnInterfaceLists = elanDpnInterfacesList.getDpnInterfaces();
+            dpnInterfaceLists = new ArrayList<DpnInterfaces>(elanDpnInterfacesList.nonnullDpnInterfaces().values());
         }
-        if (dpnInterfaceLists == null) {
-            dpnInterfaceLists = new ArrayList<>();
+        if (dpnInterfaceLists != null && !dpnInterfaceLists.isEmpty()) {
+            Uint64 dstDpId = interfaceInfo.getDpId();
+            processRemoteDmacFlowForInterface(dstDpId, elanInstance, dpnInterfaceLists, writeFlowGroupTx);
         }
+    }
+
+    private void processRemoteDmacFlowForInterface(Uint64 dstDpId, ElanInstance elanInstance,
+             List<DpnInterfaces> dpnInterfaceLists, TypedWriteTransaction<Configuration> writeFlowGroupTx) {
         for (DpnInterfaces dpnInterfaces : dpnInterfaceLists) {
-            Uint64 dstDpId = interfaceInfo.getDpId();
             if (Objects.equals(dpnInterfaces.getDpId(), dstDpId)) {
                 continue;
             }
             List<String> remoteElanInterfaces = dpnInterfaces.getInterfaces();
+            if (remoteElanInterfaces == null || remoteElanInterfaces.isEmpty()) {
+                continue;
+            }
             for (String remoteIf : remoteElanInterfaces) {
                 ElanInterfaceMac elanIfMac = elanUtils.getElanInterfaceMacByInterfaceName(remoteIf);
                 InterfaceInfo remoteInterface = interfaceManager.getInterfaceInfo(remoteIf);
                 if (elanIfMac == null || remoteInterface == null) {
                     continue;
                 }
-                List<MacEntry> remoteMacEntries = elanIfMac.getMacEntry();
-                if (remoteMacEntries != null) {
-                    for (MacEntry macEntry : remoteMacEntries) {
-                        String macAddress = macEntry.getMacAddress().getValue();
-                        LOG.info("Programming remote dmac {} on the newly added DPN {} for elan {}", macAddress,
-                                dstDpId, elanInstance.getElanInstanceName());
-                        elanUtils.setupRemoteDmacFlow(dstDpId, remoteInterface.getDpId(),
-                                remoteInterface.getInterfaceTag(), elanInstance.getElanTag(), macAddress,
-                                elanInstance.getElanInstanceName(), writeFlowGroupTx, remoteIf, elanInstance);
-                    }
+                Map<MacEntryKey, MacEntry> remoteMacEntries = elanIfMac.nonnullMacEntry();
+                for (MacEntry macEntry : remoteMacEntries.values()) {
+                    String macAddress = macEntry.getMacAddress().getValue();
+                    LOG.info("Programming remote dmac {} on the newly added DPN {} for elan {}", macAddress,
+                            dstDpId, elanInstance.getElanInstanceName());
+                    elanUtils.setupRemoteDmacFlow(dstDpId, remoteInterface.getDpId(),
+                            remoteInterface.getInterfaceTag(), elanInstance.getElanTag(), macAddress,
+                            elanInstance.getElanInstanceName(), writeFlowGroupTx, remoteIf, elanInstance);
                 }
             }
         }
@@ -711,7 +732,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
     }
 
     @SuppressWarnings("checkstyle:ForbidCertainMethod")
-    List<ListenableFuture<Void>> addElanInterface(ElanInterface elanInterface,
+    List<ListenableFuture<?>> addElanInterface(ElanInterface elanInterface,
             InterfaceInfo interfaceInfo, ElanInstance elanInstance) {
         Preconditions.checkNotNull(elanInstance, "elanInstance cannot be null");
         Preconditions.checkNotNull(interfaceInfo, "interfaceInfo cannot be null");
@@ -722,7 +743,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         LOG.trace("Adding elan interface: interface name {} , instance name {}", interfaceName, elanInstanceName);
         EVENT_LOGGER.debug("ELAN-InterfaceState, ADD {} Instance {}", interfaceName, elanInstanceName);
 
-        List<ListenableFuture<Void>> futures = new ArrayList<>();
+        List<ListenableFuture<?>> futures = new ArrayList<>();
         AddElanInterfaceHolder holder = new AddElanInterfaceHolder();
         futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, operTx -> {
             Elan elanInfo = ElanUtils.getElanByName(broker, elanInstanceName);
@@ -801,8 +822,6 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
             // terminating service table flow entry
             // call bindservice of interfacemanager to create ingress table flow
             // enty.
-            // Add interface to the ElanInterfaceForwardingEntires Container
-            createElanInterfaceTablesList(interfaceName, operTx);
         }));
         futures.forEach(ElanUtils::waitForTransactionToComplete);
         futures.add(
@@ -822,8 +841,8 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
             // ELAN's 1st ElanInterface added to this DPN
             LOG.debug("Adding dpn into operational dpn list {}", holder.dpId);
             futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, operTx -> {
-                operTx.put(ElanUtils.getElanDpnInterfaceOperationalDataPath(elanInstanceName, holder.dpId),
-                        holder.dpnInterfaces, CREATE_MISSING_PARENTS);
+                operTx.mergeParentStructurePut(ElanUtils.getElanDpnInterfaceOperationalDataPath(elanInstanceName,
+                        holder.dpId), holder.dpnInterfaces);
             }));
         } else {
             LOG.debug("Updated dpn into operational dpn list {}", holder.dpId);
@@ -835,23 +854,22 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
     }
 
     @SuppressWarnings("checkstyle:ForbidCertainMethod")
-    List<ListenableFuture<Void>> setupEntriesForElanInterface(ElanInstance elanInstance,
+    List<ListenableFuture<?>> setupEntriesForElanInterface(ElanInstance elanInstance,
             ElanInterface elanInterface, InterfaceInfo interfaceInfo, boolean isFirstInterfaceInDpn) {
         String elanInstanceName = elanInstance.getElanInstanceName();
         String interfaceName = elanInterface.getName();
-        List<ListenableFuture<Void>> futures = new ArrayList<>();
+        List<ListenableFuture<?>> futures = new ArrayList<>();
         Uint64 dpId = interfaceInfo.getDpId();
         boolean isInterfaceOperational = isOperational(interfaceInfo);
         futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> {
             futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, operTx -> {
                 installEntriesForElanInterface(elanInstance, elanInterface, interfaceInfo,
                     isFirstInterfaceInDpn, confTx);
-
-                List<StaticMacEntries> staticMacEntriesList = elanInterface.getStaticMacEntries();
+                Map<StaticMacEntriesKey, StaticMacEntries> staticMacEntriesMap =
+                    elanInterface.nonnullStaticMacEntries();
                 List<PhysAddress> staticMacAddresses = Lists.newArrayList();
-
-                if (ElanUtils.isNotEmpty(staticMacEntriesList)) {
-                    for (StaticMacEntries staticMacEntry : staticMacEntriesList) {
+                if (ElanUtils.isNotEmpty(staticMacEntriesMap.values())) {
+                    for (StaticMacEntries staticMacEntry : staticMacEntriesMap.values()) {
                         InstanceIdentifier<MacEntry> macId = getMacEntryOperationalDataPath(elanInstanceName,
                             staticMacEntry.getMacAddress());
                         Optional<MacEntry> existingMacEntry = ElanUtils.read(broker,
@@ -883,7 +901,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                     if (isInterfaceOperational) {
                         // Add MAC in TOR's remote MACs via OVSDB. Outside of the loop
                         // on purpose.
-                        for (StaticMacEntries staticMacEntry : staticMacEntriesList) {
+                        for (StaticMacEntries staticMacEntry : staticMacEntriesMap.values()) {
                             staticMacAddresses.add(staticMacEntry.getMacAddress());
                         }
                         elanL2GatewayUtils.scheduleAddDpnMacInExtDevices(elanInstance.getElanInstanceName(), dpId,
@@ -921,7 +939,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         MacEntry macEntry = new MacEntryBuilder().setMacAddress(physAddress).setInterface(interfaceName)
                 .withKey(new MacEntryKey(physAddress)).build();
         elanForwardingEntriesHandler.deleteElanInterfaceForwardingEntries(
-                elanInstanceCache.get(elanInstanceName).orNull(), interfaceInfo, macEntry);
+                elanInstanceCache.get(elanInstanceName).orElse(null), interfaceInfo, macEntry);
     }
 
     private boolean checkIfFirstInterface(String elanInterface, String elanInstanceName,
@@ -1055,11 +1073,16 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         mdsalManager.addFlow(writeFlowGroupTx, interfaceInfo.getDpId(), flow);
         LOG.trace("Filter equals table(55) flow entry created on dpn: {} for interface port: {}",
                 interfaceInfo.getDpId(), interfaceInfo.getPortName());
+        Map<InstructionKey, Instruction> customInstructionsMap = new HashMap<InstructionKey, Instruction>();
+        int instructionKey = 0;
+        for (Instruction instructionObj : MDSALUtil.buildInstructionsDrop()) {
+            customInstructionsMap.put(new InstructionKey(++instructionKey), instructionObj);
+        }
 
         Flow flowEntry = MDSALUtil.buildFlowNew(NwConstants.ELAN_FILTER_EQUALS_TABLE,
                 getFlowRef(NwConstants.ELAN_FILTER_EQUALS_TABLE, ifTag, "drop"), 12, elanInfo.getElanInstanceName(), 0,
                 0, Uint64.valueOf(ElanConstants.COOKIE_ELAN_FILTER_EQUALS.toJava().add(BigInteger.valueOf(ifTag))),
-                getMatchesForFilterEqualsLPortTag(ifTag), MDSALUtil.buildInstructionsDrop());
+                getMatchesForFilterEqualsLPortTag(ifTag), customInstructionsMap);
 
         mdsalManager.addFlow(writeFlowGroupTx, interfaceInfo.getDpId(), flowEntry);
         LOG.trace("Filter equals table(55) drop flow entry created on dpn: {} for interface port: {}",
@@ -1121,15 +1144,15 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
     }
 
     // Install DMAC entry on dst DPN
-    public List<ListenableFuture<Void>> installDMacAddressTables(ElanInstance elanInfo, InterfaceInfo interfaceInfo,
+    public List<ListenableFuture<?>> installDMacAddressTables(ElanInstance elanInfo, InterfaceInfo interfaceInfo,
             Uint64 dstDpId) {
         String interfaceName = interfaceInfo.getInterfaceName();
         ElanInterfaceMac elanInterfaceMac = elanUtils.getElanInterfaceMacByInterfaceName(interfaceName);
         if (elanInterfaceMac != null && elanInterfaceMac.getMacEntry() != null) {
-            List<MacEntry> macEntries = elanInterfaceMac.getMacEntry();
+            Map<MacEntryKey, MacEntry> macEntries = elanInterfaceMac.nonnullMacEntry();
             return Collections.singletonList(ElanUtils.waitForTransactionToComplete(
                 txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
-                    for (MacEntry macEntry : macEntries) {
+                    for (MacEntry macEntry : macEntries.values()) {
                         String macAddress = macEntry.getMacAddress().getValue();
                         LOG.info("Installing remote dmac for mac address {} and interface {}", macAddress,
                             interfaceName);
@@ -1452,7 +1475,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         Optional<BoundServices> existingElanService = ElanUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
                 bindServiceId);
         if (!existingElanService.isPresent()) {
-            tx.put(bindServiceId, serviceInfo, CREATE_MISSING_PARENTS);
+            tx.mergeParentStructurePut(bindServiceId, serviceInfo);
             LOG.trace("Done binding elan service for elan: {} for interface: {}", elanInstanceName, interfaceName);
         }
     }
@@ -1514,8 +1537,8 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
             List<String> interfaceNames, TypedWriteTransaction<Operational> tx) {
         DpnInterfaces dpnInterface = new DpnInterfacesBuilder().setDpId(dpId).setInterfaces(interfaceNames)
                 .withKey(new DpnInterfacesKey(dpId)).build();
-        tx.put(ElanUtils.getElanDpnInterfaceOperationalDataPath(elanInstanceName, dpId), dpnInterface,
-                CREATE_MISSING_PARENTS);
+        tx.mergeParentStructurePut(ElanUtils
+                .getElanDpnInterfaceOperationalDataPath(elanInstanceName, dpId), dpnInterface);
         LOG.trace("Updated operational dpn interfaces for elan: {} with interfaces: {}", elanInstanceName,
                 interfaceNames);
         return dpnInterface;
@@ -1548,22 +1571,6 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         return dpnInterface;
     }
 
-    private static void createElanInterfaceTablesList(String interfaceName, TypedReadWriteTransaction<Operational> tx)
-            throws ExecutionException, InterruptedException {
-        InstanceIdentifier<ElanInterfaceMac> elanInterfaceMacTables = ElanUtils
-                .getElanInterfaceMacEntriesOperationalDataPath(interfaceName);
-        Optional<ElanInterfaceMac> interfaceMacTables = tx.read(elanInterfaceMacTables).get();
-        // Adding new Elan Interface Port to the operational DataStore without
-        // Static-Mac Entries..
-        if (!interfaceMacTables.isPresent()) {
-            ElanInterfaceMac elanInterfaceMacTable = new ElanInterfaceMacBuilder().setElanInterface(interfaceName)
-                    .withKey(new ElanInterfaceMacKey(interfaceName)).build();
-            tx.put(ElanUtils.getElanInterfaceMacEntriesOperationalDataPath(interfaceName), elanInterfaceMacTable,
-                    CREATE_MISSING_PARENTS);
-            LOG.trace("Created interface MAC table for interface: {}", interfaceName);
-        }
-    }
-
     private static void createElanStateList(String elanInstanceName, String interfaceName,
             TypedReadWriteTransaction<Operational> tx) throws ExecutionException, InterruptedException {
         InstanceIdentifier<Elan> elanInstance = ElanUtils.getElanInstanceOperationalDataPath(elanInstanceName);
@@ -1580,7 +1587,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
 
             Elan elanState = new ElanBuilder().setName(elanInstanceName).setElanInterfaces(interfaceLists)
                     .withKey(new ElanKey(elanInstanceName)).build();
-            tx.put(ElanUtils.getElanInstanceOperationalDataPath(elanInstanceName), elanState, CREATE_MISSING_PARENTS);
+            tx.mergeParentStructurePut(ElanUtils.getElanInstanceOperationalDataPath(elanInstanceName), elanState);
             LOG.trace("Updated operational elan state for elan: {} with interfaces: {}", elanInstanceName,
                     interfaceLists);
         }
@@ -1598,11 +1605,12 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         if (dpnInterfaceLists == null) {
             return;
         }
-        List<ElanDpnInterfacesList> elanDpnIf = dpnInterfaceLists.nonnullElanDpnInterfacesList();
-        for (ElanDpnInterfacesList elanDpns : elanDpnIf) {
+        Map<ElanDpnInterfacesListKey, ElanDpnInterfacesList> elanDpnIf = dpnInterfaceLists
+                .nonnullElanDpnInterfacesList();
+        for (ElanDpnInterfacesList elanDpns : elanDpnIf.values()) {
             int cnt = 0;
             String elanName = elanDpns.getElanInstanceName();
-            ElanInstance elanInfo = elanInstanceCache.get(elanName).orNull();
+            ElanInstance elanInfo = elanInstanceCache.get(elanName).orElse(null);
             if (elanInfo == null) {
                 LOG.warn("ELAN Info is null for elanName {} that does exist in elanDpnInterfaceList, "
                         + "skipping this ELAN for tunnel handling", elanName);
@@ -1612,12 +1620,12 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                 LOG.debug("Ignoring internal tunnel state event for Flat/Vlan elan {}", elanName);
                 continue;
             }
-            List<DpnInterfaces> dpnInterfaces = elanDpns.getDpnInterfaces();
+            Map<DpnInterfacesKey, DpnInterfaces> dpnInterfaces = elanDpns.nonnullDpnInterfaces();
             if (dpnInterfaces == null) {
                 continue;
             }
             DpnInterfaces dstDpnIf = null;
-            for (DpnInterfaces dpnIf : dpnInterfaces) {
+            for (DpnInterfaces dpnIf : dpnInterfaces.values()) {
                 Uint64 dpnIfDpId = dpnIf.getDpId();
                 if (Objects.equals(dpnIfDpId, srcDpId)) {
                     cnt++;
@@ -1690,10 +1698,11 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         if (dpnInterfaceLists == null) {
             return;
         }
-        List<ElanDpnInterfacesList> elanDpnIf = dpnInterfaceLists.nonnullElanDpnInterfacesList();
-        for (ElanDpnInterfacesList elanDpns : elanDpnIf) {
+        Map<ElanDpnInterfacesListKey, ElanDpnInterfacesList> elanDpnIf
+                = dpnInterfaceLists.nonnullElanDpnInterfacesList();
+        for (ElanDpnInterfacesList elanDpns : elanDpnIf.values()) {
             String elanName = elanDpns.getElanInstanceName();
-            ElanInstance elanInfo = elanInstanceCache.get(elanName).orNull();
+            ElanInstance elanInfo = elanInstanceCache.get(elanName).orElse(null);
 
             DpnInterfaces dpnInterfaces = elanUtils.getElanInterfaceInfoByElanDpn(elanName, dpId);
             if (elanInfo == null || dpnInterfaces == null || dpnInterfaces.getInterfaces() == null
@@ -1754,6 +1763,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                 dpnTepIp);
         LOG.debug("phyLocAlreadyExists = {} for locator [{}] in remote mcast entry for elan [{}], nodeId [{}]",
                 phyLocAlreadyExists, dpnTepIp.stringValue(), elanName, externalNodeId.getValue());
+        /*
         List<PhysAddress> staticMacs = elanL2GatewayUtils.getElanDpnMacsFromInterfaces(lstElanInterfaceNames);
 
         if (phyLocAlreadyExists) {
@@ -1762,6 +1772,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         }
         elanL2GatewayMulticastUtils.scheduleMcastMacUpdateJob(elanName, elanL2GwDevice);
         elanL2GatewayUtils.scheduleAddDpnMacsInExtDevice(elanName, dpnId, staticMacs, elanL2GwDevice);
+        */
     }
 
     /**
@@ -1804,11 +1815,6 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         return mkMatches;
     }
 
-    @Override
-    protected ElanInterfaceManager getDataTreeChangeListener() {
-        return this;
-    }
-
     public void handleExternalInterfaceEvent(ElanInstance elanInstance, DpnInterfaces dpnInterfaces,
                                              Uint64 dpId) {
         LOG.debug("setting up remote BC group for elan {}", elanInstance.getPhysicalNetworkName());