2 * Copyright (c) 2016 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 org.opendaylight.controller.md.sal.binding.api.ClusteredDataChangeListener;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
13 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.netvirt.elan.utils.ElanClusterUtils;
16 import org.opendaylight.netvirt.elan.utils.ElanUtils;
17 import org.opendaylight.genius.datastoreutils.AsyncClusteredDataChangeListenerBase;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.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;
26 public class ElanInterfaceStateClusteredListener extends
27 AsyncClusteredDataChangeListenerBase<Interface, ElanInterfaceStateClusteredListener> implements AutoCloseable {
29 private static final Logger logger = LoggerFactory.getLogger(ElanInterfaceStateClusteredListener.class);
31 private final DataBroker broker;
32 private final ElanInterfaceManager elanInterfaceManager;
33 private final ElanUtils elanUtils;
34 private final EntityOwnershipService entityOwnershipService;
36 public ElanInterfaceStateClusteredListener(DataBroker broker, ElanInterfaceManager elanInterfaceManager,
37 ElanUtils elanUtils, EntityOwnershipService entityOwnershipService) {
38 super(Interface.class, ElanInterfaceStateClusteredListener.class);
40 this.elanInterfaceManager = elanInterfaceManager;
41 this.elanUtils = elanUtils;
42 this.entityOwnershipService = entityOwnershipService;
46 registerListener(LogicalDatastoreType.OPERATIONAL, broker);
50 public InstanceIdentifier<Interface> getWildCardPath() {
51 return InstanceIdentifier.create(InterfacesState.class).child(Interface.class);
55 protected ClusteredDataChangeListener getDataChangeListener() {
56 return ElanInterfaceStateClusteredListener.this;
60 protected AsyncDataBroker.DataChangeScope getDataChangeScope() {
61 return AsyncDataBroker.DataChangeScope.BASE;
65 protected void remove(InstanceIdentifier<Interface> identifier, Interface delIf) {
69 protected void update(InstanceIdentifier<Interface> identifier, Interface original, final Interface update) {
70 add(identifier, update);
74 protected void add(InstanceIdentifier<Interface> identifier, final Interface intrf) {
75 if (intrf.getType() != null && intrf.getType().equals(Tunnel.class)) {
76 if (intrf.getOperStatus().equals(Interface.OperStatus.Up)) {
77 final String interfaceName = intrf.getName();
79 ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, new Runnable() {
82 logger.debug("running external tunnel update job for interface {} added", interfaceName);
83 handleExternalTunnelUpdate(interfaceName, intrf);
90 private void handleExternalTunnelUpdate(String interfaceName, Interface update) {
91 ExternalTunnel externalTunnel = elanUtils.getExternalTunnel(interfaceName, LogicalDatastoreType.CONFIGURATION);
92 if (externalTunnel != null) {
93 logger.debug("handling external tunnel update event for ext device dst {} src {} ",
94 externalTunnel.getDestinationDevice(), externalTunnel.getSourceDevice());
95 elanInterfaceManager.handleExternalTunnelStateEvent(externalTunnel, update);
97 logger.trace("External tunnel not found with interfaceName: {}", interfaceName);