Elan Junit Testcases
[netvirt.git] / vpnservice / elanmanager / elanmanager-impl / src / main / java / org / opendaylight / netvirt / elan / utils / ElanUtils.java
old mode 100644 (file)
new mode 100755 (executable)
index 7599108..ad0ce12
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -8,23 +8,36 @@
 package org.opendaylight.netvirt.elan.utils;
 
 import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.Lists;
+import com.google.common.primitives.Ints;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
+
 import java.math.BigInteger;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+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.binding.api.ReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
@@ -33,35 +46,45 @@ import org.opendaylight.genius.interfacemanager.globals.InterfaceServiceUtil;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
 import org.opendaylight.genius.itm.globals.ITMConstants;
 import org.opendaylight.genius.mdsalutil.ActionInfo;
-import org.opendaylight.genius.mdsalutil.ActionType;
 import org.opendaylight.genius.mdsalutil.FlowEntity;
+import org.opendaylight.genius.mdsalutil.FlowEntityBuilder;
 import org.opendaylight.genius.mdsalutil.InstructionInfo;
-import org.opendaylight.genius.mdsalutil.InstructionType;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
-import org.opendaylight.genius.mdsalutil.MDSALUtil.MdsalOp;
-import org.opendaylight.genius.mdsalutil.MatchFieldType;
 import org.opendaylight.genius.mdsalutil.MatchInfo;
 import org.opendaylight.genius.mdsalutil.MetaDataUtil;
+import org.opendaylight.genius.mdsalutil.NWUtil;
 import org.opendaylight.genius.mdsalutil.NwConstants;
+import org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit;
+import org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions;
+import org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable;
 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
-import org.opendaylight.genius.utils.ServiceIndex;
+import org.opendaylight.genius.mdsalutil.matches.MatchEthernetDestination;
+import org.opendaylight.genius.mdsalutil.matches.MatchEthernetSource;
+import org.opendaylight.genius.mdsalutil.matches.MatchMetadata;
+import org.opendaylight.genius.mdsalutil.matches.MatchTunnelId;
+import org.opendaylight.genius.mdsalutil.packet.ARP;
+import org.opendaylight.genius.mdsalutil.packet.Ethernet;
+import org.opendaylight.genius.mdsalutil.packet.IPv4;
 import org.opendaylight.netvirt.elan.ElanException;
-import org.opendaylight.netvirt.elan.internal.ElanBridgeManager;
+import org.opendaylight.netvirt.elan.arp.responder.ArpResponderUtil;
 import org.opendaylight.netvirt.elan.internal.ElanInstanceManager;
-import org.opendaylight.netvirt.elan.internal.ElanInterfaceManager;
 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
-import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
-import org.opendaylight.netvirt.elan.l2gw.utils.L2GatewayConnectionUtils;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
+import org.opendaylight.netvirt.elanmanager.api.ElanHelper;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
 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.interfaces.rev140508.interfaces.state.Interface.AdminStatus;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus;
+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.action.types.rev131112.action.list.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
 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.inventory.rev130819.tables.table.FlowKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder;
@@ -72,11 +95,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.IfIndexesInterfaceMap;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._if.indexes._interface.map.IfIndexInterface;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._if.indexes._interface.map.IfIndexInterfaceKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfExternal;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeBase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan;
-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.GetEgressActionsForInterfaceInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetEgressActionsForInterfaceInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetEgressActionsForInterfaceOutput;
@@ -92,24 +114,17 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.ser
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServicesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServicesKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.ExternalTunnelList;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TunnelList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.external.tunnel.list.ExternalTunnel;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.external.tunnel.list.ExternalTunnelKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.CreateTerminatingServiceActionsInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.CreateTerminatingServiceActionsInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetExternalTunnelInterfaceNameInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetExternalTunnelInterfaceNameInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetExternalTunnelInterfaceNameOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetTunnelInterfaceNameInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetTunnelInterfaceNameInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetTunnelInterfaceNameOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.RemoveTerminatingServiceActionsInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.RemoveTerminatingServiceActionsInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.config.rev150710.ElanConfig;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.etree.rev160614.EtreeInstance;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.etree.rev160614.EtreeInstanceBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.etree.rev160614.EtreeInterface;
@@ -138,9 +153,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.forwarding.tables.MacTableKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
 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.instances.ElanInstanceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.elan.instance.ElanSegments;
 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.ElanInterfaceKey;
+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.StaticMacEntriesBuilder;
+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;
@@ -157,22 +175,26 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@Singleton
 public class ElanUtils {
 
     private static final Logger LOG = LoggerFactory.getLogger(ElanUtils.class);
 
     private static Map<String, ElanInstance> elanInstanceLocalCache = new ConcurrentHashMap<>();
     private static Map<String, ElanInterface> elanInterfaceLocalCache = new ConcurrentHashMap<>();
+    private static Map<String, Set<DpnInterfaces>> elanInstancToDpnsCache = new ConcurrentHashMap<>();
+    private static Map<String, Set<String>> elanInstanceToInterfacesCache = new ConcurrentHashMap<>();
 
     private final DataBroker broker;
     private final IMdsalApiManager mdsalManager;
     private final ElanInstanceManager elanInstanceManager;
     private final OdlInterfaceRpcService interfaceManagerRpcService;
     private final ItmRpcService itmRpcService;
-    private ElanL2GatewayUtils elanL2GatewayUtils;
-    private ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
-    private L2GatewayConnectionUtils l2GatewayConnectionUtils;
-    private ElanBridgeManager bridgeManager;
+    private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
+    private final IInterfaceManager interfaceManager;
+    private final ElanConfig elanConfig;
+    private final ElanItmUtils elanItmUtils;
+    private final ElanEtreeUtils elanEtreeUtils;
 
     public static final FutureCallback<Void> DEFAULT_CALLBACK = new FutureCallback<Void>() {
         @Override
@@ -186,35 +208,33 @@ public class ElanUtils {
         }
     };
 
+    @Inject
     public ElanUtils(DataBroker dataBroker, IMdsalApiManager mdsalManager, ElanInstanceManager elanInstanceManager,
                      OdlInterfaceRpcService interfaceManagerRpcService, ItmRpcService itmRpcService,
-                     ElanInterfaceManager elanInterfaceManager,
-                     EntityOwnershipService entityOwnershipService, ElanBridgeManager bridgeManager) {
+                     ElanConfig elanConfig,
+                     IInterfaceManager interfaceManager,
+                     ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils, ElanEtreeUtils elanEtreeUtils,
+                     ElanItmUtils elanItmUtils) {
         this.broker = dataBroker;
         this.mdsalManager = mdsalManager;
         this.elanInstanceManager = elanInstanceManager;
         this.interfaceManagerRpcService = interfaceManagerRpcService;
         this.itmRpcService = itmRpcService;
-        this.bridgeManager = bridgeManager;
-
-        elanL2GatewayMulticastUtils =
-                new ElanL2GatewayMulticastUtils(broker, elanInstanceManager, elanInterfaceManager, this);
-        elanL2GatewayUtils = new ElanL2GatewayUtils(broker, itmRpcService, this,
-                entityOwnershipService, elanL2GatewayMulticastUtils);
-        l2GatewayConnectionUtils = new L2GatewayConnectionUtils(broker,
-                elanInstanceManager, entityOwnershipService, this);
-    }
+        this.interfaceManager = interfaceManager;
+        this.elanConfig = elanConfig;
 
-    public ElanL2GatewayUtils getElanL2GatewayUtils() {
-        return elanL2GatewayUtils;
+        this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
+        this.elanEtreeUtils = elanEtreeUtils;
+        this.elanItmUtils = elanItmUtils;
     }
 
     public ElanL2GatewayMulticastUtils getElanL2GatewayMulticastUtils() {
         return elanL2GatewayMulticastUtils;
     }
 
-    public L2GatewayConnectionUtils getL2GatewayConnectionUtils() {
-        return l2GatewayConnectionUtils;
+    public final Boolean isOpenStackVniSemanticsEnforced() {
+        return elanConfig.isOpenstackVniSemanticsEnforced() != null
+                ? elanConfig.isOpenstackVniSemanticsEnforced() : false;
     }
 
     public static void addElanInstanceIntoCache(String elanInstanceName, ElanInstance elanInstance) {
@@ -229,6 +249,10 @@ public class ElanUtils {
         return elanInstanceLocalCache.get(elanInstanceName);
     }
 
+    public static Set<String> getAllElanNames() {
+        return elanInstanceLocalCache.keySet();
+    }
+
     public static void addElanInterfaceIntoCache(String interfaceName, ElanInterface elanInterface) {
         elanInterfaceLocalCache.put(interfaceName, elanInterface);
     }
@@ -259,7 +283,7 @@ public class ElanUtils {
             Future<RpcResult<AllocateIdOutput>> result = idManager.allocateId(getIdInput);
             RpcResult<AllocateIdOutput> rpcResult = result.get();
             if (rpcResult.isSuccessful()) {
-                return rpcResult.getResult().getIdValue().longValue();
+                return rpcResult.getResult().getIdValue();
             } else {
                 LOG.warn("RPC Call to Allocate Id returned with Errors {}", rpcResult.getErrors());
             }
@@ -271,7 +295,7 @@ public class ElanUtils {
 
     public static void releaseId(IdManagerService idManager, String poolName, String idKey) {
         ReleaseIdInput releaseIdInput = new ReleaseIdInputBuilder().setPoolName(poolName).setIdKey(idKey).build();
-        Future<RpcResult<Void>> result = idManager.releaseId(releaseIdInput);
+        idManager.releaseId(releaseIdInput);
     }
 
     /**
@@ -282,31 +306,20 @@ public class ElanUtils {
      */
     @Deprecated
     @SuppressWarnings("checkstyle:IllegalCatch")
-    public <T extends DataObject> Optional<T> read(DataBroker broker, LogicalDatastoreType datastoreType,
-            InstanceIdentifier<T> path) {
-        ReadOnlyTransaction tx = broker != null ? broker.newReadOnlyTransaction()
-                : this.broker.newReadOnlyTransaction();
-        Optional<T> result = Optional.absent();
-        try {
-            CheckedFuture<Optional<T>, ReadFailedException> checkedFuture = tx.read(datastoreType, path);
-            result = checkedFuture.get();
+    public static <T extends DataObject> Optional<T> read(@Nonnull DataBroker broker,
+            LogicalDatastoreType datastoreType, InstanceIdentifier<T> path) {
+        try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
+            return tx.read(datastoreType, path).get();
         } catch (Exception e) {
             throw new RuntimeException(e);
-        } finally {
-            tx.close();
         }
-
-        return result;
     }
 
     public <T extends DataObject> Optional<T> read2(LogicalDatastoreType datastoreType, InstanceIdentifier<T> path)
             throws ReadFailedException {
-        ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
-        try {
+        try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
             CheckedFuture<Optional<T>, ReadFailedException> checkedFuture = tx.read(datastoreType, path);
             return checkedFuture.checkedGet();
-        } finally {
-            tx.close();
         }
     }
 
@@ -314,14 +327,14 @@ public class ElanUtils {
             InstanceIdentifier<T> path) {
         WriteTransaction tx = broker.newWriteOnlyTransaction();
         tx.delete(datastoreType, path);
-        Futures.addCallback(tx.submit(), DEFAULT_CALLBACK);
+        Futures.addCallback(tx.submit(), DEFAULT_CALLBACK, MoreExecutors.directExecutor());
     }
 
     public static <T extends DataObject> void delete(DataBroker broker, LogicalDatastoreType datastoreType,
             InstanceIdentifier<T> path, FutureCallback<Void> callback) {
         WriteTransaction tx = broker.newWriteOnlyTransaction();
         tx.delete(datastoreType, path);
-        Futures.addCallback(tx.submit(), callback);
+        Futures.addCallback(tx.submit(), callback, MoreExecutors.directExecutor());
     }
 
     public static InstanceIdentifier<ElanInstance> getElanInstanceIdentifier() {
@@ -334,18 +347,9 @@ public class ElanUtils {
         if (elanObj != null) {
             return elanObj;
         }
-        InstanceIdentifier<ElanInstance> elanIdentifierId = getElanInstanceConfigurationDataPath(elanInstanceName);
-        Optional<ElanInstance> elanInstance = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION,
-                elanIdentifierId);
-        if (elanInstance.isPresent()) {
-            return elanInstance.get();
-        }
-        return null;
-    }
-
-    public static InstanceIdentifier<ElanInstance> getElanInstanceConfigurationDataPath(String elanInstanceName) {
-        return InstanceIdentifier.builder(ElanInstances.class)
-                .child(ElanInstance.class, new ElanInstanceKey(elanInstanceName)).build();
+        InstanceIdentifier<ElanInstance> elanIdentifierId =
+                ElanHelper.getElanInstanceConfigurationDataPath(elanInstanceName);
+        return MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, elanIdentifierId).orNull();
     }
 
     // elan-interfaces Config Container
@@ -355,17 +359,16 @@ public class ElanUtils {
             return elanInterfaceObj;
         }
         InstanceIdentifier<ElanInterface> elanInterfaceId = getElanInterfaceConfigurationDataPathId(elanInterfaceName);
-        Optional<ElanInterface> existingElanInterface = MDSALUtil.read(broker,
-                LogicalDatastoreType.CONFIGURATION, elanInterfaceId);
-        if (existingElanInterface.isPresent()) {
-            return existingElanInterface.get();
-        }
-        return null;
+        return MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, elanInterfaceId).orNull();
     }
 
     public static EtreeInterface getEtreeInterfaceByElanInterfaceName(DataBroker broker, String elanInterfaceName) {
         ElanInterface elanInterface = getElanInterfaceByElanInterfaceName(broker, elanInterfaceName);
-        return elanInterface.getAugmentation(EtreeInterface.class);
+        if (elanInterface == null) {
+            return null;
+        } else {
+            return elanInterface.getAugmentation(EtreeInterface.class);
+        }
     }
 
     public static InstanceIdentifier<ElanInterface> getElanInterfaceConfigurationDataPathId(String interfaceName) {
@@ -376,12 +379,7 @@ public class ElanUtils {
     // elan-state Operational container
     public static Elan getElanByName(DataBroker broker, String elanInstanceName) {
         InstanceIdentifier<Elan> elanIdentifier = getElanInstanceOperationalDataPath(elanInstanceName);
-        Optional<Elan> elanInstance = MDSALUtil.read(broker, LogicalDatastoreType.OPERATIONAL,
-                elanIdentifier);
-        if (elanInstance.isPresent()) {
-            return elanInstance.get();
-        }
-        return null;
+        return MDSALUtil.read(broker, LogicalDatastoreType.OPERATIONAL, elanIdentifier).orNull();
     }
 
     public static InstanceIdentifier<Elan> getElanInstanceOperationalDataPath(String elanInstanceName) {
@@ -392,21 +390,13 @@ public class ElanUtils {
     public MacEntry getInterfaceMacEntriesOperationalDataPath(String interfaceName, PhysAddress physAddress) {
         InstanceIdentifier<MacEntry> existingMacEntryId = getInterfaceMacEntriesIdentifierOperationalDataPath(
                 interfaceName, physAddress);
-        Optional<MacEntry> existingInterfaceMacEntry = read(broker,
-                LogicalDatastoreType.OPERATIONAL, existingMacEntryId);
-        if (existingInterfaceMacEntry.isPresent()) {
-            return existingInterfaceMacEntry.get();
-        }
-        return null;
+        return read(broker, LogicalDatastoreType.OPERATIONAL, existingMacEntryId).orNull();
     }
 
     public MacEntry getInterfaceMacEntriesOperationalDataPathFromId(InstanceIdentifier identifier) {
         Optional<MacEntry> existingInterfaceMacEntry = read(broker,
                 LogicalDatastoreType.OPERATIONAL, identifier);
-        if (existingInterfaceMacEntry.isPresent()) {
-            return existingInterfaceMacEntry.get();
-        }
-        return null;
+        return existingInterfaceMacEntry.orNull();
     }
 
     public static InstanceIdentifier<MacEntry> getInterfaceMacEntriesIdentifierOperationalDataPath(String interfaceName,
@@ -418,23 +408,15 @@ public class ElanUtils {
     }
 
     // elan-forwarding-tables Operational container
-    public MacEntry getMacTableByElanName(String elanName, PhysAddress physAddress) {
+    public Optional<MacEntry> getMacEntryForElanInstance(String elanName, PhysAddress physAddress) {
         InstanceIdentifier<MacEntry> macId = getMacEntryOperationalDataPath(elanName, physAddress);
-        Optional<MacEntry> existingElanMacEntry = read(broker,
-                LogicalDatastoreType.OPERATIONAL, macId);
-        if (existingElanMacEntry.isPresent()) {
-            return existingElanMacEntry.get();
-        }
-        return null;
+        return read(broker, LogicalDatastoreType.OPERATIONAL, macId);
     }
 
     public MacEntry getMacEntryFromElanMacId(InstanceIdentifier identifier) {
         Optional<MacEntry> existingInterfaceMacEntry = read(broker,
                 LogicalDatastoreType.OPERATIONAL, identifier);
-        if (existingInterfaceMacEntry.isPresent()) {
-            return existingInterfaceMacEntry.get();
-        }
-        return null;
+        return existingInterfaceMacEntry.orNull();
     }
 
     public static InstanceIdentifier<MacEntry> getMacEntryOperationalDataPath(String elanName,
@@ -450,14 +432,14 @@ public class ElanUtils {
 
     // elan-interface-forwarding-entries Operational container
     public ElanInterfaceMac getElanInterfaceMacByInterfaceName(String interfaceName) {
+        return getElanInterfaceMacByInterfaceName(broker, interfaceName);
+    }
+
+    @Nullable
+    public static ElanInterfaceMac getElanInterfaceMacByInterfaceName(DataBroker dataBroker, String interfaceName) {
         InstanceIdentifier<ElanInterfaceMac> elanInterfaceId = getElanInterfaceMacEntriesOperationalDataPath(
                 interfaceName);
-        Optional<ElanInterfaceMac> existingElanInterface = read(broker,
-                LogicalDatastoreType.OPERATIONAL, elanInterfaceId);
-        if (existingElanInterface.isPresent()) {
-            return existingElanInterface.get();
-        }
-        return null;
+        return read(dataBroker, LogicalDatastoreType.OPERATIONAL, elanInterfaceId).orNull();
     }
 
     /**
@@ -498,12 +480,7 @@ public class ElanUtils {
     public DpnInterfaces getElanInterfaceInfoByElanDpn(String elanInstanceName, BigInteger dpId) {
         InstanceIdentifier<DpnInterfaces> elanDpnInterfacesId = getElanDpnInterfaceOperationalDataPath(elanInstanceName,
                 dpId);
-        Optional<DpnInterfaces> elanDpnInterfaces = read(broker,
-                LogicalDatastoreType.OPERATIONAL, elanDpnInterfacesId);
-        if (elanDpnInterfaces.isPresent()) {
-            return elanDpnInterfaces.get();
-        }
-        return null;
+        return read(broker, LogicalDatastoreType.OPERATIONAL, elanDpnInterfacesId).orNull();
     }
 
     /**
@@ -529,22 +506,7 @@ public class ElanUtils {
         InstanceIdentifier<ElanTagName> elanId = getElanInfoEntriesOperationalDataPath(elanTag);
         Optional<ElanTagName> existingElanInfo = read(broker,
                 LogicalDatastoreType.OPERATIONAL, elanId);
-        if (existingElanInfo.isPresent()) {
-            return existingElanInfo.get();
-        }
-        return null;
-    }
-
-    public EtreeLeafTagName getEtreeLeafTagByElanTag(long elanTag) {
-        InstanceIdentifier<ElanTagName> elanId = getElanInfoEntriesOperationalDataPath(elanTag);
-        Optional<ElanTagName> existingElanInfo = read(broker,
-                LogicalDatastoreType.OPERATIONAL, elanId);
-        if (existingElanInfo.isPresent()) {
-            ElanTagName elanTagName = existingElanInfo.get();
-            EtreeLeafTagName etreeAugmentation = elanTagName.getAugmentation(EtreeLeafTagName.class);
-            return etreeAugmentation;
-        }
-        return null;
+        return existingElanInfo.orNull();
     }
 
     public static InstanceIdentifier<ElanTagName> getElanInfoEntriesOperationalDataPath(long elanTag) {
@@ -570,23 +532,13 @@ public class ElanUtils {
 
     public ElanDpnInterfacesList getElanDpnInterfacesList(String elanName) {
         InstanceIdentifier<ElanDpnInterfacesList> elanDpnInterfaceId = getElanDpnOperationDataPath(elanName);
-        Optional<ElanDpnInterfacesList> existingElanDpnInterfaces = read(broker,
-                LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId);
-        if (existingElanDpnInterfaces.isPresent()) {
-            return existingElanDpnInterfaces.get();
-        }
-        return null;
+        return read(broker, LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId).orNull();
     }
 
     public ElanDpnInterfaces getElanDpnInterfacesList() {
         InstanceIdentifier<ElanDpnInterfaces> elanDpnInterfaceId = InstanceIdentifier.builder(ElanDpnInterfaces.class)
                 .build();
-        Optional<ElanDpnInterfaces> existingElanDpnInterfaces = read(broker,
-                LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId);
-        if (existingElanDpnInterfaces.isPresent()) {
-            return existingElanDpnInterfaces.get();
-        }
-        return null;
+        return read(broker, LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId).orNull();
     }
 
     /**
@@ -625,32 +577,29 @@ public class ElanUtils {
      * @return true if dpId is already present, otherwise return false
      */
     public boolean isDpnAlreadyPresentInElanInstance(BigInteger dpId, String elanInstanceName) {
-        boolean isDpIdPresent = false;
         InstanceIdentifier<ElanDpnInterfacesList> elanDpnInterfaceId = getElanDpnOperationDataPath(elanInstanceName);
         Optional<ElanDpnInterfacesList> existingElanDpnInterfaces = read(broker,
                 LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId);
         if (!existingElanDpnInterfaces.isPresent()) {
-            return isDpIdPresent;
+            return false;
         }
         List<DpnInterfaces> dpnInterfaces = existingElanDpnInterfaces.get().getDpnInterfaces();
         for (DpnInterfaces dpnInterface : dpnInterfaces) {
             if (dpnInterface.getDpId().equals(dpId)) {
-                isDpIdPresent = true;
-                break;
+                return true;
             }
         }
-        return isDpIdPresent;
+        return false;
     }
 
     public ElanForwardingTables getElanForwardingList() {
         InstanceIdentifier<ElanForwardingTables> elanForwardingTableId = InstanceIdentifier
                 .builder(ElanForwardingTables.class).build();
-        Optional<ElanForwardingTables> existingElanForwardingList = read(broker,
-                LogicalDatastoreType.OPERATIONAL, elanForwardingTableId);
-        if (existingElanForwardingList.isPresent()) {
-            return existingElanForwardingList.get();
-        }
-        return null;
+        return read(broker, LogicalDatastoreType.OPERATIONAL, elanForwardingTableId).orNull();
+    }
+
+    public static long getElanRemoteBroadCastGroupID(long elanTag) {
+        return ElanConstants.ELAN_GID_MIN + elanTag % ElanConstants.ELAN_GID_MIN * 2;
     }
 
     /**
@@ -661,13 +610,13 @@ public class ElanUtils {
      * @return the elan mac table
      */
     public MacTable getElanMacTable(String elanName) {
+        return getElanMacTable(broker, elanName);
+    }
+
+    @Nullable
+    public static MacTable getElanMacTable(DataBroker dataBroker, String elanName) {
         InstanceIdentifier<MacTable> elanMacTableId = getElanMacTableOperationalDataPath(elanName);
-        Optional<MacTable> existingElanMacTable = read(broker,
-                LogicalDatastoreType.OPERATIONAL, elanMacTableId);
-        if (existingElanMacTable.isPresent()) {
-            return existingElanMacTable.get();
-        }
-        return null;
+        return read(dataBroker, LogicalDatastoreType.OPERATIONAL, elanMacTableId).orNull();
     }
 
     public static long getElanLocalBCGId(long elanTag) {
@@ -686,25 +635,13 @@ public class ElanUtils {
         return ElanConstants.ELAN_GID_MIN + etreeLeafTag % ElanConstants.ELAN_GID_MIN * 2;
     }
 
-    public static BigInteger getElanMetadataLabel(long elanTag) {
-        return BigInteger.valueOf(elanTag).shiftLeft(24);
-    }
-
     public static BigInteger getElanMetadataLabel(long elanTag, boolean isSHFlagSet) {
         int shBit = isSHFlagSet ? 1 : 0;
         return BigInteger.valueOf(elanTag).shiftLeft(24).or(BigInteger.valueOf(shBit));
     }
 
-    public static BigInteger getElanMetadataLabel(long elanTag, int lportTag) {
-        return getElanMetadataLabel(elanTag).or(MetaDataUtil.getLportTagMetaData(lportTag));
-    }
-
-    public static BigInteger getElanMetadataMask() {
-        return MetaDataUtil.METADATA_MASK_SERVICE.or(MetaDataUtil.METADATA_MASK_LPORT_TAG);
-    }
-
     /**
-     * Setting INTERNAL_TUNNEL_TABLE, SMAC, DMAC, UDMAC in this DPN and optionally in other DPNs.
+     * Setting SMAC, DMAC, UDMAC in this DPN and optionally in other DPNs.
      *
      * @param elanInfo
      *            the elan info
@@ -720,43 +657,25 @@ public class ElanUtils {
      *            the flow group tx
      * @throws ElanException in case of issues creating the flow objects
      */
-    public void setupMacFlows(ElanInstance elanInfo, InterfaceInfo interfaceInfo, long macTimeout,
-            String macAddress, boolean configureRemoteFlows, WriteTransaction writeFlowGroupTx) throws ElanException {
-        synchronized (macAddress) {
-            LOG.debug("Acquired lock for mac : " + macAddress + ". Proceeding with install operation.");
+    public void setupMacFlows(ElanInstance elanInfo, InterfaceInfo interfaceInfo,
+                              long macTimeout, String macAddress, boolean configureRemoteFlows,
+                              WriteTransaction writeFlowGroupTx) throws ElanException {
+        synchronized (getElanMacDPNKey(elanInfo.getElanTag(), macAddress, interfaceInfo.getDpId())) {
             setupKnownSmacFlow(elanInfo, interfaceInfo, macTimeout, macAddress, mdsalManager,
-                    writeFlowGroupTx);
+                writeFlowGroupTx);
             setupOrigDmacFlows(elanInfo, interfaceInfo, macAddress, configureRemoteFlows, mdsalManager,
-                    broker, writeFlowGroupTx);
+                broker, writeFlowGroupTx);
         }
     }
 
-    /**
-     * Setting INTERNAL_TUNNEL_TABLE, SMAC, DMAC, UDMAC in this DPN and on other DPNs.
-     *
-     * @param elanInfo
-     *            the elan info
-     * @param interfaceInfo
-     *            the interface info
-     * @param macTimeout
-     *            the mac timeout
-     * @param macAddress
-     *            the mac address
-     * @param writeFlowGroupTx
-     *            the flow group tx
-     * @throws ElanException in case of issues creating the flow objects
-     */
-    public void setupMacFlows(ElanInstance elanInfo, InterfaceInfo interfaceInfo, long macTimeout,
-                              String macAddress, WriteTransaction writeFlowGroupTx) throws ElanException {
-        setupMacFlows(elanInfo, interfaceInfo, macTimeout, macAddress, true, writeFlowGroupTx);
-    }
-
-    public void setupDMacFlowonRemoteDpn(ElanInstance elanInfo, InterfaceInfo interfaceInfo, BigInteger dstDpId,
-            String macAddress, WriteTransaction writeFlowTx) throws ElanException {
-        synchronized (macAddress) {
-            LOG.debug("Acquired lock for mac : " + macAddress + ". Proceeding with install operation.");
-            setupOrigDmacFlowsonRemoteDpn(elanInfo, interfaceInfo, dstDpId, macAddress, writeFlowTx);
-        }
+    public void setupDMacFlowOnRemoteDpn(ElanInstance elanInfo, InterfaceInfo interfaceInfo, BigInteger dstDpId,
+                                         String macAddress, WriteTransaction writeFlowTx) throws ElanException {
+        String elanInstanceName = elanInfo.getElanInstanceName();
+        setupRemoteDmacFlow(dstDpId, interfaceInfo.getDpId(), interfaceInfo.getInterfaceTag(), elanInfo.getElanTag(),
+                macAddress, elanInstanceName, writeFlowTx, interfaceInfo.getInterfaceName(), elanInfo);
+        LOG.info("Remote Dmac flow entry created for elan Name:{}, logical port Name:{} and"
+                + " mac address {} on dpn:{}", elanInstanceName, interfaceInfo.getPortName(),
+                macAddress, dstDpId);
     }
 
     /**
@@ -776,25 +695,28 @@ public class ElanUtils {
         int lportTag = interfaceInfo.getInterfaceTag();
         // Matching metadata and eth_src fields
         List<MatchInfo> mkMatches = new ArrayList<>();
-        mkMatches.add(new MatchInfo(MatchFieldType.metadata, new BigInteger[] {
-                getElanMetadataLabel(elanInfo.getElanTag(), lportTag), getElanMetadataMask() }));
-        mkMatches.add(new MatchInfo(MatchFieldType.eth_src, new String[] { macAddress }));
+        mkMatches.add(new MatchMetadata(ElanHelper.getElanMetadataLabel(elanInfo.getElanTag(), lportTag),
+                ElanHelper.getElanMetadataMask()));
+        mkMatches.add(new MatchEthernetSource(new MacAddress(macAddress)));
         List<InstructionInfo> mkInstructions = new ArrayList<>();
-        mkInstructions.add(new InstructionInfo(InstructionType.goto_table, new long[] { NwConstants.ELAN_DMAC_TABLE }));
-
+        mkInstructions.add(new InstructionGotoTable(NwConstants.ELAN_DMAC_TABLE));
         BigInteger dpId = interfaceInfo.getDpId();
         long elanTag = getElanTag(broker, elanInfo, interfaceInfo);
-        FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_SMAC_TABLE,
-                getKnownDynamicmacFlowRef(NwConstants.ELAN_SMAC_TABLE, dpId, lportTag, macAddress, elanTag), 20,
-                elanInfo.getDescription(), (int) macTimeout, 0,
-                ElanConstants.COOKIE_ELAN_KNOWN_SMAC.add(BigInteger.valueOf(elanTag)), mkMatches, mkInstructions);
-        flowEntity.setStrictFlag(true);
-        flowEntity.setSendFlowRemFlag(macTimeout != 0); // If Mac timeout is 0,
-                                                        // the flow wont be
-                                                        // deleted
-                                                        // automatically, so no
-                                                        // need to get notified
-        return flowEntity;
+        return new FlowEntityBuilder()
+            .setDpnId(dpId)
+            .setTableId(NwConstants.ELAN_SMAC_TABLE)
+            .setFlowId(getKnownDynamicmacFlowRef(NwConstants.ELAN_SMAC_TABLE, dpId, lportTag, macAddress, elanTag))
+            .setPriority(20)
+            .setFlowName(elanInfo.getDescription())
+            .setIdleTimeOut((int) macTimeout)
+            .setHardTimeOut(0)
+            .setCookie(ElanConstants.COOKIE_ELAN_KNOWN_SMAC.add(BigInteger.valueOf(elanTag)))
+            .setMatchInfoList(mkMatches)
+            .setInstructionInfoList(mkInstructions)
+            .setStrictFlag(true)
+            // If Mac timeout is 0, the flow won't be deleted automatically, so no need to get notified
+            .setSendFlowRemFlag(macTimeout != 0)
+            .build();
     }
 
     private static Long getElanTag(DataBroker broker, ElanInstance elanInfo, InterfaceInfo interfaceInfo) {
@@ -804,8 +726,8 @@ public class ElanUtils {
         } else { // Leaf
             EtreeInstance etreeInstance = elanInfo.getAugmentation(EtreeInstance.class);
             if (etreeInstance == null) {
-                LOG.warn("EtreeInterface " + interfaceInfo.getInterfaceName() + " is connected to a non-Etree network: "
-                        + elanInfo.getElanInstanceName());
+                LOG.warn("EtreeInterface {} is connected to a non-Etree network: {}",
+                         interfaceInfo.getInterfaceName(), elanInfo.getElanInstanceName());
                 return elanInfo.getElanTag();
             } else {
                 return etreeInstance.getEtreeLeafTagVal().getValue();
@@ -826,7 +748,7 @@ public class ElanUtils {
      *            the writeFLowGroup tx
      */
     public void setupTermDmacFlows(InterfaceInfo interfaceInfo, IMdsalApiManager mdsalApiManager,
-            WriteTransaction writeFlowGroupTx) {
+                                   WriteTransaction writeFlowGroupTx) {
         BigInteger dpId = interfaceInfo.getDpId();
         int lportTag = interfaceInfo.getInterfaceTag();
         Flow flow = MDSALUtil.buildFlowNew(NwConstants.INTERNAL_TUNNEL_TABLE,
@@ -865,7 +787,7 @@ public class ElanUtils {
     public static List<MatchInfo> getTunnelIdMatchForFilterEqualsLPortTag(int lportTag) {
         List<MatchInfo> mkMatches = new ArrayList<>();
         // Matching metadata
-        mkMatches.add(new MatchInfo(MatchFieldType.tunnel_id, new BigInteger[] { BigInteger.valueOf(lportTag) }));
+        mkMatches.add(new MatchTunnelId(BigInteger.valueOf(lportTag)));
         return mkMatches;
     }
 
@@ -910,7 +832,7 @@ public class ElanUtils {
                     .getEgressActionsForInterface(getEgressActionInput);
             RpcResult<GetEgressActionsForInterfaceOutput> rpcResult = result.get();
             if (!rpcResult.isSuccessful()) {
-                LOG.warn("RPC Call to Get egress actions for interface {} returned with Errors {}", ifName,
+                LOG.debug("RPC Call to Get egress actions for interface {} returned with Errors {}", ifName,
                         rpcResult.getErrors());
             } else {
                 List<Action> actions = rpcResult.getResult().getAction();
@@ -931,9 +853,9 @@ public class ElanUtils {
         long ifTag = interfaceInfo.getInterfaceTag();
         String elanInstanceName = elanInfo.getElanInstanceName();
 
-        Long elanTag = getElanTag(broker, elanInfo, interfaceInfo);
+        Long elanTag = elanInfo.getElanTag();
 
-        setupLocalDmacFlow(elanTag, dpId, ifName, macAddress, elanInstanceName, mdsalApiManager, ifTag,
+        setupLocalDmacFlow(elanTag, dpId, ifName, macAddress, elanInfo, mdsalApiManager, ifTag,
                 writeFlowGroupTx);
         LOG.debug("Dmac flow entry created for elan Name:{}, logical port Name:{} mand mac address:{} "
                                     + "on dpn:{}", elanInstanceName, interfaceInfo.getPortName(), macAddress, dpId);
@@ -958,70 +880,46 @@ public class ElanUtils {
                 continue;
             }
 
-            // For remote DPNs a flow is needed to indicate that
-            // packets of this ELAN going to this MAC
-            // need to be forwarded through the appropiated ITM
-            // tunnel
+            // For remote DPNs a flow is needed to indicate that packets of this ELAN going to this MAC need to be
+            // forwarded through the appropriate ITM tunnel
             setupRemoteDmacFlow(elanDpn.getDpId(), // srcDpn (the remote DPN in this case)
                     dpId, // dstDpn (the local DPN)
                     interfaceInfo.getInterfaceTag(), // lportTag of the local interface
-                    elanTag, // identifier of the Elan
+                    elanTag,  // identifier of the Elan
                     macAddress, // MAC to be programmed in remote DPN
-                    elanInstanceName, writeFlowGroupTx, ifName, elanInfo);
-            LOG.debug("Dmac flow entry created for elan Name:{}, logical port Name:{} and mac address:{} on"
+                    elanInstanceName, writeFlowGroupTx, ifName, elanInfo
+            );
+            LOG.debug("Remote Dmac flow entry created for elan Name:{}, logical port Name:{} and mac address:{} on"
                         + " dpn:{}", elanInstanceName, interfaceInfo.getPortName(), macAddress, elanDpn.getDpId());
         }
 
         // TODO: Make sure that the same is performed against the ElanDevices.
     }
 
-    private void setupOrigDmacFlowsonRemoteDpn(ElanInstance elanInfo, InterfaceInfo interfaceInfo,
-            BigInteger dstDpId, String macAddress, WriteTransaction writeFlowTx) throws ElanException {
-        BigInteger dpId = interfaceInfo.getDpId();
-        String elanInstanceName = elanInfo.getElanInstanceName();
-        List<DpnInterfaces> remoteFEs = getInvolvedDpnsInElan(elanInstanceName);
-        for (DpnInterfaces remoteFE : remoteFEs) {
-            Long elanTag = elanInfo.getElanTag();
-            if (remoteFE.getDpId().equals(dstDpId)) {
-                // Check for the Remote DPN present in Inventory Manager
-                setupRemoteDmacFlow(dstDpId, dpId, interfaceInfo.getInterfaceTag(), elanTag, macAddress,
-                        elanInstanceName, writeFlowTx, interfaceInfo.getInterfaceName(), elanInfo);
-                LOG.debug("Dmac flow entry created for elan Name:{}, logical port Name:{} and mac address {} on dpn:{}",
-                        elanInstanceName, interfaceInfo.getPortName(), macAddress, remoteFE.getDpId());
-                break;
-            }
-        }
-    }
-
-    @SuppressWarnings("unchecked")
     public List<DpnInterfaces> getInvolvedDpnsInElan(String elanName) {
-        List<DpnInterfaces> dpns = elanInstanceManager.getElanDPNByName(elanName);
-        if (dpns == null) {
-            return Collections.emptyList();
-        }
-        return dpns;
+        return elanInstanceManager.getElanDPNByName(elanName);
     }
 
     private void setupLocalDmacFlow(long elanTag, BigInteger dpId, String ifName, String macAddress,
-            String displayName, IMdsalApiManager mdsalApiManager, long ifTag, WriteTransaction writeFlowGroupTx) {
-        Flow flowEntity = buildLocalDmacFlowEntry(elanTag, dpId, ifName, macAddress, displayName, ifTag);
+            ElanInstance elanInfo, IMdsalApiManager mdsalApiManager, long ifTag, WriteTransaction writeFlowGroupTx) {
+        Flow flowEntity = buildLocalDmacFlowEntry(elanTag, dpId, ifName, macAddress, elanInfo, ifTag);
         mdsalApiManager.addFlowToTx(dpId, flowEntity, writeFlowGroupTx);
-        installEtreeLocalDmacFlow(elanTag, dpId, ifName, macAddress, displayName, mdsalApiManager, ifTag,
-                writeFlowGroupTx);
+        installEtreeLocalDmacFlow(elanTag, dpId, ifName, macAddress, elanInfo,
+                mdsalApiManager, ifTag, writeFlowGroupTx);
     }
 
     private void installEtreeLocalDmacFlow(long elanTag, BigInteger dpId, String ifName, String macAddress,
-            String displayName, IMdsalApiManager mdsalApiManager, long ifTag, WriteTransaction writeFlowGroupTx) {
+            ElanInstance elanInfo, IMdsalApiManager mdsalApiManager, long ifTag, WriteTransaction writeFlowGroupTx) {
         EtreeInterface etreeInterface = getEtreeInterfaceByElanInterfaceName(broker, ifName);
         if (etreeInterface != null) {
             if (etreeInterface.getEtreeInterfaceType() == EtreeInterfaceType.Root) {
-                EtreeLeafTagName etreeTagName = getEtreeLeafTagByElanTag(elanTag);
+                EtreeLeafTagName etreeTagName = elanEtreeUtils.getEtreeLeafTagByElanTag(elanTag);
                 if (etreeTagName == null) {
-                    LOG.warn("Interface " + ifName + " seems like it belongs to Etree but etreeTagName from elanTag "
-                            + elanTag + " is null.");
+                    LOG.warn("Interface {} seems like it belongs to Etree but etreeTagName from elanTag {} is null",
+                             ifName, elanTag);
                 } else {
                     Flow flowEntity = buildLocalDmacFlowEntry(etreeTagName.getEtreeLeafTag().getValue(), dpId, ifName,
-                            macAddress, displayName, ifTag);
+                            macAddress, elanInfo, ifTag);
                     mdsalApiManager.addFlowToTx(dpId, flowEntity, writeFlowGroupTx);
                 }
             }
@@ -1044,7 +942,7 @@ public class ElanUtils {
         return new StringBuffer().append(tableId).append(elanTag).append(dpId).append(macAddress).toString();
     }
 
-    private static String getKnownDynamicmacFlowRef(short elanDmacTable, BigInteger dpId, String extDeviceNodeId,
+    public static String getKnownDynamicmacFlowRef(short elanDmacTable, BigInteger dpId, String extDeviceNodeId,
             String dstMacAddress, long elanTag, boolean shFlag) {
         return new StringBuffer().append(elanDmacTable).append(elanTag).append(dpId).append(extDeviceNodeId)
                 .append(dstMacAddress).append(shFlag).toString();
@@ -1066,53 +964,64 @@ public class ElanUtils {
      *            the if name
      * @param macAddress
      *            the mac address
-     * @param displayName
-     *            the display name
+     * @param elanInfo
+     *            the elan info
      * @param ifTag
      *            the if tag
      * @return the flow
      */
     public Flow buildLocalDmacFlowEntry(long elanTag, BigInteger dpId, String ifName, String macAddress,
-            String displayName, long ifTag) {
+            ElanInstance elanInfo, long ifTag) {
+
         List<MatchInfo> mkMatches = new ArrayList<>();
-        mkMatches.add(new MatchInfo(MatchFieldType.metadata,
-                new BigInteger[] { getElanMetadataLabel(elanTag), MetaDataUtil.METADATA_MASK_SERVICE }));
-        mkMatches.add(new MatchInfo(MatchFieldType.eth_dst, new String[] { macAddress }));
+        mkMatches.add(new MatchMetadata(ElanHelper.getElanMetadataLabel(elanTag), MetaDataUtil.METADATA_MASK_SERVICE));
+        mkMatches.add(new MatchEthernetDestination(new MacAddress(macAddress)));
 
         List<Instruction> mkInstructions = new ArrayList<>();
         List<Action> actions = getEgressActionsForInterface(ifName, /* tunnelKey */ null);
         mkInstructions.add(MDSALUtil.buildApplyActionsInstruction(actions));
         Flow flow = MDSALUtil.buildFlowNew(NwConstants.ELAN_DMAC_TABLE,
                 getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpId, ifTag, macAddress, elanTag), 20,
-                displayName, 0, 0, ElanConstants.COOKIE_ELAN_KNOWN_DMAC.add(BigInteger.valueOf(elanTag)), mkMatches,
-                mkInstructions);
+                elanInfo.getElanInstanceName(), 0, 0, ElanConstants.COOKIE_ELAN_KNOWN_DMAC.add(
+                        BigInteger.valueOf(elanTag)), mkMatches, mkInstructions);
 
         return flow;
     }
 
-    public void setupRemoteDmacFlow(BigInteger srcDpId, BigInteger destDpId, int lportTag, long elanTag,
-            String macAddress, String displayName, WriteTransaction writeFlowGroupTx, String interfaceName,
-            ElanInstance elanInstance) throws ElanException {
-        Flow flowEntity = buildRemoteDmacFlowEntry(srcDpId, destDpId, lportTag, elanTag, macAddress, displayName,
+    public void setupRemoteDmacFlow(BigInteger srcDpId, BigInteger destDpId, int lportTag, long elanTag, String
+            macAddress, String displayName, WriteTransaction writeFlowGroupTx, String interfaceName, ElanInstance
+            elanInstance) throws ElanException {
+        if (interfaceManager.isExternalInterface(interfaceName)) {
+            LOG.debug("Ignoring install remote DMAC {} flow on provider interface {} elan {}",
+                    macAddress, interfaceName, elanInstance.getElanInstanceName());
+            return;
+        }
+        Flow flowEntity;
+        // if openstack-vni-semantics are enforced, segmentation ID is passed as network VNI for VxLAN based provider
+        // networks, 0 otherwise
+        long lportTagOrVni = !isOpenStackVniSemanticsEnforced() ? lportTag : isVxlan(elanInstance)
+                ? elanInstance.getSegmentationId() : 0;
+        flowEntity = buildRemoteDmacFlowEntry(srcDpId, destDpId, lportTagOrVni, elanTag, macAddress, displayName,
                 elanInstance);
         mdsalManager.addFlowToTx(srcDpId, flowEntity, writeFlowGroupTx);
-        setupEtreeRemoteDmacFlow(srcDpId, destDpId, lportTag, elanTag, macAddress, displayName, interfaceName,
+        setupEtreeRemoteDmacFlow(srcDpId, destDpId, lportTagOrVni, elanTag, macAddress, displayName, interfaceName,
                 writeFlowGroupTx, elanInstance);
     }
 
-    private void setupEtreeRemoteDmacFlow(BigInteger srcDpId, BigInteger destDpId, int lportTag, long elanTag,
-                                String macAddress, String displayName, String interfaceName,
-                                WriteTransaction writeFlowGroupTx, ElanInstance elanInstance) throws ElanException {
+    private void setupEtreeRemoteDmacFlow(BigInteger srcDpId, BigInteger destDpId, long lportTagOrVni, long elanTag,
+                                          String macAddress, String displayName, String interfaceName,
+                                          WriteTransaction writeFlowGroupTx, ElanInstance elanInstance)
+                                          throws ElanException {
         Flow flowEntity;
         EtreeInterface etreeInterface = getEtreeInterfaceByElanInterfaceName(broker, interfaceName);
         if (etreeInterface != null) {
             if (etreeInterface.getEtreeInterfaceType() == EtreeInterfaceType.Root) {
-                EtreeLeafTagName etreeTagName = getEtreeLeafTagByElanTag(elanTag);
+                EtreeLeafTagName etreeTagName = elanEtreeUtils.getEtreeLeafTagByElanTag(elanTag);
                 if (etreeTagName == null) {
                     LOG.warn("Interface " + interfaceName
                             + " seems like it belongs to Etree but etreeTagName from elanTag " + elanTag + " is null.");
                 } else {
-                    flowEntity = buildRemoteDmacFlowEntry(srcDpId, destDpId, lportTag,
+                    flowEntity = buildRemoteDmacFlowEntry(srcDpId, destDpId, lportTagOrVni,
                             etreeTagName.getEtreeLeafTag().getValue(), macAddress, displayName, elanInstance);
                     mdsalManager.addFlowToTx(srcDpId, flowEntity, writeFlowGroupTx);
                 }
@@ -1123,15 +1032,15 @@ public class ElanUtils {
     /**
      * Builds a Flow to be programmed in a remote DPN's DMAC table. This flow
      * consists in: Match: + elanTag in packet's metadata + packet going to a
-     * MAC known to be located in another DPN Actions: + set_tunnel_id(lportTag)
+     * MAC known to be located in another DPN Actions: + set_tunnel_id
      * + output ITM internal tunnel interface with the other DPN
      *
      * @param srcDpId
      *            the src Dpn Id
      * @param destDpId
      *            dest Dp Id
-     * @param lportTag
-     *            lport Tag
+     * @param lportTagOrVni
+     *            lportTag or network VNI
      * @param elanTag
      *            elan Tag
      * @param macAddress
@@ -1142,12 +1051,11 @@ public class ElanUtils {
      * @throws ElanException in case of issues creating the flow objects
      */
     @SuppressWarnings("checkstyle:IllegalCatch")
-    public Flow buildRemoteDmacFlowEntry(BigInteger srcDpId, BigInteger destDpId, int lportTag, long elanTag,
+    public Flow buildRemoteDmacFlowEntry(BigInteger srcDpId, BigInteger destDpId, long lportTagOrVni, long elanTag,
             String macAddress, String displayName, ElanInstance elanInstance) throws ElanException {
         List<MatchInfo> mkMatches = new ArrayList<>();
-        mkMatches.add(new MatchInfo(MatchFieldType.metadata,
-                new BigInteger[] { getElanMetadataLabel(elanTag), MetaDataUtil.METADATA_MASK_SERVICE }));
-        mkMatches.add(new MatchInfo(MatchFieldType.eth_dst, new String[] { macAddress }));
+        mkMatches.add(new MatchMetadata(ElanHelper.getElanMetadataLabel(elanTag), MetaDataUtil.METADATA_MASK_SERVICE));
+        mkMatches.add(new MatchEthernetDestination(new MacAddress(macAddress)));
 
         List<Instruction> mkInstructions = new ArrayList<>();
 
@@ -1157,17 +1065,17 @@ public class ElanUtils {
             if (isVlan(elanInstance) || isFlat(elanInstance)) {
                 String interfaceName = getExternalElanInterface(elanInstance.getElanInstanceName(), srcDpId);
                 if (null == interfaceName) {
-                    LOG.error("buildRemoteDmacFlowEntry: Could not find interfaceName for {} {}", srcDpId,
-                            elanInstance);
+                    LOG.info("buildRemoteDmacFlowEntry: Could not find interfaceName for {} {}", srcDpId,
+                        elanInstance);
                 }
                 actions = getEgressActionsForInterface(interfaceName, null);
-            } else {
-                actions = getInternalTunnelItmEgressAction(srcDpId, destDpId, lportTag);
+            } else if (isVxlan(elanInstance)) {
+                actions = elanItmUtils.getInternalTunnelItmEgressAction(srcDpId, destDpId, lportTagOrVni);
             }
             mkInstructions.add(MDSALUtil.buildApplyActionsInstruction(actions));
         } catch (Exception e) {
             LOG.error("Could not get egress actions to add to flow for srcDpId=" + srcDpId + ", destDpId=" + destDpId
-                    + ", lportTag=" + lportTag, e);
+                    + ", lportTag/VNI=" + lportTagOrVni, e);
         }
 
         Flow flow = MDSALUtil.buildFlowNew(NwConstants.ELAN_DMAC_TABLE,
@@ -1187,8 +1095,7 @@ public class ElanUtils {
             return;
         }
         String macAddress = macEntry.getMacAddress().getValue();
-        synchronized (macAddress) {
-            LOG.debug("Acquired lock for mac : " + macAddress + ". Proceeding with remove operation.");
+        synchronized (getElanMacDPNKey(elanInfo.getElanTag(), macAddress, interfaceInfo.getDpId())) {
             deleteMacFlows(elanInfo, interfaceInfo, macAddress, /* alsoDeleteSMAC */ true, deleteFlowGroupTx);
         }
     }
@@ -1217,7 +1124,7 @@ public class ElanUtils {
     private void executeEtreeDeleteMacFlows(ElanInstance elanInfo, InterfaceInfo interfaceInfo, String macAddress,
             boolean deleteSmac, String elanInstanceName, BigInteger srcdpId, Long elanTag, BigInteger dstDpId,
             WriteTransaction deleteFlowGroupTx) {
-        EtreeLeafTagName etreeLeafTag = getEtreeLeafTagByElanTag(elanTag);
+        EtreeLeafTagName etreeLeafTag = elanEtreeUtils.getEtreeLeafTagByElanTag(elanTag);
         if (etreeLeafTag != null) {
             executeDeleteMacFlows(elanInfo, interfaceInfo, macAddress, deleteSmac, elanInstanceName, srcdpId,
                     etreeLeafTag.getEtreeLeafTag().getValue(), dstDpId, deleteFlowGroupTx);
@@ -1291,18 +1198,19 @@ public class ElanUtils {
 
         // Add the ElanState in the elan-state operational data-store
         tx.put(LogicalDatastoreType.OPERATIONAL, getElanInstanceOperationalDataPath(elanInstanceName),
-                elanInfo, true);
+                elanInfo, WriteTransaction.CREATE_MISSING_PARENTS);
 
         // Add the ElanMacTable in the elan-mac-table operational data-store
         MacTable elanMacTable = new MacTableBuilder().setKey(new MacTableKey(elanInstanceName)).build();
         tx.put(LogicalDatastoreType.OPERATIONAL, getElanMacTableOperationalDataPath(elanInstanceName),
-                elanMacTable, true);
+                elanMacTable, WriteTransaction.CREATE_MISSING_PARENTS);
 
         ElanTagNameBuilder elanTagNameBuilder = new ElanTagNameBuilder().setElanTag(elanTag)
                 .setKey(new ElanTagNameKey(elanTag)).setName(elanInstanceName);
         long etreeLeafTag = -1;
         if (isEtreeInstance(elanInstanceAdded)) {
-            etreeLeafTag = retrieveNewElanTag(idManager, elanInstanceName + ElanConstants.LEAVES_POSTFIX);
+            etreeLeafTag = retrieveNewElanTag(idManager,elanInstanceName + ElanConstants
+                    .LEAVES_POSTFIX);
             EtreeLeafTagName etreeLeafTagName = new EtreeLeafTagNameBuilder()
                     .setEtreeLeafTag(new EtreeLeafTag(etreeLeafTag)).build();
             elanTagNameBuilder.addAugmentation(EtreeLeafTagName.class, etreeLeafTagName);
@@ -1328,7 +1236,7 @@ public class ElanUtils {
             elanInstanceBuilder.addAugmentation(EtreeInstance.class, etreeInstance);
         }
         ElanInstance elanInstanceWithTag = elanInstanceBuilder.build();
-        tx.merge(LogicalDatastoreType.CONFIGURATION, getElanInstanceConfigurationDataPath(elanInstanceName),
+        tx.merge(LogicalDatastoreType.CONFIGURATION, ElanHelper.getElanInstanceConfigurationDataPath(elanInstanceName),
                 elanInstanceWithTag, true);
     }
 
@@ -1350,36 +1258,12 @@ public class ElanUtils {
 
         InstanceIdentifier<Node> node = InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(nodeId))
                 .build();
-        Optional<Node> nodePresent = read(broker, LogicalDatastoreType.OPERATIONAL, node);
-        return nodePresent.isPresent();
+        return read(broker, LogicalDatastoreType.CONFIGURATION, node).isPresent();
     }
 
-    public static ServicesInfo getServiceInfo(String elanInstanceName, long elanTag, String interfaceName) {
-        int priority = ElanConstants.ELAN_SERVICE_PRIORITY;
-        int instructionKey = 0;
-        List<Instruction> instructions = new ArrayList<>();
-        instructions.add(MDSALUtil.buildAndGetWriteMetadaInstruction(getElanMetadataLabel(elanTag),
-                MetaDataUtil.METADATA_MASK_SERVICE, ++instructionKey));
-        instructions.add(MDSALUtil.buildAndGetGotoTableInstruction(NwConstants.ELAN_SMAC_TABLE, ++instructionKey));
-
-        short serviceIndex = ServiceIndex.getIndex(NwConstants.ELAN_SERVICE_NAME, NwConstants.ELAN_SERVICE_INDEX);
-        ServicesInfo serviceInfo = InterfaceServiceUtil.buildServiceInfo(
-                String.format("%s.%s", elanInstanceName, interfaceName), serviceIndex, priority,
-                NwConstants.COOKIE_ELAN_INGRESS_TABLE, instructions);
-        return serviceInfo;
-    }
-
-    public static <T extends DataObject> void syncWrite(DataBroker broker, LogicalDatastoreType datastoreType,
-            InstanceIdentifier<T> path, T data) {
-        WriteTransaction tx = broker.newWriteOnlyTransaction();
-        tx.put(datastoreType, path, data, true);
-        CheckedFuture<Void, TransactionCommitFailedException> futures = tx.submit();
-        try {
-            futures.get();
-        } catch (InterruptedException | ExecutionException e) {
-            LOG.error("Error writing to datastore (path, data) : ({}, {})", path, data);
-            throw new RuntimeException(e.getMessage());
-        }
+    public static ServicesInfo getServiceInfo(String elanInstanceName, String interfaceName) {
+        return InterfaceServiceUtil.buildServiceInfo(elanInstanceName + "." + interfaceName,
+                ElanConstants.ELAN_SERVICE_PRIORITY);
     }
 
     public static BoundServices getBoundServices(String serviceName, short servicePriority, int flowPriority,
@@ -1391,160 +1275,16 @@ public class ElanUtils {
                 .addAugmentation(StypeOpenflow.class, augBuilder.build()).build();
     }
 
-    public static InstanceIdentifier<BoundServices> buildServiceId(String vpnInterfaceName, short serviceIndex) {
+    public static InstanceIdentifier<BoundServices> buildServiceId(String interfaceName, short serviceIndex) {
         return InstanceIdentifier.builder(ServiceBindings.class)
-                .child(ServicesInfo.class, new ServicesInfoKey(vpnInterfaceName, ServiceModeIngress.class))
+                .child(ServicesInfo.class, new ServicesInfoKey(interfaceName, ServiceModeIngress.class))
                 .child(BoundServices.class, new BoundServicesKey(serviceIndex)).build();
     }
 
-    /**
-     * Builds the list of actions to be taken when sending the packet over a
-     * VxLan Tunnel Interface, such as setting the tunnel_id field, the vlanId
-     * if proceeds and output the packet over the right port.
-     *
-     * @param tunnelIfaceName
-     *            the tunnel iface name
-     * @param tunnelKey
-     *            the tunnel key
-     * @return the list
-     */
-    public List<Action> buildTunnelItmEgressActions(String tunnelIfaceName, Long tunnelKey) {
-        if (tunnelIfaceName != null && !tunnelIfaceName.isEmpty()) {
-            return buildItmEgressActions(tunnelIfaceName, tunnelKey);
-        }
-
-        return Collections.emptyList();
-    }
-
-    /**
-     * Builds the list of actions to be taken when sending the packet over
-     * external port such as tunnel, physical port etc.
-     *
-     * @param interfaceName
-     *            the interface name
-     * @param tunnelKey
-     *            can be VNI for VxLAN tunnel interfaces, Gre Key for GRE
-     *            tunnels, etc.
-     * @return the list
-     */
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    public List<Action> buildItmEgressActions(String interfaceName, Long tunnelKey) {
-        List<Action> result = Collections.emptyList();
-        try {
-            GetEgressActionsForInterfaceInput getEgressActInput = new GetEgressActionsForInterfaceInputBuilder()
-                    .setIntfName(interfaceName).setTunnelKey(tunnelKey).build();
-
-            Future<RpcResult<GetEgressActionsForInterfaceOutput>> egressActionsOutputFuture = interfaceManagerRpcService
-                    .getEgressActionsForInterface(getEgressActInput);
-            if (egressActionsOutputFuture.get().isSuccessful()) {
-                GetEgressActionsForInterfaceOutput egressActionsOutput = egressActionsOutputFuture.get().getResult();
-                result = egressActionsOutput.getAction();
-            }
-        } catch (Exception e) {
-            LOG.error("Error in RPC call getEgressActionsForInterface {}", e);
-        }
-
-        if (result == null || result.size() == 0) {
-            LOG.warn("Could not build Egress actions for interface {} and tunnelId {}", interfaceName, tunnelKey);
-        }
-        return result;
-    }
-
-    /**
-     * Builds the list of actions to be taken when sending the packet over an
-     * external VxLan tunnel interface, such as stamping the VNI on the VxLAN
-     * header, setting the vlanId if it proceeds and output the packet over the
-     * right port.
-     *
-     * @param srcDpnId
-     *            Dpn where the tunnelInterface is located
-     * @param torNode
-     *            NodeId of the ExternalDevice where the packet must be sent to.
-     * @param vni
-     *            Vni to be stamped on the VxLAN Header.
-     * @return the external itm egress action
-     */
-    public List<Action> getExternalTunnelItmEgressAction(BigInteger srcDpnId, NodeId torNode, long vni) {
-        List<Action> result = Collections.emptyList();
-
-        GetExternalTunnelInterfaceNameInput input = new GetExternalTunnelInterfaceNameInputBuilder()
-                .setDestinationNode(torNode.getValue()).setSourceNode(srcDpnId.toString())
-                .setTunnelType(TunnelTypeVxlan.class).build();
-        Future<RpcResult<GetExternalTunnelInterfaceNameOutput>> output = itmRpcService
-                .getExternalTunnelInterfaceName(input);
-        try {
-            if (output.get().isSuccessful()) {
-                GetExternalTunnelInterfaceNameOutput tunnelInterfaceNameOutput = output.get().getResult();
-                String tunnelIfaceName = tunnelInterfaceNameOutput.getInterfaceName();
-                LOG.debug("Received tunnelInterfaceName from getTunnelInterfaceName RPC {}", tunnelIfaceName);
-
-                result = buildTunnelItmEgressActions(tunnelIfaceName, vni);
-            }
-
-        } catch (InterruptedException | ExecutionException e) {
-            LOG.error("Error in RPC call getTunnelInterfaceName {}", e);
-        }
-
-        return result;
-    }
-
-    /**
-     * Builds the list of actions to be taken when sending the packet over an
-     * internal VxLan tunnel interface, such as setting the serviceTag on the
-     * VNI field of the VxLAN header, setting the vlanId if it proceeds and
-     * output the packet over the right port.
-     *
-     * @param sourceDpnId
-     *            Dpn where the tunnelInterface is located
-     * @param destinationDpnId
-     *            Dpn where the packet must be sent to. It is used here in order
-     *            to select the right tunnel interface.
-     * @param serviceTag
-     *            serviceId to be sent on the VxLAN header.
-     * @return the internal itm egress action
-     */
-    public List<Action> getInternalTunnelItmEgressAction(BigInteger sourceDpnId, BigInteger destinationDpnId,
-            long serviceTag) {
-        List<Action> result = Collections.emptyList();
-
-        LOG.debug("In getInternalItmEgressAction Action source {}, destination {}, elanTag {}", sourceDpnId,
-                destinationDpnId, serviceTag);
-        Class<? extends TunnelTypeBase> tunType = TunnelTypeVxlan.class;
-        GetTunnelInterfaceNameInput input = new GetTunnelInterfaceNameInputBuilder()
-                .setDestinationDpid(destinationDpnId).setSourceDpid(sourceDpnId).setTunnelType(tunType).build();
-        Future<RpcResult<GetTunnelInterfaceNameOutput>> output = itmRpcService
-                .getTunnelInterfaceName(input);
-        try {
-            if (output.get().isSuccessful()) {
-                GetTunnelInterfaceNameOutput tunnelInterfaceNameOutput = output.get().getResult();
-                String tunnelIfaceName = tunnelInterfaceNameOutput.getInterfaceName();
-                LOG.debug("Received tunnelInterfaceName from getTunnelInterfaceName RPC {}", tunnelIfaceName);
-
-                result = buildTunnelItmEgressActions(tunnelIfaceName, serviceTag);
-            }
-        } catch (InterruptedException | ExecutionException e) {
-            LOG.error("Error in RPC call getTunnelInterfaceName {}", e);
-        }
-
-        return result;
-    }
-
-    /**
-     * Build the list of actions to be taken when sending the packet to external
-     * (physical) port.
-     *
-     * @param interfaceName
-     *            Interface name
-     * @return the external port itm egress actions
-     */
-    public List<Action> getExternalPortItmEgressAction(String interfaceName) {
-        return buildItmEgressActions(interfaceName, null);
-    }
-
     public static List<MatchInfo> getTunnelMatchesForServiceId(int elanTag) {
         List<MatchInfo> mkMatches = new ArrayList<>();
         // Matching metadata
-        mkMatches.add(new MatchInfo(MatchFieldType.tunnel_id, new BigInteger[] { BigInteger.valueOf(elanTag) }));
+        mkMatches.add(new MatchTunnelId(BigInteger.valueOf(elanTag)));
 
         return mkMatches;
     }
@@ -1552,40 +1292,22 @@ public class ElanUtils {
     public void removeTerminatingServiceAction(BigInteger destDpId, int serviceId) {
         RemoveTerminatingServiceActionsInput input = new RemoveTerminatingServiceActionsInputBuilder()
                 .setDpnId(destDpId).setServiceId(serviceId).build();
-        Future<RpcResult<Void>> futureObject = itmRpcService
-                .removeTerminatingServiceActions(input);
+        Future<RpcResult<Void>> futureObject = itmRpcService.removeTerminatingServiceActions(input);
         try {
             RpcResult<Void> result = futureObject.get();
             if (result.isSuccessful()) {
-                LOG.debug("Successfully completed removeTerminatingServiceActions");
+                LOG.debug("Successfully completed removeTerminatingServiceActions for ELAN with serviceId {} on "
+                                + "dpn {}", serviceId, destDpId);
             } else {
-                LOG.debug("Failure in removeTerminatingServiceAction RPC call");
+                LOG.debug("Failure in removeTerminatingServiceAction RPC call for ELAN with serviceId {} on "
+                        + "dpn {}", serviceId, destDpId);
             }
         } catch (InterruptedException | ExecutionException e) {
-            LOG.error("Error in RPC call removeTerminatingServiceActions {}", e);
+            LOG.error("Error in RPC call removeTerminatingServiceActions for ELAN with serviceId {} on "
+                    + "dpn {}: {}", serviceId, destDpId, e);
         }
     }
 
-    public void createTerminatingServiceActions(BigInteger destDpId, int serviceId, List<Action> actions) {
-        List<Instruction> mkInstructions = new ArrayList<>();
-        mkInstructions.add(MDSALUtil.buildApplyActionsInstruction(actions));
-        CreateTerminatingServiceActionsInput input = new CreateTerminatingServiceActionsInputBuilder()
-                .setDpnId(destDpId).setServiceId(serviceId).setInstruction(mkInstructions).build();
-
-        itmRpcService.createTerminatingServiceActions(input);
-    }
-
-    public static TunnelList buildInternalTunnel(DataBroker broker) {
-        InstanceIdentifier<TunnelList> tunnelListInstanceIdentifier = InstanceIdentifier.builder(TunnelList.class)
-                .build();
-        Optional<TunnelList> tunnelList = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION,
-                tunnelListInstanceIdentifier);
-        if (tunnelList.isPresent()) {
-            return tunnelList.get();
-        }
-        return null;
-    }
-
     /**
      * Gets the external tunnel.
      *
@@ -1599,15 +1321,10 @@ public class ElanUtils {
      */
     public ExternalTunnel getExternalTunnel(String sourceDevice, String destinationDevice,
             LogicalDatastoreType datastoreType) {
-        ExternalTunnel externalTunnel = null;
         Class<? extends TunnelTypeBase> tunType = TunnelTypeVxlan.class;
         InstanceIdentifier<ExternalTunnel> iid = InstanceIdentifier.builder(ExternalTunnelList.class)
                 .child(ExternalTunnel.class, new ExternalTunnelKey(destinationDevice, sourceDevice, tunType)).build();
-        Optional<ExternalTunnel> tunnelList = read(broker, datastoreType, iid);
-        if (tunnelList.isPresent()) {
-            externalTunnel = tunnelList.get();
-        }
-        return externalTunnel;
+        return read(broker, datastoreType, iid).orNull();
     }
 
     /**
@@ -1639,377 +1356,19 @@ public class ElanUtils {
      * @return the all external tunnels
      */
     public List<ExternalTunnel> getAllExternalTunnels(LogicalDatastoreType datastoreType) {
-        List<ExternalTunnel> result = null;
         InstanceIdentifier<ExternalTunnelList> iid = InstanceIdentifier.builder(ExternalTunnelList.class).build();
-        Optional<ExternalTunnelList> tunnelList = read(broker, datastoreType, iid);
-        if (tunnelList.isPresent()) {
-            result = tunnelList.get().getExternalTunnel();
-        }
-        if (result == null) {
-            result = Collections.emptyList();
-        }
-        return result;
-    }
-
-    /**
-     * Installs a Flow in a DPN's DMAC table. The Flow is for a MAC that is
-     * connected remotely in another CSS and accessible through an internal
-     * tunnel. It also installs the flow for dropping the packet if it came over
-     * an ITM tunnel (that is, if the Split-Horizon flag is set)
-     *
-     * @param localDpId
-     *            Id of the DPN where the MAC Addr is accessible locally
-     * @param remoteDpId
-     *            Id of the DPN where the flow must be installed
-     * @param lportTag
-     *            lportTag of the interface where the mac is connected to.
-     * @param elanTag
-     *            Identifier of the ELAN
-     * @param macAddress
-     *            MAC to be installed in remoteDpId's DMAC table
-     * @param displayName
-     *            the display name
-     * @throws ElanException in case of issues creating the flow objects
-     */
-    public void installDmacFlowsToInternalRemoteMac(BigInteger localDpId, BigInteger remoteDpId, long lportTag,
-            long elanTag, String macAddress, String displayName) throws ElanException {
-        Flow flow = buildDmacFlowForInternalRemoteMac(localDpId, remoteDpId, lportTag, elanTag, macAddress,
-                displayName);
-        mdsalManager.installFlow(remoteDpId, flow);
-    }
-
-    /**
-     * Installs a Flow in the specified DPN's DMAC table. The flow is for a MAC
-     * that is connected remotely in an External Device (TOR) and that is
-     * accessible through an external tunnel. It also installs the flow for
-     * dropping the packet if it came over an ITM tunnel (that is, if the
-     * Split-Horizon flag is set)
-     *
-     * @param dpnId
-     *            Id of the DPN where the flow must be installed
-     * @param extDeviceNodeId
-     *            the ext device node id
-     * @param elanTag
-     *            the elan tag
-     * @param vni
-     *            the vni
-     * @param macAddress
-     *            the mac address
-     * @param displayName
-     *            the display name
-     * @param interfaceName
-     *            the interface name
-     *
-     * @return the dmac flows
-     * @throws ElanException in case of issues creating the flow objects
-     */
-    public List<ListenableFuture<Void>> installDmacFlowsToExternalRemoteMac(BigInteger dpnId,
-            String extDeviceNodeId, Long elanTag, Long vni, String macAddress, String displayName,
-            String interfaceName) throws ElanException {
-        List<ListenableFuture<Void>> futures = new ArrayList<>();
-        synchronized (macAddress) {
-            Flow flow = buildDmacFlowForExternalRemoteMac(dpnId, extDeviceNodeId, elanTag, vni, macAddress,
-                    displayName);
-            futures.add(mdsalManager.installFlow(dpnId, flow));
-
-            Flow dropFlow = buildDmacFlowDropIfPacketComingFromTunnel(dpnId, extDeviceNodeId, elanTag, macAddress);
-            futures.add(mdsalManager.installFlow(dpnId, dropFlow));
-            installEtreeDmacFlowsToExternalRemoteMac(dpnId, extDeviceNodeId, elanTag, vni, macAddress, displayName,
-                    interfaceName, futures);
-        }
-        return futures;
-    }
-
-    private void installEtreeDmacFlowsToExternalRemoteMac(BigInteger dpnId, String extDeviceNodeId, Long elanTag,
-            Long vni, String macAddress, String displayName, String interfaceName,
-            List<ListenableFuture<Void>> futures) throws ElanException {
-        EtreeLeafTagName etreeLeafTag = getEtreeLeafTagByElanTag(elanTag);
-        if (etreeLeafTag != null) {
-            buildEtreeDmacFlowDropIfPacketComingFromTunnel(dpnId, extDeviceNodeId, elanTag, macAddress, futures,
-                    etreeLeafTag);
-            buildEtreeDmacFlowForExternalRemoteMac(dpnId, extDeviceNodeId, vni, macAddress, displayName, interfaceName,
-                    futures, etreeLeafTag);
-        }
-    }
-
-    private void buildEtreeDmacFlowForExternalRemoteMac(BigInteger dpnId, String extDeviceNodeId, Long vni,
-            String macAddress, String displayName, String interfaceName, List<ListenableFuture<Void>> futures,
-            EtreeLeafTagName etreeLeafTag) throws ElanException {
-        boolean isRoot = false;
-        if (interfaceName == null) {
-            isRoot = true;
-        } else {
-            EtreeInterface etreeInterface = getEtreeInterfaceByElanInterfaceName(broker, interfaceName);
-            if (etreeInterface != null) {
-                if (etreeInterface.getEtreeInterfaceType() == EtreeInterfaceType.Root) {
-                    isRoot = true;
-                }
-            }
-        }
-        if (isRoot) {
-            Flow flow = buildDmacFlowForExternalRemoteMac(dpnId, extDeviceNodeId,
-                    etreeLeafTag.getEtreeLeafTag().getValue(), vni, macAddress, displayName);
-            futures.add(mdsalManager.installFlow(dpnId, flow));
-        }
-    }
-
-    private void buildEtreeDmacFlowDropIfPacketComingFromTunnel(BigInteger dpnId, String extDeviceNodeId,
-            Long elanTag, String macAddress, List<ListenableFuture<Void>> futures, EtreeLeafTagName etreeLeafTag) {
-        if (etreeLeafTag != null) {
-            Flow dropFlow = buildDmacFlowDropIfPacketComingFromTunnel(dpnId, extDeviceNodeId,
-                    etreeLeafTag.getEtreeLeafTag().getValue(), macAddress);
-            futures.add(mdsalManager.installFlow(dpnId, dropFlow));
-        }
+        return read(broker, datastoreType, iid).toJavaUtil().map(ExternalTunnelList::getExternalTunnel).orElse(
+                Collections.emptyList());
     }
 
     public static List<MatchInfo> buildMatchesForElanTagShFlagAndDstMac(long elanTag, boolean shFlag, String macAddr) {
         List<MatchInfo> mkMatches = new ArrayList<>();
-        mkMatches.add(new MatchInfo(MatchFieldType.metadata, new BigInteger[] {
-                getElanMetadataLabel(elanTag, shFlag), MetaDataUtil.METADATA_MASK_SERVICE_SH_FLAG }));
-        mkMatches.add(new MatchInfo(MatchFieldType.eth_dst, new String[] { macAddr }));
-
+        mkMatches.add(
+                new MatchMetadata(getElanMetadataLabel(elanTag, shFlag), MetaDataUtil.METADATA_MASK_SERVICE_SH_FLAG));
+        mkMatches.add(new MatchEthernetDestination(new MacAddress(macAddr)));
         return mkMatches;
     }
 
-    /**
-     * Builds a Flow to be programmed in a DPN's DMAC table. This method must be
-     * used when the MAC is located in an External Device (TOR). The flow
-     * matches on the specified MAC and 1) sends the packet over the CSS-TOR
-     * tunnel if SHFlag is not set, or 2) drops it if SHFlag is set (what means
-     * the packet came from an external tunnel)
-     *
-     * @param dpId
-     *            DPN whose DMAC table is going to be modified
-     * @param extDeviceNodeId
-     *            Hwvtep node where the mac is attached to
-     * @param elanTag
-     *            ElanId to which the MAC is being added to
-     * @param vni
-     *            the vni
-     * @param dstMacAddress
-     *            The mac address to be programmed
-     * @param displayName
-     *            the display name
-     * @return the flow
-     * @throws ElanException in case of issues creating the flow objects
-     */
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    public Flow buildDmacFlowForExternalRemoteMac(BigInteger dpId, String extDeviceNodeId, long elanTag,
-            Long vni, String dstMacAddress, String displayName) throws ElanException {
-        List<MatchInfo> mkMatches = buildMatchesForElanTagShFlagAndDstMac(elanTag, /* shFlag */ false, dstMacAddress);
-        List<Instruction> mkInstructions = new ArrayList<>();
-        try {
-            List<Action> actions = getExternalTunnelItmEgressAction(dpId, new NodeId(extDeviceNodeId), vni);
-            mkInstructions.add(MDSALUtil.buildApplyActionsInstruction(actions));
-        } catch (Exception e) {
-            LOG.error("Could not get Egress Actions for DpId=" + dpId + ", externalNode=" + extDeviceNodeId, e);
-        }
-
-        Flow flow = MDSALUtil.buildFlowNew(NwConstants.ELAN_DMAC_TABLE,
-                getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpId, extDeviceNodeId, dstMacAddress, elanTag,
-                        false),
-                20, /* prio */
-                displayName, 0, /* idleTimeout */
-                0, /* hardTimeout */
-                ElanConstants.COOKIE_ELAN_KNOWN_DMAC.add(BigInteger.valueOf(elanTag)), mkMatches, mkInstructions);
-
-        return flow;
-    }
-
-    /**
-     * Builds the flow that drops the packet if it came through an external
-     * tunnel, that is, if the Split-Horizon flag is set.
-     *
-     * @param dpnId
-     *            DPN whose DMAC table is going to be modified
-     * @param extDeviceNodeId
-     *            Hwvtep node where the mac is attached to
-     * @param elanTag
-     *            ElanId to which the MAC is being added to
-     * @param dstMacAddress
-     *            The mac address to be programmed
-     */
-    private static Flow buildDmacFlowDropIfPacketComingFromTunnel(BigInteger dpnId, String extDeviceNodeId,
-            Long elanTag, String dstMacAddress) {
-        List<MatchInfo> mkMatches = buildMatchesForElanTagShFlagAndDstMac(elanTag, /* shFlag */ true, dstMacAddress);
-        List<Instruction> mkInstructions = MDSALUtil.buildInstructionsDrop();
-        String flowId = getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpnId, extDeviceNodeId, dstMacAddress,
-                elanTag, true);
-        Flow flow = MDSALUtil.buildFlowNew(NwConstants.ELAN_DMAC_TABLE, flowId, 20, /* prio */
-                "Drop", 0, /* idleTimeout */
-                0, /* hardTimeout */
-                ElanConstants.COOKIE_ELAN_KNOWN_DMAC.add(BigInteger.valueOf(elanTag)), mkMatches, mkInstructions);
-
-        return flow;
-    }
-
-    private static String getDmacDropFlowId(Long elanTag, String dstMacAddress) {
-        return new StringBuilder(NwConstants.ELAN_DMAC_TABLE).append(elanTag).append(dstMacAddress).append("Drop")
-                .toString();
-    }
-
-    /**
-     * Builds a Flow to be programmed in a remote DPN's DMAC table. This method
-     * must be used when the MAC is located in another CSS.
-     *
-     * <p>This flow consists in: Match: + elanTag in packet's metadata + packet
-     * going to a MAC known to be located in another DPN Actions: +
-     * set_tunnel_id(lportTag) + output on ITM internal tunnel interface with
-     * the other DPN
-     *
-     * @param localDpId
-     *            the local dp id
-     * @param remoteDpId
-     *            the remote dp id
-     * @param lportTag
-     *            the lport tag
-     * @param elanTag
-     *            the elan tag
-     * @param macAddress
-     *            the mac address
-     * @param displayName
-     *            the display name
-     * @return the flow
-     * @throws ElanException in case of issues creating the flow objects
-     */
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    public Flow buildDmacFlowForInternalRemoteMac(BigInteger localDpId, BigInteger remoteDpId, long lportTag,
-            long elanTag, String macAddress, String displayName) throws ElanException {
-        List<MatchInfo> mkMatches = buildMatchesForElanTagShFlagAndDstMac(elanTag, /* shFlag */ false, macAddress);
-
-        List<Instruction> mkInstructions = new ArrayList<>();
-
-        try {
-            // List of Action for the provided Source and Destination DPIDs
-            List<Action> actions = getInternalTunnelItmEgressAction(localDpId, remoteDpId, lportTag);
-            mkInstructions.add(MDSALUtil.buildApplyActionsInstruction(actions));
-        } catch (Exception e) {
-            LOG.error("Could not get Egress Actions for localDpId=" + localDpId + ", remoteDpId="
-                    + remoteDpId + ", lportTag=" + lportTag, e);
-        }
-
-        Flow flow = MDSALUtil.buildFlowNew(NwConstants.ELAN_DMAC_TABLE,
-                getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, localDpId, remoteDpId, macAddress, elanTag),
-                20, /* prio */
-                displayName, 0, /* idleTimeout */
-                0, /* hardTimeout */
-                ElanConstants.COOKIE_ELAN_KNOWN_DMAC.add(BigInteger.valueOf(elanTag)), mkMatches, mkInstructions);
-
-        return flow;
-
-    }
-
-    /**
-     * Installs or removes flows in DMAC table for MACs that are/were located in
-     * an external Elan Device.
-     *
-     * @param dpId
-     *            Id of the DPN where the DMAC table is going to be modified
-     * @param extNodeId
-     *            Id of the External Device where the MAC is located
-     * @param elanTag
-     *            Id of the ELAN
-     * @param vni
-     *            VNI of the LogicalSwitch to which the MAC belongs to, and that
-     *            is associated with the ELAN
-     * @param macAddress
-     *            the mac address
-     * @param elanInstanceName
-     *            the elan instance name
-     * @param addOrRemove
-     *            Indicates if flows must be installed or removed.
-     * @param interfaceName
-     *            the interface name
-     * @throws ElanException in case of issues creating the flow objects
-     * @see org.opendaylight.genius.mdsalutil.MDSALUtil.MdsalOp
-     */
-    public void setupDmacFlowsToExternalRemoteMac(BigInteger dpId, String extNodeId, Long elanTag, Long vni,
-            String macAddress, String elanInstanceName, MdsalOp addOrRemove, String interfaceName)
-            throws ElanException {
-        if (addOrRemove == MdsalOp.CREATION_OP) {
-            installDmacFlowsToExternalRemoteMac(dpId, extNodeId, elanTag, vni, macAddress, elanInstanceName,
-                    interfaceName);
-        } else if (addOrRemove == MdsalOp.REMOVAL_OP) {
-            deleteDmacFlowsToExternalMac(elanTag, dpId, extNodeId, macAddress);
-        }
-    }
-
-    /**
-     * Delete dmac flows to external mac.
-     *
-     * @param elanTag
-     *            the elan tag
-     * @param dpId
-     *            the dp id
-     * @param extDeviceNodeId
-     *            the ext device node id
-     * @param macToRemove
-     *            the mac to remove
-     * @return dmac flow
-     */
-    public List<ListenableFuture<Void>> deleteDmacFlowsToExternalMac(long elanTag, BigInteger dpId,
-            String extDeviceNodeId, String macToRemove) {
-        List<ListenableFuture<Void>> futures = new ArrayList<>();
-        synchronized (macToRemove) {
-            // Removing the flows that sends the packet on an external tunnel
-            removeFlowThatSendsThePacketOnAnExternalTunnel(elanTag, dpId, extDeviceNodeId, macToRemove, futures);
-
-            // And now removing the drop flow
-            removeTheDropFlow(elanTag, dpId, extDeviceNodeId, macToRemove, futures);
-
-            deleteEtreeDmacFlowsToExternalMac(elanTag, dpId, extDeviceNodeId, macToRemove, futures);
-        }
-        return futures;
-    }
-
-    private void deleteEtreeDmacFlowsToExternalMac(long elanTag, BigInteger dpId, String extDeviceNodeId,
-            String macToRemove, List<ListenableFuture<Void>> futures) {
-        EtreeLeafTagName etreeLeafTag = getEtreeLeafTagByElanTag(elanTag);
-        if (etreeLeafTag != null) {
-            removeFlowThatSendsThePacketOnAnExternalTunnel(etreeLeafTag.getEtreeLeafTag().getValue(), dpId,
-                    extDeviceNodeId, macToRemove, futures);
-            removeTheDropFlow(etreeLeafTag.getEtreeLeafTag().getValue(), dpId, extDeviceNodeId, macToRemove, futures);
-        }
-    }
-
-    private void removeTheDropFlow(long elanTag, BigInteger dpId, String extDeviceNodeId, String macToRemove,
-            List<ListenableFuture<Void>> futures) {
-        String flowId = getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpId, extDeviceNodeId, macToRemove,
-                elanTag, true);
-        Flow flowToRemove = new FlowBuilder().setId(new FlowId(flowId)).setTableId(NwConstants.ELAN_DMAC_TABLE).build();
-        futures.add(mdsalManager.removeFlow(dpId, flowToRemove));
-    }
-
-    private void removeFlowThatSendsThePacketOnAnExternalTunnel(long elanTag, BigInteger dpId,
-            String extDeviceNodeId, String macToRemove, List<ListenableFuture<Void>> futures) {
-        String flowId = getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpId, extDeviceNodeId, macToRemove,
-                elanTag, false);
-        Flow flowToRemove = new FlowBuilder().setId(new FlowId(flowId)).setTableId(NwConstants.ELAN_DMAC_TABLE).build();
-        futures.add(mdsalManager.removeFlow(dpId, flowToRemove));
-    }
-
-    /**
-     * Gets the dpid from interface.
-     *
-     * @param interfaceName
-     *            the interface name
-     * @return the dpid from interface
-     */
-    public BigInteger getDpidFromInterface(String interfaceName) {
-        BigInteger dpId = null;
-        Future<RpcResult<GetDpidFromInterfaceOutput>> output = interfaceManagerRpcService
-                .getDpidFromInterface(new GetDpidFromInterfaceInputBuilder().setIntfName(interfaceName).build());
-        try {
-            RpcResult<GetDpidFromInterfaceOutput> rpcResult = output.get();
-            if (rpcResult.isSuccessful()) {
-                dpId = rpcResult.getResult().getDpid();
-            }
-        } catch (NullPointerException | InterruptedException | ExecutionException e) {
-            LOG.error("Failed to get the DPN ID: {} for interface {}: {} ", dpId, interfaceName, e);
-        }
-        return dpId;
-    }
-
     /**
      * Checks if is interface operational.
      *
@@ -2045,36 +1404,7 @@ public class ElanUtils {
         InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
             .ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId = createInterfaceStateInstanceIdentifier(
                 interfaceName);
-        Optional<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
-            .ietf.interfaces.rev140508.interfaces.state.Interface> ifStateOptional = MDSALUtil
-                .read(dataBroker, LogicalDatastoreType.OPERATIONAL, ifStateId);
-        if (ifStateOptional.isPresent()) {
-            return ifStateOptional.get();
-        }
-        return null;
-    }
-
-    /**
-     * Gets the interface from config ds.
-     *
-     * @param interfaceName
-     *            the interface name
-     * @param dataBroker
-     *            the data broker
-     * @return the interface from config ds
-     */
-    public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
-        .ietf.interfaces.rev140508.interfaces.Interface getInterfaceFromConfigDS(
-            String interfaceName, DataBroker dataBroker) {
-        InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
-            .ietf.interfaces.rev140508.interfaces.Interface> ifaceId = createInterfaceInstanceIdentifier(interfaceName);
-        Optional<org.opendaylight.yang.gen.v1.urn
-            .ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface> iface = MDSALUtil
-                .read(dataBroker, LogicalDatastoreType.CONFIGURATION, ifaceId);
-        if (iface.isPresent()) {
-            return iface.get();
-        }
-        return null;
+        return MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, ifStateId).orNull();
     }
 
     /**
@@ -2098,27 +1428,6 @@ public class ElanUtils {
         return idBuilder.build();
     }
 
-    /**
-     * Creates the interface instance identifier.
-     *
-     * @param interfaceName
-     *            the interface name
-     * @return the instance identifier
-     */
-    public static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
-        .ietf.interfaces.rev140508.interfaces.Interface> createInterfaceInstanceIdentifier(
-            String interfaceName) {
-        InstanceIdentifierBuilder<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
-            .ietf.interfaces.rev140508.interfaces.Interface> idBuilder = InstanceIdentifier
-                .builder(Interfaces.class)
-                .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
-                        .ietf.interfaces.rev140508.interfaces.Interface.class,
-                        new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
-                            .ietf.interfaces.rev140508.interfaces.InterfaceKey(
-                                interfaceName));
-        return idBuilder.build();
-    }
-
     public static CheckedFuture<Void, TransactionCommitFailedException> waitForTransactionToComplete(
             WriteTransaction tx) {
         CheckedFuture<Void, TransactionCommitFailedException> futures = tx.submit();
@@ -2130,16 +1439,60 @@ public class ElanUtils {
         return futures;
     }
 
+    public static boolean isVxlanNetwork(DataBroker broker, String elanInstanceName) {
+        ElanInstance elanInstance = getElanInstanceByName(broker, elanInstanceName);
+        return elanInstance != null && isVxlan(elanInstance);
+    }
+
     public static boolean isVxlan(ElanInstance elanInstance) {
         return elanInstance != null && elanInstance.getSegmentType() != null
                 && elanInstance.getSegmentType().isAssignableFrom(SegmentTypeVxlan.class)
-                && elanInstance.getSegmentationId() != null && elanInstance.getSegmentationId().longValue() != 0;
+                && elanInstance.getSegmentationId() != null && elanInstance.getSegmentationId() != 0;
+    }
+
+    private static boolean isVxlanSegment(ElanInstance elanInstance) {
+        if (elanInstance != null) {
+            List<ElanSegments> elanSegments = elanInstance.getElanSegments();
+            if (elanSegments != null) {
+                for (ElanSegments segment : elanSegments) {
+                    if (segment != null && segment.getSegmentType().isAssignableFrom(SegmentTypeVxlan.class)
+                            && segment.getSegmentationId() != null
+                            && segment.getSegmentationId().longValue() != 0) {
+                        return true;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+    public static boolean isVxlanNetworkOrVxlanSegment(ElanInstance elanInstance) {
+        return isVxlan(elanInstance) || isVxlanSegment(elanInstance);
+    }
+
+    public static Long getVxlanSegmentationId(ElanInstance elanInstance) {
+        Long segmentationId = 0L;
+
+        if (elanInstance != null && elanInstance.getSegmentType() != null
+                && elanInstance.getSegmentType().isAssignableFrom(SegmentTypeVxlan.class)
+                && elanInstance.getSegmentationId() != null && elanInstance.getSegmentationId().longValue() != 0) {
+            segmentationId = elanInstance.getSegmentationId();
+        } else {
+            for (ElanSegments segment: elanInstance.getElanSegments()) {
+                if (segment != null && segment.getSegmentType().isAssignableFrom(SegmentTypeVxlan.class)
+                    && segment.getSegmentationId() != null
+                    && segment.getSegmentationId().longValue() != 0) {
+                    segmentationId = segment.getSegmentationId();
+                }
+            }
+        }
+        return segmentationId;
     }
 
     public static boolean isVlan(ElanInstance elanInstance) {
         return elanInstance != null && elanInstance.getSegmentType() != null
                 && elanInstance.getSegmentType().isAssignableFrom(SegmentTypeVlan.class)
-                && elanInstance.getSegmentationId() != null && elanInstance.getSegmentationId().longValue() != 0;
+                && elanInstance.getSegmentationId() != null && elanInstance.getSegmentationId() != 0;
     }
 
     public static boolean isFlat(ElanInstance elanInstance) {
@@ -2147,56 +1500,33 @@ public class ElanUtils {
                 && elanInstance.getSegmentType().isAssignableFrom(SegmentTypeFlat.class);
     }
 
-    public boolean isExternal(String interfaceName) {
-        return isExternal(getInterfaceFromConfigDS(interfaceName, broker));
-    }
-
-    public static boolean isExternal(
-            org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
-            .ietf.interfaces.rev140508.interfaces.Interface iface) {
-        if (iface == null) {
-            return false;
-        }
-
-        IfExternal ifExternal = iface.getAugmentation(IfExternal.class);
-        return ifExternal != null && Boolean.TRUE.equals(ifExternal.isExternal());
-    }
-
-    public static boolean isEtreeRootInterfaceByInterfaceName(DataBroker broker, String interfaceName) {
-        EtreeInterface etreeInterface = getEtreeInterfaceByElanInterfaceName(broker, interfaceName);
-        if (etreeInterface != null && etreeInterface.getEtreeInterfaceType() == EtreeInterfaceType.Root) {
-            return true;
+    public void addDmacRedirectToDispatcherFlows(Long elanTag, String displayName,
+            String macAddress, List<BigInteger> dpnIds) {
+        for (BigInteger dpId : dpnIds) {
+            WriteTransaction writeTx = broker.newWriteOnlyTransaction();
+            mdsalManager.addFlowToTx(buildDmacRedirectToDispatcherFlow(dpId, macAddress, displayName, elanTag),
+                    writeTx);
+            writeTx.submit();
         }
-        return false;
     }
 
-    public void handleDmacRedirectToDispatcherFlows(Long elanTag, String displayName,
-            String macAddress, int addOrRemove, List<BigInteger> dpnIds) {
+    public void removeDmacRedirectToDispatcherFlows(Long elanTag, String macAddress, List<BigInteger> dpnIds) {
         for (BigInteger dpId : dpnIds) {
-            if (addOrRemove == NwConstants.ADD_FLOW) {
-                WriteTransaction writeTx = broker.newWriteOnlyTransaction();
-                mdsalManager.addFlowToTx(buildDmacRedirectToDispatcherFlow(dpId, macAddress, displayName, elanTag),
-                        writeTx);
-                writeTx.submit();
-            } else {
-                String flowId = getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpId, macAddress, elanTag);
-                mdsalManager.removeFlow(dpId, MDSALUtil.buildFlow(NwConstants.ELAN_DMAC_TABLE, flowId));
-            }
+            String flowId = getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpId, macAddress, elanTag);
+            mdsalManager.removeFlow(dpId, MDSALUtil.buildFlow(NwConstants.ELAN_DMAC_TABLE, flowId));
         }
     }
 
     public static FlowEntity buildDmacRedirectToDispatcherFlow(BigInteger dpId, String dstMacAddress,
             String displayName, long elanTag) {
-        List<MatchInfo> matches = new ArrayList<MatchInfo>();
-        matches.add(new MatchInfo(MatchFieldType.metadata,
-                new BigInteger[] { getElanMetadataLabel(elanTag), MetaDataUtil.METADATA_MASK_SERVICE }));
-        matches.add(new MatchInfo(MatchFieldType.eth_dst, new String[] { dstMacAddress }));
-        List<InstructionInfo> instructions = new ArrayList<InstructionInfo>();
-        List<ActionInfo> actions = new ArrayList<ActionInfo>();
-        actions.add(new ActionInfo(ActionType.nx_resubmit,
-                new String[] { String.valueOf(NwConstants.LPORT_DISPATCHER_TABLE) }));
-
-        instructions.add(new InstructionInfo(InstructionType.apply_actions, actions));
+        List<MatchInfo> matches = new ArrayList<>();
+        matches.add(new MatchMetadata(ElanHelper.getElanMetadataLabel(elanTag), MetaDataUtil.METADATA_MASK_SERVICE));
+        matches.add(new MatchEthernetDestination(new MacAddress(dstMacAddress)));
+        List<InstructionInfo> instructions = new ArrayList<>();
+        List<ActionInfo> actions = new ArrayList<>();
+        actions.add(new ActionNxResubmit(NwConstants.LPORT_DISPATCHER_TABLE));
+
+        instructions.add(new InstructionApplyActions(actions));
         String flowId = getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpId, dstMacAddress, elanTag);
         FlowEntity flow  = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_DMAC_TABLE, flowId, 20, displayName, 0, 0,
                 ElanConstants.COOKIE_ELAN_KNOWN_DMAC.add(BigInteger.valueOf(elanTag)),
@@ -2204,26 +1534,12 @@ public class ElanUtils {
         return flow;
     }
 
-    public static FlowEntity buildDmacRedirectToDispatcherFlowMacNoActions(BigInteger dpId, String dstMacAddress,
-            String displayName, long elanTag) {
-        List<MatchInfo> matches = new ArrayList<MatchInfo>();
-        matches.add(new MatchInfo(MatchFieldType.metadata,
-                new BigInteger[] { getElanMetadataLabel(elanTag), MetaDataUtil.METADATA_MASK_SERVICE }));
-        matches.add(new MatchInfo(MatchFieldType.eth_dst, new String[] { dstMacAddress }));
-
-        String flowId = getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpId, dstMacAddress, elanTag);
-        FlowEntity flow  = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_DMAC_TABLE, flowId, 20, displayName, 0, 0,
-                ElanConstants.COOKIE_ELAN_KNOWN_DMAC.add(BigInteger.valueOf(elanTag)),
-                matches, new ArrayList<InstructionInfo>());
-        return flow;
-    }
-
     /**
      * Add Mac Address to ElanInterfaceForwardingEntries and ElanForwardingTables
      * Install SMAC and DMAC flows.
      */
     public void addMacEntryToDsAndSetupFlows(IInterfaceManager interfaceManager, String interfaceName,
-            String macAddress, String elanName, WriteTransaction tx, WriteTransaction flowWritetx, int macTimeOut)
+            String macAddress, String elanName, WriteTransaction interfaceTx, WriteTransaction flowTx, int macTimeOut)
             throws ElanException {
         LOG.trace("Adding mac address {} and interface name {} to ElanInterfaceForwardingEntries and "
             + "ElanForwardingTables DS", macAddress, interfaceName);
@@ -2234,12 +1550,12 @@ public class ElanUtils {
                 .setIsStaticAddress(false).build();
         InstanceIdentifier<MacEntry> macEntryId = ElanUtils
                 .getInterfaceMacEntriesIdentifierOperationalDataPath(interfaceName, physAddress);
-        tx.put(LogicalDatastoreType.OPERATIONAL, macEntryId, macEntry);
+        interfaceTx.put(LogicalDatastoreType.OPERATIONAL, macEntryId, macEntry);
         InstanceIdentifier<MacEntry> elanMacEntryId = ElanUtils.getMacEntryOperationalDataPath(elanName, physAddress);
-        tx.put(LogicalDatastoreType.OPERATIONAL, elanMacEntryId, macEntry);
+        interfaceTx.put(LogicalDatastoreType.OPERATIONAL, elanMacEntryId, macEntry);
         ElanInstance elanInstance = ElanUtils.getElanInstanceByName(broker, elanName);
-        setupMacFlows(elanInstance, interfaceManager.getInterfaceInfo(interfaceName), macTimeOut, macAddress,
-                flowWritetx);
+        setupMacFlows(elanInstance, interfaceManager.getInterfaceInfo(interfaceName), macTimeOut, macAddress, true,
+                flowTx);
     }
 
     /**
@@ -2247,18 +1563,18 @@ public class ElanUtils {
      * Remove SMAC and DMAC flows.
      */
     public void deleteMacEntryFromDsAndRemoveFlows(IInterfaceManager interfaceManager, String interfaceName,
-            String macAddress, String elanName, WriteTransaction tx, WriteTransaction deleteFlowTx) {
+            String macAddress, String elanName, WriteTransaction interfaceTx, WriteTransaction flowTx) {
         LOG.trace("Deleting mac address {} and interface name {} from ElanInterfaceForwardingEntries "
                 + "and ElanForwardingTables DS", macAddress, interfaceName);
         PhysAddress physAddress = new PhysAddress(macAddress);
         MacEntry macEntry = getInterfaceMacEntriesOperationalDataPath(interfaceName, physAddress);
         InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(interfaceName);
         if (macEntry != null && interfaceInfo != null) {
-            deleteMacFlows(ElanUtils.getElanInstanceByName(broker, elanName), interfaceInfo, macEntry, deleteFlowTx);
+            deleteMacFlows(ElanUtils.getElanInstanceByName(broker, elanName), interfaceInfo, macEntry, flowTx);
         }
-        tx.delete(LogicalDatastoreType.OPERATIONAL,
+        interfaceTx.delete(LogicalDatastoreType.OPERATIONAL,
                 ElanUtils.getInterfaceMacEntriesIdentifierOperationalDataPath(interfaceName, physAddress));
-        tx.delete(LogicalDatastoreType.OPERATIONAL,
+        interfaceTx.delete(LogicalDatastoreType.OPERATIONAL,
                 ElanUtils.getMacEntryOperationalDataPath(elanName, physAddress));
     }
 
@@ -2270,7 +1586,7 @@ public class ElanUtils {
         }
 
         for (String dpnInterface : dpnInterfaces.getInterfaces()) {
-            if (isExternal(dpnInterface)) {
+            if (interfaceManager.isExternalInterface(dpnInterface)) {
                 return dpnInterface;
             }
         }
@@ -2278,4 +1594,213 @@ public class ElanUtils {
         LOG.trace("Elan {} does not have any external interace attached to DPN {}", elanInstanceName, dpnId);
         return null;
     }
+
+    public static String getElanMacDPNKey(long elanTag, String macAddress, BigInteger dpnId) {
+        String elanMacDmacDpnKey = "MAC-" + macAddress + " ELAN_TAG-" + elanTag + "DPN_ID-" + dpnId;
+        return elanMacDmacDpnKey.intern();
+    }
+
+    public static String getElanMacKey(long elanTag, String macAddress) {
+        String elanMacKey = "MAC-" + macAddress + " ELAN_TAG-" + elanTag;
+        return elanMacKey.intern();
+    }
+
+    // TODO This should return a collection of futures
+    public static void addToListenableFutureIfTxException(RuntimeException exception,
+            List<ListenableFuture<Void>> futures) {
+        Throwable cause = exception.getCause();
+        if (cause != null && cause instanceof TransactionCommitFailedException) {
+            futures.add(Futures.immediateFailedCheckedFuture((TransactionCommitFailedException) cause));
+        }
+    }
+
+    public static List<PhysAddress> getPhysAddress(List<String> macAddress) {
+        Preconditions.checkNotNull(macAddress, "macAddress cannot be null");
+        List<PhysAddress> physAddresses = new ArrayList<>();
+        for (String mac : macAddress) {
+            physAddresses.add(new PhysAddress(mac));
+        }
+        return physAddresses;
+    }
+
+    public static List<StaticMacEntries> getStaticMacEntries(List<String> staticMacAddresses) {
+        if (isEmpty(staticMacAddresses)) {
+            return Collections.EMPTY_LIST;
+        }
+        StaticMacEntriesBuilder staticMacEntriesBuilder = new StaticMacEntriesBuilder();
+        List<StaticMacEntries> staticMacEntries = new ArrayList<>();
+        List<PhysAddress> physAddressList = getPhysAddress(staticMacAddresses);
+        for (PhysAddress physAddress : physAddressList) {
+            staticMacEntries.add(staticMacEntriesBuilder.setMacAddress(physAddress).build());
+        }
+        return staticMacEntries;
+    }
+
+    public static InstanceIdentifier<StaticMacEntries> getStaticMacEntriesCfgDataPathIdentifier(String interfaceName,
+                                                                                                String macAddress) {
+        return InstanceIdentifier.builder(ElanInterfaces.class)
+                .child(ElanInterface.class, new ElanInterfaceKey(interfaceName)).child(StaticMacEntries.class,
+                        new StaticMacEntriesKey(new PhysAddress(macAddress))).build();
+    }
+
+    public static List<StaticMacEntries> getDeletedEntries(List<StaticMacEntries> originalStaticMacEntries,
+                                                           List<StaticMacEntries> updatedStaticMacEntries) {
+        if (isEmpty(originalStaticMacEntries)) {
+            return Collections.EMPTY_LIST;
+        }
+        List<StaticMacEntries> deleted = Lists.newArrayList(originalStaticMacEntries);
+        if (isNotEmpty(updatedStaticMacEntries)) {
+            deleted.removeAll(updatedStaticMacEntries);
+        }
+        return deleted;
+    }
+
+    public static <T> List<T> diffOf(List<T> orig, List<T> updated) {
+        if (isEmpty(orig)) {
+            return Collections.EMPTY_LIST;
+        }
+        List<T> diff = Lists.newArrayList(orig);
+        if (isNotEmpty(updated)) {
+            diff.removeAll(updated);
+        }
+        return diff;
+    }
+
+    public static void segregateToBeDeletedAndAddEntries(List<StaticMacEntries> originalStaticMacEntries,
+                                                             List<StaticMacEntries> updatedStaticMacEntries) {
+        if (isNotEmpty(updatedStaticMacEntries)) {
+            List<StaticMacEntries> existingClonedStaticMacEntries = new ArrayList<>();
+            if (isNotEmpty(originalStaticMacEntries)) {
+                existingClonedStaticMacEntries.addAll(0, originalStaticMacEntries);
+                originalStaticMacEntries.removeAll(updatedStaticMacEntries);
+                updatedStaticMacEntries.removeAll(existingClonedStaticMacEntries);
+            }
+        }
+    }
+
+    public static boolean isEmpty(Collection collection) {
+        return collection == null || collection.isEmpty();
+    }
+
+    public static boolean isNotEmpty(Collection collection) {
+        return !isEmpty(collection);
+    }
+
+    public static void setElanInstancToDpnsCache(Map<String, Set<DpnInterfaces>> elanInstancToDpnsCache) {
+        ElanUtils.elanInstancToDpnsCache = elanInstancToDpnsCache;
+    }
+
+    public static Set<DpnInterfaces> getElanInvolvedDPNsFromCache(String elanName) {
+        return elanInstancToDpnsCache.get(elanName);
+    }
+
+    public static void addDPNInterfaceToElanInCache(String elanName, DpnInterfaces dpnInterfaces) {
+        elanInstancToDpnsCache.computeIfAbsent(elanName, key -> new HashSet<>()).add(dpnInterfaces);
+    }
+
+    public static void removeDPNInterfaceFromElanInCache(String elanName, DpnInterfaces dpnInterfaces) {
+        elanInstancToDpnsCache.computeIfAbsent(elanName, key -> new HashSet<>()).remove(dpnInterfaces);
+    }
+
+    public Optional<IpAddress> getSourceIpAddress(Ethernet ethernet) {
+        Optional<IpAddress> srcIpAddress = Optional.absent();
+        if (ethernet.getPayload() == null) {
+            return srcIpAddress;
+        }
+        byte[] ipAddrBytes = null;
+        if (ethernet.getPayload() instanceof IPv4) {
+            IPv4 ipv4 = (IPv4) ethernet.getPayload();
+            ipAddrBytes = Ints.toByteArray(ipv4.getSourceAddress());
+        } else if (ethernet.getPayload() instanceof ARP) {
+            ipAddrBytes = ((ARP) ethernet.getPayload()).getSenderProtocolAddress();
+        }
+        if (ipAddrBytes != null) {
+            String ipAddr = NWUtil.toStringIpAddress(ipAddrBytes);
+            return Optional.of(IpAddressBuilder.getDefaultInstance(ipAddr));
+        }
+        return srcIpAddress;
+    }
+
+    public List<MacEntry> getElanMacEntries(String elanName) {
+        MacTable macTable = getElanMacTable(elanName);
+        if (macTable == null) {
+            return Collections.emptyList();
+        }
+        return macTable.getMacEntry();
+    }
+
+    public boolean isTunnelInLogicalGroup(String interfaceName, DataBroker broker) {
+        org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
+            .ietf.interfaces.rev140508.interfaces.Interface configIface =
+            interfaceManager.getInterfaceInfoFromConfigDataStore(interfaceName);
+        IfTunnel ifTunnel = configIface.getAugmentation(IfTunnel.class);
+        if (ifTunnel != null && ifTunnel.getTunnelInterfaceType().isAssignableFrom(TunnelTypeVxlan.class)) {
+            ParentRefs refs = configIface.getAugmentation(ParentRefs.class);
+            if (refs != null && !Strings.isNullOrEmpty(refs.getParentInterface())) {
+                return true; //multiple VxLAN tunnels enabled, i.e. only logical tunnel should be treated
+            }
+        }
+        return false;
+    }
+
+    public static void addElanInterfaceToElanInstanceCache(String elanInstanceName, String elanInterfaceName) {
+        elanInstanceToInterfacesCache.computeIfAbsent(elanInstanceName, key -> new HashSet<>()).add(elanInterfaceName);
+    }
+
+    public static void removeElanInterfaceToElanInstanceCache(String elanInstanceName, String interfaceName) {
+        Set<String> elanInterfaces = elanInstanceToInterfacesCache.get(elanInstanceName);
+        if (elanInterfaces == null || elanInterfaces.isEmpty()) {
+            return;
+        }
+        elanInterfaces.remove(interfaceName);
+    }
+
+    @Nonnull public static Set<String> removeAndGetElanInterfaces(String elanInstanceName) {
+        Set<String> removed = elanInstanceToInterfacesCache.remove(elanInstanceName);
+        return removed != null ? removed : Collections.emptySet();
+    }
+
+    public static InstanceIdentifier<Flow> getFlowIid(Flow flow, BigInteger dpnId) {
+        FlowKey flowKey = new FlowKey(new FlowId(flow.getId()));
+        org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId nodeId =
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId("openflow:" + dpnId);
+        org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node nodeDpn =
+                new NodeBuilder().setId(nodeId).setKey(new NodeKey(nodeId)).build();
+        return InstanceIdentifier.builder(Nodes.class)
+                .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class,
+                        nodeDpn.getKey()).augmentation(FlowCapableNode.class)
+                .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flowKey).build();
+    }
+
+    public static String getElanInterfaceJobKey(String interfaceName) {
+        return "elaninterface-" + interfaceName;
+    }
+
+    public void addArpResponderFlow(BigInteger dpnId, String ingressInterfaceName, String ipAddress, String macAddress,
+            int lportTag, List<Instruction> instructions) {
+        LOG.info("Installing the ARP responder flow on DPN {} for Interface {} with MAC {} & IP {}", dpnId,
+                ingressInterfaceName, macAddress, ipAddress);
+        ElanInterface elanIface = getElanInterfaceByElanInterfaceName(broker, ingressInterfaceName);
+        ElanInstance elanInstance = getElanInstanceByName(broker, elanIface.getElanInstanceName());
+        if (elanInstance == null) {
+            LOG.debug("addArpResponderFlow: elanInstance is null, Failed to install arp responder flow for Interface {}"
+                      + " with MAC {} & IP {}", dpnId,
+                ingressInterfaceName, macAddress, ipAddress);
+            return;
+        }
+        String flowId = ArpResponderUtil.getFlowId(lportTag, ipAddress);
+        ArpResponderUtil.installFlow(mdsalManager, dpnId, flowId, flowId, NwConstants.DEFAULT_ARP_FLOW_PRIORITY,
+                ArpResponderUtil.generateCookie(lportTag, ipAddress),
+                ArpResponderUtil.getMatchCriteria(lportTag, elanInstance, ipAddress), instructions);
+        LOG.info("Installed the ARP Responder flow for Interface {}", ingressInterfaceName);
+    }
+
+    public void removeArpResponderFlow(BigInteger dpnId, String ingressInterfaceName, String ipAddress,
+            int lportTag) {
+        LOG.info("Removing the ARP responder flow on DPN {} of Interface {} with IP {}", dpnId, ingressInterfaceName,
+                ipAddress);
+        ArpResponderUtil.removeFlow(mdsalManager, dpnId, ArpResponderUtil.getFlowId(lportTag, ipAddress));
+    }
 }
+
+