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.netvirt.elan.cache.ElanInstanceCache;
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;
36 private final ElanInstanceCache elanInstanceCache;
39 public ElanDpnToTransportZoneListener(final DataBroker dbx,
40 final ElanConfig elanConfig, final TransportZoneNotificationUtil tznu,
41 final ElanInstanceCache elanInstanceCache) {
42 useTransportZone = elanConfig.isAutoConfigTransportZones();
43 transportZoneNotificationUtil = tznu;
45 this.elanInstanceCache = elanInstanceCache;
50 LOG.info("{} start", getClass().getSimpleName());
52 if (useTransportZone) {
53 registerListener(LogicalDatastoreType.OPERATIONAL, dbx);
58 public InstanceIdentifier<DpnInterfaces> getWildCardPath() {
59 return InstanceIdentifier.builder(ElanDpnInterfaces.class).child(ElanDpnInterfacesList.class)
60 .child(DpnInterfaces.class).build();
64 protected void remove(InstanceIdentifier<DpnInterfaces> key, DpnInterfaces dataObjectModification) {
65 LOG.debug("Elan dpn {} delete detected, deleting transport zones", dataObjectModification.getDpId());
66 BigInteger dpId = dataObjectModification.getDpId();
67 String elanInstanceName = key.firstKeyOf(ElanDpnInterfacesList.class).getElanInstanceName();
69 if (!ElanUtils.isVxlanNetworkOrVxlanSegment(elanInstanceCache.get(elanInstanceName).orNull())) {
70 LOG.debug("ElanInstance {} is not vxlan network, nothing to do", elanInstanceName);
73 LOG.debug("Deleting tz for elanInstance {} dpId {}", elanInstanceName, dpId);
74 transportZoneNotificationUtil.deleteTransportZone(elanInstanceName, dpId);
79 protected void update(InstanceIdentifier<DpnInterfaces> key, DpnInterfaces dataObjectModificationBefore,
80 DpnInterfaces dataObjectModificationAfter) {
84 protected void add(InstanceIdentifier<DpnInterfaces> key, DpnInterfaces dataObjectModification) {
85 LOG.debug("Elan dpn {} add detected, updating transport zones", dataObjectModification.getDpId());
87 BigInteger dpId = dataObjectModification.getDpId();
88 String elanInstanceName = key.firstKeyOf(ElanDpnInterfacesList.class).getElanInstanceName();
90 if (!ElanUtils.isVxlanNetworkOrVxlanSegment(elanInstanceCache.get(elanInstanceName).orNull())) {
94 transportZoneNotificationUtil.updateTransportZone(elanInstanceName, dpId);
98 protected ElanDpnToTransportZoneListener getDataTreeChangeListener() {
99 return ElanDpnToTransportZoneListener.this;