X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=itm%2Fitm-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fvpnservice%2Fitm%2Fconfighelpers%2FItmInternalTunnelDeleteWorker.java;fp=itm%2Fitm-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fvpnservice%2Fitm%2Fconfighelpers%2FItmInternalTunnelDeleteWorker.java;h=8922fd93a2d9d35af5655b2a3a110c5faea001e2;hb=50bb8cd056ca25114a412398c4df672eac891b28;hp=0000000000000000000000000000000000000000;hpb=c27f9ad4bdc259ff9709d433d3a1e8fc24fc215f;p=vpnservice.git diff --git a/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmInternalTunnelDeleteWorker.java b/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmInternalTunnelDeleteWorker.java new file mode 100644 index 00000000..8922fd93 --- /dev/null +++ b/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmInternalTunnelDeleteWorker.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.vpnservice.itm.confighelpers; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Callable; + +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.vpnservice.itm.impl.ItmUtils; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.itm.op.rev150701.Tunnels; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.itm.op.rev150701.tunnels.DPNTEPsInfo; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.itm.op.rev150701.tunnels.dpn.teps.info.TunnelEndPoints; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.Optional; +import com.google.common.util.concurrent.ListenableFuture; + +public class ItmInternalTunnelDeleteWorker { + private static final Logger logger = LoggerFactory.getLogger(ItmInternalTunnelDeleteWorker.class) ; + + public static List> deleteTunnels(DataBroker dataBroker, List dpnTepsList, List meshedDpnList) + { + List> futures = new ArrayList<>(); + WriteTransaction t = dataBroker.newWriteOnlyTransaction(); + try { + if (dpnTepsList == null || dpnTepsList.size() == 0) { + logger.debug("no vtep to delete"); + return null ; + } + + if (meshedDpnList == null || meshedDpnList.size() == 0) { + logger.debug("No Meshed Vteps"); + return null ; + } + for (DPNTEPsInfo srcDpn : dpnTepsList) { + logger.trace("Processing srcDpn " + srcDpn); + for (TunnelEndPoints srcTep : srcDpn.getTunnelEndPoints()) { + logger.trace("Processing srcTep " + srcTep); + String srcTZone = srcTep.getTransportZone(); + + // run through all other DPNS other than srcDpn + for (DPNTEPsInfo dstDpn : meshedDpnList) { + if (!(srcDpn.getDPNID().equals(dstDpn.getDPNID()))) { + for (TunnelEndPoints dstTep : dstDpn.getTunnelEndPoints()) { + logger.trace("Processing dstTep " + dstTep); + if (dstTep.getTransportZone().equals(srcTZone)) { + // remove all trunk interfaces + logger.trace("Invoking removeTrunkInterface between source TEP {} , Destination TEP {} " ,srcTep , dstTep); + removeTrunkInterface(dataBroker, srcTep, dstTep, srcDpn.getDPNID(), dstDpn.getDPNID(), t, futures); + } + } + } + } + + // removing vtep / dpn from Tunnels OpDs. + InstanceIdentifier tepPath = + InstanceIdentifier.builder(Tunnels.class).child(DPNTEPsInfo.class, srcDpn.getKey()) + .child(TunnelEndPoints.class, srcTep.getKey()).build(); + + logger.trace("Tep Removal from DPNTEPSINFO CONFIG DS " + srcTep); + t.delete(LogicalDatastoreType.CONFIGURATION, tepPath); + InstanceIdentifier dpnPath = + InstanceIdentifier.builder(Tunnels.class).child(DPNTEPsInfo.class, srcDpn.getKey()) + .build(); + Optional dpnOptional = + ItmUtils.read(LogicalDatastoreType.CONFIGURATION, dpnPath, dataBroker); + if (dpnOptional.isPresent()) { + DPNTEPsInfo dpnRead = dpnOptional.get(); + // remove dpn if no vteps exist on dpn + if (dpnRead.getTunnelEndPoints() == null || dpnRead.getTunnelEndPoints().size() == 0) { + logger.debug( "Removing Terminating Service Table Flow ") ; + // setUpOrRemoveTerminatingServiceTable(dpnRead.getDPNID(), false); + logger.trace("DPN Removal from DPNTEPSINFO CONFIG DS " + dpnRead); + t.delete(LogicalDatastoreType.CONFIGURATION, dpnPath); + InstanceIdentifier tnlContainerPath = + InstanceIdentifier.builder(Tunnels.class).build(); + Optional containerOptional = + ItmUtils.read(LogicalDatastoreType.CONFIGURATION, + tnlContainerPath, dataBroker); + // remove container if no DPNs are present + if (containerOptional.isPresent()) { + Tunnels tnls = containerOptional.get(); + if (tnls.getDPNTEPsInfo() == null || tnls.getDPNTEPsInfo().isEmpty()) { + logger.trace("Container Removal from DPNTEPSINFO CONFIG DS"); + t.delete(LogicalDatastoreType.CONFIGURATION, tnlContainerPath); + } + } + } + } + } + } + futures.add( t.submit() ); + } catch (Exception e1) { + logger.error("exception while deleting tep", e1); + } + return futures ; + } + + private static void removeTrunkInterface(DataBroker dataBroker, TunnelEndPoints srcTep, TunnelEndPoints dstTep, BigInteger srcDpnId, BigInteger dstDpnId, + WriteTransaction t, List> futures) { + String trunkfwdIfName = + ItmUtils.getTrunkInterfaceName(srcTep.getInterfaceName(), srcTep.getIpAddress() + .getIpv4Address().getValue(), dstTep.getIpAddress().getIpv4Address() + .getValue()); + logger.trace("Removing forward Trunk Interface " + trunkfwdIfName); + InstanceIdentifier trunkIdentifier = ItmUtils.buildId(trunkfwdIfName); + logger.debug( " Removing Trunk Interface Name - {} , Id - {} from Config DS {}, {} ", trunkfwdIfName, trunkIdentifier ) ; + t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier); + String trunkRevIfName = + ItmUtils.getTrunkInterfaceName(dstTep.getInterfaceName(), dstTep.getIpAddress() + .getIpv4Address().getValue(), srcTep.getIpAddress().getIpv4Address() + .getValue()); + logger.trace("Removing Reverse Trunk Interface " + trunkRevIfName); + trunkIdentifier = ItmUtils.buildId(trunkfwdIfName); + logger.debug( " Removing Trunk Interface Name - {} , Id - {} from Config DS {}, {} ", trunkfwdIfName, trunkIdentifier ) ; + t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier); + } +}