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.itm.op.rev150701.DpnEndpoints;
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.yangtools.yang.binding.InstanceIdentifier;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 import com.google.common.base.Optional;
28 import com.google.common.util.concurrent.ListenableFuture;
30 public class ItmInternalTunnelDeleteWorker {
31 private static final Logger logger = LoggerFactory.getLogger(ItmInternalTunnelDeleteWorker.class) ;
33 public static List<ListenableFuture<Void>> deleteTunnels(DataBroker dataBroker, List<DPNTEPsInfo> dpnTepsList, List<DPNTEPsInfo> meshedDpnList)
35 List<ListenableFuture<Void>> futures = new ArrayList<>();
36 WriteTransaction t = dataBroker.newWriteOnlyTransaction();
38 if (dpnTepsList == null || dpnTepsList.size() == 0) {
39 logger.debug("no vtep to delete");
43 if (meshedDpnList == null || meshedDpnList.size() == 0) {
44 logger.debug("No Meshed Vteps");
47 for (DPNTEPsInfo srcDpn : dpnTepsList) {
48 logger.trace("Processing srcDpn " + srcDpn);
49 for (TunnelEndPoints srcTep : srcDpn.getTunnelEndPoints()) {
50 logger.trace("Processing srcTep " + srcTep);
51 String srcTZone = srcTep.getTransportZone();
53 // run through all other DPNS other than srcDpn
54 for (DPNTEPsInfo dstDpn : meshedDpnList) {
55 if (!(srcDpn.getDPNID().equals(dstDpn.getDPNID()))) {
56 for (TunnelEndPoints dstTep : dstDpn.getTunnelEndPoints()) {
57 logger.trace("Processing dstTep " + dstTep);
58 if (dstTep.getTransportZone().equals(srcTZone)) {
59 // remove all trunk interfaces
60 logger.trace("Invoking removeTrunkInterface between source TEP {} , Destination TEP {} " ,srcTep , dstTep);
61 removeTrunkInterface(dataBroker, srcTep, dstTep, srcDpn.getDPNID(), dstDpn.getDPNID(), t, futures);
67 // removing vtep / dpn from Tunnels OpDs.
68 InstanceIdentifier<TunnelEndPoints> tepPath =
69 InstanceIdentifier.builder(DpnEndpoints.class).child(DPNTEPsInfo.class, srcDpn.getKey())
70 .child(TunnelEndPoints.class, srcTep.getKey()).build();
72 logger.trace("Tep Removal from DPNTEPSINFO CONFIG DS " + srcTep);
73 t.delete(LogicalDatastoreType.CONFIGURATION, tepPath);
74 InstanceIdentifier<DPNTEPsInfo> dpnPath =
75 InstanceIdentifier.builder(DpnEndpoints.class).child(DPNTEPsInfo.class, srcDpn.getKey())
77 Optional<DPNTEPsInfo> dpnOptional =
78 ItmUtils.read(LogicalDatastoreType.CONFIGURATION, dpnPath, dataBroker);
79 if (dpnOptional.isPresent()) {
80 DPNTEPsInfo dpnRead = dpnOptional.get();
81 // remove dpn if no vteps exist on dpn
82 if (dpnRead.getTunnelEndPoints() == null || dpnRead.getTunnelEndPoints().size() == 0) {
83 logger.debug( "Removing Terminating Service Table Flow ") ;
84 // setUpOrRemoveTerminatingServiceTable(dpnRead.getDPNID(), false);
85 logger.trace("DPN Removal from DPNTEPSINFO CONFIG DS " + dpnRead);
86 t.delete(LogicalDatastoreType.CONFIGURATION, dpnPath);
87 InstanceIdentifier<DpnEndpoints> tnlContainerPath =
88 InstanceIdentifier.builder(DpnEndpoints.class).build();
89 Optional<DpnEndpoints> containerOptional =
90 ItmUtils.read(LogicalDatastoreType.CONFIGURATION,
91 tnlContainerPath, dataBroker);
92 // remove container if no DPNs are present
93 if (containerOptional.isPresent()) {
94 DpnEndpoints deps = containerOptional.get();
95 if (deps.getDPNTEPsInfo() == null || deps.getDPNTEPsInfo().isEmpty()) {
96 logger.trace("Container Removal from DPNTEPSINFO CONFIG DS");
97 t.delete(LogicalDatastoreType.CONFIGURATION, tnlContainerPath);
104 futures.add( t.submit() );
105 } catch (Exception e1) {
106 logger.error("exception while deleting tep", e1);
111 private static void removeTrunkInterface(DataBroker dataBroker, TunnelEndPoints srcTep, TunnelEndPoints dstTep, BigInteger srcDpnId, BigInteger dstDpnId,
112 WriteTransaction t, List<ListenableFuture<Void>> futures) {
113 String trunkfwdIfName =
114 ItmUtils.getTrunkInterfaceName(srcTep.getInterfaceName(), srcTep.getIpAddress()
115 .getIpv4Address().getValue(), dstTep.getIpAddress().getIpv4Address()
117 logger.trace("Removing forward Trunk Interface " + trunkfwdIfName);
118 InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(trunkfwdIfName);
119 logger.debug( " Removing Trunk Interface Name - {} , Id - {} from Config DS {}, {} ", trunkfwdIfName, trunkIdentifier ) ;
120 t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
121 String trunkRevIfName =
122 ItmUtils.getTrunkInterfaceName(dstTep.getInterfaceName(), dstTep.getIpAddress()
123 .getIpv4Address().getValue(), srcTep.getIpAddress().getIpv4Address()
125 logger.trace("Removing Reverse Trunk Interface " + trunkRevIfName);
126 trunkIdentifier = ItmUtils.buildId(trunkfwdIfName);
127 logger.debug( " Removing Trunk Interface Name - {} , Id - {} from Config DS {}, {} ", trunkfwdIfName, trunkIdentifier ) ;
128 t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);