1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
18 #include "common_def.h"
25 #include "du_app_mac_inf.h"
26 #include "du_app_rlc_inf.h"
27 #include "du_e2ap_mgr.h"
28 #include "du_e2_conversions.h"
29 #include "du_e2ap_msg_hdl.h"
33 #include "du_mgr_main.h"
36 /*******************************************************************
38 * @brief Assigns new transaction id to DU initiated procedure
42 * Function : assignTransactionId
44 * Functionality: Assigns new transaction id to a DU initiated
47 * @params[in] Region region
49 * @return ROK - success
52 * ****************************************************************/
53 uint8_t assignTransactionId()
55 uint8_t currTransId = duCb.e2apDb.e2TransInfo.transIdCounter;
57 /* Update to next valid value */
58 duCb.e2apDb.e2TransInfo.transIdCounter++;
59 if(duCb.e2apDb.e2TransInfo.transIdCounter == MAX_NUM_TRANSACTION)
60 duCb.e2apDb.e2TransInfo.transIdCounter = 0;
65 /*******************************************************************
67 * @brief Decode subscription ID
71 * Function : decodeSubscriptionId
73 * Functionality: Decode subscription id to get RAN function ID
76 * @params[in] Subscription ID
77 * RAN Function ID to be extracted
78 * RIC Request ID to be extracted
81 * ****************************************************************/
82 void decodeSubscriptionId(uint64_t subscriptionId, uint16_t *ranFuncId, RicRequestId *ricReqId)
84 /* Extract following from 64 bit subscription-ID :
85 * First 16 MSB is unused
86 * Next 16 MSB = RAN-Function-ID
87 * Next 16 MSB = Requestor-ID in RIC-Request-ID
88 * Last 16 LSB = Instance-ID in RIC-Request-ID
90 ricReqId->instanceId = subscriptionId & 0xFFFF;
91 ricReqId->requestorId = (subscriptionId >> 16) & 0xFFFF;
92 *ranFuncId = (subscriptionId >> 32) & 0xFFFF;
95 /*******************************************************************
97 * @brief Encode subscription ID
101 * Function : encodeSubscriptionId
103 * Functionality: Encode subscription id to get RAN function ID
106 * @params[in] Subscription ID to be encoded
111 * ****************************************************************/
112 void encodeSubscriptionId(uint64_t *subscriptionId, uint16_t ranFuncId, RicRequestId ricReqId)
114 /* Calculate 64 bit subscription-ID :
115 * First 16 MSB is unused
116 * Next 16 MSB = RAN-Function-ID
117 * Next 16 MSB = Requestor-ID in RIC-Request-ID
118 * Last 16 LSB = Instance-ID in RIC-Request-ID
120 *subscriptionId = ricReqId.instanceId;
121 *subscriptionId |= ((uint64_t)ricReqId.requestorId << 16);
122 *subscriptionId |= ((uint64_t)ranFuncId << 32);
125 /*******************************************************************
127 * @brief Stores the current time at the start of reporting period
131 * Function : storeReportStartTime
133 * Functionality: Stores the current time at the start of
136 * @params[in] Start Timer to be stored
139 * ****************************************************************/
140 void storeReportStartTime(ReportStartTime *startTime)
144 gettimeofday(&tv, NULL);
145 startTime->timeInSec = tv.tv_sec;
146 startTime->timeInMilliSec = (tv.tv_usec/1000);
150 /*******************************************************************
152 * @brief Fetch Measurement Info using measurement type name
156 * Function : fetchMeasInfoFromMeasTypeName
158 * Functionality: Fetch Measurement Info using measurement type name
160 * @params[in] Measurement type name to search
161 * Measurement Info list to search from
162 * Measurement Info node found from list
163 * @return Measurement Info DB
165 * ****************************************************************/
166 MeasurementInfo *fetchMeasInfoFromMeasTypeName(char *e2MeasTypeName, CmLListCp *measInfoList, CmLList **measInfoNode)
168 MeasurementInfo *measInfo = NULLP;
170 /* Fetch subscription detail in RAN Function DB */
171 CM_LLIST_FIRST_NODE(measInfoList, *measInfoNode);
174 measInfo = (MeasurementInfo *)((*measInfoNode)->node);
175 if(measInfo && !strcmp(e2MeasTypeName, measInfo->measurementTypeName))
179 *measInfoNode = (*measInfoNode)->next;
185 DU_LOG("\nERROR --> E2AP : fetchMeasInfoFromMeasTypeName: Measurement [%s] not found", e2MeasTypeName);
191 /*******************************************************************
193 * @brief Fetch Action details
197 * Function : fetchActionInfoFromActionId
199 * Functionality: Fetch action details from RIC subscription DB
202 * @params[in] Action ID
203 * RIC Subscription DB
204 * @return Action Info DB
205 * NULL, in case of failure
207 * ****************************************************************/
208 ActionInfo *fetchActionInfoFromActionId(uint8_t actionId, RicSubscription *ricSubscriptionInfo)
210 ActionInfo *actionInfoDb = NULLP;
211 if(ricSubscriptionInfo->actionSequence[actionId].actionId == actionId)
213 actionInfoDb = &ricSubscriptionInfo->actionSequence[actionId];
217 DU_LOG("\nERROR --> E2AP : fetchActionInfoFromActionId: Action Id [%d] not found in \
218 subscription info [Requestor id : %d] [Instance Id : %d]", actionId,\
219 ricSubscriptionInfo->requestId.requestorId, ricSubscriptionInfo->requestId.instanceId);
225 /*******************************************************************
227 * @brief Fetch subscripton DB
231 * Function : fetchSubsInfoFromRicReqId
233 * Functionality: Fetches subscription DB from RAN Function DB
234 * using RIC Request ID
236 * @params[in] RIC Request ID
238 * Pointer to RIC Subscription node to be searched
239 * @return RIC Subscription from RAN Function's subcription list
240 * NULL, in case of failure
242 * ****************************************************************/
243 RicSubscription *fetchSubsInfoFromRicReqId(RicRequestId ricReqId, RanFunction *ranFuncDb, CmLList **ricSubscriptionNode)
245 RicSubscription *ricSubscriptionInfo = NULLP;
247 /* Fetch subscription detail in RAN Function DB */
248 CM_LLIST_FIRST_NODE(&ranFuncDb->subscriptionList, *ricSubscriptionNode);
249 while(*ricSubscriptionNode)
251 ricSubscriptionInfo = (RicSubscription *)((*ricSubscriptionNode)->node);
252 if(ricSubscriptionInfo && (ricSubscriptionInfo->requestId.requestorId == ricReqId.requestorId) &&
253 (ricSubscriptionInfo->requestId.instanceId == ricReqId.instanceId))
257 *ricSubscriptionNode = (*ricSubscriptionNode)->next;
258 ricSubscriptionInfo = NULLP;
261 if(!ricSubscriptionInfo)
263 DU_LOG("\nERROR --> E2AP : fetchSubsInfoFromRicReqId: Subscription not found for Requestor ID [%d] \
264 Instance ID [%d] in RAN Function ID [%d]", ricReqId.requestorId, ricReqId.instanceId, ranFuncDb->id);
267 return ricSubscriptionInfo;
270 /*******************************************************************
272 * @brief Fetches RAN Function DB
276 * Function : fetchRanFuncFromRanFuncId
278 * Functionality: Fetches RAN function DB from E2AP DB using
281 * @params[in] RAN Function ID
282 * @return RAN Function DB
283 * NULL, in case of failure
285 * ****************************************************************/
286 RanFunction *fetchRanFuncFromRanFuncId(uint16_t ranFuncId)
288 RanFunction *ranFuncDb = NULLP;
290 /* Fetch RAN Function DB */
291 if(duCb.e2apDb.ranFunction[ranFuncId-1].id == ranFuncId)
293 ranFuncDb = &duCb.e2apDb.ranFunction[ranFuncId-1];
297 DU_LOG("\nERROR --> E2AP : fetchRanFuncFromRanFuncId: Invalid RAN Function ID[%d]", ranFuncId);
303 /*******************************************************************
305 * @brief Fetches subscription info
309 * Function : fetchSubsInfoFromSubsId
312 * 1. Firstly, RAN Function ID and RIC request ID is extracted
313 * from Subscription ID
314 * 2. Using RAN Function ID, RAN Function DB is searched
315 * 3. Using RIC Request ID, the subscription DB is searched in
318 * @params[in] Subscription ID
320 * RIC Subscription node from RAN Func's Subscription list
324 * ****************************************************************/
325 uint8_t fetchSubsInfoFromSubsId(uint64_t subscriptionId, RanFunction **ranFuncDb, CmLList **ricSubscriptionNode, \
326 RicSubscription **ricSubscriptionInfo)
328 uint16_t ranFuncId = 0;
329 RicRequestId ricReqId;
331 memset(&ricReqId, 0, sizeof(RicRequestId));
333 /* Decode subscription ID o get RIC Request ID and RAN Function ID */
334 decodeSubscriptionId(subscriptionId, &ranFuncId, &ricReqId);
336 /* Fetch RAN Function DB using RAN Function ID */
337 *ranFuncDb = fetchRanFuncFromRanFuncId(ranFuncId);
338 if((*ranFuncDb) == NULLP)
343 /* Fetch Sunscription DB from RAN Function using RIC Request ID */
344 *ricSubscriptionInfo = fetchSubsInfoFromRicReqId(ricReqId, *ranFuncDb, ricSubscriptionNode);
345 if((*ricSubscriptionInfo) == NULLP)
353 /*******************************************************************
355 * @brief Sends E2 msg over SCTP
359 * Function : SendE2APMsg
361 * Functionality: Sends E2 msg over SCTP
363 * @params[in] Region region
365 * @return ROK - success
368 * ****************************************************************/
370 uint8_t SendE2APMsg(Region region, Pool pool, char *encBuf, int encBufSize)
374 if(ODU_GET_MSG_BUF(region, pool, &mBuf) == ROK)
376 if(ODU_ADD_POST_MSG_MULT((Data *)encBuf, encBufSize, mBuf) == ROK)
378 ODU_PRINT_MSG(mBuf, 0,0);
380 if(sctpSend(mBuf, E2_INTERFACE) != ROK)
382 DU_LOG("\nERROR --> E2AP : SCTP Send for E2 failed");
383 ODU_PUT_MSG_BUF(mBuf);
389 DU_LOG("\nERROR --> E2AP : ODU_ADD_POST_MSG_MULT failed");
390 ODU_PUT_MSG_BUF(mBuf);
393 ODU_PUT_MSG_BUF(mBuf);
397 DU_LOG("\nERROR --> E2AP : Failed to allocate memory");
404 /*******************************************************************
410 * Function : ResetE2Request
412 * Functionality: This function resets E2.
413 * As per ORAN WG3 E2GAP v3.0 Spec, section 5.5.3
414 * If E2 node initates reset procedure then:
415 * a. Send reset request to RIC
416 * b. Delete any pre-established RIC subscriptions
417 * c. Gracefully terminates any ongoing RIC services
418 * If RIC initiates reset procedure then :
419 * a. Delete any pre-established RIC subscriptions
420 * b. Gracefully terminates any ongoing RIC services
421 * c. Send reset response to RIC
424 * @return ROK - success
427 * ****************************************************************/
428 uint8_t ResetE2Request(E2ProcedureDirection dir, E2FailureCause resetCause)
430 /* Send Reset Request to RIC if DU detects any abnormal failure */
431 if(dir == E2_NODE_INITIATED)
433 if(BuildAndSendE2ResetRequest(resetCause) != ROK)
435 DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest failed");
440 /* TODO when RIC subscription service model is implemented
441 Process following steps of resetting E2
442 1. Deletes any pre-established RIC subscriptions
443 2. Gracefully terminates any ongoing RIC services
446 /* Send Reset Response if RIC initiated Reset request is received at DU */
447 if(dir == RIC_INITIATED)
449 //BuildAndSendE2ResetResponse();
454 /*******************************************************************
456 * @brief Fill RIC Subscription datils in MAC Statistics Request
460 * Function : fillRicSubsInMacStatsReq
462 * Functionality: Fill RIC Subscription datils in MAC Statistics
465 * @params[in] MAC Statistics Request to be filled
466 * RIC Subscription Info
468 * @return ROK - success
471 * ****************************************************************/
472 uint8_t fillRicSubsInMacStatsReq(MacStatsReq *macStatsReq, RicSubscription* ricSubscriptionInfo)
474 uint8_t actionIdx = 0, grpIdx = 0, statsIdx = 0;
475 uint64_t subscriptionId = 0;
476 ActionInfo *actionDb = NULLP;
477 ActionDefFormat1 *format1Action = NULLP;
479 /* Generate subscription ID using RIC Request ID and RAN Function ID */
480 encodeSubscriptionId(&subscriptionId, ricSubscriptionInfo->ranFuncId, ricSubscriptionInfo->requestId);
482 macStatsReq->subscriptionId = subscriptionId;
483 for(actionIdx = 0; actionIdx < MAX_RIC_ACTION; actionIdx++)
485 if(ricSubscriptionInfo->actionSequence[actionIdx].action == CONFIG_ADD)
487 actionDb = &ricSubscriptionInfo->actionSequence[actionIdx];
488 macStatsReq->statsGrpList[grpIdx].groupId = actionDb->actionId;
489 switch(actionDb->definition.formatType)
493 format1Action = &actionDb->definition.choice.format1;
494 macStatsReq->statsGrpList[grpIdx].periodicity = format1Action->granularityPeriod;
496 CmLList *node = NULLP;
497 MeasurementInfo *measInfo = NULLP;
499 /* Update DL PRB Usage for all stats group which requested for DL Total PRB Usage */
500 node = cmLListFirst(&format1Action->measurementInfoList);
503 measInfo = (MeasurementInfo *)(node->node);
504 switch(measInfo->measurementTypeId)
508 macStatsReq->statsGrpList[grpIdx].statsList[statsIdx++] = MAC_DL_TOTAL_PRB_USAGE;
513 macStatsReq->statsGrpList[grpIdx].statsList[statsIdx++] = MAC_UL_TOTAL_PRB_USAGE;
518 DU_LOG("\nERROR --> E2AP : Invalid measurement name");
524 macStatsReq->statsGrpList[grpIdx].numStats = statsIdx;
529 DU_LOG("\nERROR --> E2AP : fillRicSubsInMacStatsReq: Only Action Definition Format 1 supported");
533 if(macStatsReq->statsGrpList[grpIdx].numStats)
538 macStatsReq->numStatsGroup = grpIdx;
539 if(macStatsReq->numStatsGroup)
546 /*******************************************************************
548 * @brief Rejects all actions received in a subscription request
552 * Function : duRejectAllStatsGroup
554 * Functionality: Rejects all actions received in a subscription
556 * a. Removing the subscription entry from RAN function
557 * b. Sending RIC Subscription Failure to RIC with appropriate
560 * @params[in] RAN Function DB
561 * Subscription entry in RAN Function subscription list
562 * Statistics Response from MAC
564 * @return ROK - success
567 * ****************************************************************/
568 uint8_t rejectAllStatsGroup(RanFunction *ranFuncDb, CmLList *ricSubscriptionNode, MacStatsRsp *statsRsp)
571 RicRequestId requestId;
572 E2FailureCause failureCause;
574 /* Delete subcription from RAN Function */
575 memcpy(&requestId, &((RicSubscription *)ricSubscriptionNode->node)->requestId, sizeof(RicRequestId));
576 cmLListDelFrm(&ranFuncDb->subscriptionList, ricSubscriptionNode);
577 deleteRicSubscriptionNode(ricSubscriptionNode);
578 ricSubscriptionNode = NULLP;
579 convertDuCauseToE2Cause(statsRsp->statsGrpRejectedList[0].cause, &failureCause);
581 /* Send RIC subscription failure to RIC */
582 ret = BuildAndSendRicSubscriptionFailure(requestId, ranFuncDb->id, failureCause);
586 /*******************************************************************
588 * @brief Process statistics response from MAC
592 * Function : e2ProcStatsRsp
594 * Functionality: Processes statistics configuration response
595 * from MAC. If configuration is succsessful, DUAPP starts
596 * reporting period timer for this subscription request
599 * @params[in] Statistics response received from MAC
601 * @return ROK - success
604 * ****************************************************************/
605 uint8_t e2ProcStatsRsp(MacStatsRsp *statsRsp)
608 uint8_t actionId = 0;
609 uint32_t reportingPeriod = 0;
610 RanFunction *ranFuncDb = NULLP;
611 CmLList *ricSubscriptionNode = NULLP;
612 RicSubscription *ricSubscriptionInfo = NULLP;
613 ActionInfo *actionInfoDb = NULLP;
614 PendingSubsRspInfo *pendingSubsRsp = NULLP;
616 /* Fetch RAN Function and Subscription DB using subscription Id received in statistics response */
617 if(fetchSubsInfoFromSubsId(statsRsp->subscriptionId, &ranFuncDb, &ricSubscriptionNode, &ricSubscriptionInfo) != ROK)
619 DU_LOG("\nERROR --> E2AP : DuProcMacStatsRsp: Failed to fetch subscriprtion details");
623 /* Fetch pre-stored statistics response info by DU APP */
624 for(idx=0; idx<ranFuncDb->numPendingSubsRsp; idx++)
626 if((ranFuncDb->pendingSubsRspInfo[idx].requestId.requestorId == ricSubscriptionInfo->requestId.requestorId) &&
627 (ricSubscriptionInfo->requestId.instanceId == ricSubscriptionInfo->requestId.instanceId))
629 pendingSubsRsp = &ranFuncDb->pendingSubsRspInfo[idx];
634 /* If no action is accepted
635 * a. Remove subcription entry from RAN Function
636 * b. Send RIC subscription failure */
637 if(statsRsp->numGrpAccepted == 0)
639 rejectAllStatsGroup(ranFuncDb, ricSubscriptionNode, statsRsp);
643 /* Start RIC Subscription reporting timer */
644 switch(ricSubscriptionInfo->eventTriggerDefinition.formatType)
648 reportingPeriod = ricSubscriptionInfo->eventTriggerDefinition.choice.format1.reportingPeriod;
650 /* Save the start time of reporting period */
651 storeReportStartTime(&ricSubscriptionInfo->eventTriggerDefinition.choice.format1.startTime);
656 DU_LOG("\nERROR --> E2AP : Invalid event trigger format of RIC subscription");
660 if(duChkTmr((PTR)ricSubscriptionInfo, EVENT_RIC_SUBSCRIPTION_REPORTING_TMR) != true)
662 duStartTmr((PTR)ricSubscriptionInfo, EVENT_RIC_SUBSCRIPTION_REPORTING_TMR, reportingPeriod);
666 DU_LOG("\nERROR --> E2AP : RIC Subscription reporting timer already running for RIC Subscription");
671 /* If even 1 action is accepted :
673 * For accepted groups:
674 * Mark subscribed-action's -> action = CONFIG_UNKNOWN
675 * Add to accepted-action-list of subscription response
677 for(idx=0; idx<statsRsp->numGrpAccepted; idx++)
679 actionInfoDb = NULLP;
681 actionId = statsRsp->statsGrpAcceptedList[idx];
682 actionInfoDb = fetchActionInfoFromActionId(actionId, ricSubscriptionInfo);
683 if(actionInfoDb && (actionInfoDb->action == CONFIG_ADD))
685 actionInfoDb->action = CONFIG_UNKNOWN;
686 pendingSubsRsp->acceptedActionList[pendingSubsRsp->numOfAcceptedActions++] = actionId;
690 /* For rejected groups:
691 * Remove entry from DU's RAN Function->subscription->actionList
692 * Add to rejected-action-list in subscription response
694 for(idx=0; idx<statsRsp->numGrpRejected; idx++)
696 actionId = statsRsp->statsGrpRejectedList[idx].groupId;
697 if(ricSubscriptionInfo->actionSequence[actionId].actionId == actionId)
699 memset(&ricSubscriptionInfo->actionSequence[actionId], 0, sizeof(ActionInfo));
700 ricSubscriptionInfo->numOfActions--;
702 pendingSubsRsp->rejectedActionList[pendingSubsRsp->numOfRejectedActions].id = actionId;
703 convertDuCauseToE2Cause(statsRsp->statsGrpRejectedList[idx].cause, \
704 &pendingSubsRsp->rejectedActionList[pendingSubsRsp->numOfRejectedActions].failureCause);
705 pendingSubsRsp->numOfRejectedActions++;
709 /* Send subscription response with accepted and rejected action lists to RIC */
710 BuildAndSendRicSubscriptionRsp(pendingSubsRsp);
712 memset(pendingSubsRsp, 0, sizeof(PendingSubsRspInfo));
716 /*******************************************************************
718 * @brief Extract and store statistics received from DU layers
722 * Function : e2ProcStatsInd
724 * Functionality: Extract statistics received from DU layers
725 * and store in respective RAN function's subscription's
728 * @params[in] Statistics Indication message received from MAC
729 * @return ROK-success
732 * ****************************************************************/
733 uint8_t e2ProcStatsInd(MacStatsInd *statsInd)
735 uint8_t statsIdx = 0;
736 RanFunction *ranFuncDb = NULLP;
737 CmLList *ricSubscriptionNode = NULLP;
738 RicSubscription *ricSubscriptionInfo = NULLP;
739 ActionInfo *actionInfo = NULLP;
740 ActionDefFormat1 *actionFormat = NULLP;
741 char e2MeasTypeName[STRING_SIZE_150_BYTES] = "";
742 MeasurementInfo *measInfo = NULLP;
743 CmLList *measInfoNode = NULLP;
744 double *measValue = NULLP;
745 CmLList *measValueNode = NULLP;
747 /* TODO : When stats indication is received
748 * DU APP searches for the message type in E2AP RIC subscription
749 * database and stores in the value in the list of subscribed measurements
751 * This will be implemented in next gerrit.
754 /* Fetch RAN Function and Subscription DB using subscription Id received
755 * in statistics response */
756 if(fetchSubsInfoFromSubsId(statsInd->subscriptionId, &ranFuncDb, &ricSubscriptionNode, &ricSubscriptionInfo) != ROK)
758 DU_LOG("\nERROR --> E2AP : extractStatsMeasurement: Failed to fetch subscriprtion details");
762 /* Fetch RIC subscription's action DB */
763 actionInfo = fetchActionInfoFromActionId(statsInd->groupId, ricSubscriptionInfo);
764 if(actionInfo == NULLP)
766 DU_LOG("\nERROR --> E2AP : extractStatsMeasurement: Failed to fetch action ID [%d]", statsInd->groupId);
770 /* Check Action format */
771 switch(actionInfo->definition.formatType)
775 actionFormat = &actionInfo->definition.choice.format1;
780 DU_LOG("\nERROR --> E2AP : extractStatsMeasurement: Action Format [%d] is not supported", \
781 actionInfo->definition.formatType);
786 /* Fetch each Measurement info from action info and store its reported value in DB */
787 for(statsIdx = 0; statsIdx < statsInd->numStats; statsIdx++)
789 memset(e2MeasTypeName, 0, STRING_SIZE_150_BYTES);
791 measInfoNode = NULLP;
793 /* Convert Measurement type from MAC-supported format to E2-supported format */
794 if(convertMacMeasTypeToE2MeasType(statsInd->measuredStatsList[statsIdx].type, e2MeasTypeName) != ROK)
796 DU_LOG("\nERROR --> E2AP : extractStatsMeasurement: Failed to convert measurement type from MAC-supported\
797 MAC-supported format to E2-supported format");
801 /* Fetch Measurement Info using E2-supported measurement type name */
802 measInfo = fetchMeasInfoFromMeasTypeName(e2MeasTypeName, &actionFormat->measurementInfoList, &measInfoNode);
803 if(measInfo == NULLP)
805 DU_LOG("\nERROR --> E2AP : extractStatsMeasurement: Measurement Type Name [%s] not found", e2MeasTypeName);
809 /* Store the measurement value in the measurement info DB fetched */
810 DU_ALLOC(measValue, sizeof(double));
813 DU_LOG("\nERROR --> E2AP : extractStatsMeasurement: Memory allocation failed at line [%d]", __LINE__);
816 *measValue = statsInd->measuredStatsList[statsIdx].value;
818 DU_ALLOC(measValueNode, sizeof(CmLList));
821 DU_LOG("\nERROR --> E2AP : extractStatsMeasurement: Memory allocation failed at line [%d]", __LINE__);
822 DU_FREE(measValue, sizeof(double));
825 measValueNode->node = (PTR) measValue;
826 cmLListAdd2Tail(&measInfo->measuredValue, measValueNode);
831 /*******************************************************************
833 * @brief Handle RIC Subscription reporting timer expry
837 * Function : E2apHdlRicSubsReportTmrExp
839 * Functionality: On expiry of RIC subscription reporting
840 * timer expiry, RIC indication is sent for all actions
841 * in RIC subscription
843 * @params[in] RIC subscription DB
846 * ****************************************************************/
847 void E2apHdlRicSubsReportTmrExp(RicSubscription *ricSubscription)
849 uint8_t actionIdx = 0;
850 uint32_t reportingPeriod = 0;
852 for(actionIdx = 0; actionIdx < MAX_RIC_ACTION; actionIdx++)
854 if(ricSubscription->actionSequence[actionIdx].actionId >= 0)
856 BuildAndSendRicIndication(ricSubscription, &ricSubscription->actionSequence[actionIdx]);
860 /* Start RIC Subscription reporting timer again */
861 switch(ricSubscription->eventTriggerDefinition.formatType)
865 reportingPeriod = ricSubscription->eventTriggerDefinition.choice.format1.reportingPeriod;
866 /* Save the start time of reporting period */
867 storeReportStartTime(&ricSubscription->eventTriggerDefinition.choice.format1.startTime);
873 if(duChkTmr((PTR)ricSubscription, EVENT_RIC_SUBSCRIPTION_REPORTING_TMR) != true)
875 duStartTmr((PTR)ricSubscription, EVENT_RIC_SUBSCRIPTION_REPORTING_TMR, reportingPeriod);
879 DU_LOG("\nERROR --> E2AP : Failed in %s at line %d", __func__, __LINE__);
884 /******************************************************************
886 * @brief Search E2 node component with the help of action type
890 * Function : fetchE2NodeComponentInfo
892 * Functionality: Search E2 node component with the help of action type
896 * Component action type
897 * Pointer to E2 component node to be searched
900 * ****************************************************************/
902 E2NodeComponent *fetchE2NodeComponentInfo(InterfaceType interfaceType, uint8_t componentActionType, CmLList **e2ComponentNode)
904 E2NodeComponent *e2NodeComponentInfo=NULLP;
906 if(duCb.e2apDb.e2NodeComponentList.count)
908 CM_LLIST_FIRST_NODE(&duCb.e2apDb.e2NodeComponentList, *e2ComponentNode);
909 while(*e2ComponentNode)
911 e2NodeComponentInfo = (E2NodeComponent*)((*e2ComponentNode)->node);
912 if((e2NodeComponentInfo->interfaceType == interfaceType) && (e2NodeComponentInfo->componentActionType == componentActionType))
918 *e2ComponentNode = (*e2ComponentNode)->next;
919 e2NodeComponentInfo = NULLP;
922 return e2NodeComponentInfo;
925 /*******************************************************************
927 * @brief add or modify E2NodeComponent list
931 * Function : addOrModifyE2NodeComponent
933 * Functionality: add or modify E2NodeComponent list
937 * Component action type
938 * boolean variable to check req or rsp msg type
939 * Size of buffer which needs to be store
940 * buffer string which needs to be store
941 * @return ROK - success
944 ******************************************************************/
946 uint8_t addOrModifyE2NodeComponent(InterfaceType interfaceType, uint8_t action, bool reqPart, uint8_t bufSize, char *bufString)
948 E2NodeComponent *e2NodeComponentInfo= NULL;
949 CmLList *node = NULLP;
953 DU_ALLOC(e2NodeComponentInfo, sizeof(E2NodeComponent));
954 if(!e2NodeComponentInfo)
956 DU_LOG("\nERROR --> E2AP : Memory allocation failed for e2NodeComponentInfo in %s",__func__);
959 e2NodeComponentInfo->interfaceType =interfaceType;
960 e2NodeComponentInfo->componentId=duCfgParam.duId;
961 e2NodeComponentInfo->componentActionType = action;
962 e2NodeComponentInfo->reqBufSize = bufSize;
964 DU_ALLOC(e2NodeComponentInfo->componentRequestPart, bufSize);
965 if(e2NodeComponentInfo->componentRequestPart == NULLP)
967 DU_LOG("\nERROR --> E2AP : Memory allocation failed for componentRequestPart");
968 DU_FREE(e2NodeComponentInfo, sizeof(E2NodeComponent));
971 memcpy(e2NodeComponentInfo->componentRequestPart, bufString, e2NodeComponentInfo->reqBufSize);
972 DU_ALLOC(node, sizeof(CmLList));
975 node->node = (PTR) e2NodeComponentInfo;
976 cmLListAdd2Tail(&duCb.e2apDb.e2NodeComponentList, node);
980 DU_LOG("\nERROR --> E2AP : Memory allocation failed for e2NodeComponentList node");
981 DU_FREE(e2NodeComponentInfo->componentRequestPart, bufSize);
982 DU_FREE(e2NodeComponentInfo, sizeof(E2NodeComponent));
988 if(duCb.e2apDb.e2NodeComponentList.count)
990 e2NodeComponentInfo = fetchE2NodeComponentInfo(interfaceType, action, &node);
991 if(e2NodeComponentInfo->componentRequestPart== NULLP)
993 DU_LOG("\nERROR --> E2AP : E2 node Component request part is not present");
997 e2NodeComponentInfo->rspBufSize = bufSize;
998 DU_ALLOC(e2NodeComponentInfo->componentResponsePart, bufSize);
999 if(e2NodeComponentInfo->componentResponsePart == NULLP)
1001 DU_LOG("\nERROR --> E2AP : Memory allocation failed to store the encoding of rsp");
1004 memcpy(e2NodeComponentInfo->componentResponsePart, bufString, e2NodeComponentInfo->rspBufSize);
1009 DU_LOG("\nERROR --> E2AP : Unable to find the node");
1016 /******************************************************************
1018 * @brief Delete measured Value list
1022 * Function : deleteMeasuredValueList
1024 * Functionality: Delete measured Value list
1026 * @params[in] List of measured Value
1030 * ****************************************************************/
1031 void deleteMeasuredValueList(CmLListCp *measuredValueList)
1033 CmLList *measValNode = NULLP;
1035 CM_LLIST_FIRST_NODE(measuredValueList, measValNode);
1039 cmLListDelFrm(measuredValueList, measValNode);
1040 DU_FREE(measValNode->node, sizeof(double));
1041 DU_FREE(measValNode, sizeof(CmLList));
1042 CM_LLIST_FIRST_NODE(measuredValueList, measValNode);
1046 /******************************************************************
1048 * @brief Delete Measurement Info List
1052 * Function : deleteMeasurementInfoList
1054 * Functionality: Delete Measurement Info List
1056 * @params[in] List of Measurement Info List
1060 * ****************************************************************/
1062 void deleteMeasurementInfoList(CmLListCp *measInfoList)
1064 CmLList *measInfoNode = NULLP;
1065 MeasurementInfo *measInfo = NULLP;
1067 CM_LLIST_FIRST_NODE(measInfoList, measInfoNode);
1070 measInfo = (MeasurementInfo *)measInfoNode->node;
1071 cmLListDelFrm(measInfoList, measInfoNode);
1072 deleteMeasuredValueList(&measInfo->measuredValue);
1073 DU_FREE(measInfo, sizeof(MeasurementInfo));
1074 DU_FREE(measInfoNode, sizeof(CmLList));
1075 CM_LLIST_FIRST_NODE(measInfoList, measInfoNode);
1079 /******************************************************************
1081 * @brief Delete Ric subscription action
1085 * Function : deleteActionSequence
1087 * Functionality: Delete Ric subscription action
1089 * @params[in] Action info
1093 * ****************************************************************/
1094 void deleteActionSequence(ActionInfo *action)
1096 ActionDefinition *definition=NULLP;
1097 definition= &action->definition;
1099 switch(definition->formatType)
1103 deleteMeasurementInfoList(&definition->choice.format1.measurementInfoList);
1113 DU_LOG("\nERROR --> E2AP : Format %d does not supported", definition->formatType);
1117 memset(action, 0, sizeof(ActionInfo));
1118 action->actionId = -1;
1120 /******************************************************************
1122 * @brief Delete Ric subscription node
1126 * Function : deleteRicSubscriptionNode
1128 * Functionality: Delete Ric subscription node
1130 * @params[in] Ric subscription info
1134 * ****************************************************************/
1136 void deleteRicSubscriptionNode(CmLList *subscriptionNode)
1138 uint8_t actionIdx=0;
1139 RicSubscription *ricSubscriptionInfo = NULLP;
1141 ricSubscriptionInfo = (RicSubscription*)subscriptionNode->node;
1143 for(actionIdx = 0; actionIdx < MAX_RIC_ACTION; actionIdx++)
1145 if(ricSubscriptionInfo->actionSequence[actionIdx].actionId > -1)
1147 deleteActionSequence(&ricSubscriptionInfo->actionSequence[actionIdx]);
1151 if(duChkTmr((PTR)ricSubscriptionInfo, EVENT_RIC_SUBSCRIPTION_REPORTING_TMR) == TRUE)
1153 duStopTmr((PTR)ricSubscriptionInfo, EVENT_RIC_SUBSCRIPTION_REPORTING_TMR);
1156 memset(ricSubscriptionInfo, 0, sizeof(RicSubscription));
1157 DU_FREE(subscriptionNode->node, sizeof(RicSubscription));
1158 DU_FREE(subscriptionNode, sizeof(CmLList));
1161 /******************************************************************
1163 * @brief Delete ric subscription list from the database
1167 * Function : deleteRicSubscriptionList
1169 * Functionality: Delete ric subscription list
1172 * Subscription List to be deleted
1176 * ****************************************************************/
1179 void deleteRicSubscriptionList(CmLListCp *subscriptionList)
1181 CmLList *subscriptionNode=NULLP;
1183 CM_LLIST_FIRST_NODE(subscriptionList, subscriptionNode);
1184 while(subscriptionNode)
1186 /* TODO - Remove subscription information from MAC and SCH as well */
1187 cmLListDelFrm(subscriptionList, subscriptionNode);
1188 deleteRicSubscriptionNode(subscriptionNode);
1189 CM_LLIST_FIRST_NODE(subscriptionList, subscriptionNode);
1193 /**********************************************************************
1195 **********************************************************************/