2 * Copyright (c) 2016, 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 javax.annotation.PostConstruct;
11 import javax.inject.Inject;
12 import javax.inject.Singleton;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase;
16 import org.opendaylight.netvirt.elan.utils.ElanClusterUtils;
17 import org.opendaylight.netvirt.elan.utils.ElanUtils;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev170119.Tunnel;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.external.tunnel.list.ExternalTunnel;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 public class ElanInterfaceStateClusteredListener extends
28 AsyncClusteredDataTreeChangeListenerBase<Interface, ElanInterfaceStateClusteredListener> {
30 private static final Logger LOG = LoggerFactory.getLogger(ElanInterfaceStateClusteredListener.class);
32 private final DataBroker broker;
33 private final ElanInterfaceManager elanInterfaceManager;
34 private final ElanUtils elanUtils;
35 private final ElanClusterUtils elanClusterUtils;
38 * Why do we have ElanInterfaceStateChangeListener and ElanInterfaceStateClusteredListener
39 * both within same module? Refactor this code into single listener.
42 public ElanInterfaceStateClusteredListener(DataBroker broker, ElanInterfaceManager elanInterfaceManager,
43 ElanUtils elanUtils, ElanClusterUtils elanClusterUtils) {
45 this.elanInterfaceManager = elanInterfaceManager;
46 this.elanUtils = elanUtils;
47 this.elanClusterUtils = elanClusterUtils;
52 registerListener(LogicalDatastoreType.OPERATIONAL, broker);
56 public InstanceIdentifier<Interface> getWildCardPath() {
57 return InstanceIdentifier.create(InterfacesState.class).child(Interface.class);
61 protected void remove(InstanceIdentifier<Interface> identifier, Interface delIf) {
65 protected void update(InstanceIdentifier<Interface> identifier, Interface original, final Interface update) {
66 add(identifier, update);
70 protected void add(InstanceIdentifier<Interface> identifier, final Interface intrf) {
71 if (intrf.getType() != null && intrf.getType().equals(Tunnel.class)) {
72 if (Interface.OperStatus.Up.equals(intrf.getOperStatus())) {
73 final String interfaceName = intrf.getName();
75 elanClusterUtils.runOnlyInOwnerNode("external tunnel update", () -> {
76 LOG.debug("running external tunnel update job for interface {} added", interfaceName);
77 handleExternalTunnelUpdate(interfaceName, intrf);
83 private void handleExternalTunnelUpdate(String interfaceName, Interface update) {
84 ExternalTunnel externalTunnel = elanUtils.getExternalTunnel(interfaceName, LogicalDatastoreType.CONFIGURATION);
85 if (externalTunnel != null) {
86 LOG.debug("handling external tunnel update event for ext device dst {} src {} ",
87 externalTunnel.getDestinationDevice(), externalTunnel.getSourceDevice());
88 elanInterfaceManager.handleExternalTunnelStateEvent(externalTunnel, update);
90 LOG.trace("External tunnel not found with interfaceName: {}", interfaceName);
95 * @see org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase#getDataTreeChangeListener()
98 protected ElanInterfaceStateClusteredListener getDataTreeChangeListener() {