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.vpnservice.elan.l2gw.jobs;
11 import java.util.List;
12 import java.util.concurrent.Callable;
13 import java.util.concurrent.ConcurrentMap;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.elanmanager.utils.ElanL2GwCacheUtils;
17 import org.opendaylight.vpnservice.elan.l2gw.utils.ElanL2GatewayUtils;
18 import org.opendaylight.vpnservice.neutronvpn.api.l2gw.L2GatewayDevice;
19 import org.opendaylight.vpnservice.utils.hwvtep.HwvtepUtils;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 import com.google.common.collect.Lists;
26 import com.google.common.util.concurrent.FutureCallback;
27 import com.google.common.util.concurrent.Futures;
28 import com.google.common.util.concurrent.ListenableFuture;
31 * The Job class to delete L2 gateway device local ucast macs from other Elan L2
34 public class DeleteL2GwDeviceMacsFromElanJob implements Callable<List<ListenableFuture<Void>>> {
36 /** The Constant JOB_KEY_PREFIX. */
37 private static final String JOB_KEY_PREFIX = "hwvtep:";
39 /** The Constant LOG. */
40 private static final Logger LOG = LoggerFactory.getLogger(DeleteL2GwDeviceMacsFromElanJob.class);
43 private final DataBroker broker;
46 private final String elanName;
48 /** The l2 gw device. */
49 private final L2GatewayDevice l2GwDevice;
51 /** The mac addresses. */
52 private final List<MacAddress> macAddresses;
55 * Instantiates a new delete l2 gw device macs from elan job.
66 public DeleteL2GwDeviceMacsFromElanJob(DataBroker broker, String elanName, L2GatewayDevice l2GwDevice,
67 List<MacAddress> macAddresses) {
69 this.elanName = elanName;
70 this.l2GwDevice = l2GwDevice;
71 this.macAddresses = macAddresses;
74 public String getJobKey() {
75 return JOB_KEY_PREFIX + this.elanName;
81 * @see java.util.concurrent.Callable#call()
84 public List<ListenableFuture<Void>> call() {
85 LOG.debug("Deleting l2gw device [{}] macs from other l2gw devices for elan [{}]",
86 this.l2GwDevice.getHwvtepNodeId(), this.elanName);
87 final String logicalSwitchName = ElanL2GatewayUtils.getLogicalSwitchFromElan(this.elanName);
89 ConcurrentMap<String, L2GatewayDevice> elanL2GwDevices = ElanL2GwCacheUtils
90 .getInvolvedL2GwDevices(this.elanName);
91 List<ListenableFuture<Void>> futures = Lists.newArrayList();
92 for (L2GatewayDevice otherDevice : elanL2GwDevices.values()) {
93 if (!otherDevice.getHwvtepNodeId().equals(this.l2GwDevice.getHwvtepNodeId())
94 && !ElanL2GatewayUtils.areMLAGDevices(this.l2GwDevice, otherDevice)) {
95 final String hwvtepId = otherDevice.getHwvtepNodeId();
96 // never batch deletes
97 ListenableFuture<Void> uninstallFuture = HwvtepUtils.deleteRemoteUcastMacs(this.broker,
98 new NodeId(hwvtepId), logicalSwitchName, this.macAddresses);
99 Futures.addCallback(uninstallFuture, new FutureCallback<Void>() {
101 public void onSuccess(Void noarg) {
102 LOG.trace("Successful in initiating ucast_remote_macs deletion related to {} in {}",
103 logicalSwitchName, hwvtepId);
107 public void onFailure(Throwable error) {
108 LOG.error(String.format("Failed removing ucast_remote_macs related to %s in %s",
109 logicalSwitchName, hwvtepId), error);
112 // TODO: why to create a new arraylist for uninstallFuture?
113 futures.addAll(Lists.newArrayList(uninstallFuture));