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;
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;
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;
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());
}
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() {
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;
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());
}
+++ /dev/null
-/*
- * 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);
- }
- }
- }
-}
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;
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;
this.haOpClusteredListener = haOpClusteredListener;
this.elanInstanceCache = elanInstanceCache;
this.hwvtepNodeHACache = hwvtepNodeHACache;
+ this.elanRefUtil = elanRefUtil;
}
@Override
// 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);