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.netvirt.elan.l2gw.ha.HwvtepHAUtil;
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;
24 * The Class LogicalSwitchAddedWorker.
26 public class LogicalSwitchAddedJob implements Callable<List<ListenableFuture<Void>>> {
27 private static final Logger LOG = LoggerFactory.getLogger(LogicalSwitchAddedJob.class);
29 /** The logical switch name. */
30 private final String logicalSwitchName;
32 /** The physical device. */
33 private final Devices physicalDevice;
35 /** The l2 gateway device. */
36 private final L2GatewayDevice elanL2GwDevice;
38 /** The default vlan id. */
39 private final Integer defaultVlanId;
41 private final ElanL2GatewayUtils elanL2GatewayUtils;
42 private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
44 public LogicalSwitchAddedJob(ElanL2GatewayUtils elanL2GatewayUtils,
45 ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils, String logicalSwitchName,
46 Devices physicalDevice, L2GatewayDevice l2GatewayDevice, Integer defaultVlanId) {
47 this.elanL2GatewayUtils = elanL2GatewayUtils;
48 this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
49 this.logicalSwitchName = logicalSwitchName;
50 this.physicalDevice = physicalDevice;
51 this.elanL2GwDevice = l2GatewayDevice;
52 this.defaultVlanId = defaultVlanId;
53 LOG.debug("created logical switch added job for {} {}", logicalSwitchName, elanL2GwDevice.getHwvtepNodeId());
56 public String getJobKey() {
57 return logicalSwitchName + HwvtepHAUtil.L2GW_JOB_KEY;
61 public List<ListenableFuture<Void>> call() {
62 elanL2GatewayUtils.cancelDeleteLogicalSwitch(new NodeId(elanL2GwDevice.getHwvtepNodeId()), logicalSwitchName);
63 LOG.debug("running logical switch added job for {} {}", logicalSwitchName,
64 elanL2GwDevice.getHwvtepNodeId());
65 List<ListenableFuture<Void>> futures = new ArrayList<>();
67 LOG.info("creating vlan bindings for {} {}", logicalSwitchName, elanL2GwDevice.getHwvtepNodeId());
68 futures.add(elanL2GatewayUtils.updateVlanBindingsInL2GatewayDevice(
69 new NodeId(elanL2GwDevice.getHwvtepNodeId()), logicalSwitchName, physicalDevice, defaultVlanId));
70 LOG.info("creating mast mac entries for {} {}", logicalSwitchName, elanL2GwDevice.getHwvtepNodeId());
71 elanL2GatewayMulticastUtils.handleMcastForElanL2GwDeviceAdd(logicalSwitchName, elanL2GwDevice);
72 futures.add(elanL2GatewayUtils.installElanMacsInL2GatewayDevice(
73 logicalSwitchName, elanL2GwDevice));