[Epic-ID: ODUHIGH-516][Task-ID: ODUHIGH-530] Handling of Ric action deletion
[o-du/l2.git] / src / 5gnrmac / mac_cfg_hdl.c
index 0572fd7..c682a66 100644 (file)
@@ -70,6 +70,12 @@ MacDuStatsRspFunc macDuStatsRspOpts[] =
    packDuMacStatsRsp   /* packing for light weight loosly coupled */
 };
 
+MacDuStatsDeleteRspFunc macDuStatsDeleteRspOpts[] =
+{
+   packDuMacStatsDeleteRsp,   /* packing for loosely coupled */
+   DuProcMacStatsDeleteRsp,   /* packing for tightly coupled */
+   packDuMacStatsDeleteRsp   /* packing for light weight loosly coupled */
+};
 
 /**
  * @brief Layer Manager  Configuration request handler for Scheduler
@@ -1335,6 +1341,189 @@ uint8_t MacProcSchStatsRsp(Pst *pst, SchStatsRsp *schStatsRsp)
    return ret;
 }
 
+/**
+ * @brief Fill and send statistics delete response to DU APP
+ *
+ * @details
+ *
+ *     Function : MacSendStatsDeleteRspToDuApp
+ *
+ *     Fill and send statistics delete response to DU APP
+ *  [Step-1] In SCH delete response is received, fill MAC stats delete 
+ *    response with info from SCH stats delete response.
+ *  [Step-2] If a failure occurs while processing MAC stats delete request, 
+ *    then fill MAC stats delete rsp with failure using info from MAC stats delete request.
+ *  [Step-3] Else if numStatsGroup > 0, then send stats delete response 
+ *    with deletion status of each stats group.
+ *  [Step-4] If numStatsGroup = 0, send Stats delete response 
+ *    for deletion of complete subscription.
+ *
+ *  @param[in]  SchStatsDeleteRsp
+ *  @param[in]  MacStatsDeleteReq
+ *  @return  int
+ *      -# ROK
+ **/
+uint8_t MacSendStatsDeleteRspToDuApp(SchStatsDeleteRsp *schStatsDeleteRsp,  MacStatsDeleteReq *macStatsDeleteReq)
+{
+   Pst  pst;
+   uint8_t ret = ROK, idx=0;
+   MacStatsDeleteRsp *macStatsDeleteRsp=NULLP;
+
+   MAC_ALLOC_SHRABL_BUF(macStatsDeleteRsp, sizeof(MacStatsDeleteRsp));
+   if(macStatsDeleteRsp == NULLP)
+   {
+      DU_LOG("\nERROR  -->  MAC : Failed to allocate memory in MacProcSchStatsDeleteRsp");
+      ret = RFAILED;
+   }
+   
+   if(schStatsDeleteRsp)
+   {
+      /* [Step-1] */ 
+      macStatsDeleteRsp->subscriptionId = schStatsDeleteRsp->subscriptionId;
+      macStatsDeleteRsp->numStatsGroupDeleted = schStatsDeleteRsp->numStatsGroupDeleted;
+
+      if(macStatsDeleteRsp->numStatsGroupDeleted)
+      {
+         /* [Step-3] */ 
+         for(idx =0;idx<macStatsDeleteRsp->numStatsGroupDeleted; idx++)
+         {
+            if(schStatsDeleteRsp->statsGrpDelInfo[idx].statsGrpDelRsp == RSP_OK)
+            {
+               macStatsDeleteRsp->statsGrpDelInfo[idx].statsGrpDelRsp =MAC_DU_APP_RSP_OK;
+               macStatsDeleteRsp->statsGrpDelInfo[idx].statsGrpDelCause =schStatsDeleteRsp->statsGrpDelInfo[idx].statsGrpDelCause;
+            }
+            else
+            {
+               macStatsDeleteRsp->statsGrpDelInfo[idx].statsGrpDelRsp =MAC_DU_APP_RSP_NOK;
+               macStatsDeleteRsp->statsGrpDelInfo[idx].statsGrpDelCause =schStatsDeleteRsp->statsGrpDelInfo[idx].statsGrpDelCause;
+            }
+         }
+      }
+      else
+      {
+         /* [Step-4] */ 
+         if(schStatsDeleteRsp->subsDelRsp == RSP_OK)
+            macStatsDeleteRsp->subsDelRsp = MAC_DU_APP_RSP_OK;
+         else
+            macStatsDeleteRsp->subsDelRsp = MAC_DU_APP_RSP_NOK;
+         macStatsDeleteRsp->subsDelCause = schStatsDeleteRsp->subsDelCause;
+      }
+   }
+   else
+   {
+      /* [Step-2] */ 
+      macStatsDeleteRsp->subscriptionId = macStatsDeleteReq->subscriptionId;
+      macStatsDeleteRsp->numStatsGroupDeleted= macStatsDeleteReq->numStatsGroupToBeDeleted;
+      
+      if(macStatsDeleteRsp->numStatsGroupDeleted)
+      {
+         /* [Step-3] */ 
+         for(idx =0;idx<macStatsDeleteRsp->numStatsGroupDeleted; idx++)
+         {
+            macStatsDeleteRsp->statsGrpDelInfo[idx].statsGrpDelRsp =MAC_DU_APP_RSP_NOK;
+            macStatsDeleteRsp->statsGrpDelInfo[idx].statsGrpDelCause = RESOURCE_UNAVAILABLE;
+         }
+      }
+      else
+      {
+         /* [Step-4] */ 
+         macStatsDeleteRsp->subsDelRsp = MAC_DU_APP_RSP_NOK;
+         macStatsDeleteRsp->subsDelCause = RESOURCE_UNAVAILABLE;
+      }
+   }
+
+   DU_LOG("\nINFO  -->  MAC : MacSendStatsDeleteRspToDuApp: Sending Delete Statistics Response to DU APP");
+
+   memset(&pst, 0, sizeof(Pst));
+   FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_STATS_DELETE_RSP);
+   if(((*macDuStatsDeleteRspOpts[pst.selector])(&pst, macStatsDeleteRsp))!= ROK)
+   {
+      DU_LOG("\nERROR  -->  MAC : Failed to send statistics delete response to DU APP");
+      MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, macStatsDeleteRsp, sizeof(MacStatsDeleteRsp));
+      ret = RFAILED;
+   }
+
+   return ret;
+}
+                 
+/**
+ * @brief Mac process the statistics delete rsp received from sch.
+ *
+ * @details
+ *
+ *     Function : MacProcSchStatsDeleteRsp
+ *
+ *     This function  process the statistics delete response received from sch
+ *
+ *  @param[in]  Pst           *pst
+ *  @param[in]  SchStatsDeleteRsp *schStatsDeleteRsp
+ *  @return  int
+ *      -# ROK
+ **/
+uint8_t MacProcSchStatsDeleteRsp(Pst *pst, SchStatsDeleteRsp *schStatsDeleteRsp)
+{
+   uint8_t ret = RFAILED;
+
+   if(schStatsDeleteRsp)
+   {
+      ret = MacSendStatsDeleteRspToDuApp(schStatsDeleteRsp, NULLP);
+      MAC_FREE(schStatsDeleteRsp, sizeof(SchStatsDeleteRsp));
+   }
+   return ret;
+}
+
+/**
+ * @brief Mac process the statistics delete Req received from DUAPP
+ *
+ * @details
+ *
+ *     Function : MacProcStatsDeleteReq
+ *
+ *     Functionality: Process the statistics delete request from duapp
+ *  @param[in]  Pst      *pst
+ *  @param[in]  StatsDeleteReq *statsReq
+ *  @return  int
+ *      -# ROK
+ **/
+
+uint8_t MacProcStatsDeleteReq(Pst *pst, MacStatsDeleteReq *macStatsDeleteReq)
+{
+   Pst       schPst;
+   uint8_t   ret = RFAILED;
+   SchStatsDeleteReq  *schStatsDeleteReq = NULLP;
+   DU_LOG("\nINFO   -->  MAC : Received Statistics delete Request from DU_APP");
+
+   if(macStatsDeleteReq == NULLP)
+   {
+      DU_LOG("\nERROR  -->  MAC : MacProcStatsDeleteReq(): Received Null pointer");
+      return RFAILED;
+   }
+   
+   MAC_ALLOC(schStatsDeleteReq, sizeof(SchStatsDeleteReq));
+   if(schStatsDeleteReq == NULLP)
+   {
+      DU_LOG("\nERROR  -->  MAC : MacProcStatsDeleteReq: Failed to allocate memory");
+   }
+   else
+   {
+      /* fill all the information in schStatsDeleteReq structure */
+      schStatsDeleteReq->subscriptionId = macStatsDeleteReq->subscriptionId;
+      schStatsDeleteReq->numStatsGroupToBeDeleted = macStatsDeleteReq->numStatsGroupToBeDeleted;
+      memcpy(&schStatsDeleteReq->statsGrpIdToBeDelList, &macStatsDeleteReq->statsGrpIdToBeDelList, schStatsDeleteReq->numStatsGroupToBeDeleted*sizeof(uint8_t)); 
+      FILL_PST_MAC_TO_SCH(schPst, EVENT_STATISTICS_DELETE_REQ_TO_SCH);
+      ret = SchMessageRouter(&schPst, (void *)schStatsDeleteReq);
+   }
+
+   if(ret != ROK)
+   {
+      ret = MacSendStatsDeleteRspToDuApp(NULLP, macStatsDeleteReq);
+   }
+
+   MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macStatsDeleteReq, sizeof(MacStatsDeleteReq));
+   return ret;
+}
+
 /**********************************************************************
   End of file
  **********************************************************************/