2 * Copyright (c) 2016 ,2017 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.utils;
10 import java.util.concurrent.ExecutionException;
11 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants;
12 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
13 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.DeleteL2GwDeviceInputBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.DeleteL2GwDeviceOutput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
19 import org.opendaylight.yangtools.yang.common.RpcResult;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 public final class L2GatewayUtils {
24 private static final Logger LOG = LoggerFactory.getLogger(L2GatewayUtils.class);
26 private L2GatewayUtils() {
30 public static boolean isLastL2GatewayBeingDeleted(L2GatewayDevice l2GwDevice) {
31 return l2GwDevice.getL2GatewayIds().size() == 1;
34 public static void deleteItmTunnels(ItmRpcService itmRpcService, String hwvtepId, String psName,
36 DeleteL2GwDeviceInputBuilder builder = new DeleteL2GwDeviceInputBuilder();
37 builder.setTopologyId(HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID.getValue());
38 builder.setNodeId(HwvtepSouthboundUtils.createManagedNodeId(new NodeId(hwvtepId), psName).getValue());
39 builder.setIpAddress(tunnelIp);
41 RpcResult<DeleteL2GwDeviceOutput> rpcResult = itmRpcService.deleteL2GwDevice(builder.build()).get();
42 if (rpcResult.isSuccessful()) {
43 LOG.info("Deleted ITM tunnels for {}", hwvtepId);
45 LOG.error("Failed to delete ITM Tunnels: {}", rpcResult.getErrors());
47 } catch (InterruptedException | ExecutionException e) {
48 LOG.error("RPC to delete ITM tunnels failed", e);