L2 Gw connection support and Elan manager changes
[vpnservice.git] / elanmanager / elanmanager-impl / src / main / java / org / opendaylight / vpnservice / elan / internal / ElanServiceProvider.java
index e1fafb55b966b1c934a7034d8f45f0d7acb97576..af817b8595fd34ea60aef5f3c6d60f3a40072efa 100644 (file)
@@ -5,25 +5,40 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
+
 package org.opendaylight.vpnservice.elan.internal;
 
-import com.google.common.base.Optional;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.Future;
+
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
+import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.elanmanager.api.IElanService;
+import org.opendaylight.elanmanager.exceptions.MacNotFoundException;
+import org.opendaylight.vpnservice.elan.l2gw.internal.ElanL2GatewayProvider;
 import org.opendaylight.vpnservice.elan.statisitcs.ElanStatisticsImpl;
+import org.opendaylight.vpnservice.elan.statusanddiag.ElanStatusMonitor;
 import org.opendaylight.vpnservice.elan.utils.ElanConstants;
 import org.opendaylight.vpnservice.elan.utils.ElanUtils;
 import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
 import org.opendaylight.vpnservice.itm.api.IITMProvider;
 import org.opendaylight.vpnservice.mdsalutil.MDSALUtil;
 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
+import org.opendaylight.vpnservice.utils.hwvtep.HwvtepSouthboundUtils;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+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.flow.service.rev130819.SalFlowService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.ElanInstances;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.ElanInterfaces;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.elan._interface.forwarding.entries.ElanInterfaceMac;
@@ -41,16 +56,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.OdlInterfaceRpcService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.ItmRpcService;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
+import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.elanmanager.exceptions.MacNotFoundException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.concurrent.Future;
+import com.google.common.base.Optional;
 
 public class ElanServiceProvider implements BindingAwareProvider, IElanService, AutoCloseable {
 
@@ -67,68 +82,87 @@ public class ElanServiceProvider implements BindingAwareProvider, IElanService,
     private ElanNodeListener elanNodeListener;
     private NotificationService notificationService;
     private RpcProviderRegistry rpcProviderRegistry;
+    private IITMProvider itmManager;
+    private ItmRpcService itmRpcService;
+    private DataBroker broker;
+    private ElanL2GatewayProvider elanL2GatewayProvider;
+
+    private EntityOwnershipService entityOwnershipService;
+    private BindingNormalizedNodeSerializer bindingNormalizedNodeSerializer;
+
+    private static final ElanStatusMonitor elanStatusMonitor = ElanStatusMonitor.getInstance();
 
     public ElanServiceProvider(RpcProviderRegistry rpcRegistry) {
         rpcProviderRegistry = rpcRegistry;
+        elanStatusMonitor.registerMbean();
     }
 
-    //private ElanInterfaceStateChangeListener elanInterfaceEventListener;
+    // private ElanInterfaceStateChangeListener elanInterfaceEventListener;
     private ElanItmEventListener elanItmEventListener;
 
-    public void setItmRpcService(ItmRpcService itmRpcService) {
-        this.itmRpcService = itmRpcService;
-    }
-
-    public ItmRpcService getItmRpcService() {
-        return itmRpcService;
-    }
-
-    private ItmRpcService itmRpcService;
-    private DataBroker broker;
-
     private static final Logger logger = LoggerFactory.getLogger(ElanServiceProvider.class);
 
     @Override
     public void onSessionInitiated(ProviderContext session) {
-        createIdPool();
-        broker = session.getSALService(DataBroker.class);
+        elanStatusMonitor.reportStatus("STARTING");
+        try {
+            createIdPool();
+            broker = session.getSALService(DataBroker.class);
+
+            ElanUtils.setDataBroker(broker);
+            ElanUtils.setIfaceMgrRpcService(interfaceManagerRpcService);
+            ElanUtils.setItmRpcService(itmRpcService);
+            ElanUtils.setMdsalManager(mdsalManager);
+
+            elanForwardingEntriesHandler = new ElanForwardingEntriesHandler(broker);
+
+            elanInterfaceManager = ElanInterfaceManager.getElanInterfaceManager();
+            elanInterfaceManager.setInterfaceManager(interfaceManager);
+            elanInterfaceManager.setIdManager(idManager);
+            elanInterfaceManager.setMdSalApiManager(mdsalManager);
+            elanInterfaceManager.setDataBroker(broker);
+            elanInterfaceManager.setInterfaceManagerRpcService(interfaceManagerRpcService);
+            elanInterfaceManager.setElanForwardingEntriesHandler(elanForwardingEntriesHandler);
+
+            elanInstanceManager = ElanInstanceManager.getElanInstanceManager();
+            elanInstanceManager.setDataBroker(broker);
+            elanInstanceManager.setIdManager(idManager);
+            elanInstanceManager.setElanInterfaceManager(elanInterfaceManager);
+
+
+            elanNodeListener = new ElanNodeListener(broker, mdsalManager);
+
+            elanPacketInHandler = new ElanPacketInHandler(broker);
+            elanPacketInHandler.setInterfaceManager(interfaceManager);
+
 
-        elanForwardingEntriesHandler = new ElanForwardingEntriesHandler(broker);
+            elanSmacFlowEventListener = new ElanSmacFlowEventListener(broker);
+            elanSmacFlowEventListener.setMdSalApiManager(mdsalManager);
+            elanSmacFlowEventListener.setInterfaceManager(interfaceManager);
+            elanSmacFlowEventListener.setSalFlowService(session.getRpcService(SalFlowService.class));
 
-        elanInterfaceManager = ElanInterfaceManager.getElanInterfaceManager();
-        elanInterfaceManager.setInterfaceManager(interfaceManager);
-        elanInterfaceManager.setIdManager(idManager);
-        elanInterfaceManager.setMdSalApiManager(mdsalManager);
-        elanInterfaceManager.setDataBroker(broker);
-        elanInterfaceManager.registerListener();
-        elanInterfaceManager.setInterfaceManagerRpcService(interfaceManagerRpcService);
-        elanInterfaceManager.setElanForwardingEntriesHandler(elanForwardingEntriesHandler);
 
-        elanInstanceManager = ElanInstanceManager.getElanInstanceManager();
-        elanInstanceManager.setDataBroker(broker);
-        elanInstanceManager.setIdManager(idManager);
-        elanInstanceManager.setElanInterfaceManager(elanInterfaceManager);
-        elanInstanceManager.registerListener();
+            // Initialize statistics rpc provider for elan
+            ElanStatisticsService interfaceStatsService = new ElanStatisticsImpl(broker, interfaceManager,
+                    mdsalManager);
+            rpcProviderRegistry.addRpcImplementation(ElanStatisticsService.class, interfaceStatsService);
 
-        elanNodeListener = new ElanNodeListener(broker, mdsalManager);
+            elanInterfaceStateChangeListener = new ElanInterfaceStateChangeListener(broker, elanInterfaceManager);
+            elanInterfaceStateChangeListener.setInterfaceManager(interfaceManager);
 
-        elanPacketInHandler = new ElanPacketInHandler(broker);
-        elanPacketInHandler.setInterfaceManager(interfaceManager);
-        notificationService.registerNotificationListener(elanPacketInHandler);
 
-        elanSmacFlowEventListener = new ElanSmacFlowEventListener(broker);
-        elanSmacFlowEventListener.setMdSalApiManager(mdsalManager);
-        elanSmacFlowEventListener.setInterfaceManager(interfaceManager);
-        elanSmacFlowEventListener.setSalFlowService(session.getRpcService(SalFlowService.class));
-        notificationService.registerNotificationListener(elanSmacFlowEventListener);
+            this.elanL2GatewayProvider = new ElanL2GatewayProvider(this);
 
-        // Initialize statistics rpc provider for elan
-        ElanStatisticsService interfaceStatsService = new ElanStatisticsImpl(broker, interfaceManager, mdsalManager);
-        rpcProviderRegistry.addRpcImplementation(ElanStatisticsService.class, interfaceStatsService);
+            elanInterfaceManager.registerListener();
+            elanInstanceManager.registerListener();
+            notificationService.registerNotificationListener(elanSmacFlowEventListener);
+            notificationService.registerNotificationListener(elanPacketInHandler);
 
-        elanInterfaceStateChangeListener = new ElanInterfaceStateChangeListener(broker, elanInterfaceManager);
-        elanInterfaceStateChangeListener.setInterfaceManager(interfaceManager);
-        ElanUtils.setElanServiceProvider(this);
+            elanStatusMonitor.reportStatus("OPERATIONAL");
+        } catch (Exception e) {
+            logger.error("Error initializing services", e);
+            elanStatusMonitor.reportStatus("ERROR");
+        }
     }
 
     public void setIdManager(IdManagerService idManager) {
@@ -143,11 +177,27 @@ public class ElanServiceProvider implements BindingAwareProvider, IElanService,
         this.interfaceManager = interfaceManager;
     }
 
+    public void setEntityOwnershipService(EntityOwnershipService entityOwnershipService) {
+        this.entityOwnershipService = entityOwnershipService;
+    }
+
+    public void setBindingNormalizedNodeSerializer(BindingNormalizedNodeSerializer bindingNormalizedNodeSerializer) {
+        this.bindingNormalizedNodeSerializer = bindingNormalizedNodeSerializer;
+    }
+
+    public IInterfaceManager getInterfaceManager() {
+        return this.interfaceManager;
+    }
+
     public IMdsalApiManager getMdsalManager() {
         return mdsalManager;
     }
 
-     public DataBroker getBroker() {
+    public IITMProvider getItmManager() {
+        return itmManager;
+    }
+
+    public DataBroker getBroker() {
         return broker;
     }
 
@@ -163,14 +213,41 @@ public class ElanServiceProvider implements BindingAwareProvider, IElanService,
         return interfaceManagerRpcService;
     }
 
+    public void setItmManager(IITMProvider itmManager) {
+        this.itmManager = itmManager;
+    }
+
+    public void setItmRpcService(ItmRpcService itmRpcService) {
+        this.itmRpcService = itmRpcService;
+    }
+
+    public ItmRpcService getItmRpcService() {
+        return itmRpcService;
+    }
+
+    public ElanInstanceManager getElanInstanceManager() {
+        return elanInstanceManager;
+    }
+
+    public ElanInterfaceManager getElanInterfaceManager() {
+        return elanInterfaceManager;
+    }
+
+    public EntityOwnershipService getEntityOwnershipService() {
+        return entityOwnershipService;
+    }
+
+    public BindingNormalizedNodeSerializer getBindingNormalizedNodeSerializer() {
+        return bindingNormalizedNodeSerializer;
+    }
+
     private void createIdPool() {
-        CreateIdPoolInput createPool = new CreateIdPoolInputBuilder()
-            .setPoolName(ElanConstants.ELAN_ID_POOL_NAME).setLow(ElanConstants.ELAN_ID_LOW_VALUE).setHigh(ElanConstants.ELAN_ID_HIGH_VALUE)
-            .build();
+        CreateIdPoolInput createPool = new CreateIdPoolInputBuilder().setPoolName(ElanConstants.ELAN_ID_POOL_NAME)
+                .setLow(ElanConstants.ELAN_ID_LOW_VALUE).setHigh(ElanConstants.ELAN_ID_HIGH_VALUE).build();
         try {
-           Future<RpcResult<Void>> result = idManager.createIdPool(createPool);
-           if ((result != null) && (result.get().isSuccessful())) {
-               logger.debug("ELAN Id Pool is created successfully");
+            Future<RpcResult<Void>> result = idManager.createIdPool(createPool);
+            if ((result != null) && (result.get().isSuccessful())) {
+                logger.debug("ELAN Id Pool is created successfully");
             }
         } catch (Exception e) {
             logger.error("Failed to create ELAN Id pool {}", e);
@@ -181,30 +258,40 @@ public class ElanServiceProvider implements BindingAwareProvider, IElanService,
     public boolean createElanInstance(String elanInstanceName, long macTimeout, String description) {
         ElanInstance existingElanInstance = elanInstanceManager.getElanInstanceByName(elanInstanceName);
         boolean isSuccess = true;
-        if(existingElanInstance != null) {
-           if(compareWithExistingElanInstance(existingElanInstance, macTimeout, description)) {
-               logger.debug("Elan Instance is already present in the Operational DS {}", existingElanInstance);
-               return true;
-           } else {
-               ElanInstance updateElanInstance = new ElanInstanceBuilder().setElanInstanceName(elanInstanceName).setDescription(description).setMacTimeout(macTimeout).setKey(new ElanInstanceKey(elanInstanceName)).build();
-               MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, ElanUtils.getElanInstanceConfigurationDataPath(elanInstanceName), updateElanInstance);
-               logger.debug("Updating the Elan Instance {} with MAC TIME-OUT %l and Description %s ", updateElanInstance, macTimeout, description);
-           }
+        if (existingElanInstance != null) {
+            if (compareWithExistingElanInstance(existingElanInstance, macTimeout, description)) {
+                logger.debug("Elan Instance is already present in the Operational DS {}", existingElanInstance);
+                return true;
+            } else {
+                ElanInstance updateElanInstance = new ElanInstanceBuilder().setElanInstanceName(elanInstanceName)
+                        .setDescription(description).setMacTimeout(macTimeout)
+                        .setKey(new ElanInstanceKey(elanInstanceName)).build();
+                MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION,
+                        ElanUtils.getElanInstanceConfigurationDataPath(elanInstanceName), updateElanInstance);
+                logger.debug("Updating the Elan Instance {} with MAC TIME-OUT %l and Description %s ",
+                        updateElanInstance, macTimeout, description);
+            }
         } else {
-            ElanInstance elanInstance = new ElanInstanceBuilder().setElanInstanceName(elanInstanceName).setMacTimeout(macTimeout).setDescription(description).setKey(new ElanInstanceKey(elanInstanceName)).build();
-            MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, ElanUtils.getElanInstanceConfigurationDataPath(elanInstanceName), elanInstance);
+            ElanInstance elanInstance = new ElanInstanceBuilder().setElanInstanceName(elanInstanceName)
+                    .setMacTimeout(macTimeout).setDescription(description).setKey(new ElanInstanceKey(elanInstanceName))
+                    .build();
+            MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION,
+                    ElanUtils.getElanInstanceConfigurationDataPath(elanInstanceName), elanInstance);
             logger.debug("Creating the new Elan Instance {}", elanInstance);
         }
         return isSuccess;
     }
 
-    public static boolean compareWithExistingElanInstance(ElanInstance existingElanInstance, long macTimeOut, String description) {
+    public static boolean compareWithExistingElanInstance(ElanInstance existingElanInstance, long macTimeOut,
+            String description) {
         boolean isEqual = false;
-        if(existingElanInstance.getMacTimeout() == macTimeOut && existingElanInstance.getDescription().equals(description)) {
+        if (existingElanInstance.getMacTimeout() == macTimeOut
+                && existingElanInstance.getDescription().equals(description)) {
             isEqual = true;
         }
         return isEqual;
     }
+
     @Override
     public void updateElanInstance(String elanInstanceName, long newMacTimout, String newDescription) {
         createElanInstance(elanInstanceName, newMacTimout, newDescription);
@@ -214,34 +301,43 @@ public class ElanServiceProvider implements BindingAwareProvider, IElanService,
     public boolean deleteElanInstance(String elanInstanceName) {
         boolean isSuccess = false;
         ElanInstance existingElanInstance = elanInstanceManager.getElanInstanceByName(elanInstanceName);
-        if(existingElanInstance == null) {
-            logger.debug("Elan Instance is not present {}" , existingElanInstance);
+        if (existingElanInstance == null) {
+            logger.debug("Elan Instance is not present {}", existingElanInstance);
             return isSuccess;
         }
         logger.debug("Deletion of the existing Elan Instance {}", existingElanInstance);
-        ElanUtils.delete(broker, LogicalDatastoreType.CONFIGURATION, ElanUtils.getElanInstanceConfigurationDataPath(elanInstanceName));
+        ElanUtils.delete(broker, LogicalDatastoreType.CONFIGURATION,
+                ElanUtils.getElanInstanceConfigurationDataPath(elanInstanceName));
         isSuccess = true;
         return isSuccess;
     }
 
     @Override
-    public void addElanInterface(String elanInstanceName, String interfaceName, List<String> staticMacAddresses, String description) {
-          ElanInstance existingElanInstance = elanInstanceManager.getElanInstanceByName(elanInstanceName);
-          if(existingElanInstance != null) {
-              ElanInterface elanInterface;
-              if(staticMacAddresses == null) {
-                  elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName).setDescription(description).setName(interfaceName).setKey(new ElanInterfaceKey(interfaceName)).build();
-              } else {
-                  elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName).setDescription(description).setName(interfaceName).setStaticMacEntries(getPhysAddress(staticMacAddresses)).setKey(new ElanInterfaceKey(interfaceName)).build();
-              }
-              MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, ElanUtils.getElanInterfaceConfigurationDataPathId(interfaceName), elanInterface);
-              logger.debug("Creating the new ELan Interface {}", elanInterface);
-          }
+    public void addElanInterface(String elanInstanceName, String interfaceName, List<String> staticMacAddresses,
+            String description) {
+        ElanInstance existingElanInstance = elanInstanceManager.getElanInstanceByName(elanInstanceName);
+        if (existingElanInstance != null) {
+            ElanInterface elanInterface;
+            if (staticMacAddresses == null) {
+                elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName)
+                        .setDescription(description).setName(interfaceName).setKey(new ElanInterfaceKey(interfaceName))
+                        .build();
+            } else {
+                elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName)
+                        .setDescription(description).setName(interfaceName)
+                        .setStaticMacEntries(getPhysAddress(staticMacAddresses))
+                        .setKey(new ElanInterfaceKey(interfaceName)).build();
+            }
+            MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION,
+                    ElanUtils.getElanInterfaceConfigurationDataPathId(interfaceName), elanInterface);
+            logger.debug("Creating the new ELan Interface {}", elanInterface);
+        }
 
     }
 
     @Override
-    public void updateElanInterface(String elanInstanceName, String interfaceName, List<String> updatedStaticMacAddresses, String newDescription) {
+    public void updateElanInterface(String elanInstanceName, String interfaceName,
+            List<String> updatedStaticMacAddresses, String newDescription) {
         ElanInterface existingElanInterface = ElanUtils.getElanInterfaceByElanInterfaceName(interfaceName);
         if (existingElanInterface == null) {
             return;
@@ -249,18 +345,22 @@ public class ElanServiceProvider implements BindingAwareProvider, IElanService,
         List<PhysAddress> existingMacAddress = existingElanInterface.getStaticMacEntries();
         List<PhysAddress> updatedMacAddresses = getPhysAddress(updatedStaticMacAddresses);
         List<PhysAddress> updatedPhysAddress = getUpdatedPhyAddress(existingMacAddress, updatedMacAddresses);
-        if(updatedPhysAddress.size() > 0) {
+        if (updatedPhysAddress.size() > 0) {
             logger.debug("updating the ElanInterface with new Mac Entries {}", updatedStaticMacAddresses);
-            ElanInterface elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName).setName(interfaceName).setDescription(newDescription).setStaticMacEntries(updatedPhysAddress).setKey(new ElanInterfaceKey(interfaceName)).build();
-            MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, ElanUtils.getElanInterfaceConfigurationDataPathId(interfaceName), elanInterface);
+            ElanInterface elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName)
+                    .setName(interfaceName).setDescription(newDescription).setStaticMacEntries(updatedPhysAddress)
+                    .setKey(new ElanInterfaceKey(interfaceName)).build();
+            MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION,
+                    ElanUtils.getElanInterfaceConfigurationDataPathId(interfaceName), elanInterface);
         }
     }
 
     @Override
     public void deleteElanInterface(String elanInstanceName, String interfaceName) {
         ElanInterface existingElanInterface = ElanUtils.getElanInterfaceByElanInterfaceName(interfaceName);
-        if(existingElanInterface != null) {
-            ElanUtils.delete(broker, LogicalDatastoreType.CONFIGURATION, ElanUtils.getElanInterfaceConfigurationDataPathId(interfaceName));
+        if (existingElanInterface != null) {
+            ElanUtils.delete(broker, LogicalDatastoreType.CONFIGURATION,
+                    ElanUtils.getElanInterfaceConfigurationDataPathId(interfaceName));
             logger.debug("deleting the Elan Interface {}", existingElanInterface);
         }
     }
@@ -271,27 +371,36 @@ public class ElanServiceProvider implements BindingAwareProvider, IElanService,
         PhysAddress updateStaticMacAddress = new PhysAddress(macAddress);
         if (existingElanInterface != null) {
             List<PhysAddress> existingMacAddress = existingElanInterface.getStaticMacEntries();
-            if(existingMacAddress.contains(updateStaticMacAddress)) {
+            if (existingMacAddress.contains(updateStaticMacAddress)) {
                 return;
             }
             existingMacAddress.add(updateStaticMacAddress);
-            ElanInterface elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName).setName(interfaceName).setStaticMacEntries(existingMacAddress).setDescription(existingElanInterface.getDescription()).setKey(new ElanInterfaceKey(interfaceName)).build();
-            MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, ElanUtils.getElanInterfaceConfigurationDataPathId(interfaceName), elanInterface);
+            ElanInterface elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName)
+                    .setName(interfaceName).setStaticMacEntries(existingMacAddress)
+                    .setDescription(existingElanInterface.getDescription()).setKey(new ElanInterfaceKey(interfaceName))
+                    .build();
+            MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION,
+                    ElanUtils.getElanInterfaceConfigurationDataPathId(interfaceName), elanInterface);
         }
     }
 
     @Override
-    public void deleteStaticMacAddress(String elanInstanceName, String interfaceName, String macAddress) throws MacNotFoundException {
-           ElanInterface existingElanInterface = ElanUtils.getElanInterfaceByElanInterfaceName(interfaceName);
+    public void deleteStaticMacAddress(String elanInstanceName, String interfaceName, String macAddress)
+            throws MacNotFoundException {
+        ElanInterface existingElanInterface = ElanUtils.getElanInterfaceByElanInterfaceName(interfaceName);
         PhysAddress physAddress = new PhysAddress(macAddress);
-        if(existingElanInterface == null) {
+        if (existingElanInterface == null) {
             return;
         }
         List<PhysAddress> existingMacAddress = existingElanInterface.getStaticMacEntries();
-        if(existingMacAddress.contains(physAddress)) {
+        if (existingMacAddress.contains(physAddress)) {
             existingMacAddress.remove(physAddress);
-            ElanInterface elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName).setName(interfaceName).setStaticMacEntries(existingMacAddress).setDescription(existingElanInterface.getDescription()).setKey(new ElanInterfaceKey(interfaceName)).build();
-            MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, ElanUtils.getElanInterfaceConfigurationDataPathId(interfaceName), elanInterface);
+            ElanInterface elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName)
+                    .setName(interfaceName).setStaticMacEntries(existingMacAddress)
+                    .setDescription(existingElanInterface.getDescription()).setKey(new ElanInterfaceKey(interfaceName))
+                    .build();
+            MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION,
+                    ElanUtils.getElanInterfaceConfigurationDataPathId(interfaceName), elanInterface);
         } else {
             throw new MacNotFoundException("Mac Not Found Exception");
         }
@@ -301,25 +410,26 @@ public class ElanServiceProvider implements BindingAwareProvider, IElanService,
     public Collection<MacEntry> getElanMacTable(String elanInstanceName) {
         Elan elanInfo = ElanUtils.getElanByName(elanInstanceName);
         List<MacEntry> macAddress = new ArrayList<>();
-        if(elanInfo == null) {
+        if (elanInfo == null) {
             return macAddress;
         }
-       List<String> elanInterfaces =  elanInfo.getElanInterfaces();
-        if(elanInterfaces != null && elanInterfaces.size() > 0) {
-            for(String elanInterface : elanInterfaces) {
+        List<String> elanInterfaces = elanInfo.getElanInterfaces();
+        if (elanInterfaces != null && elanInterfaces.size() > 0) {
+            for (String elanInterface : elanInterfaces) {
                 ElanInterfaceMac elanInterfaceMac = ElanUtils.getElanInterfaceMacByInterfaceName(elanInterface);
-                if(elanInterfaceMac != null && elanInterfaceMac.getMacEntry() != null && elanInterfaceMac.getMacEntry().size() > 0){
+                if (elanInterfaceMac != null && elanInterfaceMac.getMacEntry() != null
+                        && elanInterfaceMac.getMacEntry().size() > 0) {
                     macAddress.addAll(elanInterfaceMac.getMacEntry());
                 }
             }
         }
-       return macAddress;
+        return macAddress;
     }
 
     @Override
     public void flushMACTable(String elanInstanceName) {
         Elan elanInfo = ElanUtils.getElanByName(elanInstanceName);
-        if(elanInfo == null) {
+        if (elanInfo == null) {
             return;
         }
         List<String> elanInterfaces = elanInfo.getElanInterfaces();
@@ -329,8 +439,8 @@ public class ElanServiceProvider implements BindingAwareProvider, IElanService,
         for (String elanInterface : elanInterfaces) {
             ElanInterfaceMac elanInterfaceMac = ElanUtils.getElanInterfaceMacByInterfaceName(elanInterface);
             if (elanInterfaceMac.getMacEntry() != null && elanInterfaceMac.getMacEntry().size() > 0) {
-                List<MacEntry> macEntries =  elanInterfaceMac.getMacEntry();
-                for(MacEntry macEntry : macEntries) {
+                List<MacEntry> macEntries = elanInterfaceMac.getMacEntry();
+                for (MacEntry macEntry : macEntries) {
                     try {
                         deleteStaticMacAddress(elanInstanceName, elanInterface, macEntry.getMacAddress().getValue());
                     } catch (MacNotFoundException e) {
@@ -345,20 +455,21 @@ public class ElanServiceProvider implements BindingAwareProvider, IElanService,
 
     @Override
     public void close() throws Exception {
-        elanInstanceManager.close();
+        this.elanInstanceManager.close();
+        this.elanL2GatewayProvider.close();
     }
 
     public static List<PhysAddress> getPhysAddress(List<String> macAddress) {
         List<PhysAddress> physAddresses = new ArrayList<>();
-        for(String mac : macAddress) {
+        for (String mac : macAddress) {
             physAddresses.add(new PhysAddress(mac));
         }
         return physAddresses;
     }
 
-
-    public List<PhysAddress> getUpdatedPhyAddress(List<PhysAddress> originalAddresses, List<PhysAddress> updatePhyAddresses) {
-        if(updatePhyAddresses != null && !updatePhyAddresses.isEmpty()) {
+    public List<PhysAddress> getUpdatedPhyAddress(List<PhysAddress> originalAddresses,
+            List<PhysAddress> updatePhyAddresses) {
+        if (updatePhyAddresses != null && !updatePhyAddresses.isEmpty()) {
             List<PhysAddress> existingClonedPhyAddress = new ArrayList<>();
             if (originalAddresses != null && !originalAddresses.isEmpty()) {
                 existingClonedPhyAddress.addAll(0, originalAddresses);
@@ -377,9 +488,11 @@ public class ElanServiceProvider implements BindingAwareProvider, IElanService,
     @Override
     public List<ElanInstance> getElanInstances() {
         List<ElanInstance> elanList = new ArrayList<ElanInstance>();
-        InstanceIdentifier<ElanInstances> elanInstancesIdentifier =  InstanceIdentifier.builder(ElanInstances.class).build();
-        Optional<ElanInstances> elansOptional  = ElanUtils.read(broker, LogicalDatastoreType.CONFIGURATION, elanInstancesIdentifier);
-        if(elansOptional.isPresent()) {
+        InstanceIdentifier<ElanInstances> elanInstancesIdentifier = InstanceIdentifier.builder(ElanInstances.class)
+                .build();
+        Optional<ElanInstances> elansOptional = ElanUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+                elanInstancesIdentifier);
+        if (elansOptional.isPresent()) {
             elanList.addAll(elansOptional.get().getElanInstance());
         }
         return elanList;
@@ -388,14 +501,16 @@ public class ElanServiceProvider implements BindingAwareProvider, IElanService,
     @Override
     public List<String> getElanInterfaces(String elanInstanceName) {
         List<String> elanInterfaces = new ArrayList<>();
-        InstanceIdentifier<ElanInterfaces> elanInterfacesIdentifier =  InstanceIdentifier.builder(ElanInterfaces.class).build();
-        Optional<ElanInterfaces> elanInterfacesOptional  = ElanUtils.read(broker, LogicalDatastoreType.CONFIGURATION, elanInterfacesIdentifier);
-        if(!elanInterfacesOptional.isPresent()) {
-             return elanInterfaces;
+        InstanceIdentifier<ElanInterfaces> elanInterfacesIdentifier = InstanceIdentifier.builder(ElanInterfaces.class)
+                .build();
+        Optional<ElanInterfaces> elanInterfacesOptional = ElanUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+                elanInterfacesIdentifier);
+        if (!elanInterfacesOptional.isPresent()) {
+            return elanInterfaces;
         }
         List<ElanInterface> elanInterfaceList = elanInterfacesOptional.get().getElanInterface();
-        for(ElanInterface elanInterface : elanInterfaceList) {
-            if(elanInterface.getElanInstanceName().equals(elanInstanceName)) {
+        for (ElanInterface elanInterface : elanInterfaceList) {
+            if (elanInterface.getElanInstanceName().equals(elanInstanceName)) {
                 elanInterfaces.add(elanInterface.getName());
             }
         }