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.controller.md.sal.binding.api.ClusteredDataChangeListener;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
13 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
14 import org.opendaylight.genius.datastoreutils.AsyncClusteredDataChangeListenerBase;
15 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
16 import org.opendaylight.netvirt.elan.l2gw.jobs.LogicalSwitchAddedJob;
17 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
18 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
19 import org.opendaylight.netvirt.elan.l2gw.utils.L2GatewayConnectionUtils;
20 import org.opendaylight.netvirt.elan.utils.ElanClusterUtils;
21 import org.opendaylight.netvirt.elan.utils.ElanUtils;
22 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * The listener class for listening to {@code LogicalSwitches}
36 * @see LogicalSwitches
38 public class HwvtepLogicalSwitchListener extends
39 AsyncClusteredDataChangeListenerBase<LogicalSwitches, HwvtepLogicalSwitchListener> {
41 /** The Constant LOG. */
42 private static final Logger LOG = LoggerFactory.getLogger(HwvtepLogicalSwitchListener.class);
45 private NodeId nodeId;
47 /** The logical switch name. */
48 private String logicalSwitchName;
50 /** The physical device. */
51 private Devices physicalDevice;
53 /** The l2 gateway device. */
54 private L2GatewayDevice l2GatewayDevice;
56 // The default vlan id
57 private Integer defaultVlanId;
59 // Id of L2 Gateway connection responsible for this logical switch creation
60 private Uuid l2GwConnId;
62 private final DataBroker broker;
63 private final ElanL2GatewayUtils elanL2GatewayUtils;
64 private final EntityOwnershipService entityOwnershipService;
65 private final ElanUtils elanUtils;
66 private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
69 * Instantiates a new hardware vtep logical switch listener.
71 * @param dataBroker DataBroker
72 * @param elanL2GatewayUtils l2 gateway utils
73 * @param entityOwnershipService the entity ownership service
74 * @param elanUtils the ELAN utilities
75 * @param elanL2GatewayMulticastUtils l2 gateway multicast utils
76 * @param l2GatewayDevice the l2 gateway device
77 * @param logicalSwitchName the logical switch name
78 * @param physicalDevice the physical device
79 * @param defaultVlanId the default vlan id
80 * @param l2GwConnId l2 gateway connection id
82 public HwvtepLogicalSwitchListener(DataBroker dataBroker, ElanL2GatewayUtils elanL2GatewayUtils,
83 EntityOwnershipService entityOwnershipService, ElanUtils elanUtils,
84 ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils,
85 L2GatewayDevice l2GatewayDevice,
86 String logicalSwitchName,
87 Devices physicalDevice, Integer defaultVlanId, Uuid l2GwConnId) {
88 super(LogicalSwitches.class, HwvtepLogicalSwitchListener.class);
89 this.broker = dataBroker;
90 this.elanL2GatewayUtils = elanL2GatewayUtils;
91 this.entityOwnershipService = entityOwnershipService;
92 this.elanUtils = elanUtils;
93 this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
94 this.nodeId = new NodeId(l2GatewayDevice.getHwvtepNodeId());
95 this.logicalSwitchName = logicalSwitchName;
96 this.physicalDevice = physicalDevice;
97 this.l2GatewayDevice = l2GatewayDevice;
98 this.defaultVlanId = defaultVlanId;
99 this.l2GwConnId = l2GwConnId;
106 * org.opendaylight.genius.datastoreutils.AsyncClusteredDataChangeListenerBase#
110 public InstanceIdentifier<LogicalSwitches> getWildCardPath() {
111 return HwvtepSouthboundUtils.createLogicalSwitchesInstanceIdentifier(nodeId,
112 new HwvtepNodeName(logicalSwitchName));
119 * org.opendaylight.genius.datastoreutils.AsyncClusteredDataChangeListenerBase#
120 * getDataChangeListener()
123 protected ClusteredDataChangeListener getDataChangeListener() {
124 return HwvtepLogicalSwitchListener.this;
131 * org.opendaylight.genius.datastoreutils.AsyncClusteredDataChangeListenerBase#
132 * getDataChangeScope()
135 protected AsyncDataBroker.DataChangeScope getDataChangeScope() {
136 return AsyncDataBroker.DataChangeScope.BASE;
143 * org.opendaylight.genius.datastoreutils.AsyncClusteredDataChangeListenerBase#
144 * remove(org.opendaylight.yangtools.yang.binding.InstanceIdentifier,
145 * org.opendaylight.yangtools.yang.binding.DataObject)
148 protected void remove(InstanceIdentifier<LogicalSwitches> identifier, LogicalSwitches deletedLogicalSwitch) {
149 LOG.trace("Received Remove DataChange Notification for identifier: {}, LogicalSwitches: {}", identifier,
150 deletedLogicalSwitch);
157 * org.opendaylight.genius.datastoreutils.AsyncClusteredDataChangeListenerBase#
158 * update(org.opendaylight.yangtools.yang.binding.InstanceIdentifier,
159 * org.opendaylight.yangtools.yang.binding.DataObject,
160 * org.opendaylight.yangtools.yang.binding.DataObject)
163 protected void update(InstanceIdentifier<LogicalSwitches> identifier, LogicalSwitches logicalSwitchOld,
164 LogicalSwitches logicalSwitchNew) {
165 LOG.trace("Received Update DataChange Notification for identifier: {}, LogicalSwitches old: {}, new: {}."
166 + "No Action Performed.", identifier, logicalSwitchOld, logicalSwitchNew);
173 * org.opendaylight.genius.datastoreutils.AsyncClusteredDataChangeListenerBase#
174 * add(org.opendaylight.yangtools.yang.binding.InstanceIdentifier,
175 * org.opendaylight.yangtools.yang.binding.DataObject)
178 protected void add(InstanceIdentifier<LogicalSwitches> identifier, LogicalSwitches logicalSwitchNew) {
179 LOG.debug("Received Add DataChange Notification for identifier: {}, LogicalSwitches: {}", identifier,
182 L2GatewayDevice elanDevice = L2GatewayConnectionUtils.addL2DeviceToElanL2GwCache(
183 logicalSwitchNew.getHwvtepNodeName().getValue(), l2GatewayDevice, l2GwConnId);
185 LogicalSwitchAddedJob logicalSwitchAddedWorker = new LogicalSwitchAddedJob(broker, elanL2GatewayUtils,
186 elanUtils, elanL2GatewayMulticastUtils, logicalSwitchName, physicalDevice, elanDevice,
188 ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, logicalSwitchAddedWorker.getJobKey() ,
189 "create vlan mappings and mcast configurations",
190 logicalSwitchAddedWorker);
191 } catch (Exception e) {
192 LOG.error("Failed to handle HwVTEPLogicalSwitch - add: {}", e);
195 // This listener is specific to handle a specific logical
196 // switch, hence closing it.
197 LOG.trace("Closing LogicalSwitches listener for node: {}, logicalSwitch: {}", nodeId.getValue(),
200 } catch (Exception e) {
201 LOG.warn("Failed to close HwVTEPLogicalSwitchListener: {}", e);