[Epic-ID: ODUHIGH-406][Task-ID: ODUHIGH-423] UE context setup request from CU to...
[o-du/l2.git] / src / cu_stub / cu_stub.c
index 3663201..31515a4 100644 (file)
 
 /* This functions contains main() for cu_app */
 #include "common_def.h"
-#include "odu_common_codec.h"
-#include "cu_stub.h"
 #include "cu_stub_sctp.h"
 #include "cu_stub_egtp.h"
-#include "du_log.h"
-
-#define CU_ID 1
-#define CU_NAME "ORAN_OAM_CU"
-#define DU_IP_V4_ADDR "192.168.130.81"
-#define CU_IP_V4_ADDR "192.168.130.82"
-#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"
-#define DU_PORT 38472
-#define CU_PORT 38472 
-#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
+#include "OCTET_STRING.h"
+#include "cu_f1ap_msg_hdl.h"
+#include "cu_stub.h"
+
+#ifdef O1_ENABLE
+#include "CmInterface.h"
+#endif
+
+
+#ifdef O1_ENABLE
+extern StartupConfig g_cfg;
+#endif
 
 /*******************************************************************
  *
@@ -65,7 +55,7 @@ void sctpNtfyInd(CmInetSctpNotification *ntfy)
 
 void init_log()
 {
-       openlog("CU_STUB",LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
+    openlog("CU_STUB",LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
 }
 /*******************************************************************
  *
@@ -86,10 +76,27 @@ void init_log()
  *
  * ****************************************************************/
 
-S16 tst()
+uint8_t tst()
 {
+   int retVal=0;
+   pthread_t conThrdId;
+   pthread_attr_t attr;
+
    init_log();   
-   DU_LOG("\nStarting CU_STUB");
+   DU_LOG("\nINFO   -->  CU_STUB : Starting CU_STUB\n");
+
+   /* Start thread to receive console input */
+   pthread_attr_init(&attr);
+   pthread_attr_setstacksize(&attr, (size_t)NULLD);
+   pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
+   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+   retVal = pthread_create(&conThrdId, &attr, cuConsoleHandler, NULLP);
+   if(retVal != 0)
+   {
+      DU_LOG("\nERROR  -->  CU_STUB :  Thread creation failed. Cause %d", retVal);
+   }
+   pthread_attr_destroy(&attr);
+
    /* Read CU configurations */
    readCuCfg();
 
@@ -104,7 +111,7 @@ S16 tst()
    sctpCfgReq();
    sctpStartReq();
 
-   RETVALUE(ROK);
+   return ROK;
 }
 
 /*******************************************************************
@@ -126,51 +133,226 @@ S16 tst()
 
 void readCuCfg()
 {
-   U32 ipv4_du, ipv4_cu;
+   uint8_t  *numDu;
+   uint32_t ipv4_du, ipv4_cu;
 
-   DU_LOG("\nReading CU configurations");
+   DU_LOG("\nDEBUG  -->  CU_STUB : Reading CU configurations");
 
-   cmInetAddr((S8*)DU_IP_V4_ADDR, &ipv4_du);
-   cmInetAddr((S8*)CU_IP_V4_ADDR, &ipv4_cu);
-   //U32 ipv6_int = inet_addr(DU_IP_V6_ADDR);
-   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;
-   cuCfgParams.sctpParams.duPort = DU_PORT;
+   cuCb.cuCfgParams.cuId = CU_ID;
+   strcpy(cuCb.cuCfgParams.cuName, CU_NAME);
 
-   /* CU IP Address and Port*/
-   cuCfgParams.sctpParams.cuIpAddr.ipV4Addr = ipv4_cu;
-   cuCfgParams.sctpParams.cuIpAddr.ipV6Pres = false;
-   cuCfgParams.sctpParams.cuPort = CU_PORT;
+#ifdef O1_ENABLE
+   if( getStartupConfigForStub(&g_cfg) != ROK )
+   {
+      DU_LOG("\nError  -->  CU_STUB : Could not fetch startup "\
+             "configurations from Netconf interface\n");
+      exit(1);
+   }
+   
+   cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
+   cuCb.cuCfgParams.sctpParams.sctpAssoc[0].duIpAddr.ipV4Addr = ipv4_du;
+   cuCb.cuCfgParams.sctpParams.sctpAssoc[0].duIpAddr.ipV6Pres = false;
+   
+   cmInetAddr((S8*)g_cfg.CU_IPV4_Addr, &ipv4_cu);
+   cuCb.cuCfgParams.sctpParams.sctpAssoc[0].cuIpAddr.ipV4Addr = ipv4_cu;
+   cuCb.cuCfgParams.sctpParams.sctpAssoc[0].cuIpAddr.ipV6Pres = false;
+   
+   cuCb.cuCfgParams.sctpParams.sctpAssoc[0].duPort = g_cfg.DU_Port;
+   cuCb.cuCfgParams.sctpParams.sctpAssoc[0].cuPort = g_cfg.CU_Port; 
+   cuCb.cuCfgParams.sctpParams.numDu = 1;
+#else
+   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)++;
+   }
+
+#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 = 0;
-   cuCfgParams.egtpParams.maxTunnelId = 10;
+   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)
+{
+    uint8_t duIdx = 0;
+    DuDb *duDb = NULLP;
+    CuUeCb *ueCb = NULLP;
+   
+    SEARCH_DU_DB(duIdx, sourceDuId, duDb); 
+    if(duDb)
+       ueCb = &duDb->ueCb[ueId-1];
+    if(ueCb)
+    {
+       ueCb->state = UE_HANDOVER_IN_PROGRESS;
+       ueCb->hoInfo.sourceDuId = sourceDuId;
+       ueCb->hoInfo.targetDuId = targetDuId;
+    }
+
+    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
+ *
+ * @details
+ *
+ *    Function : cuConsoleHandler
+ *
+ *    Functionality: Handles Console input
+ *
+ * @params[in] 
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+void *cuConsoleHandler(void *args)
+{
+   char ch;
+   uint8_t teId = 0;
+   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 == 'd')
+      {
+
+      /* Change #if 0 to #if 1 to take input from user */
+#if 0
+         DU_LOG("\n EGTP --> : Enter TEID id(1..10) where DL Data to be sent\n");
+         scanf("%d",&teId);
+         
+         if(teId > MAX_TEID || teId < MIN_TEID)
+         {
+            DU_LOG("\nERROR  -->  EGTP : TEID(%x) OUT Of Range",teId);
+            printf("\n");
+            continue;
+         }
+         /* Start Pumping data from CU to DU */
+         DU_LOG("\nDEBUG  -->  EGTP: Sending DL User Data(teId:%d)\n",teId);
+
+         cnt =0;
+         while(cnt < NUM_DL_PACKETS)
+         {
+            ret =  cuEgtpDatReq(teId);
+            if(ret != ROK)
+            {
+               DU_LOG("\nERROR --> EGTP: Issue with teid=%d\n",teId);
+               break;
+            }
+            cnt++;
+         }
+#else
+         while(totalNumOfTestFlow)
+         {
+            for(teId = 1; teId <= NUM_TUNNEL_TO_PUMP_DATA; teId++)
+            {
+               DU_LOG("\nDEBUG  -->  EGTP: Sending DL User Data(teId:%d)\n",teId);
+               cnt =0;
+               while(cnt < NUM_DL_PACKETS)
+               {
+                  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++;
+               }
+            }
+            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);
+      }
+   }
+}
 /**********************************************************************
          End of file
 **********************************************************************/