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.netvirt.elan.l2gw.jobs;
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.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.netvirt.elan.l2gw.listeners.HwvtepRemoteMcastMacListener;
16 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
17 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
18 import org.opendaylight.netvirt.elan.utils.ElanUtils;
19 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * The Class LogicalSwitchAddedWorker.
29 public class LogicalSwitchAddedJob implements Callable<List<ListenableFuture<Void>>> {
30 /** The logical switch name. */
31 private String logicalSwitchName;
33 /** The physical device. */
34 private Devices physicalDevice;
36 /** The l2 gateway device. */
37 private L2GatewayDevice elanL2GwDevice;
39 /** The default vlan id. */
40 private Integer defaultVlanId;
42 private static final Logger LOG = LoggerFactory.getLogger(LogicalSwitchAddedJob.class);
44 private final DataBroker broker;
45 private final ElanL2GatewayUtils elanL2GatewayUtils;
46 private final ElanUtils elanUtils;
47 private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
49 public LogicalSwitchAddedJob(DataBroker dataBroker, ElanL2GatewayUtils elanL2GatewayUtils, ElanUtils elanUtils,
50 ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils, String logicalSwitchName,
51 Devices physicalDevice, L2GatewayDevice l2GatewayDevice,
52 Integer defaultVlanId) {
53 this.broker = dataBroker;
54 this.elanL2GatewayUtils = elanL2GatewayUtils;
55 this.elanUtils = elanUtils;
56 this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
57 this.logicalSwitchName = logicalSwitchName;
58 this.physicalDevice = physicalDevice;
59 this.elanL2GwDevice = l2GatewayDevice;
60 this.defaultVlanId = defaultVlanId;
61 LOG.debug("created logical switch added job for {} {}", logicalSwitchName, elanL2GwDevice.getHwvtepNodeId());
64 public String getJobKey() {
65 return logicalSwitchName;
69 public List<ListenableFuture<Void>> call() throws Exception {
70 LOG.debug("running logical switch added job for {} {}", logicalSwitchName,
71 elanL2GwDevice.getHwvtepNodeId());
72 List<ListenableFuture<Void>> futures = new ArrayList<>();
73 String elan = ElanL2GatewayUtils.getElanFromLogicalSwitch(logicalSwitchName);
75 LOG.info("creating vlan bindings for {} {}", logicalSwitchName, elanL2GwDevice.getHwvtepNodeId());
76 futures.add(elanL2GatewayUtils.updateVlanBindingsInL2GatewayDevice(
77 new NodeId(elanL2GwDevice.getHwvtepNodeId()), logicalSwitchName, physicalDevice, defaultVlanId));
78 LOG.info("creating mast mac entries for {} {}", logicalSwitchName, elanL2GwDevice.getHwvtepNodeId());
79 futures.add(elanL2GatewayMulticastUtils.handleMcastForElanL2GwDeviceAdd(logicalSwitchName, elanL2GwDevice));
81 List<IpAddress> expectedPhyLocatorIps = new ArrayList<>();
82 HwvtepRemoteMcastMacListener list = new HwvtepRemoteMcastMacListener(broker,
83 elanUtils, logicalSwitchName, elanL2GwDevice, expectedPhyLocatorIps,
85 LOG.info("adding remote ucast macs for {} {}", logicalSwitchName,
86 elanL2GwDevice.getHwvtepNodeId());
87 List<ListenableFuture<Void>> futures1 = new ArrayList<>();
88 futures1.add(elanL2GatewayUtils.installElanMacsInL2GatewayDevice(
89 logicalSwitchName, elanL2GwDevice));