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.vpnservice.elan.l2gw.listeners;
10 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
11 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
12 import org.opendaylight.vpnservice.datastoreutils.AsyncDataChangeListenerBase;
13 import org.opendaylight.vpnservice.datastoreutils.DataStoreJobCoordinator;
14 import org.opendaylight.vpnservice.elan.l2gw.jobs.LogicalSwitchAddedJob;
15 import org.opendaylight.vpnservice.elan.l2gw.utils.L2GatewayConnectionUtils;
16 import org.opendaylight.vpnservice.neutronvpn.api.l2gw.L2GatewayDevice;
17 import org.opendaylight.vpnservice.utils.SystemPropertyReader;
18 import org.opendaylight.vpnservice.utils.hwvtep.HwvtepSouthboundUtils;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * The listener class for listening to {@code LogicalSwitches}
32 * @see LogicalSwitches
34 public class HwvtepLogicalSwitchListener
35 extends AsyncDataChangeListenerBase<LogicalSwitches, HwvtepLogicalSwitchListener> {
37 /** The Constant LOG. */
38 private static final Logger LOG = LoggerFactory.getLogger(HwvtepLogicalSwitchListener.class);
41 private NodeId nodeId;
43 /** The logical switch name. */
44 private String logicalSwitchName;
46 /** The physical device. */
47 private Devices physicalDevice;
49 /** The l2 gateway device. */
50 private L2GatewayDevice l2GatewayDevice;
52 /** The default vlan id. */
53 private Integer defaultVlanId;
55 /** Id of L2 Gateway connection responsible for this logical switch creation */
56 private Uuid l2GwConnId;
58 static DataStoreJobCoordinator dataStoreJobCoordinator;
60 public static void setDataStoreJobCoordinator(DataStoreJobCoordinator ds) {
61 dataStoreJobCoordinator = ds;
65 * Instantiates a new hardware vtep logical switch listener.
67 * @param l2GatewayDevice
68 * the l2 gateway device
69 * @param logicalSwitchName
70 * the logical switch name
71 * @param physicalDevice
73 * @param defaultVlanId
76 * the l2 gateway connection id
78 public HwvtepLogicalSwitchListener(L2GatewayDevice l2GatewayDevice, String logicalSwitchName,
79 Devices physicalDevice, Integer defaultVlanId, Uuid l2GwConnId) {
80 super(LogicalSwitches.class, HwvtepLogicalSwitchListener.class);
81 this.nodeId = new NodeId(l2GatewayDevice.getHwvtepNodeId());
82 this.logicalSwitchName = logicalSwitchName;
83 this.physicalDevice = physicalDevice;
84 this.l2GatewayDevice = l2GatewayDevice;
85 this.defaultVlanId = defaultVlanId;
86 this.l2GwConnId = l2GwConnId;
93 * org.opendaylight.vpnservice.datastoreutils.AsyncDataChangeListenerBase#
97 public InstanceIdentifier<LogicalSwitches> getWildCardPath() {
98 return HwvtepSouthboundUtils.createLogicalSwitchesInstanceIdentifier(nodeId,
99 new HwvtepNodeName(logicalSwitchName));
106 * org.opendaylight.vpnservice.datastoreutils.AsyncDataChangeListenerBase#
107 * getDataChangeListener()
110 protected DataChangeListener getDataChangeListener() {
111 return HwvtepLogicalSwitchListener.this;
118 * org.opendaylight.vpnservice.datastoreutils.AsyncDataChangeListenerBase#
119 * getDataChangeScope()
122 protected AsyncDataBroker.DataChangeScope getDataChangeScope() {
123 return AsyncDataBroker.DataChangeScope.BASE;
130 * org.opendaylight.vpnservice.datastoreutils.AsyncDataChangeListenerBase#
131 * remove(org.opendaylight.yangtools.yang.binding.InstanceIdentifier,
132 * org.opendaylight.yangtools.yang.binding.DataObject)
135 protected void remove(InstanceIdentifier<LogicalSwitches> identifier, LogicalSwitches deletedLogicalSwitch) {
136 LOG.trace("Received Remove DataChange Notification for identifier: {}, LogicalSwitches: {}", identifier,
137 deletedLogicalSwitch);
144 * org.opendaylight.vpnservice.datastoreutils.AsyncDataChangeListenerBase#
145 * update(org.opendaylight.yangtools.yang.binding.InstanceIdentifier,
146 * org.opendaylight.yangtools.yang.binding.DataObject,
147 * org.opendaylight.yangtools.yang.binding.DataObject)
150 protected void update(InstanceIdentifier<LogicalSwitches> identifier, LogicalSwitches logicalSwitchOld,
151 LogicalSwitches logicalSwitchNew) {
152 LOG.trace("Received Update DataChange Notification for identifier: {}, LogicalSwitches old: {}, new: {}."
153 + "No Action Performed.", identifier, logicalSwitchOld, logicalSwitchNew);
160 * org.opendaylight.vpnservice.datastoreutils.AsyncDataChangeListenerBase#
161 * add(org.opendaylight.yangtools.yang.binding.InstanceIdentifier,
162 * org.opendaylight.yangtools.yang.binding.DataObject)
165 protected void add(InstanceIdentifier<LogicalSwitches> identifier, LogicalSwitches logicalSwitchNew) {
166 LOG.debug("Received Add DataChange Notification for identifier: {}, LogicalSwitches: {}", identifier,
169 L2GatewayDevice elanDevice = L2GatewayConnectionUtils.addL2DeviceToElanL2GwCache(
170 logicalSwitchNew.getHwvtepNodeName().getValue(), l2GatewayDevice, l2GwConnId);
172 LogicalSwitchAddedJob logicalSwitchAddedWorker = new LogicalSwitchAddedJob(
173 logicalSwitchName, physicalDevice, elanDevice, defaultVlanId);
174 dataStoreJobCoordinator.enqueueJob(logicalSwitchAddedWorker.getJobKey(), logicalSwitchAddedWorker,
175 SystemPropertyReader.getDataStoreJobCoordinatorMaxRetries());
177 } catch (Exception e) {
178 LOG.error("Failed to handle HwVTEPLogicalSwitch - add: {}", e);
181 // This listener is specific to handle a specific logical
182 // switch, hence closing it.
183 LOG.trace("Closing LogicalSwitches listener for node: {}, logicalSwitch: {}", nodeId.getValue(),
186 } catch (Exception e) {
187 LOG.warn("Failed to close HwVTEPLogicalSwitchListener: {}", e);