Bulk merge of l2gw changes
[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.netvirt.elan.l2gw.utils.ElanL2GatewayBcGroupUtils;
15 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
16 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
17 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 /**
24  * The Class LogicalSwitchAddedWorker.
25  */
26 public class LogicalSwitchAddedJob implements Callable<List<? extends ListenableFuture<?>>> {
27     private static final Logger LOG = LoggerFactory.getLogger(LogicalSwitchAddedJob.class);
28
29     /** The logical switch name. */
30     private final String logicalSwitchName;
31
32     /** The physical device. */
33     private final Devices physicalDevice;
34
35     /** The l2 gateway device. */
36     private final L2GatewayDevice elanL2GwDevice;
37
38     /** The default vlan id. */
39     private Integer defaultVlanId;
40
41     private final ElanL2GatewayUtils elanL2GatewayUtils;
42     private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
43     private final ElanL2GatewayBcGroupUtils elanL2GatewayBcGroupUtils;
44
45     public LogicalSwitchAddedJob(ElanL2GatewayUtils elanL2GatewayUtils,
46                                  ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils,
47                                  ElanL2GatewayBcGroupUtils elanL2GatewayBcGroupUtils,
48                                  String logicalSwitchName, Devices physicalDevice,
49                                  L2GatewayDevice l2GatewayDevice, Integer defaultVlanId) {
50         this.elanL2GatewayUtils = elanL2GatewayUtils;
51         this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
52         this.elanL2GatewayBcGroupUtils = elanL2GatewayBcGroupUtils;
53         this.logicalSwitchName = logicalSwitchName;
54         this.physicalDevice = physicalDevice;
55         this.elanL2GwDevice = l2GatewayDevice;
56         this.defaultVlanId = defaultVlanId;
57         LOG.debug("created logical switch added job for {} {}", logicalSwitchName, elanL2GwDevice.getHwvtepNodeId());
58     }
59
60     public String getJobKey() {
61 //        return logicalSwitchName + HwvtepHAUtil.L2GW_JOB_KEY;
62         return logicalSwitchName + ":" + elanL2GwDevice.getHwvtepNodeId();
63     }
64
65     @Override
66     public List<ListenableFuture<?>> call() throws Exception {
67         elanL2GatewayUtils.cancelDeleteLogicalSwitch(new NodeId(elanL2GwDevice.getHwvtepNodeId()), logicalSwitchName);
68         LOG.info("LogicalSwitchAddedJob Running logical switch added job for {} {}", logicalSwitchName,
69                 elanL2GwDevice.getHwvtepNodeId());
70         List<ListenableFuture<?>> futures = new ArrayList<>();
71         ListenableFuture<?> ft = null;
72         //String elan = elanL2GatewayUtils.getElanFromLogicalSwitch(logicalSwitchName);
73
74         LOG.trace("LogicalSwitchAddedJob Creating vlan bindings for {} {}",
75                 logicalSwitchName, elanL2GwDevice.getHwvtepNodeId());
76         ft = elanL2GatewayUtils.updateVlanBindingsInL2GatewayDevice(
77                 new NodeId(elanL2GwDevice.getHwvtepNodeId()), logicalSwitchName, physicalDevice, defaultVlanId);
78         futures.add(ft);
79         //logResultMsg(ft);
80         LOG.trace("LogicalSwitchAddedJob Creating mast mac entries and bc group for {} {}",
81                 logicalSwitchName, elanL2GwDevice.getHwvtepNodeId());
82         elanL2GatewayBcGroupUtils.updateBcGroupForAllDpns(logicalSwitchName, elanL2GwDevice, true);
83         elanL2GatewayMulticastUtils.updateMcastMacsForAllElanDevices(logicalSwitchName, elanL2GwDevice, true);
84         futures.add(elanL2GatewayUtils.installElanMacsInL2GatewayDevice(
85                 logicalSwitchName, elanL2GwDevice));
86         return futures;
87     }
88
89     /*private void logResultMsg(ListenableFuture<Void> ft) {
90         String portName = null;
91         if (physicalDevice.getInterfaces() != null && !physicalDevice.getInterfaces().isEmpty()) {
92             portName = physicalDevice.getInterfaces().get(0).getInterfaceName();
93             if (physicalDevice.getInterfaces().get(0).getSegmentationIds() != null
94                     && !physicalDevice.getInterfaces().get(0).getSegmentationIds().isEmpty()) {
95                 defaultVlanId = physicalDevice.getInterfaces().get(0).getSegmentationIds().get(0);
96             }
97         }
98         if (portName != null && defaultVlanId != null) {
99             new FtCallback(ft, "Added vlan bindings {} logical switch {} to node {}",
100                     portName + ":" + defaultVlanId, logicalSwitchName, elanL2GwDevice.getHwvtepNodeId());
101         }
102     }*/
103
104 }