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 com.google.common.collect.Lists;
11 import com.google.common.util.concurrent.SettableFuture;
12 import javax.annotation.PostConstruct;
13 import javax.inject.Inject;
14 import javax.inject.Singleton;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
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.cache.ElanInstanceCache;
20 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
21 import org.opendaylight.netvirt.elan.utils.ElanConstants;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInstances;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.elan.instance.ExternalTeps;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
30 public class ElanExtnTepListener extends AsyncDataTreeChangeListenerBase<ExternalTeps, ElanExtnTepListener> {
32 private static final Logger LOG = LoggerFactory.getLogger(ElanExtnTepListener.class);
34 private final DataBroker broker;
35 private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
36 private final JobCoordinator jobCoordinator;
37 private final ElanInstanceCache elanInstanceCache;
40 public ElanExtnTepListener(DataBroker dataBroker, ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils,
41 JobCoordinator jobCoordinator, ElanInstanceCache elanInstanceCache) {
42 super(ExternalTeps.class, ElanExtnTepListener.class);
43 this.broker = dataBroker;
44 this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
45 this.jobCoordinator = jobCoordinator;
46 this.elanInstanceCache = elanInstanceCache;
52 registerListener(LogicalDatastoreType.OPERATIONAL, broker);
56 public InstanceIdentifier<ExternalTeps> getWildCardPath() {
57 return InstanceIdentifier.create(ElanInstances.class).child(ElanInstance.class).child(ExternalTeps.class);
61 protected void add(InstanceIdentifier<ExternalTeps> instanceIdentifier, ExternalTeps tep) {
62 LOG.trace("ExternalTeps add received {}", instanceIdentifier);
63 updateElanRemoteBroadCastGroup(instanceIdentifier);
67 protected void update(InstanceIdentifier<ExternalTeps> instanceIdentifier, ExternalTeps tep, ExternalTeps t1) {
71 protected void remove(InstanceIdentifier<ExternalTeps> instanceIdentifier, ExternalTeps tep) {
72 LOG.trace("ExternalTeps remove received {}", instanceIdentifier);
73 updateElanRemoteBroadCastGroup(instanceIdentifier);
76 @SuppressWarnings("checkstyle:IllegalCatch")
77 private void updateElanRemoteBroadCastGroup(final InstanceIdentifier<ExternalTeps> iid) {
78 String elanName = iid.firstKeyOf(ElanInstance.class).getElanInstanceName();
79 ElanInstance elanInfo = elanInstanceCache.get(elanName).orNull();
80 if (elanInfo == null) {
84 jobCoordinator.enqueueJob(elanName, () -> {
85 SettableFuture<Void> ft = SettableFuture.create();
87 //TODO make the following method return ft
88 elanL2GatewayMulticastUtils.updateRemoteBroadcastGroupForAllElanDpns(elanInfo);
90 } catch (Exception e) {
91 //since the above method does a sync write , if it fails there was no retry
92 //by setting the above mdsal exception in ft, and returning the ft makes sures that job is retried
95 return Lists.newArrayList(ft);
96 }, ElanConstants.JOB_MAX_RETRIES);
100 protected ElanExtnTepListener getDataTreeChangeListener() {