2 * Copyright (c) 2015 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.itm.confighelpers;
10 import java.math.BigInteger;
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.concurrent.Callable;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
18 import org.opendaylight.vpnservice.itm.impl.ItmUtils;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
21 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.DpnEndpoints;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TunnelList;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.DPNTEPsInfo;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.dpn.teps.info.TunnelEndPoints;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnel;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnelKey;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 import com.google.common.base.Optional;
33 import com.google.common.util.concurrent.ListenableFuture;
35 public class ItmInternalTunnelDeleteWorker {
36 private static final Logger logger = LoggerFactory.getLogger(ItmInternalTunnelDeleteWorker.class) ;
38 public static List<ListenableFuture<Void>> deleteTunnels(DataBroker dataBroker, IdManagerService idManagerService,IMdsalApiManager mdsalManager,
39 List<DPNTEPsInfo> dpnTepsList, List<DPNTEPsInfo> meshedDpnList)
41 List<ListenableFuture<Void>> futures = new ArrayList<>();
42 WriteTransaction t = dataBroker.newWriteOnlyTransaction();
44 if (dpnTepsList == null || dpnTepsList.size() == 0) {
45 logger.debug("no vtep to delete");
49 if (meshedDpnList == null || meshedDpnList.size() == 0) {
50 logger.debug("No Meshed Vteps");
53 for (DPNTEPsInfo srcDpn : dpnTepsList) {
54 logger.trace("Processing srcDpn " + srcDpn);
55 for (TunnelEndPoints srcTep : srcDpn.getTunnelEndPoints()) {
56 logger.trace("Processing srcTep " + srcTep);
57 String srcTZone = srcTep.getTransportZone();
59 // run through all other DPNS other than srcDpn
60 for (DPNTEPsInfo dstDpn : meshedDpnList) {
61 if (!(srcDpn.getDPNID().equals(dstDpn.getDPNID()))) {
62 for (TunnelEndPoints dstTep : dstDpn.getTunnelEndPoints()) {
63 logger.trace("Processing dstTep " + dstTep);
64 if (dstTep.getTransportZone().equals(srcTZone)) {
65 // remove all trunk interfaces
66 logger.trace("Invoking removeTrunkInterface between source TEP {} , Destination TEP {} " ,srcTep , dstTep);
67 removeTrunkInterface(dataBroker, idManagerService, srcTep, dstTep, srcDpn.getDPNID(), dstDpn.getDPNID(), t, futures);
73 // removing vtep / dpn from Tunnels OpDs.
74 InstanceIdentifier<TunnelEndPoints> tepPath =
75 InstanceIdentifier.builder(DpnEndpoints.class).child(DPNTEPsInfo.class, srcDpn.getKey())
76 .child(TunnelEndPoints.class, srcTep.getKey()).build();
78 logger.trace("Tep Removal from DPNTEPSINFO CONFIG DS " + srcTep);
79 t.delete(LogicalDatastoreType.CONFIGURATION, tepPath);
80 InstanceIdentifier<DPNTEPsInfo> dpnPath =
81 InstanceIdentifier.builder(DpnEndpoints.class).child(DPNTEPsInfo.class, srcDpn.getKey())
83 Optional<DPNTEPsInfo> dpnOptional =
84 ItmUtils.read(LogicalDatastoreType.CONFIGURATION, dpnPath, dataBroker);
85 if (dpnOptional.isPresent()) {
86 DPNTEPsInfo dpnRead = dpnOptional.get();
87 // remove dpn if no vteps exist on dpn
88 if (dpnRead.getTunnelEndPoints() == null || dpnRead.getTunnelEndPoints().size() == 0) {
89 logger.debug( "Removing Terminating Service Table Flow ") ;
90 ItmUtils.setUpOrRemoveTerminatingServiceTable(dpnRead.getDPNID(), mdsalManager,false);
91 logger.trace("DPN Removal from DPNTEPSINFO CONFIG DS " + dpnRead);
92 t.delete(LogicalDatastoreType.CONFIGURATION, dpnPath);
93 InstanceIdentifier<DpnEndpoints> tnlContainerPath =
94 InstanceIdentifier.builder(DpnEndpoints.class).build();
95 Optional<DpnEndpoints> containerOptional =
96 ItmUtils.read(LogicalDatastoreType.CONFIGURATION,
97 tnlContainerPath, dataBroker);
98 // remove container if no DPNs are present
99 if (containerOptional.isPresent()) {
100 DpnEndpoints deps = containerOptional.get();
101 if (deps.getDPNTEPsInfo() == null || deps.getDPNTEPsInfo().isEmpty()) {
102 logger.trace("Container Removal from DPNTEPSINFO CONFIG DS");
103 t.delete(LogicalDatastoreType.CONFIGURATION, tnlContainerPath);
110 futures.add( t.submit() );
111 } catch (Exception e1) {
112 logger.error("exception while deleting tep", e1);
117 private static void removeTrunkInterface(DataBroker dataBroker, IdManagerService idManagerService,
118 TunnelEndPoints srcTep, TunnelEndPoints dstTep, BigInteger srcDpnId, BigInteger dstDpnId,
119 WriteTransaction t, List<ListenableFuture<Void>> futures) {
120 String trunkfwdIfName =
121 ItmUtils.getTrunkInterfaceName(idManagerService, srcTep.getInterfaceName(), srcTep.getIpAddress()
122 .getIpv4Address().getValue(), dstTep.getIpAddress().getIpv4Address()
124 logger.trace("Removing forward Trunk Interface " + trunkfwdIfName);
125 InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(trunkfwdIfName);
126 logger.debug( " Removing Trunk Interface Name - {} , Id - {} from Config DS {}, {} ", trunkfwdIfName, trunkIdentifier ) ;
127 t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
129 // also update itm-state ds -- Delete the forward tunnel-interface from the tunnel list
130 InstanceIdentifier<InternalTunnel> path = InstanceIdentifier.create(
132 .child(InternalTunnel.class, new InternalTunnelKey( srcDpnId, dstDpnId));
133 t.delete(LogicalDatastoreType.CONFIGURATION,path) ;
134 // Release the Ids for the forward trunk interface Name
135 ItmUtils.releaseIdForTrunkInterfaceName(idManagerService,srcTep.getInterfaceName(), srcTep.getIpAddress()
136 .getIpv4Address().getValue(), dstTep.getIpAddress().getIpv4Address()
139 String trunkRevIfName =
140 ItmUtils.getTrunkInterfaceName(idManagerService, dstTep.getInterfaceName(), dstTep.getIpAddress()
141 .getIpv4Address().getValue(), srcTep.getIpAddress().getIpv4Address()
143 logger.trace("Removing Reverse Trunk Interface " + trunkRevIfName);
144 trunkIdentifier = ItmUtils.buildId(trunkfwdIfName);
145 logger.debug( " Removing Trunk Interface Name - {} , Id - {} from Config DS {}, {} ", trunkfwdIfName, trunkIdentifier ) ;
146 t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
148 // also update itm-state ds -- Delete the reverse tunnel-interface from the tunnel list
149 path = InstanceIdentifier.create(
151 .child(InternalTunnel.class, new InternalTunnelKey(dstDpnId, srcDpnId));
152 t.delete(LogicalDatastoreType.CONFIGURATION,path) ;
154 // Release the Ids for the reverse trunk interface Name
155 ItmUtils.releaseIdForTrunkInterfaceName(idManagerService, dstTep.getInterfaceName(), dstTep.getIpAddress()
156 .getIpv4Address().getValue(), srcTep.getIpAddress().getIpv4Address()