2 * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netvirt.elan.l2gw.listeners;
10 import org.opendaylight.genius.datastoreutils.hwvtep.HwvtepClusteredDataTreeChangeListener;
11 import org.opendaylight.genius.utils.hwvtep.HwvtepNodeHACache;
12 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
13 import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
14 import org.opendaylight.netvirt.elan.l2gw.jobs.LogicalSwitchAddedJob;
15 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
16 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
17 import org.opendaylight.netvirt.elan.l2gw.utils.L2GatewayConnectionUtils;
18 import org.opendaylight.netvirt.elan.utils.ElanClusterUtils;
19 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
30 * The listener class for listening to {@code LogicalSwitches}
33 * @see LogicalSwitches
35 public class HwvtepLogicalSwitchListener extends
36 HwvtepClusteredDataTreeChangeListener<LogicalSwitches, HwvtepLogicalSwitchListener> {
38 /** The Constant LOG. */
39 private static final Logger LOG = LoggerFactory.getLogger(HwvtepLogicalSwitchListener.class);
42 private final NodeId nodeId;
44 /** The logical switch name. */
45 private final String logicalSwitchName;
47 /** The physical device. */
48 private final Devices physicalDevice;
50 /** The l2 gateway device. */
51 private final L2GatewayDevice l2GatewayDevice;
53 // The default vlan id
54 private final Integer defaultVlanId;
56 // Id of L2 Gateway connection responsible for this logical switch creation
57 private final Uuid l2GwConnId;
59 private final ElanInstanceCache elanInstanceCache;
60 private final ElanL2GatewayUtils elanL2GatewayUtils;
61 private final ElanClusterUtils elanClusterUtils;
62 private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
63 private final L2GatewayConnectionUtils l2GatewayConnectionUtils;
66 * Instantiates a new hardware vtep logical switch listener.
68 public HwvtepLogicalSwitchListener(ElanInstanceCache elanInstanceCache, ElanL2GatewayUtils elanL2GatewayUtils,
69 ElanClusterUtils elanClusterUtils, ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils,
70 L2GatewayConnectionUtils l2GatewayConnectionUtils, L2GatewayDevice l2GatewayDevice,
71 String logicalSwitchName, Devices physicalDevice, Integer defaultVlanId, Uuid l2GwConnId,
72 HwvtepNodeHACache hwvtepNodeHACache) {
73 super(LogicalSwitches.class, HwvtepLogicalSwitchListener.class, hwvtepNodeHACache);
74 this.elanInstanceCache = elanInstanceCache;
75 this.elanL2GatewayUtils = elanL2GatewayUtils;
76 this.elanClusterUtils = elanClusterUtils;
77 this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
78 this.l2GatewayConnectionUtils = l2GatewayConnectionUtils;
79 this.nodeId = new NodeId(l2GatewayDevice.getHwvtepNodeId());
80 this.logicalSwitchName = logicalSwitchName;
81 this.physicalDevice = physicalDevice;
82 this.l2GatewayDevice = l2GatewayDevice;
83 this.defaultVlanId = defaultVlanId;
84 this.l2GwConnId = l2GwConnId;
91 * org.opendaylight.genius.datastoreutils.AsyncClusteredDataChangeListenerBase#
95 public InstanceIdentifier<LogicalSwitches> getWildCardPath() {
96 return HwvtepSouthboundUtils.createLogicalSwitchesInstanceIdentifier(nodeId,
97 new HwvtepNodeName(logicalSwitchName));
101 protected HwvtepLogicalSwitchListener getDataTreeChangeListener() {
109 * org.opendaylight.genius.datastoreutils.AsyncClusteredDataChangeListenerBase#
110 * remove(org.opendaylight.yangtools.yang.binding.InstanceIdentifier,
111 * org.opendaylight.yangtools.yang.binding.DataObject)
114 protected void removed(InstanceIdentifier<LogicalSwitches> identifier, LogicalSwitches deletedLogicalSwitch) {
115 LOG.trace("Received Remove DataChange Notification for identifier: {}, LogicalSwitches: {}", identifier,
116 deletedLogicalSwitch);
123 * org.opendaylight.genius.datastoreutils.AsyncClusteredDataChangeListenerBase#
124 * update(org.opendaylight.yangtools.yang.binding.InstanceIdentifier,
125 * org.opendaylight.yangtools.yang.binding.DataObject,
126 * org.opendaylight.yangtools.yang.binding.DataObject)
129 protected void updated(InstanceIdentifier<LogicalSwitches> identifier, LogicalSwitches logicalSwitchOld,
130 LogicalSwitches logicalSwitchNew) {
131 LOG.trace("Received Update DataChange Notification for identifier: {}, LogicalSwitches old: {}, new: {}."
132 + "No Action Performed.", identifier, logicalSwitchOld, logicalSwitchNew);
136 @SuppressWarnings("checkstyle:IllegalCatch")
137 protected void added(InstanceIdentifier<LogicalSwitches> identifier, LogicalSwitches logicalSwitchNew) {
138 LOG.debug("Received Add DataChange Notification for identifier: {}, LogicalSwitches: {}", identifier,
141 L2GatewayDevice elanDevice = l2GatewayConnectionUtils.addL2DeviceToElanL2GwCache(
142 logicalSwitchNew.getHwvtepNodeName().getValue(), l2GatewayDevice, l2GwConnId, physicalDevice);
144 LogicalSwitchAddedJob logicalSwitchAddedWorker = new LogicalSwitchAddedJob(
145 elanL2GatewayUtils, elanL2GatewayMulticastUtils, logicalSwitchName, physicalDevice, elanDevice,
147 elanClusterUtils.runOnlyInOwnerNode(logicalSwitchAddedWorker.getJobKey(),
148 "create vlan mappings and mcast configurations", logicalSwitchAddedWorker);
149 } catch (RuntimeException e) {
150 LOG.error("Failed to handle HwVTEPLogicalSwitch - add for: {}", identifier, e);
153 // This listener is specific to handle a specific logical
154 // switch, hence closing it.
155 LOG.trace("Closing LogicalSwitches listener for node: {}, logicalSwitch: {}", nodeId.getValue(),
157 // TODO use https://git.opendaylight.org/gerrit/#/c/44145/ when merged, and remove @SuppressWarnings
159 } catch (Exception e) {
160 LOG.warn("Failed to close HwVTEPLogicalSwitchListener", e);