2 * Copyright (c) 2016 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
9 package org.opendaylight.netvirt.elan.l2gw.jobs;
11 import com.google.common.util.concurrent.FutureCallback;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import java.util.ArrayList;
15 import java.util.List;
16 import java.util.concurrent.Callable;
17 import java.util.concurrent.ConcurrentMap;
18 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
19 import org.opendaylight.genius.utils.hwvtep.HwvtepUtils;
20 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
21 import org.opendaylight.netvirt.elanmanager.utils.ElanL2GwCacheUtils;
22 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * The Job class to delete L2 gateway device local ucast macs from other Elan L2
32 public class DeleteL2GwDeviceMacsFromElanJob implements Callable<List<ListenableFuture<Void>>> {
34 /** The Constant JOB_KEY_PREFIX. */
35 private static final String JOB_KEY_PREFIX = "hwvtep:";
37 /** The Constant LOG. */
38 private static final Logger LOG = LoggerFactory.getLogger(DeleteL2GwDeviceMacsFromElanJob.class);
41 private final DataBroker broker;
44 private final String elanName;
46 /** The l2 gw device. */
47 private final L2GatewayDevice l2GwDevice;
49 /** The mac addresses. */
50 private final List<MacAddress> macAddresses;
53 * Instantiates a new delete l2 gw device macs from elan job.
64 public DeleteL2GwDeviceMacsFromElanJob(DataBroker broker, String elanName, L2GatewayDevice l2GwDevice,
65 List<MacAddress> macAddresses) {
67 this.elanName = elanName;
68 this.l2GwDevice = l2GwDevice;
69 this.macAddresses = macAddresses;
77 public String getJobKey() {
78 String jobKey = JOB_KEY_PREFIX + this.elanName;
79 if (macAddresses != null && macAddresses.size() == 1) {
80 jobKey += ":" + macAddresses.get(0).getValue();
88 * @see java.util.concurrent.Callable#call()
91 public List<ListenableFuture<Void>> call() {
92 LOG.debug("Deleting l2gw device [{}] macs from other l2gw devices for elan [{}]",
93 this.l2GwDevice.getHwvtepNodeId(), this.elanName);
94 final String logicalSwitchName = ElanL2GatewayUtils.getLogicalSwitchFromElan(this.elanName);
96 ConcurrentMap<String, L2GatewayDevice> elanL2GwDevices = ElanL2GwCacheUtils
97 .getInvolvedL2GwDevices(this.elanName);
98 List<ListenableFuture<Void>> futures = new ArrayList<>();
99 for (L2GatewayDevice otherDevice : elanL2GwDevices.values()) {
100 if (!otherDevice.getHwvtepNodeId().equals(this.l2GwDevice.getHwvtepNodeId())
101 && !ElanL2GatewayUtils.areMLAGDevices(this.l2GwDevice, otherDevice)) {
102 final String hwvtepId = otherDevice.getHwvtepNodeId();
103 // never batch deletes
104 ListenableFuture<Void> uninstallFuture = HwvtepUtils.deleteRemoteUcastMacs(this.broker,
105 new NodeId(hwvtepId), logicalSwitchName, this.macAddresses);
106 Futures.addCallback(uninstallFuture, new FutureCallback<Void>() {
108 public void onSuccess(Void noarg) {
109 LOG.trace("Successful in initiating ucast_remote_macs deletion related to {} in {}",
110 logicalSwitchName, hwvtepId);
114 public void onFailure(Throwable error) {
115 LOG.error(String.format("Failed removing ucast_remote_macs related to %s in %s",
116 logicalSwitchName, hwvtepId), error);
119 futures.add(uninstallFuture);