2 ==================================================================================
4 Copyright (c) 2018-2019 AT&T Intellectual Property.
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
22 * Created on: Mar, 2020
23 * Author: Shraboni Jana
28 Xapp::Xapp(XappSettings &config, XappRmr &rmr){
38 int threadcnt = xapp_rcv_thread.size();
39 for(int i=0; i<threadcnt; i++){
40 if(xapp_rcv_thread[i].joinable())
41 xapp_rcv_thread[i].join();
50 //get rnib information
55 void Xapp::startup() {
56 //send subscriptions and read A1 policies.
57 startup_subscribe_requests();
58 //startup_get_policies();
62 void Xapp::start_xapp_receiver(XappMsgHandler& mp_handler){
63 //start a receiver thread. Can be multiple receiver threads for more than 1 listening port.
65 xapp_mutex = new std::mutex();
67 mdclog_write(MDCLOG_INFO,"Receiver Thread file= %s, line=%d",__FILE__,__LINE__);
68 //std::unique_ptr<XappMsgHandler> mp_handler = std::make_unique<XappMsgHandler>();
69 //auto mp_handler = _callbacks[0];
70 std::lock_guard<std::mutex> guard(*xapp_mutex);
71 std::thread th_recv([&](){ rmr_ref->xapp_rmr_receive(std::move(mp_handler), rmr_ref);});
73 xapp_rcv_thread.push_back(std::move(th_recv));
81 void Xapp::shutdown(){
88 void Xapp::startup_subscribe_requests(void ){
89 size_t data_size = ASN_BUFF_MAX_SIZE;
90 unsigned char data[data_size];
92 for(auto &it: rnib_gnblist){
96 /* bool res_encode = msg.encode_subscription_request(data, &data_size);
97 if(!res_encode) exit(0);*/
98 char *strMsg = "HelloWorld\0";
99 strncpy((char *)data,strMsg,strlen(strMsg));
100 data_size = sizeof(data);
102 xapp_rmr_header rmr_header;
103 rmr_header.message_type = RIC_SUB_RESP;
104 rmr_header.payload_length = data_size;
107 auto transmitter = std::bind(&XappRmr::xapp_rmr_send,rmr_ref, &rmr_header, (void*)data);
108 transmitter(); //this will go to subscription manager.
114 void Xapp::startup_get_policies(void){
116 int policy_id = HELLOWORLD_POLICY_ID;
118 std::string policy_query = "{\"policy_id\":" + std::to_string(policy_id) + "}";
119 unsigned char * message = (unsigned char *)calloc(policy_query.length(), sizeof(unsigned char));
120 memcpy(message, policy_query.c_str(), policy_query.length());
121 xapp_rmr_header header;
122 header.payload_length = policy_query.length();
123 header.message_type = A1_POLICY_QUERY;
124 mdclog_write(MDCLOG_INFO, "Sending request for policy id %d\n", policy_id);
125 rmr_ref->xapp_rmr_send(&header, (void *)message);
130 void Xapp::set_rnib_gnblist(void) {
133 void *result = getListGnbIds();
135 mdclog_write(MDCLOG_ERR, "ERROR: no data from getListGnbIds\n");
139 mdclog_write(MDCLOG_INFO, "GNB List in R-NIB %s\n", (char*)result);
142 doc.Parse((char*)result);
143 assert(doc.HasMember("gnb_list"));
144 const Value& gnblist = doc["gnb_list"];
145 assert(gnblist.IsArray());
146 for (SizeType i = 0; i < gnblist.Size(); i++) // Uses SizeType instead of size_t
148 assert(gnblist[i].IsObject());
149 const Value& gnbobj = gnblist[i];
150 assert(gnbobj.HasMember("inventory_name"));
151 assert(gnbobj["inventory_name"].IsString());
152 rnib_gnblist.push_back(gnbobj["inventory_name"].GetString());