Implemented new RPCs, add/delete int/ext I/f name
[vpnservice.git] / itm / itm-impl / src / main / java / org / opendaylight / vpnservice / itm / confighelpers / ItmInternalTunnelDeleteWorker.java
index a6d3d47f418ebed058747341e17da0fe5e402f04..096d81cffdec780ed96d74ee54cc12be3022ffa4 100644 (file)
@@ -17,9 +17,13 @@ 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.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,7 +34,8 @@ import com.google.common.util.concurrent.ListenableFuture;
 public class ItmInternalTunnelDeleteWorker {
    private static final Logger logger = LoggerFactory.getLogger(ItmInternalTunnelDeleteWorker.class) ;
 
-    public static List<ListenableFuture<Void>> deleteTunnels(DataBroker dataBroker, List<DPNTEPsInfo> dpnTepsList, List<DPNTEPsInfo> meshedDpnList)
+    public static List<ListenableFuture<Void>> deleteTunnels(DataBroker dataBroker, IdManagerService idManagerService,
+                                                             List<DPNTEPsInfo> dpnTepsList, List<DPNTEPsInfo> meshedDpnList)
     {
         List<ListenableFuture<Void>> futures = new ArrayList<>();
         WriteTransaction t = dataBroker.newWriteOnlyTransaction();
@@ -58,7 +63,7 @@ public class ItmInternalTunnelDeleteWorker {
                                 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);
+                                    removeTrunkInterface(dataBroker, idManagerService, srcTep, dstTep, srcDpn.getDPNID(), dstDpn.getDPNID(), t, futures);
                                 }
                             }
                         }
@@ -108,23 +113,42 @@ public class ItmInternalTunnelDeleteWorker {
         return futures ;
     }
 
-    private static void removeTrunkInterface(DataBroker dataBroker, TunnelEndPoints srcTep, TunnelEndPoints dstTep, BigInteger srcDpnId, BigInteger dstDpnId,
-        WriteTransaction t, List<ListenableFuture<Void>> futures) {
+    private static void removeTrunkInterface(DataBroker dataBroker, IdManagerService idManagerService,
+                                             TunnelEndPoints srcTep, TunnelEndPoints dstTep, BigInteger srcDpnId, BigInteger dstDpnId,
+                                             WriteTransaction t, List<ListenableFuture<Void>> futures) {
         String trunkfwdIfName =
-                        ItmUtils.getTrunkInterfaceName(srcTep.getInterfaceName(), srcTep.getIpAddress()
+                        ItmUtils.getTrunkInterfaceName(idManagerService, srcTep.getInterfaceName(), srcTep.getIpAddress()
                                         .getIpv4Address().getValue(), dstTep.getIpAddress().getIpv4Address()
                                         .getValue());
         logger.trace("Removing forward Trunk Interface " + trunkfwdIfName);
         InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(trunkfwdIfName);
         logger.debug(  " Removing Trunk Interface Name - {} , Id - {} from Config DS {}, {} ", trunkfwdIfName, trunkIdentifier ) ;
         t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
+
+        // also update itm-state ds -- Delete the forward tunnel-interface from the tunnel list
+        InstanceIdentifier<InternalTunnel> path = InstanceIdentifier.create(
+                TunnelList.class)
+                    .child(InternalTunnel.class, new InternalTunnelKey( srcDpnId, dstDpnId));   
+        t.delete(LogicalDatastoreType.CONFIGURATION,path) ;
+        // Release the Id for the forward trunk
+        ItmUtils.releaseId(idManagerService, trunkfwdIfName);
+
         String trunkRevIfName =
-                        ItmUtils.getTrunkInterfaceName(dstTep.getInterfaceName(), dstTep.getIpAddress()
+                        ItmUtils.getTrunkInterfaceName(idManagerService, 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);
+
+     // 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));   
+        t.delete(LogicalDatastoreType.CONFIGURATION,path) ;
+        
+        // Release the Id for the Reverse trunk
+        ItmUtils.releaseId(idManagerService, trunkRevIfName);
     }
 }