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.Collection;
13 import java.util.List;
14 import java.util.Locale;
15 import java.util.concurrent.Callable;
16 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
17 import org.opendaylight.netvirt.elan.l2gw.utils.ElanRefUtil;
18 import org.opendaylight.netvirt.elan.utils.ElanDmacUtils;
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.yang.types.rev130715.MacAddress;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.elan.dpn.interfaces.list.DpnInterfaces;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 public class DpnDmacJob implements Callable<List<? extends ListenableFuture<?>>> {
29 private static final Logger LOG = LoggerFactory.getLogger(DpnDmacJob.class);
31 private String elanName;
32 private DpnInterfaces dpnInterfaces;
33 private ElanL2GatewayUtils elanL2GatewayUtils;
34 private ElanDmacUtils elanDmacUtils;
35 private final ElanRefUtil elanRefUtil;
36 private String nodeId;
37 private boolean added;
38 protected String jobKey;
40 public DpnDmacJob(String elanName,
41 DpnInterfaces dpnInterfaces,
44 ElanL2GatewayUtils elanL2GatewayUtils, ElanRefUtil elanRefUtil,
45 ElanDmacUtils elanDmacUtils) {
46 this.jobKey = ElanUtils.getBcGroupUpdateKey(elanName);
47 this.elanName = elanName;
48 this.dpnInterfaces = dpnInterfaces;
50 this.elanL2GatewayUtils = elanL2GatewayUtils;
51 this.elanRefUtil = elanRefUtil;
52 this.elanDmacUtils = elanDmacUtils;
56 public void submit() {
57 elanRefUtil.getElanClusterUtils().runOnlyInOwnerNode(this.jobKey,"Dpn Dmac Job", this);
61 public List<ListenableFuture<Void>> call() throws Exception {
62 ElanInstance elan = elanRefUtil.getElanInstanceCache().get(elanName).orElse(null);
64 LOG.error("failed.elan.not.found.{}", jobKey);
67 List<ListenableFuture<Void>> result = new ArrayList<>();
68 L2GatewayDevice device = ElanL2GwCacheUtils.getL2GatewayDeviceFromCache(elanName, nodeId);
70 result.addAll(elanL2GatewayUtils.installDmacFlowsOnDpn(dpnInterfaces.getDpId(), device, elan,
71 dpnInterfaces.getInterfaces().get(0)));
73 Collection<MacAddress> localMacs = elanL2GatewayUtils.getL2GwDeviceLocalMacs(
74 elan.getElanInstanceName(), device);
75 if (localMacs != null && !localMacs.isEmpty()) {
76 for (MacAddress mac : localMacs) {
77 result.addAll(elanDmacUtils.deleteDmacFlowsToExternalMac(elan.getElanTag().toJava(),
78 dpnInterfaces.getDpId(), nodeId, mac.getValue().toLowerCase(Locale.getDefault())));
85 public static void uninstallDmacFromL2gws(String elanName,
86 DpnInterfaces dpnInterfaces,
87 ElanL2GatewayUtils elanL2GatewayUtils,
88 ElanRefUtil elanRefUtil,
89 ElanDmacUtils elanDmacUtils) {
90 ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName).forEach(l2GatewayDevice -> {
91 new DpnDmacJob(elanName, dpnInterfaces, l2GatewayDevice.getHwvtepNodeId(), false, elanL2GatewayUtils,
92 elanRefUtil, elanDmacUtils).submit();
96 public static void installDmacFromL2gws(String elanName,
97 DpnInterfaces dpnInterfaces,
98 ElanL2GatewayUtils elanL2GatewayUtils,
99 ElanRefUtil elanRefUtil,
100 ElanDmacUtils elanDmacUtils) {
101 ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName).forEach(l2GatewayDevice -> {
102 new DpnDmacJob(elanName, dpnInterfaces, l2GatewayDevice.getHwvtepNodeId(), true, elanL2GatewayUtils,
103 elanRefUtil, elanDmacUtils).submit();