[Epic-ID: ODUHIGH-516][Task-ID: ODUHIGH-529] RIC Indication
[o-du/l2.git] / src / du_app / du_msg_hdl.c
index 6502840..a99b7db 100644 (file)
@@ -29,6 +29,7 @@
 #include "du_app_mac_inf.h"
 #include "du_app_rlc_inf.h"
 #include "du_e2ap_mgr.h"
+#include "du_e2ap_msg_hdl.h"
 #include "du_cfg.h"
 #include "du_app_rlc_inf.h"
 #include "du_mgr.h"
@@ -2093,12 +2094,9 @@ uint8_t DuProcRlcSliceMetrics(Pst *pst, SlicePmList *sliceStats)
  *         RFAILED - failure
  *
  * ****************************************************************/
-uint8_t BuildAndSendStatsReqToMac(uint64_t subscriptionId, RicSubscription *ricSubscriptionInfo)
+uint8_t BuildAndSendStatsReqToMac(RicSubscription *ricSubscriptionInfo)
 {
    Pst pst;
-   uint8_t    actionIdx = 0, grpIdx = 0, statsIdx = 0;
-   ActionInfo *actionDb = NULLP;
-   ActionDefFormat1 *format1Action = NULLP;
    MacStatsReq *macStatsReq = NULLP;
 
    /* Fill MAC statistics request */
@@ -2109,64 +2107,8 @@ uint8_t BuildAndSendStatsReqToMac(uint64_t subscriptionId, RicSubscription *ricS
       return RFAILED;
    }
 
-   macStatsReq->subscriptionId = subscriptionId;
-   for(actionIdx = 0; actionIdx < ricSubscriptionInfo->numOfActions; actionIdx++)
-   {
-      if(ricSubscriptionInfo->actionSequence[actionIdx].action == CONFIG_ADD)
-      {
-         actionDb = &ricSubscriptionInfo->actionSequence[actionIdx];
-         macStatsReq->statsGrpList[grpIdx].groupId = actionDb->id;
-         switch(actionDb->definition.formatType)
-         {
-            case 1:
-               {
-                  format1Action = &actionDb->definition.choice.format1;
-                  macStatsReq->statsGrpList[grpIdx].periodicity = format1Action->granularityPeriod;
-
-                  CmLList *node = NULLP;
-                  MeasurementInfo *measInfo = NULLP;
-                  statsIdx = 0;
-                  /* Update DL PRB Usage for all stats group which requested for DL Total PRB Usage */
-                  node = cmLListFirst(&format1Action->measurementInfoList);
-                  while(node)
-                  {
-                     measInfo = (MeasurementInfo *)(node->node);
-                     switch(measInfo->measurementTypeId)
-                     {
-                        case 1:
-                           {
-                              macStatsReq->statsGrpList[grpIdx].statsList[statsIdx++] = MAC_DL_TOTAL_PRB_USAGE;
-                              break;
-                           }
-                        case 2:
-                           {
-                              macStatsReq->statsGrpList[grpIdx].statsList[statsIdx++] = MAC_UL_TOTAL_PRB_USAGE;
-                              break;
-                           }
-                        default:
-                           {
-                              DU_LOG("\nERROR  -->  DU_APP : Invalid measurement name BuildAndSendStatsReqToMac");
-                              break;
-                           }
-                     }
-                     node = node->next;
-                  }
-                  macStatsReq->statsGrpList[grpIdx].numStats = statsIdx;
-                  break;
-               }
-            default:
-               {
-                  DU_LOG("\nERROR  -->  DU_APP : BuildAndSendStatsReqToMac: Only Action Definition Format 1 supported");
-                  break;
-               }
-         }
-         if(macStatsReq->statsGrpList[grpIdx].numStats)
-            grpIdx++;
-      }
-   }
-   macStatsReq->numStatsGroup = grpIdx;
-
-   if(macStatsReq->numStatsGroup)
+   /* Fill E2 Subscription Info in MAC Statistics Request and send to MAC */
+   if(fillRicSubsInMacStatsReq(macStatsReq, ricSubscriptionInfo) == ROK)
    {
       DU_LOG("\nDEBUG  -->  DU_APP: Sending Statistics Request to MAC ");
       FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_STATISTICS_REQ);
@@ -2182,44 +2124,6 @@ uint8_t BuildAndSendStatsReqToMac(uint64_t subscriptionId, RicSubscription *ricS
    return RFAILED;
 }
 
-/*******************************************************************
- *
- * @brief Fetch statistics details from Action Definition Format 1
- *
- * @details
- *
- *    Function : FetchStatsFromActionDefFormat1()
- *
- *    Functionality: Fetch statistics details from Action 
- *       Definition Format 1 received in an E2 message from 
- *       RIC.
- *
- * @params[in] ActionDefFormat1
- *
- * @return Statistics
- *
- * ****************************************************************/
-Statistics FetchStatsFromActionDefFormat1(ActionDefFormat1 format1)
-{
-   Statistics stats;
-
-   /* TODO : When E2AP subscription procedure is implemented:
-    * Measurement info list is traveresed 
-    * Based on KPI type, stats.macStatsReq or stats.rlcstatsReq is filled */
-
-   /* Hardcoding values for now for testing purpose 
-    * Will be removed in next gerrit */
-   stats.macStatsReq.subscriptionId = 1;
-   stats.macStatsReq.numStatsGroup = 1;
-   stats.macStatsReq.statsGrpList[0].groupId = 1;
-   stats.macStatsReq.statsGrpList[0].periodicity = 100;
-   stats.macStatsReq.statsGrpList[0].numStats = 2;
-   stats.macStatsReq.statsGrpList[0].statsList[0] = MAC_DL_TOTAL_PRB_USAGE;
-   stats.macStatsReq.statsGrpList[0].statsList[1] = MAC_UL_TOTAL_PRB_USAGE;
-
-   return stats;
-}
-
 /*******************************************************************
  *
  * @brief Send Statistics request to DU layers
@@ -2238,22 +2142,10 @@ Statistics FetchStatsFromActionDefFormat1(ActionDefFormat1 format1)
  *         RFAILED - failure
  *
  * ****************************************************************/
-uint8_t BuildAndSendStatsReq(uint16_t ranFuncId, RicSubscription *ricSubscriptionInfo)
+uint8_t BuildAndSendStatsReq(RicSubscription *ricSubscriptionInfo)
 {
-   uint64_t   subscriptionId = 0; 
-
-   /* Calculate 64 bit subscription-ID :
-    *  First 16 MSB is unused
-    *  Next 16 MSB = RAN-Function-ID
-    *  Next 16 MSB = Requestor-ID in RIC-Request-ID
-    *  Last 16 LSB = Instance-ID in RIC-Request-ID
-    */
-   subscriptionId = ricSubscriptionInfo->requestId.instanceId;
-   subscriptionId |= ((uint64_t)ricSubscriptionInfo->requestId.requestorId << 16);
-   subscriptionId |= ((uint64_t)ranFuncId << 32);
-
    /* Build and sent subscription information to MAC in Statistics Request */
-   if(BuildAndSendStatsReqToMac(subscriptionId, ricSubscriptionInfo) != ROK)
+   if(BuildAndSendStatsReqToMac(ricSubscriptionInfo) != ROK)
    {
       DU_LOG("\nERROR  -->  DU_APP : Failed at BuildAndSendStatsReqToMac()");
       return RFAILED;   
@@ -2293,6 +2185,7 @@ uint8_t BuildAndSendStatsReq(uint16_t ranFuncId, RicSubscription *ricSubscriptio
  * ****************************************************************/
 uint8_t DuProcMacStatsRsp(Pst *pst, MacStatsRsp *statsRsp)
 {
+   uint8_t ret = RFAILED;
    DU_LOG("\nINFO  -->  DU_APP : DuProcMacStatsRsp: Received Statistics Response from MAC");
 
    if(statsRsp)
@@ -2310,30 +2203,24 @@ uint8_t DuProcMacStatsRsp(Pst *pst, MacStatsRsp *statsRsp)
       DU_LOG("\n  Number of Rejected Groups [%d]", statsRsp->numGrpRejected);
       for(idx=0; idx<statsRsp->numGrpRejected; idx++)
       {
-         DU_LOG("\n    Group Id [%d]", statsRsp->statsGrpRejectedList[idx]);
+         DU_LOG("\n    Group Id [%d]", statsRsp->statsGrpRejectedList[idx].groupId);
       }
 #endif      
-     
-      /* TODO :
-       * For accepted groups:
-       *    Mark scubscrbed-action's -> action = CONFIG_UNKNOWN
-       *    Add action ID to accpeted-action-list in Subscription response
-       *
-       * For rejected groups:
-       *    Remove entry from DU's RAN Function->subscription->actionList
-       *    Add Rejected action Id to reject-action-list created by DU APP while
-       *     processing of subscription request.
-       *
-       * Send subscription response with accepted and rejected action lists to
-       * RIC
-       */
+
+      /* Check the list of accepted and rejected statistics group and send
+       * Ric subscription response/failure accordingly */
+      if((ret = e2ProcStatsRsp(statsRsp)) != ROK)
+      {
+         DU_LOG("\nERROR  -->  DU_APP : DuProcMacStatsRsp: Failed in %s at line %d", __func__, __LINE__);
+      }
 
       DU_FREE_SHRABL_BUF(pst->region, pst->pool, statsRsp, sizeof(MacStatsRsp));
-      return ROK;
    }
-
-   DU_LOG("\nERROR  -->  DU_APP : DuProcMacStatsRsp: Received NULL Pointer");
-   return RFAILED;
+   else
+   {
+      DU_LOG("\nERROR  -->  DU_APP : DuProcMacStatsRsp: Received NULL Pointer");
+   }
+   return ret;
 }
 
 /*******************************************************************
@@ -2354,6 +2241,8 @@ uint8_t DuProcMacStatsRsp(Pst *pst, MacStatsRsp *statsRsp)
  * ****************************************************************/
 uint8_t DuProcMacStatsInd(Pst *pst, MacStatsInd *statsInd)
 {
+   uint8_t ret = RFAILED;
+
    if(statsInd)
    {
 #ifdef DEBUG_PRINT   
@@ -2367,19 +2256,20 @@ uint8_t DuProcMacStatsInd(Pst *pst, MacStatsInd *statsInd)
       }
 #endif      
 
-      /* TODO : When stats indication is received
-       * DU APP searches for the message type in E2AP RIC subscription database
-       * and stores in the value in the list of subscribed measurements
-       *
-       * This will be implemented in next gerrit.
-       */
+      /* Extract statistics from statistics indication message and store in E2 DB */
+      if((ret = e2ProcStatsInd(statsInd)) != ROK)
+      {
+          DU_LOG("\nINFO  -->  DU_APP : Failed in %s at line %d", __func__, __LINE__);
+      }
 
+      /* Free statistics indication */
       DU_FREE_SHRABL_BUF(pst->region, pst->pool, statsInd, sizeof(MacStatsInd));
-      return ROK;
    }
-   
-   DU_LOG("\nINFO  -->  DU_APP : DuProcMacStatsInd: Received NULL Pointer");
-   return RFAILED;
+   else
+   {
+      DU_LOG("\nINFO  -->  DU_APP : DuProcMacStatsInd: Received NULL Pointer");
+   }
+   return ret;
 }
 
 /**********************************************************************