Merge "Corrections on DHCP caches"
[netvirt.git] / vpnservice / neutronvpn / neutronvpn-impl / src / main / java / org / opendaylight / netvirt / neutronvpn / InterfaceStateToTransportZoneListener.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.binding.api.DataChangeListener;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18
19 public class InterfaceStateToTransportZoneListener extends AsyncDataTreeChangeListenerBase<Interface, InterfaceStateToTransportZoneListener> implements ClusteredDataTreeChangeListener<Interface>, AutoCloseable{
20
21     private InterfaceStateManager ism;
22
23     public InterfaceStateToTransportZoneListener(DataBroker dbx, NeutronvpnManager nvManager, String autoTunnelConfig) {
24         super(Interface.class, InterfaceStateToTransportZoneListener.class);
25         ism = new InterfaceStateManager(dbx, nvManager);
26         if (isAutoTunnelConfigEnabled(autoTunnelConfig)) {
27             registerListener(LogicalDatastoreType.OPERATIONAL, dbx);
28         }       
29
30     }
31
32     @Override
33     protected InstanceIdentifier<Interface> getWildCardPath() {
34         return InstanceIdentifier.create(InterfacesState.class).child(Interface.class);
35     }
36
37
38     @Override
39     protected void remove(InstanceIdentifier<Interface> identifier, Interface del) {
40         // FIXME: once the TZ is declared it will stay forever
41
42     }
43
44     @Override
45     protected void update(InstanceIdentifier<Interface> identifier, Interface original, Interface update) {
46         ism.updateTrasportZone(update);
47     }
48
49
50     @Override
51     protected void add(InstanceIdentifier<Interface> identifier, Interface add) {
52         ism.updateTrasportZone(add);
53     }
54     
55     @Override
56     protected InterfaceStateToTransportZoneListener getDataTreeChangeListener() {
57         return InterfaceStateToTransportZoneListener.this;
58     }
59     
60     private boolean isAutoTunnelConfigEnabled(String autoTunnelConfig) {
61         return !"no".equals(autoTunnelConfig);
62     }
63
64 }