From 8e2a7be3e9816f410c769b39de0ed7d3f5720b9d Mon Sep 17 00:00:00 2001 From: "aa7133@att.com" Date: Wed, 27 May 2020 17:45:46 +0300 Subject: [PATCH] 5.0.0 new release. remove '\n' and '\t' from XML, Clear XML buffer when building the setup request to avoid wrapped buffers added start of Prometheus support Servive Query, service update and reset with XML support Change-Id: I1bf576ed5103a2be19f81058af969abe23d17633 Signed-off-by: aa7133@att.com --- .gitreview | 2 +- RIC-E2-TERMINATION/BuildRunName.h | 24 +- RIC-E2-TERMINATION/BuildXml.h | 89 ++-- RIC-E2-TERMINATION/CMakeLists.txt | 10 +- RIC-E2-TERMINATION/Dockerfile | 5 +- RIC-E2-TERMINATION/TEST/T1/E2Builder.h | 360 +++++++++++++++- .../TEST/testAsn/T2/SubscriptionTest.cpp | 352 --------------- .../TEST/testAsn/setUpMessages/SetUpMessages.cpp | 92 +++- RIC-E2-TERMINATION/config/config.conf | 1 + RIC-E2-TERMINATION/container-tag.yaml | 2 +- RIC-E2-TERMINATION/sctpThread.cpp | 480 ++++++++++++++------- RIC-E2-TERMINATION/sctpThread.h | 29 +- RIC-E2-TERMINATION/statCollector.h | 166 ------- 13 files changed, 858 insertions(+), 754 deletions(-) delete mode 100644 RIC-E2-TERMINATION/TEST/testAsn/T2/SubscriptionTest.cpp delete mode 100644 RIC-E2-TERMINATION/statCollector.h diff --git a/.gitreview b/.gitreview index 351d6b6..3bae4aa 100644 --- a/.gitreview +++ b/.gitreview @@ -2,4 +2,4 @@ host=gerrit.o-ran-sc.org port=29418 project=ric-plt/e2 -defaultbranch=master +defaultbranch=PI5 diff --git a/RIC-E2-TERMINATION/BuildRunName.h b/RIC-E2-TERMINATION/BuildRunName.h index 801f365..e6eaccd 100644 --- a/RIC-E2-TERMINATION/BuildRunName.h +++ b/RIC-E2-TERMINATION/BuildRunName.h @@ -43,10 +43,10 @@ static int translatePlmnId(char * plmnId, const unsigned char *data, const char* int j = 0; if (mnc3 != 15) { - j = snprintf(plmnId, 20, "%s%1d%1d%1d-%1d%1d%1d", type, mcc1, mcc2, mcc3, mnc1, mnc2, mnc3); + j = snprintf(plmnId, 20, "%s%1d%1d%1d_%1d%1d%1d", type, mcc1, mcc2, mcc3, mnc1, mnc2, mnc3); } else { - j = snprintf(plmnId, 20, "%s%1d%1d%1d-0%1d%1d", type, mcc1, mcc2, mcc3, mnc1, mnc2); + j = snprintf(plmnId, 20, "%s%1d%1d%1d_0%1d%1d", type, mcc1, mcc2, mcc3, mnc1, mnc2); } return j; @@ -55,7 +55,7 @@ static int translatePlmnId(char * plmnId, const unsigned char *data, const char* static int translateBitStringToChar(char *ranName, BIT_STRING_t &data) { // dont care of last unused bits char buffer[256] {}; - auto j = snprintf(buffer, 256, "%s-", ranName); + auto j = snprintf(buffer, 256, "%s_", ranName); memcpy(ranName, buffer, j); unsigned b1 = 0; @@ -77,7 +77,7 @@ int buildRanName(char *ranName, E2setupRequestIEs_t *ie) { switch (ie->value.choice.GlobalE2node_ID.present) { case GlobalE2node_ID_PR_gNB: { auto *gnb = ie->value.choice.GlobalE2node_ID.choice.gNB; - translatePlmnId(ranName, (const unsigned char *)gnb->global_gNB_ID.plmn_id.buf, (const char *)"gnb:"); + translatePlmnId(ranName, (const unsigned char *)gnb->global_gNB_ID.plmn_id.buf, (const char *)"gnb_"); if (gnb->global_gNB_ID.gnb_id.present == GNB_ID_Choice_PR_gnb_ID) { translateBitStringToChar(ranName, gnb->global_gNB_ID.gnb_id.choice.gnb_ID); } @@ -87,7 +87,7 @@ int buildRanName(char *ranName, E2setupRequestIEs_t *ie) { auto *enGnb = ie->value.choice.GlobalE2node_ID.choice.en_gNB; translatePlmnId(ranName, (const unsigned char *)enGnb->global_gNB_ID.pLMN_Identity.buf, - (const char *)"en-gnb:"); + (const char *)"en_gnb_"); if (enGnb->global_gNB_ID.gNB_ID.present == ENGNB_ID_PR_gNB_ID) { translateBitStringToChar(ranName, enGnb->global_gNB_ID.gNB_ID.choice.gNB_ID); } @@ -100,17 +100,17 @@ int buildRanName(char *ranName, E2setupRequestIEs_t *ie) { BIT_STRING_t *data = nullptr; switch (ngEnb->global_ng_eNB_ID.enb_id.present) { case ENB_ID_Choice_PR_enb_ID_macro: { - strncpy(str, (const char *)"ng-enB-macro:", 13); + strncpy(str, (const char *)"ng_enB_macro_", 13); data = &ngEnb->global_ng_eNB_ID.enb_id.choice.enb_ID_macro; break; } case ENB_ID_Choice_PR_enb_ID_shortmacro: { - strncpy(str, (const char *)"ng-enB-shortmacro:", 18); + strncpy(str, (const char *)"ng_enB_shortmacro_", 18); data = &ngEnb->global_ng_eNB_ID.enb_id.choice.enb_ID_shortmacro; break; } case ENB_ID_Choice_PR_enb_ID_longmacro: { - strncpy(str, (const char *)"ng-enB-longmacro:", 17); + strncpy(str, (const char *)"ng_enB_longmacro_", 17); data = &ngEnb->global_ng_eNB_ID.enb_id.choice.enb_ID_longmacro; } case ENB_ID_Choice_PR_NOTHING: { @@ -131,22 +131,22 @@ int buildRanName(char *ranName, E2setupRequestIEs_t *ie) { switch (enb->global_eNB_ID.eNB_ID.present) { case ENB_ID_PR_macro_eNB_ID: { - strncpy(str, (const char *)"enB-macro:", 10); + strncpy(str, (const char *)"enB_macro_", 10); data = &enb->global_eNB_ID.eNB_ID.choice.macro_eNB_ID; break; } case ENB_ID_PR_home_eNB_ID: { - strncpy(str, (const char *)"enB-home:", 9); + strncpy(str, (const char *)"enB_home_", 9); data = &enb->global_eNB_ID.eNB_ID.choice.home_eNB_ID; break; } case ENB_ID_PR_short_Macro_eNB_ID: { - strncpy(str, (const char *)"enB-shortmacro:", 15); + strncpy(str, (const char *)"enB_shortmacro_", 15); data = &enb->global_eNB_ID.eNB_ID.choice.short_Macro_eNB_ID; break; } case ENB_ID_PR_long_Macro_eNB_ID: { - strncpy(str, (const char *)"enB-longmacro:", 14); + strncpy(str, (const char *)"enB_longmacro_", 14); data = &enb->global_eNB_ID.eNB_ID.choice.long_Macro_eNB_ID; break; } diff --git a/RIC-E2-TERMINATION/BuildXml.h b/RIC-E2-TERMINATION/BuildXml.h index beca88b..e71fa4d 100644 --- a/RIC-E2-TERMINATION/BuildXml.h +++ b/RIC-E2-TERMINATION/BuildXml.h @@ -21,6 +21,7 @@ #ifndef E2_BUILDXML_H #define E2_BUILDXML_H + #include #include #include @@ -42,32 +43,6 @@ struct xml_string_writer : pugi::xml_writer { result.append(static_cast(data), size); } }; -// end::code[] - -//struct xml_memory_writer : pugi::xml_writer { -// char *buffer; -// size_t capacity; -// size_t result; -// -// xml_memory_writer() : buffer(nullptr), capacity(0), result(0) { -// } -// -// xml_memory_writer(char *buffer, size_t capacity) : buffer(buffer), capacity(capacity), result(0) { -// } -// -// [[nodiscard]] size_t written_size() const { -// return result < capacity ? result : capacity; -// } -// -// void write(const void *data, size_t size) override { -// if (result < capacity) { -// size_t chunk = (capacity - result < size) ? capacity - result : size; -// -// memcpy(buffer + result, data, chunk); -// } -// result += size; -// } -//}; std::string node_to_string(pugi::xml_node node) { xml_string_writer writer; @@ -76,15 +51,24 @@ std::string node_to_string(pugi::xml_node node) { return writer.result; } +string buildXmlData(const string &messageName, + const string &ieName, + vector &RANfunctionsAdded, + vector &RANfunctionsModified, + unsigned char *buffer, + size_t size) { + pugi::xml_document *doc = new pugi::xml_document(); -int buildXmlData(const string &messageName, const string &ieName, vector &RANfunctionsAdded, unsigned char *buffer, size_t size) { - pugi::xml_document doc; + char RANfunctionsAddedID[8]; + snprintf(RANfunctionsAddedID, 8, "%d", (int) ProtocolIE_ID_id_RANfunctionsAdded); + char RANfunctionsModifiedID[8]; + snprintf(RANfunctionsModifiedID, 8, "%d", (int) ProtocolIE_ID_id_RANfunctionsModified); + char GlobalE2nodeID[8]; + snprintf(GlobalE2nodeID, 8, "%d", (int) ProtocolIE_ID_id_GlobalE2node_ID); - doc.reset(); - pugi::xml_parse_result result = doc.load_buffer((const char *)buffer, size); + pugi::xml_parse_result result = doc->load_buffer((const char *) buffer, size); if (result) { - unsigned int index = 0; - for (auto tool : doc.child("E2AP-PDU") + for (auto tool : doc->child("E2AP-PDU") .child("initiatingMessage") .child("value") .child(messageName.c_str()) @@ -94,14 +78,14 @@ int buildXmlData(const string &messageName, const string &ieName, vector auto node = tool.child("id"); // get the id to identify the type of the contained message if (node.empty()) { mdclog_write(MDCLOG_ERR, "Failed to find ID node in the XML. File %s, line %d", - __FILE__, __LINE__); + __FILE__, __LINE__); continue; } - if (strcmp(node.name(), "id") == 0 && strcmp(node.child_value(), "10") == 0) { + if (strcmp(node.name(), "id") == 0 && strcmp(node.child_value(), RANfunctionsAddedID) == 0) { auto nodea = tool.child("value"). child("RANfunctions-List"). children("ProtocolIE-SingleContainer"); - + unsigned int index = 0; for (auto n1 : nodea) { auto n2 = n1.child("value").child("RANfunction-Item").child("ranFunctionDefinition"); n2.remove_children(); @@ -112,22 +96,41 @@ int buildXmlData(const string &messageName, const string &ieName, vector mdclog_write(MDCLOG_DEBUG, "entry %s Replaced with : %s", n2.name(), n2.child_value()); } } + } else if (strcmp(node.name(), "id") == 0 && strcmp(node.child_value(), RANfunctionsModifiedID) == 0) { + auto nodea = tool.child("value"). + child("RANfunctions-List"). + children("ProtocolIE-SingleContainer"); + unsigned int index = 0; + for (auto n1 : nodea) { + auto n2 = n1.child("value").child("RANfunction-Item").child("ranFunctionDefinition"); + n2.remove_children(); + string val = RANfunctionsModified.at(index++); + // here we get vector with counter + n2.append_child(pugi::node_pcdata).set_value(val.c_str()); + if (mdclog_level_get() >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "entry %s Replaced with : %s", n2.name(), n2.child_value()); + } + } + } else if (strcmp(node.name(), "id") == 0 && strcmp(node.child_value(), GlobalE2nodeID) == 0) { + continue; } else { if (mdclog_level_get() >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "Entry %s = value %s skipped", node.name(), node.child_value()); + mdclog_write(MDCLOG_DEBUG, "Entry name :%s with entry of %s skipped", node.name(), node.child_value()); } continue; } } - - auto res = node_to_string(doc); - memcpy(buffer, res.c_str(), res.length()); - doc.reset(); } else { - mdclog_write(MDCLOG_ERR, "Error loading xml string"); - return -1; + mdclog_write(MDCLOG_ERR, + "Error loading xml string"); + delete doc; + return string(""); } - return 0; + auto res = node_to_string(*doc); + res.erase(std::remove(res.begin(), res.end(), '\n'), res.end()); + res.erase(std::remove(res.begin(), res.end(), '\t'), res.end()); + delete doc; + return res; } diff --git a/RIC-E2-TERMINATION/CMakeLists.txt b/RIC-E2-TERMINATION/CMakeLists.txt index 75f27b1..398fd6d 100644 --- a/RIC-E2-TERMINATION/CMakeLists.txt +++ b/RIC-E2-TERMINATION/CMakeLists.txt @@ -44,6 +44,8 @@ include_directories(RIC-E2-TERMINATION RIC-E2-TERMINATION/3rdparty/oranE2 RIC-E2-TERMINATION/3rdparty/oranE2SM RIC-E2-TERMINATION/3rdparty/cxxopts/include + RIC-E2-TERMINATION/3rdparty/prometheus-cpp + RIC-E2-TERMINATION/3rdparty/prometheus-cpp/core/include RIC-E2-TERMINATION/3rdparty cmake-modules) @@ -99,6 +101,10 @@ link_libraries(nsl tbb boost_filesystem cgreen + prometheus-cpp-core + prometheus-cpp-pull + z + curl pthread) add_executable(e2 RIC-E2-TERMINATION/sctpThread.cpp @@ -109,7 +115,6 @@ add_executable(e2 RIC-E2-TERMINATION/sctpThread.cpp RIC-E2-TERMINATION/base64.cpp RIC-E2-TERMINATION/ReadConfigFile.h RIC-E2-TERMINATION/BuildRunName.h - RIC-E2-TERMINATION/statCollector.h RIC-E2-TERMINATION/3rdparty/pugixml/src/pugiconfig.hpp RIC-E2-TERMINATION/3rdparty/pugixml/src/pugixml.cpp RIC-E2-TERMINATION/3rdparty/pugixml/src/pugixml.hpp @@ -119,6 +124,8 @@ target_link_libraries(e2 librmr_si.a) target_link_libraries(e2 libicui18n.a) target_link_libraries(e2 libicuuc.a) target_link_libraries(e2 libicudata.a) +target_link_libraries(e2 prometheus-cpp-core.a) +target_link_libraries(e2 prometheus-cpp-pull.a) #target_link_libraries(e2 libnng.a) @@ -147,7 +154,6 @@ add_executable(sctpClient ) target_link_libraries(sctpClient libpistache.a) target_link_libraries(sctpClient librmr_si.a) -#target_link_libraries(sctpClient libnng.a) add_executable(setUpMessages RIC-E2-TERMINATION/TEST/testAsn/setUpMessages/SetUpMessages.cpp diff --git a/RIC-E2-TERMINATION/Dockerfile b/RIC-E2-TERMINATION/Dockerfile index f617363..df56433 100644 --- a/RIC-E2-TERMINATION/Dockerfile +++ b/RIC-E2-TERMINATION/Dockerfile @@ -50,8 +50,9 @@ RUN mv /opt/e2/RIC-E2-TERMINATION/CMakeLists.txt /opt/e2/ && cat /opt/e2/RIC-E2- && cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DPISTACHE_BUILD_DOCS=false \ -DPISTACHE_USE_SSL=false -DPISTACHE_BUILD_TESTS=false -DCMAKE_INSTALL_PREFIX=/usr/local ../ \ && make -j && make install && ldconfig \ -# && git clone http://gerrit.o-ran-sc.org/r/com/log \ -# && cd log && ./autogen.sh && ./configure && make && make install && ldconfig \ + && cd /opt/e2/RIC-E2-TERMINATION/3rdparty && git clone -v https://github.com/jupp0r/prometheus-cpp.git \ + && cd prometheus-cpp && git submodule init && git submodule update && mkdir build && cd build \ + && cmake .. -DBUILD_SHARED_LIBS=OFF && make -j 4 && make install && ldconfig \ && cd /opt/e2/RIC-E2-TERMINATION/3rdparty && git clone https://github.com/jarro2783/cxxopts.git \ && cd /opt/e2/RIC-E2-TERMINATION/3rdparty && git clone https://github.com/Tencent/rapidjson.git \ && cd /opt/e2/RIC-E2-TERMINATION/3rdparty && git clone https://github.com/zeux/pugixml.git \ diff --git a/RIC-E2-TERMINATION/TEST/T1/E2Builder.h b/RIC-E2-TERMINATION/TEST/T1/E2Builder.h index a82d246..af2f39e 100644 --- a/RIC-E2-TERMINATION/TEST/T1/E2Builder.h +++ b/RIC-E2-TERMINATION/TEST/T1/E2Builder.h @@ -33,6 +33,7 @@ #include <3rdparty/oranE2SM/RIC-InsertStyle-List.h> #include <3rdparty/oranE2SM/RANparameterDef-Item.h> #include <3rdparty/oranE2/GlobalE2node-en-gNB-ID.h> +#include <3rdparty/oranE2/RICsubsequentAction.h> //#include @@ -571,8 +572,6 @@ void buildSetupRequestWithFunc(E2AP_PDU_t *pdu, int mcc, int mnc) { ranFlistIEs->id = ProtocolIE_ID_id_RANfunctionsAdded; ranFlistIEs->value.present = E2setupRequestIEs__value_PR_RANfunctions_List; - auto *itemIes = (RANfunction_ItemIEs_t *)calloc(1, sizeof(RANfunction_ItemIEs_t)); - ASN_STRUCT_RESET(asn_DEF_RANfunction_ItemIEs, itemIes); E2SM_gNB_NRT_RANfunction_Definition_t ranFunDef; @@ -621,6 +620,9 @@ void buildSetupRequestWithFunc(E2AP_PDU_t *pdu, int mcc, int mnc) { ASN_SEQUENCE_ADD(&ranFunDef.ric_InsertStyle_List->list, &insertStyleList); //ranFunDef.ric_InsertStyle_List. + auto *itemIes = (RANfunction_ItemIEs_t *)calloc(1, sizeof(RANfunction_ItemIEs_t)); + ASN_STRUCT_RESET(asn_DEF_RANfunction_ItemIEs, itemIes); + uint8_t buffer[8192]; size_t buffer_size = 8192; auto *ranDef = &itemIes->value.choice.RANfunction_Item.ranFunctionDefinition; @@ -638,8 +640,6 @@ void buildSetupRequestWithFunc(E2AP_PDU_t *pdu, int mcc, int mnc) { memcpy(ranDef->buf, buffer, ranDef->size); } - - itemIes->id = ProtocolIE_ID_id_RANfunction_Item; itemIes->criticality = Criticality_reject; itemIes->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item; @@ -672,7 +672,109 @@ void buildSetupRequestWithFunc(E2AP_PDU_t *pdu, int mcc, int mnc) { } +void buildSubsReq(E2AP_PDU_t *pdu) { + ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu); + + pdu->choice.initiatingMessage = (InitiatingMessage_t *)calloc(1, sizeof(InitiatingMessage_t)); + pdu->present = E2AP_PDU_PR_initiatingMessage; + + auto *initMsg = pdu->choice.initiatingMessage; + ASN_STRUCT_RESET(asn_DEF_InitiatingMessage, initMsg); + initMsg->procedureCode = ProcedureCode_id_RICsubscription; + initMsg->criticality = Criticality_reject; + initMsg->value.present = InitiatingMessage__value_PR_RICsubscriptionRequest; + + auto *subReq = &(initMsg->value.choice.RICsubscriptionRequest); + ASN_STRUCT_RESET(asn_DEF_RICsubscriptionRequest, subReq); + + { // RICrequestID + auto *e = (RICsubscriptionRequest_IEs_t *)calloc(1, sizeof(RICsubscriptionRequest_IEs_t)); + ASN_STRUCT_RESET(asn_DEF_RICsubscriptionRequest_IEs, e); + e->id = ProtocolIE_ID_id_RICrequestID; + e->value.present = RICsubscriptionRequest_IEs__value_PR_RICrequestID; + e->value.choice.RICrequestID.ricRequestorID = 88; + e->value.choice.RICrequestID.ricInstanceID = 5; + ASN_SEQUENCE_ADD(&subReq->protocolIEs.list, e); + } + { // RANfunctionID + auto *e = (RICsubscriptionRequest_IEs_t *)calloc(1, sizeof(RICsubscriptionRequest_IEs_t)); + ASN_STRUCT_RESET(asn_DEF_RICsubscriptionRequest_IEs, e); + e->id = ProtocolIE_ID_id_RANfunctionID; + e->criticality = Criticality_reject; + e->value.present = RICsubscriptionRequest_IEs__value_PR_RANfunctionID; + e->value.choice.RANfunctionID = 8; + ASN_SEQUENCE_ADD(&subReq->protocolIEs.list, e); + } + { // RICrequestID + auto *e = (RICsubscriptionRequest_IEs_t *)calloc(1, sizeof(RICsubscriptionRequest_IEs_t)); + ASN_STRUCT_RESET(asn_DEF_RICsubscriptionRequest_IEs, e); + e->id = ProtocolIE_ID_id_RICsubscriptionDetails; + e->criticality = Criticality_reject; + e->value.present = RICsubscriptionRequest_IEs__value_PR_RICsubscriptionDetails; + + uint8_t buf[10] = {1,2,3,4,5,6,7,8,9,0} ; + e->value.choice.RICsubscriptionDetails.ricEventTriggerDefinition.size = 10; + e->value.choice.RICsubscriptionDetails.ricEventTriggerDefinition.buf = (uint8_t *)calloc(1, 10); + memcpy(e->value.choice.RICsubscriptionDetails.ricEventTriggerDefinition.buf, + buf, + e->value.choice.RICsubscriptionDetails.ricEventTriggerDefinition.size); + { // item 1 + auto ie = (RICaction_ToBeSetup_ItemIEs_t *)calloc(1, sizeof(RICaction_ToBeSetup_ItemIEs_t)); + ASN_STRUCT_RESET(asn_DEF_RICaction_ToBeSetup_ItemIEs, ie); + ie->id = ProtocolIE_ID_id_RICaction_ToBeSetup_Item; + ie->criticality = Criticality_ignore; + ie->value.present = RICaction_ToBeSetup_ItemIEs__value_PR_RICaction_ToBeSetup_Item; + ie->value.choice.RICaction_ToBeSetup_Item.ricActionID = 22; + ie->value.choice.RICaction_ToBeSetup_Item.ricActionType = RICactionType_report; + + auto *ad = (RICactionDefinition_t *)calloc(1, sizeof(RICactionDefinition_t)); + ASN_STRUCT_RESET(asn_DEF_RICactionDefinition, ad); + ad->size = 10; + uint8_t buf[10] = {1,2,3,4,5,6,7,8,9,0} ; + ad->buf = (uint8_t *)calloc(1, ad->size); + memcpy(ad->buf, buf, ad->size); + ie->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition = ad; + + auto *sa = (RICsubsequentAction_t *) calloc(1, sizeof(RICsubsequentAction_t)); + ASN_STRUCT_RESET(asn_DEF_RICsubsequentAction, sa); + + sa->ricTimeToWait = RICtimeToWait_w500ms; + sa->ricSubsequentActionType = RICsubsequentActionType_continue; + + ie->value.choice.RICaction_ToBeSetup_Item.ricSubsequentAction = sa; + ASN_SEQUENCE_ADD(&e->value.choice.RICsubscriptionDetails.ricAction_ToBeSetup_List.list, ie); + } + + { // item 2 + auto ie = (RICaction_ToBeSetup_ItemIEs_t *)calloc(1, sizeof(RICaction_ToBeSetup_ItemIEs_t)); + ASN_STRUCT_RESET(asn_DEF_RICaction_ToBeSetup_ItemIEs, ie); + ie->id = ProtocolIE_ID_id_RICaction_ToBeSetup_Item; + ie->criticality = Criticality_ignore; + ie->value.present = RICaction_ToBeSetup_ItemIEs__value_PR_RICaction_ToBeSetup_Item; + ie->value.choice.RICaction_ToBeSetup_Item.ricActionID = 47; + ie->value.choice.RICaction_ToBeSetup_Item.ricActionType = RICactionType_policy; + + auto *ad = (RICactionDefinition_t *)calloc(1, sizeof(RICactionDefinition_t)); + ASN_STRUCT_RESET(asn_DEF_RICactionDefinition, ad); + ad->size = 10; + uint8_t buf[10] = {1,2,3,4,5,6,7,8,9,0} ; + ad->buf = (uint8_t *)calloc(1, ad->size); + memcpy(ad->buf, buf, ad->size); + ie->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition = ad; + + auto *sa = (RICsubsequentAction_t *) calloc(1, sizeof(RICsubsequentAction_t)); + ASN_STRUCT_RESET(asn_DEF_RICsubsequentAction, sa); + + sa->ricTimeToWait = RICtimeToWait_w5s; + sa->ricSubsequentActionType = RICsubsequentActionType_wait; + + ie->value.choice.RICaction_ToBeSetup_Item.ricSubsequentAction = sa; + ASN_SEQUENCE_ADD(&e->value.choice.RICsubscriptionDetails.ricAction_ToBeSetup_List.list, ie); + } + ASN_SEQUENCE_ADD(&subReq->protocolIEs.list, e); + } +} void buildSetupSuccsessfulResponse(E2AP_PDU_t *pdu, int mcc, int mnc, uint8_t *data) { @@ -784,4 +886,254 @@ void buildSetupUnSuccsessfulResponse(E2AP_PDU_t *pdu) { pdu->present = E2AP_PDU_PR_unsuccessfulOutcome; } +void buildResetReq(E2AP_PDU_t *pdu) { + ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu); + + pdu->choice.initiatingMessage = (InitiatingMessage_t *)calloc(1, sizeof(InitiatingMessage_t)); + pdu->present = E2AP_PDU_PR_initiatingMessage; + + auto *initMsg = pdu->choice.initiatingMessage; + ASN_STRUCT_RESET(asn_DEF_InitiatingMessage, initMsg); + initMsg->procedureCode = ProcedureCode_id_Reset; + initMsg->criticality = Criticality_reject; + initMsg->value.present = InitiatingMessage__value_PR_ResetRequest; + + + auto *resetReq = &(initMsg->value.choice.ResetRequest); + ASN_STRUCT_RESET(asn_DEF_ResetRequest, resetReq); + + { // + auto *e = (ResetRequestIEs_t *)calloc(1, sizeof(ResetRequestIEs_t)); + ASN_STRUCT_RESET(asn_DEF_ResetRequestIEs, e); + e->id = ProtocolIE_ID_id_Cause; + e->criticality = Criticality_ignore; + e->value.present = ResetRequestIEs__value_PR_Cause; + e->value.choice.Cause.present = Cause_PR_ricRequest; + e->value.choice.Cause.choice.ricRequest = 1; + ASN_SEQUENCE_ADD(&resetReq->protocolIEs.list, e); + } + +} + +void buildResetResponse(E2AP_PDU_t *pdu) { + ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu); + + pdu->choice.successfulOutcome = (SuccessfulOutcome_t *)calloc(1, sizeof(SuccessfulOutcome_t)); + pdu->present = E2AP_PDU_PR_successfulOutcome; + + auto *succ = pdu->choice.successfulOutcome; + ASN_STRUCT_RESET(asn_DEF_InitiatingMessage, succ); + succ->procedureCode = ProcedureCode_id_Reset; + succ->criticality = Criticality_reject; + succ->value.present = SuccessfulOutcome__value_PR_ResetResponse; + + + auto *resetRespo = &(succ->value.choice.ResetResponse); + ASN_STRUCT_RESET(asn_DEF_ResetResponse, resetRespo); + + { // + auto *e = (ResetResponseIEs_t *)calloc(1, sizeof(ResetResponseIEs_t)); + ASN_STRUCT_RESET(asn_DEF_ResetResponseIEs, e); + e->id = ProtocolIE_ID_id_CriticalityDiagnostics; + e->criticality = Criticality_ignore; + e->value.present = ResetResponseIEs__value_PR_CriticalityDiagnostics; + + e->value.choice.CriticalityDiagnostics.procedureCode = (ProcedureCode_t *)calloc(1,sizeof(ProcedureCode_t)); + *e->value.choice.CriticalityDiagnostics.procedureCode = ProcedureCode_id_Reset; + e->value.choice.CriticalityDiagnostics.triggeringMessage = (TriggeringMessage_t *)calloc(1,sizeof(TriggeringMessage_t)); + *e->value.choice.CriticalityDiagnostics.triggeringMessage = TriggeringMessage_initiating_message; + e->value.choice.CriticalityDiagnostics.procedureCriticality = (Criticality_t *)calloc(1, sizeof(Criticality_t)); + *e->value.choice.CriticalityDiagnostics.procedureCriticality = Criticality_reject; + ASN_SEQUENCE_ADD(&resetRespo->protocolIEs.list, e); + } + +} + +void buildServiceQuery(E2AP_PDU_t *pdu) { + ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu); + + pdu->choice.initiatingMessage = (InitiatingMessage_t *)calloc(1, sizeof(InitiatingMessage_t)); + pdu->present = E2AP_PDU_PR_initiatingMessage; + + auto *initMsg = pdu->choice.initiatingMessage; + ASN_STRUCT_RESET(asn_DEF_InitiatingMessage, initMsg); + initMsg->procedureCode = ProcedureCode_id_RICserviceQuery; + initMsg->criticality = Criticality_ignore; + initMsg->value.present = InitiatingMessage__value_PR_RICserviceQuery; + + + auto *serviceQuery = &(initMsg->value.choice.RICserviceQuery); + ASN_STRUCT_RESET(asn_DEF_ResetRequest, serviceQuery); + + { // + auto *e = (RICserviceQuery_IEs_t *)calloc(1, sizeof(RICserviceQuery_IEs_t)); + ASN_STRUCT_RESET(asn_DEF_RICserviceQuery_IEs, e); + e->id = ProtocolIE_ID_id_RANfunctionsAccepted; + e->criticality = Criticality_reject; + e->value.present = RICserviceQuery_IEs__value_PR_RANfunctionsID_List; + { + auto *ranFuncIdItemIEs = (RANfunctionID_ItemIEs_t *)calloc(1, sizeof(RANfunctionID_ItemIEs_t)); + + ranFuncIdItemIEs->criticality = Criticality_ignore; + ranFuncIdItemIEs->id = ProtocolIE_ID_id_RANfunctionID_Item; + ranFuncIdItemIEs->value.present = RANfunctionID_ItemIEs__value_PR_RANfunctionID_Item; + ranFuncIdItemIEs->value.choice.RANfunctionID_Item.ranFunctionID = 10; + ranFuncIdItemIEs->value.choice.RANfunctionID_Item.ranFunctionRevision = 1; + ASN_SEQUENCE_ADD(&e->value.choice.RANfunctionsID_List.list, ranFuncIdItemIEs); + } + { + auto *ranFuncIdItemIEs = (RANfunctionID_ItemIEs_t *)calloc(1, sizeof(RANfunctionID_ItemIEs_t)); + + ranFuncIdItemIEs->criticality = Criticality_ignore; + ranFuncIdItemIEs->id = ProtocolIE_ID_id_RANfunctionID_Item; + ranFuncIdItemIEs->value.present = RANfunctionID_ItemIEs__value_PR_RANfunctionID_Item; + ranFuncIdItemIEs->value.choice.RANfunctionID_Item.ranFunctionID = 11; + ranFuncIdItemIEs->value.choice.RANfunctionID_Item.ranFunctionRevision = 2; + ASN_SEQUENCE_ADD(&e->value.choice.RANfunctionsID_List.list, ranFuncIdItemIEs); + } + { + auto *ranFuncIdItemIEs = (RANfunctionID_ItemIEs_t *)calloc(1, sizeof(RANfunctionID_ItemIEs_t)); + + ranFuncIdItemIEs->criticality = Criticality_ignore; + ranFuncIdItemIEs->id = ProtocolIE_ID_id_RANfunctionID_Item; + ranFuncIdItemIEs->value.present = RANfunctionID_ItemIEs__value_PR_RANfunctionID_Item; + ranFuncIdItemIEs->value.choice.RANfunctionID_Item.ranFunctionID = 28; + ranFuncIdItemIEs->value.choice.RANfunctionID_Item.ranFunctionRevision = 13; + ASN_SEQUENCE_ADD(&e->value.choice.RANfunctionsID_List.list, ranFuncIdItemIEs); + } + { + auto *ranFuncIdItemIEs = (RANfunctionID_ItemIEs_t *)calloc(1, sizeof(RANfunctionID_ItemIEs_t)); + + ranFuncIdItemIEs->criticality = Criticality_ignore; + ranFuncIdItemIEs->id = ProtocolIE_ID_id_RANfunctionID_Item; + ranFuncIdItemIEs->value.present = RANfunctionID_ItemIEs__value_PR_RANfunctionID_Item; + ranFuncIdItemIEs->value.choice.RANfunctionID_Item.ranFunctionID = 1; + ranFuncIdItemIEs->value.choice.RANfunctionID_Item.ranFunctionRevision = 4; + ASN_SEQUENCE_ADD(&e->value.choice.RANfunctionsID_List.list, ranFuncIdItemIEs); + } + ASN_SEQUENCE_ADD(&serviceQuery->protocolIEs.list, e); + } + +} +void buildServiceUpdateResponce(E2AP_PDU_t *pdu) { + ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, pdu); + + pdu->choice.successfulOutcome = (SuccessfulOutcome_t *)calloc(1, sizeof(SuccessfulOutcome_t)); + pdu->present = E2AP_PDU_PR_successfulOutcome; + + auto *succ = pdu->choice.successfulOutcome; + ASN_STRUCT_RESET(asn_DEF_SuccessfulOutcome, succ); + succ->procedureCode = ProcedureCode_id_RICserviceQuery; + succ->criticality = Criticality_reject; + succ->value.present = SuccessfulOutcome__value_PR_RICserviceUpdateAcknowledge; + + + auto *serviceUpdAck = &(succ->value.choice.RICserviceUpdateAcknowledge); + ASN_STRUCT_RESET(asn_DEF_RICserviceUpdateAcknowledge, serviceUpdAck); + + { // + auto *e = (RICserviceUpdateAcknowledge_IEs_t *)calloc(1, sizeof(RICserviceUpdateAcknowledge_IEs_t)); + ASN_STRUCT_RESET(asn_DEF_RICserviceUpdateAcknowledge_IEs, e); + e->id = ProtocolIE_ID_id_RANfunctionsAccepted; + e->criticality = Criticality_reject; + e->value.present = RICserviceUpdateAcknowledge_IEs__value_PR_RANfunctionsID_List; + { + auto *ranFuncIdItemIEs = (RANfunctionID_ItemIEs_t *)calloc(1, sizeof(RANfunctionID_ItemIEs_t)); + + ranFuncIdItemIEs->criticality = Criticality_reject; + ranFuncIdItemIEs->id = ProtocolIE_ID_id_RANfunctionID_Item; + ranFuncIdItemIEs->value.present = RANfunctionID_ItemIEs__value_PR_RANfunctionID_Item; + ranFuncIdItemIEs->value.choice.RANfunctionID_Item.ranFunctionID = 10; + ranFuncIdItemIEs->value.choice.RANfunctionID_Item.ranFunctionRevision = 1; + ASN_SEQUENCE_ADD(&e->value.choice.RANfunctionsID_List.list, ranFuncIdItemIEs); + } + { + auto *ranFuncIdItemIEs = (RANfunctionID_ItemIEs_t *)calloc(1, sizeof(RANfunctionID_ItemIEs_t)); + + ranFuncIdItemIEs->criticality = Criticality_reject; + ranFuncIdItemIEs->id = ProtocolIE_ID_id_RANfunctionID_Item; + ranFuncIdItemIEs->value.present = RANfunctionID_ItemIEs__value_PR_RANfunctionID_Item; + ranFuncIdItemIEs->value.choice.RANfunctionID_Item.ranFunctionID = 11; + ranFuncIdItemIEs->value.choice.RANfunctionID_Item.ranFunctionRevision = 2; + ASN_SEQUENCE_ADD(&e->value.choice.RANfunctionsID_List.list, ranFuncIdItemIEs); + } + { + auto *ranFuncIdItemIEs = (RANfunctionID_ItemIEs_t *)calloc(1, sizeof(RANfunctionID_ItemIEs_t)); + + ranFuncIdItemIEs->criticality = Criticality_reject; + ranFuncIdItemIEs->id = ProtocolIE_ID_id_RANfunctionID_Item; + ranFuncIdItemIEs->value.present = RANfunctionID_ItemIEs__value_PR_RANfunctionID_Item; + ranFuncIdItemIEs->value.choice.RANfunctionID_Item.ranFunctionID = 28; + ranFuncIdItemIEs->value.choice.RANfunctionID_Item.ranFunctionRevision = 13; + ASN_SEQUENCE_ADD(&e->value.choice.RANfunctionsID_List.list, ranFuncIdItemIEs); + } + { + auto *ranFuncIdItemIEs = (RANfunctionID_ItemIEs_t *)calloc(1, sizeof(RANfunctionID_ItemIEs_t)); + + ranFuncIdItemIEs->criticality = Criticality_reject; + ranFuncIdItemIEs->id = ProtocolIE_ID_id_RANfunctionID_Item; + ranFuncIdItemIEs->value.present = RANfunctionID_ItemIEs__value_PR_RANfunctionID_Item; + ranFuncIdItemIEs->value.choice.RANfunctionID_Item.ranFunctionID = 1; + ranFuncIdItemIEs->value.choice.RANfunctionID_Item.ranFunctionRevision = 4; + ASN_SEQUENCE_ADD(&e->value.choice.RANfunctionsID_List.list, ranFuncIdItemIEs); + } + ASN_SEQUENCE_ADD(&serviceUpdAck->protocolIEs.list, e); + } + + + { + auto *e = (RICserviceUpdateAcknowledge_IEs_t *)calloc(1, sizeof(RICserviceUpdateAcknowledge_IEs_t)); + ASN_STRUCT_RESET(asn_DEF_RICserviceUpdateAcknowledge_IEs, e); + e->id = ProtocolIE_ID_id_RANfunctionsRejected; + e->criticality = Criticality_reject; + e->value.present = RICserviceUpdateAcknowledge_IEs__value_PR_RANfunctionsIDcause_List; + { + + auto *ranFuncIdcause = (RANfunctionIDcause_ItemIEs_t *) calloc(1, sizeof(RANfunctionIDcause_ItemIEs_t)); + ASN_STRUCT_RESET(asn_DEF_RANfunctionIDcause_Item, ranFuncIdcause); + + ranFuncIdcause->criticality = Criticality_ignore; + ranFuncIdcause->id = ProtocolIE_ID_id_RANfunctionIEcause_Item; + ranFuncIdcause->value.present = RANfunctionIDcause_ItemIEs__value_PR_RANfunctionIDcause_Item; + ranFuncIdcause->value.choice.RANfunctionIDcause_Item.ranFunctionID = 1; + + ranFuncIdcause->value.choice.RANfunctionIDcause_Item.cause.present = Cause_PR_ricService; + ranFuncIdcause->value.choice.RANfunctionIDcause_Item.cause.choice.ricService = 1; + ASN_SEQUENCE_ADD(&e->value.choice.RANfunctionsIDcause_List.list, ranFuncIdcause); + + } + { + + auto *ranFuncIdcause = (RANfunctionIDcause_ItemIEs_t *) calloc(1, sizeof(RANfunctionIDcause_ItemIEs_t)); + ASN_STRUCT_RESET(asn_DEF_RANfunctionIDcause_Item, ranFuncIdcause); + + ranFuncIdcause->criticality = Criticality_ignore; + ranFuncIdcause->id = ProtocolIE_ID_id_RANfunctionIEcause_Item; + ranFuncIdcause->value.present = RANfunctionIDcause_ItemIEs__value_PR_RANfunctionIDcause_Item; + ranFuncIdcause->value.choice.RANfunctionIDcause_Item.ranFunctionID = 2; + + ranFuncIdcause->value.choice.RANfunctionIDcause_Item.cause.present = Cause_PR_ricService; + ranFuncIdcause->value.choice.RANfunctionIDcause_Item.cause.choice.ricService = 2; + ASN_SEQUENCE_ADD(&e->value.choice.RANfunctionsIDcause_List.list, ranFuncIdcause); + + } + { + auto *ranFuncIdcause = (RANfunctionIDcause_ItemIEs_t *) calloc(1, sizeof(RANfunctionIDcause_ItemIEs_t)); + ASN_STRUCT_RESET(asn_DEF_RANfunctionIDcause_Item, ranFuncIdcause); + + ranFuncIdcause->criticality = Criticality_ignore; + ranFuncIdcause->id = ProtocolIE_ID_id_RANfunctionIEcause_Item; + ranFuncIdcause->value.present = RANfunctionIDcause_ItemIEs__value_PR_RANfunctionIDcause_Item; + ranFuncIdcause->value.choice.RANfunctionIDcause_Item.ranFunctionID = 3; + + ranFuncIdcause->value.choice.RANfunctionIDcause_Item.cause.present = Cause_PR_ricService; + ranFuncIdcause->value.choice.RANfunctionIDcause_Item.cause.choice.ricService = 2; + ASN_SEQUENCE_ADD(&e->value.choice.RANfunctionsIDcause_List.list, ranFuncIdcause); + + } + ASN_SEQUENCE_ADD(&serviceUpdAck->protocolIEs.list, e); + } + +} + #endif //E2_E2BUILDER_H diff --git a/RIC-E2-TERMINATION/TEST/testAsn/T2/SubscriptionTest.cpp b/RIC-E2-TERMINATION/TEST/testAsn/T2/SubscriptionTest.cpp deleted file mode 100644 index f0d4c50..0000000 --- a/RIC-E2-TERMINATION/TEST/testAsn/T2/SubscriptionTest.cpp +++ /dev/null @@ -1,352 +0,0 @@ -/* - * Copyright 2019 AT&T Intellectual Property - * Copyright 2019 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * This source code is part of the near-RT RIC (RAN Intelligent Controller) - * platform project (RICP). - */ - - -// -// Created by adi ENZEL on 6/17/19. -// - -#include - -#include "asn/type_defs.h" -#include "asn/per/codec.hpp" -#include "asn/printer.hpp" - -#include "X2AP-CommonDataTypes.hpp" -#include "X2AP-Containers.hpp" -#include "X2AP-Constants.hpp" -#include "X2AP-IEs.hpp" -#include "X2AP-PDU-Contents.hpp" - -#include "E2AP-Constants.hpp" -#include "E2AP-IEs.hpp" -#include "E2AP-PDU-Contents.hpp" -#include "E2AP-PDU-Descriptions.hpp" - - -#include -#include -#include -#include - -#include -#include -#include - -#include "logInit.h" - -// test X2SetUP request and response -using namespace std; - -#define MAXEVENTS 64 - -int main(const int argc, char **argv) { - mdclog_severity_t loglevel = MDCLOG_INFO; - - auto buff = new string("Subscription TEST"); - init_log((char *)buff->c_str()); - - mdclog_level_set(loglevel); - - if (argc < 5){ - mdclog_mdc_add("app", argv[0]); - mdclog_write(MDCLOG_ERR, "Usage ran rmr [logLevel = MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, "We are after RMR INIT wait for RMR_Ready"); - } - - int rmrReady = 0; - int count = 0; - while (!rmrReady) { - if ((rmrReady = rmr_ready(rmrCtx)) == 0) { - sleep(1); - } - count++; - if (count % 60 == 0) { - mdclog_write(MDCLOG_INFO, "waiting to RMR ready state for %d seconds", count); - } - if (count > 180) { - mdclog_write(MDCLOG_ERR, "RMR not ready tried for 3 minutes "); - return(-2); - } - } - if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, "RMR running"); - } - - E2AP_PDU cuAckPdu {}; - auto &succ = cuAckPdu.select_successfulOutcome(); - succ.ref_procedureCode().select_id_endcConfigurationUpdate(); - succ.ref_criticality().select_id_endcConfigurationUpdate(); - auto &endcConfAck = succ.ref_value().select_id_endcConfigurationUpdate(); - auto &confAckIes = endcConfAck.ref_protocolIEs(); - - ENDCConfigurationUpdateAcknowledge::protocolIEs_t::value_type endcENB {}; - endcENB.ref_id().select_id_RespondingNodeType_EndcConfigUpdate(); - endcENB.ref_criticality().select_id_RespondingNodeType_EndcConfigUpdate(); - - auto &respondingNode = endcENB.ref_value().select_id_RespondingNodeType_EndcConfigUpdate(); - - auto &enb = respondingNode.select_respond_eNB(); - - - confAckIes.push_back(endcENB); - - - - E2AP_PDU pdu {}; - auto &initiatingMsg = pdu.select_initiatingMessage(); - initiatingMsg.ref_procedureCode().select_id_ricSubscription(); - initiatingMsg.ref_criticality().select_id_ricSubscription(); - auto &subscription = initiatingMsg.ref_value().select_id_ricSubscription(); - - auto &ies = subscription.ref_protocolIEs(); - - - - RICsubscriptionRequest::protocolIEs_t::value_type ranFuncId {}; - ranFuncId.ref_id().select_id_RANfunctionID(); - ranFuncId.ref_criticality().select_id_RANfunctionID(); - ranFuncId.ref_value().select_id_RANfunctionID().set(28); - ies.push_back(ranFuncId); - - RICsubscriptionRequest::protocolIEs_t::value_type ricRequestId {}; - ricRequestId.ref_id().select_id_RICrequestID(); - ricRequestId.ref_criticality().select_id_RICrequestID(); - ricRequestId.ref_value().select_id_RICrequestID().ref_ricRequestorID().set(44); - ricRequestId.ref_value().select_id_RICrequestID().ref_ricRequestSequenceNumber().set(55); - ies.push_back(ricRequestId); - - RICsubscriptionRequest::protocolIEs_t::value_type ricSubId {}; - ricSubId.ref_id().select_id_RICsubscription(); - ricSubId.ref_criticality().select_id_RICsubscription(); - - //E2SM_gNB_X2_eventTriggerDefinition_t evt; - uint8_t v1[] = {0x02, 0xf8, 0x29, 0x88}; - - RICeventTriggerDefinition eventTriggerDef {}; // octet string in E2AP but struct in E2SM - eventTriggerDef.set(4, v1); - -// eventTriggerDef. -// -// -// RICaction_Admitted_List::value_type actbl {}; -// actbl.ref_id().select_id_RICaction_Admitted_Item(); -// actbl.ref_criticality().select_id_RICaction_Admitted_Item(); - - -// RICaction_ToBeSetup_Item actb1{}; -// -// actbl.ref_value().select_id_RICaction_Admitted_Item().ref_ricActionID().set(actb1); -// ricSubId.ref_value().select_id_RICsubscription().ref_ricAction_ToBeSetup_List().set(actbl); - - - ies.push_back(ricSubId); - -/* - - ies.push_back(ranFuncId); - - X2SetupRequest::protocolIEs_t::value_type sc {}; - ies.push_back(sc); - - sc.ref_id().select_id_ServedCells(); - sc.ref_criticality().select_id_ServedCells(); - - ServedCells::value_type sce; - sc.ref_value().select_id_ServedCells().push_back(sce); - - sce.ref_servedCellInfo().ref_pCI().set(0x1F7); - uint8_t v3[] = {0x1, 0x2}; - sce.ref_servedCellInfo().ref_tAC().set(2,v3); - sce.ref_servedCellInfo().ref_cellId().ref_pLMN_Identity().set(3, v1); - uint8_t v4[] = {0x00, 0x07, 0xab, ((unsigned)0x50) >> (unsigned)4}; - sce.ref_servedCellInfo().ref_cellId().ref_eUTRANcellIdentifier().set_buffer(28, v4); - - BroadcastPLMNs_Item::value_type bpe; - sce.ref_servedCellInfo().ref_broadcastPLMNs().push_back(bpe); - bpe.set(3, v1); - - sce.ref_servedCellInfo().ref_eUTRA_Mode_Info().select_fDD().ref_uL_EARFCN().set(0x1); - sce.ref_servedCellInfo().ref_eUTRA_Mode_Info().select_fDD().ref_dL_EARFCN().set(0x1); - sce.ref_servedCellInfo().ref_eUTRA_Mode_Info().select_fDD().ref_uL_Transmission_Bandwidth().set(Transmission_Bandwidth::bw50); - sce.ref_servedCellInfo().ref_eUTRA_Mode_Info().select_fDD().ref_dL_Transmission_Bandwidth().set(Transmission_Bandwidth::bw50); - -*/ - - unsigned char s_buffer[64 * 1024]; - asn::per::EncoderCtx ctx{s_buffer, sizeof(s_buffer)}; - std::cout << asn::get_printed(pdu) << std::endl; - if (!asn::per::pack(pdu, ctx)) { - std::cout << ctx.refErrorCtx().toString() << std::endl; - return -3; - } - size_t packed_buf_size; - packed_buf_size = static_cast(ctx.refBuffer().getBytesUsed()); - - // build message - char data[4096] {}; - //auto delimiter = (const char) '|'; - sprintf(data, "%s/0", ctx.refBuffer().getBytes(packed_buf_size)); - - rmr_mbuf_t *msg = rmr_alloc_msg(rmrCtx, int(strlen(data))); - rmr_bytes2meid(msg, (unsigned char const*)ranName, strlen(ranName)); - rmr_bytes2payload(msg, (unsigned char const*)data, strlen(data)); - rmr_bytes2xact(msg, (unsigned char const*)ranName, strlen(ranName)); - msg->mtype = RIC_SUB_REQ; - msg->state = 0; - - msg = rmr_send_msg(rmrCtx, msg); - if (msg->state != 0) { - mdclog_write(MDCLOG_ERR, "Message state %d while sending RIC_X2_SETUP to %s", msg->state, ranName); - rmr_free_msg(msg); - rmr_close(rmrCtx); - return -4; - } - rmr_free_msg(msg); - - - unsigned char allocBuffer[64*1024] {0}; - auto *events = (struct epoll_event *)calloc(MAXEVENTS, sizeof(event)); - - while (true) { - - auto numOfEvents = epoll_wait(epoll_fd, events, MAXEVENTS, -1); - if (numOfEvents < 0) { - mdclog_write(MDCLOG_ERR, "Epoll wait failed, errno = %s", strerror(errno)); - rmr_close(rmrCtx); - return -4; - } - for (auto i = 0; i < numOfEvents; i++) { - if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP) || (!(events[i].events & EPOLLIN))) { - mdclog_write(MDCLOG_ERR, "epoll error"); - } else if (rmrListenFd == events[i].data.fd) { - msg = rmr_alloc_msg(rmrCtx, 4096); - if (msg == nullptr) { - mdclog_write(MDCLOG_ERR, "RMR Allocation message, %s", strerror(errno)); - rmr_close(rmrCtx); - return -5; - } - - msg = rmr_rcv_msg(rmrCtx, msg); - if (msg == nullptr) { - mdclog_write(MDCLOG_ERR, "RMR Receving message, %s", strerror(errno)); - rmr_close(rmrCtx); - return -6; - } - memset(allocBuffer, 0, 64*1024); - switch (msg->mtype) { - default: { - mdclog_write(MDCLOG_INFO, "RMR receiveing message type %d", msg->mtype); - asn::per::DecoderCtx dCtx{msg->payload, (size_t) msg->len, allocBuffer, sizeof(allocBuffer)}; - E2AP_PDU opdu; - if (!asn::per::unpack(opdu, dCtx)) { - mdclog_write(MDCLOG_ERR, "Failed to unpack ASN message, %s", dCtx.refErrorCtx().toString()); - rmr_close(rmrCtx); - return -7; - } - - switch (opdu.get_index()) { - case 1: { //initiating message - mdclog_write(MDCLOG_INFO, "ASN initiating message type %ld", - opdu.get_initiatingMessage()->ref_procedureCode().ref_value().get()); - break; - } - case 2: { //successful message - mdclog_write(MDCLOG_INFO, "ASN initiating message type %ld", - opdu.get_successfulOutcome()->ref_procedureCode().ref_value().get()); - break; - } - case 3: { //unsuccessesful message - mdclog_write(MDCLOG_INFO, "ASN initiating message type %ld", - opdu.get_unsuccessfulOutcome()->ref_procedureCode().ref_value().get()); - break; - } - - } - mdclog_write(MDCLOG_INFO, "RMR receiveing message from E2 terminator, %d", - msg->mtype); - break; - } - } - } - } - } -} \ No newline at end of file diff --git a/RIC-E2-TERMINATION/TEST/testAsn/setUpMessages/SetUpMessages.cpp b/RIC-E2-TERMINATION/TEST/testAsn/setUpMessages/SetUpMessages.cpp index 1c5a129..36d5f02 100644 --- a/RIC-E2-TERMINATION/TEST/testAsn/setUpMessages/SetUpMessages.cpp +++ b/RIC-E2-TERMINATION/TEST/testAsn/setUpMessages/SetUpMessages.cpp @@ -135,31 +135,30 @@ std::string otherXml = "\n" "\n"; - std::string newXml = "1413 10 14101010101100110011109611621631"; std::string setupFailure = "" - "" - "1" - "" - "" - "" - "" - "" - "1" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" + "" + "1" + "" + "" + "" + "" + "" + "1" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" ""; @@ -203,7 +202,19 @@ auto main(const int argc, char **argv) -> int { cout << "Encoding E2AP PDU of size " << size << endl << printBuffer << endl; fseek(stream,0,SEEK_SET); -// cout << "=========================" << endl << otherXml << endl << "========================" << endl; + cout << "=========================" << endl << endl << endl << "========================" << endl; + buildSubsReq(&pdu); + char errbuf[256]; + int errlen = 256; + int ret = asn_check_constraints(&asn_DEF_E2AP_PDU, &pdu, errbuf, (size_t *)&errlen); + if (ret) { + cout << "Constraint validation failed: " << errbuf << endl; + } + asn_fprint(stream, &asn_DEF_E2AP_PDU, &pdu); + cout << "Encoding E2AP PDU of size " << size << endl << printBuffer << endl; + //fseek(stream,0,SEEK_SET); + extractPdu(&pdu, buffer, buffer_size); + memset(buffer, 0, buffer_size); buildSetupRequest(&pdu, 311, 410); asn_fprint(stream, &asn_DEF_E2AP_PDU, &pdu); @@ -261,4 +272,39 @@ auto main(const int argc, char **argv) -> int { fseek(stream,0,SEEK_SET); extractPdu(&pdu, buffer, buffer_size); + memset(buffer, 0, buffer_size); + + buildResetReq(&pdu); + asn_fprint(stream, &asn_DEF_E2AP_PDU, &pdu); + cout << "Encoding E2AP PDU (Reset Request) of size " << size << endl << printBuffer << endl; + fseek(stream,0,SEEK_SET); + + extractPdu(&pdu, buffer, buffer_size); + memset(buffer, 0, buffer_size); + + + buildServiceQuery(&pdu); + asn_fprint(stream, &asn_DEF_E2AP_PDU, &pdu); + cout << "Encoding E2AP PDU (service query) of size " << size << endl << printBuffer << endl; + fseek(stream,0,SEEK_SET); + + extractPdu(&pdu, buffer, buffer_size); + memset(buffer, 0, buffer_size); + + buildServiceUpdateResponce(&pdu); + asn_fprint(stream, &asn_DEF_E2AP_PDU, &pdu); + cout << "Encoding E2AP PDU (service update ack) of size " << size << endl << printBuffer << endl; + fseek(stream,0,SEEK_SET); + + extractPdu(&pdu, buffer, buffer_size); + memset(buffer, 0, buffer_size); + + buildResetResponse(&pdu); + asn_fprint(stream, &asn_DEF_E2AP_PDU, &pdu); + cout << "Encoding E2AP PDU (reset response example) of size " << size << endl << printBuffer << endl; + fseek(stream,0,SEEK_SET); + + extractPdu(&pdu, buffer, buffer_size); + memset(buffer, 0, buffer_size); + } diff --git a/RIC-E2-TERMINATION/config/config.conf b/RIC-E2-TERMINATION/config/config.conf index 43a124a..86d1180 100644 --- a/RIC-E2-TERMINATION/config/config.conf +++ b/RIC-E2-TERMINATION/config/config.conf @@ -4,6 +4,7 @@ volume=log #the key name of the environment holds the local ip address #ip address of the E2T in the RMR local-ip=127.0.0.1 +prometheusPort=8088 #trace is start, stop trace=start external-fqdn=e2t.com diff --git a/RIC-E2-TERMINATION/container-tag.yaml b/RIC-E2-TERMINATION/container-tag.yaml index 8c395d4..adeeeda 100644 --- a/RIC-E2-TERMINATION/container-tag.yaml +++ b/RIC-E2-TERMINATION/container-tag.yaml @@ -1,3 +1,3 @@ # The Jenkins job requires a tag to build the Docker image. # Global-JJB script assumes this file is in the repo root. -tag: 4.0.10 +tag: 5.0.0 diff --git a/RIC-E2-TERMINATION/sctpThread.cpp b/RIC-E2-TERMINATION/sctpThread.cpp index 7fa142e..49a4c51 100644 --- a/RIC-E2-TERMINATION/sctpThread.cpp +++ b/RIC-E2-TERMINATION/sctpThread.cpp @@ -31,6 +31,8 @@ using namespace std; //using namespace std::placeholders; using namespace boost::filesystem; +using namespace prometheus; + //#ifdef __cplusplus //extern "C" @@ -237,6 +239,11 @@ int buildConfiguration(sctp_params_t &sctpParams) { } jsonTrace = sctpParams.trace; + tmpStr = conf.getStringValue("prometheusPort"); + if (tmpStr.length() != 0) { + sctpParams.prometheusPort = tmpStr; + } + sctpParams.ka_message_length = snprintf(sctpParams.ka_message, KA_MESSAGE_SIZE, "{\"address\": \"%s:%d\"," "\"fqdn\": \"%s\"," "\"pod_name\": \"%s\"}", @@ -325,6 +332,20 @@ int main(const int argc, char **argv) { exit(-1); } + //auto registry = std::make_shared(); + sctpParams.promteheusRegistry = std::make_shared(); + + //sctpParams.prometheusFamily = new Family("E2T", "E2T message counter", {{"E", sctpParams.podName}}); + + sctpParams.prometheusFamily = &BuildCounter() + .Name("E2T") + .Help("E2T message counter") + .Labels({{"E", sctpParams.podName}}) + .Register(*sctpParams.promteheusRegistry); + + Exposer exposer{sctpParams.myIP + ":" + sctpParams.prometheusPort, "/metrics", 1}; + + // start epoll sctpParams.epoll_fd = epoll_create1(0); if (sctpParams.epoll_fd == -1) { @@ -357,6 +378,8 @@ int main(const int argc, char **argv) { std::vector threads(num_cpus); // std::vector threads; + exposer.RegisterCollectable(sctpParams.promteheusRegistry); + num_cpus = 1; for (unsigned int i = 0; i < num_cpus; i++) { threads[i] = std::thread(listener, &sctpParams); @@ -370,8 +393,6 @@ int main(const int argc, char **argv) { } } - auto statFlag = false; - auto statThread = std::thread(statColectorThread, (void *)&statFlag); //loop over term_init until first message from xApp handleTermInit(sctpParams); @@ -380,9 +401,6 @@ int main(const int argc, char **argv) { t.join(); } - statFlag = true; - statThread.join(); - return 0; } @@ -530,7 +548,6 @@ void listener(sctp_params_t *params) { mdclog_write(MDCLOG_DEBUG, "started thread number %s", tid); } - RmrMessagesBuffer_t rmrMessageBuffer{}; //create and init RMR rmrMessageBuffer.rmrCtx = params->rmrCtx; @@ -557,8 +574,6 @@ void listener(sctp_params_t *params) { // rmrMessageBuffer.sendBufferedMessages[i] = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE); // } - message.statCollector = StatCollector::GetInstance(); - while (true) { if (mdclog_level_get() >= MDCLOG_DEBUG) { mdclog_write(MDCLOG_DEBUG, "Start EPOLL Wait"); @@ -983,8 +998,6 @@ int sendSctpMsg(ConnectedCU_t *peerInfo, ReportingMessages_t &message, Sctp_Map_ m->erase(key); return -1; } - // TODO remove stat update - //message.statCollector->incSentMessage(string(message.message.enodbName)); message.message.direction = 'D'; // send report.buffer of size buildJsonMessage(message); @@ -1042,14 +1055,12 @@ int receiveDataFromSctp(struct epoll_event *events, // get the identity of the interface message.peerInfo = (ConnectedCU_t *)events->data.ptr; - message.statCollector = StatCollector::GetInstance(); struct timespec start{0, 0}; struct timespec decodestart{0, 0}; struct timespec end{0, 0}; E2AP_PDU_t *pdu = nullptr; - while (true) { if (loglevel >= MDCLOG_DEBUG) { mdclog_write(MDCLOG_DEBUG, "Start Read from SCTP %d fd", message.peerInfo->fileDescriptor); @@ -1066,7 +1077,6 @@ int receiveDataFromSctp(struct epoll_event *events, } memcpy(message.message.enodbName, message.peerInfo->enodbName, sizeof(message.peerInfo->enodbName)); - message.statCollector->incRecvMessage(string(message.message.enodbName)); message.message.direction = 'U'; message.message.time.tv_nsec = ts.tv_nsec; message.message.time.tv_sec = ts.tv_sec; @@ -1115,7 +1125,6 @@ int receiveDataFromSctp(struct epoll_event *events, if (rval.code != RC_OK) { mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) E2AP PDU from RAN : %s", rval.code, message.peerInfo->enodbName); - //todo may need reset to pdu break; } @@ -1195,89 +1204,97 @@ int receiveDataFromSctp(struct epoll_event *events, static void buildAndsendSetupRequest(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer, E2AP_PDU_t *pdu, - vector &repValues) { + string const &messageName, + string const &ieName, + vector &functionsToAdd_v, + vector &functionsToModified_v) { auto logLevel = mdclog_level_get(); // now we can send the data to e2Mgr + + asn_enc_rval_t er; auto buffer_size = RECEIVE_SCTP_BUFFER_SIZE * 2; - 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, at %s line %d", - (int) buffer_size, - asn_DEF_E2AP_PDU.name, __func__, __LINE__); - } else { - string messageType("E2setupRequest"); - string ieName("E2setupRequestIEs"); + unsigned char *buffer; + while (true) { + buffer = (unsigned char *)malloc(buffer_size); + 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)); + return; + } else if (er.encoded > (ssize_t) buffer_size) { + buffer_size = er.encoded + 128; + mdclog_write(MDCLOG_WARN, "Buffer of size %d is to small for %s. Reallocate buffer of size %d", + (int) buffer_size, + asn_DEF_E2AP_PDU.name, buffer_size); + buffer_size = er.encoded + 128; + free(buffer); + continue; + } 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", + break; + } + // encode to xml + + auto res = buildXmlData(messageName, ieName, functionsToAdd_v, functionsToModified_v, buffer, (size_t) er.encoded); + rmr_mbuf_t *rmrMsg; + if (res.length() == 0) { + rmrMsg = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, buffer_size + 256); + rmrMsg->len = snprintf((char *) rmrMsg->payload, RECEIVE_SCTP_BUFFER_SIZE * 2, "%s:%d|%s", message.peerInfo->sctpParams->myIP.c_str(), message.peerInfo->sctpParams->rmrPort, buffer); - if (logLevel >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "Setup request of size %d :\n %s\n", rmrMsg->len, rmrMsg->payload); - } - // send to RMR - message.message.messageType = rmrMsg->mtype = RIC_E2_SETUP_REQ; - rmrMsg->state = 0; - rmr_bytes2meid(rmrMsg, (unsigned char *) message.message.enodbName, strlen(message.message.enodbName)); + } else { + rmrMsg = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, (int)res.length() + 256); + rmrMsg->len = snprintf((char *) rmrMsg->payload, res.length() + 256, "%s:%d|%s", + message.peerInfo->sctpParams->myIP.c_str(), + message.peerInfo->sctpParams->rmrPort, + res.c_str()); + } - static unsigned char tx[32]; - snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); - rmr_bytes2xact(rmrMsg, tx, strlen((const char *) tx)); - - rmrMsg = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMsg); - if (rmrMsg == nullptr) { - mdclog_write(MDCLOG_ERR, "RMR failed to send returned nullptr"); - } else if (rmrMsg->state != 0) { - char meid[RMR_MAX_MEID]{}; - if (rmrMsg->state == RMR_ERR_RETRY) { - usleep(5); - rmrMsg->state = 0; - mdclog_write(MDCLOG_INFO, "RETRY sending Message %d to Xapp from %s", - rmrMsg->mtype, rmr_get_meid(rmrMsg, (unsigned char *) meid)); - rmrMsg = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMsg); - if (rmrMsg == nullptr) { - mdclog_write(MDCLOG_ERR, "RMR failed send returned nullptr"); - } else if (rmrMsg->state != 0) { - mdclog_write(MDCLOG_ERR, - "RMR Retry failed %s sending request %d to Xapp from %s", - translateRmrErrorMessages(rmrMsg->state).c_str(), - rmrMsg->mtype, - rmr_get_meid(rmrMsg, (unsigned char *) meid)); - } - } else { - mdclog_write(MDCLOG_ERR, "RMR failed: %s. sending request %d to Xapp from %s", + if (logLevel >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Setup request of size %d :\n %s\n", rmrMsg->len, rmrMsg->payload); + } + // send to RMR + rmrMsg->mtype = message.message.messageType; + rmrMsg->state = 0; + rmr_bytes2meid(rmrMsg, (unsigned char *) message.message.enodbName, strlen(message.message.enodbName)); + + static unsigned char tx[32]; + snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); + rmr_bytes2xact(rmrMsg, tx, strlen((const char *) tx)); + + rmrMsg = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMsg); + if (rmrMsg == nullptr) { + mdclog_write(MDCLOG_ERR, "RMR failed to send returned nullptr"); + } else if (rmrMsg->state != 0) { + char meid[RMR_MAX_MEID]{}; + if (rmrMsg->state == RMR_ERR_RETRY) { + usleep(5); + rmrMsg->state = 0; + mdclog_write(MDCLOG_INFO, "RETRY sending Message %d to Xapp from %s", + rmrMsg->mtype, rmr_get_meid(rmrMsg, (unsigned char *) meid)); + rmrMsg = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMsg); + if (rmrMsg == nullptr) { + mdclog_write(MDCLOG_ERR, "RMR failed send returned nullptr"); + } else if (rmrMsg->state != 0) { + mdclog_write(MDCLOG_ERR, + "RMR Retry failed %s sending request %d to Xapp from %s", translateRmrErrorMessages(rmrMsg->state).c_str(), rmrMsg->mtype, rmr_get_meid(rmrMsg, (unsigned char *) meid)); } - } - message.peerInfo->gotSetup = true; - buildJsonMessage(message); - if (rmrMsg != nullptr) { - rmr_free_msg(rmrMsg); + } else { + mdclog_write(MDCLOG_ERR, "RMR failed: %s. sending request %d to Xapp from %s", + translateRmrErrorMessages(rmrMsg->state).c_str(), + rmrMsg->mtype, + rmr_get_meid(rmrMsg, (unsigned char *) meid)); } } - + message.peerInfo->gotSetup = true; + buildJsonMessage(message); + if (rmrMsg != nullptr) { + rmr_free_msg(rmrMsg); + } + free(buffer); } int RAN_Function_list_To_Vector(RANfunctions_List_t& list, vector &runFunXML_v) { @@ -1301,17 +1318,9 @@ int RAN_Function_list_To_Vector(RANfunctions_List_t& list, vector &runF 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]; + memset(xml_buffer, 0, RECEIVE_SCTP_BUFFER_SIZE * 2); // encode to xml auto er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, @@ -1334,6 +1343,7 @@ int RAN_Function_list_To_Vector(RANfunctions_List_t& list, vector &runF index++, xml_buffer); } + string runFuncs = (char *)(xml_buffer); runFunXML_v.emplace_back(runFuncs); } @@ -1342,13 +1352,129 @@ int RAN_Function_list_To_Vector(RANfunctions_List_t& list, vector &runF return 0; } +int collectServiceUpdate_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.RICserviceUpdate.protocolIEs.list.count; i++) { + auto *ie = pdu->choice.initiatingMessage->value.choice.RICserviceUpdate.protocolIEs.list.array[i]; + if (ie->id == ProtocolIE_ID_id_RANfunctionsAdded) { + if (ie->value.present == RICserviceUpdate_IEs__value_PR_RANfunctionsID_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 == RICserviceUpdate_IEs__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; +} + + + +void buildPromethuslist(ConnectedCU_t *peerInfo, Family *prometheusFamily) { + peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_E2setup - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"SetupRequest", "Messages"}}); + peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_E2setup - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"SetupRequest", "Bytes"}}); + + peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_ErrorIndication - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ErrorIndication", "Messages"}}); + peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_ErrorIndication - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ErrorIndication", "Bytes"}}); + + peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_RICindication - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICindication", "Messages"}}); + peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_RICindication - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICindication", "Bytes"}}); + + peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_Reset - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ResetRequest", "Messages"}}); + peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_Reset - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ResetRequest", "Bytes"}}); + + peerInfo->counters[IN_INITI][MSG_COUNTER][(ProcedureCode_id_RICserviceUpdate - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICserviceUpdate", "Messages"}}); + peerInfo->counters[IN_INITI][BYTES_COUNTER][(ProcedureCode_id_RICserviceUpdate - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICserviceUpdate", "Bytes"}}); + // --------------------------------------------- + peerInfo->counters[IN_SUCC][MSG_COUNTER][(ProcedureCode_id_Reset - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ResetACK", "Messages"}}); + peerInfo->counters[IN_SUCC][BYTES_COUNTER][(ProcedureCode_id_Reset - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"ResetACK", "Bytes"}}); + + peerInfo->counters[IN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICcontrol - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICcontrolACK", "Messages"}}); + peerInfo->counters[IN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICcontrol - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICcontrolACK", "Bytes"}}); + + peerInfo->counters[IN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICsubscription - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionACK", "Messages"}}); + peerInfo->counters[IN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICsubscription - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionACK", "Bytes"}}); + + peerInfo->counters[IN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICsubscriptionDelete - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteACK", "Messages"}}); + peerInfo->counters[IN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICsubscriptionDelete - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteACK", "Bytes"}}); + //------------------------------------------------------------- + + peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICcontrol - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICcontrolFailure", "Messages"}}); + peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICcontrol - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICcontrolFailure", "Bytes"}}); + + peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICsubscription - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionFailure", "Messages"}}); + peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICsubscription - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionFailure", "Bytes"}}); + peerInfo->counters[IN_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICsubscriptionDelete - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteFailure", "Messages"}}); + peerInfo->counters[IN_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICsubscriptionDelete - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "IN"}, {"RICsubscriptionDeleteFailure", "Bytes"}}); -int collectSetupAndServiceUpdate_RequestData(E2AP_PDU_t *pdu, - Sctp_Map_t *sctpMap, - ReportingMessages_t &message, - vector &RANfunctionsAdded_v, - vector &RANfunctionsModified_v) { + //==================================================================================== + peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_ErrorIndication - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ErrorIndication", "Messages"}}); + peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_ErrorIndication - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ErrorIndication", "Bytes"}}); + + peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_Reset - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ResetRequest", "Messages"}}); + peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_Reset - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ResetRequest", "Bytes"}}); + + peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_RICcontrol - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICcontrol", "Messages"}}); + peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_RICcontrol - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICcontrol", "Bytes"}}); + + peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_RICserviceQuery - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceQuery", "Messages"}}); + peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_RICserviceQuery - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceQuery", "Bytes"}}); + + peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_RICsubscription - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICsubscription", "Messages"}}); + peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_RICsubscription - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICsubscription", "Bytes"}}); + + peerInfo->counters[OUT_INITI][MSG_COUNTER][(ProcedureCode_id_RICsubscriptionDelete - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICsubscriptionDelete", "Messages"}}); + peerInfo->counters[OUT_INITI][BYTES_COUNTER][(ProcedureCode_id_RICsubscriptionDelete - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICsubscriptionDelete", "Bytes"}}); + //--------------------------------------------------------------------------------------------------------- + peerInfo->counters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_E2setup - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"SetupResponse", "Messages"}}); + peerInfo->counters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2setup - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"SetupResponse", "Bytes"}}); + + peerInfo->counters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_Reset - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ResetACK", "Messages"}}); + peerInfo->counters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_Reset - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"ResetACK", "Bytes"}}); + + peerInfo->counters[OUT_SUCC][MSG_COUNTER][(ProcedureCode_id_RICserviceUpdate - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceUpdateResponse", "Messages"}}); + peerInfo->counters[OUT_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICserviceUpdate - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceUpdateResponse", "Bytes"}}); + //---------------------------------------------------------------------------------------------------------------- + peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_E2setup - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"SetupRequestFailure", "Messages"}}); + peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_E2setup - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"SetupRequestFailure", "Bytes"}}); + + peerInfo->counters[OUT_UN_SUCC][MSG_COUNTER][(ProcedureCode_id_RICserviceUpdate - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceUpdateFailure", "Messages"}}); + peerInfo->counters[OUT_UN_SUCC][BYTES_COUNTER][(ProcedureCode_id_RICserviceUpdate - 1)] = &prometheusFamily->Add({{peerInfo->enodbName, "OUT"}, {"RICserviceUpdateFailure", "Bytes"}}); +} +/** + * + * @param pdu + * @param sctpMap + * @param message + * @param RANfunctionsAdded_v + * @return + */ +int collectSetupRequestData(E2AP_PDU_t *pdu, + Sctp_Map_t *sctpMap, + ReportingMessages_t &message, + vector &RANfunctionsAdded_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]; @@ -1360,8 +1486,10 @@ int collectSetupAndServiceUpdate_RequestData(E2AP_PDU_t *pdu, // 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); + buildPromethuslist(message.peerInfo, message.peerInfo->sctpParams->prometheusFamily); } } else if (ie->id == ProtocolIE_ID_id_RANfunctionsAdded) { if (ie->value.present == E2setupRequestIEs__value_PR_RANfunctions_List) { @@ -1373,16 +1501,6 @@ int collectSetupAndServiceUpdate_RequestData(E2AP_PDU_t *pdu, 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) { @@ -1391,6 +1509,42 @@ int collectSetupAndServiceUpdate_RequestData(E2AP_PDU_t *pdu, } return 0; } + +int XML_From_PER(ReportingMessages_t &message, RmrMessagesBuffer_t &rmrMessageBuffer) { + E2AP_PDU_t *pdu = nullptr; + + if (mdclog_level_get() >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "got PER message of size %d is:%s", + rmrMessageBuffer.sendMessage->len, rmrMessageBuffer.sendMessage->payload); + } + auto rval = asn_decode(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, (void **) &pdu, + rmrMessageBuffer.sendMessage->payload, rmrMessageBuffer.sendMessage->len); + if (rval.code != RC_OK) { + mdclog_write(MDCLOG_ERR, "Error %d Decoding (unpack) setup response from E2MGR : %s", + rval.code, + message.message.enodbName); + return -1; + } + + int buff_size = RECEIVE_XAPP_BUFFER_SIZE; + auto er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu, + rmrMessageBuffer.sendMessage->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)buff_size) { + mdclog_write(MDCLOG_ERR, "Buffer of size %d is to small for %s, at %s line %d", + (int)rmrMessageBuffer.sendMessage->len, + asn_DEF_E2AP_PDU.name, + __func__, + __LINE__); + return -1; + } + rmrMessageBuffer.sendMessage->len = er.encoded; + return 0; + +} + /** * * @param pdu @@ -1412,41 +1566,37 @@ void asnInitiatingRequest(E2AP_PDU_t *pdu, 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]; - - 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, at %s line %d", - (int)setup_xml_buffer_size, - asn_DEF_E2AP_PDU.name, __func__, __LINE__); - break; - } - std::string xmlString(setup_xml_buffer_size, setup_xml_buffer_size + er.encoded); - vector RANfunctionsAdded_v; vector RANfunctionsModified_v; RANfunctionsAdded_v.clear(); RANfunctionsModified_v.clear(); - if (collectSetupAndServiceUpdate_RequestData(pdu, sctpMap, message, - RANfunctionsAdded_v, RANfunctionsModified_v) != 0) { + if (collectSetupRequestData(pdu, sctpMap, message, RANfunctionsAdded_v) != 0) { break; } - buildAndsendSetupRequest(message, rmrMessageBuffer, pdu, RANfunctionsAdded_v); + string messageName("E2setupRequest"); + string ieName("E2setupRequestIEs"); + message.message.messageType = RIC_E2_SETUP_REQ; + buildAndsendSetupRequest(message, rmrMessageBuffer, pdu, messageName, ieName, RANfunctionsAdded_v, RANfunctionsModified_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"); + vector RANfunctionsAdded_v; + vector RANfunctionsModified_v; + RANfunctionsAdded_v.clear(); + RANfunctionsModified_v.clear(); + if (collectServiceUpdate_RequestData(pdu, sctpMap, message, + RANfunctionsAdded_v, RANfunctionsModified_v) != 0) { + break; } + + string messageName("RICserviceUpdate"); + string ieName("RICserviceUpdateIEs"); + message.message.messageType = RIC_SERVICE_UPDATE; + buildAndsendSetupRequest(message, rmrMessageBuffer, pdu, messageName, ieName, RANfunctionsAdded_v, RANfunctionsModified_v); break; } case ProcedureCode_id_ErrorIndication: { @@ -1462,8 +1612,13 @@ void asnInitiatingRequest(E2AP_PDU_t *pdu, if (logLevel >= MDCLOG_DEBUG) { mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName); } - if (sendRequestToXapp(message, RIC_X2_RESET, rmrMessageBuffer) != 0) { - mdclog_write(MDCLOG_ERR, "RIC_X2_RESET message failed to send to xAPP"); + + if (XML_From_PER(message, rmrMessageBuffer) < 0) { + break; + } + + if (sendRequestToXapp(message, RIC_E2_RESET_REQ, rmrMessageBuffer) != 0) { + mdclog_write(MDCLOG_ERR, "RIC_E2_RESET_REQ message failed to send to xAPP"); } break; } @@ -1582,8 +1737,11 @@ void asnSuccsesfulMsg(E2AP_PDU_t *pdu, if (logLevel >= MDCLOG_DEBUG) { mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName); } - if (sendRequestToXapp(message, RIC_X2_RESET, rmrMessageBuffer) != 0) { - mdclog_write(MDCLOG_ERR, "RIC_X2_RESET message failed to send to xAPP"); + if (XML_From_PER(message, rmrMessageBuffer) < 0) { + break; + } + if (sendRequestToXapp(message, RIC_E2_RESET_RESP, rmrMessageBuffer) != 0) { + mdclog_write(MDCLOG_ERR, "RIC_E2_RESET_RESP message failed to send to xAPP"); } break; } @@ -1744,12 +1902,7 @@ void asnUnSuccsesfulMsg(E2AP_PDU_t *pdu, break; } case ProcedureCode_id_Reset: { - if (logLevel >= MDCLOG_DEBUG) { - mdclog_write(MDCLOG_DEBUG, "Got Reset %s", message.message.enodbName); - } - if (sendRequestToXapp(message, RIC_X2_RESET, rmrMessageBuffer) != 0) { - mdclog_write(MDCLOG_ERR, "RIC_X2_RESET message failed to send to xAPP"); - } + mdclog_write(MDCLOG_ERR, "Got Reset for %s, Protocol ERROR", message.message.enodbName); break; } case ProcedureCode_id_RICcontrol: { @@ -1898,7 +2051,10 @@ int sendRequestToXapp(ReportingMessages_t &message, return rc; } - +/** + * + * @param pSctpParams + */ void getRmrContext(sctp_params_t &pSctpParams) { pSctpParams.rmrCtx = nullptr; pSctpParams.rmrCtx = rmr_init(pSctpParams.rmrAddress, RECEIVE_XAPP_BUFFER_SIZE, RMRFL_NONE); @@ -1942,11 +2098,17 @@ void getRmrContext(sctp_params_t &pSctpParams) { } } +/** + * + * @param message + * @param rmrMessageBuffer + * @return + */ 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", + mdclog_write(MDCLOG_DEBUG, "got xml Format data from xApp 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, @@ -2093,16 +2255,22 @@ int receiveXappMessages(Sctp_Map_t *sctpMap, } break; } - case RIC_X2_RESET: { + case RIC_E2_RESET_REQ: { + if (PER_FromXML(message, rmrMessageBuffer) != 0) { + break; + } if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { - mdclog_write(MDCLOG_ERR, "Failed to send RIC_X2_RESET"); + mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_RESET"); return -6; } break; } - case RIC_X2_RESET_RESP: { + case RIC_E2_RESET_RESP: { + if (PER_FromXML(message, rmrMessageBuffer) != 0) { + break; + } if (sendDirectionalSctpMsg(rmrMessageBuffer, message, 0, sctpMap) != 0) { - mdclog_write(MDCLOG_ERR, "Failed to send RIC_X2_RESET_RESP"); + mdclog_write(MDCLOG_ERR, "Failed to send RIC_E2_RESET_RESP"); return -6; } break; @@ -2165,6 +2333,30 @@ int receiveXappMessages(Sctp_Map_t *sctpMap, break; } + case RIC_HEALTH_CHECK_REQ: { + // send message back + rmr_bytes2payload(rmrMessageBuffer.sendMessage, + (unsigned char *)"OK", + 2); + rmrMessageBuffer.sendMessage->mtype = RIC_HEALTH_CHECK_RESP; + rmrMessageBuffer.sendMessage->state = 0; + static unsigned char tx[32]; + auto txLen = snprintf((char *) tx, sizeof tx, "%15ld", transactionCounter++); + rmr_bytes2xact(rmrMessageBuffer.sendMessage, tx, txLen); + rmrMessageBuffer.sendMessage = rmr_send_msg(rmrMessageBuffer.rmrCtx, rmrMessageBuffer.sendMessage); + if (rmrMessageBuffer.sendMessage == nullptr) { + rmrMessageBuffer.sendMessage = rmr_alloc_msg(rmrMessageBuffer.rmrCtx, RECEIVE_XAPP_BUFFER_SIZE); + mdclog_write(MDCLOG_ERR, "Failed to send RIC_HEALTH_CHECK_RESP RMR message returned NULL"); + } else if (rmrMessageBuffer.sendMessage->state != 0) { + mdclog_write(MDCLOG_ERR, "Failed to send RIC_HEALTH_CHECK_RESP, on RMR state = %d ( %s)", + rmrMessageBuffer.sendMessage->state, translateRmrErrorMessages(rmrMessageBuffer.sendMessage->state).c_str()); + } else if (mdclog_level_get() >= MDCLOG_DEBUG) { + mdclog_write(MDCLOG_DEBUG, "Got RIC_HEALTH_CHECK_REQ Request send : OK"); + } + + break; + } + default: mdclog_write(MDCLOG_WARN, "Message Type : %d is not seported", rmrMessageBuffer.rcvMessage->mtype); message.message.asndata = rmrMessageBuffer.rcvMessage->payload; diff --git a/RIC-E2-TERMINATION/sctpThread.h b/RIC-E2-TERMINATION/sctpThread.h index 10c6d90..8b40784 100644 --- a/RIC-E2-TERMINATION/sctpThread.h +++ b/RIC-E2-TERMINATION/sctpThread.h @@ -83,10 +83,14 @@ #include "cxxopts.hpp" //#include "config-cpp/include/config-cpp/config-cpp.h" +#include +#include +#include +#include +using namespace prometheus; #include "mapWrapper.h" -#include "statCollector.h" #include "base64.h" @@ -106,8 +110,8 @@ namespace expr = boost::log::expressions; #define MAXEVENTS 128 -#define RECEIVE_SCTP_BUFFER_SIZE (128 * 1024) -#define RECEIVE_XAPP_BUFFER_SIZE RECEIVE_SCTP_BUFFER_SIZE +#define RECEIVE_SCTP_BUFFER_SIZE (256 * 1024) +#define RECEIVE_XAPP_BUFFER_SIZE RECEIVE_SCTP_BUFFER_SIZE typedef mapWrapper Sctp_Map_t; @@ -137,9 +141,25 @@ typedef struct sctp_params { string configFilePath {}; string configFileName {}; bool trace = true; + shared_ptr promteheusRegistry; + string prometheusPort {"8088"}; + Family *prometheusFamily; //shared_timed_mutex fence; // moved to mapWrapper } sctp_params_t; +// RAN to RIC +#define IN_INITI 0 //INITIATING +#define IN_SUCC 1 //SUCCESSFULL +#define IN_UN_SUCC 2 //UN-Successfull + +// RIC To RAN +#define OUT_INITI 3 //INITIATING +#define OUT_SUCC 4 //SUCCESSFULL +#define OUT_UN_SUCC 5 //UN-Successfull + +#define MSG_COUNTER 0 +#define BYTES_COUNTER 1 + typedef struct ConnectedCU { int fileDescriptor = 0; char hostName[NI_MAXHOST] {}; @@ -151,8 +171,10 @@ typedef struct ConnectedCU { bool isConnected = false; bool gotSetup = false; sctp_params_t *sctpParams = nullptr; + Counter *counters[6][2][ProcedureCode_id_RICsubscriptionDelete] {}; } ConnectedCU_t ; + #define MAX_RMR_BUFF_ARRY 32 typedef struct RmrMessagesBuffer { char ka_message[KA_MESSAGE_SIZE] {}; @@ -179,7 +201,6 @@ typedef struct ReportingMessages { long outLen = 0; unsigned char base64Data[RECEIVE_SCTP_BUFFER_SIZE * 2] {}; char buffer[RECEIVE_SCTP_BUFFER_SIZE * 8] {}; - StatCollector *statCollector = nullptr; } ReportingMessages_t; cxxopts::ParseResult parse(int argc, char *argv[], sctp_params_t &pSctpParams); diff --git a/RIC-E2-TERMINATION/statCollector.h b/RIC-E2-TERMINATION/statCollector.h deleted file mode 100644 index 3279585..0000000 --- a/RIC-E2-TERMINATION/statCollector.h +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright 2020 AT&T Intellectual Property - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// -// Created by adi ENZEL on 3/24/20. -// - -#ifndef E2_STATCOLLECTOR_H -#define E2_STATCOLLECTOR_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -//#include - -//using namespace tbb; - -typedef struct statResult { - std::string ranName; - uint32_t receivedMessages; - uint32_t sentMessages; -} statResult_t ; - -class StatCollector { - - static std::mutex singltonMutex; - static std::atomic obj; - -public: - static StatCollector* GetInstance() { - StatCollector* pStatCollector = obj.load(std::memory_order_acquire); - if (pStatCollector == nullptr) { - std::lock_guard lock(singltonMutex); - pStatCollector = obj.load(std::memory_order_relaxed); - if (pStatCollector == nullptr) { - pStatCollector = new StatCollector(); - obj.store(pStatCollector, std::memory_order_release); - } - } - return pStatCollector; - } - - void incSentMessage(const std::string &key) { - increment(sentMessages, key); - } - void incRecvMessage(const std::string &key) { - increment(recvMessages, key); - } - - std::vector &getCurrentStats() { - results.clear(); - - for (auto const &e : recvMessages) { - statResult_t result {}; - result.ranName = e.first; - result.receivedMessages = e.second.load(std::memory_order_acquire); - auto found = sentMessages.find(result.ranName); - if (found != sentMessages.end()) { - result.sentMessages = found->second.load(std::memory_order_acquire); - } else { - result.sentMessages = 0; - } - - results.emplace_back(result); - } - return results; - } - - StatCollector(const StatCollector&)= delete; - StatCollector& operator=(const StatCollector&)= delete; - -private: - //tbb::concurrent_unordered_map sentMessages; - std::unordered_map> sentMessages; - std::unordered_map> recvMessages; -// tbb::concurrent_unordered_map recvMessages; - std::vector results; - - -// StatCollector() = default; - StatCollector() { - sentMessages.clear(); - recvMessages.clear(); - } - ~StatCollector() = default; - - - void increment(std::unordered_map> &map, const std::string &key); - -}; - -void StatCollector::increment(std::unordered_map> &map, const std::string &key) { - if (map.empty()) { - map.emplace(std::piecewise_construct, - std::forward_as_tuple(key), - std::forward_as_tuple(1)); - return; - } - auto found = map.find(key); - if (found != map.end()) { //inc - map[key].fetch_add(1, std::memory_order_release); - //map[key]++; - } else { //add - //sentMessages.emplace(std::make_pair(std::string(key), std::atomic(0))); - map.emplace(std::piecewise_construct, - std::forward_as_tuple(key), - std::forward_as_tuple(1)); - } - -} - - -// must define this to allow StatCollector private variables to be known to compiler linker -std::mutex StatCollector::singltonMutex; -std::atomic StatCollector::obj; - - -void statColectorThread(void *runtime) { - bool *stop_loop = (bool *)runtime; - auto *statCollector = StatCollector::GetInstance(); - std::time_t tt = std::chrono::system_clock::to_time_t (std::chrono::system_clock::now()); - - struct std::tm * ptm = std::localtime(&tt); - std::cout << "Waiting for the next minute to begin...\n"; - ptm->tm_min = ptm->tm_min + (5 - ptm->tm_min % 5); - ptm->tm_sec=0; - - std::this_thread::sleep_until(std::chrono::system_clock::from_time_t(mktime(ptm))); - -// alligned to 5 minutes - while (true) { - if (*stop_loop) { - break; - } - for (auto const &e : statCollector->getCurrentStats()) { - if (mdclog_level_get() >= MDCLOG_INFO) { - mdclog_write(MDCLOG_INFO, "RAN : %s sent messages : %d recived messages : %d\n", - e.ranName.c_str(), e.sentMessages, e.receivedMessages); - } - } - std::this_thread::sleep_for(std::chrono::seconds(300)); - } -} -#endif //E2_STATCOLLECTOR_H -- 2.16.6