Memory handling fixes [Issue-ID: ODUHIGH-337]
[o-du/l2.git] / src / cu_stub / cu_stub.c
index c9a8daa..6c59800 100644 (file)
 #include "cu_stub_egtp.h"
 #include "du_log.h"
 
+#ifdef O1_ENABLE
+#include "ConfigInterface.h"
+#endif
+
 #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"
+
+#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 
+
+#endif
+
 #define DU_EGTP_PORT 39001
 #define CU_EGTP_PORT 39002
 #define RRC_VER 0
 #define PLMN_MNC1 8
 #define PLMN_MNC2 0
 
+#ifdef O1_ENABLE
+
+extern StartupConfig g_cfg;
+
+#endif
+
+
 /*******************************************************************
  *
  * @brief Handles SCTP notification 
@@ -64,7 +82,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);
 }
 /*******************************************************************
  *
@@ -87,8 +105,25 @@ void init_log()
 
 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();
 
@@ -125,26 +160,40 @@ uint8_t tst()
 
 void readCuCfg()
 {
-   U32 ipv4_du, ipv4_cu;
-
-   DU_LOG("\nReading CU configurations");
-
+   uint32_t ipv4_du, ipv4_cu;
+
+   DU_LOG("\nDEBUG  -->  CU_STUB : Reading CU configurations");
+
+#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);
+   cmInetAddr((S8*)g_cfg.CU_IPV4_Addr, &ipv4_cu);
+
+   cuCfgParams.sctpParams.duPort = g_cfg.DU_Port;
+   cuCfgParams.sctpParams.cuPort = g_cfg.CU_Port;
+#else
    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.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;
-   cuCfgParams.sctpParams.duPort = DU_PORT;
 
    /* CU IP Address and Port*/
    cuCfgParams.sctpParams.cuIpAddr.ipV4Addr = ipv4_cu;
    cuCfgParams.sctpParams.cuIpAddr.ipV6Pres = false;
-   cuCfgParams.sctpParams.cuPort = CU_PORT;
 
    /*PLMN*/
    cuCfgParams.plmn.mcc[0] = PLMN_MCC0;
@@ -170,6 +219,36 @@ void readCuCfg()
    cuCfgParams.egtpParams.maxTunnelId = 10;
 
 } /* End of readCuCfg */
+
+/*******************************************************************
+ *
+ * @brief Handles Console input
+ *
+ * @details
+ *
+ *    Function : cuConsoleHandler
+ *
+ *    Functionality: Handles Console input
+ *
+ * @params[in] 
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+void *cuConsoleHandler(void *args)
+{
+   char ch;
+   while(true) 
+   {
+      /* Send DL user data to CU when user enters 'd' on console */
+      if((ch = getchar()) == 'd')
+      {
+         /* Start Pumping data from CU to DU */
+         DU_LOG("\nDEBUG  -->  EGTP: Sending DL User Data");
+         cuEgtpDatReq();      
+      } 
+   }
+}
 /**********************************************************************
          End of file
 **********************************************************************/