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.vpnservice.elan.l2gw.jobs;
10 import com.google.common.util.concurrent.ListenableFuture;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.vpnservice.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
13 import org.opendaylight.vpnservice.elan.l2gw.utils.ElanL2GatewayUtils;
14 import org.opendaylight.vpnservice.neutronvpn.api.l2gw.L2GatewayDevice;
15 import org.opendaylight.vpnservice.utils.hwvtep.HwvtepUtils;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.elan.instances.ElanInstance;
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.concurrent.Callable;
27 * Created by ekvsver on 4/15/2016.
29 public class DisAssociateHwvtepFromElanJob implements Callable<List<ListenableFuture<Void>>> {
31 L2GatewayDevice l2GatewayDevice;
32 ElanInstance elanInstance;
35 boolean isLastL2GwConnDeleted;
37 private static final Logger LOG = LoggerFactory.getLogger(DisAssociateHwvtepFromElanJob.class);
39 public DisAssociateHwvtepFromElanJob(DataBroker broker, L2GatewayDevice l2GatewayDevice, ElanInstance elanInstance,
40 Devices l2Device, Integer defaultVlan, boolean isLastL2GwConnDeleted) {
42 this.l2GatewayDevice = l2GatewayDevice;
43 this.elanInstance = elanInstance;
44 this.l2Device = l2Device;
45 this.defaultVlan = defaultVlan;
46 this.isLastL2GwConnDeleted = isLastL2GwConnDeleted;
47 LOG.info("created disassosiate l2gw connection job for {} {}", elanInstance.getElanInstanceName(),
48 l2GatewayDevice.getHwvtepNodeId());
51 public String getJobKey() {
52 return elanInstance.getElanInstanceName();
56 public List<ListenableFuture<Void>> call() throws Exception {
57 String elanName = elanInstance.getElanInstanceName();
58 String strHwvtepNodeId = l2GatewayDevice.getHwvtepNodeId();
59 NodeId hwvtepNodeId = new NodeId(strHwvtepNodeId);
60 LOG.info("running disassosiate l2gw connection job for {} {}", elanName, strHwvtepNodeId);
62 List<ListenableFuture<Void>> futures = new ArrayList<>();
64 // Remove remote MACs and vlan mappings from physical port
65 // Once all above configurations are deleted, delete logical
67 LOG.info("delete vlan bindings for {} {}", elanName, strHwvtepNodeId);
68 futures.add(ElanL2GatewayUtils.deleteVlanBindingsFromL2GatewayDevice(hwvtepNodeId, l2Device, defaultVlan));
70 if (isLastL2GwConnDeleted) {
71 LOG.info("delete remote ucast macs {} {}", elanName, strHwvtepNodeId);
72 futures.add(ElanL2GatewayUtils.deleteElanMacsFromL2GatewayDevice(l2GatewayDevice, elanName));
74 LOG.info("delete mcast mac for {} {}", elanName, strHwvtepNodeId);
75 futures.addAll(ElanL2GatewayMulticastUtils.handleMcastForElanL2GwDeviceDelete(elanInstance,
78 LOG.info("delete local ucast macs {} {}", elanName, strHwvtepNodeId);
79 futures.addAll(ElanL2GatewayUtils.deleteL2GwDeviceUcastLocalMacsFromElan(l2GatewayDevice, elanName));
81 LOG.info("scheduled delete logical switch {} {}", elanName, strHwvtepNodeId);
82 ElanL2GatewayUtils.scheduleDeleteLogicalSwitch(hwvtepNodeId,
83 ElanL2GatewayUtils.getLogicalSwitchFromElan(elanName));