From: Tuan Nguyen Date: Thu, 23 May 2024 11:35:44 +0000 (+0000) Subject: SIM-118: Enable to set RAN function id via environment variable X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;ds=sidebyside;h=HEAD;hp=f5900596513e4359fc839ba361da085674e90b68;p=sim%2Fe2-interface.git SIM-118: Enable to set RAN function id via environment variable Improve log message, remove unused files Change-Id: Ie1b7fa634c6f2db434f064784b92b42a89993aa2 Signed-off-by: Tuan Nguyen --- diff --git a/e2sim/Dockerfile_kpm b/e2sim/Dockerfile_kpm index a5ddfa7..63a77b0 100755 --- a/e2sim/Dockerfile_kpm +++ b/e2sim/Dockerfile_kpm @@ -32,10 +32,10 @@ # the builder has: git, wget, cmake, gcc/g++, make, python2/3. v7 dropped nng support # ARG CONTAINER_PULL_REGISTRY=nexus3.o-ran-sc.org:10001 -FROM ${CONTAINER_PULL_REGISTRY}/o-ran-sc/bldr-ubuntu18-c-go:1.9.0 as buildenv +FROM ${CONTAINER_PULL_REGISTRY}/o-ran-sc/bldr-ubuntu22-c-go:1.0.0 as buildenv # spaces to save things in the build image to copy to final image -RUN mkdir -p /playpen/assets /playpen/src /playpen/bin /playpen/asn1c +RUN mkdir -p /playpen/assets /playpen/src /playpen/bin /playpen/asn1c /playpen/e2sim ARG SRC=. WORKDIR /playpen @@ -65,10 +65,16 @@ RUN apt-get update \ nmap \ && apt-get clean -COPY e2sm_examples/kpm_e2sm/e2sim_1.0.0_amd64.deb /playpen -COPY e2sm_examples/kpm_e2sm/e2sim-dev_1.0.0_amd64.deb /playpen +COPY asn1c/ /playpen/e2sim/asn1c +COPY e2sm_examples/ /playpen/e2sim/e2sm_examples +COPY src/ /playpen/e2sim/src +COPY CMakeLists.txt /playpen/e2sim -RUN dpkg -i e2sim_1.0.0_amd64.deb e2sim-dev_1.0.0_amd64.deb +RUN mkdir /playpen/e2sim/build && cd /playpen/e2sim/build && cmake .. && make package && cmake .. -DDEV_PKG=1 && make package + +RUN dpkg -i /playpen/e2sim/build/e2sim_1.0.0_amd64.deb /playpen/e2sim/build/e2sim-dev_1.0.0_amd64.deb + +RUN rm -rf /playpen/e2sim RUN mkdir /usr/local/include/nlohmann RUN git clone https://github.com/azadkuh/nlohmann_json_release.git @@ -85,4 +91,4 @@ RUN wc -l /playpen/src/reports.json make install #CMD sleep 100000000000 -#CMD kpm_sim 10.111.138.172 36422 +#CMD kpm_sim 10.111.138.172 32222 diff --git a/e2sim/e2sm_examples/kpm_e2sm/e2sim-dev_1.0.0_amd64.deb b/e2sim/e2sm_examples/kpm_e2sm/e2sim-dev_1.0.0_amd64.deb deleted file mode 100755 index 7abedad..0000000 Binary files a/e2sim/e2sm_examples/kpm_e2sm/e2sim-dev_1.0.0_amd64.deb and /dev/null differ diff --git a/e2sim/e2sm_examples/kpm_e2sm/e2sim_1.0.0_amd64.deb b/e2sim/e2sm_examples/kpm_e2sm/e2sim_1.0.0_amd64.deb deleted file mode 100755 index 7dda0da..0000000 Binary files a/e2sim/e2sm_examples/kpm_e2sm/e2sim_1.0.0_amd64.deb and /dev/null differ diff --git a/e2sim/e2sm_examples/kpm_e2sm/src/kpm/encode_kpm.cpp b/e2sim/e2sm_examples/kpm_e2sm/src/kpm/encode_kpm.cpp index 8bfe7c6..676c5a1 100755 --- a/e2sim/e2sm_examples/kpm_e2sm/src/kpm/encode_kpm.cpp +++ b/e2sim/e2sm_examples/kpm_e2sm/src/kpm/encode_kpm.cpp @@ -27,15 +27,26 @@ #include "e2sim_defs.h" using namespace std; +const char* performance_measurements[] = { + "DRB.RlcSduTransmittedVolumeDL_Filter", + "DRB.RlcSduTransmittedVolumeUL_Filter", + "DRB.PerDataVolumeDLDist.Bin", + "DRB.PerDataVolumeULDist.Bin", + "DRB.RlcPacketDropRateDLDist", + "DRB.PacketLossRateULDist", + "L1M.DL-SS-RSRP.SSB", + "L1M.DL-SS-SINR.SSB", + "L1M.UL-SRS-RSRP" + }; + +int NUMBER_MEASUREMENTS = 9; + void encode_kpm_function_description(E2SM_KPM_RANfunction_Description_t* ranfunc_desc) { uint8_t* short_name = (uint8_t*)"ORAN-E2SM-KPM"; uint8_t* func_desc = (uint8_t*)"KPM Monitor"; uint8_t* e2sm_odi = (uint8_t*)"OID123"; LOG_I("short_name: %s, func_desc: %s, e2sm_odi: %s", short_name, func_desc, e2sm_odi); - - long inst = 1; - ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_RANfunction_Description, ranfunc_desc); ranfunc_desc->ranFunction_Name.ranFunction_ShortName.size = strlen((char*)short_name); @@ -49,7 +60,8 @@ void encode_kpm_function_description(E2SM_KPM_RANfunction_Description_t* ranfunc memcpy(ranfunc_desc->ranFunction_Name.ranFunction_Description.buf, func_desc, strlen((char*)func_desc)); ranfunc_desc->ranFunction_Name.ranFunction_Description.size = strlen((char*)func_desc); - ranfunc_desc->ranFunction_Name.ranFunction_Instance = &inst; + ranfunc_desc->ranFunction_Name.ranFunction_Instance = (long *)calloc(1, sizeof(long)); + *ranfunc_desc->ranFunction_Name.ranFunction_Instance = 1; ranfunc_desc->ranFunction_Name.ranFunction_E2SM_OID.buf = (uint8_t*)calloc(1, strlen((char*)e2sm_odi)); @@ -66,7 +78,7 @@ void encode_kpm_function_description(E2SM_KPM_RANfunction_Description_t* ranfunc trigger_style->ric_EventTriggerStyle_Name.buf = (uint8_t*)calloc(1, strlen((char*)style_name)); memcpy(trigger_style->ric_EventTriggerStyle_Name.buf, style_name, strlen((char*)style_name)); trigger_style->ric_EventTriggerStyle_Name.size = strlen((char*)style_name); - trigger_style->ric_EventTriggerFormat_Type = 5; + trigger_style->ric_EventTriggerFormat_Type = 1; ranfunc_desc->ric_EventTriggerStyle_List = (E2SM_KPM_RANfunction_Description:: @@ -80,10 +92,9 @@ void encode_kpm_function_description(E2SM_KPM_RANfunction_Description_t* ranfunc MeasurementInfo_Action_List_t* measInfo_Action_List = (MeasurementInfo_Action_List_t*)calloc(1, sizeof(MeasurementInfo_Action_List_t)); - uint8_t* measured_metrics[] = {(uint8_t*)"CQI", (uint8_t*)"RSRP", (uint8_t*)"RSRQ"}; - for (int i = 0; i < 3; i++) { - uint8_t* metrics = measured_metrics[i]; + for (int i = 0; i < NUMBER_MEASUREMENTS; i++) { + uint8_t* metrics = (uint8_t *)performance_measurements[i]; MeasurementInfo_Action_Item_t* measItem = (MeasurementInfo_Action_Item_t*)calloc(1, sizeof(MeasurementInfo_Action_Item_t)); measItem->measName.buf = (uint8_t*)calloc(1, strlen((char*)metrics)); @@ -218,90 +229,67 @@ void kpm_report_indication_header_initialized(E2SM_KPM_IndicationHeader_t* ihead ind_header->colletStartTime = *ts; if (ts) free(ts); - uint8_t* buf5 = (uint8_t*)"1.0"; - ind_header->fileFormatversion = (PrintableString_t*)calloc(1, sizeof(PrintableString_t)); - ind_header->fileFormatversion->buf = (uint8_t*)calloc(1, strlen((char*)buf5)); - memcpy(ind_header->fileFormatversion->buf, buf5, strlen((char*)buf5)); - ind_header->fileFormatversion->size = strlen((char*)buf5); - ihead->indicationHeader_formats.present = E2SM_KPM_IndicationHeader__indicationHeader_formats_PR_indicationHeader_Format1; ihead->indicationHeader_formats.choice.indicationHeader_Format1 = ind_header; - // xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationHeader, ihead); } void ue_meas_kpm_report_indication_message_initialized( E2SM_KPM_IndicationMessage_t* indicationmessage, uint8_t* nrcellid_buf, uint8_t* crnti_buf, const uint8_t* serving_buf, const uint8_t* neighbor_buf) { - GranularityPeriod_t period = 1; - MeasurementData_t* measData = (MeasurementData_t*)calloc(1, sizeof(MeasurementData_t)); - MeasurementDataItem_t* measDataItem = - (MeasurementDataItem_t*)calloc(1, sizeof(MeasurementDataItem_t)); - MeasurementRecord_t* measDataItem_record = - (MeasurementRecord_t*)calloc(1, sizeof(MeasurementRecord_t)); - MeasurementRecordItem_t* measDataRecordItem = - (MeasurementRecordItem_t*)calloc(1, sizeof(MeasurementRecordItem_t)); - - unsigned long val = 1; - measDataRecordItem->present = MeasurementRecordItem_PR_integer; - measDataRecordItem->choice.integer = val; - - ASN_SEQUENCE_ADD(&measDataItem_record->list, measDataRecordItem); + + MeasurementRecord_t* measDataItem_record = (MeasurementRecord_t*)calloc(1, sizeof(MeasurementRecord_t)); + for (size_t i = 0; i < NUMBER_MEASUREMENTS; i++) + { + MeasurementRecordItem_t* measDataRecordItem = (MeasurementRecordItem_t*)calloc(1, sizeof(MeasurementRecordItem_t)); + measDataRecordItem->present = MeasurementRecordItem_PR_integer; + measDataRecordItem->choice.integer = 1; + + ASN_SEQUENCE_ADD(&measDataItem_record->list, measDataRecordItem); + } + MeasurementDataItem_t* measDataItem = (MeasurementDataItem_t*)calloc(1, sizeof(MeasurementDataItem_t)); measDataItem->measRecord = *measDataItem_record; - long incomplete = 0; measDataItem->incompleteFlag = (long*)calloc(1, sizeof(long)); - *measDataItem->incompleteFlag = incomplete; + *measDataItem->incompleteFlag = 0; + + MeasurementData_t* measData = (MeasurementData_t*)calloc(1, sizeof(MeasurementData_t)); ASN_SEQUENCE_ADD(&measData->list, measDataItem); + MeasurementInfoList_t* measList = (MeasurementInfoList_t*)calloc(1, sizeof(MeasurementInfoList_t)); + for (size_t i = 0; i < NUMBER_MEASUREMENTS; i++) + { + MeasurementLabel_t* measLabel = (MeasurementLabel_t*)calloc(1, sizeof(MeasurementLabel_t)); + measLabel->noLabel = (long *)calloc(1, sizeof(long)); + *measLabel->noLabel = 0; + + LabelInfoItem_t* labelItem = (LabelInfoItem_t*)calloc(1, sizeof(LabelInfoItem_t)); + labelItem->measLabel = *measLabel; + + LabelInfoList_t* labelList = (LabelInfoList_t*)calloc(1, sizeof(LabelInfoList_t)); + ASN_SEQUENCE_ADD(&labelList->list, labelItem); + + MeasurementType_t measType; + measType.present = MeasurementType_PR_measID; + uint8_t* metrics = (uint8_t *)performance_measurements[i]; + measType.choice.measName.buf = (uint8_t*)calloc(1, strlen((char*)metrics)); + memcpy(measType.choice.measName.buf, metrics, strlen((char*)metrics)); + measType.choice.measName.size = strlen((char*)metrics); + + MeasurementInfoItem_t* measItem = (MeasurementInfoItem_t*)calloc(1, sizeof(MeasurementInfoItem_t)); + measItem->measType = measType; + measItem->labelInfoList = *labelList; + if (labelList) free(labelList); + + ASN_SEQUENCE_ADD(&measList->list, measItem); + } + E2SM_KPM_IndicationMessage_Format1_t* format = (E2SM_KPM_IndicationMessage_Format1_t*)calloc( 1, sizeof(E2SM_KPM_IndicationMessage_Format1_t)); format->granulPeriod = (GranularityPeriod_t*)calloc(1, sizeof(GranularityPeriod_t)); - *format->granulPeriod = period; + *format->granulPeriod = 1; format->measData = *measData; - - MeasurementInfoList_t* measList = - (MeasurementInfoList_t*)calloc(1, sizeof(MeasurementInfoList_t)); - MeasurementInfoItem_t* measItem = - (MeasurementInfoItem_t*)calloc(1, sizeof(MeasurementInfoItem_t)); - LabelInfoList_t* labelList = (LabelInfoList_t*)calloc(1, sizeof(LabelInfoList_t)); - LabelInfoItem_t* labelItem = (LabelInfoItem_t*)calloc(1, sizeof(LabelInfoItem_t)); - MeasurementLabel_t* measLabel = (MeasurementLabel_t*)calloc(1, sizeof(MeasurementLabel_t)); - - uint8_t* plmnid_buf = (uint8_t*)"747"; - uint8_t* sst_buf = (uint8_t*)"1"; - uint8_t* sd_buf = (uint8_t*)"100"; - - S_NSSAI_t* snssai = (S_NSSAI_t*)calloc(1, sizeof(S_NSSAI_t)); - snssai->sST.buf = (uint8_t*)calloc(strlen((char*)sst_buf), sizeof(uint8_t)); - snssai->sST.size = strlen((char*)sst_buf); - memcpy(snssai->sST.buf, sst_buf, strlen((char*)sst_buf)); - - snssai->sD = (SD_t*)calloc(1, sizeof(SD_t)); - snssai->sD->buf = (uint8_t*)calloc(strlen((char*)sd_buf), sizeof(uint8_t)); - snssai->sD->size = strlen((char*)sd_buf); - memcpy(snssai->sD->buf, sd_buf, strlen((char*)sd_buf)); - - int plmnid_size = strlen((char*)plmnid_buf); - PLMNIdentity_t* plmnidstr = (PLMNIdentity_t*)calloc(1, sizeof(PLMNIdentity_t)); - plmnidstr->buf = (uint8_t*)calloc(plmnid_size, 1); - plmnidstr->size = plmnid_size; - memcpy(plmnidstr->buf, plmnid_buf, plmnidstr->size); - - measLabel->plmnID = plmnidstr; - measLabel->sliceID = snssai; - - labelItem->measLabel = *measLabel; - ASN_SEQUENCE_ADD(&labelList->list, labelItem); - measItem->labelInfoList = *labelList; - if (labelList) free(labelList); - MeasurementType_t measType; - measType.present = MeasurementType_PR_measID; - measType.choice.measID = 1; - measItem->measType = measType; - ASN_SEQUENCE_ADD(&measList->list, measItem); - format->measInfoList = measList; E2SM_KPM_IndicationMessage__indicationMessage_formats_PR pres = @@ -417,7 +405,6 @@ void cell_meas_kpm_report_indication_message_style_1_initialized( if (ret) { LOG_I("Constraint validation of indication message failed: %s\n", error_buf); } - // xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage); } void encode_kpm_report_style1(E2SM_KPM_IndicationMessage_t* indicationmessage) { @@ -478,9 +465,11 @@ void encode_kpm_report_style1(E2SM_KPM_IndicationMessage_t* indicationmessage) { indicationmessage, e2smbuffer, e2smbuffer_size); if (er.encoded == -1) { - LOG_I("Failed to serialize message. Detail: %s.\n", asn_DEF_E2SM_KPM_IndicationMessage.name); + LOG_E("Failed to serialize message. Detail: %s.\n", asn_DEF_E2SM_KPM_IndicationMessage.name); + exit(1); } else if (er.encoded > e2smbuffer_size) { - LOG_I("Buffer of size %zu is too small for %s, need %zu\n", e2smbuffer_size, asn_DEF_E2SM_KPM_IndicationMessage.name, er.encoded); + LOG_E("Buffer of size %zu is too small for %s, need %zu\n", e2smbuffer_size, asn_DEF_E2SM_KPM_IndicationMessage.name, er.encoded); + exit(1); } } diff --git a/e2sim/e2sm_examples/kpm_e2sm/src/kpm/kpm_callbacks.cpp b/e2sim/e2sm_examples/kpm_e2sm/src/kpm/kpm_callbacks.cpp index 59bd744..2c94856 100755 --- a/e2sim/e2sm_examples/kpm_e2sm/src/kpm/kpm_callbacks.cpp +++ b/e2sim/e2sm_examples/kpm_e2sm/src/kpm/kpm_callbacks.cpp @@ -50,11 +50,13 @@ extern "C" { #include "viavi_connector.hpp" #include "errno.h" #include "e2sim_defs.h" +#include + using json = nlohmann::json; using namespace std; class E2Sim; - +int gFuncId; E2Sim e2sim; @@ -97,10 +99,12 @@ int main(int argc, char* argv[]) { ranfunc_ostr->buf = (uint8_t*)calloc(1,er.encoded); ranfunc_ostr->size = er.encoded; memcpy(ranfunc_ostr->buf,e2smbuffer,er.encoded); - - e2sim.register_e2sm(0,ranfunc_ostr); - e2sim.register_subscription_callback(0,&callback_kpm_subscription_request); + const char* func_id_str = std::getenv("RAN_FUNC_ID"); + ::gFuncId = func_id_str == nullptr ? 0 : std::stoi(func_id_str); + + e2sim.register_e2sm(gFuncId, ranfunc_ostr); + e2sim.register_subscription_callback(gFuncId, &callback_kpm_subscription_request); e2sim.run_loop(argc, argv); } @@ -337,7 +341,7 @@ void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long LOG_I("Buffer of size %zu is too small for %s, need %zu\n", e2sm_message_buf_size_cucp_ue, asn_DEF_E2SM_KPM_IndicationMessage.name, er_message_cucp_ue.encoded); exit(1); } else { - LOG_I("Encoded UE indication message succesfully, size in bytes: %d", er_message_cucp_ue.encoded) + LOG_I("Encoded UE indication message succesfully, size in bytes: %zu", er_message_cucp_ue.encoded) } ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationMessage, ind_msg_cucp_ue); @@ -362,7 +366,7 @@ void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long LOG_I("Buffer of size %zu is too small for %s, need %zu\n", e2sm_header_buf_size_cucp_ue, asn_DEF_E2SM_KPM_IndicationHeader.name, er_header_cucp_ue.encoded); exit(1); } else { - LOG_I("Encoded UE indication header succesfully, size in bytes: %d", er_header_cucp_ue.encoded); + LOG_I("Encoded UE indication header succesfully, size in bytes: %zu", er_header_cucp_ue.encoded); for(int i = 0; i < er_header_cucp_ue.encoded; i ++) { printf("%x ", e2sm_header_buf_cucp_ue[i]); } @@ -381,7 +385,7 @@ void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long er_message_cucp_ue.encoded); e2sim.encode_and_send_sctp_data(pdu_cucp_ue); - LOG_I("Measurement report for UE %d has been sent\n", i); + LOG_I("Measurement report for UE %d has been sent", i); seqNum++; std::this_thread::sleep_for (std::chrono::milliseconds(50)); } @@ -473,13 +477,13 @@ void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long e2sm_message_buf_style1, e2sm_message_buf_size_style1); if(er_message_style1.encoded == -1) { - LOG_I("Failed to serialize data. Detail: %s.\n", asn_DEF_E2SM_KPM_IndicationMessage.name); + LOG_I("Failed to serialize data. Detail: %s.", asn_DEF_E2SM_KPM_IndicationMessage.name); exit(1); } else if(er_message_style1.encoded > e2sm_message_buf_size_style1) { LOG_I("Buffer of size %zu is too small for %s, need %zu\n", e2sm_message_buf_size_style1, asn_DEF_E2SM_KPM_IndicationMessage.name, er_message_style1.encoded); exit(1); } else { - LOG_I("Encoded Cell indication message succesfully, size in bytes: %d", er_message_style1.encoded) + LOG_I("Encoded Cell indication message succesfully, size in bytes: %ld", er_message_style1.encoded) } ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationMessage, ind_message_style1); @@ -531,8 +535,6 @@ void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long void callback_kpm_subscription_request(E2AP_PDU_t *sub_req_pdu) { - fprintf(stderr, "[%s:%d]Calling callback_kpm_subscription_request"); - //Record RIC Request ID //Go through RIC action to be Setup List //Find first entry with REPORT action Type @@ -563,79 +565,70 @@ void callback_kpm_subscription_request(E2AP_PDU_t *sub_req_pdu) { RICsubscriptionRequest_IEs_t *next_ie = ies[i]; pres = next_ie->value.present; - LOG_I("The next present value %d\n", pres); + LOG_I("The next present value %d", pres); switch(pres) { - case RICsubscriptionRequest_IEs__value_PR_RICrequestID: - { - LOG_I("in case request id"); - RICrequestID_t reqId = next_ie->value.choice.RICrequestID; - long requestorId = reqId.ricRequestorID; - long instanceId = reqId.ricInstanceID; - LOG_I("requestorId %d\n", requestorId); - LOG_I("instanceId %d\n", instanceId); - reqRequestorId = requestorId; - reqInstanceId = instanceId; - - break; - } - case RICsubscriptionRequest_IEs__value_PR_RANfunctionID: - { - LOG_I("in case ran func id"); - break; - } - case RICsubscriptionRequest_IEs__value_PR_RICsubscriptionDetails: - { - RICsubscriptionDetails_t subDetails = next_ie->value.choice.RICsubscriptionDetails; - RICeventTriggerDefinition_t triggerDef = subDetails.ricEventTriggerDefinition; - RICactions_ToBeSetup_List_t actionList = subDetails.ricAction_ToBeSetup_List; - //We are ignoring the trigger definition - - //We identify the first action whose type is REPORT - //That is the only one accepted; all others are rejected - - int actionCount = actionList.list.count; - LOG_I("Action count%d\n", actionCount); + case RICsubscriptionRequest_IEs__value_PR_RICrequestID: { + LOG_I("in case request id"); + RICrequestID_t reqId = next_ie->value.choice.RICrequestID; + long requestorId = reqId.ricRequestorID; + long instanceId = reqId.ricInstanceID; - auto **item_array = actionList.list.array; + LOG_I("requestorId: %ld, InstanceID: %ld", requestorId, instanceId); - bool foundAction = false; + reqRequestorId = requestorId; + reqInstanceId = instanceId; - for (int i=0; i < actionCount; i++) { + break; + } + case RICsubscriptionRequest_IEs__value_PR_RANfunctionID: { + LOG_I("in case ran func id"); + break; + } + case RICsubscriptionRequest_IEs__value_PR_RICsubscriptionDetails: { + RICsubscriptionDetails_t subDetails = next_ie->value.choice.RICsubscriptionDetails; + RICeventTriggerDefinition_t triggerDef = subDetails.ricEventTriggerDefinition; + RICactions_ToBeSetup_List_t actionList = subDetails.ricAction_ToBeSetup_List; + //We are ignoring the trigger definition - auto *next_item = item_array[i]; - RICactionID_t actionId = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionID; - RICactionType_t actionType = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionType; + //We identify the first action whose type is REPORT + //That is the only one accepted; all others are rejected - if (!foundAction && actionType == RICactionType_report) { - reqActionId = actionId; - actionIdsAccept.push_back(reqActionId); - foundAction = true; - } else { - reqActionId = actionId; - actionIdsReject.push_back(reqActionId); - } - } - - break; - } - default: - { - break; - } + int actionCount = actionList.list.count; + LOG_I("Action count%d", actionCount); + + auto **item_array = actionList.list.array; + + bool foundAction = false; + + for (int i=0; i < actionCount; i++) { + auto *next_item = item_array[i]; + RICactionID_t actionId = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionID; + RICactionType_t actionType = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionType; + + if (!foundAction && actionType == RICactionType_report) { + reqActionId = actionId; + actionIdsAccept.push_back(reqActionId); + foundAction = true; + } else { + reqActionId = actionId; + actionIdsReject.push_back(reqActionId); + } + } + + break; + } + default: { + break; + } } } LOG_I("After Processing Subscription Request"); - LOG_I("requestorId %d\n", reqRequestorId); - LOG_I("instanceId %d\n", reqInstanceId); - - for (int i=0; i < actionIdsAccept.size(); i++) { - LOG_I("Action ID %d %ld\n", i, actionIdsAccept.at(i)); - + LOG_D("Action ID %d %ld\n", i, actionIdsAccept.at(i)); } E2AP_PDU *e2ap_pdu = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU)); @@ -650,8 +643,7 @@ void callback_kpm_subscription_request(E2AP_PDU_t *sub_req_pdu) { LOG_I("Encode and sending E2AP subscription success response via SCTP"); e2sim.encode_and_send_sctp_data(e2ap_pdu); - long funcId = 0; - - run_report_loop(reqRequestorId, reqInstanceId, funcId, reqActionId); + LOG_I("Now generating data for subscription request"); + run_report_loop(reqRequestorId, reqInstanceId, gFuncId, reqActionId); } diff --git a/e2sim/src/DEF/e2sim_defs.h b/e2sim/src/DEF/e2sim_defs.h index f10cebf..dc469ba 100755 --- a/e2sim/src/DEF/e2sim_defs.h +++ b/e2sim/src/DEF/e2sim_defs.h @@ -49,12 +49,40 @@ char* time_stamp(void); else { \ fileName = file; \ } \ - printf("[%s:%d] ", fileName, __LINE__); \ - printf(format, ##__VA_ARGS__); \ - printf("\n"); \ + fprintf(stderr, "[%s:%d] [INFO] ", fileName, __LINE__); \ + fprintf(stderr, format, ##__VA_ARGS__); \ + fprintf(stderr, "\n"); \ + } while (0); + +#define LOG_D(format, ...) \ + do { \ + const char *file = __FILE__; \ + const char *fileName = strrchr(file, '/'); \ + if (fileName != NULL) { \ + fileName++; \ + } \ + else { \ + fileName = file; \ + } \ + fprintf(stderr, "[%s:%d] [DEBUG] ", fileName, __LINE__); \ + fprintf(stderr, format, ##__VA_ARGS__); \ + fprintf(stderr, "\n"); \ + } while (0); + +#define LOG_E(format, ...) \ + do { \ + const char *file = __FILE__; \ + const char *fileName = strrchr(file, '/'); \ + if (fileName != NULL) { \ + fileName++; \ + } \ + else { \ + fileName = file; \ + } \ + fprintf(stderr, "[%s:%d] [ERROR] ", fileName, __LINE__); \ + fprintf(stderr, format, ##__VA_ARGS__); \ + fprintf(stderr, "\n"); \ } while (0); -#define LOG_E(...) {printf(__VA_ARGS__); printf("\n");} -#define LOG_D(...) {printf(__VA_ARGS__); printf("\n");} typedef struct SCTP_DATA { unsigned char *data; @@ -74,6 +102,4 @@ typedef struct { options_t read_input_options(int argc, char *argv[]); -#define min(a, b) ((a) < (b)) ? (a) : (b) - #endif diff --git a/e2sim/src/base/e2sim.cpp b/e2sim/src/base/e2sim.cpp index 9c3ec42..6203171 100755 --- a/e2sim/src/base/e2sim.cpp +++ b/e2sim/src/base/e2sim.cpp @@ -40,13 +40,13 @@ std::unordered_map E2Sim::getRegistered_ran_functions() { } void E2Sim::register_subscription_callback(long func_id, SubscriptionCallback cb) { - fprintf(stderr,"%%%%about to register callback for subscription for func_id %d\n", func_id); + LOG_I("About to register callback for subscription for RAN function with ID %d", func_id); subscription_callbacks[func_id] = cb; } SubscriptionCallback E2Sim::get_subscription_callback(long func_id) { - fprintf(stderr, "%%%%we are getting the subscription callback for func id %d\n", func_id); + LOG_I("We are getting the subscription callback for func id %d", func_id); SubscriptionCallback cb; try { @@ -62,14 +62,10 @@ void E2Sim::register_e2sm(long func_id, OCTET_STRING_t *ostr) { //Error conditions: //If we already have an entry for func_id - - printf("%%%%about to register e2sm func desc for %d\n", func_id); - + LOG_I("About to register E2SM RAN function description with ID %d", func_id); ran_functions_registered[func_id] = ostr; - } - void E2Sim::encode_and_send_sctp_data(E2AP_PDU_t* pdu) { uint8_t *buf; @@ -78,9 +74,6 @@ void E2Sim::encode_and_send_sctp_data(E2AP_PDU_t* pdu) data.len = e2ap_asn1c_encode_pdu(pdu, &buf); memcpy(data.buffer, buf, min(data.len, MAX_SCTP_BUFFER)); if (buf) free(buf); - - LOG_I("Number of bytes sent via SCTP connection %d", min(data.len, MAX_SCTP_BUFFER)); - sctp_send_data(client_fd, data); } @@ -108,7 +101,7 @@ void E2Sim::generate_e2apv1_indication_request_parameterized(E2AP_PDU *e2ap_pdu, int E2Sim::run_loop(int argc, char* argv[]){ - printf("Start E2 Agent (E2 Simulator\n"); + LOG_I("Start E2 Agent (E2 Simulator)"); ifstream simfile; string line; @@ -129,7 +122,7 @@ int E2Sim::run_loop(int argc, char* argv[]){ options_t ops = read_input_options(argc, argv); - printf("After reading input options\n"); + LOG_I("After reading input options"); //E2 Agent will automatically restart upon sctp disconnection // int server_fd = sctp_start_server(ops.server_ip, ops.server_port); @@ -137,8 +130,7 @@ int E2Sim::run_loop(int argc, char* argv[]){ client_fd = sctp_start_client(ops.server_ip, ops.server_port); E2AP_PDU_t* pdu_setup = (E2AP_PDU_t*)calloc(1,sizeof(E2AP_PDU)); - printf("After starting client\n"); - printf("client_fd value is %d\n", client_fd); + LOG_I("SCTP client has been started"); std::vector all_funcs; RANfunctionOID_t *ranFunctionOIDe = (RANfunctionOID_t*)calloc(1,sizeof(RANfunctionOID_t)); @@ -148,9 +140,14 @@ int E2Sim::run_loop(int argc, char* argv[]){ ranFunctionOIDe->size = strlen((char*)buf); //Loop through RAN function definitions that are registered - + LOG_I("Constructing a list of RAN functions based on registered information"); for (std::pair elem : ran_functions_registered) { - printf("looping through ran func\n"); + char* ran_desc = (char*) calloc(1, elem.second->size+1); + ran_desc = (char*)elem.second->buf; + ran_desc[elem.second->size] = '\0'; + + LOG_I("Adding RAN function ID %ld, description: %s to the list", elem.first, ran_desc); + encoding::ran_func_info next_func; next_func.ranFunctionId = elem.first; @@ -161,15 +158,11 @@ int E2Sim::run_loop(int argc, char* argv[]){ all_funcs.push_back(next_func); } - printf("about to call setup request encode\n"); + LOG_I("Generate E2AP v1 setup request for all registered RAN functions"); generate_e2apv1_setup_request_parameterized(pdu_setup, all_funcs); - printf("After generating e2setup req\n"); - xer_fprint(stderr, &asn_DEF_E2AP_PDU, pdu_setup); - printf("After XER Encoding\n"); - auto buffer_size = MAX_SCTP_BUFFER; unsigned char buffer[MAX_SCTP_BUFFER]; @@ -179,66 +172,41 @@ int E2Sim::run_loop(int argc, char* argv[]){ size_t errlen = 0; asn_check_constraints(&asn_DEF_E2AP_PDU, pdu_setup, error_buf, &errlen); - printf("error length %d\n", errlen); - printf("error buf %s\n", error_buf); + LOG_I("Error length %d, error buf %s", errlen, error_buf); auto er = asn_encode_to_buffer(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, pdu_setup, buffer, buffer_size); data.len = er.encoded; - fprintf(stderr, "er encded is %d\n", er.encoded); + LOG_I("Error encoded %d", er.encoded); memcpy(data.buffer, buffer, er.encoded); if(sctp_send_data(client_fd, data) > 0) { - LOG_I("[SCTP] Sent E2-SETUP-REQUEST"); + LOG_I("Sent E2-SETUP-REQUEST as E2AP message"); } else { - LOG_E("[SCTP] Unable to send E2-SETUP-REQUEST to peer"); + LOG_E("Fail to send E2-SETUP-REQUEST to peer"); } buffer_size = MAX_SCTP_BUFFER; memset(buffer, '\0', sizeof(buffer)); - E2AP_PDU_t* pdu = (E2AP_PDU_t*)calloc(1,sizeof(E2AP_PDU)); - - LOG_D("about to call E2ResetRequest encode\n"); - - encoding::generate_e2apv2_reset_request(pdu); - - LOG_D("[E2AP] Created E2ResetRequest"); - - e2ap_asn1c_print_pdu(pdu); - - sctp_buffer_t resetdata; - - error_buf[300] = {0, }; - errlen = 0; - - asn_check_constraints(&asn_DEF_E2AP_PDU, pdu, error_buf, &errlen); - printf("error length %d\n", errlen); - printf("error buf %s\n", error_buf); - er = asn_encode_to_buffer(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, pdu, buffer, buffer_size); - - resetdata.len = er.encoded; - fprintf(stderr, "er encoded is %d\n", er.encoded); - - memcpy(resetdata.buffer, buffer, er.encoded); - - LOG_I("Test to delete ReSet code"); sctp_buffer_t recv_buf; - LOG_I("[SCTP] Waiting for SCTP data"); + LOG_I("Waiting for SCTP data"); while(1) //constantly looking for data on SCTP interface { if(sctp_receive_data(client_fd, recv_buf) <= 0) break; - LOG_I("[SCTP] Received new data of size %d", recv_buf.len); + LOG_I("Received new data of size %d", recv_buf.len); e2ap_handle_sctp_data(client_fd, recv_buf, xmlenc, this); if (xmlenc) xmlenc = false; } + close(client_fd); + return 0; } diff --git a/e2sim/src/encoding/encode_e2apv1.cpp b/e2sim/src/encoding/encode_e2apv1.cpp index 85d8cbf..85dae2a 100755 --- a/e2sim/src/encoding/encode_e2apv1.cpp +++ b/e2sim/src/encoding/encode_e2apv1.cpp @@ -71,8 +71,7 @@ long encoding::get_function_id_from_subscription(E2AP_PDU_t *e2ap_pdu) { RICsubscriptionRequest_IEs_t **ies = (RICsubscriptionRequest_IEs_t**)orig_req.protocolIEs.list.array; - fprintf(stderr, "count%d\n", count); - fprintf(stderr, "size%d\n", size); + LOG_I("Number of IEs in original request: %d, size: %d", count, size); RICsubscriptionRequest_IEs__value_PR pres; @@ -82,17 +81,15 @@ long encoding::get_function_id_from_subscription(E2AP_PDU_t *e2ap_pdu) { RICsubscriptionRequest_IEs_t *next_ie = ies[i]; pres = next_ie->value.present; - fprintf(stderr, "next present value %d\n", pres); - fprintf(stderr, "value of pres ranfuncid is %d\n", RICsubscriptionRequest_IEs__value_PR_RANfunctionID); + LOG_D("Next present value: %d, pres RAN func id: %d", pres, RICsubscriptionRequest_IEs__value_PR_RANfunctionID); if (pres == RICsubscriptionRequest_IEs__value_PR_RANfunctionID) { - fprintf(stderr, "equal pres to ranfuncid\n"); + LOG_E("equal pres to ranfuncid"); func_id = next_ie->value.choice.RANfunctionID; } - } - fprintf(stderr, "After loop, func_id is %d\n", func_id); + LOG_I("After loop, func_id is %d", func_id); return func_id; @@ -100,7 +97,7 @@ long encoding::get_function_id_from_subscription(E2AP_PDU_t *e2ap_pdu) { void encoding::generate_e2apv1_service_update(E2AP_PDU_t *e2ap_pdu, std::vector all_funcs) { char* ran_function_op_type = getenv("RAN_FUNCTION_OP_TYPE"); - LOG_D("Ran funciton : %s", ran_function_op_type); + LOG_D("Ran function : %s", ran_function_op_type); ProtocolIE_ID_t prID; if (ran_function_op_type != NULL) { @@ -668,7 +665,7 @@ void encoding::generate_e2apv1_subscription_response_success(E2AP_PDU *e2ap_pdu, respfuncid->id = ProtocolIE_ID_id_RANfunctionID; respfuncid->criticality = 0; respfuncid->value.present = RICsubscriptionResponse_IEs__value_PR_RANfunctionID; - respfuncid->value.choice.RANfunctionID = (long)0; + respfuncid->value.choice.RANfunctionID = (long)147; RICsubscriptionResponse_IEs_t *ricactionadmitted = @@ -756,14 +753,9 @@ void encoding::generate_e2apv1_subscription_response_success(E2AP_PDU *e2ap_pdu, size_t errlen = 0; asn_check_constraints(&asn_DEF_E2AP_PDU, e2ap_pdu, error_buf, &errlen); - printf("error length %d\n", errlen); - printf("error buf %s\n", error_buf); - - printf("now printing xer of subscription response\n"); - xer_fprint(stderr, &asn_DEF_E2AP_PDU, e2ap_pdu); - printf("done printing xer of subscription response\n"); - + LOG_I("Subscription response"); + xer_fprint(stderr, &asn_DEF_E2AP_PDU, e2ap_pdu); } void encoding::generate_e2apv1_subscription_response(E2AP_PDU *e2ap_pdu, E2AP_PDU *sub_req_pdu) { @@ -781,8 +773,7 @@ void encoding::generate_e2apv1_subscription_response(E2AP_PDU *e2ap_pdu, E2AP_PD RICsubscriptionRequest_IEs_t **ies = (RICsubscriptionRequest_IEs_t**)orig_req.protocolIEs.list.array; - fprintf(stderr, "count%d\n", count); - fprintf(stderr, "size%d\n", size); + LOG_I("Number of IEs in original request: %d, size: %d", count, size); RICsubscriptionRequest_IEs__value_PR pres; @@ -796,61 +787,49 @@ void encoding::generate_e2apv1_subscription_response(E2AP_PDU *e2ap_pdu, E2AP_PD RICsubscriptionRequest_IEs_t *next_ie = ies[i]; pres = next_ie->value.present; - fprintf(stderr, "next present value %d\n", pres); + LOG_D("Next present value %d", pres); switch(pres) { case RICsubscriptionRequest_IEs__value_PR_RICrequestID: { - RICrequestID_t reqId = next_ie->value.choice.RICrequestID; - long requestorId = reqId.ricRequestorID; - long instanceId = reqId.ricInstanceID; - fprintf(stderr, "requestorId %d\n", requestorId); - fprintf(stderr, "instanceId %d\n", instanceId); - responseRequestorId = requestorId; - responseInstanceId = instanceId; - - break; + RICrequestID_t reqId = next_ie->value.choice.RICrequestID; + long requestorId = reqId.ricRequestorID; + long instanceId = reqId.ricInstanceID; + + LOG_I("RequestorId %d, InstanceId: %d", requestorId, instanceId); + + responseRequestorId = requestorId; + responseInstanceId = instanceId; + break; } case RICsubscriptionRequest_IEs__value_PR_RANfunctionID: break; case RICsubscriptionRequest_IEs__value_PR_RICsubscriptionDetails: { - RICsubscriptionDetails_t subDetails = next_ie->value.choice.RICsubscriptionDetails; - RICeventTriggerDefinition_t triggerDef = subDetails.ricEventTriggerDefinition; - RICactions_ToBeSetup_List_t actionList = subDetails.ricAction_ToBeSetup_List; - - int actionCount = actionList.list.count; - fprintf(stderr, "action count%d\n", actionCount); - - auto **item_array = actionList.list.array; - - for (int i=0; i < actionCount; i++) { - //RICaction_ToBeSetup_Item_t - auto *next_item = item_array[i]; - RICactionID_t actionId = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionID; - fprintf(stderr, "Next Action ID %ld\n", actionId); - responseActionId = actionId; - actionIds.push_back(responseActionId); - } - - break; + RICsubscriptionDetails_t subDetails = next_ie->value.choice.RICsubscriptionDetails; + RICeventTriggerDefinition_t triggerDef = subDetails.ricEventTriggerDefinition; + RICactions_ToBeSetup_List_t actionList = subDetails.ricAction_ToBeSetup_List; + + int actionCount = actionList.list.count; + LOG_I("Action count%d", actionCount); + + auto **item_array = actionList.list.array; + + for (int i=0; i < actionCount; i++) { + //RICaction_ToBeSetup_Item_t + auto *next_item = item_array[i]; + RICactionID_t actionId = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionID; + LOG_D("Next Action ID %ld", actionId); + responseActionId = actionId; + actionIds.push_back(responseActionId); + } + + break; } } } - fprintf(stderr, "After Processing Subscription Request\n"); - - fprintf(stderr, "requestorId %d\n", responseRequestorId); - fprintf(stderr, "instanceId %d\n", responseInstanceId); - - - for (int i=0; i < actionIds.size(); i++) { - fprintf(stderr, "Action ID %d %ld\n", i, actionIds.at(i)); - - } - - RICsubscriptionResponse_IEs_t *respricreqid = (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t)); @@ -861,7 +840,6 @@ void encoding::generate_e2apv1_subscription_response(E2AP_PDU *e2ap_pdu, E2AP_PD respricreqid->value.choice.RICrequestID.ricInstanceID = responseInstanceId; - RICsubscriptionResponse_IEs_t *ricactionadmitted = (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t)); ricactionadmitted->id = ProtocolIE_ID_id_RICactions_Admitted; @@ -873,8 +851,6 @@ void encoding::generate_e2apv1_subscription_response(E2AP_PDU *e2ap_pdu, E2AP_PD ricactionadmitted->value.choice.RICaction_Admitted_List = *admlist; for (int i=0; i < actionIds.size(); i++) { - fprintf(stderr, "in for loop i = %d\n", i); - long aid = actionIds.at(i); RICaction_Admitted_ItemIEs_t *admitie = (RICaction_Admitted_ItemIEs_t*)calloc(1,sizeof(RICaction_Admitted_ItemIEs_t)); @@ -887,7 +863,6 @@ void encoding::generate_e2apv1_subscription_response(E2AP_PDU *e2ap_pdu, E2AP_PD } - RICsubscriptionResponse_t *ricsubresp = (RICsubscriptionResponse_t*)calloc(1,sizeof(RICsubscriptionResponse_t)); ASN_SEQUENCE_ADD(&ricsubresp->protocolIEs.list, respricreqid); @@ -911,11 +886,6 @@ void encoding::generate_e2apv1_subscription_response(E2AP_PDU *e2ap_pdu, E2AP_PD size_t errlen = 0; asn_check_constraints(&asn_DEF_E2AP_PDU, e2ap_pdu, error_buf, &errlen); - printf("error length %d\n", errlen); - printf("error buf %s\n", error_buf); - - - } void encoding::generate_e2apv1_indication_request_parameterized(E2AP_PDU *e2ap_pdu, @@ -929,7 +899,7 @@ void encoding::generate_e2apv1_indication_request_parameterized(E2AP_PDU *e2ap_p uint8_t *ind_message_buf, int message_length) { - printf("Initializing E2AP request\n"); + LOG_I("Initializing E2AP request"); RICindication_IEs_t *ricind_ies = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t)); RICindication_IEs_t *ricind_ies2 = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t)); @@ -1044,11 +1014,6 @@ void encoding::generate_e2apv1_indication_request_parameterized(E2AP_PDU *e2ap_p int ret = asn_check_constraints(&asn_DEF_E2AP_PDU, e2ap_pdu, error_buf, &errlen); if(ret) { - fprintf(stderr, "Constraint validation of E2AP PDU message failed: %s\n", error_buf); + LOG_I("Constraint validation of E2AP PDU message failed: %s\n", error_buf); } - - //xer_fprint(stderr, &asn_DEF_E2AP_PDU, e2ap_pdu); - -} - - +} \ No newline at end of file diff --git a/e2sim/src/messagerouting/e2ap_asn1c_codec.c b/e2sim/src/messagerouting/e2ap_asn1c_codec.c index b17431e..8e1bff2 100755 --- a/e2sim/src/messagerouting/e2ap_asn1c_codec.c +++ b/e2sim/src/messagerouting/e2ap_asn1c_codec.c @@ -21,17 +21,13 @@ void e2ap_asn1c_print_pdu(const E2AP_PDU_t* pdu) { - printf("before\n"); // xer_fprint(stdout, &asn_DEF_E2AP_PDU, (void *)pdu); xer_fprint(stdout, &asn_DEF_E2AP_PDU, pdu); - printf("after\n"); - printf("\n"); } void asn1c_xer_print(asn_TYPE_descriptor_t *typeDescriptor, void *data) { xer_fprint(stdout, typeDescriptor, (void *)data); - printf("\n"); } @@ -208,7 +204,7 @@ int e2ap_asn1c_get_procedureCode(E2AP_PDU_t* pdu) switch(pdu->present) { case E2AP_PDU_PR_initiatingMessage: - fprintf(stderr,"initiating message\n"); + LOG_I("Initiating E2AP PDU PR message"); procedureCode = pdu->choice.initiatingMessage->procedureCode; break; diff --git a/e2sim/src/messagerouting/e2ap_message_handler.cpp b/e2sim/src/messagerouting/e2ap_message_handler.cpp index 57d28c2..7b712a7 100755 --- a/e2sim/src/messagerouting/e2ap_message_handler.cpp +++ b/e2sim/src/messagerouting/e2ap_message_handler.cpp @@ -22,224 +22,191 @@ //#include //#include +#include +#include #include "encode_e2apv1.hpp" - -#include - -void e2ap_handle_sctp_data(int &socket_fd, sctp_buffer_t &data, bool xmlenc, E2Sim *e2sim) -{ - fprintf(stderr, "in e2ap_handle_sctp_data()\n"); - //decode the data into E2AP-PDU +void e2ap_handle_sctp_data(int& socket_fd, sctp_buffer_t& data, bool xmlenc, E2Sim* e2sim) { E2AP_PDU_t* pdu = (E2AP_PDU_t*)calloc(1, sizeof(E2AP_PDU)); ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu); - fprintf(stderr, "decoding...\n"); - asn_transfer_syntax syntax; - syntax = ATS_ALIGNED_BASIC_PER; - - - fprintf(stderr, "full buffer\n%s\n", data.buffer); - // e2ap_asn1c_decode_pdu(pdu, data.buffer, data.len); - - auto rval = asn_decode(nullptr, syntax, &asn_DEF_E2AP_PDU, (void **) &pdu, - data.buffer, data.len); - + auto rval = asn_decode(nullptr, syntax, &asn_DEF_E2AP_PDU, (void**)&pdu, data.buffer, data.len); + + switch (rval.code) { + case RC_WMORE: + case RC_FAIL: + LOG_E("Failed to decode E2AP data from SCTP connection"); + ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu); + exit(1); + default: + break; + } - int index = (int)pdu->present; - fprintf(stderr, "length of data %d\n", rval.consumed); - fprintf(stderr, "result %d\n", rval.code); - fprintf(stderr, "index is %d\n", index); - - fprintf(stderr, "showing xer of data\n"); - - xer_fprint(stderr, &asn_DEF_E2AP_PDU, pdu); - - int procedureCode = e2ap_asn1c_get_procedureCode(pdu); - index = (int)pdu->present; - - LOG_D("[E2AP] Unpacked E2AP-PDU: index = %d, procedureCode = %d\n", - index, procedureCode); - - switch(procedureCode) - { - - case ProcedureCode_id_E2setup: - switch(index) - { + int procedureCode = e2ap_asn1c_get_procedureCode(pdu); + int index = (int)pdu->present; + + LOG_D("Unpacked E2AP-PDU: index = %d, procedureCode = %d", index, procedureCode); + + switch (procedureCode) { + case ProcedureCode_id_E2setup: + LOG_I("Received a message of E2 setup procedure"); + switch (index) { case E2AP_PDU_PR_initiatingMessage: - e2ap_handle_E2SetupRequest(pdu, socket_fd); - LOG_I("[E2AP] Received SETUP-REQUEST"); + e2ap_handle_E2SetupRequest(pdu, socket_fd); + LOG_I("Received SETUP-REQUEST"); break; - + case E2AP_PDU_PR_successfulOutcome: - LOG_I("[E2AP] Received SETUP-RESPONSE-SUCCESS"); + LOG_I("Received SETUP-RESPONSE-SUCCESS"); break; - + case E2AP_PDU_PR_unsuccessfulOutcome: - LOG_I("[E2AP] Received SETUP-RESPONSE-FAILURE"); + LOG_I("Received SETUP-RESPONSE-FAILURE"); break; - + default: - LOG_E("[E2AP] Invalid message index=%d in E2AP-PDU", index); + LOG_E("Invalid message index=%d in E2AP-PDU", index); break; - } - break; - - case ProcedureCode_id_Reset: //reset = 7 - switch(index) - { + } + break; + + case ProcedureCode_id_Reset: // reset = 7 + LOG_I("Received a message of Reset procedure"); + switch (index) { case E2AP_PDU_PR_initiatingMessage: - LOG_I("[E2AP] Received RESET-REQUEST"); + LOG_I("Received RESET-REQUEST"); break; - + case E2AP_PDU_PR_successfulOutcome: break; - + case E2AP_PDU_PR_unsuccessfulOutcome: break; - + default: - LOG_E("[E2AP] Invalid message index=%d in E2AP-PDU", index); + LOG_E("Invalid message index=%d in E2AP-PDU", index); break; - } + } break; - - case ProcedureCode_id_RICsubscription: //RIC SUBSCRIPTION = 201 - switch(index) - { - case E2AP_PDU_PR_initiatingMessage: { //initiatingMessage - LOG_I("[E2AP] Received RIC-SUBSCRIPTION-REQUEST"); - // e2ap_handle_RICSubscriptionRequest(pdu, socket_fd); - long func_id = encoding::get_function_id_from_subscription(pdu); - fprintf(stderr, "Function Id of message is %d\n", func_id); - SubscriptionCallback cb; - - bool func_exists = true; - - try { - cb = e2sim->get_subscription_callback(func_id); - } catch(const std::out_of_range& e) { - func_exists = false; - } - - if (func_exists) { - fprintf(stderr, "Calling callback function\n"); - cb(pdu); - } else { - fprintf(stderr, "Error: No RAN Function with this ID exists\n"); - } - // callback_kpm_subscription_request(pdu, socket_fd); - - } - break; - - case E2AP_PDU_PR_successfulOutcome: - LOG_I("[E2AP] Received RIC-SUBSCRIPTION-RESPONSE"); + + case ProcedureCode_id_RICsubscription: // RIC SUBSCRIPTION = 201 + LOG_I("Received a message of RIC subscription procedure"); + switch (index) { + case E2AP_PDU_PR_initiatingMessage: { // initiatingMessage + long func_id = encoding::get_function_id_from_subscription(pdu); + LOG_I("Received RIC subscription request for function with ID %d", func_id); + + try { + SubscriptionCallback cb; + cb = e2sim->get_subscription_callback(func_id); + LOG_I("Calling callback subscription function to handle subscription request to function with ID %d", func_id); + cb(pdu); + } catch (const std::out_of_range& e) { + LOG_E("No RAN Function with this ID exists\n"); + } + + break; + } + + case E2AP_PDU_PR_successfulOutcome: + LOG_I("Received RIC-SUBSCRIPTION-RESPONSE"); break; - + case E2AP_PDU_PR_unsuccessfulOutcome: - LOG_I("[E2AP] Received RIC-SUBSCRIPTION-FAILURE"); + LOG_I("Received RIC-SUBSCRIPTION-FAILURE"); break; - + default: - LOG_E("[E2AP] Invalid message index=%d in E2AP-PDU", index); + LOG_E("Invalid message index=%d in E2AP-PDU", index); break; - } + } break; - case ProcedureCode_id_RICindication: // 205 - switch(index) - { - case E2AP_PDU_PR_initiatingMessage: //initiatingMessage - LOG_I("[E2AP] Received RIC-INDICATION-REQUEST"); + case ProcedureCode_id_RICindication: // 205 + LOG_I("Received a message of RIC indication procedure"); + switch (index) { + case E2AP_PDU_PR_initiatingMessage: // initiatingMessage + LOG_I("Received RIC-INDICATION-REQUEST"); // e2ap_handle_RICSubscriptionRequest(pdu, socket_fd); break; case E2AP_PDU_PR_successfulOutcome: - LOG_I("[E2AP] Received RIC-INDICATION-RESPONSE"); + LOG_I("Received RIC-INDICATION-RESPONSE"); break; - + case E2AP_PDU_PR_unsuccessfulOutcome: - LOG_I("[E2AP] Received RIC-INDICATION-FAILURE"); + LOG_I("Received RIC-INDICATION-FAILURE"); break; - + default: - LOG_E("[E2AP] Invalid message index=%d in E2AP-PDU %d", index, - (int)ProcedureCode_id_RICindication); + LOG_E("Invalid message index=%d in E2AP-PDU %d", index, (int)ProcedureCode_id_RICindication); break; - } + } break; case ProcedureCode_id_RICserviceQuery: - switch (index) - { - case E2AP_PDU_PR_initiatingMessage: - LOG_I("[E2AP] Received RIC-Service-Query") + LOG_I("Received a message of RIC service query procedure"); + switch (index) { + case E2AP_PDU_PR_initiatingMessage: + LOG_I("Received RIC-Service-Query") e2ap_handle_E2SeviceRequest(pdu, socket_fd, e2sim); break; - default: - LOG_E("[E2AP] Invalid message index=%d in E2AP-PDU %d", index, - (int)ProcedureCode_id_RICserviceQuery); + default: + LOG_E("Invalid message index=%d in E2AP-PDU %d", index, (int)ProcedureCode_id_RICserviceQuery); break; - } + } break; case ProcedureCode_id_E2nodeConfigurationUpdate: - switch (index) - { - case E2AP_PDU_PR_successfulOutcome: - LOG_I("[E2AP] Received E2nodeConfigurationUpdate") + LOG_I("Received a message of E2 node configuration update procedure"); + switch (index) { + case E2AP_PDU_PR_successfulOutcome: + LOG_I("Received E2nodeConfigurationUpdate") break; - default: - LOG_E("[E2AP] Invalid message index=%d in E2AP-PDU %d", index, - (int)ProcedureCode_id_E2nodeConfigurationUpdate); + default: + LOG_E("Invalid message index=%d in E2AP-PDU %d", index, (int)ProcedureCode_id_E2nodeConfigurationUpdate); break; - } + } break; case ProcedureCode_id_RICserviceUpdate: - switch (index) - { - case E2AP_PDU_PR_successfulOutcome: - LOG_I("[E2AP] Received RIC-SERVICE-UPDATE-SUCCESS") + LOG_I("Received a message of RIC service update procedure"); + switch (index) { + case E2AP_PDU_PR_successfulOutcome: + LOG_I("Received RIC-SERVICE-UPDATE-SUCCESS") break; - case E2AP_PDU_PR_unsuccessfulOutcome: - LOG_I("[E2AP] Received RIC-SERVICE-UPDATE-FAILURE") + case E2AP_PDU_PR_unsuccessfulOutcome: + LOG_I("Received RIC-SERVICE-UPDATE-FAILURE") break; - default: - LOG_E("[E2AP] Invalid message index=%d in E2AP-PDU %d", index, - (int)ProcedureCode_id_RICserviceUpdate); + default: + LOG_E("Invalid message index=%d in E2AP-PDU %d", index, (int)ProcedureCode_id_RICserviceUpdate); break; - } + } break; - - default: - - LOG_E("[E2AP] No available handler for procedureCode=%d", procedureCode); + default: + LOG_E("No available handler for procedureCode=%d", procedureCode); break; - } + } ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu); } -void e2ap_handle_E2SeviceRequest(E2AP_PDU_t* pdu, int &socket_fd, E2Sim *e2sim) { - +void e2ap_handle_E2SeviceRequest(E2AP_PDU_t* pdu, int& socket_fd, E2Sim* e2sim) { auto buffer_size = MAX_SCTP_BUFFER; unsigned char buffer[MAX_SCTP_BUFFER]; - E2AP_PDU_t* res_pdu = (E2AP_PDU_t*)calloc(1,sizeof(E2AP_PDU)); + E2AP_PDU_t* res_pdu = (E2AP_PDU_t*)calloc(1, sizeof(E2AP_PDU)); // prepare ran function defination std::vector all_funcs; - //Loop through RAN function definitions that are registered + // Loop through RAN function definitions that are registered for (std::pair elem : e2sim->getRegistered_ran_functions()) { printf("looping through ran func\n"); @@ -250,18 +217,20 @@ void e2ap_handle_E2SeviceRequest(E2AP_PDU_t* pdu, int &socket_fd, E2Sim *e2sim) next_func.ranFunctionRev = (long)3; all_funcs.push_back(next_func); } - + printf("about to call service update encode\n"); encoding::generate_e2apv1_service_update(res_pdu, all_funcs); - LOG_D("[E2AP] Created E2-SERVICE-UPDATE"); + LOG_D("Created E2-SERVICE-UPDATE"); e2ap_asn1c_print_pdu(res_pdu); sctp_buffer_t data; - char error_buf[300] = {0, }; + char error_buf[300] = { + 0, + }; size_t errlen = 0; asn_check_constraints(&asn_DEF_E2AP_PDU, res_pdu, error_buf, &errlen); @@ -269,92 +238,107 @@ void e2ap_handle_E2SeviceRequest(E2AP_PDU_t* pdu, int &socket_fd, E2Sim *e2sim) printf("error buf %s\n", error_buf); auto er = asn_encode_to_buffer(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, res_pdu, buffer, buffer_size); + + if (er.encoded == -1) { + LOG_E("Failed to serialize message. Detail: %s.\n", asn_DEF_E2AP_PDU.name); + exit(1); + } else if (er.encoded > buffer_size) { + LOG_E("Buffer of size %zu is too small for %s, need %zu\n", buffer_size, asn_DEF_E2AP_PDU.name, er.encoded); + exit(1); + } data.len = er.encoded; - fprintf(stderr, "er encoded is %d\n", er.encoded); memcpy(data.buffer, buffer, er.encoded); - //send response data over sctp - if(sctp_send_data(socket_fd, data) > 0) { - LOG_I("[SCTP] Sent E2-SERVICE-UPDATE"); + // send response data over sctp + if (sctp_send_data(socket_fd, data) > 0) { + LOG_I("Sent E2-SERVICE-UPDATE"); } else { - LOG_E("[SCTP] Unable to send E2-SERVICE-UPDATE to peer"); + LOG_E("Unable to send E2-SERVICE-UPDATE to peer"); } } -void e2ap_send_e2nodeConfigUpdate(int &socket_fd) { - +void e2ap_send_e2nodeConfigUpdate(int& socket_fd) { auto buffer_size = MAX_SCTP_BUFFER; unsigned char buffer[MAX_SCTP_BUFFER]; - E2AP_PDU_t* pdu = (E2AP_PDU_t*)calloc(1,sizeof(E2AP_PDU)); + E2AP_PDU_t* pdu = (E2AP_PDU_t*)calloc(1, sizeof(E2AP_PDU)); - LOG_D("about to call e2nodeconfigUpdate encode\n"); + LOG_I("Generating E2 node configure update"); encoding::generate_e2apv2_config_update(pdu); - LOG_D("[E2AP] Created E2nodeConfigUpdate"); - e2ap_asn1c_print_pdu(pdu); sctp_buffer_t data; - char error_buf[300] = {0, }; + char error_buf[300] = { + 0, + }; size_t errlen = 0; asn_check_constraints(&asn_DEF_E2AP_PDU, pdu, error_buf, &errlen); auto er = asn_encode_to_buffer(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, pdu, buffer, buffer_size); + if (er.encoded == -1) { + LOG_E("Failed to serialize message. Detail: %s.\n", asn_DEF_E2AP_PDU.name); + exit(1); + } else if (er.encoded > buffer_size) { + LOG_E("Buffer of size %zu is too small for %s, need %zu\n", buffer_size, asn_DEF_E2AP_PDU.name, er.encoded); + exit(1); + } + data.len = er.encoded; - fprintf(stderr, "er encoded is %d\n", er.encoded); memcpy(data.buffer, buffer, er.encoded); - //send response data over sctp - if(sctp_send_data(socket_fd, data) > 0) { - LOG_I("[SCTP] Sent E2nodeConfigUpdate"); + // send response data over sctp + if (sctp_send_data(socket_fd, data) > 0) { + LOG_I("Sent E2nodeConfigUpdate"); } else { LOG_E("[SCTP] Unable to send E2nodeConfigUpdate to peer"); } } -void e2ap_handle_E2SetupRequest(E2AP_PDU_t* pdu, int &socket_fd) { - - +void e2ap_handle_E2SetupRequest(E2AP_PDU_t* pdu, int& socket_fd) { E2AP_PDU_t* res_pdu = (E2AP_PDU_t*)calloc(1, sizeof(E2AP_PDU)); encoding::generate_e2apv1_setup_response(res_pdu); - - LOG_D("[E2AP] Created E2-SETUP-RESPONSE"); + LOG_D("Created E2-SETUP-RESPONSE"); e2ap_asn1c_print_pdu(res_pdu); - auto buffer_size = MAX_SCTP_BUFFER; unsigned char buffer[MAX_SCTP_BUFFER]; - + sctp_buffer_t data; auto er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, res_pdu, buffer, buffer_size); + if (er.encoded == -1) { + LOG_E("Failed to serialize message. Detail: %s.\n", asn_DEF_E2AP_PDU.name); + exit(1); + } else if (er.encoded > buffer_size) { + LOG_E("Buffer of size %zu is too small for %s, need %zu\n", buffer_size, asn_DEF_E2AP_PDU.name, er.encoded); + exit(1); + } + data.len = er.encoded; - fprintf(stderr, "er encoded is %d\n", er.encoded); - //data.len = e2ap_asn1c_encode_pdu(res_pdu, &buf); memcpy(data.buffer, buffer, er.encoded); - //send response data over sctp - if(sctp_send_data(socket_fd, data) > 0) { - LOG_I("[SCTP] Sent E2-SETUP-RESPONSE"); + // send response data over sctp + if (sctp_send_data(socket_fd, data) > 0) { + LOG_I("Sent E2-SETUP-RESPONSE"); } else { LOG_E("[SCTP] Unable to send E2-SETUP-RESPONSE to peer"); } sleep(5); - //Sending Subscription Request + // Sending Subscription Request - E2AP_PDU_t* pdu_sub = (E2AP_PDU_t*)calloc(1,sizeof(E2AP_PDU)); + E2AP_PDU_t* pdu_sub = (E2AP_PDU_t*)calloc(1, sizeof(E2AP_PDU)); encoding::generate_e2apv1_subscription_request(pdu_sub); @@ -362,23 +346,27 @@ void e2ap_handle_E2SetupRequest(E2AP_PDU_t* pdu, int &socket_fd) { auto buffer_size2 = MAX_SCTP_BUFFER; unsigned char buffer2[MAX_SCTP_BUFFER]; - + sctp_buffer_t data2; auto er2 = asn_encode_to_buffer(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, pdu_sub, buffer2, buffer_size2); - + + if (er2.encoded == -1) { + LOG_E("Failed to serialize message. Detail: %s.\n", asn_DEF_E2AP_PDU.name); + exit(1); + } else if (er2.encoded > buffer_size2) { + LOG_E("Buffer of size %zu is too small for %s, need %zu\n", buffer_size2, asn_DEF_E2AP_PDU.name, er2.encoded); + exit(1); + } + data2.len = er2.encoded; memcpy(data2.buffer, buffer2, er2.encoded); - - fprintf(stderr, "er encded is %d\n", er2.encoded); - if(sctp_send_data(socket_fd, data2) > 0) { - LOG_I("[SCTP] Sent E2-SUBSCRIPTION-REQUEST"); + if (sctp_send_data(socket_fd, data2) > 0) { + LOG_I("Sent E2-SUBSCRIPTION-REQUEST"); } else { LOG_E("[SCTP] Unable to send E2-SUBSCRIPTION-REQUEST to peer"); - } - - + } } /* @@ -397,7 +385,7 @@ void e2ap_handle_RICSubscriptionRequest(E2AP_PDU_t* pdu, int &socket_fd) auto buffer_size2 = MAX_SCTP_BUFFER; unsigned char buffer2[MAX_SCTP_BUFFER]; - + sctp_buffer_t data2; auto er2 = asn_encode_to_buffer(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, pdu_resp, buffer2, buffer_size2); @@ -408,12 +396,12 @@ void e2ap_handle_RICSubscriptionRequest(E2AP_PDU_t* pdu, int &socket_fd) memcpy(data2.buffer, buffer2, er2.encoded); if(sctp_send_data(socket_fd, data2) > 0) { - LOG_I("[SCTP] Sent RIC-SUBSCRIPTION-RESPONSE"); + LOG_I("Sent RIC-SUBSCRIPTION-RESPONSE"); } else { LOG_E("[SCTP] Unable to send RIC-SUBSCRIPTION-RESPONSE to peer"); } - - + + //Send back an Indication E2AP_PDU_t* pdu_ind = (E2AP_PDU_t*)calloc(1,sizeof(E2AP_PDU)); @@ -424,7 +412,7 @@ void e2ap_handle_RICSubscriptionRequest(E2AP_PDU_t* pdu, int &socket_fd) auto buffer_size = MAX_SCTP_BUFFER; unsigned char buffer[MAX_SCTP_BUFFER]; - + sctp_buffer_t data; auto er = asn_encode_to_buffer(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, pdu_ind, buffer, buffer_size); @@ -435,13 +423,10 @@ void e2ap_handle_RICSubscriptionRequest(E2AP_PDU_t* pdu, int &socket_fd) memcpy(data.buffer, buffer, er.encoded); if(sctp_send_data(socket_fd, data) > 0) { - LOG_I("[SCTP] Sent RIC-INDICATION-REQUEST"); + LOG_I("Sent RIC-INDICATION-REQUEST"); } else { LOG_E("[SCTP] Unable to send RIC-INDICATION-REQUEST to peer"); - } + } } */ - - -