-void send_rest_control_request( string msg ) {
- CURL *curl = curl_easy_init();
- curl_easy_setopt( curl, CURLOPT_URL, ts_control_ep.c_str() );
- curl_easy_setopt( curl, CURLOPT_TIMEOUT, 10 );
- curl_easy_setopt( curl, CURLOPT_POST, 1L );
- // curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
-
- // response information
- long httpCode( 0 );
- unique_ptr<string> httpData( new string() );
-
- curl_easy_setopt( curl, CURLOPT_WRITEFUNCTION, handoff_reply_callback );
- curl_easy_setopt( curl, CURLOPT_WRITEDATA, httpData.get());
- curl_easy_setopt( curl, CURLOPT_POSTFIELDS, msg.c_str() );
-
- struct curl_slist *headers = NULL; // needs to free this after easy perform
- headers = curl_slist_append( headers, "Accept: application/json" );
- headers = curl_slist_append( headers, "Content-Type: application/json" );
- curl_easy_setopt( curl, CURLOPT_HTTPHEADER, headers );
+void send_rest_control_request( string ue_id, string serving_cell_id, string target_cell_id ) {
+ time_t now;
+ string str_now;
+ static unsigned int seq_number = 0; // static counter, not thread-safe
+
+ // building a handoff control message
+ now = time( nullptr );
+ str_now = ctime( &now );
+ str_now.pop_back(); // removing the \n character
+
+ seq_number++; // static counter, not thread-safe
+
+ rapidjson::StringBuffer s;
+ rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(s);
+ writer.StartObject();
+ writer.Key( "command" );
+ writer.String( "HandOff" );
+ writer.Key( "seqNo" );
+ writer.Int( seq_number );
+ writer.Key( "ue" );
+ writer.String( ue_id.c_str() );
+ writer.Key( "fromCell" );
+ writer.String( serving_cell_id.c_str() );
+ writer.Key( "toCell" );
+ writer.String( target_cell_id.c_str() );
+ writer.Key( "timestamp" );
+ writer.String( str_now.c_str() );
+ writer.Key( "reason" );
+ writer.String( "HandOff Control Request from TS xApp" );
+ writer.Key( "ttl" );
+ writer.Int( 10 );
+ writer.EndObject();
+ // creates a message like
+ /* {
+ "command": "HandOff",
+ "seqNo": 1,
+ "ue": "ueid-here",
+ "fromCell": "CID1",
+ "toCell": "CID3",
+ "timestamp": "Sat May 22 10:35:33 2021",
+ "reason": "HandOff Control Request from TS xApp",
+ "ttl": 10
+ } */
+
+ string msg = s.GetString();