Imported vpnservice as a subtree
[netvirt.git] / vpnservice / elanmanager / elanmanager-impl / src / main / java / org / opendaylight / vpnservice / elan / l2gw / jobs / DisAssociateHwvtepFromElanJob.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.vpnservice.elan.l2gw.jobs;
9
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;
21
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.concurrent.Callable;
25
26 /**
27 * Created by ekvsver on 4/15/2016.
28 */
29 public class DisAssociateHwvtepFromElanJob implements Callable<List<ListenableFuture<Void>>> {
30     DataBroker broker;
31     L2GatewayDevice l2GatewayDevice;
32     ElanInstance elanInstance;
33     Devices l2Device;
34     Integer defaultVlan;
35     boolean isLastL2GwConnDeleted;
36
37     private static final Logger LOG = LoggerFactory.getLogger(DisAssociateHwvtepFromElanJob.class);
38
39     public DisAssociateHwvtepFromElanJob(DataBroker broker, L2GatewayDevice l2GatewayDevice, ElanInstance elanInstance,
40                                          Devices l2Device, Integer defaultVlan, boolean isLastL2GwConnDeleted) {
41         this.broker = broker;
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());
49     }
50
51     public String getJobKey() {
52         return elanInstance.getElanInstanceName();
53     }
54
55     @Override
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);
61
62         List<ListenableFuture<Void>> futures = new ArrayList<>();
63
64         // Remove remote MACs and vlan mappings from physical port
65         // Once all above configurations are deleted, delete logical
66         // switch
67         LOG.info("delete vlan bindings for {} {}", elanName, strHwvtepNodeId);
68         futures.add(ElanL2GatewayUtils.deleteVlanBindingsFromL2GatewayDevice(hwvtepNodeId, l2Device, defaultVlan));
69
70         if (isLastL2GwConnDeleted) {
71             LOG.info("delete remote ucast macs {} {}", elanName, strHwvtepNodeId);
72             futures.add(ElanL2GatewayUtils.deleteElanMacsFromL2GatewayDevice(l2GatewayDevice, elanName));
73
74             LOG.info("delete mcast mac for {} {}", elanName, strHwvtepNodeId);
75             futures.addAll(ElanL2GatewayMulticastUtils.handleMcastForElanL2GwDeviceDelete(elanInstance,
76                     l2GatewayDevice));
77
78             LOG.info("delete local ucast macs {} {}", elanName, strHwvtepNodeId);
79             futures.addAll(ElanL2GatewayUtils.deleteL2GwDeviceUcastLocalMacsFromElan(l2GatewayDevice, elanName));
80
81             LOG.info("scheduled delete logical switch {} {}", elanName, strHwvtepNodeId);
82             ElanL2GatewayUtils.scheduleDeleteLogicalSwitch(hwvtepNodeId,
83                     ElanL2GatewayUtils.getLogicalSwitchFromElan(elanName));
84         }
85
86         return futures;
87     }
88 }