MRI version bumpup for Aluminium
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / l2gw / jobs / LogicalSwitchAddedJob.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.netvirt.elan.l2gw.jobs;
9
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.opendaylight.mdsal.binding.api.DataBroker;
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.elan.l2gw.utils.ElanRefUtil;
19 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 /**
26  * The Class LogicalSwitchAddedWorker.
27  */
28 public class LogicalSwitchAddedJob implements Callable<List<? extends ListenableFuture<?>>> {
29     private static final Logger LOG = LoggerFactory.getLogger(LogicalSwitchAddedJob.class);
30
31     /** The logical switch name. */
32     private final String logicalSwitchName;
33
34     /** The physical device. */
35     private final Devices physicalDevice;
36
37     /** The l2 gateway device. */
38     private final L2GatewayDevice elanL2GwDevice;
39
40     /** The default vlan id. */
41     private final Integer defaultVlanId;
42
43     private final ElanL2GatewayUtils elanL2GatewayUtils;
44     private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
45     private final ElanRefUtil elanRefUtil;
46     private final DataBroker dataBroker;
47
48     public LogicalSwitchAddedJob(ElanL2GatewayUtils elanL2GatewayUtils,
49                                  ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils, String logicalSwitchName,
50                                  Devices physicalDevice, L2GatewayDevice l2GatewayDevice, Integer defaultVlanId,
51                                  ElanRefUtil elanRefUtil, DataBroker dataBroker) {
52         this.elanL2GatewayUtils = elanL2GatewayUtils;
53         this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
54         this.logicalSwitchName = logicalSwitchName;
55         this.physicalDevice = physicalDevice;
56         this.elanL2GwDevice = l2GatewayDevice;
57         this.defaultVlanId = defaultVlanId;
58         this.elanRefUtil = elanRefUtil;
59         this.dataBroker = dataBroker;
60         LOG.debug("created logical switch added job for {} {}", logicalSwitchName, elanL2GwDevice.getHwvtepNodeId());
61     }
62
63     public String getJobKey() {
64         return logicalSwitchName + HwvtepHAUtil.L2GW_JOB_KEY;
65     }
66
67     @Override
68     public List<ListenableFuture<?>> call() {
69         elanL2GatewayUtils.cancelDeleteLogicalSwitch(new NodeId(elanL2GwDevice.getHwvtepNodeId()), logicalSwitchName);
70         LOG.debug("running logical switch added job for {} {}", logicalSwitchName,
71                 elanL2GwDevice.getHwvtepNodeId());
72         List<ListenableFuture<?>> futures = new ArrayList<>();
73
74         LOG.info("creating vlan bindings for {} {}", logicalSwitchName, elanL2GwDevice.getHwvtepNodeId());
75         futures.add(elanL2GatewayUtils.updateVlanBindingsInL2GatewayDevice(
76             new NodeId(elanL2GwDevice.getHwvtepNodeId()), logicalSwitchName, physicalDevice, defaultVlanId));
77         LOG.info("creating mast mac entries for {} {}", logicalSwitchName, elanL2GwDevice.getHwvtepNodeId());
78         elanL2GatewayMulticastUtils.handleMcastForElanL2GwDeviceAdd(logicalSwitchName, elanL2GwDevice);
79         futures.add(elanL2GatewayUtils.installElanMacsInL2GatewayDevice(
80                 logicalSwitchName, elanL2GwDevice));
81         return futures;
82     }
83
84 }