X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=RIC-E2-TERMINATION%2FsctpThread.cpp;h=7fa142e8b3312c7d048de85cf1bb155b3fc65d9b;hb=9a0e46cb67faa9cf177d3f4effa5f30fa704b836;hp=95b0e468afa782c76a79af4162b039f3e55b6278;hpb=9ae4dcc1dd3facbadd9041c4036c6d81a69d19d1;p=ric-plt%2Fe2.git diff --git a/RIC-E2-TERMINATION/sctpThread.cpp b/RIC-E2-TERMINATION/sctpThread.cpp index 95b0e46..7fa142e 100644 --- a/RIC-E2-TERMINATION/sctpThread.cpp +++ b/RIC-E2-TERMINATION/sctpThread.cpp @@ -24,17 +24,9 @@ #include "sctpThread.h" #include "BuildRunName.h" -//#define asn_DEF_E2SM_gNB_NRT_RANfunction_Definition e2sm_asn_DEF_E2SM_gNB_NRT_RANfunction_Definition -//#define __gcov_init e2sm___gcov_init -//#define __gcov_merge_add e2sm___gcov_merge_add -//#define calloc e2sm_calloc - #include "3rdparty/oranE2SM/E2SM-gNB-NRT-RANfunction-Definition.h" - -//#undef calloc -//#undef __gcov_merge_add -//#undef __gcov_init -//#undef asn_DEF_E2SM_gNB_NRT_RANfunction_Definition +#include "BuildXml.h" +#include "pugixml/src/pugixml.hpp" using namespace std; //using namespace std::placeholders; @@ -429,7 +421,7 @@ void sendTermInit(sctp_params_t &sctpParams) { rmr_bytes2xact(msg, tx, txLen); msg = rmr_send_msg(sctpParams.rmrCtx, msg); if (msg == nullptr) { - msg = rmr_alloc_msg(sctpParams.rmrCtx, sctpParams.myIP.length()); + msg = rmr_alloc_msg(sctpParams.rmrCtx, sctpParams.ka_message_length); } else if (msg->state == 0) { rmr_free_msg(msg); if (mdclog_level_get() >= MDCLOG_INFO) { @@ -726,12 +718,16 @@ void handleConfigChange(sctp_params_t *sctpParams) { // not the directory } if (event->len) { - if (!(sctpParams->configFileName.compare(event->name))) { + auto retVal = strcmp(sctpParams->configFileName.c_str(), event->name); + if (retVal != 0) { continue; } } // only the file we want if (event->mask & (uint32_t)IN_CLOSE_WRITE) { + if (mdclog_level_get() >= MDCLOG_INFO) { + mdclog_write(MDCLOG_INFO, "Configuration file changed"); + } if (exists(p)) { const int size = 2048; auto fileSize = file_size(p); @@ -987,7 +983,8 @@ int sendSctpMsg(ConnectedCU_t *peerInfo, ReportingMessages_t &message, Sctp_Map_ m->erase(key); return -1; } - message.statCollector->incSentMessage(string(message.message.enodbName)); + // TODO remove stat update + //message.statCollector->incSentMessage(string(message.message.enodbName)); message.message.direction = 'D'; // send report.buffer of size buildJsonMessage(message); @@ -1158,22 +1155,12 @@ int receiveDataFromSctp(struct epoll_event *events, message.peerInfo->enodbName, end.tv_sec - decodestart.tv_sec, end.tv_nsec - decodestart.tv_nsec); } numOfMessages++; - // remove the break for EAGAIN - //break; if (pdu != nullptr) { - //TODO need to test ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu); to get better performance ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu); //ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu); //pdu = nullptr; } - //clock_gettime(CLOCK_MONOTONIC, &start); } - // in case of break to avoid memory leak -// if (pdu != nullptr) { -// //ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu); -// ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu); -// //pdu = nullptr; -// } if (done) { if (loglevel >= MDCLOG_INFO) { @@ -1207,27 +1194,40 @@ int receiveDataFromSctp(struct epoll_event *events, static void buildAndsendSetupRequest(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer, - E2AP_PDU_t *pdu) { + E2AP_PDU_t *pdu, + vector &repValues) { auto logLevel = mdclog_level_get(); - // now we can send the data to e2Mgr auto buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2; - - auto *rmrMsg = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, buffer_size); - // add addrees to message - - - // unsigned char *buffer = &rmrMsg->payload[j]; unsigned char buffer[RECEIVE_SCTP_BUFFER_SIZE * 2]; + auto *rmrMsg = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, buffer_size); // encode to xml auto er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu, buffer, buffer_size); if (er.encoded == -1) { mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno)); } else if (er.encoded > (ssize_t) buffer_size) { - mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s", + mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s, at %s line %d", (int) buffer_size, - asn_DEF_E2AP_PDU.name); + asn_DEF_E2AP_PDU.name, __func__, __LINE__); } else { + string messageType("E2setupRequest"); + string ieName("E2setupRequestIEs"); + buffer[er.encoded] = '\0'; + buildXmlData(messageType, ieName, repValues, buffer, (size_t)er.encoded); + +// string xmlStr = (char *)buffer; +// auto removeSpaces = [] (string str) -> string { +// str.erase(remove(str.begin(), str.end(), ' '), str.end()); +// str.erase(remove(str.begin(), str.end(), '\t'), str.end()); +// return str; +// }; +// +// xmlStr = removeSpaces(xmlStr); +// // we have the XML +// rmrMsg->len = snprintf((char *)rmrMsg->payload, RECEIVE_SCTP_BUFFER_SIZE * 2, "%s:%d|%s", +// message.peerInfo->sctpParams->myIP.c_str(), +// message.peerInfo->sctpParams->rmrPort, +// xmlStr.c_str()); rmrMsg->len = snprintf((char *)rmrMsg->payload, RECEIVE_SCTP_BUFFER_SIZE * 2, "%s:%d|%s", message.peerInfo->sctpParams->myIP.c_str(), message.peerInfo->sctpParams->rmrPort, @@ -1279,6 +1279,118 @@ static void buildAndsendSetupRequest(ReportingMessages_t &message, } } + +int RAN_Function_list_To_Vector(RANfunctions_List_t& list, vector &runFunXML_v) { + auto index = 0; + runFunXML_v.clear(); + for (auto j = 0; j < list.list.count; j++) { + auto *raNfunctionItemIEs = (RANfunction_ItemIEs_t *)list.list.array[j]; + if (raNfunctionItemIEs->id == ProtocolIE_ID_id_RANfunction_Item && + (raNfunctionItemIEs->value.present == RANfunction_ItemIEs__value_PR_RANfunction_Item)) { + // encode to xml + E2SM_gNB_NRT_RANfunction_Definition_t *ranFunDef = nullptr; + auto rval = asn_decode(nullptr, ATS_ALIGNED_BASIC_PER, + &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition, + (void **)&ranFunDef, + raNfunctionItemIEs->value.choice.RANfunction_Item.ranFunctionDefinition.buf, + raNfunctionItemIEs->value.choice.RANfunction_Item.ranFunctionDefinition.size); + if (rval.code != RC_OK) { + mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) E2SM message from : %s", + rval.code, + asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name); + return -1; + } + +// if (mdclog_level_get() >= MDCLOG_DEBUG) { +// char *printBuffer; +// size_t size; +// FILE *stream = open_memstream(&printBuffer, &size); +// asn_fprint(stream, &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition, ranFunDef); +// mdclog_write(MDCLOG_DEBUG, "Encoding E2SM %s PDU past : %s", +// asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name, +// printBuffer); +// } + auto xml_buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2; + unsigned char xml_buffer[RECEIVE_SCTP_BUFFER_SIZE * 2]; + // encode to xml + auto er = asn_encode_to_buffer(nullptr, + ATS_BASIC_XER, + &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition, + ranFunDef, + xml_buffer, + xml_buffer_size); + if (er.encoded == -1) { + mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", + asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name, + strerror(errno)); + } else if (er.encoded > (ssize_t)xml_buffer_size) { + mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s, at %s line %d", + (int) xml_buffer_size, + asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name, __func__, __LINE__); + } else { + if (mdclog_level_get() >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Encoding E2SM %s PDU number %d : %s", + asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name, + index++, + xml_buffer); + } + string runFuncs = (char *)(xml_buffer); + runFunXML_v.emplace_back(runFuncs); + } + } + } + return 0; +} + + + +int collectSetupAndServiceUpdate_RequestData(E2AP_PDU_t *pdu, + Sctp_Map_t *sctpMap, + ReportingMessages_t &message, + vector &RANfunctionsAdded_v, + vector &RANfunctionsModified_v) { + memset(message.peerInfo->enodbName, 0 , MAX_ENODB_NAME_SIZE); + for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.count; i++) { + auto *ie = pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.array[i]; + if (ie->id == ProtocolIE_ID_id_GlobalE2node_ID) { + // get the ran name for meid + if (ie->value.present == E2setupRequestIEs__value_PR_GlobalE2node_ID) { + if (buildRanName(message.peerInfo->enodbName, ie) < 0) { + mdclog_write(MDCLOG_ERR, "Bad param in E2setupRequestIEs GlobalE2node_ID.\n"); + // no mesage will be sent + return -1; + } + memcpy(message.message.enodbName, message.peerInfo->enodbName, strlen(message.peerInfo->enodbName)); + sctpMap->setkey(message.message.enodbName, message.peerInfo); + } + } else if (ie->id == ProtocolIE_ID_id_RANfunctionsAdded) { + if (ie->value.present == E2setupRequestIEs__value_PR_RANfunctions_List) { + if (mdclog_level_get() >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Run function list have %d entries", + ie->value.choice.RANfunctions_List.list.count); + } + if (RAN_Function_list_To_Vector(ie->value.choice.RANfunctions_List, RANfunctionsAdded_v) != 0 ) { + return -1; + } + } + } else if (ie->id == ProtocolIE_ID_id_RANfunctionsModified) { + if (ie->value.present == E2setupRequestIEs__value_PR_RANfunctions_List) { + if (mdclog_level_get() >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Run function list have %d entries", + ie->value.choice.RANfunctions_List.list.count); + } + if (RAN_Function_list_To_Vector(ie->value.choice.RANfunctions_List, RANfunctionsModified_v) != 0 ) { + return -1; + } + } + } + } + if (mdclog_level_get() >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Run function vector have %ld entries", + RANfunctionsAdded_v.size()); + } + return 0; +} /** * * @param pdu @@ -1297,106 +1409,44 @@ void asnInitiatingRequest(E2AP_PDU_t *pdu, switch (procedureCode) { case ProcedureCode_id_E2setup: { if (logLevel >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "Got E2setup\n"); + mdclog_write(MDCLOG_DEBUG, "Got E2setup"); } // first get the message as XML buffer auto setup_xml_buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2; unsigned char setup_xml_buffer[RECEIVE_SCTP_BUFFER_SIZE * 2]; - //unsigned char *tmp_buff_cursor = setup_xml_buffer; auto er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu, setup_xml_buffer, setup_xml_buffer_size); if (er.encoded == -1) { mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno)); + break; } else if (er.encoded > (ssize_t) setup_xml_buffer_size) { - mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s", + mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s, at %s line %d", (int)setup_xml_buffer_size, - asn_DEF_E2AP_PDU.name); + asn_DEF_E2AP_PDU.name, __func__, __LINE__); + break; } std::string xmlString(setup_xml_buffer_size, setup_xml_buffer_size + er.encoded); - auto failed = false; - memset(message.peerInfo->enodbName, 0 , MAX_ENODB_NAME_SIZE); - for (auto i = 0; i < pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.count; i++) { - auto *ie = pdu->choice.initiatingMessage->value.choice.E2setupRequest.protocolIEs.list.array[i]; - if (ie->id == ProtocolIE_ID_id_GlobalE2node_ID) { - // get the ran name for meid - if (ie->value.present == E2setupRequestIEs__value_PR_GlobalE2node_ID) { - if (buildRanName(message.peerInfo->enodbName, ie) < 0) { - mdclog_write(MDCLOG_ERR, "Bad param in E2setupRequestIEs GlobalE2node_ID.\n"); - // no mesage will be sent - break; - } - memcpy(message.message.enodbName, message.peerInfo->enodbName, strlen(message.peerInfo->enodbName)); - sctpMap->setkey(message.message.enodbName, message.peerInfo); - } - } - // reformat RANFUNCTION Definition to XML - if (ie->id == ProtocolIE_ID_id_RANfunctionsAdded) { - if (ie->value.present == E2setupRequestIEs__value_PR_RANfunctions_List) { - for (auto j = 0; i < ie->value.choice.RANfunctions_List.list.count; i++) { - auto *raNfunctionItemIEs = (RANfunction_ItemIEs_t *)ie->value.choice.RANfunctions_List.list.array[j]; - if (raNfunctionItemIEs->id == ProtocolIE_ID_id_RANfunction_Item) { - auto buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2; - unsigned char buffer[RECEIVE_SCTP_BUFFER_SIZE * 2]; - // encode to xml - E2SM_gNB_NRT_RANfunction_Definition_t *ranFunDef = nullptr; - auto rval = asn_decode(nullptr, ATS_ALIGNED_BASIC_PER, - &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition, - (void **)&ranFunDef, - buffer, - buffer_size); - if (rval.code != RC_OK) { - mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) E2AP PDU from E2MGR : %s", - rval.code, - asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name); - failed = true; - break; - } - - if (mdclog_level_get() >= MDCLOG_DEBUG) { - char *printBuffer; - size_t size; - FILE *stream = open_memstream(&printBuffer, &size); - asn_fprint(stream, &asn_DEF_E2AP_PDU, pdu); - mdclog_write(MDCLOG_DEBUG, "Encoding E2AP PDU past : %s", printBuffer); - } - auto xml_buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2; - unsigned char xml_buffer[RECEIVE_SCTP_BUFFER_SIZE * 2]; - // encode to xml - er = asn_encode_to_buffer(nullptr, - ATS_BASIC_XER, - &asn_DEF_E2SM_gNB_NRT_RANfunction_Definition, - ranFunDef, - xml_buffer, - xml_buffer_size); - if (er.encoded == -1) { - mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", - asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name, - strerror(errno)); - } else if (er.encoded > (ssize_t) buffer_size) { - mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s", - (int) xml_buffer_size, - asn_DEF_E2SM_gNB_NRT_RANfunction_Definition.name); - } else { - // we have the xml - } - - } - } - if (failed) { - break; - } - } - } - } - if (failed) { + vector RANfunctionsAdded_v; + vector RANfunctionsModified_v; + RANfunctionsAdded_v.clear(); + RANfunctionsModified_v.clear(); + if (collectSetupAndServiceUpdate_RequestData(pdu, sctpMap, message, + RANfunctionsAdded_v, RANfunctionsModified_v) != 0) { break; } - //build all parts and send the XML (need to copy the XML with the header to the rmrMessageBuffer payload - //TODO replace with new function - buildAndsendSetupRequest(message, rmrMessageBuffer, pdu); + buildAndsendSetupRequest(message, rmrMessageBuffer, pdu, RANfunctionsAdded_v); + break; + } + case ProcedureCode_id_RICserviceUpdate: { + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got RICserviceUpdate %s", message.message.enodbName); + } + if (sendRequestToXapp(message, RIC_SERVICE_UPDATE, rmrMessageBuffer) != 0) { + mdclog_write(MDCLOG_ERR, "RIC_SERVICE_UPDATE message failed to send to xAPP"); + } break; } case ProcedureCode_id_ErrorIndication: { @@ -1446,11 +1496,15 @@ void asnInitiatingRequest(E2AP_PDU_t *pdu, (unsigned char *)message.message.enodbName, strlen(message.message.enodbName)); rmrMessageBuffer.sendMessage->state = 0; - rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID; + rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricInstanceID; + + //ie->value.choice.RICrequestID.ricInstanceID; if (mdclog_level_get() >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "RIC sub id = %d, message type = %d", + mdclog_write(MDCLOG_DEBUG, "sub id = %d, mtype = %d, ric instance id %ld, requestor id = %ld", rmrMessageBuffer.sendMessage->sub_id, - rmrMessageBuffer.sendMessage->mtype); + rmrMessageBuffer.sendMessage->mtype, + ie->value.choice.RICrequestID.ricInstanceID, + ie->value.choice.RICrequestID.ricRequestorID); } sendRmrMessage(rmrMessageBuffer, message); messageSent = true; @@ -1470,15 +1524,6 @@ void asnInitiatingRequest(E2AP_PDU_t *pdu, } break; } - case ProcedureCode_id_RICserviceUpdate: { - if (logLevel >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "Got RICserviceUpdate %s", message.message.enodbName); - } - if (sendRequestToXapp(message, RIC_SERVICE_UPDATE, rmrMessageBuffer) != 0) { - mdclog_write(MDCLOG_ERR, "RIC_SERVICE_UPDATE message failed to send to xAPP"); - } - break; - } case ProcedureCode_id_RICsubscription: { if (logLevel >= MDCLOG_DEBUG) { mdclog_write(MDCLOG_DEBUG, "Got RICsubscription %s", message.message.enodbName); @@ -1560,7 +1605,9 @@ void asnSuccsesfulMsg(E2AP_PDU_t *pdu, if (ie->value.present == RICcontrolAcknowledge_IEs__value_PR_RICrequestID) { message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_CONTROL_ACK; rmrMessageBuffer.sendMessage->state = 0; - rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID; +// rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID; + rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricInstanceID; + static unsigned char tx[32]; snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx)); @@ -1604,7 +1651,7 @@ void asnSuccsesfulMsg(E2AP_PDU_t *pdu, (unsigned char *)message.message.enodbName, strlen(message.message.enodbName)); rmrMessageBuffer.sendMessage->state = 0; - rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID; + rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricInstanceID; if (mdclog_level_get() >= MDCLOG_DEBUG) { mdclog_write(MDCLOG_DEBUG, "RIC sub id = %d, message type = %d", rmrMessageBuffer.sendMessage->sub_id, @@ -1723,7 +1770,8 @@ void asnUnSuccsesfulMsg(E2AP_PDU_t *pdu, if (ie->value.present == RICcontrolFailure_IEs__value_PR_RICrequestID) { message.message.messageType = rmrMessageBuffer.sendMessage->mtype = RIC_CONTROL_FAILURE; rmrMessageBuffer.sendMessage->state = 0; - rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID; +// rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricRequestorID; + rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricInstanceID; static unsigned char tx[32]; snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, strlen((const char *) tx)); @@ -1764,7 +1812,8 @@ void asnUnSuccsesfulMsg(E2AP_PDU_t *pdu, (unsigned char *)message.message.enodbName, strlen(message.message.enodbName)); rmrMessageBuffer.sendMessage->state = 0; - rmrMessageBuffer.sendMessage->sub_id = (int) ie->value.choice.RICrequestID.ricRequestorID; +// rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricRequestorID; + rmrMessageBuffer.sendMessage->sub_id = (int)ie->value.choice.RICrequestID.ricInstanceID; if (mdclog_level_get() >= MDCLOG_DEBUG) { mdclog_write(MDCLOG_DEBUG, "RIC sub id = %d, message type = %d", rmrMessageBuffer.sendMessage->sub_id, @@ -1852,7 +1901,7 @@ int sendRequestToXapp(ReportingMessages_t &message, void getRmrContext(sctp_params_t &pSctpParams) { pSctpParams.rmrCtx = nullptr; - pSctpParams.rmrCtx = rmr_init(pSctpParams.rmrAddress, RMR_MAX_RCV_BYTES, RMRFL_NONE); + pSctpParams.rmrCtx = rmr_init(pSctpParams.rmrAddress, RECEIVE_XAPP_BUFFER_SIZE, RMRFL_NONE); if (pSctpParams.rmrCtx == nullptr) { mdclog_write(MDCLOG_ERR, "Failed to initialize RMR"); return; @@ -1893,28 +1942,37 @@ void getRmrContext(sctp_params_t &pSctpParams) { } } -int BuildPERSetupResponseMessaeFromXML(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) { - E2AP_PDU_t *pdu; +int PER_FromXML(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) { + E2AP_PDU_t *pdu = nullptr; + + if (mdclog_level_get() >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "got xml setup response of size %d is:%s", + rmrMessageBuffer.rcvMessage->len, rmrMessageBuffer.rcvMessage->payload); + } auto rval = asn_decode(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, (void **) &pdu, rmrMessageBuffer.rcvMessage->payload, rmrMessageBuffer.rcvMessage->len); if (rval.code != RC_OK) { - mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) E2AP PDU from E2MGR : %s", + mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) setup response from E2MGR : %s", rval.code, message.message.enodbName); return -1; } - auto er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu, - rmrMessageBuffer.rcvMessage->payload, rmrMessageBuffer.rcvMessage->len); + int buff_size = RECEIVE_XAPP_BUFFER_SIZE; + auto er = asn_encode_to_buffer(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, pdu, + rmrMessageBuffer.rcvMessage->payload, buff_size); if (er.encoded == -1) { mdclog_write(MDCLOG_ERR, "encoding of %s failed, %s", asn_DEF_E2AP_PDU.name, strerror(errno)); return -1; - } else if (er.encoded > (ssize_t)rmrMessageBuffer.rcvMessage->len) { - mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s", + } else if (er.encoded > (ssize_t)buff_size) { + mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s, at %s line %d", (int)rmrMessageBuffer.rcvMessage->len, - asn_DEF_E2AP_PDU.name); + asn_DEF_E2AP_PDU.name, + __func__, + __LINE__); return -1; } + rmrMessageBuffer.rcvMessage->len = er.encoded; return 0; } @@ -1957,7 +2015,7 @@ int receiveXappMessages(Sctp_Map_t *sctpMap, rmr_get_meid(rmrMessageBuffer.rcvMessage, (unsigned char *)message.message.enodbName); switch (rmrMessageBuffer.rcvMessage->mtype) { case RIC_E2_SETUP_RESP : { - if (BuildPERSetupResponseMessaeFromXML(message, rmrMessageBuffer) != 0) { + if (PER_FromXML(message, rmrMessageBuffer) != 0) { break; } @@ -1968,7 +2026,7 @@ int receiveXappMessages(Sctp_Map_t *sctpMap, break; } case RIC_E2_SETUP_FAILURE : { - if (BuildPERSetupResponseMessaeFromXML(message, rmrMessageBuffer) != 0) { + if (PER_FromXML(message, rmrMessageBuffer) != 0) { break; } if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { @@ -2006,6 +2064,9 @@ int receiveXappMessages(Sctp_Map_t *sctpMap, break; } case RIC_SERVICE_QUERY: { + if (PER_FromXML(message, rmrMessageBuffer) != 0) { + break; + } if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_QUERY"); return -6; @@ -2013,6 +2074,9 @@ int receiveXappMessages(Sctp_Map_t *sctpMap, break; } case RIC_SERVICE_UPDATE_ACK: { + if (PER_FromXML(message, rmrMessageBuffer) != 0) { + break; + } if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_UPDATE_ACK"); return -6; @@ -2020,6 +2084,9 @@ int receiveXappMessages(Sctp_Map_t *sctpMap, break; } case RIC_SERVICE_UPDATE_FAILURE: { + if (PER_FromXML(message, rmrMessageBuffer) != 0) { + break; + } if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { mdclog_write(MDCLOG_ERR, "Failed to send RIC_SERVICE_UPDATE_FAILURE"); return -6; @@ -2337,7 +2404,7 @@ void buildJsonMessage(ReportingMessages_t &message) { message.base64Data, message.outLen); if (mdclog_level_get() >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "asn data length = %d, base64 message length = %d ", + mdclog_write(MDCLOG_DEBUG, "Tracing: ASN length = %d, base64 message length = %d ", (int) message.message.asnLength, (int) message.outLen); }