2 * Copyright (c) 2017 HPE 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.internal;
10 import java.math.BigInteger;
11 import javax.annotation.PostConstruct;
12 import javax.inject.Inject;
13 import javax.inject.Singleton;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
17 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
18 import org.opendaylight.netvirt.elan.utils.ElanUtils;
19 import org.opendaylight.netvirt.elan.utils.TransportZoneNotificationUtil;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.config.rev150710.ElanConfig;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanDpnInterfaces;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.ElanDpnInterfacesList;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.elan.dpn.interfaces.list.DpnInterfaces;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 public class ElanDpnToTransportZoneListener
30 extends AsyncDataTreeChangeListenerBase<DpnInterfaces, ElanDpnToTransportZoneListener> {
32 private static final Logger LOG = LoggerFactory.getLogger(ElanDpnToTransportZoneListener.class);
33 private final TransportZoneNotificationUtil transportZoneNotificationUtil;
34 private final DataBroker dbx;
35 private final Boolean useTransportZone;
38 public ElanDpnToTransportZoneListener(final DataBroker dbx, final IInterfaceManager interfaceManager,
39 final ElanConfig elanConfig, final TransportZoneNotificationUtil tznu) {
40 useTransportZone = elanConfig.isAutoConfigTransportZones();
41 transportZoneNotificationUtil = tznu;
47 LOG.info("{} start", getClass().getSimpleName());
49 if (useTransportZone) {
50 registerListener(LogicalDatastoreType.OPERATIONAL, dbx);
55 public InstanceIdentifier<DpnInterfaces> getWildCardPath() {
56 return InstanceIdentifier.builder(ElanDpnInterfaces.class).child(ElanDpnInterfacesList.class)
57 .child(DpnInterfaces.class).build();
61 protected void remove(InstanceIdentifier<DpnInterfaces> key, DpnInterfaces dataObjectModification) {
62 LOG.debug("Elan dpn {} delete detected, deleting transport zones", dataObjectModification.getDpId());
63 BigInteger dpId = dataObjectModification.getDpId();
64 String elanInstanceName = key.firstKeyOf(ElanDpnInterfacesList.class).getElanInstanceName();
66 if (!ElanUtils.isVxlanNetwork(dbx, elanInstanceName)) {
67 LOG.debug("ElanInstance {} is not vxlan network, nothing to do", elanInstanceName);
70 LOG.debug("Deleting tz for elanInstance {} dpId {}", elanInstanceName, dpId);
71 transportZoneNotificationUtil.deleteTransportZone(elanInstanceName, dpId);
76 protected void update(InstanceIdentifier<DpnInterfaces> key, DpnInterfaces dataObjectModificationBefore,
77 DpnInterfaces dataObjectModificationAfter) {
81 protected void add(InstanceIdentifier<DpnInterfaces> key, DpnInterfaces dataObjectModification) {
82 LOG.debug("Elan dpn {} add detected, updating transport zones", dataObjectModification.getDpId());
84 BigInteger dpId = dataObjectModification.getDpId();
85 String elanInstanceName = key.firstKeyOf(ElanDpnInterfacesList.class).getElanInstanceName();
87 if (!ElanUtils.isVxlanNetwork(dbx, elanInstanceName)) {
91 transportZoneNotificationUtil.updateTransportZone(elanInstanceName, dpId);
95 protected ElanDpnToTransportZoneListener getDataTreeChangeListener() {
96 return ElanDpnToTransportZoneListener.this;