Bulk merge of l2gw changes
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / l2gw / utils / ElanL2GatewayBcGroupUtils.java
1 /*
2  * Copyright (c) 2020 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netvirt.elan.l2gw.utils;
9
10 import static org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION;
11
12 import com.google.common.util.concurrent.ListenableFuture;
13 import java.util.Collections;
14 import java.util.List;
15 import javax.inject.Inject;
16 import javax.inject.Singleton;
17 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
18 import org.opendaylight.mdsal.binding.api.DataBroker;
19 import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner;
20 import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl;
21 import org.opendaylight.netvirt.elan.cache.ElanInstanceDpnsCache;
22 import org.opendaylight.netvirt.elan.l2gw.jobs.BcGroupUpdateJob;
23 import org.opendaylight.netvirt.elan.utils.ElanItmUtils;
24 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.elan.dpn.interfaces.list.DpnInterfaces;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 /**
31  * The utility class to handle ELAN L2 Gateway related to multicast.
32  */
33 @Singleton
34 public class ElanL2GatewayBcGroupUtils {
35
36     /** The Constant LOG. */
37     private static final Logger LOG = LoggerFactory.getLogger(ElanL2GatewayBcGroupUtils.class);
38
39     private ElanRefUtil elanRefUtil;
40     private ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
41     private IMdsalApiManager mdsalApiManager;
42     private ElanInstanceDpnsCache elanInstanceDpnsCache;
43     private ElanItmUtils elanItmUtils;
44     private final ManagedNewTransactionRunner txRunner;
45
46     @Inject
47     public ElanL2GatewayBcGroupUtils(DataBroker db, ElanRefUtil elanRefUtil,
48                                      ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils,
49                                      IMdsalApiManager mdsalApiManager,
50                                      ElanInstanceDpnsCache elanInstanceDpnsCache,
51                                      ElanItmUtils elanItmUtils) {
52         this.elanRefUtil = elanRefUtil;
53         this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
54         this.mdsalApiManager = mdsalApiManager;
55         this.elanInstanceDpnsCache = elanInstanceDpnsCache;
56         this.elanItmUtils = elanItmUtils;
57         this.txRunner = new ManagedNewTransactionRunnerImpl(db);
58     }
59
60     public List<ListenableFuture<Void>> updateBcGroupForAllDpns(String elanName,
61                                                                 L2GatewayDevice device,
62                                                                 boolean createCase) {
63         BcGroupUpdateJob.updateAllBcGroups(elanName, createCase, null, device, elanRefUtil,
64                 elanL2GatewayMulticastUtils, mdsalApiManager, elanInstanceDpnsCache, elanItmUtils);
65         //new BcGroupUpdateJob(elanName, createCase, null, device, elanRefUtil, elanL2GatewayMulticastUtils,
66         //        mdsalApiManager, elanInstanceDpnsCache, elanItmUtils).submit();
67
68         return Collections.emptyList();
69     }
70
71     public void updateRemoteBroadcastGroupForAllElanDpns(ElanInstance elanInfo) {
72         List<DpnInterfaces> dpns = elanRefUtil.getElanUtils()
73                 .getInvolvedDpnsInElan(elanInfo.getElanInstanceName());
74         LOG.debug("Invoking method ELAN Broadcast Groups for ELAN {}", elanInfo);
75         for (DpnInterfaces dpn : dpns) {
76             txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
77                 elanL2GatewayMulticastUtils.setupElanBroadcastGroups(elanInfo, dpn.getDpId(), tx);
78             });
79
80         }
81     }
82
83 }