X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fxapp.cc;h=175366113d867ca14f1f06c2899eef6fbf044eeb;hb=refs%2Fchanges%2F07%2F4907%2F2;hp=ca737e62a720e74890c7233177dc01049b4faded;hpb=433b7b2a72c174c75ce2c0c75b225fa0bb813d32;p=ric-app%2Fhw.git diff --git a/src/xapp.cc b/src/xapp.cc index ca737e6..1753661 100644 --- a/src/xapp.cc +++ b/src/xapp.cc @@ -1,7 +1,7 @@ /* ================================================================================== - Copyright (c) 2018-2019 AT&T Intellectual Property. + Copyright (c) 2019-2020 AT&T Intellectual Property. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -19,59 +19,91 @@ /* * xapp.cc * - * Created on: Mar, 2020 - * Author: Shraboni Jana + * Mar, 2020 (Shraboni Jana) */ #include "xapp.hpp" +#define BUFFER_SIZE 1024 -Xapp::Xapp(XappSettings &config, XappRmr &rmr){ - rmr_ref = &rmr; - config_ref = &config; - xapp_mutex = NULL; - return; -} + Xapp::Xapp(XappSettings &config, XappRmr &rmr){ + rmr_ref = &rmr; + config_ref = &config; + xapp_mutex = NULL; + subhandler_ref = NULL; + return; + } -Xapp::Xapp(XappSettings &config, XappRmr &rmr, XappSDL &sdl){ - rmr_ref = &rmr; - config_ref = &config; - sdl_ref = &sdl; - //sdl_ref.insert_data(); - xapp_mutex = NULL; - - return; -} Xapp::~Xapp(void){ //Joining the threads int threadcnt = xapp_rcv_thread.size(); - for(int i=0; i~mutex(); + delete xapp_mutex; } - delete xapp_mutex; }; -void Xapp::startup() { - //send subscriptions and read A1 policies. + +//Stop the xapp. Note- To be run only from unit test scripts. +void Xapp::stop(void){ + // Get the mutex lock + std::lock_guard guard(*xapp_mutex); + rmr_ref->set_listen(false); + rmr_ref->~XappRmr(); + + //Detaching the threads....not sure if this is the right way to stop the receiver threads. + //Hence function should be called only in Unit Tests + int threadcnt = xapp_rcv_thread.size(); + for(int i=0; iset_listen(true); + if(xapp_mutex == NULL){ + xapp_mutex = new std::mutex(); + } + std::lock_guard guard(*xapp_mutex); -void Xapp::start_xapp_receiver(){ - //start a receiver thread. Can be multiple receiver threads for more than 1 listening port. + for(int j=0; j < _callbacks.size(); j++){ + std::thread th_recv([&](){ rmr_ref->xapp_rmr_receive(std::move(_callbacks[j]), rmr_ref);}); + xapp_rcv_thread.push_back(std::move(th_recv)); + } - xapp_mutex = new std::mutex(); + return; +} +//Starting a seperate single receiver +void Xapp::start_xapp_receiver(XappMsgHandler& mp_handler){ + //start a receiver thread. Can be multiple receiver threads for more than 1 listening port. + rmr_ref->set_listen(true); + if(xapp_mutex == NULL){ + xapp_mutex = new std::mutex(); + } - std::vector> message_procs; mdclog_write(MDCLOG_INFO,"Receiver Thread file= %s, line=%d",__FILE__,__LINE__); - std::unique_ptr mp_handler = std::make_unique(); std::lock_guard guard(*xapp_mutex); - std::thread th_recv([&](){ rmr_ref->xapp_rmr_receive(std::move(*mp_handler.get()), rmr_ref);}); + std::thread th_recv([&](){ rmr_ref->xapp_rmr_receive(std::move(mp_handler), rmr_ref);}); xapp_rcv_thread.push_back(std::move(th_recv)); - - return; @@ -85,40 +117,83 @@ void Xapp::shutdown(){ void Xapp::startup_subscribe_requests(void ){ + + bool res; size_t data_size = ASN_BUFF_MAX_SIZE; unsigned char data[data_size]; + unsigned char meid[RMR_MAX_MEID]; + std::string xapp_id = config_ref->operator [](XappSettings::SettingName::XAPP_ID); + + mdclog_write(MDCLOG_INFO,"Preparing to send subscription in file= %s, line=%d",__FILE__,__LINE__); + + std::string sub_id = "1"; - std::vector gNodeBs; - gNodeBs.push_back("GNB1001"); //this line should come from RNIB + auto gnblist = get_rnib_gnblist(); + int sz = gnblist.size(); + if(sz <= 0) + mdclog_write(MDCLOG_INFO,"Subscriptions cannot be sent as GNBList in RNIB is NULL"); + + for(int i = 0; i actionObj; + actionObj.add(E2APAction::ActionIEs().set_ricActionID(1).set_ricActionType(1).set_ricActionDefinition(e2sm_actdefn1)); + + E2APSubscriptionRequest requestObj(E2APSubscriptionRequest::SubscriptionRequestIEs().set_ranFunctionID(1).set_ricInstanceID(1).set_ricRequestorID(3).set_ricAction_ToBeSetup_List(actionObj).set_ricEventTriggerDefinition(eventObj)); + + bool res = requestObj.encode(&buf[0], &buf_size); + if(!res) + mdclog_write(MDCLOG_ERR,"SubscriptionRequest ENCODING Error: %s",requestObj.get_error().c_str()); + else + mdclog_write(MDCLOG_INFO,"SubscriptionRequest ENCODING SUCESS"); - for(auto &it: gNodeBs){ - int attempt = 0; - XappMsgHandler msg; - /* bool res_encode = msg.encode_subscription_request(data, &data_size); - if(!res_encode) exit(0);*/ - char *strMsg = "HelloWorld\0"; - strncpy((char *)data,strMsg,strlen(strMsg)); - data_size = sizeof(data); xapp_rmr_header rmr_header; - rmr_header.message_type = RIC_SUB_RESP; - rmr_header.payload_length = data_size; - while(1){ + rmr_header.message_type = RIC_SUB_REQ; + rmr_header.payload_length = buf_size; //data_size + + strcpy((char*)rmr_header.sid,sub_id.c_str()); + strcpy((char*)rmr_header.meid,gnblist[i].c_str()); + + mdclog_write(MDCLOG_INFO,"Sending subscription in file= %s, line=%d for MEID %s",__FILE__,__LINE__, meid); + auto transmitter = std::bind(&XappRmr::xapp_rmr_send,rmr_ref, &rmr_header, (void*)buf );//(void*)data); - auto transmitter = std::bind(&XappRmr::xapp_rmr_send,rmr_ref, &rmr_header, (void*)data); - transmitter(); //this will go to subscription manager. - break; + int result = subhandler_ref->manage_subscription_request(gnblist[i], transmitter); + if(result==SUBSCR_SUCCESS){ + mdclog_write(MDCLOG_INFO,"Subscription SUCCESSFUL in file= %s, line=%d for MEID %s",__FILE__,__LINE__, meid); + } + else { + mdclog_write(MDCLOG_ERR,"Subscription FAILED in file= %s, line=%d for MEID %s",__FILE__,__LINE__, meid); } } + } void Xapp::startup_get_policies(void){ int policy_id = HELLOWORLD_POLICY_ID; - std::string policy_query = "{\"policy_id\":" + std::to_string(policy_id) + "}"; + std::string policy_query = "{\"policy_type_id\":" + std::to_string(policy_id) + "}"; unsigned char * message = (unsigned char *)calloc(policy_query.length(), sizeof(unsigned char)); memcpy(message, policy_query.c_str(), policy_query.length()); xapp_rmr_header header; @@ -129,25 +204,58 @@ void Xapp::startup_get_policies(void){ free(message); } -void Xapp::sdl_data(void) { - sdl_ref->insert_data(); -} -/*void Xapp::rnib_data(void) { - printf("Using rnibreader lib from C:\n"); - open(); - void *result = getListGnbIds(); - if(result == NULL){ +void Xapp::set_rnib_gnblist(void) { - printf("ERROR: no data from getListGnbIds\n"); + openSdl(); + + void *result = getListGnbIds(); + if(strlen((char*)result) < 1){ + mdclog_write(MDCLOG_ERR, "ERROR: no data from getListGnbIds\n"); return; } - printf("getListGnbIds response: %s\n", (char *)result); - close(); - free(result); + + mdclog_write(MDCLOG_INFO, "GNB List in R-NIB %s\n", (char*)result); + + + Document doc; + ParseResult parseJson = doc.Parse((char*)result); + if (!parseJson) { + std::cerr << "JSON parse error: %s (%u)", GetParseErrorFunc(parseJson.Code()); + return; + } + + if(!doc.HasMember("gnb_list")){ + mdclog_write(MDCLOG_INFO, "JSON Has No GNB List Object"); + return; + } + assert(doc.HasMember("gnb_list")); + + const Value& gnblist = doc["gnb_list"]; + if (gnblist.IsNull()) + return; + + if(!gnblist.IsArray()){ + mdclog_write(MDCLOG_INFO, "GNB List is not an array"); + return; + } + + + assert(gnblist.IsArray()); + for (SizeType i = 0; i < gnblist.Size(); i++) // Uses SizeType instead of size_t + { + assert(gnblist[i].IsObject()); + const Value& gnbobj = gnblist[i]; + assert(gnbobj.HasMember("inventory_name")); + assert(gnbobj["inventory_name"].IsString()); + std::string name = gnbobj["inventory_name"].GetString(); + rnib_gnblist.push_back(name); + + } + closeSdl(); return; -}*/ +}