[Epic-ID: ODUHIGH-516][Task-ID: ODUHIGH-530] RIC Subscription Modification Req
[o-du/l2.git] / src / du_app / du_e2ap_mgr.c
index 6bdbe58..eabc0d6 100644 (file)
@@ -640,6 +640,9 @@ uint8_t e2ProcStatsRsp(MacStatsRsp *statsRsp)
    }
    else
    {
+      /* Once RIC subscription is successful, mark the config action as unknown */
+      ricSubscriptionInfo->action = CONFIG_UNKNOWN;
+
       /* Start RIC Subscription reporting timer */
       switch(ricSubscriptionInfo->eventTriggerDefinition.formatType)
       {
@@ -893,13 +896,13 @@ void E2apHdlRicSubsReportTmrExp(RicSubscription *ricSubscription)
  *
  * @params[in] 
  *       Type of interface 
- *       Component action type
+ *       Component Id
  *       Pointer to E2 component node to be searched 
  * @return CmLList
  *
  * ****************************************************************/
 
-E2NodeComponent *fetchE2NodeComponentInfo(InterfaceType interfaceType, uint8_t componentActionType, CmLList **e2ComponentNode)
+E2NodeComponent *fetchE2NodeComponentInfo(InterfaceType interfaceType, uint64_t componentId, CmLList **e2ComponentNode)
 {
    E2NodeComponent *e2NodeComponentInfo=NULLP;
 
@@ -909,9 +912,8 @@ E2NodeComponent *fetchE2NodeComponentInfo(InterfaceType interfaceType, uint8_t c
       while(*e2ComponentNode)
       {
          e2NodeComponentInfo = (E2NodeComponent*)((*e2ComponentNode)->node);
-         if((e2NodeComponentInfo->interfaceType == interfaceType) && (e2NodeComponentInfo->componentActionType == componentActionType))
+         if((e2NodeComponentInfo->interfaceType == interfaceType) && (e2NodeComponentInfo->componentId == componentId))
          {
-            
             break;
          }
          
@@ -924,18 +926,86 @@ E2NodeComponent *fetchE2NodeComponentInfo(InterfaceType interfaceType, uint8_t c
 
 /*******************************************************************
  *
- * @brief add or modify E2NodeComponent list
+ * @brief fill E2 node component rsp info
  *
  * @details
  *
- *    Function : addOrModifyE2NodeComponent 
+ *    Function : fillE2NodeComponentRspInfo 
  *
- * Functionality: add or modify E2NodeComponent list 
+ * Functionality: fill E2 Node Component rsp info 
+ *
+ * @parameter
+ *       Type of interface 
+ *       Component action type
+ *       Size of buffer which needs to be store
+ *       buffer string which needs to be store 
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+
+uint8_t fillE2NodeComponentRspInfo(InterfaceType interfaceType, uint64_t componentId, uint8_t action, uint8_t bufSize, char *bufString)
+{
+   E2NodeConfig *configInfo=NULLP;
+   E2NodeComponent *e2NodeComponentInfo= NULLP;
+   CmLList  *node = NULLP;
+
+   e2NodeComponentInfo = fetchE2NodeComponentInfo(interfaceType, componentId, &node);
+   if(!e2NodeComponentInfo) 
+   {
+      DU_LOG("\nERROR  -->  E2AP : Unable to find the node");
+      return RFAILED;
+   }
+
+   switch(action)
+   {
+      case E2_NODE_COMPONENT_ADD:
+         {
+            configInfo = e2NodeComponentInfo->addConfiguration;    
+            break;
+         }
+      case E2_NODE_COMPONENT_UPDATE: 
+         {
+            configInfo = e2NodeComponentInfo->updateConfiguration;
+            break;
+         }
+      default:
+         {
+            DU_LOG("\nERROR  -->  E2AP : Invalid action %d received",action);
+            return RFAILED;
+         }
+   }
+
+   if(configInfo->componentRequestPart== NULLP)
+   {
+      DU_LOG("\nERROR  -->  E2AP : E2 node Component request part is not present");
+      return RFAILED;
+   }
+
+   configInfo->rspBufSize = bufSize;
+   DU_ALLOC(configInfo->componentResponsePart, bufSize);
+   if(configInfo->componentResponsePart == NULLP)
+   {
+      DU_LOG("\nERROR  -->  E2AP : Memory allocation failed to store the encoding of rsp");
+      return RFAILED;
+   }
+   memcpy(configInfo->componentResponsePart, bufString, configInfo->rspBufSize);
+   return ROK;
+}
+
+/*******************************************************************
+ *
+ * @brief add E2 node component req info
+ *
+ * @details
+ *
+ *    Function : addE2NodeComponent 
+ *
+ * Functionality: add E2 node component req info 
  *
  * @parameter
  *       Type of interface 
  *       Component action type
- *       boolean variable to check req or rsp msg type
  *       Size of buffer which needs to be store
  *       buffer string which needs to be store 
  * @return ROK     - success
@@ -943,73 +1013,201 @@ E2NodeComponent *fetchE2NodeComponentInfo(InterfaceType interfaceType, uint8_t c
  *
  ******************************************************************/
 
-uint8_t addOrModifyE2NodeComponent(InterfaceType interfaceType, uint8_t action, bool reqPart, uint8_t bufSize, char *bufString)
+uint8_t addE2NodeComponent(InterfaceType interfaceType, uint64_t componentId,  uint8_t bufSize, char *bufString)
 {
-   E2NodeComponent *e2NodeComponentInfo= NULL;
+   E2NodeComponent *e2NodeComponentInfo= NULLP;
    CmLList  *node = NULLP;
    
-   if(reqPart == true)
+   DU_ALLOC(e2NodeComponentInfo, sizeof(E2NodeComponent));
+   if(!e2NodeComponentInfo)
    {
-      DU_ALLOC(e2NodeComponentInfo, sizeof(E2NodeComponent));
-      if(!e2NodeComponentInfo)
-      {
-         DU_LOG("\nERROR  -->  E2AP : Memory allocation failed for e2NodeComponentInfo in %s",__func__);
-         return RFAILED;
-      }
-      e2NodeComponentInfo->interfaceType =interfaceType;
-      e2NodeComponentInfo->componentId=duCfgParam.duId;
-      e2NodeComponentInfo->componentActionType = action;
-      e2NodeComponentInfo->reqBufSize = bufSize;
+      DU_LOG("\nERROR  -->  E2AP : Memory allocation failed in %s at %d",__func__,__LINE__);
+      return RFAILED;
+   }
+   e2NodeComponentInfo->interfaceType =interfaceType;
+   e2NodeComponentInfo->componentId=componentId;
 
-      DU_ALLOC(e2NodeComponentInfo->componentRequestPart, bufSize);
-      if(e2NodeComponentInfo->componentRequestPart == NULLP)
-      {
-         DU_LOG("\nERROR  -->  E2AP : Memory allocation failed for componentRequestPart");
-         DU_FREE(e2NodeComponentInfo, sizeof(E2NodeComponent));
-         return RFAILED;
-      }
-      memcpy(e2NodeComponentInfo->componentRequestPart, bufString, e2NodeComponentInfo->reqBufSize);
-      DU_ALLOC(node, sizeof(CmLList));
-      if(node)
-      {
-         node->node = (PTR) e2NodeComponentInfo;
-         cmLListAdd2Tail(&duCb.e2apDb.e2NodeComponentList, node);
-      }
-      else
-      {
-         DU_LOG("\nERROR  -->  E2AP : Memory allocation failed for e2NodeComponentList node");
-         DU_FREE(e2NodeComponentInfo->componentRequestPart, bufSize);
-         DU_FREE(e2NodeComponentInfo, sizeof(E2NodeComponent));
-         return RFAILED;
-      }
+   DU_ALLOC(e2NodeComponentInfo->addConfiguration, sizeof(E2NodeConfig));
+   if(!e2NodeComponentInfo->addConfiguration)
+   {
+      DU_LOG("\nERROR  -->  E2AP : Memory allocation failed in %s at %d",__func__,__LINE__);
+      return RFAILED;
+   }
+
+   e2NodeComponentInfo->addConfiguration->reqBufSize = bufSize;
+
+   DU_ALLOC(e2NodeComponentInfo->addConfiguration->componentRequestPart, bufSize);
+   if(e2NodeComponentInfo->addConfiguration->componentRequestPart == NULLP)
+   {
+      DU_LOG("\nERROR  -->  E2AP : Memory allocation failed in %s at %d",__func__,__LINE__);
+      DU_FREE(e2NodeComponentInfo, sizeof(E2NodeComponent));
+      return RFAILED;
+   }
+   memcpy(e2NodeComponentInfo->addConfiguration->componentRequestPart, bufString,\
+   e2NodeComponentInfo->addConfiguration->reqBufSize);
+
+   DU_ALLOC(node, sizeof(CmLList));
+   if(node)
+   {
+      node->node = (PTR) e2NodeComponentInfo;
+      cmLListAdd2Tail(&duCb.e2apDb.e2NodeComponentList, node);
    }
    else
    {
-      if(duCb.e2apDb.e2NodeComponentList.count)
-      {
-         e2NodeComponentInfo = fetchE2NodeComponentInfo(interfaceType, action, &node);
-         if(e2NodeComponentInfo->componentRequestPart== NULLP)
+      DU_LOG("\nERROR  -->  E2AP : Memory allocation failed in %s at %d",__func__,__LINE__);
+      DU_FREE(e2NodeComponentInfo->addConfiguration->componentRequestPart, bufSize);
+      DU_FREE(e2NodeComponentInfo->addConfiguration, sizeof(E2NodeConfig));
+      DU_FREE(e2NodeComponentInfo, sizeof(E2NodeComponent));
+      return RFAILED;
+   }
+   return ROK;
+}
+
+/*******************************************************************
+ *
+ * @brief update E2 node component req info
+ *
+ * @details
+ *
+ *    Function : updateE2NodeComponent 
+ *
+ * Functionality: update E2 node component req info 
+ *
+ * @parameter
+ *       Type of interface 
+ *       Size of buffer which needs to be store
+ *       buffer string which needs to be store 
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ ******************************************************************/
+
+uint8_t updateE2NodeComponent(InterfaceType interfaceType, uint64_t componentId, uint8_t bufSize, char *bufString)
+{
+   E2NodeComponent *e2NodeComponentInfo= NULLP;
+   CmLList  *node = NULLP;
+         
+   e2NodeComponentInfo = fetchE2NodeComponentInfo(interfaceType, componentId, &node);
+   if(!e2NodeComponentInfo)
+   {
+      DU_LOG("\nERROR  -->  E2AP : Received null information in %s",__func__);
+      return RFAILED;
+   }
+   
+   DU_ALLOC(e2NodeComponentInfo->updateConfiguration, sizeof(E2NodeConfig));
+   if(!e2NodeComponentInfo->updateConfiguration)
+   {
+      DU_LOG("\nERROR  -->  E2AP : Memory allocation failed in %s at %d",__func__,__LINE__);
+      return RFAILED;
+   }
+
+   e2NodeComponentInfo->updateConfiguration->reqBufSize = bufSize;
+
+   DU_ALLOC(e2NodeComponentInfo->updateConfiguration->componentRequestPart, bufSize);
+   if(e2NodeComponentInfo->updateConfiguration->componentRequestPart == NULLP)
+   {
+      DU_LOG("\nERROR  -->  E2AP : Memory allocation failed in %s at %d",__func__,__LINE__);
+      DU_FREE(e2NodeComponentInfo->updateConfiguration, sizeof(E2NodeConfig));
+      return RFAILED;
+   }
+
+   memcpy(e2NodeComponentInfo->updateConfiguration->componentRequestPart, bufString,\
+   e2NodeComponentInfo->updateConfiguration->reqBufSize);
+   return ROK;
+
+}
+
+/*******************************************************************
+ *
+ * @brief delete E2 node component req info
+ *
+ * @details
+ *
+ *    Function : deleteE2NodeComponent 
+ *
+ * Functionality: delete E2 node component req info 
+ *
+ * @parameter
+ *       Type of interface 
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ ******************************************************************/
+
+uint8_t deleteE2NodeComponent(InterfaceType interfaceType, uint64_t componentId)
+{
+   E2NodeComponent *e2NodeComponentInfo= NULLP;
+   CmLList  *node = NULLP;
+         
+   e2NodeComponentInfo = fetchE2NodeComponentInfo(interfaceType, componentId, &node);
+   if(!e2NodeComponentInfo)
+   {
+      DU_LOG("\nERROR  -->  E2AP : Received null information in %s",__func__);
+      return RFAILED;
+   }
+   
+   e2NodeComponentInfo->deleteConfiguration = true;
+   return ROK;
+}
+
+/*******************************************************************
+ *
+ * @brief fill E2 node component req info
+ *
+ * @details
+ *
+ *    Function : fillE2NodeComponentReqInfo 
+ *
+ * Functionality: fill E2 node component req info 
+ *
+ * @parameter
+ *       Type of interface 
+ *       Component action type
+ *       Size of buffer which needs to be store
+ *       buffer string which needs to be store 
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ ******************************************************************/
+
+uint8_t fillE2NodeComponentReqInfo(InterfaceType interfaceType, uint64_t componentId, uint8_t action, uint8_t bufSize, char *bufString)
+{
+   switch(action)
+   {
+      case E2_NODE_COMPONENT_ADD:
          {
-            DU_LOG("\nERROR  -->  E2AP : E2 node Component request part is not present");
-            return RFAILED;
+            if(addE2NodeComponent(interfaceType, componentId, bufSize, bufString) != ROK)
+            {
+               DU_LOG("\nERROR  -->  E2AP : Failed to add e2 node component");
+               return RFAILED;
+            }
+            break;
          }
-         
-         e2NodeComponentInfo->rspBufSize = bufSize;
-         DU_ALLOC(e2NodeComponentInfo->componentResponsePart, bufSize);
-         if(e2NodeComponentInfo->componentResponsePart == NULLP)
+      case E2_NODE_COMPONENT_UPDATE: 
          {
-            DU_LOG("\nERROR  -->  E2AP : Memory allocation failed to store the encoding of rsp");
+            if(updateE2NodeComponent(interfaceType, componentId, bufSize, bufString) != ROK)
+            {
+               DU_LOG("\nERROR  -->  E2AP : Failed to update e2 node component");
+               return RFAILED;
+            }
+            break;
+         }
+      case E2_NODE_COMPONENT_DEL:
+         {
+            if(deleteE2NodeComponent(interfaceType, componentId) != ROK)
+            {
+               DU_LOG("\nERROR  -->  E2AP : Failed to delete e2 node component");
+               return RFAILED;
+            }
+            break;
+         }
+      default:
+         {
+            DU_LOG("\nERROR  -->  E2AP : Invalid action %d received",action);
             return RFAILED;
          }
-         memcpy(e2NodeComponentInfo->componentResponsePart, bufString, e2NodeComponentInfo->rspBufSize);
-         return ROK;
-      }
-      else
-      {
-         DU_LOG("\nERROR  -->  E2AP : Unable to find the node");
-         return RFAILED;
-      }
-   } 
+   }
+
    return ROK;
 }
 
@@ -1058,7 +1256,6 @@ void deleteMeasuredValueList(CmLListCp *measuredValueList)
  * @return void 
  *
  * ****************************************************************/
-
 void deleteMeasurementInfoList(CmLListCp *measInfoList)
 {
    CmLList *measInfoNode = NULLP;
@@ -1117,6 +1314,7 @@ void deleteActionSequence(ActionInfo *action)
    memset(action, 0, sizeof(ActionInfo));
    action->actionId = -1;
 }
+
 /******************************************************************
  *
  * @brief Delete Ric subscription node 
@@ -1132,7 +1330,6 @@ void deleteActionSequence(ActionInfo *action)
  * @return void 
  *
  * ****************************************************************/
-
 void deleteRicSubscriptionNode(CmLList *subscriptionNode)
 {
    uint8_t actionIdx=0;
@@ -1174,8 +1371,6 @@ void deleteRicSubscriptionNode(CmLList *subscriptionNode)
  * @return void 
  *
  * ****************************************************************/
-
-
 void deleteRicSubscriptionList(CmLListCp *subscriptionList)
 {
    CmLList *subscriptionNode=NULLP;
@@ -1190,6 +1385,152 @@ void deleteRicSubscriptionList(CmLListCp *subscriptionList)
    }
 }
 
+/*******************************************************************
+ *
+ * @brief Find all RIC subscriptions to be deleted in all RAN
+ *    Functions
+ *
+ * @details
+ *
+ *    Function : fetchRicSubsToBeDeleted
+ *
+ * Functionality: Find all RIC subscriptions to be deleted in all
+ *    RAN functions and store in a temporary list
+ *
+ * @parameter Temporary list to store subscriptions to be deleted
+ * @return void
+ *
+ ******************************************************************/
+void fetchRicSubsToBeDeleted(CmLListCp *ricSubsToBeDelList)
+{
+   uint16_t ranFuncIdx = 0;
+   CmLList *subsNode = NULLP;
+   CmLList *subsToDelNode = NULLP;
+
+   for(ranFuncIdx = 0; ranFuncIdx < MAX_RAN_FUNCTION; ranFuncIdx++)
+   {
+      if(duCb.e2apDb.ranFunction[ranFuncIdx].id > 0)
+      {
+         CM_LLIST_FIRST_NODE(&duCb.e2apDb.ranFunction[ranFuncIdx].subscriptionList, subsNode);
+         while(subsNode)
+         {
+            if(((RicSubscription *)subsNode->node)->action == CONFIG_DEL)
+            {
+               DU_ALLOC(subsToDelNode, sizeof(CmLList));
+               if(!subsToDelNode)
+               {
+                  DU_LOG("\nERROR  -->  E2AP : %s: Memory allocation failure at %d", __func__, __LINE__); 
+                  return;
+               }
+               subsToDelNode->node = subsNode->node;
+               cmLListAdd2Tail(ricSubsToBeDelList, subsToDelNode);
+            }
+            subsToDelNode = NULLP;
+            subsNode = subsNode->next;
+         }
+      }
+   }
+}
+
+/******************************************************************
+ *
+ * @brief Delete e2 node information from the database
+ *
+ * @details
+ *
+ *    Function : removeE2NodeInformation 
+ *
+ *    Functionality: Delete e2 node information from the database 
+ *
+ * @params[in]
+ *
+ * @return void 
+ *
+******************************************************************/
+void removeE2NodeInformation()
+{
+   uint16_t ranFuncIdx = 0;
+   
+   DU_LOG("\nINFO  -->  E2AP : Deleting all the E2 node configuration");
+   for(ranFuncIdx=0; ranFuncIdx<MAX_RAN_FUNCTION; ranFuncIdx++)
+   {
+      if(duCb.e2apDb.ranFunction[ranFuncIdx].id >0)
+      {
+         deleteRicSubscriptionList(&(duCb.e2apDb.ranFunction[ranFuncIdx].subscriptionList));
+         memset(&(duCb.e2apDb.ranFunction[ranFuncIdx].pendingSubsRspInfo), 0, MAX_PENDING_SUBSCRIPTION_RSP*sizeof(PendingSubsRspInfo));
+      }
+   }
+   memset(&duCb.e2apDb.ricId, 0, sizeof(GlobalRicId));
+   duCb.e2apDb.numOfTNLAssoc = 0;
+   memset(&duCb.e2apDb.tnlAssoc, 0, MAX_TNL_ASSOCIATION*sizeof(TNLAssociation));
+   memset(&ricParams, 0, sizeof(DuSctpDestCb));
+}
+
+/*******************************************************************
+ *
+ * @brief Extract statistics received from DU layers and delete
+ * Ric subscription info
+ *
+ * @details
+ *
+ *    Function :e2ProcStatsDeleteRsp 
+ *
+ *    Functionality: Extract statistics received from DU layers
+ *       and delete ric subscription iformation form db
+ *
+ * @params[in] Statistics delete rsp from MAC
+ * @return ROK-success
+ *         RFAILED-failure
+ *
+ * ****************************************************************/
+uint8_t e2ProcStatsDeleteRsp(MacStatsDeleteRsp *statsDeleteRsp)
+{
+   RanFunction *ranFuncDb = NULLP;
+   CmLList *ricSubscriptionNode = NULLP;
+   RicSubscription *ricSubscriptionInfo = NULLP;
+   E2FailureCause failureCause;
+
+   /* Fetch RAN Function and Subscription DB using subscription Id received
+    * in statistics delete response */
+   if(fetchSubsInfoFromSubsId(statsDeleteRsp->subscriptionId, &ranFuncDb, &ricSubscriptionNode, &ricSubscriptionInfo) != ROK)
+   {
+      DU_LOG("\nERROR  -->  E2AP : e2ProcStatsDeleteRsp: Failed to fetch subscriprtion details");
+      return RFAILED;
+   }
+
+   deleteRicSubscriptionNode(ricSubscriptionNode);
+   
+   if(statsDeleteRsp->result == MAC_DU_APP_RSP_NOK)
+   {
+      if(statsDeleteRsp->status == STATS_ID_NOT_FOUND)
+      {
+         failureCause.causeType =E2_RIC_REQUEST;
+         failureCause.cause = E2_REQUEST_INFORMATION_UNAVAILABLE;
+      }
+      else
+      {
+         failureCause.causeType = E2_MISCELLANEOUS;
+         failureCause.cause = E2_MISCELLANEOUS_CAUSE_UNSPECIFIED;
+      }
+
+      if(BuildAndSendRicSubscriptionDeleteFailure(ricSubscriptionInfo->ranFuncId, ricSubscriptionInfo->requestId, failureCause) != ROK)
+      {
+         DU_LOG("\nERROR  -->  E2AP : e2ProcStatsDeleteRsp: failed to build and send ric subs delete failure");
+         return RFAILED;
+      }
+   }
+   else
+   {
+      if(BuildAndSendRicSubscriptionDeleteResponse(ricSubscriptionInfo->ranFuncId, ricSubscriptionInfo->requestId) != ROK)
+      {
+         DU_LOG("\nERROR  -->  E2AP : e2ProcStatsDeleteRsp: failed to build and send ric subs delete rsp");
+         return RFAILED;
+      }
+   }
+   
+   return ROK;
+}
+
 /**********************************************************************
   End of file
  **********************************************************************/