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.vpnservice.elan.l2gw.jobs;
10 import java.util.ArrayList;
11 import java.util.List;
12 import java.util.concurrent.Callable;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.vpnservice.elan.l2gw.utils.ElanL2GatewayUtils;
16 import org.opendaylight.vpnservice.neutronvpn.api.l2gw.L2GatewayDevice;
17 import org.opendaylight.vpnservice.utils.hwvtep.HwvtepSouthboundUtils;
18 import org.opendaylight.vpnservice.utils.hwvtep.HwvtepUtils;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.elan.instances.ElanInstance;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 import com.google.common.util.concurrent.FutureCallback;
29 import com.google.common.util.concurrent.Futures;
30 import com.google.common.util.concurrent.ListenableFuture;
33 * Created by ekvsver on 4/15/2016.
35 public class AssociateHwvtepToElanJob implements Callable<List<ListenableFuture<Void>>> {
37 L2GatewayDevice l2GatewayDevice;
38 ElanInstance elanInstance;
41 boolean createLogicalSwitch;
42 private static final Logger LOG = LoggerFactory.getLogger(AssociateHwvtepToElanJob.class);
44 public AssociateHwvtepToElanJob(DataBroker broker, L2GatewayDevice l2GatewayDevice, ElanInstance elanInstance,
45 Devices l2Device, Integer defaultVlan, boolean createLogicalSwitch) {
47 this.l2GatewayDevice = l2GatewayDevice;
48 this.elanInstance = elanInstance;
49 this.l2Device = l2Device;
50 this.defaultVlan = defaultVlan;
51 this.createLogicalSwitch = createLogicalSwitch;
52 LOG.debug("created assosiate l2gw connection job for {} {} ", elanInstance.getElanInstanceName(),
53 l2GatewayDevice.getHwvtepNodeId());
56 public String getJobKey() {
57 return elanInstance.getElanInstanceName();
61 public List<ListenableFuture<Void>> call() throws Exception {
62 List<ListenableFuture<Void>> futures = new ArrayList<>();
63 String hwvtepNodeId = l2GatewayDevice.getHwvtepNodeId();
64 String elanInstanceName = elanInstance.getElanInstanceName();
65 LOG.debug("running assosiate l2gw connection job for {} {} ", elanInstanceName, hwvtepNodeId);
67 // Create Logical Switch if it's not created already in the device
68 if (createLogicalSwitch) {
69 LOG.info("creating logical switch {} for {} ", elanInstanceName, hwvtepNodeId);
71 ListenableFuture<Void> lsCreateFuture = createLogicalSwitch(l2GatewayDevice, elanInstance);
72 futures.add(lsCreateFuture);
74 String logicalSwitchName = ElanL2GatewayUtils.getLogicalSwitchFromElan(elanInstanceName);
75 LOG.info("{} is already created in {}; adding remaining configurations", logicalSwitchName, hwvtepNodeId);
77 LogicalSwitchAddedJob logicalSwitchAddedJob = new LogicalSwitchAddedJob(logicalSwitchName, l2Device,
78 l2GatewayDevice, defaultVlan);
79 return logicalSwitchAddedJob.call();
85 private ListenableFuture<Void> createLogicalSwitch(L2GatewayDevice l2GatewayDevice, ElanInstance elanInstance) {
86 final String logicalSwitchName = ElanL2GatewayUtils.getLogicalSwitchFromElan(
87 elanInstance.getElanInstanceName());
88 String segmentationId = elanInstance.getVni().toString();
90 if (LOG.isTraceEnabled()) {
91 LOG.trace("logical switch {} is created on {} with VNI {}", logicalSwitchName,
92 l2GatewayDevice.getHwvtepNodeId(), segmentationId);
94 NodeId hwvtepNodeId = new NodeId(l2GatewayDevice.getHwvtepNodeId());
95 InstanceIdentifier<LogicalSwitches> path = HwvtepSouthboundUtils
96 .createLogicalSwitchesInstanceIdentifier(hwvtepNodeId, new HwvtepNodeName(logicalSwitchName));
97 LogicalSwitches logicalSwitch = HwvtepSouthboundUtils.createLogicalSwitch(logicalSwitchName,
98 elanInstance.getDescription(), segmentationId);
100 ListenableFuture<Void> lsCreateFuture = HwvtepUtils.addLogicalSwitch(broker, hwvtepNodeId, logicalSwitch);
101 Futures.addCallback(lsCreateFuture, new FutureCallback<Void>() {
103 public void onSuccess(Void noarg) {
104 // Listener will be closed after all configuration completed
107 if (LOG.isTraceEnabled()) {
108 LOG.trace("Successful in initiating logical switch {} creation", logicalSwitchName);
113 public void onFailure(Throwable error) {
114 LOG.error("Failed logical switch {} creation", logicalSwitchName, error);
117 return lsCreateFuture;