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.Collection;
14 import java.util.List;
15 import java.util.Locale;
16 import java.util.concurrent.Callable;
18 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
19 import org.opendaylight.netvirt.elan.l2gw.utils.ElanRefUtil;
20 import org.opendaylight.netvirt.elan.utils.ElanDmacUtils;
21 import org.opendaylight.netvirt.elan.utils.ElanUtils;
22 import org.opendaylight.netvirt.elanmanager.utils.ElanL2GwCacheUtils;
23 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
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;
30 public class DpnDmacJob implements Callable<List<? extends ListenableFuture<?>>> {
31 private static final Logger LOG = LoggerFactory.getLogger(DpnDmacJob.class);
33 private String elanName;
34 private DpnInterfaces dpnInterfaces;
35 private ElanL2GatewayUtils elanL2GatewayUtils;
36 private ElanDmacUtils elanDmacUtils;
37 private final ElanRefUtil elanRefUtil;
38 private String nodeId;
39 private boolean added;
40 protected String jobKey;
42 public DpnDmacJob(String elanName,
43 DpnInterfaces dpnInterfaces,
46 ElanL2GatewayUtils elanL2GatewayUtils, ElanRefUtil elanRefUtil,
47 ElanDmacUtils elanDmacUtils) {
48 this.jobKey = ElanUtils.getBcGroupUpdateKey(elanName);
49 this.elanName = elanName;
50 this.dpnInterfaces = dpnInterfaces;
52 this.elanL2GatewayUtils = elanL2GatewayUtils;
53 this.elanRefUtil = elanRefUtil;
54 this.elanDmacUtils = elanDmacUtils;
58 public void submit() {
59 elanRefUtil.getElanClusterUtils().runOnlyInOwnerNode(this.jobKey,"Dpn Dmac Job", this);
63 public List<ListenableFuture<Void>> call() throws Exception {
64 ElanInstance elan = elanRefUtil.getElanInstanceCache().get(elanName).orElse(null);
66 LOG.error("failed.elan.not.found.{}", jobKey);
69 List<ListenableFuture<Void>> result = new ArrayList<>();
70 L2GatewayDevice device = ElanL2GwCacheUtils.getL2GatewayDeviceFromCache(elanName, nodeId);
72 result.addAll(elanL2GatewayUtils.installDmacFlowsOnDpn(dpnInterfaces.getDpId(), device, elan,
73 dpnInterfaces.getInterfaces().get(0)));
75 Collection<MacAddress> localMacs = elanL2GatewayUtils.getL2GwDeviceLocalMacs(
76 elan.getElanInstanceName(), device);
77 if (localMacs != null && !localMacs.isEmpty()) {
78 for (MacAddress mac : localMacs) {
79 result.addAll(elanDmacUtils.deleteDmacFlowsToExternalMac(elan.getElanTag().toJava(),
80 dpnInterfaces.getDpId(), nodeId, mac.getValue().toLowerCase(Locale.getDefault())));
87 public static void uninstallDmacFromL2gws(String elanName,
88 DpnInterfaces dpnInterfaces,
89 ElanL2GatewayUtils elanL2GatewayUtils,
90 ElanRefUtil elanRefUtil,
91 ElanDmacUtils elanDmacUtils) {
92 ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName).forEach(l2GatewayDevice -> {
93 new DpnDmacJob(elanName, dpnInterfaces, l2GatewayDevice.getHwvtepNodeId(), false, elanL2GatewayUtils,
94 elanRefUtil, elanDmacUtils).submit();
98 public static void installDmacFromL2gws(String elanName,
99 DpnInterfaces dpnInterfaces,
100 ElanL2GatewayUtils elanL2GatewayUtils,
101 ElanRefUtil elanRefUtil,
102 ElanDmacUtils elanDmacUtils) {
103 ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName).forEach(l2GatewayDevice -> {
104 new DpnDmacJob(elanName, dpnInterfaces, l2GatewayDevice.getHwvtepNodeId(), true, elanL2GatewayUtils,
105 elanRefUtil, elanDmacUtils).submit();