[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 e9ae4ef..c8724d7 100644 (file)
 
 /* This functions contains main() for cu_app */
 #include "common_def.h"
-#include "cu_stub.h"
 #include "cu_stub_sctp.h"
 #include "cu_stub_egtp.h"
-#include "du_log.h"
+#include "OCTET_STRING.h"
+#include "cu_f1ap_msg_hdl.h"
+#include "cu_stub.h"
 
 #ifdef O1_ENABLE
-#include "ConfigInterface.h"
-#endif
-
-#define CU_ID 1
-#define CU_NAME "ORAN_OAM_CU"
-
-#define DU_IP_V6_ADDR "0000:0000:0000:0000:0000:0000:0000:0001"
-#define CU_IP_V6_ADDR "0000:0000:0000:0000:0000:0000:0000:0011"
-
-#ifndef O1_ENABLE
-
-#define DU_IP_V4_ADDR "192.168.130.81"
-#define CU_IP_V4_ADDR "192.168.130.82"
-#define DU_PORT 38472
-#define CU_PORT 38472 
-
+#include "CmInterface.h"
 #endif
 
-#define DU_EGTP_PORT 39001
-#define CU_EGTP_PORT 39002
-#define RRC_VER 0
-#define EXT_RRC_VER 5
-#define PLMN_MCC0 3
-#define PLMN_MCC1 1
-#define PLMN_MCC2 1
-#define PLMN_MNC0 4
-#define PLMN_MNC1 8
-#define PLMN_MNC2 0
 
 #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;
+}
 
 /*******************************************************************
  *
@@ -160,10 +187,14 @@ uint8_t tst()
 
 void readCuCfg()
 {
+   uint8_t  *numDu;
    uint32_t ipv4_du, ipv4_cu;
 
    DU_LOG("\nDEBUG  -->  CU_STUB : Reading CU configurations");
 
+   cuCb.cuCfgParams.cuId = CU_ID;
+   strcpy(cuCb.cuCfgParams.cuName, CU_NAME);
+
 #ifdef O1_ENABLE
    if( getStartupConfigForStub(&g_cfg) != ROK )
    {
@@ -175,52 +206,91 @@ void readCuCfg()
    cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
    cmInetAddr((S8*)g_cfg.CU_IPV4_Addr, &ipv4_cu);
 
-   cuCfgParams.sctpParams.duPort = g_cfg.DU_Port;
-   cuCfgParams.sctpParams.cuPort = g_cfg.CU_Port;
+   cuCb.cuCfgParams.sctpParams.duPort = g_cfg.DU_Port;
+   cuCb.cuCfgParams.sctpParams.cuPort = g_cfg.CU_Port;
 #else
-   cmInetAddr((S8*)DU_IP_V4_ADDR, &ipv4_du);
-   cmInetAddr((S8*)CU_IP_V4_ADDR, &ipv4_cu);
-   cuCfgParams.sctpParams.duPort = DU_PORT;
-   cuCfgParams.sctpParams.cuPort = CU_PORT;
-#endif
-    
-   cuCfgParams.cuId = CU_ID;
-   strcpy(cuCfgParams.cuName, CU_NAME);
-   /* DU IP Address and Port*/
-   cuCfgParams.sctpParams.duIpAddr.ipV4Addr = ipv4_du;
-   cuCfgParams.sctpParams.duIpAddr.ipV6Pres = false;
+   cuCb.cuCfgParams.sctpParams.numDu = 0;
+   numDu = &cuCb.cuCfgParams.sctpParams.numDu;
+   while(*numDu < MAX_DU_SUPPORTED)
+   {
+      /* DU IP Address and Port*/
+      memset(&ipv4_du, 0, sizeof(uint32_t));
+      cmInetAddr((S8*)DU_IP_V4_ADDR[*numDu], &ipv4_du);
+      cuCb.cuCfgParams.sctpParams.sctpAssoc[*numDu].duIpAddr.ipV4Addr = ipv4_du;
+      cuCb.cuCfgParams.sctpParams.sctpAssoc[*numDu].duIpAddr.ipV6Pres = false;
+      cuCb.cuCfgParams.sctpParams.sctpAssoc[*numDu].duPort = DU_SCTP_PORT[*numDu];
+
+      /* CU IP Address and Port*/
+      memset(&ipv4_du, 0, sizeof(uint32_t));
+      cmInetAddr((S8*)CU_IP_V4_ADDR, &ipv4_cu);
+      cuCb.cuCfgParams.sctpParams.sctpAssoc[*numDu].cuIpAddr.ipV4Addr = ipv4_cu;
+      cuCb.cuCfgParams.sctpParams.sctpAssoc[*numDu].cuIpAddr.ipV6Pres = false;
+      cuCb.cuCfgParams.sctpParams.sctpAssoc[*numDu].cuPort = CU_SCTP_PORT_TO_DU[*numDu];
+      (*numDu)++;
+   }
 
-   /* CU IP Address and Port*/
-   cuCfgParams.sctpParams.cuIpAddr.ipV4Addr = ipv4_cu;
-   cuCfgParams.sctpParams.cuIpAddr.ipV6Pres = false;
+#endif
 
    /*PLMN*/
-   cuCfgParams.plmn.mcc[0] = PLMN_MCC0;
-   cuCfgParams.plmn.mcc[1] = PLMN_MCC1;
-   cuCfgParams.plmn.mcc[2] = PLMN_MCC2;
-   cuCfgParams.plmn.mnc[0] = PLMN_MNC0;
-   cuCfgParams.plmn.mnc[1] = PLMN_MNC1;
-   cuCfgParams.plmn.mnc[2] = PLMN_MNC2;
+   cuCb.cuCfgParams.plmn.mcc[0] = PLMN_MCC0;
+   cuCb.cuCfgParams.plmn.mcc[1] = PLMN_MCC1;
+   cuCb.cuCfgParams.plmn.mcc[2] = PLMN_MCC2;
+   cuCb.cuCfgParams.plmn.mnc[0] = PLMN_MNC0;
+   cuCb.cuCfgParams.plmn.mnc[1] = PLMN_MNC1;
+   cuCb.cuCfgParams.plmn.mnc[2] = PLMN_MNC2;
 
    /*RRC Version*/
-   cuCfgParams.rrcVersion.rrcVer = RRC_VER;
-   cuCfgParams.rrcVersion.extRrcVer = EXT_RRC_VER;
+   cuCb.cuCfgParams.rrcVersion.rrcVer = RRC_VER;
+   cuCb.cuCfgParams.rrcVersion.extRrcVer = EXT_RRC_VER;
 
 
    /* EGTP Parameters */
-   cuCfgParams.egtpParams.localIp.ipV4Pres = TRUE;
-   cuCfgParams.egtpParams.localIp.ipV4Addr = ipv4_cu;
-   cuCfgParams.egtpParams.localPort = CU_EGTP_PORT;
-   cuCfgParams.egtpParams.destIp.ipV4Pres = TRUE;
-   cuCfgParams.egtpParams.destIp.ipV4Addr = ipv4_du;
-   cuCfgParams.egtpParams.destPort = DU_EGTP_PORT;
-   cuCfgParams.egtpParams.minTunnelId = MIN_TEID;
-   cuCfgParams.egtpParams.currTunnelId = cuCfgParams.egtpParams.minTunnelId;
-   cuCfgParams.egtpParams.maxTunnelId = MAX_TEID;
+   cuCb.cuCfgParams.egtpParams.localIp.ipV4Pres = TRUE;
+   cuCb.cuCfgParams.egtpParams.localIp.ipV4Addr = ipv4_cu;
+   cuCb.cuCfgParams.egtpParams.localPort = CU_EGTP_PORT;
+   cuCb.cuCfgParams.egtpParams.destIp.ipV4Pres = TRUE;
+   cuCb.cuCfgParams.egtpParams.destIp.ipV4Addr = ipv4_du;
+   cuCb.cuCfgParams.egtpParams.destPort = DU_EGTP_PORT;
+   cuCb.cuCfgParams.egtpParams.minTunnelId = MIN_TEID;
+   cuCb.cuCfgParams.egtpParams.currTunnelId = cuCb.cuCfgParams.egtpParams.minTunnelId;
+   cuCb.cuCfgParams.egtpParams.maxTunnelId = MAX_TEID;
 
 } /* 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
@@ -243,10 +313,19 @@ void *cuConsoleHandler(void *args)
    uint8_t ret = ROK;
    uint8_t cnt = 0;
 
+   /* This variable is taken for sending specific number of downlink data packet. 
+    * Presently the code is supporting total 4500 data packets trasfer for 3 UEs only with sleep(1).
+    * If you wants to pump data for 3 UE change the following macro values
+    * NUM_TUNNEL_TO_PUMP_DATA = 9, NUM_DL_PACKETS = 1.
+    * totalDataPacket = totalNumOfTestFlow * NUM_TUNNEL_TO_PUMP_DATA * NUM_DL_PACKETS 
+    * totalDataPacket = [500*9*1] */
+   int32_t totalNumOfTestFlow = 500; 
+
    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 */
@@ -275,24 +354,46 @@ void *cuConsoleHandler(void *args)
             cnt++;
          }
 #else
-         for(teId = 1; teId <= NUM_TUNNEL_TO_PUMP_DATA; teId++)
+         while(totalNumOfTestFlow)
          {
-            DU_LOG("\nDEBUG  -->  EGTP: Sending DL User Data(teId:%d)\n",teId);
-            cnt =0;
-            while(cnt < NUM_DL_PACKETS)
+            for(teId = 1; teId <= NUM_TUNNEL_TO_PUMP_DATA; teId++)
             {
-               ret =  cuEgtpDatReq(teId);      
-               if(ret != ROK)
+               DU_LOG("\nDEBUG  -->  EGTP: Sending DL User Data(teId:%d)\n",teId);
+               cnt =0;
+               while(cnt < NUM_DL_PACKETS)
                {
-                  DU_LOG("\nERROR --> EGTP: Issue with teid=%d\n",teId);
-                  break;
+                  ret =  cuEgtpDatReq(teId);      
+                  if(ret != ROK)
+                  {
+                     DU_LOG("\nERROR --> EGTP: Issue with teid=%d\n",teId);
+                     break;
+                  }
+                  /* TODO : sleep(1) will be removed later once we will be able to
+                   * support the continuous data pack transfer */
+                  sleep(1);
+                  cnt++;
                }
-               cnt++;
             }
+            totalNumOfTestFlow--;
          }
 #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);
+      }
    }
 }
 /**********************************************************************