Bug 7831 : BgpRouter receives unnecessary events
[netvirt.git] / vpnservice / neutronvpn / neutronvpn-impl / src / main / java / org / opendaylight / netvirt / neutronvpn / BridgeRefEntryToTransportZoneListener.java
1 /*
2  * Copyright (c) 2015 - 2016 HPE and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netvirt.neutronvpn;
9
10 import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
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.AsyncDataTreeChangeListenerBase;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.BridgeRefInfo;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.bridge.ref.info.BridgeRefEntry;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public class BridgeRefEntryToTransportZoneListener extends AsyncDataTreeChangeListenerBase<BridgeRefEntry,
21     BridgeRefEntryToTransportZoneListener> implements ClusteredDataTreeChangeListener<BridgeRefEntry>, AutoCloseable {
22
23     private static final Logger LOG = LoggerFactory.getLogger(BridgeRefEntryToTransportZoneListener.class);
24     private TransportZoneNotificationUtil ism;
25     private DataBroker dbx;
26
27     public BridgeRefEntryToTransportZoneListener(DataBroker dbx, NeutronvpnManager nvManager) {
28         super(BridgeRefEntry.class, BridgeRefEntryToTransportZoneListener.class);
29         this.dbx = dbx;
30         ism = new TransportZoneNotificationUtil(dbx, nvManager);
31     }
32
33     public void start() {
34         LOG.info("{} start", getClass().getSimpleName());
35         if (ism.isAutoTunnelConfigEnabled()) {
36             registerListener(LogicalDatastoreType.OPERATIONAL, dbx);
37         }
38     }
39
40     @Override
41     protected InstanceIdentifier<BridgeRefEntry> getWildCardPath() {
42         InstanceIdentifier.InstanceIdentifierBuilder<BridgeRefEntry> bridgeRefEntryInstanceIdentifierBuilder =
43                 InstanceIdentifier.builder(BridgeRefInfo.class)
44                         .child(BridgeRefEntry.class);
45         return bridgeRefEntryInstanceIdentifierBuilder.build();
46     }
47
48
49     @Override
50     protected void remove(InstanceIdentifier<BridgeRefEntry> identifier, BridgeRefEntry del) {
51         // once the TZ is declared it will stay forever
52     }
53
54     @Override
55     protected void update(InstanceIdentifier<BridgeRefEntry> identifier, BridgeRefEntry original,
56             BridgeRefEntry update) {
57         LOG.debug("handle BridgeRefEntry update notification {}", update);
58         ism.updateTransportZone(update);
59     }
60
61     @Override
62     protected void add(InstanceIdentifier<BridgeRefEntry> identifier, BridgeRefEntry add) {
63         LOG.debug("handle BridgeRefEntry add notification {}", add);
64         ism.updateTransportZone(add);
65     }
66
67     @Override
68     protected BridgeRefEntryToTransportZoneListener getDataTreeChangeListener() {
69         return BridgeRefEntryToTransportZoneListener.this;
70     }
71
72 }