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 entityOwnershipService the entity ownership service
72 * @param elanUtils the ELAN utilities
73 * @param elanL2GatewayMulticastUtils
74 * @param l2GatewayDevice the l2 gateway device
75 * @param logicalSwitchName the logical switch name
76 * @param physicalDevice the physical device
77 * @param defaultVlanId the default vlan id
80 public HwvtepLogicalSwitchListener(DataBroker dataBroker, ElanL2GatewayUtils elanL2GatewayUtils,
81 EntityOwnershipService entityOwnershipService, ElanUtils elanUtils,
82 ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils,
83 L2GatewayDevice l2GatewayDevice,
84 String logicalSwitchName,
85 Devices physicalDevice, Integer defaultVlanId, Uuid l2GwConnId) {
86 super(LogicalSwitches.class, HwvtepLogicalSwitchListener.class);
87 this.broker = dataBroker;
88 this.elanL2GatewayUtils = elanL2GatewayUtils;
89 this.entityOwnershipService = entityOwnershipService;
90 this.elanUtils = elanUtils;
91 this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
92 this.nodeId = new NodeId(l2GatewayDevice.getHwvtepNodeId());
93 this.logicalSwitchName = logicalSwitchName;
94 this.physicalDevice = physicalDevice;
95 this.l2GatewayDevice = l2GatewayDevice;
96 this.defaultVlanId = defaultVlanId;
97 this.l2GwConnId = l2GwConnId;
104 * org.opendaylight.genius.datastoreutils.AsyncClusteredDataChangeListenerBase#
108 public InstanceIdentifier<LogicalSwitches> getWildCardPath() {
109 return HwvtepSouthboundUtils.createLogicalSwitchesInstanceIdentifier(nodeId,
110 new HwvtepNodeName(logicalSwitchName));
117 * org.opendaylight.genius.datastoreutils.AsyncClusteredDataChangeListenerBase#
118 * getDataChangeListener()
121 protected ClusteredDataChangeListener getDataChangeListener() {
122 return HwvtepLogicalSwitchListener.this;
129 * org.opendaylight.genius.datastoreutils.AsyncClusteredDataChangeListenerBase#
130 * getDataChangeScope()
133 protected AsyncDataBroker.DataChangeScope getDataChangeScope() {
134 return AsyncDataBroker.DataChangeScope.BASE;
141 * org.opendaylight.genius.datastoreutils.AsyncClusteredDataChangeListenerBase#
142 * remove(org.opendaylight.yangtools.yang.binding.InstanceIdentifier,
143 * org.opendaylight.yangtools.yang.binding.DataObject)
146 protected void remove(InstanceIdentifier<LogicalSwitches> identifier, LogicalSwitches deletedLogicalSwitch) {
147 LOG.trace("Received Remove DataChange Notification for identifier: {}, LogicalSwitches: {}", identifier,
148 deletedLogicalSwitch);
155 * org.opendaylight.genius.datastoreutils.AsyncClusteredDataChangeListenerBase#
156 * update(org.opendaylight.yangtools.yang.binding.InstanceIdentifier,
157 * org.opendaylight.yangtools.yang.binding.DataObject,
158 * org.opendaylight.yangtools.yang.binding.DataObject)
161 protected void update(InstanceIdentifier<LogicalSwitches> identifier, LogicalSwitches logicalSwitchOld,
162 LogicalSwitches logicalSwitchNew) {
163 LOG.trace("Received Update DataChange Notification for identifier: {}, LogicalSwitches old: {}, new: {}."
164 + "No Action Performed.", identifier, logicalSwitchOld, logicalSwitchNew);
171 * org.opendaylight.genius.datastoreutils.AsyncClusteredDataChangeListenerBase#
172 * add(org.opendaylight.yangtools.yang.binding.InstanceIdentifier,
173 * org.opendaylight.yangtools.yang.binding.DataObject)
176 protected void add(InstanceIdentifier<LogicalSwitches> identifier, LogicalSwitches logicalSwitchNew) {
177 LOG.debug("Received Add DataChange Notification for identifier: {}, LogicalSwitches: {}", identifier,
180 L2GatewayDevice elanDevice = L2GatewayConnectionUtils.addL2DeviceToElanL2GwCache(
181 logicalSwitchNew.getHwvtepNodeName().getValue(), l2GatewayDevice, l2GwConnId);
183 LogicalSwitchAddedJob logicalSwitchAddedWorker = new LogicalSwitchAddedJob(broker, elanL2GatewayUtils,
184 elanUtils, elanL2GatewayMulticastUtils, logicalSwitchName, physicalDevice, elanDevice, defaultVlanId);
185 ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, logicalSwitchAddedWorker.getJobKey() ,
186 "create vlan mappings and mcast configurations",
187 logicalSwitchAddedWorker);
188 } catch (Exception e) {
189 LOG.error("Failed to handle HwVTEPLogicalSwitch - add: {}", e);
192 // This listener is specific to handle a specific logical
193 // switch, hence closing it.
194 LOG.trace("Closing LogicalSwitches listener for node: {}, logicalSwitch: {}", nodeId.getValue(),
197 } catch (Exception e) {
198 LOG.warn("Failed to close HwVTEPLogicalSwitchListener: {}", e);