Creating vlan bindings upfront 73/84273/3
authormanojna v <manojna.vijayakrishna@ericsson.com>
Mon, 9 Sep 2019 07:04:13 +0000 (12:34 +0530)
committermanojna v <manojna.vijayakrishna@ericsson.com>
Wed, 18 Sep 2019 09:07:59 +0000 (14:37 +0530)
Instead of waiting for the logical switch to be populated
in the oper ds first, we push the vlan bindings along
with the logical switches.

Change-Id: I8d2bb8c479f08c2ad412202db012d14dc80c17a6
Signed-off-by: manojna v <manojna.vijayakrishna@ericsson.com>
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/jobs/AssociateHwvtepToElanJob.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/jobs/LogicalSwitchAddedJob.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/HwvtepLogicalSwitchListener.java [deleted file]
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/L2GatewayConnectionUtils.java

index b6f8e52a4b73043d38dfb82d8ce80d214c963aa6..8529a5016070839dcfcf6505584b8a6e1f59978d 100644 (file)
@@ -11,7 +11,6 @@ import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
-import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.Callable;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -21,6 +20,7 @@ import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
+import org.opendaylight.netvirt.elan.l2gw.utils.ElanRefUtil;
 import org.opendaylight.netvirt.elan.utils.ElanUtils;
 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
 import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils;
@@ -45,12 +45,12 @@ public class AssociateHwvtepToElanJob implements Callable<List<ListenableFuture<
     private final ElanInstance elanInstance;
     private final Devices l2Device;
     private final Integer defaultVlan;
-    private final boolean createLogicalSwitch;
+    private final ElanRefUtil elanRefUtil;
 
     public AssociateHwvtepToElanJob(DataBroker broker, ElanL2GatewayUtils elanL2GatewayUtils,
             ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils, ElanInstanceCache elanInstanceCache,
             L2GatewayDevice l2GatewayDevice, ElanInstance elanInstance, Devices l2Device, Integer defaultVlan,
-            boolean createLogicalSwitch) {
+            ElanRefUtil elanRefUtil) {
         this.broker = broker;
         this.elanL2GatewayUtils = elanL2GatewayUtils;
         this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
@@ -59,7 +59,7 @@ public class AssociateHwvtepToElanJob implements Callable<List<ListenableFuture<
         this.elanInstance = elanInstance;
         this.l2Device = l2Device;
         this.defaultVlan = defaultVlan;
-        this.createLogicalSwitch = createLogicalSwitch;
+        this.elanRefUtil = elanRefUtil;
         LOG.debug("created assosiate l2gw connection job for {} {} ", elanInstance.getElanInstanceName(),
                 l2GatewayDevice.getHwvtepNodeId());
     }
@@ -78,21 +78,15 @@ public class AssociateHwvtepToElanJob implements Callable<List<ListenableFuture<
                 ElanL2GatewayUtils.getLogicalSwitchFromElan(elanInstanceName));
 
         // Create Logical Switch if it's not created already in the device
-        if (createLogicalSwitch) {
-            LOG.info("creating logical switch {} for {} ", elanInstanceName, hwvtepNodeId);
-
-            return Collections.singletonList(createLogicalSwitch());
-        } else {
-            createLogicalSwitch();
-            String logicalSwitchName = ElanL2GatewayUtils.getLogicalSwitchFromElan(elanInstanceName);
-            LOG.info("{} is already created in {}; adding remaining configurations", logicalSwitchName, hwvtepNodeId);
-
-            LogicalSwitchAddedJob logicalSwitchAddedJob =
-                    new LogicalSwitchAddedJob(elanL2GatewayUtils, elanL2GatewayMulticastUtils,
-                        logicalSwitchName, l2Device, l2GatewayDevice, defaultVlan
-                    );
-            return logicalSwitchAddedJob.call();
-        }
+        LOG.info("creating logical switch {} for {} ", elanInstanceName, hwvtepNodeId);
+        createLogicalSwitch();
+        String logicalSwitchName = ElanL2GatewayUtils.getLogicalSwitchFromElan(elanInstanceName);
+        LOG.info("{} is already created in {}; adding remaining configurations", logicalSwitchName, hwvtepNodeId);
+
+        LogicalSwitchAddedJob logicalSwitchAddedJob =
+                new LogicalSwitchAddedJob(elanL2GatewayUtils, elanL2GatewayMulticastUtils,
+                        logicalSwitchName, l2Device, l2GatewayDevice, defaultVlan, elanRefUtil, broker);
+        return logicalSwitchAddedJob.call();
     }
 
     private ListenableFuture<Void> createLogicalSwitch() {
index 75b65bf0da292cbb70e082e652364c2bbe696e99..cba6adab15ecc581670e8754bd0e30c02b85636c 100644 (file)
@@ -11,9 +11,12 @@ import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.Callable;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
+import org.opendaylight.netvirt.elan.l2gw.utils.ElanRefUtil;
 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
@@ -40,16 +43,21 @@ public class LogicalSwitchAddedJob implements Callable<List<ListenableFuture<Voi
 
     private final ElanL2GatewayUtils elanL2GatewayUtils;
     private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
+    private final ElanRefUtil elanRefUtil;
+    private final DataBroker dataBroker;
 
     public LogicalSwitchAddedJob(ElanL2GatewayUtils elanL2GatewayUtils,
                                  ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils, String logicalSwitchName,
-                                 Devices physicalDevice, L2GatewayDevice l2GatewayDevice, Integer defaultVlanId) {
+                                 Devices physicalDevice, L2GatewayDevice l2GatewayDevice, Integer defaultVlanId,
+                                 ElanRefUtil elanRefUtil, DataBroker dataBroker) {
         this.elanL2GatewayUtils = elanL2GatewayUtils;
         this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
         this.logicalSwitchName = logicalSwitchName;
         this.physicalDevice = physicalDevice;
         this.elanL2GwDevice = l2GatewayDevice;
         this.defaultVlanId = defaultVlanId;
+        this.elanRefUtil = elanRefUtil;
+        this.dataBroker = dataBroker;
         LOG.debug("created logical switch added job for {} {}", logicalSwitchName, elanL2GwDevice.getHwvtepNodeId());
     }
 
diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/HwvtepLogicalSwitchListener.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/HwvtepLogicalSwitchListener.java
deleted file mode 100644 (file)
index 62e8796..0000000
+++ /dev/null
@@ -1,164 +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.l2gw.listeners;
-
-import org.opendaylight.genius.datastoreutils.hwvtep.HwvtepClusteredDataTreeChangeListener;
-import org.opendaylight.genius.utils.hwvtep.HwvtepNodeHACache;
-import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
-import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
-import org.opendaylight.netvirt.elan.l2gw.jobs.LogicalSwitchAddedJob;
-import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
-import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
-import org.opendaylight.netvirt.elan.l2gw.utils.L2GatewayConnectionUtils;
-import org.opendaylight.netvirt.elan.utils.ElanClusterUtils;
-import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * The listener class for listening to {@code LogicalSwitches}
- * add/delete/update.
- *
- * @see LogicalSwitches
- */
-public class HwvtepLogicalSwitchListener extends
-        HwvtepClusteredDataTreeChangeListener<LogicalSwitches, HwvtepLogicalSwitchListener> {
-
-    /** The Constant LOG. */
-    private static final Logger LOG = LoggerFactory.getLogger(HwvtepLogicalSwitchListener.class);
-
-    /** The node id. */
-    private final NodeId nodeId;
-
-    /** The logical switch name. */
-    private final String logicalSwitchName;
-
-    /** The physical device. */
-    private final Devices physicalDevice;
-
-    /** The l2 gateway device. */
-    private final L2GatewayDevice l2GatewayDevice;
-
-    // The default vlan id
-    private final Integer defaultVlanId;
-
-    // Id of L2 Gateway connection responsible for this logical switch creation
-    private final Uuid l2GwConnId;
-
-    private final ElanInstanceCache elanInstanceCache;
-    private final ElanL2GatewayUtils elanL2GatewayUtils;
-    private final ElanClusterUtils elanClusterUtils;
-    private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
-    private final L2GatewayConnectionUtils l2GatewayConnectionUtils;
-
-    /**
-     * Instantiates a new hardware vtep logical switch listener.
-     */
-    public HwvtepLogicalSwitchListener(ElanInstanceCache elanInstanceCache, ElanL2GatewayUtils elanL2GatewayUtils,
-            ElanClusterUtils elanClusterUtils, ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils,
-            L2GatewayConnectionUtils l2GatewayConnectionUtils, L2GatewayDevice l2GatewayDevice,
-            String logicalSwitchName, Devices physicalDevice, Integer defaultVlanId, Uuid l2GwConnId,
-            HwvtepNodeHACache hwvtepNodeHACache) {
-        super(LogicalSwitches.class, HwvtepLogicalSwitchListener.class, hwvtepNodeHACache);
-        this.elanInstanceCache = elanInstanceCache;
-        this.elanL2GatewayUtils = elanL2GatewayUtils;
-        this.elanClusterUtils = elanClusterUtils;
-        this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
-        this.l2GatewayConnectionUtils = l2GatewayConnectionUtils;
-        this.nodeId = new NodeId(l2GatewayDevice.getHwvtepNodeId());
-        this.logicalSwitchName = logicalSwitchName;
-        this.physicalDevice = physicalDevice;
-        this.l2GatewayDevice = l2GatewayDevice;
-        this.defaultVlanId = defaultVlanId;
-        this.l2GwConnId = l2GwConnId;
-    }
-
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.opendaylight.genius.datastoreutils.AsyncClusteredDataChangeListenerBase#
-     * getWildCardPath()
-     */
-    @Override
-    public InstanceIdentifier<LogicalSwitches> getWildCardPath() {
-        return HwvtepSouthboundUtils.createLogicalSwitchesInstanceIdentifier(nodeId,
-                new HwvtepNodeName(logicalSwitchName));
-    }
-
-    @Override
-    protected HwvtepLogicalSwitchListener getDataTreeChangeListener() {
-        return this;
-    }
-
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.opendaylight.genius.datastoreutils.AsyncClusteredDataChangeListenerBase#
-     * remove(org.opendaylight.yangtools.yang.binding.InstanceIdentifier,
-     * org.opendaylight.yangtools.yang.binding.DataObject)
-     */
-    @Override
-    protected void removed(InstanceIdentifier<LogicalSwitches> identifier, LogicalSwitches deletedLogicalSwitch) {
-        LOG.trace("Received Remove DataChange Notification for identifier: {}, LogicalSwitches: {}", identifier,
-                deletedLogicalSwitch);
-    }
-
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.opendaylight.genius.datastoreutils.AsyncClusteredDataChangeListenerBase#
-     * update(org.opendaylight.yangtools.yang.binding.InstanceIdentifier,
-     * org.opendaylight.yangtools.yang.binding.DataObject,
-     * org.opendaylight.yangtools.yang.binding.DataObject)
-     */
-    @Override
-    protected void updated(InstanceIdentifier<LogicalSwitches> identifier, LogicalSwitches logicalSwitchOld,
-            LogicalSwitches logicalSwitchNew) {
-        LOG.trace("Received Update DataChange Notification for identifier: {}, LogicalSwitches old: {}, new: {}."
-                + "No Action Performed.", identifier, logicalSwitchOld, logicalSwitchNew);
-    }
-
-    @Override
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    protected void added(InstanceIdentifier<LogicalSwitches> identifier, LogicalSwitches logicalSwitchNew) {
-        LOG.debug("Received Add DataChange Notification for identifier: {}, LogicalSwitches: {}", identifier,
-                logicalSwitchNew);
-        try {
-            L2GatewayDevice elanDevice = l2GatewayConnectionUtils.addL2DeviceToElanL2GwCache(
-                    logicalSwitchNew.getHwvtepNodeName().getValue(), l2GatewayDevice, l2GwConnId, physicalDevice);
-
-            LogicalSwitchAddedJob logicalSwitchAddedWorker = new LogicalSwitchAddedJob(
-                    elanL2GatewayUtils, elanL2GatewayMulticastUtils, logicalSwitchName, physicalDevice, elanDevice,
-                    defaultVlanId);
-            elanClusterUtils.runOnlyInOwnerNode(logicalSwitchAddedWorker.getJobKey(),
-                    "create vlan mappings and mcast configurations", logicalSwitchAddedWorker);
-        } catch (RuntimeException e) {
-            LOG.error("Failed to handle HwVTEPLogicalSwitch - add for: {}", identifier, e);
-        } finally {
-            try {
-                // This listener is specific to handle a specific logical
-                // switch, hence closing it.
-                LOG.trace("Closing LogicalSwitches listener for node: {}, logicalSwitch: {}", nodeId.getValue(),
-                        logicalSwitchName);
-                // TODO use https://git.opendaylight.org/gerrit/#/c/44145/ when merged, and remove @SuppressWarnings
-                close();
-            } catch (Exception e) {
-                LOG.warn("Failed to close HwVTEPLogicalSwitchListener", e);
-            }
-        }
-    }
-}
index a96358f6b711ec3e2edb93f1181a8901984cba3c..a8ce5b713c6ffcf490b4650d6674355634d495e5 100644 (file)
@@ -31,13 +31,11 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
 import org.opendaylight.genius.utils.hwvtep.HwvtepNodeHACache;
 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.l2gw.ha.listeners.HAOpClusteredListener;
 import org.opendaylight.netvirt.elan.l2gw.jobs.AssociateHwvtepToElanJob;
 import org.opendaylight.netvirt.elan.l2gw.jobs.DisAssociateHwvtepFromElanJob;
-import org.opendaylight.netvirt.elan.l2gw.listeners.HwvtepLogicalSwitchListener;
 import org.opendaylight.netvirt.elan.l2gw.listeners.LocalUcastMacListener;
 import org.opendaylight.netvirt.elan.utils.ElanClusterUtils;
 import org.opendaylight.netvirt.elanmanager.utils.ElanL2GwCacheUtils;
@@ -75,13 +73,15 @@ public class L2GatewayConnectionUtils implements AutoCloseable {
     private final List<AutoCloseable> closeables = new CopyOnWriteArrayList<>();
     private final HwvtepNodeHACache hwvtepNodeHACache;
     private final HAOpClusteredListener haOpClusteredListener;
+    private final ElanRefUtil elanRefUtil;
 
     @Inject
-    public L2GatewayConnectionUtils(DataBroker dataBroker,
-            ElanClusterUtils elanClusterUtils, ElanL2GatewayUtils elanL2GatewayUtils,
-            JobCoordinator jobCoordinator, ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils,
-            L2GatewayCache l2GatewayCache, HAOpClusteredListener haOpClusteredListener,
-            ElanInstanceCache elanInstanceCache, HwvtepNodeHACache hwvtepNodeHACache) {
+    public L2GatewayConnectionUtils(DataBroker dataBroker, ElanClusterUtils elanClusterUtils,
+                                    ElanL2GatewayUtils elanL2GatewayUtils, JobCoordinator jobCoordinator,
+                                    ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils,
+                                    L2GatewayCache l2GatewayCache, HAOpClusteredListener haOpClusteredListener,
+                                    ElanInstanceCache elanInstanceCache, HwvtepNodeHACache hwvtepNodeHACache,
+                                    ElanRefUtil elanRefUtil) {
         this.broker = dataBroker;
         this.elanL2GatewayUtils = elanL2GatewayUtils;
         this.elanClusterUtils = elanClusterUtils;
@@ -91,6 +91,7 @@ public class L2GatewayConnectionUtils implements AutoCloseable {
         this.haOpClusteredListener = haOpClusteredListener;
         this.elanInstanceCache = elanInstanceCache;
         this.hwvtepNodeHACache = hwvtepNodeHACache;
+        this.elanRefUtil = elanRefUtil;
     }
 
     @Override
@@ -310,22 +311,11 @@ public class L2GatewayConnectionUtils implements AutoCloseable {
 
                 // Add L2 Gateway device to 'ElanL2GwDevice' cache
                 boolean createLogicalSwitch;
-                LogicalSwitches logicalSwitch = HwvtepUtils.getLogicalSwitch(broker, LogicalDatastoreType.CONFIGURATION,
-                        hwvtepNodeId, elanName);
-                if (logicalSwitch == null) {
-                    HwvtepLogicalSwitchListener hwVTEPLogicalSwitchListener = new HwvtepLogicalSwitchListener(
-                            elanInstanceCache, elanL2GatewayUtils, elanClusterUtils, elanL2GatewayMulticastUtils,
-                            this, l2GatewayDevice, elanName, l2Device, defaultVlan, l2GwConnId, hwvtepNodeHACache);
-                    hwVTEPLogicalSwitchListener.registerListener(LogicalDatastoreType.OPERATIONAL, broker);
-                    closeables.add(hwVTEPLogicalSwitchListener);
-                    createLogicalSwitch = true;
-                } else {
-                    addL2DeviceToElanL2GwCache(elanName, l2GatewayDevice, l2GwConnId, l2Device);
-                    createLogicalSwitch = false;
-                }
+                addL2DeviceToElanL2GwCache(elanName, l2GatewayDevice, l2GwConnId, l2Device);
+
                 AssociateHwvtepToElanJob associateHwvtepToElanJob = new AssociateHwvtepToElanJob(broker,
                         elanL2GatewayUtils, elanL2GatewayMulticastUtils, elanInstanceCache, l2GatewayDevice,
-                        elanInstance, l2Device, defaultVlan, createLogicalSwitch);
+                        elanInstance, l2Device, defaultVlan, elanRefUtil);
 
                 elanClusterUtils.runOnlyInOwnerNode(associateHwvtepToElanJob.getJobKey(),
                         "create logical switch in hwvtep topo", associateHwvtepToElanJob);