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 the AD xApp sending an anomaly dectection message to
24 the TS xApp. It sends one message and exits.
27 Author: Alexandre Huff
36 #include <rmr/RIC_message_types.h>
37 #include "ricxfcpp/xapp.hpp"
44 void ts_callback( Message& mbuf, int mtype, int subid, int len, Msg_component payload, void* data ) {
45 string json ((char *)payload.get(), len);
47 cout << "[AD] TS Callback got a message, type=" << mtype << ", length=" << len << "\n";
48 cout << "[AD] Payload is " << json << endl;
50 // we only send one message, so we expect to receive only one as well
54 // this thread just sends out one anomaly message to the TS xApp
56 std::unique_ptr<Message> msg;
57 Msg_component payload;
61 cout << "[AD] In Anomaly Detection ad_loop()\n";
62 sleep( 1 ); // just wait receiver thread starting up
64 msg = xfw->Alloc_msg(2048);
65 size = msg->Get_available_size();
67 cout << "[ERROR] Message returned does not have enough size: " << size << " < 2048" << endl;
71 // the message we are sending
72 const char *ad_msg = "[{\"du-id\": 1010, \"ue-id\": \"Train passenger 2\", \"measTimeStampRf\": 1620835470108, \"Degradation\": \"RSRP RSSINR\"}]";
74 payload = msg->Get_payload();
75 snprintf( (char *) payload.get(), 2048, "%s", ad_msg );
77 plen = strlen( (char *) payload.get() );
78 cout << "[AD] Sending a message to TS, length: " << plen << "\n";
79 cout << "[AD] Message body " << payload.get() << endl;
81 // payload updated in place, nothing to copy from, so payload parm is nil
82 if ( ! msg->Send_msg( TS_ANOMALY_UPDATE, Message::NO_SUBID, plen, nullptr ) ) // msg type 30003
83 cout << "[ERROR] Unable to send a message to TS xApp, state: " << msg->Get_state() << endl;
86 int main(int argc, char const *argv[]) {
89 char* port = (char *) "4570";
91 cout << "[AD] Listening on port " << port << endl;
92 xfw = std::unique_ptr<Xapp>( new Xapp( port, true ) );
94 xfw->Add_msg_cb( TS_ANOMALY_ACK, ts_callback, NULL ); /*Register a callback function for msg type 30004*/
96 std::thread ad_thread;
97 ad_thread = std::thread(&ad_loop);