[Epic-ID: ODUHIGH-405][Task-ID: ODUHIGH-420] GNB-DU Configuration Query and response
[o-du/l2.git] / src / cu_stub / cu_stub.c
index 8dafe67..c8724d7 100644 (file)
@@ -20,6 +20,8 @@
 #include "common_def.h"
 #include "cu_stub_sctp.h"
 #include "cu_stub_egtp.h"
+#include "OCTET_STRING.h"
+#include "cu_f1ap_msg_hdl.h"
 #include "cu_stub.h"
 
 #ifdef O1_ENABLE
 
 
 #ifdef O1_ENABLE
-
 extern StartupConfig g_cfg;
-
 #endif
 
+/*******************************************************************
+ *
+ * @brief Fetches pointer to DU Database
+ *
+ * @details
+ *
+ *    Function : getDuDb
+ *
+ *    Functionality:
+ *      Searches and returns pointer to DU structure based on DU Id
+ *
+ * @params[in] DU Id
+ * @return Pointer to DU Db
+ *
+ ******************************************************************/
+DuDb* getDuDb(uint32_t duId)
+{
+   uint8_t duIdx;
+   for(duIdx=0; duIdx < cuCb.numDu; duIdx++)
+   {
+      if(cuCb.duInfo[duIdx].duId == duId)
+         return (&cuCb.duInfo[duIdx]);
+   }
+   return NULLP;
+}
+
+/*******************************************************************
+ *
+ * @brief Fetches pointer to Cell Cb
+ *
+ * @details
+ *
+ *    Function : getCellCb
+ *
+ *    Functionality:
+ *       Searches for a cell within a DU based on NR cell Id
+ *       Returns pointer to this cell Cb structure
+ *
+ * @params[in] Pointer to DU Db
+ *             NR Cell ID
+ * @return Pointer to cell Cb
+ *
+ ******************************************************************/
+CuCellCb* getCellCb(DuDb *duDb, uint32_t cellId)
+{
+   uint8_t cellIdx;
+   for(cellIdx=0; cellIdx < duDb->numCells; cellIdx++)
+   {
+      if(duDb->cellCb[cellIdx].nrCellId == cellId)
+         return &(duDb->cellCb[cellIdx]);
+   }
+   return NULLP;
+}
 
 /*******************************************************************
  *
@@ -204,6 +257,40 @@ void readCuCfg()
 
 } /* End of readCuCfg */
 
+/*******************************************************************
+ *
+ * @brief Initiates inter DU handover
+ *
+ * @details
+ *
+ *    Function : initiateInterDuHandover
+ *
+ *    Functionality: Initiates the first procedure of inter-DU
+ *    handover i.eG GNB-DU configuration query to source DU
+ *
+ * @params[in] Source DU Id
+ *             Target DU Id
+ *             UE Id to be handed off 
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+void initiateInterDuHandover(uint32_t sourceDuId, uint32_t targetDuId, uint32_t ueId)
+{
+    DuDb *duDb = NULLP;
+    CuUeCb *ueCb = NULLP;
+
+    duDb = getDuDb(sourceDuId);
+    if(duDb)
+       ueCb = &duDb->ueCb[ueId-1];
+    if(ueCb)
+       ueCb->state = HANDOVER_IN_PROGRESS;
+
+    DU_LOG("\nINFO  --> CU_STUB: Inter-DU Handover Started for ueId [%d] from DU ID [%d] to DU ID [%d]", \
+          ueId, sourceDuId, targetDuId);
+    BuildAndSendUeContextModificationReq(sourceDuId, ueCb, QUERY_CONFIG);
+}
+
 /*******************************************************************
  *
  * @brief Handles Console input
@@ -236,8 +323,9 @@ void *cuConsoleHandler(void *args)
 
    while(true) 
    {
+      ch = getchar();
       /* Send DL user data to CU when user enters 'd' on console */
-      if((ch = getchar()) == 'd')
+      if(ch == 'd')
       {
 
       /* Change #if 0 to #if 1 to take input from user */
@@ -291,6 +379,21 @@ void *cuConsoleHandler(void *args)
 #endif
          continue;
       } 
+
+      /* Start Handover procedure towards DU when 'h' is received from console input */
+      else if(ch == 'h')
+      {
+         uint32_t sourceDuId, targetDuId, ueId;
+
+         DU_LOG("\nEnter Source DU ID for Inter-DU Handover");
+         scanf("%d", &sourceDuId);
+         DU_LOG("\nEnter Target DU ID for Inter-DU Handover");
+         scanf("%d", &targetDuId);
+         DU_LOG("\nEnter DU UE F1AP ID to be handed over");
+         scanf("%d", &ueId);
+
+         initiateInterDuHandover(sourceDuId, targetDuId, ueId);
+      }
    }
 }
 /**********************************************************************