Implemented new RPCs, add/delete int/ext I/f name
[vpnservice.git] / itm / itm-impl / src / main / java / org / opendaylight / vpnservice / itm / confighelpers / ItmExternalTunnelDeleteWorker.java
1 /*
2  * Copyright (c) 2015 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.vpnservice.itm.confighelpers;
9
10 import java.util.ArrayList;
11 import java.util.List;
12
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.vpnservice.itm.impl.ItmUtils;
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.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.TunnelTypeBase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.ExternalTunnelList;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.DPNTEPsInfo;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.dpn.teps.info.TunnelEndPoints;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnel;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnelKey;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 import com.google.common.util.concurrent.ListenableFuture;
31
32 public class ItmExternalTunnelDeleteWorker {
33     private static final Logger logger = LoggerFactory.getLogger(ItmExternalTunnelDeleteWorker.class ) ;
34
35     public static List<ListenableFuture<Void>> deleteTunnels(DataBroker dataBroker, IdManagerService idManagerService, List<DPNTEPsInfo> dpnTepsList,IpAddress extIp, Class<? extends TunnelTypeBase> tunType ) {
36         logger.trace( " Delete Tunnels towards DC Gateway with Ip  {}", extIp ) ;
37         List<ListenableFuture<Void>> futures = new ArrayList<>();
38         WriteTransaction t = dataBroker.newWriteOnlyTransaction();
39
40             if (dpnTepsList == null || dpnTepsList.size() == 0) {
41                 logger.debug("no vtep to delete");
42                 return null ;
43             }
44             for( DPNTEPsInfo teps : dpnTepsList) {
45                 TunnelEndPoints firstEndPt = teps.getTunnelEndPoints().get(0) ;
46                 if( firstEndPt.getTunnelType().equals(tunType)) {
47                     String interfaceName = firstEndPt.getInterfaceName() ;
48                     String trunkInterfaceName = ItmUtils.getTrunkInterfaceName(idManagerService, interfaceName,firstEndPt.getIpAddress().getIpv4Address().getValue(), extIp.getIpv4Address().getValue()) ;
49                     InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(trunkInterfaceName);
50                     t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
51
52                     InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(
53                             ExternalTunnelList.class)
54                                 .child(ExternalTunnel.class, new ExternalTunnelKey(extIp, teps.getDPNID()));
55                     t.delete(LogicalDatastoreType.CONFIGURATION, path);
56                     // Release the Ids for the trunk interface
57                     ItmUtils.releaseId(idManagerService, trunkInterfaceName);
58                 }
59             }
60             futures.add(t.submit()) ;
61         return futures ;
62     }
63
64 }