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 java.util.Collections;
11 import javax.annotation.PostConstruct;
12 import javax.inject.Inject;
13 import javax.inject.Singleton;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
18 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
19 import org.opendaylight.netvirt.elan.utils.ElanConstants;
20 import org.opendaylight.netvirt.elan.utils.ElanUtils;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterface;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
30 public class ElanInterfaceConfigListener
31 extends AsyncDataTreeChangeListenerBase<Interface, ElanInterfaceConfigListener> {
33 private static final Logger LOG = LoggerFactory.getLogger(ElanInterfaceConfigListener.class);
35 private final DataBroker dataBroker;
36 private final ElanInterfaceManager elanInterfaceManager;
37 private final JobCoordinator jobCoordinator;
40 public ElanInterfaceConfigListener(DataBroker dataBroker, ElanInterfaceManager elanInterfaceManager,
41 JobCoordinator jobCoordinator) {
42 super(Interface.class, ElanInterfaceConfigListener.class);
43 this.dataBroker = dataBroker;
44 this.elanInterfaceManager = elanInterfaceManager;
45 this.jobCoordinator = jobCoordinator;
51 LOG.info("ElanInterfaceConfigListener init");
52 registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
56 protected InstanceIdentifier<Interface> getWildCardPath() {
57 return InstanceIdentifier.create(Interfaces.class).child(Interface.class);
61 protected void remove(InstanceIdentifier<Interface> key, Interface intrf) {
62 // Sometimes elan service is not unbound on the interface when the user does nova delete followed
63 // by neutron port delete since interface config is deleted a bit later. so adding logic to
64 // unbind service for interface config removal.
65 if (intrf == null || intrf.getAugmentation(IfL2vlan.class) == null) {
66 LOG.debug("The interface {} is not a L2 interface. Ignoring it", intrf);
70 String interfaceName = intrf.getName();
71 ElanInterface elanInterface = ElanUtils.getElanInterfaceByElanInterfaceName(dataBroker, interfaceName);
72 if (elanInterface == null) {
73 LOG.debug("There is no ELAN service for interface {}. Ignoring it", interfaceName);
76 jobCoordinator.enqueueJob(ElanUtils.getElanInterfaceJobKey(interfaceName), () -> {
77 WriteTransaction writeConfigTxn = dataBroker.newWriteOnlyTransaction();
78 LOG.debug("unbinding elan service on interface {} for its config removal", interfaceName);
79 elanInterfaceManager.unbindService(interfaceName, writeConfigTxn);
80 return Collections.singletonList(writeConfigTxn.submit());
81 }, ElanConstants.JOB_MAX_RETRIES);
85 protected void update(InstanceIdentifier<Interface> key, Interface dataObjectModificationBefore,
86 Interface dataObjectModificationAfter) {
87 // Not required to handle this event
91 protected void add(InstanceIdentifier<Interface> key, Interface dataObjectModification) {
92 // Not required to handle this event
96 protected ElanInterfaceConfigListener getDataTreeChangeListener() {