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.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.DpnEndpoints;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TunnelList;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.DPNTEPsInfo;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.dpn.teps.info.TunnelEndPoints;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnel;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnelKey;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 import com.google.common.base.Optional;
32 import com.google.common.util.concurrent.ListenableFuture;
34 public class ItmInternalTunnelDeleteWorker {
35 private static final Logger logger = LoggerFactory.getLogger(ItmInternalTunnelDeleteWorker.class) ;
37 public static List<ListenableFuture<Void>> deleteTunnels(DataBroker dataBroker, IdManagerService idManagerService,
38 List<DPNTEPsInfo> dpnTepsList, List<DPNTEPsInfo> meshedDpnList)
40 List<ListenableFuture<Void>> futures = new ArrayList<>();
41 WriteTransaction t = dataBroker.newWriteOnlyTransaction();
43 if (dpnTepsList == null || dpnTepsList.size() == 0) {
44 logger.debug("no vtep to delete");
48 if (meshedDpnList == null || meshedDpnList.size() == 0) {
49 logger.debug("No Meshed Vteps");
52 for (DPNTEPsInfo srcDpn : dpnTepsList) {
53 logger.trace("Processing srcDpn " + srcDpn);
54 for (TunnelEndPoints srcTep : srcDpn.getTunnelEndPoints()) {
55 logger.trace("Processing srcTep " + srcTep);
56 String srcTZone = srcTep.getTransportZone();
58 // run through all other DPNS other than srcDpn
59 for (DPNTEPsInfo dstDpn : meshedDpnList) {
60 if (!(srcDpn.getDPNID().equals(dstDpn.getDPNID()))) {
61 for (TunnelEndPoints dstTep : dstDpn.getTunnelEndPoints()) {
62 logger.trace("Processing dstTep " + dstTep);
63 if (dstTep.getTransportZone().equals(srcTZone)) {
64 // remove all trunk interfaces
65 logger.trace("Invoking removeTrunkInterface between source TEP {} , Destination TEP {} " ,srcTep , dstTep);
66 removeTrunkInterface(dataBroker, idManagerService, srcTep, dstTep, srcDpn.getDPNID(), dstDpn.getDPNID(), t, futures);
72 // removing vtep / dpn from Tunnels OpDs.
73 InstanceIdentifier<TunnelEndPoints> tepPath =
74 InstanceIdentifier.builder(DpnEndpoints.class).child(DPNTEPsInfo.class, srcDpn.getKey())
75 .child(TunnelEndPoints.class, srcTep.getKey()).build();
77 logger.trace("Tep Removal from DPNTEPSINFO CONFIG DS " + srcTep);
78 t.delete(LogicalDatastoreType.CONFIGURATION, tepPath);
79 InstanceIdentifier<DPNTEPsInfo> dpnPath =
80 InstanceIdentifier.builder(DpnEndpoints.class).child(DPNTEPsInfo.class, srcDpn.getKey())
82 Optional<DPNTEPsInfo> dpnOptional =
83 ItmUtils.read(LogicalDatastoreType.CONFIGURATION, dpnPath, dataBroker);
84 if (dpnOptional.isPresent()) {
85 DPNTEPsInfo dpnRead = dpnOptional.get();
86 // remove dpn if no vteps exist on dpn
87 if (dpnRead.getTunnelEndPoints() == null || dpnRead.getTunnelEndPoints().size() == 0) {
88 logger.debug( "Removing Terminating Service Table Flow ") ;
89 // setUpOrRemoveTerminatingServiceTable(dpnRead.getDPNID(), false);
90 logger.trace("DPN Removal from DPNTEPSINFO CONFIG DS " + dpnRead);
91 t.delete(LogicalDatastoreType.CONFIGURATION, dpnPath);
92 InstanceIdentifier<DpnEndpoints> tnlContainerPath =
93 InstanceIdentifier.builder(DpnEndpoints.class).build();
94 Optional<DpnEndpoints> containerOptional =
95 ItmUtils.read(LogicalDatastoreType.CONFIGURATION,
96 tnlContainerPath, dataBroker);
97 // remove container if no DPNs are present
98 if (containerOptional.isPresent()) {
99 DpnEndpoints deps = containerOptional.get();
100 if (deps.getDPNTEPsInfo() == null || deps.getDPNTEPsInfo().isEmpty()) {
101 logger.trace("Container Removal from DPNTEPSINFO CONFIG DS");
102 t.delete(LogicalDatastoreType.CONFIGURATION, tnlContainerPath);
109 futures.add( t.submit() );
110 } catch (Exception e1) {
111 logger.error("exception while deleting tep", e1);
116 private static void removeTrunkInterface(DataBroker dataBroker, IdManagerService idManagerService,
117 TunnelEndPoints srcTep, TunnelEndPoints dstTep, BigInteger srcDpnId, BigInteger dstDpnId,
118 WriteTransaction t, List<ListenableFuture<Void>> futures) {
119 String trunkfwdIfName =
120 ItmUtils.getTrunkInterfaceName(idManagerService, srcTep.getInterfaceName(), srcTep.getIpAddress()
121 .getIpv4Address().getValue(), dstTep.getIpAddress().getIpv4Address()
123 logger.trace("Removing forward Trunk Interface " + trunkfwdIfName);
124 InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(trunkfwdIfName);
125 logger.debug( " Removing Trunk Interface Name - {} , Id - {} from Config DS {}, {} ", trunkfwdIfName, trunkIdentifier ) ;
126 t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
128 // also update itm-state ds -- Delete the forward tunnel-interface from the tunnel list
129 InstanceIdentifier<InternalTunnel> path = InstanceIdentifier.create(
131 .child(InternalTunnel.class, new InternalTunnelKey( srcDpnId, dstDpnId));
132 t.delete(LogicalDatastoreType.CONFIGURATION,path) ;
133 // Release the Id for the forward trunk
134 ItmUtils.releaseId(idManagerService, trunkfwdIfName);
136 String trunkRevIfName =
137 ItmUtils.getTrunkInterfaceName(idManagerService, dstTep.getInterfaceName(), dstTep.getIpAddress()
138 .getIpv4Address().getValue(), srcTep.getIpAddress().getIpv4Address()
140 logger.trace("Removing Reverse Trunk Interface " + trunkRevIfName);
141 trunkIdentifier = ItmUtils.buildId(trunkfwdIfName);
142 logger.debug( " Removing Trunk Interface Name - {} , Id - {} from Config DS {}, {} ", trunkfwdIfName, trunkIdentifier ) ;
143 t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
145 // also update itm-state ds -- Delete the reverse tunnel-interface from the tunnel list
146 path = InstanceIdentifier.create(
148 .child(InternalTunnel.class, new InternalTunnelKey(dstDpnId, srcDpnId));
149 t.delete(LogicalDatastoreType.CONFIGURATION,path) ;
151 // Release the Id for the Reverse trunk
152 ItmUtils.releaseId(idManagerService, trunkRevIfName);