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