Fix extra nil termination char sent in RMR payload 29/6429/2 1.1.1
authorAlexandre Huff <alexandrehuff@utfpr.edu.br>
Thu, 24 Jun 2021 16:22:08 +0000 (13:22 -0300)
committerAlexandre Huff <alexandrehuff@utfpr.edu.br>
Thu, 24 Jun 2021 16:41:15 +0000 (13:41 -0300)
Issue-ID: RICAPP-172

Change-Id: I5707ff9309a711ccb69073a5f09aaa47fb46bb04
Signed-off-by: Alexandre Huff <alexandrehuff@utfpr.edu.br>
CMakeLists.txt
container-tag.yaml
docs/rel-notes.rst
src/ts_xapp/ts_xapp.cpp
test/app/ad_xapp.cpp
test/app/qp_xapp.cpp
xapp-descriptor/config.json

index 7767bfd..d11c6af 100644 (file)
@@ -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" )
index 94914f5..5963b56 100644 (file)
@@ -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'
index 270a4e3..8f5e27b 100644 (file)
@@ -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
index bf146ec..a198c32 100644 (file)
@@ -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<string> 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<string> 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
index bb142d2..cc62c31 100644 (file)
@@ -42,8 +42,10 @@ using namespace xapp;
 unique_ptr<Xapp> 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;
 
index c1a7502..242e568 100644 (file)
@@ -53,15 +53,13 @@ unique_ptr<Xapp> 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;
index d410e71..10d10fc 100644 (file)
@@ -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"
                 }
             }
         ],