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 com.google.common.collect.Lists;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
13 import org.opendaylight.genius.datastoreutils.hwvtep.HwvtepClusteredDataTreeChangeListener;
14 import org.opendaylight.genius.utils.hwvtep.HwvtepUtils;
15 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
16 import org.opendaylight.netvirt.elan.utils.ElanUtils;
17 import org.opendaylight.netvirt.elanmanager.utils.ElanL2GwCacheUtils;
18 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacs;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * A listener for Ucast MAC entries that are added/removed to/from an External
30 * <p>When a Ucast MAC addr appears in the hwvtep's operational DS, that MAC must
31 * be populated in DMAC tables in all Elan participating DPNs. ELAN is selected
32 * according to field 'tunnel_key' of the Logical Switch to which the new MAC
35 public class HwvtepLocalUcastMacListener extends
36 HwvtepClusteredDataTreeChangeListener<LocalUcastMacs, HwvtepLocalUcastMacListener> implements AutoCloseable {
38 private static final Logger LOG = LoggerFactory.getLogger(HwvtepLocalUcastMacListener.class);
40 private final DataBroker broker;
41 private final ElanL2GatewayUtils elanL2GatewayUtils;
43 public HwvtepLocalUcastMacListener(DataBroker broker, ElanUtils elanUtils) {
44 super(LocalUcastMacs.class, HwvtepLocalUcastMacListener.class);
47 this.elanL2GatewayUtils = elanUtils.getElanL2GatewayUtils();
51 registerListener(LogicalDatastoreType.OPERATIONAL, broker);
55 protected void removed(InstanceIdentifier<LocalUcastMacs> identifier, LocalUcastMacs macRemoved) {
56 String hwvtepNodeId = identifier.firstKeyOf(Node.class).getNodeId().getValue();
57 String macAddress = macRemoved.getMacEntryKey().getValue();
59 LOG.trace("LocalUcastMacs {} removed from {}", macAddress, hwvtepNodeId);
61 ElanInstance elan = elanL2GatewayUtils.getElanInstanceForUcastLocalMac(macRemoved);
63 LOG.warn("Could not find ELAN for mac {} being deleted", macAddress);
67 String elanName = elan.getElanInstanceName();
68 L2GatewayDevice elanL2GwDevice = ElanL2GwCacheUtils.getL2GatewayDeviceFromCache(elanName, hwvtepNodeId);
69 if (elanL2GwDevice == null) {
70 LOG.warn("Could not find L2GatewayDevice for ELAN: {}, nodeID:{} from cache", elanName, hwvtepNodeId);
74 // Remove MAC from cache
75 elanL2GwDevice.removeUcastLocalMac(macRemoved);
77 elanL2GatewayUtils.unInstallL2GwUcastMacFromElan(elan, elanL2GwDevice,
78 Lists.newArrayList(macRemoved.getMacEntryKey()));
82 protected void updated(InstanceIdentifier<LocalUcastMacs> identifier, LocalUcastMacs original,
83 LocalUcastMacs update) {
84 // TODO (eperefr) what can change here?
89 protected void added(InstanceIdentifier<LocalUcastMacs> identifier, LocalUcastMacs macAdded) {
90 String hwvtepNodeId = identifier.firstKeyOf(Node.class).getNodeId().getValue();
91 String macAddress = macAdded.getMacEntryKey().getValue();
93 LOG.trace("LocalUcastMacs {} added to {}", macAddress, hwvtepNodeId);
95 ElanInstance elan = elanL2GatewayUtils.getElanInstanceForUcastLocalMac(macAdded);
97 LOG.warn("Could not find ELAN for mac {} being added", macAddress);
101 String elanName = elan.getElanInstanceName();
102 L2GatewayDevice elanL2GwDevice = ElanL2GwCacheUtils.getL2GatewayDeviceFromCache(elanName, hwvtepNodeId);
103 if (elanL2GwDevice == null) {
104 LOG.warn("Could not find L2GatewayDevice for ELAN: {}, nodeID:{} from cache", elanName, hwvtepNodeId);
108 // Cache MAC for furthur processing later
109 elanL2GwDevice.addUcastLocalMac(macAdded);
111 elanL2GatewayUtils.installL2GwUcastMacInElan(elan, elanL2GwDevice, macAddress, null);
115 protected InstanceIdentifier<LocalUcastMacs> getWildCardPath() {
116 return HwvtepUtils.getWildCardPathForLocalUcastMacs();
120 protected HwvtepLocalUcastMacListener getDataTreeChangeListener() {