Bug 6559: Create TZ for routed networks
[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.genius.mdsalutil.MDSALDataStoreUtils;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.config.rev160806.NeutronvpnConfig;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 import com.google.common.base.Optional;
24
25 public class InterfaceStateToTransportZoneListener extends AsyncDataTreeChangeListenerBase<Interface, InterfaceStateToTransportZoneListener> implements ClusteredDataTreeChangeListener<Interface>, AutoCloseable{
26
27     private static final Logger LOG = LoggerFactory.getLogger(InterfaceStateToTransportZoneListener.class);
28     private ToTransportZoneManagerManager ism;
29
30     public InterfaceStateToTransportZoneListener(DataBroker dbx, NeutronvpnManager nvManager) {
31         super(Interface.class, InterfaceStateToTransportZoneListener.class);
32         ism = new ToTransportZoneManagerManager(dbx, nvManager);
33         
34         if (ism.isAutoTunnelConfigEnabled()) {
35             registerListener(LogicalDatastoreType.OPERATIONAL, dbx);
36         }
37
38     }
39
40     @Override
41     protected InstanceIdentifier<Interface> getWildCardPath() {
42         return InstanceIdentifier.create(InterfacesState.class).child(Interface.class);
43     }
44
45
46     @Override
47     protected void remove(InstanceIdentifier<Interface> identifier, Interface del) {
48         // FIXME: once the TZ is declared it will stay forever
49
50     }
51
52     @Override
53     protected void update(InstanceIdentifier<Interface> identifier, Interface original, Interface update) {
54         ism.updateTrasportZone(update);
55     }
56
57
58     @Override
59     protected void add(InstanceIdentifier<Interface> identifier, Interface add) {
60         ism.updateTrasportZone(add);
61     }
62     
63     @Override
64     protected InterfaceStateToTransportZoneListener getDataTreeChangeListener() {
65         return InterfaceStateToTransportZoneListener.this;
66     }
67     
68 }