2 * Copyright (c) 2019 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.l2gw.jobs;
10 import com.google.common.util.concurrent.ListenableFuture;
12 import java.util.ArrayList;
13 import java.util.List;
14 import java.util.concurrent.Callable;
16 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
17 import org.opendaylight.netvirt.elan.utils.ElanClusterUtils;
18 import org.opendaylight.netvirt.elan.utils.ElanItmUtils;
19 import org.opendaylight.netvirt.elan.utils.ElanUtils;
20 import org.opendaylight.netvirt.elanmanager.utils.ElanL2GwCacheUtils;
21 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
24 import org.opendaylight.yangtools.yang.common.Uint64;
26 public class McastUpdateJob implements Callable<List<ListenableFuture<Void>>> {
27 private String elanName;
28 private String nodeId;
29 private ElanL2GatewayMulticastUtils mcastUtils;
30 private ElanClusterUtils elanClusterUtils;
32 protected String jobKey;
33 private IpAddress removedDstTep;
34 private boolean dpnOrConnectionRemoved;
36 public McastUpdateJob(String elanName,
39 ElanL2GatewayMulticastUtils mcastUtils,
40 ElanClusterUtils elanClusterUtils) {
41 this.jobKey = ElanUtils.getBcGroupUpdateKey(elanName);
42 this.elanName = elanName;
44 this.mcastUtils = mcastUtils;
46 this.elanClusterUtils = elanClusterUtils;
49 public void submit() {
50 elanClusterUtils.runOnlyInOwnerNode(this.jobKey, "Mcast Update job",this);
54 public List<ListenableFuture<Void>> call() throws Exception {
55 L2GatewayDevice device = ElanL2GwCacheUtils.getL2GatewayDeviceFromCache(elanName, nodeId);
56 ListenableFuture<Void> ft = null;
57 //TODO: make prepareRemoteMcastMacUpdateOnDevice return a ListenableFuture<Void>
59 ft = mcastUtils.prepareRemoteMcastMacUpdateOnDevice(elanName, device, !dpnOrConnectionRemoved ,
62 ft = mcastUtils.deleteRemoteMcastMac(new NodeId(nodeId), elanName);
64 List<ListenableFuture<Void>> fts = new ArrayList<ListenableFuture<Void>>();
69 public static void updateAllMcasts(String elanName,
70 ElanL2GatewayMulticastUtils mcastUtils,
71 ElanClusterUtils elanClusterUtils) {
72 ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName).forEach(device -> {
73 new McastUpdateJob(elanName, device.getHwvtepNodeId(), true, mcastUtils,
74 elanClusterUtils).submit();
78 public static void removeMcastForNode(String elanName, String nodeId,
79 ElanL2GatewayMulticastUtils mcastUtils,
80 ElanClusterUtils elanClusterUtils) {
81 new McastUpdateJob(elanName, nodeId, false, mcastUtils,
82 elanClusterUtils).submit();
85 public static void updateMcastForNode(String elanName, String nodeId,
86 ElanL2GatewayMulticastUtils mcastUtils,
87 ElanClusterUtils elanClusterUtils) {
88 new McastUpdateJob(elanName, nodeId, true, mcastUtils,
89 elanClusterUtils).submit();
92 private McastUpdateJob setRemovedDstTep(IpAddress removedDstTep) {
93 this.removedDstTep = removedDstTep;
97 private McastUpdateJob setDpnOrconnectionRemoved() {
98 this.dpnOrConnectionRemoved = true;
102 public static void updateAllMcastsForConnectionAdd(String elanName,
103 ElanL2GatewayMulticastUtils mcastUtils,
104 ElanClusterUtils elanClusterUtils) {
105 ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName).forEach(device -> {
106 new McastUpdateJob(elanName, device.getHwvtepNodeId(), true , mcastUtils, elanClusterUtils).submit();
110 public static void updateAllMcastsForConnectionDelete(String elanName,
111 ElanL2GatewayMulticastUtils mcastUtils,
112 ElanClusterUtils elanClusterUtils,
113 L2GatewayDevice deletedDevice) {
114 ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName).forEach(device -> {
115 IpAddress deletedTep = deletedDevice.getTunnelIp();
116 new McastUpdateJob(elanName, device.getHwvtepNodeId(), true , mcastUtils, elanClusterUtils)
117 .setDpnOrconnectionRemoved()
118 .setRemovedDstTep(deletedTep)
123 public static void updateAllMcastsForDpnAdd(String elanName,
124 ElanL2GatewayMulticastUtils mcastUtils,
125 ElanClusterUtils elanClusterUtils) {
126 ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName).forEach(device -> {
127 new McastUpdateJob(elanName, device.getHwvtepNodeId(), true , mcastUtils, elanClusterUtils).submit();
131 public static void updateAllMcastsForDpnDelete(String elanName,
132 ElanL2GatewayMulticastUtils mcastUtils,
133 ElanClusterUtils elanClusterUtils,
135 ElanItmUtils elanItmUtils) {
136 ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName).forEach(device -> {
137 IpAddress deletedTep = elanItmUtils.getSourceDpnTepIp(srcDpnId, new NodeId(device.getHwvtepNodeId()));
138 new McastUpdateJob(elanName, device.getHwvtepNodeId(), true , mcastUtils, elanClusterUtils)
139 .setDpnOrconnectionRemoved()
140 .setRemovedDstTep(deletedTep)