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;
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.concurrent.Callable;
14 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
15 import org.opendaylight.netvirt.elan.utils.ElanClusterUtils;
16 import org.opendaylight.netvirt.elan.utils.ElanItmUtils;
17 import org.opendaylight.netvirt.elan.utils.ElanUtils;
18 import org.opendaylight.netvirt.elanmanager.utils.ElanL2GwCacheUtils;
19 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
22 import org.opendaylight.yangtools.yang.common.Uint64;
24 public class McastUpdateJob implements Callable<List<? extends ListenableFuture<?>>> {
25 private String elanName;
26 private String nodeId;
27 private ElanL2GatewayMulticastUtils mcastUtils;
28 private ElanClusterUtils elanClusterUtils;
30 protected String jobKey;
31 private IpAddress removedDstTep;
32 private boolean dpnOrConnectionRemoved;
34 public McastUpdateJob(String elanName,
37 ElanL2GatewayMulticastUtils mcastUtils,
38 ElanClusterUtils elanClusterUtils) {
39 this.jobKey = ElanUtils.getBcGroupUpdateKey(elanName);
40 this.elanName = elanName;
42 this.mcastUtils = mcastUtils;
44 this.elanClusterUtils = elanClusterUtils;
47 public void submit() {
48 elanClusterUtils.runOnlyInOwnerNode(this.jobKey, "Mcast Update job",this);
52 public List<ListenableFuture<?>> call() throws Exception {
53 L2GatewayDevice device = ElanL2GwCacheUtils.getL2GatewayDeviceFromCache(elanName, nodeId);
54 ListenableFuture<?> ft = null;
55 //TODO: make prepareRemoteMcastMacUpdateOnDevice return a ListenableFuture<Void>
57 ft = mcastUtils.prepareRemoteMcastMacUpdateOnDevice(elanName, device, !dpnOrConnectionRemoved ,
60 ft = mcastUtils.deleteRemoteMcastMac(new NodeId(nodeId), elanName);
62 List<ListenableFuture<?>> fts = new ArrayList<>();
67 public static void updateAllMcasts(String elanName,
68 ElanL2GatewayMulticastUtils mcastUtils,
69 ElanClusterUtils elanClusterUtils) {
70 ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName).forEach(device -> {
71 new McastUpdateJob(elanName, device.getHwvtepNodeId(), true, mcastUtils,
72 elanClusterUtils).submit();
76 public static void removeMcastForNode(String elanName, String nodeId,
77 ElanL2GatewayMulticastUtils mcastUtils,
78 ElanClusterUtils elanClusterUtils) {
79 new McastUpdateJob(elanName, nodeId, false, mcastUtils,
80 elanClusterUtils).submit();
83 public static void updateMcastForNode(String elanName, String nodeId,
84 ElanL2GatewayMulticastUtils mcastUtils,
85 ElanClusterUtils elanClusterUtils) {
86 new McastUpdateJob(elanName, nodeId, true, mcastUtils,
87 elanClusterUtils).submit();
90 private McastUpdateJob setRemovedDstTep(IpAddress removedDstTep) {
91 this.removedDstTep = removedDstTep;
95 private McastUpdateJob setDpnOrconnectionRemoved() {
96 this.dpnOrConnectionRemoved = true;
100 public static void updateAllMcastsForConnectionAdd(String elanName,
101 ElanL2GatewayMulticastUtils mcastUtils,
102 ElanClusterUtils elanClusterUtils) {
103 ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName).forEach(device -> {
104 new McastUpdateJob(elanName, device.getHwvtepNodeId(), true , mcastUtils, elanClusterUtils).submit();
108 public static void updateAllMcastsForConnectionDelete(String elanName,
109 ElanL2GatewayMulticastUtils mcastUtils,
110 ElanClusterUtils elanClusterUtils,
111 L2GatewayDevice deletedDevice) {
112 ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName).forEach(device -> {
113 IpAddress deletedTep = deletedDevice.getTunnelIp();
114 new McastUpdateJob(elanName, device.getHwvtepNodeId(), true , mcastUtils, elanClusterUtils)
115 .setDpnOrconnectionRemoved()
116 .setRemovedDstTep(deletedTep)
121 public static void updateAllMcastsForDpnAdd(String elanName,
122 ElanL2GatewayMulticastUtils mcastUtils,
123 ElanClusterUtils elanClusterUtils) {
124 ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName).forEach(device -> {
125 new McastUpdateJob(elanName, device.getHwvtepNodeId(), true , mcastUtils, elanClusterUtils).submit();
129 public static void updateAllMcastsForDpnDelete(String elanName,
130 ElanL2GatewayMulticastUtils mcastUtils,
131 ElanClusterUtils elanClusterUtils,
133 ElanItmUtils elanItmUtils) {
134 ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName).forEach(device -> {
135 IpAddress deletedTep = elanItmUtils.getSourceDpnTepIp(srcDpnId, new NodeId(device.getHwvtepNodeId()));
136 new McastUpdateJob(elanName, device.getHwvtepNodeId(), true , mcastUtils, elanClusterUtils)
137 .setDpnOrconnectionRemoved()
138 .setRemovedDstTep(deletedTep)