Refactor elanInstanceLocalCache to a non-static singleton 53/66753/8
authorTom Pantelis <tompantelis@gmail.com>
Sun, 24 Dec 2017 04:04:22 +0000 (23:04 -0500)
committerTom Pantelis <tompantelis@gmail.com>
Mon, 19 Feb 2018 15:32:23 +0000 (10:32 -0500)
Created an ElanInstanceCache class derived form DataObjectCache
to replace the static elanInstanceLocalCache Map in ElanUtils.

Change-Id: I4b8f489b7bdae70f3ebae456715bab81ab7e76e8
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
28 files changed:
elanmanager/impl/pom.xml
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cache/ElanInstanceCache.java [new file with mode: 0644]
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/evpn/listeners/ElanMacEntryListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/evpn/listeners/EvpnElanInstanceListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/evpn/utils/EvpnMacVrfUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/evpn/utils/EvpnUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanDpnInterfaceClusteredListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanDpnInterfacesListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanDpnToTransportZoneListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanExtnTepListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanInterfaceManager.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanInterfaceStateChangeListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanLearntVpnVipToPortListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanPacketInHandler.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanServiceProvider.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanSmacFlowEventListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/ElanGroupListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/HwvtepLocalUcastMacListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/LocalUcastMacListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/ElanL2GatewayUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/L2GatewayConnectionUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/StaleVlanBindingsCleaner.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/CacheElanInstanceListener.java [deleted file]
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanForwardingEntriesHandler.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/TransportZoneNotificationUtil.java
elanmanager/impl/src/main/resources/org/opendaylight/blueprint/elanmanager.xml
elanmanager/impl/src/test/java/org/opendaylight/netvirt/elanmanager/tests/ElanServiceTest.java

index 93b9c1e0c7ad58d9791143135891b5c39a7453bb..ee12efaf1aa06248681dee557ee4bd0af3de530a 100644 (file)
@@ -177,6 +177,12 @@ this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
             <version>${infrautils.version}</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+          <groupId>org.opendaylight.infrautils</groupId>
+          <artifactId>caches-test</artifactId>
+          <version>${infrautils.version}</version>
+          <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.opendaylight.genius</groupId>
             <artifactId>mdsalutil-testutils</artifactId>
diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cache/ElanInstanceCache.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cache/ElanInstanceCache.java
new file mode 100644 (file)
index 0000000..d771271
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2017 Inocybe Technologies 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netvirt.elan.cache;
+
+import com.google.common.base.Optional;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.genius.mdsalutil.cache.DataObjectCache;
+import org.opendaylight.infrautils.caches.CacheProvider;
+import org.opendaylight.netvirt.elanmanager.api.ElanHelper;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInstances;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Caches ElanInstances.
+ *
+ * @author Thomas Pantelis
+ */
+@Singleton
+public class ElanInstanceCache extends DataObjectCache<ElanInstance> {
+    private static final Logger LOG = LoggerFactory.getLogger(ElanInstanceCache.class);
+
+    @Inject
+    public ElanInstanceCache(DataBroker dataBroker, CacheProvider cacheProvider) {
+        super(ElanInstance.class, dataBroker, LogicalDatastoreType.CONFIGURATION,
+                InstanceIdentifier.create(ElanInstances.class).child(ElanInstance.class), cacheProvider);
+    }
+
+    public Optional<ElanInstance> get(String elanInstanceName) {
+        try {
+            return get(ElanHelper.getElanInstanceConfigurationDataPath(elanInstanceName));
+        } catch (ReadFailedException e) {
+            LOG.warn("Error reading ElanInstance {}", elanInstanceName, e);
+            return Optional.absent();
+        }
+    }
+}
index 325e9e2c955f05a105519f4429e645ea5eb1ae5c..a5d44ab60ffc14b9448c4a28a28d6448578599b0 100644 (file)
@@ -15,8 +15,8 @@ import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
+import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.evpn.utils.EvpnUtils;
-import org.opendaylight.netvirt.elan.utils.ElanUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanForwardingTables;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.forwarding.tables.MacTable;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
@@ -31,11 +31,14 @@ public class ElanMacEntryListener extends AsyncDataTreeChangeListenerBase<MacEnt
     private static final Logger LOG = LoggerFactory.getLogger(ElanMacEntryListener.class);
     private final DataBroker broker;
     private final EvpnUtils evpnUtils;
+    private final ElanInstanceCache elanInstanceCache;
 
     @Inject
-    public ElanMacEntryListener(final DataBroker broker, final EvpnUtils evpnUtils) {
+    public ElanMacEntryListener(final DataBroker broker, final EvpnUtils evpnUtils,
+            final ElanInstanceCache elanInstanceCache) {
         this.broker = broker;
         this.evpnUtils = evpnUtils;
+        this.elanInstanceCache = elanInstanceCache;
     }
 
     @Override
@@ -61,7 +64,7 @@ public class ElanMacEntryListener extends AsyncDataTreeChangeListenerBase<MacEnt
     protected void add(InstanceIdentifier<MacEntry> instanceIdentifier, MacEntry macEntry) {
         LOG.info("ElanMacEntryListener : ADD macEntry {} ", instanceIdentifier);
         String elanName = instanceIdentifier.firstKeyOf(MacTable.class).getElanInstanceName();
-        ElanInstance elanInfo = ElanUtils.getElanInstanceByName(broker, elanName);
+        ElanInstance elanInfo = elanInstanceCache.get(elanName).orNull();
         if (EvpnUtils.getEvpnNameFromElan(elanInfo) == null) {
             LOG.trace("ElanMacEntryListener : Add evpnName is null for elan {} ", elanInfo);
             return;
@@ -73,7 +76,7 @@ public class ElanMacEntryListener extends AsyncDataTreeChangeListenerBase<MacEnt
     protected void remove(InstanceIdentifier<MacEntry> instanceIdentifier, MacEntry macEntry) {
         LOG.info("ElanMacEntryListener : remove macEntry {} ", instanceIdentifier);
         String elanName = instanceIdentifier.firstKeyOf(MacTable.class).getElanInstanceName();
-        ElanInstance elanInfo = ElanUtils.getElanInstanceByName(broker, elanName);
+        ElanInstance elanInfo = elanInstanceCache.get(elanName).orNull();
         if (EvpnUtils.getEvpnNameFromElan(elanInfo) == null) {
             LOG.trace("ElanMacEntryListener : Remove evpnName is null for elan {} ", elanInfo);
             return;
index f0e9752b395ccf793390f7113d4b6ff9103885b8..7322a80b9cf980660bb7357ce01ee044d42a123e 100644 (file)
@@ -11,14 +11,12 @@ package org.opendaylight.netvirt.elan.evpn.listeners;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Singleton;
-
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.netvirt.elan.evpn.utils.EvpnMacVrfUtils;
 import org.opendaylight.netvirt.elan.evpn.utils.EvpnUtils;
-import org.opendaylight.netvirt.elan.utils.ElanUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInstances;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.EvpnAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
@@ -70,7 +68,6 @@ public class EvpnElanInstanceListener extends AsyncDataTreeChangeListenerBase<El
     protected void update(InstanceIdentifier<ElanInstance> instanceIdentifier, ElanInstance original,
                           ElanInstance update) {
         String elanName = update.getElanInstanceName();
-        ElanUtils.addElanInstanceIntoCache(elanName, update);
         if (evpnUtils.isWithdrawEvpnRT2Routes(original, update)) {
             evpnUtils.withdrawEvpnRT2Routes(original.getAugmentation(EvpnAugmentation.class), elanName);
             evpnMacVrfUtils.updateEvpnDmacFlows(original, false);
index 85e09132e71979f15f08fad8b5aba3f9c331c4c1..d7994d9605e4093145f798dfac734caf75ddec06 100644 (file)
@@ -12,6 +12,7 @@ import com.google.common.util.concurrent.ListenableFuture;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
+import javax.annotation.Nullable;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -20,6 +21,7 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
+import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.utils.ElanConstants;
 import org.opendaylight.netvirt.elan.utils.ElanUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
@@ -50,11 +52,12 @@ public class EvpnMacVrfUtils {
     private final EvpnUtils evpnUtils;
     private final JobCoordinator jobCoordinator;
     private final ElanUtils elanUtils;
+    private final ElanInstanceCache elanInstanceCache;
 
     @Inject
     public EvpnMacVrfUtils(final DataBroker dataBroker, final IdManagerService idManager,
             final ElanEvpnFlowUtils elanEvpnFlowUtils, final IMdsalApiManager mdsalManager, final EvpnUtils evpnUtils,
-            final JobCoordinator jobCoordinator, final ElanUtils elanUtils) {
+            final JobCoordinator jobCoordinator, final ElanUtils elanUtils, final ElanInstanceCache elanInstanceCache) {
         this.dataBroker = dataBroker;
         this.idManager = idManager;
         this.elanEvpnFlowUtils = elanEvpnFlowUtils;
@@ -62,14 +65,20 @@ public class EvpnMacVrfUtils {
         this.evpnUtils = evpnUtils;
         this.jobCoordinator = jobCoordinator;
         this.elanUtils = elanUtils;
+        this.elanInstanceCache = elanInstanceCache;
     }
 
-    public Long getElanTagByMacvrfiid(InstanceIdentifier<MacVrfEntry> macVrfEntryIid) {
+    @Nullable
+    private Long getElanTagByMacvrfiid(InstanceIdentifier<MacVrfEntry> macVrfEntryIid) {
         String elanName = getElanNameByMacvrfiid(macVrfEntryIid);
         if (elanName == null) {
             LOG.error("getElanTag: elanName is NULL for iid = {}", macVrfEntryIid);
         }
-        ElanInstance elanInstance = ElanUtils.getElanInstanceByName(dataBroker, elanName);
+        ElanInstance elanInstance = elanInstanceCache.get(elanName).orNull();
+        if (elanInstance == null) {
+            return null;
+        }
+
         Long elanTag = elanInstance.getElanTag();
         if (elanTag == null || elanTag == 0L) {
             elanTag = ElanUtils.retrieveNewElanTag(idManager, elanName);
@@ -131,7 +140,7 @@ public class EvpnMacVrfUtils {
     }
 
     public boolean checkEvpnAttachedToNet(String elanName) {
-        ElanInstance elanInfo = ElanUtils.getElanInstanceByName(dataBroker, elanName);
+        ElanInstance elanInfo = elanInstanceCache.get(elanName).orNull();
         String evpnName = EvpnUtils.getEvpnNameFromElan(elanInfo);
         if (evpnName == null) {
             LOG.error("Error : evpnName is null for elanName {}", elanName);
@@ -153,6 +162,10 @@ public class EvpnMacVrfUtils {
             String nexthopIP = macVrfEntry.getRoutePaths().get(0).getNexthopAddress();
             IpAddress ipAddress = new IpAddress(new Ipv4Address(nexthopIP));
             Long elanTag = getElanTagByMacvrfiid(instanceIdentifier);
+            if (elanTag == null) {
+                return;
+            }
+
             String dstMacAddress = macVrfEntry.getMac();
             long vni = macVrfEntry.getL2vni();
             jobCoordinator.enqueueJob(dstMacAddress, () -> {
@@ -187,6 +200,10 @@ public class EvpnMacVrfUtils {
         String nexthopIP = macVrfEntry.getRoutePaths().get(0).getNexthopAddress();
         IpAddress ipAddress = new IpAddress(new Ipv4Address(nexthopIP));
         Long elanTag = getElanTagByMacvrfiid(instanceIdentifier);
+        if (elanTag == null) {
+            return;
+        }
+
         String macToRemove = macVrfEntry.getMac();
         jobCoordinator.enqueueJob(macToRemove, () -> {
             List<ListenableFuture<Void>> futures = new ArrayList<>();
index cb9f99afa6d8f1cd2afab9367b775cc23f10a98f..f754359f9835ebde70b869cf6edc546f03a4abe3 100644 (file)
@@ -43,6 +43,7 @@ import org.opendaylight.genius.mdsalutil.matches.MatchTunnelId;
 import org.opendaylight.genius.utils.ServiceIndex;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
 import org.opendaylight.netvirt.bgpmanager.api.IBgpManager;
+import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.l2gw.utils.SettableFutureCallback;
 import org.opendaylight.netvirt.elan.utils.ElanConstants;
 import org.opendaylight.netvirt.elan.utils.ElanUtils;
@@ -86,11 +87,12 @@ public class EvpnUtils {
     private final JobCoordinator jobCoordinator;
     private final IBgpManager bgpManager;
     private final IVpnManager vpnManager;
+    private final ElanInstanceCache elanInstanceCache;
 
     @Inject
     public EvpnUtils(DataBroker broker, IInterfaceManager interfaceManager, ElanUtils elanUtils,
             ItmRpcService itmRpcService, IVpnManager vpnManager, IBgpManager bgpManager,
-            JobCoordinator jobCoordinator) {
+            JobCoordinator jobCoordinator, ElanInstanceCache elanInstanceCache) {
         this.broker = broker;
         this.interfaceManager = interfaceManager;
         this.elanUtils = elanUtils;
@@ -98,6 +100,7 @@ public class EvpnUtils {
         this.vpnManager = vpnManager;
         this.bgpManager = bgpManager;
         this.jobCoordinator = jobCoordinator;
+        this.elanInstanceCache = elanInstanceCache;
     }
 
     public boolean isWithdrawEvpnRT2Routes(ElanInstance original, ElanInstance update) {
@@ -120,7 +123,7 @@ public class EvpnUtils {
             return;
         }
         String rd = vpnManager.getVpnRd(broker, evpnName);
-        ElanInstance elanInfo = ElanUtils.getElanInstanceByName(broker, elanName);
+        ElanInstance elanInfo = elanInstanceCache.get(elanName).orNull();
         macEntries.stream().filter(isIpv4PrefixAvailable).forEach(macEntry -> {
             InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(macEntry.getInterface());
             if (interfaceInfo == null) {
@@ -425,7 +428,7 @@ public class EvpnUtils {
 
     public void programEvpnL2vniDemuxTable(String elanName, final BiConsumer<String, String> serviceHandler,
                                            BiConsumer<BigInteger, FlowEntity> flowHandler) {
-        ElanInstance elanInfo = ElanUtils.getElanInstanceByName(broker, elanName);
+        ElanInstance elanInfo = elanInstanceCache.get(elanName).orNull();
         List<String> tunnelInterfaceNameList = getDcGatewayTunnelInterfaceNameList();
         if (tunnelInterfaceNameList.isEmpty()) {
             LOG.info("No DC gateways tunnels while programming l2vni table for elan {}.", elanName);
index 247e3d71e15d64f9e13ab21c4c03445fdd86a6d6..b17b4c715af963e95c4aaa0238111b548f0421d2 100644 (file)
@@ -17,6 +17,7 @@ import org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListen
 import org.opendaylight.genius.utils.clustering.EntityOwnershipUtils;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
+import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
 import org.opendaylight.netvirt.elan.utils.ElanClusterUtils;
@@ -42,18 +43,21 @@ public class ElanDpnInterfaceClusteredListener
     private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
     private final ElanClusterUtils elanClusterUtils;
     private final JobCoordinator jobCoordinator;
+    private final ElanInstanceCache elanInstanceCache;
 
     @Inject
     public ElanDpnInterfaceClusteredListener(DataBroker broker, EntityOwnershipUtils entityOwnershipUtils,
                                              ElanL2GatewayUtils elanL2GatewayUtils,
                                              ElanClusterUtils elanClusterUtils, JobCoordinator jobCoordinator,
-                                             ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils) {
+                                             ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils,
+                                             ElanInstanceCache elanInstanceCache) {
         this.broker = broker;
         this.entityOwnershipUtils = entityOwnershipUtils;
         this.elanL2GatewayUtils = elanL2GatewayUtils;
         this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
         this.elanClusterUtils = elanClusterUtils;
         this.jobCoordinator = jobCoordinator;
+        this.elanInstanceCache = elanInstanceCache;
     }
 
     @PostConstruct
@@ -129,12 +133,14 @@ public class ElanDpnInterfaceClusteredListener
                 if (entityOwnershipUtils.isEntityOwner(HwvtepSouthboundConstants.ELAN_ENTITY_TYPE,
                         HwvtepSouthboundConstants.ELAN_ENTITY_NAME)) {
                     ElanUtils.addDPNInterfaceToElanInCache(getElanName(identifier), dpnInterfaces);
-                    ElanInstance elanInstance = ElanUtils.getElanInstanceByName(broker, elanName);
-                    elanL2GatewayUtils.installElanL2gwDevicesLocalMacsInDpn(
-                            dpnInterfaces.getDpId(), elanInstance, dpnInterfaces.getInterfaces().get(0));
-
-                    // updating remote mcast mac on l2gw devices
-                    elanL2GatewayMulticastUtils.updateRemoteMcastMacOnElanL2GwDevices(elanName);
+                    ElanInstance elanInstance = elanInstanceCache.get(elanName).orNull();
+                    if (elanInstance != null) {
+                        elanL2GatewayUtils.installElanL2gwDevicesLocalMacsInDpn(
+                                dpnInterfaces.getDpId(), elanInstance, dpnInterfaces.getInterfaces().get(0));
+
+                        // updating remote mcast mac on l2gw devices
+                        elanL2GatewayMulticastUtils.updateRemoteMcastMacOnElanL2GwDevices(elanName);
+                    }
                 }
             } finally {
                 ElanUtils.addDPNInterfaceToElanInCache(getElanName(identifier), dpnInterfaces);
index f65405fe9c520829144fd1e200e5b6224a7fcd20..5b17290e75ad10a64199f40134594826d16ded39 100644 (file)
@@ -19,6 +19,7 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
+import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.utils.ElanUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanDpnInterfaces;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.ElanDpnInterfacesList;
@@ -37,14 +38,17 @@ public class ElanDpnInterfacesListener
     private final IInterfaceManager interfaceManager;
     private final ElanServiceProvider elanService;
     private final JobCoordinator jobCoordinator;
+    private final ElanInstanceCache elanInstanceCache;
 
     @Inject
     public ElanDpnInterfacesListener(final DataBroker dataBroker, final IInterfaceManager interfaceManager,
-                                     final ElanServiceProvider elanService, final JobCoordinator jobCoordinator) {
+                                     final ElanServiceProvider elanService, final JobCoordinator jobCoordinator,
+                                     final ElanInstanceCache elanInstanceCache) {
         this.dataBroker = dataBroker;
         this.interfaceManager = interfaceManager;
         this.elanService = elanService;
         this.jobCoordinator = jobCoordinator;
+        this.elanInstanceCache = elanInstanceCache;
     }
 
     @PostConstruct
@@ -69,7 +73,7 @@ public class ElanDpnInterfacesListener
         LOG.debug("received Dpninterfaces update event for dpn {}", update.getDpId());
         BigInteger dpnId = update.getDpId();
         String elanInstanceName = identifier.firstKeyOf(ElanDpnInterfacesList.class).getElanInstanceName();
-        ElanInstance elanInstance = ElanUtils.getElanInstanceByName(dataBroker, elanInstanceName);
+        ElanInstance elanInstance = elanInstanceCache.get(elanInstanceName).orNull();
 
         if (elanInstance != null && !elanInstance.isExternal() && ElanUtils.isVlan(elanInstance)) {
             List<String> interfaces = update.getInterfaces();
@@ -89,7 +93,7 @@ public class ElanDpnInterfacesListener
         LOG.debug("received Dpninterfaces add event for dpn {}", dpnInterfaces.getDpId());
         BigInteger dpnId = dpnInterfaces.getDpId();
         String elanInstanceName = identifier.firstKeyOf(ElanDpnInterfacesList.class).getElanInstanceName();
-        ElanInstance elanInstance = ElanUtils.getElanInstanceByName(dataBroker, elanInstanceName);
+        ElanInstance elanInstance = elanInstanceCache.get(elanInstanceName).orNull();
 
         // trigger creation of vlan provider intf for the vlan provider network
         // on br-int patch port for this DPN
index fef1284f50c2ddb92ab14c431d912d54d49cd90d..e6062a0c97b9ead45ddafc6cf14246bfe29cc83e 100644 (file)
@@ -15,6 +15,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
+import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.utils.ElanUtils;
 import org.opendaylight.netvirt.elan.utils.TransportZoneNotificationUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.config.rev150710.ElanConfig;
@@ -33,13 +34,16 @@ public class ElanDpnToTransportZoneListener
     private final TransportZoneNotificationUtil transportZoneNotificationUtil;
     private final DataBroker dbx;
     private final Boolean useTransportZone;
+    private final ElanInstanceCache elanInstanceCache;
 
     @Inject
     public ElanDpnToTransportZoneListener(final DataBroker dbx, final IInterfaceManager interfaceManager,
-            final ElanConfig elanConfig, final TransportZoneNotificationUtil tznu) {
+            final ElanConfig elanConfig, final TransportZoneNotificationUtil tznu,
+            final ElanInstanceCache elanInstanceCache) {
         useTransportZone = elanConfig.isAutoConfigTransportZones();
         transportZoneNotificationUtil = tznu;
         this.dbx = dbx;
+        this.elanInstanceCache = elanInstanceCache;
     }
 
     @PostConstruct
@@ -63,7 +67,7 @@ public class ElanDpnToTransportZoneListener
         BigInteger dpId = dataObjectModification.getDpId();
         String elanInstanceName = key.firstKeyOf(ElanDpnInterfacesList.class).getElanInstanceName();
 
-        if (!ElanUtils.isVxlanNetwork(dbx, elanInstanceName)) {
+        if (!ElanUtils.isVxlan(elanInstanceCache.get(elanInstanceName).orNull())) {
             LOG.debug("ElanInstance {} is not vxlan network, nothing to do", elanInstanceName);
             return;
         }
@@ -84,7 +88,7 @@ public class ElanDpnToTransportZoneListener
         BigInteger dpId = dataObjectModification.getDpId();
         String elanInstanceName = key.firstKeyOf(ElanDpnInterfacesList.class).getElanInstanceName();
 
-        if (!ElanUtils.isVxlanNetwork(dbx, elanInstanceName)) {
+        if (!ElanUtils.isVxlan(elanInstanceCache.get(elanInstanceName).orNull())) {
             return;
         }
 
index 9c33a3a7688f6bc7d1046c75dc753fdbfa95602b..4da91ca16cc6317a49f1a3c1360a91d6437e757b 100644 (file)
@@ -16,9 +16,9 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
+import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
 import org.opendaylight.netvirt.elan.utils.ElanConstants;
-import org.opendaylight.netvirt.elan.utils.ElanUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInstances;
 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.elan.instance.ExternalTeps;
@@ -34,14 +34,16 @@ public class ElanExtnTepListener extends AsyncDataTreeChangeListenerBase<Externa
     private final DataBroker broker;
     private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
     private final JobCoordinator jobCoordinator;
+    private final ElanInstanceCache elanInstanceCache;
 
     @Inject
     public ElanExtnTepListener(DataBroker dataBroker, ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils,
-            JobCoordinator jobCoordinator) {
+            JobCoordinator jobCoordinator, ElanInstanceCache elanInstanceCache) {
         super(ExternalTeps.class, ElanExtnTepListener.class);
         this.broker = dataBroker;
         this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
         this.jobCoordinator = jobCoordinator;
+        this.elanInstanceCache = elanInstanceCache;
     }
 
     @Override
@@ -74,7 +76,10 @@ public class ElanExtnTepListener extends AsyncDataTreeChangeListenerBase<Externa
     @SuppressWarnings("checkstyle:IllegalCatch")
     private void updateElanRemoteBroadCastGroup(final InstanceIdentifier<ExternalTeps> iid) {
         String elanName = iid.firstKeyOf(ElanInstance.class).getElanInstanceName();
-        ElanInstance elanInfo = ElanUtils.getElanInstanceByName(broker, elanName);
+        ElanInstance elanInfo = elanInstanceCache.get(elanName).orNull();
+        if (elanInfo == null) {
+            return;
+        }
 
         jobCoordinator.enqueueJob(elanName, () -> {
             SettableFuture<Void> ft = SettableFuture.create();
index 759f94be1ba44b62db88d4f091fac278ce8160f5..8b77a03a00adf8439b496754bc75e19350c98b75 100644 (file)
@@ -59,6 +59,7 @@ import org.opendaylight.genius.mdsalutil.matches.MatchTunnelId;
 import org.opendaylight.genius.utils.ServiceIndex;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
 import org.opendaylight.netvirt.elan.ElanException;
+import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
 import org.opendaylight.netvirt.elan.utils.ElanConstants;
@@ -144,6 +145,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
     private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
     private final ElanUtils elanUtils;
     private final JobCoordinator jobCoordinator;
+    private final ElanInstanceCache elanInstanceCache;
 
     private final Map<String, ConcurrentLinkedQueue<ElanInterface>>
         unProcessedElanInterfaces = new ConcurrentHashMap<>();
@@ -155,7 +157,8 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                                 final INeutronVpnManager neutronVpnManager, final ElanItmUtils elanItmUtils,
                                 final ElanEtreeUtils elanEtreeUtils, final ElanL2GatewayUtils elanL2GatewayUtils,
                                 final ElanUtils elanUtils, final JobCoordinator jobCoordinator,
-                                final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils) {
+                                final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils,
+                                final ElanInstanceCache elanInstanceCache) {
         super(ElanInterface.class, ElanInterfaceManager.class);
         this.broker = dataBroker;
         this.idManager = managerService;
@@ -169,6 +172,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         this.elanUtils = elanUtils;
         this.jobCoordinator = jobCoordinator;
         this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
+        this.elanInstanceCache = elanInstanceCache;
     }
 
     @Override
@@ -185,7 +189,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
     @Override
     protected void remove(InstanceIdentifier<ElanInterface> identifier, ElanInterface del) {
         String interfaceName = del.getName();
-        ElanInstance elanInfo = ElanUtils.getElanInstanceByName(broker, del.getElanInstanceName());
+        ElanInstance elanInfo = elanInstanceCache.get(del.getElanInstanceName()).orNull();
         /*
          * Handling in case the elan instance is deleted.If the Elan instance is
          * deleted, there is no need to explicitly delete the elan interfaces
@@ -525,7 +529,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                         tx);
             } else {
                 elanForwardingEntriesHandler.addElanInterfaceForwardingTableList(
-                        ElanUtils.getElanInstanceByName(broker, elanName), interfaceName, staticMacEntry, tx);
+                        elanName, interfaceName, staticMacEntry, tx);
             }
             ElanUtils.waitForTransactionToComplete(tx);
         }
@@ -540,7 +544,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
             LOG.info("Interface {} is removed from Interface Oper DS due to port down ", interfaceName);
             return;
         }
-        ElanInstance elanInstance = ElanUtils.getElanInstanceByName(broker, elanInstanceName);
+        ElanInstance elanInstance = elanInstanceCache.get(elanInstanceName).orNull();
 
         if (elanInstance == null) {
             elanInstance = new ElanInstanceBuilder().setElanInstanceName(elanInstanceName)
@@ -735,7 +739,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                             existingMacEntry.get(), tx);
                 } else {
                     elanForwardingEntriesHandler
-                            .addElanInterfaceForwardingTableList(elanInstance, interfaceName, staticMacEntry, tx);
+                            .addElanInterfaceForwardingTableList(elanInstanceName, interfaceName, staticMacEntry, tx);
                 }
 
                 if (isInterfaceOperational) {
@@ -791,7 +795,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                 .setKey(new MacEntryKey(physAddress)).build();
         WriteTransaction tx = broker.newWriteOnlyTransaction();
         elanForwardingEntriesHandler.deleteElanInterfaceForwardingEntries(
-                ElanUtils.getElanInstanceByName(broker, elanInstanceName), interfaceInfo, macEntry, tx);
+                elanInstanceCache.get(elanInstanceName).orNull(), interfaceInfo, macEntry, tx);
         ElanUtils.waitForTransactionToComplete(tx);
     }
 
@@ -1513,7 +1517,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         for (ElanDpnInterfacesList elanDpns : elanDpnIf) {
             int cnt = 0;
             String elanName = elanDpns.getElanInstanceName();
-            ElanInstance elanInfo = ElanUtils.getElanInstanceByName(broker, elanName);
+            ElanInstance elanInfo = elanInstanceCache.get(elanName).orNull();
             if (elanInfo == null) {
                 LOG.warn("ELAN Info is null for elanName {} that does exist in elanDpnInterfaceList, "
                         + "skipping this ELAN for tunnel handling", elanName);
@@ -1603,10 +1607,10 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         List<ElanDpnInterfacesList> elanDpnIf = dpnInterfaceLists.getElanDpnInterfacesList();
         for (ElanDpnInterfacesList elanDpns : elanDpnIf) {
             String elanName = elanDpns.getElanInstanceName();
-            ElanInstance elanInfo = ElanUtils.getElanInstanceByName(broker, elanName);
+            ElanInstance elanInfo = elanInstanceCache.get(elanName).orNull();
 
             DpnInterfaces dpnInterfaces = elanUtils.getElanInterfaceInfoByElanDpn(elanName, dpId);
-            if (dpnInterfaces == null || dpnInterfaces.getInterfaces() == null
+            if (elanInfo == null || dpnInterfaces == null || dpnInterfaces.getInterfaces() == null
                     || dpnInterfaces.getInterfaces().isEmpty()) {
                 continue;
             }
index edd5cfd38a4a18af33abb62e7d49f79608301e93..a4dfd14649411d9c1eaf76fa8686385965a2fbd1 100644 (file)
@@ -17,6 +17,7 @@ import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
 import org.opendaylight.genius.interfacemanager.globals.InterfaceInfo;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
+import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.utils.ElanConstants;
 import org.opendaylight.netvirt.elan.utils.ElanUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan;
@@ -38,14 +39,16 @@ public class ElanInterfaceStateChangeListener
     private final DataBroker broker;
     private final ElanInterfaceManager elanInterfaceManager;
     private final JobCoordinator jobCoordinator;
+    private final ElanInstanceCache elanInstanceCache;
 
     @Inject
     public ElanInterfaceStateChangeListener(final DataBroker db, final ElanInterfaceManager ifManager,
-            final JobCoordinator jobCoordinator) {
+            final JobCoordinator jobCoordinator, final ElanInstanceCache elanInstanceCache) {
         super(Interface.class, ElanInterfaceStateChangeListener.class);
         broker = db;
         elanInterfaceManager = ifManager;
         this.jobCoordinator = jobCoordinator;
+        this.elanInstanceCache = elanInstanceCache;
     }
 
     @Override
@@ -73,7 +76,7 @@ public class ElanInterfaceStateChangeListener
         interfaceInfo.setInterfaceType(InterfaceInfo.InterfaceType.VLAN_INTERFACE);
         interfaceInfo.setInterfaceTag(delIf.getIfIndex());
         String elanInstanceName = elanInterface.getElanInstanceName();
-        ElanInstance elanInstance = ElanUtils.getElanInstanceByName(broker, elanInstanceName);
+        ElanInstance elanInstance = elanInstanceCache.get(elanInstanceName).orNull();
         if (elanInstance == null) {
             LOG.debug("No Elan instance is available for the interface:{} ", interfaceName);
             return;
index 9c934510c96800d1637898b99abba2cf070eb5fb..96882d4072c24b2440755e823eb16a4eef36f99b 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.netvirt.elan.internal;
 
 import com.google.common.util.concurrent.ListenableFuture;
+import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -19,11 +20,19 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
+import org.opendaylight.genius.interfacemanager.globals.InterfaceInfo;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
+import org.opendaylight.netvirt.elan.ElanException;
+import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.utils.ElanConstants;
 import org.opendaylight.netvirt.elan.utils.ElanUtils;
+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.netvirt.elan.rev150602.elan.instances.ElanInstance;
 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.forwarding.entries.MacEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.forwarding.entries.MacEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.forwarding.entries.MacEntryKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.LearntVpnVipToPortData;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -38,15 +47,17 @@ public class ElanLearntVpnVipToPortListener extends
     private final IInterfaceManager interfaceManager;
     private final ElanUtils elanUtils;
     private final JobCoordinator jobCoordinator;
+    private final ElanInstanceCache elanInstanceCache;
 
     @Inject
     public ElanLearntVpnVipToPortListener(DataBroker broker, IInterfaceManager interfaceManager, ElanUtils elanUtils,
-            JobCoordinator jobCoordinator) {
+            JobCoordinator jobCoordinator, ElanInstanceCache elanInstanceCache) {
         super(LearntVpnVipToPort.class, ElanLearntVpnVipToPortListener.class);
         this.broker = broker;
         this.interfaceManager = interfaceManager;
         this.elanUtils = elanUtils;
         this.jobCoordinator = jobCoordinator;
+        this.elanInstanceCache = elanInstanceCache;
     }
 
     @Override
@@ -106,13 +117,33 @@ public class ElanLearntVpnVipToPortListener extends
             }
             WriteTransaction interfaceTx = broker.newWriteOnlyTransaction();
             WriteTransaction flowTx = broker.newWriteOnlyTransaction();
-            elanUtils.addMacEntryToDsAndSetupFlows(interfaceName, macAddress,
-                    elanInterface.getElanInstanceName(), interfaceTx, flowTx, ElanConstants.STATIC_MAC_TIMEOUT);
+            addMacEntryToDsAndSetupFlows(elanInterface.getElanInstanceName(), interfaceTx,
+                    flowTx, ElanConstants.STATIC_MAC_TIMEOUT);
             List<ListenableFuture<Void>> futures = new ArrayList<>();
             futures.add(interfaceTx.submit());
             futures.add(flowTx.submit());
             return futures;
         }
+
+        private void addMacEntryToDsAndSetupFlows(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);
+            BigInteger timeStamp = new BigInteger(String.valueOf(System.currentTimeMillis()));
+            PhysAddress physAddress = new PhysAddress(macAddress);
+            MacEntry macEntry = new MacEntryBuilder().setInterface(interfaceName).setMacAddress(physAddress)
+                    .setKey(new MacEntryKey(physAddress)).setControllerLearnedForwardingEntryTimestamp(timeStamp)
+                    .setIsStaticAddress(false).build();
+            InstanceIdentifier<MacEntry> macEntryId = ElanUtils
+                    .getInterfaceMacEntriesIdentifierOperationalDataPath(interfaceName, physAddress);
+            interfaceTx.put(LogicalDatastoreType.OPERATIONAL, macEntryId, macEntry);
+            InstanceIdentifier<MacEntry> elanMacEntryId =
+                    ElanUtils.getMacEntryOperationalDataPath(elanName, physAddress);
+            interfaceTx.put(LogicalDatastoreType.OPERATIONAL, elanMacEntryId, macEntry);
+            ElanInstance elanInstance = elanInstanceCache.get(elanName).orNull();
+            elanUtils.setupMacFlows(elanInstance, interfaceManager.getInterfaceInfo(interfaceName), macTimeOut,
+                    macAddress, true, flowTx);
+        }
     }
 
     private class StaticMacRemoveWorker implements Callable<List<ListenableFuture<Void>>> {
@@ -133,13 +164,29 @@ public class ElanLearntVpnVipToPortListener extends
             }
             WriteTransaction interfaceTx = broker.newWriteOnlyTransaction();
             WriteTransaction flowTx = broker.newWriteOnlyTransaction();
-            elanUtils.deleteMacEntryFromDsAndRemoveFlows(interfaceName, macAddress,
-                    elanInterface.getElanInstanceName(), interfaceTx, flowTx);
+            deleteMacEntryFromDsAndRemoveFlows(elanInterface.getElanInstanceName(), interfaceTx,
+                    flowTx);
             List<ListenableFuture<Void>> futures = new ArrayList<>();
             futures.add(interfaceTx.submit());
             futures.add(flowTx.submit());
             return futures;
         }
+
+        private void deleteMacEntryFromDsAndRemoveFlows(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 = elanUtils.getInterfaceMacEntriesOperationalDataPath(interfaceName, physAddress);
+            InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(interfaceName);
+            if (macEntry != null && interfaceInfo != null) {
+                elanUtils.deleteMacFlows(elanInstanceCache.get(elanName).orNull(), interfaceInfo, macEntry, flowTx);
+            }
+            interfaceTx.delete(LogicalDatastoreType.OPERATIONAL,
+                    ElanUtils.getInterfaceMacEntriesIdentifierOperationalDataPath(interfaceName, physAddress));
+            interfaceTx.delete(LogicalDatastoreType.OPERATIONAL,
+                    ElanUtils.getMacEntryOperationalDataPath(elanName, physAddress));
+        }
     }
 
     private String buildJobKey(String mac, String interfaceName) {
index 75a518bd3f2180499c8dc07691ece74a97bfa4f4..6db538831c2d5193dcc45fff458dd92697b751dd 100755 (executable)
@@ -22,6 +22,7 @@ import org.opendaylight.genius.mdsalutil.NWUtil;
 import org.opendaylight.genius.mdsalutil.NwConstants;
 import org.opendaylight.genius.mdsalutil.packet.Ethernet;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
+import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.evpn.utils.EvpnUtils;
 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
 import org.opendaylight.netvirt.elan.utils.ElanUtils;
@@ -55,16 +56,19 @@ public class ElanPacketInHandler implements PacketProcessingListener {
     private final ElanL2GatewayUtils elanL2GatewayUtils;
     private final EvpnUtils evpnUtils;
     private final JobCoordinator jobCoordinator;
+    private final ElanInstanceCache elanInstanceCache;
 
     @Inject
     public ElanPacketInHandler(DataBroker dataBroker, final IInterfaceManager interfaceManager, ElanUtils elanUtils,
-            EvpnUtils evpnUtils, ElanL2GatewayUtils elanL2GatewayUtils, JobCoordinator jobCoordinator) {
+            EvpnUtils evpnUtils, ElanL2GatewayUtils elanL2GatewayUtils, JobCoordinator jobCoordinator,
+            ElanInstanceCache elanInstanceCache) {
         broker = dataBroker;
         this.interfaceManager = interfaceManager;
         this.elanUtils = elanUtils;
         this.elanL2GatewayUtils = elanL2GatewayUtils;
         this.evpnUtils = evpnUtils;
         this.jobCoordinator = jobCoordinator;
+        this.elanInstanceCache = elanInstanceCache;
     }
 
     @Override
@@ -126,13 +130,13 @@ public class ElanPacketInHandler implements PacketProcessingListener {
                 if (srcIpAddress.isPresent()) {
                     String prefix = srcIpAddress.get().getIpv4Address().getValue();
                     InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(interfaceName);
-                    ElanInstance elanInstance = ElanUtils.getElanInstanceByName(broker, elanName);
+                    ElanInstance elanInstance = elanInstanceCache.get(elanName).orNull();
                     evpnUtils.advertisePrefix(elanInstance, macAddress, prefix, interfaceName, interfaceInfo.getDpId());
                 }
                 enqueueJobForMacSpecificTasks(macAddress, elanTag, interfaceName, elanName, physAddress, oldMacEntry,
                         newMacEntry, isVlanOrFlatProviderIface);
 
-                ElanInstance elanInstance = ElanUtils.getElanInstanceByName(broker, elanName);
+                ElanInstance elanInstance = elanInstanceCache.get(elanName).orNull();
                 InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(interfaceName);
                 if (interfaceInfo == null) {
                     LOG.trace("Interface:{} is not present under Config DS", interfaceName);
@@ -223,7 +227,7 @@ public class ElanPacketInHandler implements PacketProcessingListener {
      * Static MAC having been added on a wrong ELAN.
      */
     private void tryAndRemoveInvalidMacEntry(String elanName, MacEntry macEntry) {
-        ElanInstance elanInfo = ElanUtils.getElanInstanceByName(broker, elanName);
+        ElanInstance elanInfo = elanInstanceCache.get(elanName).orNull();
         if (elanInfo == null) {
             LOG.warn("MAC {} is been added (either statically or dynamically) for an invalid Elan {}. "
                     + "Manual cleanup may be necessary", macEntry.getMacAddress(), elanName);
index a1504834d46b3130d1cf7c5fbb3c8256bbc63ffe..d696419ea59eb81c9936e21674e0621d585bbe44 100644 (file)
@@ -32,6 +32,7 @@ import org.opendaylight.genius.mdsalutil.MDSALUtil;
 import org.opendaylight.genius.mdsalutil.MatchInfoBase;
 import org.opendaylight.genius.mdsalutil.MetaDataUtil;
 import org.opendaylight.genius.mdsalutil.NwConstants;
+import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.genius.mdsalutil.nxmatches.NxMatchRegister;
 import org.opendaylight.genius.utils.ServiceIndex;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants;
@@ -41,6 +42,8 @@ import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipCandidateRegistrati
 import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService;
 import org.opendaylight.mdsal.eos.common.api.CandidateAlreadyRegisteredException;
 import org.opendaylight.netvirt.elan.arp.responder.ArpResponderInput;
+import org.opendaylight.netvirt.elan.arp.responder.ArpResponderUtil;
+import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.utils.ElanConstants;
 import org.opendaylight.netvirt.elan.utils.ElanUtils;
 import org.opendaylight.netvirt.elanmanager.api.ElanHelper;
@@ -92,6 +95,8 @@ public class ElanServiceProvider extends AbstractLifecycle implements IElanServi
     private final DataBroker broker;
     private final ElanUtils elanUtils;
     private final SouthboundUtils southboundUtils;
+    private final IMdsalApiManager mdsalManager;
+    private final ElanInstanceCache elanInstanceCache;
     private boolean isL2BeforeL3;
 
     private final EntityOwnershipCandidateRegistration candidateRegistration;
@@ -103,7 +108,8 @@ public class ElanServiceProvider extends AbstractLifecycle implements IElanServi
                                ElanInterfaceManager elanInterfaceManager,
                                ElanUtils elanUtils,
                                EntityOwnershipService entityOwnershipService,
-                               SouthboundUtils southboundUtils) {
+                               SouthboundUtils southboundUtils, ElanInstanceCache elanInstanceCache,
+                               IMdsalApiManager mdsalManager) {
         this.idManager = idManager;
         this.interfaceManager = interfaceManager;
         this.elanInstanceManager = elanInstanceManager;
@@ -111,6 +117,8 @@ public class ElanServiceProvider extends AbstractLifecycle implements IElanServi
         this.broker = dataBroker;
         this.elanUtils = elanUtils;
         this.southboundUtils = southboundUtils;
+        this.elanInstanceCache = elanInstanceCache;
+        this.mdsalManager = mdsalManager;
 
         candidateRegistration = registerCandidate(entityOwnershipService);
     }
@@ -413,7 +421,7 @@ public class ElanServiceProvider extends AbstractLifecycle implements IElanServi
 
     @Override
     public ElanInstance getElanInstance(String elanName) {
-        return ElanUtils.getElanInstanceByName(broker, elanName);
+        return elanInstanceCache.get(elanName).orNull();
     }
 
     @Override
@@ -672,7 +680,7 @@ public class ElanServiceProvider extends AbstractLifecycle implements IElanServi
             LOG.trace("ELAN service is after L3VPN in the Netvirt pipeline skip known L3DMAC flows installation");
             return;
         }
-        ElanInstance elanInstance = ElanUtils.getElanInstanceByName(broker, elanInstanceName);
+        ElanInstance elanInstance = elanInstanceCache.get(elanInstanceName).orNull();
         if (elanInstance == null) {
             LOG.warn("Null elan instance {}", elanInstanceName);
             return;
@@ -694,7 +702,7 @@ public class ElanServiceProvider extends AbstractLifecycle implements IElanServi
             LOG.trace("ELAN service is after L3VPN in the Netvirt pipeline skip known L3DMAC flows installation");
             return;
         }
-        ElanInstance elanInstance = ElanUtils.getElanInstanceByName(broker, elanInstanceName);
+        ElanInstance elanInstance = elanInstanceCache.get(elanInstanceName).orNull();
         if (elanInstance == null) {
             LOG.warn("Null elan instance {}", elanInstanceName);
             return;
@@ -849,16 +857,51 @@ public class ElanServiceProvider extends AbstractLifecycle implements IElanServi
 
     @Override
     public void addArpResponderFlow(ArpResponderInput arpResponderInput) {
-        elanUtils.addArpResponderFlow(arpResponderInput.getDpId(), arpResponderInput.getInterfaceName(),
-                arpResponderInput.getSpa(), arpResponderInput.getSha(), arpResponderInput.getLportTag(),
+        String ingressInterfaceName = arpResponderInput.getInterfaceName();
+        String macAddress = arpResponderInput.getSha();
+        String ipAddress = arpResponderInput.getSpa();
+        int lportTag = arpResponderInput.getLportTag();
+        BigInteger dpnId = arpResponderInput.getDpId();
+
+        LOG.info("Installing the ARP responder flow on DPN {} for Interface {} with MAC {} & IP {}", dpnId,
+                ingressInterfaceName, macAddress, ipAddress);
+        ElanInterface elanIface = ElanUtils.getElanInterfaceByElanInterfaceName(broker, ingressInterfaceName);
+        ElanInstance elanInstance = elanInstanceCache.get(elanIface.getElanInstanceName()).orNull();
+        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),
                 arpResponderInput.getInstructions());
+        LOG.info("Installed the ARP Responder flow for Interface {}", ingressInterfaceName);
     }
 
     @Override
     public void addExternalTunnelArpResponderFlow(ArpResponderInput arpResponderInput, String elanInstanceName) {
-        elanUtils.addExternalTunnelArpResponderFlow(arpResponderInput.getDpId(), arpResponderInput.getSpa(),
-                arpResponderInput.getSha(), arpResponderInput.getLportTag(),
-                arpResponderInput.getInstructions(), elanInstanceName);
+        BigInteger dpnId = arpResponderInput.getDpId();
+        String ipAddress = arpResponderInput.getSpa();
+        String macAddress = arpResponderInput.getSha();
+
+        LOG.trace("Installing the ExternalTunnel ARP responder flow on DPN {} for ElanInstance {} with MAC {} & IP {}",
+                dpnId, elanInstanceName, macAddress, ipAddress);
+
+        ElanInstance elanInstance = elanInstanceCache.get(elanInstanceName).orNull();
+        if (elanInstance == null) {
+            LOG.warn("Null elan instance {}", elanInstanceName);
+            return;
+        }
+
+        int lportTag = arpResponderInput.getLportTag();
+        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), arpResponderInput.getInstructions());
+        LOG.trace("Installed the ExternalTunnel ARP Responder flow for ElanInstance {}", elanInstanceName);
     }
 
     @Override
index ab74c0ad23fdb212ee3665f364086ea02694be5b..1ece47d77c296392b25c625069eaca072ab24161 100644 (file)
@@ -25,6 +25,7 @@ import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
 import org.opendaylight.genius.mdsalutil.MetaDataUtil;
 import org.opendaylight.genius.mdsalutil.NwConstants;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
+import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.utils.ElanConstants;
 import org.opendaylight.netvirt.elan.utils.ElanUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
@@ -51,14 +52,16 @@ public class ElanSmacFlowEventListener implements SalFlowListener {
     private final IInterfaceManager interfaceManager;
     private final ElanUtils elanUtils;
     private final JobCoordinator jobCoordinator;
+    private final ElanInstanceCache elanInstanceCache;
 
     @Inject
     public ElanSmacFlowEventListener(DataBroker broker, IInterfaceManager interfaceManager, ElanUtils elanUtils,
-            JobCoordinator jobCoordinator) {
+            JobCoordinator jobCoordinator, ElanInstanceCache elanInstanceCache) {
         this.broker = broker;
         this.interfaceManager = interfaceManager;
         this.elanUtils = elanUtils;
         this.jobCoordinator = jobCoordinator;
+        this.elanInstanceCache = elanInstanceCache;
     }
 
     @Override
@@ -103,7 +106,7 @@ public class ElanSmacFlowEventListener implements SalFlowListener {
                 LOG.info("Deleting the Mac-Entry:{} present on ElanInstance:{}", macEntry, elanInstanceName);
                 if (macEntry != null && interfaceInfo != null) {
                     WriteTransaction deleteFlowTx = broker.newWriteOnlyTransaction();
-                    elanUtils.deleteMacFlows(ElanUtils.getElanInstanceByName(broker, elanInstanceName), interfaceInfo,
+                    elanUtils.deleteMacFlows(elanInstanceCache.get(elanInstanceName).orNull(), interfaceInfo,
                             macEntry, deleteFlowTx);
                     ListenableFuture<Void> result = deleteFlowTx.submit();
                     elanFutures.add(result);
index bfd66da2e5add271776089df2a0ffac12ed5213b..829a8369e12f39790399302a0073485ca17f9e9a 100644 (file)
@@ -9,13 +9,13 @@ package org.opendaylight.netvirt.elan.l2gw.listeners;
 
 import java.math.BigInteger;
 import java.util.List;
-import java.util.Set;
 import java.util.concurrent.ConcurrentMap;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase;
+import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
 import org.opendaylight.netvirt.elan.utils.ElanClusterUtils;
 import org.opendaylight.netvirt.elan.utils.ElanUtils;
@@ -40,15 +40,17 @@ public class ElanGroupListener extends AsyncClusteredDataTreeChangeListenerBase<
     private final ElanClusterUtils elanClusterUtils;
     private final ElanUtils elanUtils;
     private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
+    private final ElanInstanceCache elanInstanceCache;
 
     @Inject
     public ElanGroupListener(DataBroker db, ElanClusterUtils elanClusterUtils, ElanUtils elanUtils,
-            ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils) {
+            ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils, ElanInstanceCache elanInstanceCache) {
         super(Group.class, ElanGroupListener.class);
         broker = db;
         this.elanClusterUtils = elanClusterUtils;
         this.elanUtils = elanUtils;
         this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
+        this.elanInstanceCache = elanInstanceCache;
         registerListener(LogicalDatastoreType.CONFIGURATION, broker);
         LOG.trace("ElanGroupListener registered");
     }
@@ -66,9 +68,7 @@ public class ElanGroupListener extends AsyncClusteredDataTreeChangeListenerBase<
 
 
     ElanInstance getElanInstanceFromGroupId(Group update) {
-        Set<String> elanNames = ElanUtils.getAllElanNames();
-        for (String elanName : elanNames) {
-            ElanInstance elanInstance = ElanUtils.getElanInstanceByName(broker, elanName);
+        for (ElanInstance elanInstance : elanInstanceCache.getAllPresent()) {
             if (elanInstance.getElanTag() != null) {
                 long elanTag = elanInstance.getElanTag();
                 long elanBCGroupId = ElanUtils.getElanRemoteBroadCastGroupID(elanTag);
index d9585087c1ee496e41c49063811a9be8c06c736e..c115a6576edff5f6a0c466b795491474e0cc2f01 100644 (file)
@@ -14,8 +14,8 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.hwvtep.HwvtepClusteredDataTreeChangeListener;
 import org.opendaylight.genius.utils.batching.ResourceBatchingManager;
 import org.opendaylight.genius.utils.hwvtep.HwvtepUtils;
+import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
-import org.opendaylight.netvirt.elan.utils.ElanUtils;
 import org.opendaylight.netvirt.elanmanager.utils.ElanL2GwCacheUtils;
 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
@@ -43,12 +43,15 @@ public class HwvtepLocalUcastMacListener extends
 
     private final DataBroker broker;
     private final ElanL2GatewayUtils elanL2GatewayUtils;
+    private final ElanInstanceCache elanInstanceCache;
 
-    public HwvtepLocalUcastMacListener(DataBroker broker, ElanL2GatewayUtils elanL2GatewayUtils) {
+    public HwvtepLocalUcastMacListener(DataBroker broker, ElanL2GatewayUtils elanL2GatewayUtils,
+            ElanInstanceCache elanInstanceCache) {
         super(LocalUcastMacs.class, HwvtepLocalUcastMacListener.class);
 
         this.broker = broker;
         this.elanL2GatewayUtils = elanL2GatewayUtils;
+        this.elanInstanceCache = elanInstanceCache;
         ResourceBatchingManager.getInstance().registerDefaultBatchHandlers(this.broker);
     }
 
@@ -75,7 +78,7 @@ public class HwvtepLocalUcastMacListener extends
         elanL2GwDevice.removeUcastLocalMac(macRemoved);
         elanL2GatewayUtils.unInstallL2GwUcastMacFromL2gwDevices(elanName, elanL2GwDevice,
                 Collections.singletonList(new MacAddress(macAddress.toLowerCase(Locale.getDefault()))));
-        elanL2GatewayUtils.unInstallL2GwUcastMacFromElanDpns(ElanUtils.getElanInstanceByName(broker, elanName),
+        elanL2GatewayUtils.unInstallL2GwUcastMacFromElanDpns(elanInstanceCache.get(elanName).orNull(),
                 elanL2GwDevice, Collections.singletonList(new MacAddress(macAddress.toLowerCase(Locale.getDefault()))));
     }
 
@@ -99,7 +102,7 @@ public class HwvtepLocalUcastMacListener extends
         LOG.trace("LocalUcastMacs {} added to {}", macAddress, hwvtepNodeId);
 
         String elanName = getElanName(macAdded);
-        ElanInstance elan = ElanUtils.getElanInstanceByName(broker, elanName);
+        ElanInstance elan = elanInstanceCache.get(elanName).orNull();
         if (elan == null) {
             LOG.warn("Could not find ELAN for mac {} being added", macAddress);
             return;
index f0503e57123545d02e00cbaa3d7e37021a3deb3f..21e6496fc52e295bcf1b1c5d4ae305998ff157da 100644 (file)
@@ -31,10 +31,10 @@ import org.opendaylight.genius.utils.batching.ResourceBatchingManager;
 import org.opendaylight.genius.utils.hwvtep.HwvtepHACache;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
+import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
 import org.opendaylight.netvirt.elan.l2gw.ha.listeners.HAOpClusteredListener;
 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
-import org.opendaylight.netvirt.elan.utils.ElanUtils;
 import org.opendaylight.netvirt.elanmanager.utils.ElanL2GwCacheUtils;
 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
@@ -68,16 +68,19 @@ public class LocalUcastMacListener extends ChildListener<Node, LocalUcastMacs, S
     private final ElanL2GatewayUtils elanL2GatewayUtils;
     private final HAOpClusteredListener haOpClusteredListener;
     private final JobCoordinator jobCoordinator;
+    private final ElanInstanceCache elanInstanceCache;
 
     @Inject
     public LocalUcastMacListener(final DataBroker dataBroker,
                                  final HAOpClusteredListener haOpClusteredListener,
                                  final ElanL2GatewayUtils elanL2GatewayUtils,
-                                 final JobCoordinator jobCoordinator) {
+                                 final JobCoordinator jobCoordinator,
+                                 final ElanInstanceCache elanInstanceCache) {
         super(dataBroker, false);
         this.elanL2GatewayUtils = elanL2GatewayUtils;
         this.haOpClusteredListener = haOpClusteredListener;
         this.jobCoordinator = jobCoordinator;
+        this.elanInstanceCache = elanInstanceCache;
     }
 
     @Override
@@ -140,7 +143,7 @@ public class LocalUcastMacListener extends ChildListener<Node, LocalUcastMacs, S
                 }
 
                 elanL2GwDevice.removeUcastLocalMac(macRemoved);
-                ElanInstance elanInstance = ElanUtils.getElanInstanceByName(dataBroker, elanName);
+                ElanInstance elanInstance = elanInstanceCache.get(elanName).orNull();
                 elanL2GatewayUtils.unInstallL2GwUcastMacFromL2gwDevices(elanName, elanL2GwDevice,
                         Collections.singletonList(new MacAddress(macAddress.toLowerCase(Locale.getDefault()))));
                 elanL2GatewayUtils.unInstallL2GwUcastMacFromElanDpns(elanInstance, elanL2GwDevice,
@@ -159,7 +162,7 @@ public class LocalUcastMacListener extends ChildListener<Node, LocalUcastMacs, S
 
         LOG.trace("LocalUcastMacs {} added to {}", macAddress, hwvtepNodeId);
 
-        ElanInstance elan = ElanUtils.getElanInstanceByName(dataBroker, elanName);
+        ElanInstance elan = elanInstanceCache.get(elanName).orNull();
         if (elan == null) {
             LOG.warn("Could not find ELAN for mac {} being added", macAddress);
             return;
index ae3874d949c5b2559f6f3ec0dc580afbb3ad7e94..466a230b8e035689e74380777bc3d423f7925cb5 100644 (file)
@@ -34,7 +34,6 @@ import javax.annotation.Nonnull;
 import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
-
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -49,6 +48,7 @@ import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
 import org.opendaylight.genius.utils.hwvtep.HwvtepUtils;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
 import org.opendaylight.netvirt.elan.ElanException;
+import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.l2gw.jobs.DeleteL2GwDeviceMacsFromElanJob;
 import org.opendaylight.netvirt.elan.l2gw.jobs.DeleteLogicalSwitchJob;
 import org.opendaylight.netvirt.elan.utils.ElanClusterUtils;
@@ -118,6 +118,7 @@ public class ElanL2GatewayUtils {
     private final OdlInterfaceRpcService interfaceManagerRpcService;
     private final JobCoordinator jobCoordinator;
     private final ElanUtils elanUtils;
+    private final ElanInstanceCache elanInstanceCache;
 
     private final ConcurrentMap<Pair<NodeId, String>, ScheduledFuture> logicalSwitchDeletedTasks
             = new ConcurrentHashMap<>();
@@ -129,7 +130,7 @@ public class ElanL2GatewayUtils {
     public ElanL2GatewayUtils(DataBroker broker, ElanDmacUtils elanDmacUtils, ElanItmUtils elanItmUtils,
             ElanClusterUtils elanClusterUtils, OdlInterfaceRpcService interfaceManagerRpcService,
             JobCoordinator jobCoordinator, ElanUtils elanUtils,
-            Scheduler scheduler, ElanConfig elanConfig) {
+            Scheduler scheduler, ElanConfig elanConfig, ElanInstanceCache elanInstanceCache) {
         this.broker = broker;
         this.elanDmacUtils = elanDmacUtils;
         this.elanItmUtils = elanItmUtils;
@@ -139,6 +140,7 @@ public class ElanL2GatewayUtils {
         this.elanUtils = elanUtils;
         this.scheduler = scheduler;
         this.elanConfig = elanConfig;
+        this.elanInstanceCache = elanInstanceCache;
     }
 
     @PreDestroy
@@ -267,7 +269,7 @@ public class ElanL2GatewayUtils {
             if (ls != null) {
                 // Logical switch name is Elan name
                 String elanName = getElanFromLogicalSwitch(ls.getHwvtepNodeName().getValue());
-                return ElanUtils.getElanInstanceByName(broker, elanName);
+                return elanInstanceCache.get(elanName).orNull();
             } else {
                 String macAddress = localUcastMac.getMacEntryKey().getValue();
                 LOG.error("Could not find logical_switch for {} being added/deleted", macAddress);
@@ -485,7 +487,7 @@ public class ElanL2GatewayUtils {
             LOG.trace("No L2 gateway devices in Elan [{}] cache.", elanName);
             return;
         }
-        final ElanInstance elan = ElanUtils.getElanInstanceByName(broker, elanName);
+        final ElanInstance elan = elanInstanceCache.get(elanName).orNull();
         if (elan == null) {
             LOG.error("Could not find Elan by name: {}", elanName);
             return;
@@ -968,7 +970,7 @@ public class ElanL2GatewayUtils {
         LOG.info("Deleting L2GatewayDevice [{}] UcastLocalMacs from elan [{}]", l2GatewayDevice.getHwvtepNodeId(),
                 elanName);
 
-        ElanInstance elan = ElanUtils.getElanInstanceByName(broker, elanName);
+        ElanInstance elan = elanInstanceCache.get(elanName).orNull();
         if (elan == null) {
             LOG.error("Could not find Elan by name: {}", elanName);
             return;
index 9a8ae7dbac4ea100e0079b130fe8bae472e9976d..48f16049162389e9943d0df5bc12d1edb30ac55a 100644 (file)
@@ -30,6 +30,7 @@ import org.opendaylight.genius.mdsalutil.MDSALUtil;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
 import org.opendaylight.genius.utils.hwvtep.HwvtepUtils;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
+import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.internal.ElanInstanceManager;
 import org.opendaylight.netvirt.elan.l2gw.ha.listeners.HAOpClusteredListener;
 import org.opendaylight.netvirt.elan.l2gw.jobs.AssociateHwvtepToElanJob;
@@ -70,6 +71,7 @@ public class L2GatewayConnectionUtils implements AutoCloseable {
     private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
     private final JobCoordinator jobCoordinator;
     private final L2GatewayCache l2GatewayCache;
+    private final ElanInstanceCache elanInstanceCache;
     private final List<AutoCloseable> closeables = new CopyOnWriteArrayList<>();
     private final HAOpClusteredListener haOpClusteredListener;
 
@@ -77,7 +79,8 @@ public class L2GatewayConnectionUtils implements AutoCloseable {
     public L2GatewayConnectionUtils(DataBroker dataBroker, ElanInstanceManager elanInstanceManager,
             ElanClusterUtils elanClusterUtils, ElanL2GatewayUtils elanL2GatewayUtils,
             JobCoordinator jobCoordinator, ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils,
-            L2GatewayCache l2GatewayCache, HAOpClusteredListener haOpClusteredListener) {
+            L2GatewayCache l2GatewayCache, HAOpClusteredListener haOpClusteredListener,
+            ElanInstanceCache elanInstanceCache) {
         this.broker = dataBroker;
         this.elanInstanceManager = elanInstanceManager;
         this.elanL2GatewayUtils = elanL2GatewayUtils;
@@ -86,6 +89,7 @@ public class L2GatewayConnectionUtils implements AutoCloseable {
         this.jobCoordinator = jobCoordinator;
         this.l2GatewayCache = l2GatewayCache;
         this.haOpClusteredListener = haOpClusteredListener;
+        this.elanInstanceCache = elanInstanceCache;
     }
 
     @Override
@@ -370,7 +374,7 @@ public class L2GatewayConnectionUtils implements AutoCloseable {
                         public void onSuccess(@Nonnull Optional<Node> resultNode) {
                             LocalUcastMacListener localUcastMacListener =
                                     new LocalUcastMacListener(broker, haOpClusteredListener,
-                                            elanL2GatewayUtils, jobCoordinator);
+                                            elanL2GatewayUtils, jobCoordinator, elanInstanceCache);
                             settableFuture.set(resultNode);
                             Optional<Node> nodeOptional = resultNode;
                             if (nodeOptional.isPresent()) {
index e12aff3d0ae800f6d88317806c39ae1a47fa2dc7..56be989feeeb833bf6a86ff7cd26119e28cdc7bc 100644 (file)
@@ -14,7 +14,6 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
@@ -24,13 +23,13 @@ import java.util.function.Predicate;
 import java.util.stream.Collectors;
 import javax.inject.Inject;
 import javax.inject.Singleton;
-
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
 import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
+import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.utils.ElanUtils;
 import org.opendaylight.netvirt.elan.utils.Scheduler;
 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache;
@@ -77,6 +76,7 @@ public class StaleVlanBindingsCleaner {
     private final Scheduler scheduler;
     private final ElanConfig elanConfig;
     private final L2GatewayCache l2GatewayCache;
+    private final ElanInstanceCache elanInstanceCache;
     private final Map<NodeId, ScheduledFuture> cleanupTasks = new ConcurrentHashMap<>();
 
     @Inject
@@ -85,13 +85,15 @@ public class StaleVlanBindingsCleaner {
                                     final ElanL2GatewayUtils elanL2GatewayUtils,
                                     final Scheduler scheduler,
                                     final ElanConfig elanConfig,
-                                    final L2GatewayCache l2GatewayCache) {
+                                    final L2GatewayCache l2GatewayCache,
+                                    final ElanInstanceCache elanInstanceCache) {
         this.broker = broker;
         this.elanUtils = elanUtils;
         this.elanL2GatewayUtils = elanL2GatewayUtils;
         this.scheduler = scheduler;
         this.elanConfig = elanConfig;
         this.l2GatewayCache = l2GatewayCache;
+        this.elanInstanceCache = elanInstanceCache;
     }
 
     private long getCleanupDelay() {
@@ -134,7 +136,7 @@ public class StaleVlanBindingsCleaner {
 
         List<String> validNetworks = connectionsOfDevice.stream()
                 .map((connection) -> connection.getNetworkId().getValue())
-                .filter(elan -> elanUtils.getElanInstanceByName(broker, elan) != null)
+                .filter(elan -> elanInstanceCache.get(elan).isPresent())
                 .collect(Collectors.toList());
 
         List<String> logicalSwitchesOnDevice = getLogicalSwitchesOnDevice(configNode);
diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/CacheElanInstanceListener.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/CacheElanInstanceListener.java
deleted file mode 100644 (file)
index c51f782..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (c) 2016 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.netvirt.elan.utils;
-
-import java.util.Collection;
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInstances;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Singleton
-public class CacheElanInstanceListener implements ClusteredDataTreeChangeListener<ElanInstance> {
-
-    private static final Logger LOG = LoggerFactory.getLogger(CacheElanInstanceListener.class);
-
-    private final DataBroker broker;
-
-    private ListenerRegistration<CacheElanInstanceListener> registration;
-
-    @Inject
-    public CacheElanInstanceListener(DataBroker dataBroker) {
-        this.broker = dataBroker;
-    }
-
-    @PostConstruct
-    public void init() {
-        registerListener();
-    }
-
-    private void registerListener() {
-        final DataTreeIdentifier<ElanInstance> treeId =
-                new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, getWildcardPath());
-        LOG.trace("Registering on path: {}", treeId);
-        registration = broker.registerDataTreeChangeListener(treeId, CacheElanInstanceListener.this);
-    }
-
-    protected InstanceIdentifier<ElanInstance> getWildcardPath() {
-        return InstanceIdentifier.create(ElanInstances.class).child(ElanInstance.class);
-    }
-
-    @PreDestroy
-    public void close() throws Exception {
-        if (registration != null) {
-            registration.close();
-        }
-    }
-
-    @Override
-    public void onDataTreeChanged(Collection<DataTreeModification<ElanInstance>> changes) {
-        for (DataTreeModification<ElanInstance> change : changes) {
-            DataObjectModification<ElanInstance> mod = change.getRootNode();
-            switch (mod.getModificationType()) {
-                case DELETE:
-                    ElanUtils.removeElanInstanceFromCache(mod.getDataBefore().getElanInstanceName());
-                    break;
-                case SUBTREE_MODIFIED:
-                case WRITE:
-                    ElanInstance elanInstance = mod.getDataAfter();
-                    ElanUtils.addElanInstanceIntoCache(elanInstance.getElanInstanceName(), elanInstance);
-                    break;
-                default:
-                    throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
-            }
-        }
-    }
-
-}
index aeed676c5f712efb387fc496ff9b9554cb09b4fe..150dfbaa1c6fc52c57b0af59867ad3e8db12f086 100644 (file)
@@ -61,14 +61,14 @@ public class ElanForwardingEntriesHandler {
 
     }
 
-    public void addElanInterfaceForwardingTableList(ElanInstance elanInstance, String interfaceName,
+    public void addElanInterfaceForwardingTableList(String elanInstanceName, String interfaceName,
                                                     StaticMacEntries staticMacEntries, WriteTransaction tx) {
         MacEntry macEntry = new MacEntryBuilder().setIsStaticAddress(true)
                 .setMacAddress(staticMacEntries.getMacAddress())
                 .setIpPrefix(staticMacEntries.getIpPrefix())
                 .setInterface(interfaceName).setKey(new MacEntryKey(staticMacEntries.getMacAddress())).build();
 
-        createElanForwardingTablesList(elanInstance.getElanInstanceName(), macEntry, tx);
+        createElanForwardingTablesList(elanInstanceName, macEntry, tx);
         createElanInterfaceForwardingTablesList(interfaceName, macEntry, tx);
     }
 
index c615ff86af3af4f105ce7d1fb615ec39ab9139d6..475992beb867d918fd197b24cdeb2eaf1d7371e4 100755 (executable)
@@ -163,7 +163,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.tag.name.map.ElanTagNameBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.tag.name.map.ElanTagNameKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.forwarding.entries.MacEntry;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.forwarding.entries.MacEntryBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.forwarding.entries.MacEntryKey;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -177,7 +176,6 @@ 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<>();
@@ -222,22 +220,6 @@ public class ElanUtils {
                 ? elanConfig.isOpenstackVniSemanticsEnforced() : false;
     }
 
-    public static void addElanInstanceIntoCache(String elanInstanceName, ElanInstance elanInstance) {
-        elanInstanceLocalCache.put(elanInstanceName, elanInstance);
-    }
-
-    public static void removeElanInstanceFromCache(String elanInstanceName) {
-        elanInstanceLocalCache.remove(elanInstanceName);
-    }
-
-    public static ElanInstance getElanInstanceFromCache(String elanInstanceName) {
-        return elanInstanceLocalCache.get(elanInstanceName);
-    }
-
-    public static Set<String> getAllElanNames() {
-        return elanInstanceLocalCache.keySet();
-    }
-
     public static void addElanInterfaceIntoCache(String interfaceName, ElanInterface elanInterface) {
         elanInterfaceLocalCache.put(interfaceName, elanInterface);
     }
@@ -331,18 +313,6 @@ public class ElanUtils {
         return InstanceIdentifier.builder(ElanInstances.class).child(ElanInstance.class).build();
     }
 
-    // elan-instances config container
-    @Nullable
-    public static ElanInstance getElanInstanceByName(DataBroker broker, String elanInstanceName) {
-        ElanInstance elanObj = getElanInstanceFromCache(elanInstanceName);
-        if (elanObj != null) {
-            return elanObj;
-        }
-        InstanceIdentifier<ElanInstance> elanIdentifierId =
-                ElanHelper.getElanInstanceConfigurationDataPath(elanInstanceName);
-        return MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, elanIdentifierId).orNull();
-    }
-
     // elan-interfaces Config Container
     public static ElanInterface getElanInterfaceByElanInterfaceName(DataBroker broker, String elanInterfaceName) {
         ElanInterface elanInterfaceObj = getElanInterfaceFromCache(elanInterfaceName);
@@ -1444,11 +1414,6 @@ 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)
@@ -1542,62 +1507,6 @@ public class ElanUtils {
         return flow;
     }
 
-    /**
-     * Add Mac Address to ElanInterfaceForwardingEntries and ElanForwardingTables
-     * Install SMAC and DMAC flows.
-     * @param interfaceName interface name
-     * @param macAddress mac addresses
-     * @param elanName elan Name
-     * @param interfaceTx write transaction
-     * @param flowTx flow write transaction
-     * @param macTimeOut timeout value
-     * @throws ElanException elan exception is thrown upon write failure
-     */
-    public void addMacEntryToDsAndSetupFlows(String interfaceName,
-            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);
-        BigInteger timeStamp = new BigInteger(String.valueOf(System.currentTimeMillis()));
-        PhysAddress physAddress = new PhysAddress(macAddress);
-        MacEntry macEntry = new MacEntryBuilder().setInterface(interfaceName).setMacAddress(physAddress)
-                .setKey(new MacEntryKey(physAddress)).setControllerLearnedForwardingEntryTimestamp(timeStamp)
-                .setIsStaticAddress(false).build();
-        InstanceIdentifier<MacEntry> macEntryId = ElanUtils
-                .getInterfaceMacEntriesIdentifierOperationalDataPath(interfaceName, physAddress);
-        interfaceTx.put(LogicalDatastoreType.OPERATIONAL, macEntryId, macEntry);
-        InstanceIdentifier<MacEntry> elanMacEntryId = ElanUtils.getMacEntryOperationalDataPath(elanName, physAddress);
-        interfaceTx.put(LogicalDatastoreType.OPERATIONAL, elanMacEntryId, macEntry);
-        ElanInstance elanInstance = ElanUtils.getElanInstanceByName(broker, elanName);
-        setupMacFlows(elanInstance, interfaceManager.getInterfaceInfo(interfaceName), macTimeOut, macAddress, true,
-                flowTx);
-    }
-
-    /**
-     * Remove Mac Address from ElanInterfaceForwardingEntries and ElanForwardingTables
-     * Remove SMAC and DMAC flows.
-     * @param interfaceName interface name
-     * @param macAddress mac addresses
-     * @param elanName elan name
-     * @param interfaceTx write transaction
-     * @param flowTx flow write transaction
-     */
-    public void deleteMacEntryFromDsAndRemoveFlows(String interfaceName,
-            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, flowTx);
-        }
-        interfaceTx.delete(LogicalDatastoreType.OPERATIONAL,
-                ElanUtils.getInterfaceMacEntriesIdentifierOperationalDataPath(interfaceName, physAddress));
-        interfaceTx.delete(LogicalDatastoreType.OPERATIONAL,
-                ElanUtils.getMacEntryOperationalDataPath(elanName, physAddress));
-    }
-
     public String getExternalElanInterface(String elanInstanceName, BigInteger dpnId) {
         DpnInterfaces dpnInterfaces = getElanInterfaceInfoByElanDpn(elanInstanceName, dpnId);
         if (dpnInterfaces == null || dpnInterfaces.getInterfaces() == null) {
@@ -1796,37 +1705,6 @@ public class ElanUtils {
         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 addExternalTunnelArpResponderFlow(BigInteger dpnId, String ipAddress, String macAddress,
-                        int lportTag, List<Instruction> instructions, String elanInstanceName) {
-        LOG.trace("Installing the ExternalTunnel ARP responder flow on DPN {} for ElanInstance {} with MAC {} & IP {}",
-                dpnId, elanInstanceName, macAddress, ipAddress);
-        ElanInstance elanInstance = getElanInstanceByName(broker, elanInstanceName);
-        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.trace("Installed the ExternalTunnel ARP Responder flow for ElanInstance {}", elanInstanceName);
-    }
-
     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,
index 95eb0a3617bf752bce64360cd36b2f95065c5d0b..117d012b361e155052794b2c06ec5668d81b2aaa 100644 (file)
@@ -30,6 +30,7 @@ import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
+import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.internal.ElanBridgeManager;
 import org.opendaylight.netvirt.elanmanager.api.IElanService;
 import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
@@ -79,15 +80,18 @@ public class TransportZoneNotificationUtil {
     private final IElanService elanService;
     private final ElanConfig elanConfig;
     private final ElanBridgeManager elanBridgeManager;
+    private final ElanInstanceCache elanInstanceCache;
 
     @Inject
     public TransportZoneNotificationUtil(final DataBroker dbx, final IInterfaceManager interfaceManager,
-            final IElanService elanService, final ElanConfig elanConfig, final ElanBridgeManager elanBridgeManager) {
+            final IElanService elanService, final ElanConfig elanConfig, final ElanBridgeManager elanBridgeManager,
+            final ElanInstanceCache elanInstanceCache) {
         this.dataBroker = dbx;
         this.mdsalUtils = new MdsalUtils(dbx);
         this.elanService = elanService;
         this.elanConfig = elanConfig;
         this.elanBridgeManager = elanBridgeManager;
+        this.elanInstanceCache = elanInstanceCache;
         southBoundUtils = new SouthboundUtils(mdsalUtils);
     }
 
@@ -104,7 +108,7 @@ public class TransportZoneNotificationUtil {
                 continue;
             }
 
-            if (ElanUtils.isVxlanNetwork(dataBroker, elanInt.getElanInstanceName())) {
+            if (ElanUtils.isVxlan(elanInstanceCache.get(elanInt.getElanInstanceName()).orNull())) {
                 return true;
             } else {
                 LOG.debug("Non-VXLAN elanInstance: " + elanInt.getElanInstanceName());
index 9bb697e5c1359fb4afbefd56e500922c0eaee023..4b70c6042f83e6339bf262487ddccb7e6de51b9b 100644 (file)
@@ -26,6 +26,8 @@
              interface="org.opendaylight.infrautils.jobcoordinator.JobCoordinator"/>
   <reference id="l2GatewayCache"
              interface="org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache"/>
+  <reference id="cacheProvider"
+             interface="org.opendaylight.infrautils.caches.CacheProvider"/>
 
   <odl:rpc-service id="odlInterfaceRpcService"
     interface="org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService" />
index 6d1c007d1db2eb4d8c724b2ac20590c827f015cf..0174d4ad4c77a59a4f2ef3164c4d119cf5e82505 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.netvirt.elanmanager.tests;
 import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
 
 import com.google.common.base.Optional;
-
 import javax.inject.Inject;
 import org.junit.Before;
 import org.junit.Ignore;
@@ -25,6 +24,7 @@ import org.opendaylight.genius.interfacemanager.globals.InterfaceInfo;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
 import org.opendaylight.genius.mdsalutil.NwConstants;
 import org.opendaylight.genius.testutils.interfacemanager.TunnelInterfaceDetails;
+import org.opendaylight.infrautils.caches.testutils.CacheModule;
 import org.opendaylight.infrautils.inject.guice.testutils.GuiceRule;
 import org.opendaylight.infrautils.testutils.LogRule;
 import org.opendaylight.mdsal.binding.testutils.AssertDataObjects;
@@ -71,7 +71,8 @@ public class ElanServiceTest extends  ElanServiceTestBase {
     // public @Rule RunUntilFailureRule repeater = new RunUntilFailureRule(classRepeater);
 
     public @Rule LogRule logRule = new LogRule();
-    public @Rule MethodRule guice = new GuiceRule(ElanServiceTestModule.class, JobCoordinatorTestModule.class);
+    public @Rule MethodRule guice = new GuiceRule(ElanServiceTestModule.class, JobCoordinatorTestModule.class,
+            CacheModule.class);
     // TODO re-enable after we can await completion of listeners and DJC:
     // Otherwise this too frequently causes spurious test failures, e.g. due to error
     // logs Caused by: java.lang.RuntimeException: java.util.concurrent.ExecutionException: Operation was interrupted