3 ==================================================================================
4 Copyright (c) 2021 AT&T Intellectual Property.
5 Copyright (c) 2021 Alexandre Huff.
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18 ==================================================================================
23 Abstract: Simulates both, the QP Driver and QP xApp for testing the behavior
27 Author: Alexandre Huff
39 #include <rapidjson/document.h>
40 #include <rapidjson/writer.h>
41 #include <rapidjson/stringbuffer.h>
42 #include <rapidjson/schema.h>
43 #include <rapidjson/reader.h>
45 #include <rmr/RIC_message_types.h>
46 #include "ricxfcpp/xapp.hpp"
50 using namespace rapidjson;
55 void prediction_callback( Message& mbuf, int mtype, int subid, int len, Msg_component payload, void* data ) {
56 string json ((char *) payload.get(), len);
58 cout << "[QP] Prediction Callback got a message, type=" << mtype << ", length=" << len << "\n";
59 cout << "[QP] Payload is " << json << endl;
62 document.Parse(json.c_str());
64 const Value& uePred = document["UEPredictionSet"];
65 if ( uePred.Size() > 0 ) {
66 string ueid = uePred[0].GetString();
67 // we want to create "{"ueid-user1": {"CID1": [10, 20], "CID2": [30, 40], "CID3": [50, 60]}}";
68 string body = "{\"" + ueid + "\": {";
69 for ( int i = 1; i <= 3; i++ ) {
70 int down = rand() % 100;
71 int up = rand() % 100;
73 body += "\"CID" + to_string(i) + "\": [" + to_string(down) + ", " + to_string(up) + "], ";
75 body += "\"CID" + to_string(i) + "\": [" + to_string(down) + ", " + to_string(up) + "]}}";
79 int len = body.size();
81 cout << "[QP] Sending a message to TS, length=" << len << "\n";
82 cout << "[QP] Message body " << body << endl;
84 // payload updated in place, nothing to copy from, so payload parm is nil
85 if ( ! mbuf.Send_response( TS_QOE_PREDICTION, Message::NO_SUBID, len, (unsigned char *) body.c_str() ) ) // msg type 30002
86 cout << "[ERROR] unable to send a message to TS xApp, state: " << mbuf.Get_state() << endl;
90 int main(int argc, char const *argv[]) {
93 srand( (unsigned int) time(0) );
95 char* port = (char *) "4580";
97 cout << "[QP] listening on port " << port << endl;
98 xfw = std::unique_ptr<Xapp>( new Xapp( port, true ) );
100 xfw->Add_msg_cb( TS_UE_LIST, prediction_callback, NULL ); /*Register a callback function for msg type 30000*/
102 xfw->Run( nthreads );