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.cache.ElanInstanceCache;
19 import org.opendaylight.netvirt.elan.utils.ElanUtils;
20 import org.opendaylight.netvirt.elan.utils.TransportZoneNotificationUtil;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.config.rev150710.ElanConfig;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanDpnInterfaces;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.ElanDpnInterfacesList;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.elan.dpn.interfaces.list.DpnInterfaces;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
30 public class ElanDpnToTransportZoneListener
31 extends AsyncDataTreeChangeListenerBase<DpnInterfaces, ElanDpnToTransportZoneListener> {
33 private static final Logger LOG = LoggerFactory.getLogger(ElanDpnToTransportZoneListener.class);
34 private final TransportZoneNotificationUtil transportZoneNotificationUtil;
35 private final DataBroker dbx;
36 private final Boolean useTransportZone;
37 private final ElanInstanceCache elanInstanceCache;
40 public ElanDpnToTransportZoneListener(final DataBroker dbx, final IInterfaceManager interfaceManager,
41 final ElanConfig elanConfig, final TransportZoneNotificationUtil tznu,
42 final ElanInstanceCache elanInstanceCache) {
43 useTransportZone = elanConfig.isAutoConfigTransportZones();
44 transportZoneNotificationUtil = tznu;
46 this.elanInstanceCache = elanInstanceCache;
51 LOG.info("{} start", getClass().getSimpleName());
53 if (useTransportZone) {
54 registerListener(LogicalDatastoreType.OPERATIONAL, dbx);
59 public InstanceIdentifier<DpnInterfaces> getWildCardPath() {
60 return InstanceIdentifier.builder(ElanDpnInterfaces.class).child(ElanDpnInterfacesList.class)
61 .child(DpnInterfaces.class).build();
65 protected void remove(InstanceIdentifier<DpnInterfaces> key, DpnInterfaces dataObjectModification) {
66 LOG.debug("Elan dpn {} delete detected, deleting transport zones", dataObjectModification.getDpId());
67 BigInteger dpId = dataObjectModification.getDpId();
68 String elanInstanceName = key.firstKeyOf(ElanDpnInterfacesList.class).getElanInstanceName();
70 if (!ElanUtils.isVxlanNetworkOrVxlanSegment(elanInstanceCache.get(elanInstanceName).orNull())) {
71 LOG.debug("ElanInstance {} is not vxlan network, nothing to do", elanInstanceName);
74 LOG.debug("Deleting tz for elanInstance {} dpId {}", elanInstanceName, dpId);
75 transportZoneNotificationUtil.deleteTransportZone(elanInstanceName, dpId);
80 protected void update(InstanceIdentifier<DpnInterfaces> key, DpnInterfaces dataObjectModificationBefore,
81 DpnInterfaces dataObjectModificationAfter) {
85 protected void add(InstanceIdentifier<DpnInterfaces> key, DpnInterfaces dataObjectModification) {
86 LOG.debug("Elan dpn {} add detected, updating transport zones", dataObjectModification.getDpId());
88 BigInteger dpId = dataObjectModification.getDpId();
89 String elanInstanceName = key.firstKeyOf(ElanDpnInterfacesList.class).getElanInstanceName();
91 if (!ElanUtils.isVxlanNetworkOrVxlanSegment(elanInstanceCache.get(elanInstanceName).orNull())) {
95 transportZoneNotificationUtil.updateTransportZone(elanInstanceName, dpId);
99 protected ElanDpnToTransportZoneListener getDataTreeChangeListener() {
100 return ElanDpnToTransportZoneListener.this;