IPSec Handler: FBQ added to handle the database

Change-Id: Idb30f920ebf555b1af3b6cf5c582839531c47e1b
Signed-off-by: József Gyürüsi <jozsef.gyurusi@ericsson.com>
diff --git a/src/Transport/EPTF_CLL_Transport_IPsecHandler_Definitions.ttcn b/src/Transport/EPTF_CLL_Transport_IPsecHandler_Definitions.ttcn
index 0de89e0..3ec6d7c 100644
--- a/src/Transport/EPTF_CLL_Transport_IPsecHandler_Definitions.ttcn
+++ b/src/Transport/EPTF_CLL_Transport_IPsecHandler_Definitions.ttcn
@@ -52,6 +52,7 @@
 import from TCCIPsec_XFRM_Definitions all;
 import from EPTF_CLL_Base_Definitions all;
 import from EPTF_CLL_HashMap_Definitions all;
+import from EPTF_CLL_FBQ_Definitions all;
 import from EPTF_CLL_Transport_IPsecHandler_Logging_Client_Definitions all;
 
 
@@ -92,11 +93,13 @@
 //  Elements:
 //    c_EPTF_Transport_IPsecHandler_saHashMapName - *charstring* - hashmap name used for SA handling
 //    v_EPTF_Transport_IPsecHandler_saHashMapId - *integer* - hashmap id used for SA handling
-//    v_SAAddInfo_List - <SAAddInfo_List> - the data base for SA handling
+//    v_SAAddInfo_List - <SAAddInfo_List> - the database for SA handling
+//    v_Transport_IPsecHandler_saFBQId - <EPTF_FreeBusyQueue> - FreeBusyQueue for SA handling
 //
 //    c_EPTF_Transport_IPsecHandler_spHashMapName - *charstring* - hashmap name used for SP handling
 //    v_EPTF_Transport_IPsecHandler_spHashMapId - *integer* - hashmap id used for SP handling
-//    v_SPAddInfo_List - <SPAddInfo_List> - the data base for SP handling
+//    v_SPAddInfo_List - <SPAddInfo_List> - the database for SP handling
+//    v_Transport_IPsecHandler_spFBQId - <EPTF_FreeBusyQueue> - FreeBusyQueue for SP handling
 //
 //    v_EPTF_Transport_IPsecHandler_initialized - *boolean* - prevents multiple init by calling <f_EPTF_Transport_IPsecHandler_init_CT> several times
 //
@@ -104,15 +107,17 @@
 //   The <EPTF_TransportIPL4_CT> component extends this component
 //
 ///////////////////////////////////////////////////////////
-type component EPTF_Transport_IPsecHandler_CT extends EPTF_Base_CT, EPTF_HashMap_CT, EPTF_CLL_Transport_IPsecHandler_Logging_Client_CT {
+type component EPTF_Transport_IPsecHandler_CT extends EPTF_Base_CT, EPTF_HashMap_CT, EPTF_CLL_Transport_IPsecHandler_Logging_Client_CT, EPTF_FBQ_CT {
   private const charstring c_EPTF_Transport_IPsecHandler_saHashMapName := "v_IPsecHandler_saHashMapName";
   private var integer v_EPTF_Transport_IPsecHandler_saHashMapId;
   private var SAAddInfo_List v_SAAddInfo_List := {};
+  private var EPTF_FreeBusyQueue v_Transport_IPsecHandler_saFBQId := c_EPTF_emptyFreeBusyQueue;
 
   private const charstring c_EPTF_Transport_IPsecHandler_spHashMapName := "v_IPsecHandler_spHashMapName";
   private var integer v_EPTF_Transport_IPsecHandler_spHashMapId;
   private var SPAddInfo_List v_SPAddInfo_List := {};
-  
+  private var EPTF_FreeBusyQueue v_Transport_IPsecHandler_spFBQId := c_EPTF_emptyFreeBusyQueue;
+
   private var boolean v_EPTF_Transport_IPsecHandler_initialized := false;
 }
 
diff --git a/src/Transport/EPTF_CLL_Transport_IPsecHandler_Functions.ttcn b/src/Transport/EPTF_CLL_Transport_IPsecHandler_Functions.ttcn
index 35432f1..8bec827 100644
--- a/src/Transport/EPTF_CLL_Transport_IPsecHandler_Functions.ttcn
+++ b/src/Transport/EPTF_CLL_Transport_IPsecHandler_Functions.ttcn
@@ -48,6 +48,8 @@
 import from EPTF_CLL_HashMapStr2Int_Functions all;
 import from EPTF_CLL_Base_Functions all;
 import from EPTF_CLL_HashMap_Functions all;
+import from EPTF_CLL_FBQ_Definitions all;
+import from EPTF_CLL_FBQ_Functions all;
 import from EPTF_CLL_Transport_IPsecHandler_Logging_Client_Functions all;
 import from EPTF_CLL_Transport_IPsecHandler_Logging_Server_Definitions all;
 import from TCCConversion_Functions all; // f_convertIPAddrToBinary
@@ -83,14 +85,18 @@
   f_EPTF_Base_init_CT(pl_selfName);
   f_EPTF_HashMap_init_CT(pl_selfName);
   f_EPTF_CLL_Transport_IPsecHandler_Logging_Client_init(pl_selfName, pl_LoggingIPSecServer_CT);
+  f_EPTF_FBQ_init_CT(pl_selfName);
 
   v_EPTF_Transport_IPsecHandler_saHashMapId := f_EPTF_str2int_HashMap_New(c_EPTF_Transport_IPsecHandler_saHashMapName);
   v_SAAddInfo_List := {};
+  f_EPTF_FBQ_initFreeBusyQueue(v_Transport_IPsecHandler_saFBQId);
+
   v_EPTF_Transport_IPsecHandler_spHashMapId := f_EPTF_str2int_HashMap_New(c_EPTF_Transport_IPsecHandler_spHashMapName);
   v_SPAddInfo_List := {};
-  
+  f_EPTF_FBQ_initFreeBusyQueue(v_Transport_IPsecHandler_spFBQId);
+
   f_EPTF_Base_registerCleanup(refers(f_EPTF_Transport_IPsecHandler_cleanup));
-  
+
   v_EPTF_Transport_IPsecHandler_initialized := true;
   return;
 }
@@ -99,10 +105,14 @@
   if (not v_EPTF_Transport_IPsecHandler_initialized) {
     return;
   }
-  
+
   f_EPTF_str2int_HashMap_Delete(c_EPTF_Transport_IPsecHandler_saHashMapName);
+  v_SAAddInfo_List := {};
+  v_Transport_IPsecHandler_saFBQId := c_EPTF_emptyFreeBusyQueue;
   f_EPTF_str2int_HashMap_Delete(c_EPTF_Transport_IPsecHandler_spHashMapName);
-  
+  v_SPAddInfo_List := {};
+  v_Transport_IPsecHandler_spFBQId := c_EPTF_emptyFreeBusyQueue;
+
   v_EPTF_Transport_IPsecHandler_initialized := false;
 }
 
@@ -158,7 +168,8 @@
     log2str(f_EPTF_Transport_IPsecHandler_getBinaryAddress(pl_sa_info.dst.ip_address))&"_"&log2str(pl_sa_info.dst.port_number)
   var integer vl_sa_info_id;
   if(not f_EPTF_str2int_HashMap_Find(v_EPTF_Transport_IPsecHandler_saHashMapId, vl_connectionIdStr, vl_sa_info_id)) {
-    vl_sa_info_id := sizeof(v_SAAddInfo_List); // TODO: use FBQ
+    vl_sa_info_id := f_EPTF_FBQ_getOrCreateFreeSlot(v_Transport_IPsecHandler_saFBQId);
+    f_EPTF_FBQ_moveFromFreeToBusyTail(vl_sa_info_id, v_Transport_IPsecHandler_saFBQId);
     f_EPTF_str2int_HashMap_Insert(v_EPTF_Transport_IPsecHandler_saHashMapId,vl_connectionIdStr,vl_sa_info_id);
   }
   
@@ -199,7 +210,8 @@
     log2str(f_EPTF_Transport_IPsecHandler_getBinaryAddress(pl_sp_info.dst.ip_address))&"_"&log2str(pl_sp_info.dst.port_number)
   var integer vl_sp_info_id;
   if(not f_EPTF_str2int_HashMap_Find(v_EPTF_Transport_IPsecHandler_spHashMapId, vl_connectionIdStr, vl_sp_info_id)) {
-    vl_sp_info_id := sizeof(v_SPAddInfo_List); // TODO: use FBQ
+    vl_sp_info_id := f_EPTF_FBQ_getOrCreateFreeSlot(v_Transport_IPsecHandler_spFBQId);
+    f_EPTF_FBQ_moveFromFreeToBusyTail(vl_sp_info_id, v_Transport_IPsecHandler_spFBQId);
     f_EPTF_str2int_HashMap_Insert(v_EPTF_Transport_IPsecHandler_spHashMapId,vl_connectionIdStr,vl_sp_info_id);
   }
 
@@ -239,6 +251,7 @@
   }
   if(f_EPTF_str2int_HashMap_Find(v_EPTF_Transport_IPsecHandler_saHashMapId, vl_connectionIdStr, vl_sa_info_id)) {
     f_EPTF_str2int_HashMap_Erase(v_EPTF_Transport_IPsecHandler_saHashMapId,vl_connectionIdStr);
+    f_EPTF_FBQ_moveFromBusyToFreeTail(vl_sa_info_id, v_Transport_IPsecHandler_saFBQId);
     vl_result := f_XFRM_delete_sa(pl_sa_del_info);
   } else {
     vl_result := {
@@ -284,6 +297,7 @@
   }
   if(f_EPTF_str2int_HashMap_Find(v_EPTF_Transport_IPsecHandler_spHashMapId, vl_connectionIdStr, vl_sp_info_id)) {
     f_EPTF_str2int_HashMap_Erase(v_EPTF_Transport_IPsecHandler_spHashMapId,vl_connectionIdStr);
+    f_EPTF_FBQ_moveFromBusyToFreeTail(vl_sp_info_id, v_Transport_IPsecHandler_spFBQId);
     vl_result := f_XFRM_delete_policy(pl_sp_del_info);
   } else {
     vl_result := {