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.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;
23 import com.google.common.base.Optional;
25 public class InterfaceStateToTransportZoneListener extends AsyncDataTreeChangeListenerBase<Interface, InterfaceStateToTransportZoneListener> implements ClusteredDataTreeChangeListener<Interface>, AutoCloseable{
27 private static final Logger LOG = LoggerFactory.getLogger(InterfaceStateToTransportZoneListener.class);
28 private InterfaceStateManager ism;
30 public InterfaceStateToTransportZoneListener(DataBroker dbx, NeutronvpnManager nvManager) {
31 super(Interface.class, InterfaceStateToTransportZoneListener.class);
32 ism = new InterfaceStateManager(dbx, nvManager);
33 Optional<NeutronvpnConfig> nvsConfig = MDSALDataStoreUtils.read(dbx,
34 LogicalDatastoreType.CONFIGURATION, InstanceIdentifier
35 .create(NeutronvpnConfig.class));
37 if (nvsConfig.isPresent()) {
38 useTZ = nvsConfig.get().isUseTransportZone() == null ? true : nvsConfig.get().isUseTransportZone();
40 if (isAutoTunnelConfigEnabled(useTZ)) {
41 registerListener(LogicalDatastoreType.OPERATIONAL, dbx);
47 protected InstanceIdentifier<Interface> getWildCardPath() {
48 return InstanceIdentifier.create(InterfacesState.class).child(Interface.class);
53 protected void remove(InstanceIdentifier<Interface> identifier, Interface del) {
54 // FIXME: once the TZ is declared it will stay forever
59 protected void update(InstanceIdentifier<Interface> identifier, Interface original, Interface update) {
60 ism.updateTrasportZone(update);
65 protected void add(InstanceIdentifier<Interface> identifier, Interface add) {
66 ism.updateTrasportZone(add);
70 protected InterfaceStateToTransportZoneListener getDataTreeChangeListener() {
71 return InterfaceStateToTransportZoneListener.this;
74 private boolean isAutoTunnelConfigEnabled(Boolean useTZ) {
76 LOG.info("using automatic tunnel configuration");
78 LOG.info("don't use automatic tunnel configuration");