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;
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.concurrent.Callable;
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
16 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
17 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
18 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * Created by ekvsver on 4/15/2016.
27 public class DisAssociateHwvtepFromElanJob implements Callable<List<ListenableFuture<Void>>> {
28 private static final Logger LOG = LoggerFactory.getLogger(DisAssociateHwvtepFromElanJob.class);
30 private final ElanL2GatewayUtils elanL2GatewayUtils;
31 private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
32 private final L2GatewayDevice l2GatewayDevice;
33 private final String elanName;
34 private final Devices l2Device;
35 private final Integer defaultVlan;
36 private final boolean isLastL2GwConnDeleted;
37 private final NodeId hwvtepNodeId;
39 public DisAssociateHwvtepFromElanJob(ElanL2GatewayUtils elanL2GatewayUtils,
40 ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils,
41 @Nullable L2GatewayDevice l2GatewayDevice, String elanName,
43 Integer defaultVlan, String nodeId, boolean isLastL2GwConnDeleted) {
44 this.elanL2GatewayUtils = elanL2GatewayUtils;
45 this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
46 this.l2GatewayDevice = l2GatewayDevice;
47 this.elanName = elanName;
48 this.l2Device = l2Device;
49 this.defaultVlan = defaultVlan;
50 this.isLastL2GwConnDeleted = isLastL2GwConnDeleted;
51 this.hwvtepNodeId = new NodeId(nodeId);
52 LOG.info("created disassociate l2gw connection job for {}", elanName);
55 public String getJobKey() {
56 return elanName + HwvtepHAUtil.L2GW_JOB_KEY;
60 public List<ListenableFuture<Void>> call() {
61 String strHwvtepNodeId = hwvtepNodeId.getValue();
62 LOG.info("running disassosiate l2gw connection job for {} {}", elanName, strHwvtepNodeId);
64 List<ListenableFuture<Void>> futures = new ArrayList<>();
66 // Remove remote MACs and vlan mappings from physical port
67 // Once all above configurations are deleted, delete logical
69 LOG.info("delete vlan bindings for {} {}", elanName, strHwvtepNodeId);
70 futures.add(elanL2GatewayUtils.deleteVlanBindingsFromL2GatewayDevice(hwvtepNodeId, l2Device, defaultVlan));
72 if (isLastL2GwConnDeleted) {
73 if (l2GatewayDevice == null) {
74 LOG.info("Scheduled delete logical switch {} {}", elanName, strHwvtepNodeId);
75 elanL2GatewayUtils.scheduleDeleteLogicalSwitch(hwvtepNodeId,
76 ElanL2GatewayUtils.getLogicalSwitchFromElan(elanName));
79 LOG.info("delete remote ucast macs {} {}", elanName, strHwvtepNodeId);
80 futures.add(elanL2GatewayUtils.deleteElanMacsFromL2GatewayDevice(hwvtepNodeId.getValue(), elanName));
82 LOG.info("delete mcast mac for {} {}", elanName, strHwvtepNodeId);
83 futures.addAll(elanL2GatewayMulticastUtils.handleMcastForElanL2GwDeviceDelete(this.elanName,
86 LOG.info("delete local ucast macs {} {}", elanName, strHwvtepNodeId);
87 elanL2GatewayUtils.deleteL2GwDeviceUcastLocalMacsFromElan(l2GatewayDevice, elanName);
89 LOG.info("scheduled delete logical switch {} {}", elanName, strHwvtepNodeId);
90 elanL2GatewayUtils.scheduleDeleteLogicalSwitch(hwvtepNodeId,
91 ElanL2GatewayUtils.getLogicalSwitchFromElan(elanName));
93 LOG.info("l2gw mcast delete not triggered for nodeId {} with elan {}",
94 l2GatewayDevice != null ? l2GatewayDevice.getHwvtepNodeId() : null, elanName);