2 * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. 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.elan.internal;
10 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
12 import com.google.common.base.Optional;
13 import java.util.Collections;
14 import javax.annotation.PostConstruct;
15 import javax.inject.Inject;
16 import javax.inject.Singleton;
17 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
18 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
19 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
20 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
21 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
22 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
23 import org.opendaylight.netvirt.elan.cache.ElanInterfaceCache;
24 import org.opendaylight.netvirt.elan.utils.ElanConstants;
25 import org.opendaylight.netvirt.elan.utils.ElanUtils;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterface;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
35 public class ElanInterfaceConfigListener
36 extends AsyncDataTreeChangeListenerBase<Interface, ElanInterfaceConfigListener> {
38 private static final Logger LOG = LoggerFactory.getLogger(ElanInterfaceConfigListener.class);
40 private final DataBroker dataBroker;
41 private final ManagedNewTransactionRunner txRunner;
42 private final ElanInterfaceManager elanInterfaceManager;
43 private final JobCoordinator jobCoordinator;
44 private final ElanInterfaceCache elanInterfaceCache;
47 public ElanInterfaceConfigListener(DataBroker dataBroker, ElanInterfaceManager elanInterfaceManager,
48 JobCoordinator jobCoordinator, ElanInterfaceCache elanInterfaceCache) {
49 super(Interface.class, ElanInterfaceConfigListener.class);
50 this.dataBroker = dataBroker;
51 this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
52 this.elanInterfaceManager = elanInterfaceManager;
53 this.jobCoordinator = jobCoordinator;
54 this.elanInterfaceCache = elanInterfaceCache;
60 LOG.info("ElanInterfaceConfigListener init");
61 registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
65 protected InstanceIdentifier<Interface> getWildCardPath() {
66 return InstanceIdentifier.create(Interfaces.class).child(Interface.class);
70 protected void remove(InstanceIdentifier<Interface> key, Interface intrf) {
71 // Sometimes elan service is not unbound on the interface when the user does nova delete followed
72 // by neutron port delete since interface config is deleted a bit later. so adding logic to
73 // unbind service for interface config removal.
74 if (intrf == null || intrf.augmentation(IfL2vlan.class) == null) {
75 LOG.debug("The interface {} is not a L2 interface. Ignoring it", intrf);
79 String interfaceName = intrf.getName();
80 Optional<ElanInterface> elanInterface = elanInterfaceCache.get(interfaceName);
81 if (!elanInterface.isPresent()) {
82 LOG.debug("There is no ELAN service for interface {}. Ignoring it", interfaceName);
85 jobCoordinator.enqueueJob(ElanUtils.getElanInterfaceJobKey(interfaceName),
86 () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
87 LOG.debug("unbinding elan service on interface {} for its config removal", interfaceName);
88 elanInterfaceManager.unbindService(interfaceName, tx);
89 })), ElanConstants.JOB_MAX_RETRIES);
93 protected void update(InstanceIdentifier<Interface> key, Interface dataObjectModificationBefore,
94 Interface dataObjectModificationAfter) {
95 // Not required to handle this event
99 protected void add(InstanceIdentifier<Interface> key, Interface dataObjectModification) {
100 // Not required to handle this event
104 protected ElanInterfaceConfigListener getDataTreeChangeListener() {