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
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.Collections;
14 import java.util.List;
15 import java.util.concurrent.Callable;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
18 import org.opendaylight.genius.utils.hwvtep.HwvtepUtils;
19 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
20 import org.opendaylight.netvirt.elan.utils.ElanConstants;
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.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepLogicalSwitchRef;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacsKey;
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * The Class DeleteLogicalSwitchJob.
35 public class DeleteLogicalSwitchJob implements Callable<List<ListenableFuture<Void>>> {
36 private DataBroker broker;
38 /** The logical switch name. */
39 private String logicalSwitchName;
41 /** The physical device. */
42 private NodeId hwvtepNodeId;
44 private final ElanL2GatewayUtils elanL2GatewayUtils;
45 private final boolean clearUcast;
46 private volatile boolean cancelled = false;
48 private static final Logger LOG = LoggerFactory.getLogger(DeleteLogicalSwitchJob.class);
50 public DeleteLogicalSwitchJob(DataBroker broker, ElanL2GatewayUtils elanL2GatewayUtils,
51 NodeId hwvtepNodeId, String logicalSwitchName, boolean clearUcast) {
53 this.hwvtepNodeId = hwvtepNodeId;
54 this.logicalSwitchName = logicalSwitchName;
55 this.elanL2GatewayUtils = elanL2GatewayUtils;
56 this.clearUcast = clearUcast;
57 LOG.debug("created logical switch deleted job for {} on {}", logicalSwitchName, hwvtepNodeId);
60 public void cancel() {
61 this.cancelled = true;
64 public String getJobKey() {
65 return logicalSwitchName;
69 public List<ListenableFuture<Void>> call() throws Exception {
71 LOG.info("Delete logical switch job cancelled ");
72 return Collections.emptyList();
74 LOG.debug("running logical switch deleted job for {} in {}", logicalSwitchName, hwvtepNodeId);
75 elanL2GatewayUtils.deleteElanMacsFromL2GatewayDevice(hwvtepNodeId.getValue(), logicalSwitchName);
76 InstanceIdentifier<LogicalSwitches> logicalSwitch = HwvtepSouthboundUtils
77 .createLogicalSwitchesInstanceIdentifier(hwvtepNodeId, new HwvtepNodeName(logicalSwitchName));
78 RemoteMcastMacsKey remoteMcastMacsKey = new RemoteMcastMacsKey(new HwvtepLogicalSwitchRef(logicalSwitch),
79 new MacAddress(ElanConstants.UNKNOWN_DMAC));
80 HwvtepUtils.deleteRemoteMcastMac(broker, hwvtepNodeId, remoteMcastMacsKey);
82 L2GatewayDevice l2GatewayDevice = new L2GatewayDevice("");
83 l2GatewayDevice.setHwvtepNodeId(hwvtepNodeId.getValue());
85 List<ListenableFuture<Void>> futures = new ArrayList<>();
86 futures.add(HwvtepUtils.deleteLogicalSwitch(broker, hwvtepNodeId, logicalSwitchName));
88 LOG.trace("Clearing the local ucast macs of device {} macs ", hwvtepNodeId.getValue());
90 elanL2GatewayUtils.deleteL2GwDeviceUcastLocalMacsFromElan(l2GatewayDevice, logicalSwitchName));