From 97c44dc7dc79a197abcdd3f358655e5675ea7728 Mon Sep 17 00:00:00 2001 From: manojna v Date: Mon, 9 Sep 2019 12:34:13 +0530 Subject: [PATCH] Creating vlan bindings upfront 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 --- .../l2gw/jobs/AssociateHwvtepToElanJob.java | 32 ++-- .../elan/l2gw/jobs/LogicalSwitchAddedJob.java | 10 +- .../HwvtepLogicalSwitchListener.java | 164 ------------------ .../l2gw/utils/L2GatewayConnectionUtils.java | 32 ++-- 4 files changed, 33 insertions(+), 205 deletions(-) delete mode 100644 elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/HwvtepLogicalSwitchListener.java diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/jobs/AssociateHwvtepToElanJob.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/jobs/AssociateHwvtepToElanJob.java index b6f8e52a4b..8529a50160 100644 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/jobs/AssociateHwvtepToElanJob.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/jobs/AssociateHwvtepToElanJob.java @@ -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 createLogicalSwitch() { diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/jobs/LogicalSwitchAddedJob.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/jobs/LogicalSwitchAddedJob.java index 75b65bf0da..cba6adab15 100644 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/jobs/LogicalSwitchAddedJob.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/jobs/LogicalSwitchAddedJob.java @@ -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 { - - /** 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 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 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 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 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); - } - } - } -} diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/L2GatewayConnectionUtils.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/L2GatewayConnectionUtils.java index a96358f6b7..a8ce5b713c 100644 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/L2GatewayConnectionUtils.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/L2GatewayConnectionUtils.java @@ -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 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); -- 2.36.6