X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=itm%2Fitm-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fvpnservice%2Fitm%2Fconfighelpers%2FItmInternalTunnelDeleteWorker.java;h=210622f79d190539e3028ff218b7cc3b657459b2;hb=HEAD;hp=a6d3d47f418ebed058747341e17da0fe5e402f04;hpb=3e477025479db59022496cabca5e85c79e70fc5a;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 index a6d3d47f..210622f7 100644 --- 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 2015, 2016 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, @@ -17,9 +17,15 @@ 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.vpnservice.idmanager.rev150403.IdManagerService; +import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.TunnelTypeBase; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.DpnEndpoints; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TunnelList; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.DPNTEPsInfo; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.dpn.teps.info.TunnelEndPoints; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnel; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnelKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,22 +36,30 @@ 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) + public static List> deleteTunnels(DataBroker dataBroker, IdManagerService idManagerService,IMdsalApiManager mdsalManager, + List dpnTepsList, List meshedDpnList) { + logger.trace( "TEPs to be deleted {} " , dpnTepsList ); List> futures = new ArrayList<>(); WriteTransaction t = dataBroker.newWriteOnlyTransaction(); try { if (dpnTepsList == null || dpnTepsList.size() == 0) { logger.debug("no vtep to delete"); - return null ; + return futures ; } if (meshedDpnList == null || meshedDpnList.size() == 0) { logger.debug("No Meshed Vteps"); - return null ; + return futures ; } for (DPNTEPsInfo srcDpn : dpnTepsList) { logger.trace("Processing srcDpn " + srcDpn); + List meshedEndPtCache = new ArrayList(ItmUtils.getTEPsForDpn(srcDpn.getDPNID(), meshedDpnList)) ; + if(meshedEndPtCache == null ) { + logger.debug("No Tunnel End Point configured for this DPN {}", srcDpn.getDPNID()); + continue ; + } + logger.debug( "Entries in meshEndPointCache {} ", meshedEndPtCache.size() ); for (TunnelEndPoints srcTep : srcDpn.getTunnelEndPoints()) { logger.trace("Processing srcTep " + srcTep); String srcTZone = srcTep.getTransportZone(); @@ -56,9 +70,11 @@ public class ItmInternalTunnelDeleteWorker { for (TunnelEndPoints dstTep : dstDpn.getTunnelEndPoints()) { logger.trace("Processing dstTep " + dstTep); if (dstTep.getTransportZone().equals(srcTZone)) { + if( checkIfTrunkExists(dstDpn.getDPNID(), srcDpn.getDPNID(), srcTep.getTunnelType(),dataBroker)) { // 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); + removeTrunkInterface(dataBroker, idManagerService, srcTep, dstTep, srcDpn.getDPNID(), dstDpn.getDPNID(), t, futures); + } } } } @@ -69,20 +85,26 @@ public class ItmInternalTunnelDeleteWorker { InstanceIdentifier.builder(DpnEndpoints.class).child(DPNTEPsInfo.class, srcDpn.getKey()) .child(TunnelEndPoints.class, srcTep.getKey()).build(); - logger.trace("Tep Removal from DPNTEPSINFO CONFIG DS " + srcTep); + logger.trace("Tep Removal of TEP {} from DPNTEPSINFO CONFIG DS with Key {} " + srcTep, srcTep.getKey()); t.delete(LogicalDatastoreType.CONFIGURATION, tepPath); + // remove the tep from the cache + meshedEndPtCache.remove(srcTep) ; + InstanceIdentifier dpnPath = InstanceIdentifier.builder(DpnEndpoints.class).child(DPNTEPsInfo.class, srcDpn.getKey()) .build(); + /* Optional dpnOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, dpnPath, dataBroker); if (dpnOptional.isPresent()) { - DPNTEPsInfo dpnRead = dpnOptional.get(); + */ + if( meshedEndPtCache.isEmpty()) { + //DPNTEPsInfo dpnRead = dpnOptional.get(); // remove dpn if no vteps exist on dpn - if (dpnRead.getTunnelEndPoints() == null || dpnRead.getTunnelEndPoints().size() == 0) { + // 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); + ItmUtils.setUpOrRemoveTerminatingServiceTable(srcDpn.getDPNID(), mdsalManager,false); + logger.trace("DPN Removal from DPNTEPSINFO CONFIG DS " + srcDpn.getDPNID()); t.delete(LogicalDatastoreType.CONFIGURATION, dpnPath); InstanceIdentifier tnlContainerPath = InstanceIdentifier.builder(DpnEndpoints.class).build(); @@ -91,13 +113,13 @@ public class ItmInternalTunnelDeleteWorker { tnlContainerPath, dataBroker); // remove container if no DPNs are present if (containerOptional.isPresent()) { - DpnEndpoints deps = containerOptional.get(); + DpnEndpoints deps = containerOptional.get(); if (deps.getDPNTEPsInfo() == null || deps.getDPNTEPsInfo().isEmpty()) { logger.trace("Container Removal from DPNTEPSINFO CONFIG DS"); t.delete(LogicalDatastoreType.CONFIGURATION, tnlContainerPath); } } - } + //} } } } @@ -108,23 +130,59 @@ public class ItmInternalTunnelDeleteWorker { return futures ; } - private static void removeTrunkInterface(DataBroker dataBroker, TunnelEndPoints srcTep, TunnelEndPoints dstTep, BigInteger srcDpnId, BigInteger dstDpnId, - WriteTransaction t, List> futures) { + private static void removeTrunkInterface(DataBroker dataBroker, IdManagerService idManagerService, + 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()); + ItmUtils.getTrunkInterfaceName( idManagerService, srcTep.getInterfaceName(), + srcTep.getIpAddress().getIpv4Address().getValue(), + dstTep.getIpAddress().getIpv4Address().getValue(), + srcTep.getTunnelType().getName()); logger.trace("Removing forward Trunk Interface " + trunkfwdIfName); InstanceIdentifier trunkIdentifier = ItmUtils.buildId(trunkfwdIfName); - logger.debug( " Removing Trunk Interface Name - {} , Id - {} from Config DS {}, {} ", trunkfwdIfName, trunkIdentifier ) ; + logger.debug( " Removing Trunk Interface Name - {} , Id - {} from Config DS ", trunkfwdIfName, trunkIdentifier ) ; t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier); + ItmUtils.itmCache.removeInterface(trunkfwdIfName); + // also update itm-state ds -- Delete the forward tunnel-interface from the tunnel list + InstanceIdentifier path = InstanceIdentifier.create( + TunnelList.class) + .child(InternalTunnel.class, new InternalTunnelKey( dstDpnId, srcDpnId, srcTep.getTunnelType())); + t.delete(LogicalDatastoreType.CONFIGURATION,path) ; + ItmUtils.itmCache.removeInternalTunnel(trunkfwdIfName); + // Release the Ids for the forward trunk interface Name + ItmUtils.releaseIdForTrunkInterfaceName(idManagerService,srcTep.getInterfaceName(), srcTep.getIpAddress() + .getIpv4Address().getValue(), dstTep.getIpAddress().getIpv4Address() + .getValue(), srcTep.getTunnelType().getName() ); + String trunkRevIfName = - ItmUtils.getTrunkInterfaceName(dstTep.getInterfaceName(), dstTep.getIpAddress() - .getIpv4Address().getValue(), srcTep.getIpAddress().getIpv4Address() - .getValue()); + ItmUtils.getTrunkInterfaceName( idManagerService, dstTep.getInterfaceName(), + dstTep.getIpAddress().getIpv4Address().getValue(), + srcTep.getIpAddress().getIpv4Address().getValue(), + srcTep.getTunnelType().getName()); logger.trace("Removing Reverse Trunk Interface " + trunkRevIfName); - trunkIdentifier = ItmUtils.buildId(trunkfwdIfName); - logger.debug( " Removing Trunk Interface Name - {} , Id - {} from Config DS {}, {} ", trunkfwdIfName, trunkIdentifier ) ; + trunkIdentifier = ItmUtils.buildId(trunkRevIfName); + logger.debug( " Removing Trunk Interface Name - {} , Id - {} from Config DS ", trunkRevIfName, trunkIdentifier ) ; t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier); + + // also update itm-state ds -- Delete the reverse tunnel-interface from the tunnel list + path = InstanceIdentifier.create( + TunnelList.class) + .child(InternalTunnel.class, new InternalTunnelKey(dstDpnId, srcDpnId, srcTep.getTunnelType())); + t.delete(LogicalDatastoreType.CONFIGURATION,path) ; + + // Release the Ids for the reverse trunk interface Name + ItmUtils.releaseIdForTrunkInterfaceName(idManagerService, dstTep.getInterfaceName(), dstTep.getIpAddress() + .getIpv4Address().getValue(), srcTep.getIpAddress().getIpv4Address() + .getValue(),dstTep.getTunnelType().getName()); + } + private static boolean checkIfTrunkExists(BigInteger srcDpnId, BigInteger dstDpnId, Class tunType, DataBroker dataBroker) { + boolean existsFlag = false ; + InstanceIdentifier path = InstanceIdentifier.create( + TunnelList.class) + .child(InternalTunnel.class, new InternalTunnelKey( dstDpnId, srcDpnId, tunType)); + Optional internalTunnels = ItmUtils.read(LogicalDatastoreType.CONFIGURATION,path, dataBroker) ; + if( internalTunnels.isPresent()) + existsFlag = true ; + return existsFlag ; } }