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
9 package org.opendaylight.vpnservice.neutronvpn.l2gw;
11 import java.util.concurrent.ExecutionException;
12 import java.util.concurrent.Future;
14 import org.opendaylight.vpnservice.neutronvpn.api.l2gw.L2GatewayDevice;
15 import org.opendaylight.vpnservice.utils.hwvtep.HwvtepSouthboundConstants;
16 import org.opendaylight.vpnservice.utils.hwvtep.HwvtepSouthboundUtils;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.AddL2GwDeviceInputBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.DeleteL2GwDeviceInputBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.ItmRpcService;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
22 import org.opendaylight.yangtools.yang.common.RpcResult;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public class L2GatewayUtils {
27 private static final Logger LOG = LoggerFactory.getLogger(L2GatewayUtils.class);
29 protected static boolean isGatewayAssociatedToL2Device(L2GatewayDevice l2GwDevice) {
30 return (l2GwDevice.getL2GatewayIds().size() > 0);
33 protected static boolean isLastL2GatewayBeingDeleted(L2GatewayDevice l2GwDevice) {
34 return (l2GwDevice.getL2GatewayIds().size() == 1);
37 protected static boolean isL2GwDeviceConnected(L2GatewayDevice l2GwDevice) {
38 return (l2GwDevice.getHwvtepNodeId() != null);
41 protected static boolean isItmTunnelsCreatedForL2Device(L2GatewayDevice l2GwDevice) {
42 return (l2GwDevice.getHwvtepNodeId() != null && l2GwDevice.getL2GatewayIds().size() > 0);
45 protected static void createItmTunnels(ItmRpcService itmRpcService, String hwvtepId, String psName,
47 AddL2GwDeviceInputBuilder builder = new AddL2GwDeviceInputBuilder();
48 builder.setTopologyId(HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID.getValue());
49 builder.setNodeId(HwvtepSouthboundUtils.createManagedNodeId(new NodeId(hwvtepId), psName).getValue());
50 builder.setIpAddress(tunnelIp);
52 Future<RpcResult<Void>> result = itmRpcService.addL2GwDevice(builder.build());
53 RpcResult<Void> rpcResult = result.get();
54 if (rpcResult.isSuccessful()) {
55 LOG.info("Created ITM tunnels for {}", hwvtepId);
57 LOG.error("Failed to create ITM Tunnels: ", rpcResult.getErrors());
59 } catch (InterruptedException | ExecutionException e) {
60 LOG.error("RPC to create ITM tunnels failed", e);
64 protected static void deleteItmTunnels(ItmRpcService itmRpcService, String hwvtepId, String psName,
66 DeleteL2GwDeviceInputBuilder builder = new DeleteL2GwDeviceInputBuilder();
67 builder.setTopologyId(HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID.getValue());
68 builder.setNodeId(HwvtepSouthboundUtils.createManagedNodeId(new NodeId(hwvtepId), psName).getValue());
69 builder.setIpAddress(tunnelIp);
71 Future<RpcResult<Void>> result = itmRpcService.deleteL2GwDevice(builder.build());
72 RpcResult<Void> rpcResult = result.get();
73 if (rpcResult.isSuccessful()) {
74 LOG.info("Deleted ITM tunnels for {}", hwvtepId);
76 LOG.error("Failed to delete ITM Tunnels: ", rpcResult.getErrors());
78 } catch (InterruptedException | ExecutionException e) {
79 LOG.error("RPC to delete ITM tunnels failed", e);