7ad1c45dceaa4dab721402fb06a8626f1db23224
[vpnservice.git] / elanmanager / elanmanager-impl / src / main / java / org / opendaylight / vpnservice / 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.vpnservice.elan.l2gw.jobs;
9
10 import java.util.ArrayList;
11 import java.util.List;
12 import java.util.concurrent.Callable;
13
14 import org.opendaylight.vpnservice.elan.l2gw.listeners.HwvtepRemoteMcastMacListener;
15 import org.opendaylight.vpnservice.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
16 import org.opendaylight.vpnservice.elan.l2gw.utils.ElanL2GatewayUtils;
17 import org.opendaylight.vpnservice.elan.utils.ElanUtils;
18 import org.opendaylight.vpnservice.neutronvpn.api.l2gw.L2GatewayDevice;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
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 import com.google.common.collect.Lists;
26 import com.google.common.util.concurrent.ListenableFuture;
27
28 /**
29  * The Class LogicalSwitchAddedWorker.
30  */
31 public class LogicalSwitchAddedJob implements Callable<List<ListenableFuture<Void>>> {
32     /** The logical switch name. */
33     private String logicalSwitchName;
34
35     /** The physical device. */
36     private Devices physicalDevice;
37
38     /** The l2 gateway device. */
39     private L2GatewayDevice elanL2GwDevice;
40
41     /** The default vlan id. */
42     private Integer defaultVlanId;
43
44     private static final Logger LOG = LoggerFactory.getLogger(LogicalSwitchAddedJob.class);
45
46     public LogicalSwitchAddedJob(String logicalSwitchName, Devices physicalDevice, L2GatewayDevice l2GatewayDevice,
47             Integer defaultVlanId) {
48         this.logicalSwitchName = logicalSwitchName;
49         this.physicalDevice = physicalDevice;
50         this.elanL2GwDevice = l2GatewayDevice;
51         this.defaultVlanId = defaultVlanId;
52         LOG.debug("created logical switch added job for {} {}", logicalSwitchName, elanL2GwDevice.getHwvtepNodeId());
53     }
54
55     public String getJobKey() {
56         return logicalSwitchName;
57     }
58
59     /*
60      * (non-Javadoc)
61      *
62      * @see java.util.concurrent.Callable#call()
63      */
64     @Override
65     public List<ListenableFuture<Void>> call() throws Exception {
66         try {
67             LOG.debug("running logical switch added job for {} {}", logicalSwitchName, elanL2GwDevice.getHwvtepNodeId());
68             List<ListenableFuture<Void>> futures = new ArrayList<>();
69             String elan = ElanL2GatewayUtils.getElanFromLogicalSwitch(logicalSwitchName);
70
71             LOG.info("creating vlan bindings for {} {}", logicalSwitchName, elanL2GwDevice.getHwvtepNodeId());
72             futures.add(ElanL2GatewayUtils.updateVlanBindingsInL2GatewayDevice(
73                     new NodeId(elanL2GwDevice.getHwvtepNodeId()), logicalSwitchName, physicalDevice, defaultVlanId));
74             LOG.info("creating mast mac entries for {} {}", logicalSwitchName, elanL2GwDevice.getHwvtepNodeId());
75             futures.add(ElanL2GatewayMulticastUtils.handleMcastForElanL2GwDeviceAdd(logicalSwitchName, elanL2GwDevice));
76
77             List<IpAddress> expectedPhyLocatorIps = Lists.newArrayList();
78             HwvtepRemoteMcastMacListener list = new HwvtepRemoteMcastMacListener(ElanUtils.getDataBroker(),
79                     logicalSwitchName, elanL2GwDevice, expectedPhyLocatorIps,
80                     new Callable<List<ListenableFuture<Void>>>() {
81                         @Override
82                         public List<ListenableFuture<Void>> call() {
83                             LOG.info("adding remote ucast macs for {} {}", logicalSwitchName,
84                                     elanL2GwDevice.getHwvtepNodeId());
85                             List<ListenableFuture<Void>> futures = new ArrayList<>();
86                             futures.add(ElanL2GatewayUtils.installElanMacsInL2GatewayDevice(
87                                     logicalSwitchName, elanL2GwDevice));
88                             return futures;
89                         }
90                     });
91
92             return futures;
93         } catch (Throwable e) {
94             LOG.error("failed to add ls ", e);
95             return null;
96         }
97     }
98
99 }