90600ad0f539a6299c1091efcd7079456d658893
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / l2gw / utils / L2GatewayUtils.java
1 /*
2  * Copyright (c) 2016 ,2017  Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netvirt.elan.l2gw.utils;
9
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;
22
23 public final class L2GatewayUtils {
24     private static final Logger LOG = LoggerFactory.getLogger(L2GatewayUtils.class);
25
26     private L2GatewayUtils() {
27
28     }
29
30     public static boolean isLastL2GatewayBeingDeleted(L2GatewayDevice l2GwDevice) {
31         return l2GwDevice.getL2GatewayIds().size() == 1;
32     }
33
34     public static void deleteItmTunnels(ItmRpcService itmRpcService, String hwvtepId, String psName,
35                                         IpAddress tunnelIp) {
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);
40         try {
41             RpcResult<DeleteL2GwDeviceOutput> rpcResult = itmRpcService.deleteL2GwDevice(builder.build()).get();
42             if (rpcResult.isSuccessful()) {
43                 LOG.info("Deleted ITM tunnels for {}", hwvtepId);
44             } else {
45                 LOG.error("Failed to delete ITM Tunnels: {}", rpcResult.getErrors());
46             }
47         } catch (InterruptedException | ExecutionException e) {
48             LOG.error("RPC to delete ITM tunnels failed", e);
49         }
50     }
51 }