From c6e27b05b6fdf906f2b81e3cb30cad123c40bcb8 Mon Sep 17 00:00:00 2001 From: Alexandre Huff Date: Thu, 24 Jun 2021 13:22:08 -0300 Subject: [PATCH] Fix extra nil termination char sent in RMR payload Issue-ID: RICAPP-172 Change-Id: I5707ff9309a711ccb69073a5f09aaa47fb46bb04 Signed-off-by: Alexandre Huff --- CMakeLists.txt | 2 +- container-tag.yaml | 2 +- docs/rel-notes.rst | 4 ++++ src/ts_xapp/ts_xapp.cpp | 33 +++++++++++++-------------------- test/app/ad_xapp.cpp | 10 ++++------ test/app/qp_xapp.cpp | 18 +++++++----------- xapp-descriptor/config.json | 2 +- 7 files changed, 31 insertions(+), 40 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7767bfd..d11c6af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,7 @@ cmake_minimum_required( VERSION 3.14 ) set( major_version "1" ) # until CI supports auto tagging; must hard set set( minor_version "1" ) -set( patch_level "0" ) +set( patch_level "1" ) set( install_root "${CMAKE_INSTALL_PREFIX}" ) set( install_inc "/usr/local/include" ) diff --git a/container-tag.yaml b/container-tag.yaml index 94914f5..5963b56 100644 --- a/container-tag.yaml +++ b/container-tag.yaml @@ -1,3 +1,3 @@ # this is used by CI jobs to apply a tag when it builds the image --- -tag: '1.1.0' +tag: '1.1.1' diff --git a/docs/rel-notes.rst b/docs/rel-notes.rst index 270a4e3..8f5e27b 100644 --- a/docs/rel-notes.rst +++ b/docs/rel-notes.rst @@ -9,6 +9,10 @@ Traffic Steering xAPP ===================== +2021 June 24 Version 1.1.1 +-------------------------- + Fixes the extra nil character sent in RMR payload and other potential bugs + 2021 May 28 Version 1.1.0 ------------------------- Changes to integrate with the traffic steering use case for Release D diff --git a/src/ts_xapp/ts_xapp.cpp b/src/ts_xapp/ts_xapp.cpp index bf146ec..a198c32 100644 --- a/src/ts_xapp/ts_xapp.cpp +++ b/src/ts_xapp/ts_xapp.cpp @@ -363,20 +363,19 @@ void policy_callback( Message& mbuf, int mtype, int subid, int len, Msg_componen int response_to = 0; // max timeout wating for a response int rmtype; // received message type - fprintf(stderr, "[INFO] Policy Callback got a message, type=%d, length=%d\n", mtype, len); + string arg ((const char*)payload.get(), len); // RMR payload might not have a nil terminanted char - const char *arg = (const char*)payload.get(); - - fprintf(stderr, "[INFO] Payload is %s\n", arg); + cout << "[INFO] Policy Callback got a message, type=" << mtype << ", length="<< len << "\n"; + cout << "[INFO] Payload is " << arg << endl; PolicyHandler handler; Reader reader; - StringStream ss(arg); + StringStream ss(arg.c_str()); reader.Parse(ss,handler); //Set the threshold value if (handler.found_threshold) { - fprintf(stderr, "[INFO] Setting RSRP Threshold to A1-P value: %d\n", handler.threshold); + cout << "[INFO] Setting RSRP Threshold to A1-P value: " << handler.threshold << endl; rsrp_threshold = handler.threshold; } @@ -459,15 +458,15 @@ void prediction_callback( Message& mbuf, int mtype, int subid, int len, Msg_comp int rmtype; // received message type int delay = 1000000; // mu-sec delay; default 1s + string json ((char *)payload.get(), len); // RMR payload might not have a nil terminanted char + cout << "[INFO] Prediction Callback got a message, type=" << mtype << ", length=" << len << "\n"; - cout << "[INFO] Payload is " << payload.get() << endl; + cout << "[INFO] Payload is " << json << endl; - const char* arg = (const char*)payload.get(); PredictionHandler handler; - try { Reader reader; - StringStream ss(arg); + StringStream ss(json.c_str()); reader.Parse(ss,handler); } catch (...) { cout << "[ERROR] Got an exception on stringstream read parse\n"; @@ -584,16 +583,10 @@ void send_prediction_request( vector ues_to_predict ) { string message_body = "{\"UEPredictionSet\": " + ues_list + "}"; - const char *body = message_body.c_str(); - send_payload = msg->Get_payload(); // direct access to payload - snprintf( (char *) send_payload.get(), 2048, "%s", body ); + snprintf( (char *) send_payload.get(), 2048, "%s", message_body.c_str() ); - /* - we are sending a string, so we have to include the nil byte in the RMR message - to keep things simple in the receiver side - */ - plen = strlen( (char *) send_payload.get() ) + 1; + plen = strlen( (char *)send_payload.get() ); cout << "[INFO] Prediction Request length=" << plen << ", payload=" << send_payload.get() << endl; @@ -609,14 +602,14 @@ void send_prediction_request( vector ues_to_predict ) { * sends a prediction request to the QP Driver xApp. */ void ad_callback( Message& mbuf, int mtype, int subid, int len, Msg_component payload, void* data ) { - const char *json = (const char *) payload.get(); + string json ((char *)payload.get(), len); // RMR payload might not have a nil terminanted char cout << "[INFO] AD Callback got a message, type=" << mtype << ", length=" << len << "\n"; cout << "[INFO] Payload is " << json << "\n"; AnomalyHandler handler; Reader reader; - StringStream ss(json); + StringStream ss(json.c_str()); reader.Parse(ss,handler); // just sending ACK to the AD xApp diff --git a/test/app/ad_xapp.cpp b/test/app/ad_xapp.cpp index bb142d2..cc62c31 100644 --- a/test/app/ad_xapp.cpp +++ b/test/app/ad_xapp.cpp @@ -42,8 +42,10 @@ using namespace xapp; unique_ptr xfw; void ts_callback( Message& mbuf, int mtype, int subid, int len, Msg_component payload, void* data ) { + string json ((char *)payload.get(), len); + cout << "[AD] TS Callback got a message, type=" << mtype << ", length=" << len << "\n"; - cout << "[AD] Payload is " << payload.get() << endl; + cout << "[AD] Payload is " << json << endl; // we only send one message, so we expect to receive only one as well xfw->Stop(); @@ -72,11 +74,7 @@ void ad_loop() { payload = msg->Get_payload(); snprintf( (char *) payload.get(), 2048, "%s", ad_msg ); - /* - we are sending a string, so we have to include the nil byte to send with RMR and keep - things simple in the receiver side - */ - plen = strlen( (char *) payload.get() ) + 1; + plen = strlen( (char *) payload.get() ); cout << "[AD] Sending a message to TS, length: " << plen << "\n"; cout << "[AD] Message body " << payload.get() << endl; diff --git a/test/app/qp_xapp.cpp b/test/app/qp_xapp.cpp index c1a7502..242e568 100644 --- a/test/app/qp_xapp.cpp +++ b/test/app/qp_xapp.cpp @@ -53,15 +53,13 @@ unique_ptr xfw; void prediction_callback( Message& mbuf, int mtype, int subid, int len, Msg_component payload, void* data ) { - cout << "[QP] Prediction Callback got a message, type=" << mtype << ", length=" << len << "\n"; - cout << "[QP] Payload is " << payload.get() << endl; + string json ((char *) payload.get(), len); - int randomNumber; - srand( (unsigned int) time(0) ); + cout << "[QP] Prediction Callback got a message, type=" << mtype << ", length=" << len << "\n"; + cout << "[QP] Payload is " << json << endl; - const char *json = (const char *) payload.get(); Document document; - document.Parse(json); + document.Parse(json.c_str()); const Value& uePred = document["UEPredictionSet"]; if ( uePred.Size() > 0 ) { @@ -78,11 +76,7 @@ void prediction_callback( Message& mbuf, int mtype, int subid, int len, Msg_comp } } - /* - we are sending a string, so we have to include the nil byte to send with RMR and keep - things simple in the receiver side - */ - int len = body.size() + 1; + int len = body.size(); cout << "[QP] Sending a message to TS, length=" << len << "\n"; cout << "[QP] Message body " << body << endl; @@ -96,6 +90,8 @@ void prediction_callback( Message& mbuf, int mtype, int subid, int len, Msg_comp int main(int argc, char const *argv[]) { int nthreads = 1; + srand( (unsigned int) time(0) ); + char* port = (char *) "4580"; cout << "[QP] listening on port " << port << endl; diff --git a/xapp-descriptor/config.json b/xapp-descriptor/config.json index d410e71..10d10fc 100644 --- a/xapp-descriptor/config.json +++ b/xapp-descriptor/config.json @@ -7,7 +7,7 @@ "image": { "registry": "nexus3.o-ran-sc.org:10002", "name": "o-ran-sc/ric-app-ts", - "tag": "1.1.0" + "tag": "1.1.1" } } ], -- 2.16.6