2 * Copyright (c) 2015 - 2016 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.neutronvpn;
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;
19 public class InterfaceStateToTransportZoneListener extends AsyncDataTreeChangeListenerBase<Interface, InterfaceStateToTransportZoneListener> implements ClusteredDataTreeChangeListener<Interface>, AutoCloseable{
21 private InterfaceStateManager ism;
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);
33 protected InstanceIdentifier<Interface> getWildCardPath() {
34 return InstanceIdentifier.create(InterfacesState.class).child(Interface.class);
39 protected void remove(InstanceIdentifier<Interface> identifier, Interface del) {
40 // FIXME: once the TZ is declared it will stay forever
45 protected void update(InstanceIdentifier<Interface> identifier, Interface original, Interface update) {
46 ism.updateTrasportZone(update);
51 protected void add(InstanceIdentifier<Interface> identifier, Interface add) {
52 ism.updateTrasportZone(add);
56 protected InterfaceStateToTransportZoneListener getDataTreeChangeListener() {
57 return InterfaceStateToTransportZoneListener.this;
60 private boolean isAutoTunnelConfigEnabled(String autoTunnelConfig) {
61 return !"no".equals(autoTunnelConfig);