From eb27c05c05b5042d115480c40cffa16e7d473d80 Mon Sep 17 00:00:00 2001 From: sandeepindia Date: Wed, 4 May 2022 18:42:29 +0530 Subject: [PATCH] ISSUE ID:- (RICAPP-176). Added the functionality of REST based subscription request and REST based subscription delete request Signed-off-by: sandeepindia Change-Id: I97a07fb95cacff702d0b7f9deeb847a113e07d83 --- Bouncer/Dockerfile | 22 +- Bouncer/init/config-file.json | 22 +- Bouncer/src/Makefile | 2 +- Bouncer/src/b_xapp_main.cc | 95 +++++++- .../xapp-asn/e2ap/subscription_delete_request.cc | 45 ++-- Bouncer/src/xapp-asn/e2ap/subscription_request.cc | 1 + Bouncer/src/xapp-mgmt/msgs_proc.cc | 178 +++++++++------ Bouncer/src/xapp-mgmt/subs_mgmt.cc | 45 ++-- Bouncer/src/xapp-mgmt/subs_mgmt.hpp | 53 ++++- Bouncer/src/xapp.cc | 249 ++++++++++++++++++++- Bouncer/src/xapp.hpp | 2 +- 11 files changed, 584 insertions(+), 130 deletions(-) diff --git a/Bouncer/Dockerfile b/Bouncer/Dockerfile index 39f9319..0205975 100644 --- a/Bouncer/Dockerfile +++ b/Bouncer/Dockerfile @@ -75,6 +75,10 @@ RUN apt-get install -y libboost-all-dev RUN apt-get install -y libhiredis-dev #RUN apt-get install -y valgrind +RUN mkdir /usr/local/include/nlohmann +RUN git clone https://github.com/azadkuh/nlohmann_json_release.git +RUN cp nlohmann_json_release/json.hpp /usr/local/include/nlohmann + RUN git clone https://gerrit.o-ran-sc.org/r/ric-plt/dbaas RUN cd dbaas/redismodule && \ ./autogen.sh && \ @@ -103,6 +107,20 @@ RUN git clone https://github.com/Tencent/rapidjson && \ cd ${STAGE_DIR} && \ rm -rf rapidjson +WORKDIR ${STAGE_DIR} +## Install CPPRESTSDK + +RUN apt-get install -y libcpprest-dev +RUN apt-get install -y g++ git libboost-atomic-dev libboost-thread-dev libboost-system-dev libboost-date-time-dev libboost-regex-dev libboost-filesystem-dev libboost-random-dev libboost-chrono-dev libboost-serialization-dev libwebsocketpp-dev openssl libssl-dev ninja-build zlib1g-dev +RUN git clone https://github.com/Microsoft/cpprestsdk.git casablanca && \ + cd casablanca && \ + mkdir build && \ + cd build && \ + cmake -G Ninja .. -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=OFF -DBUILD_SAMPLES=OFF -DCMAKE_INSTALL_PREFIX=/usr/local .. && \ + ninja && \ + ninja install && \ + cd ${STAGE_DIR} + #rm -rf casablanca ##----------------------------------- # Now install the program #------------------------------------ @@ -135,10 +153,12 @@ COPY --from=ricbuild /usr/local/libexec/redismodule/libredis* /usr/local/libexec RUN dpkg -i /tmp/*.deb RUN apt-get update && \ apt-get install -y libcurl3 python3 && \ - apt-get install -y libboost-all-dev cpputest libhiredis-dev valgrind && \ + apt-get install -y libboost-all-dev cpputest libcpprest-dev libhiredis-dev valgrind && \ apt-get clean COPY --from=ricbuild /etc/xapp/* /etc/xapp/ COPY --from=ricbuild /usr/local/bin/b_xapp_main /usr/local/bin/b_xapp_main +COPY --from=ricbuild /usr/local/lib/libcpprest.so* /usr/local/bin/ +COPY --from=ricbuild /usr/local/lib/libcpprest.so* /usr/local/lib/ COPY --from=ricbuild /usr/local/include/rnib/*.h /usr/local/include/rnib/ COPY --from=ricbuild /usr/local/include/rnib/rnibreader.a /usr/local/include/rnib/ diff --git a/Bouncer/init/config-file.json b/Bouncer/init/config-file.json index 508e064..958136e 100644 --- a/Bouncer/init/config-file.json +++ b/Bouncer/init/config-file.json @@ -13,13 +13,19 @@ ], "messaging": { "ports": [ + { + "name": "http", + "container": "bouncer-xapp", + "port": 8080, + "description": "http service" + }, { "name": "rmr-data", "container": "bouncer-xapp", "port": 4560, - - "rxMessages": ["RIC_SUB_RESP", "RIC_INDICATION"], - "txMessages": ["RIC_SUB_REQ"], + + "rxMessages": ["RIC_SUB_RESP", "RIC_INDICATION","RIC_SUB_DEL_RESP"], + "txMessages": ["RIC_SUB_REQ","RIC_SUB_DEL_REQ"], "policies": [1], "description": "rmr receive data port for Bouncer xApp" }, @@ -35,8 +41,12 @@ "protPort": "tcp:4560", "maxSize": 2072, "numWorkers": 1, - "txMessages": ["RIC_SUB_REQ"], - "rxMessages": ["RIC_SUB_RESP", "RIC_INDICATION"], - "policies": [1] + "txMessages": ["RIC_SUB_REQ","RIC_SUB_DEL_REQ"], + "rxMessages": ["RIC_SUB_RESP", "RIC_INDICATION","RIC_SUB_DEL_RESP"], + "policies": [1] + }, + "http":{ + "protPort": "tcp:8080" + } } diff --git a/Bouncer/src/Makefile b/Bouncer/src/Makefile index 808bafe..f6c3946 100644 --- a/Bouncer/src/Makefile +++ b/Bouncer/src/Makefile @@ -32,7 +32,7 @@ E2SMFLAGS = -I$(E2SMSRC) ########libs -LIBS= -lsdl -lrmr_si -lpthread -lm $(LOG_LIBS) $(CURL_LIBS) $(RNIB_LIBS) +LIBS= -lsdl -lrmr_si -lpthread -lm -lboost_system -lcrypto -lssl -lcpprest $(LOG_LIBS) $(CURL_LIBS) $(RNIB_LIBS) COV_FLAGS= -fprofile-arcs -ftest-coverage ####### diff --git a/Bouncer/src/b_xapp_main.cc b/Bouncer/src/b_xapp_main.cc index 42d2d3e..0492e39 100644 --- a/Bouncer/src/b_xapp_main.cc +++ b/Bouncer/src/b_xapp_main.cc @@ -17,6 +17,95 @@ */ #include "xapp.hpp" +#include +#include +#include +using namespace web; +using namespace web::http; +using namespace web::http::experimental::listener; +using namespace utility; +std::vectorSubscriptionIds; +#define TRACE(msg) wcout << msg + + +void display_json( + json::value const & jvalue) +{ + cout<<"\ndisplaying REST Notification\n"; + wcout << jvalue.serialize().c_str() << endl; +} + + +void handle_request(http_request request) +{ +auto answer = json::value::object(); +cout<<"\nPrinting POST request content\n"; +cout< task) { + try + { + answer = task.get(); + display_json(answer); + } + catch (http_exception const & e) + { + cout<<"\ninside catch block"; + wcout << e.what() << endl; + } + + }) + .wait(); + + request.reply(status_codes::OK, answer); +} + +void handle_post(http_request request) +{ + TRACE("\nhandle POST\n"); + + handle_request(request); +} + +void handle_put(http_request request) +{ + TRACE("\nhandle PUT\n"); + + handle_request(request); +} + +void start_server() +{ + + utility::string_t port = U("8080"); + utility::string_t address = U("http://0.0.0.0:"); + address.append(port); + address.append(U("/ric/v1/subscriptions/response")); + uri_builder uri(address); + + auto addr = uri.to_uri().to_string(); + http_listener listener(addr); + //http_listener listener("http://localhost:8080/ric"); + cout<<"validated uri = "<startup(sub_handler); sleep(10); @@ -78,10 +169,10 @@ int main(int argc, char *argv[]){ b_xapp->start_xapp_receiver(std::ref(*mp_handler)); - sleep(1); - + sleep(20);//waiting for some time before sending delete. + b_xapp->shutdown();//will start the sending delete procedure. while(1){ sleep(1); } diff --git a/Bouncer/src/xapp-asn/e2ap/subscription_delete_request.cc b/Bouncer/src/xapp-asn/e2ap/subscription_delete_request.cc index 6a1ffc8..f63376e 100644 --- a/Bouncer/src/xapp-asn/e2ap/subscription_delete_request.cc +++ b/Bouncer/src/xapp-asn/e2ap/subscription_delete_request.cc @@ -113,30 +113,35 @@ bool subscription_delete::encode_e2ap_subscription(unsigned char *buf, size_t *s } -bool subscription_delete::set_fields( subscription_helper &helper){ - unsigned int ie_index; - - ie_index = 0; - RICsubscriptionDeleteRequest_IEs_t *ies_ricreq = &IE_array[ie_index]; - ies_ricreq->criticality = Criticality_reject; - ies_ricreq->id = ProtocolIE_ID_id_RICrequestID; - ies_ricreq->value.present = RICsubscriptionDeleteRequest_IEs__value_PR_RICrequestID; - RICrequestID_t *ricrequest_ie = &ies_ricreq->value.choice.RICrequestID; - ricrequest_ie->ricRequestorID = helper.get_request_id(); - //ricrequest_ie->ricRequestSequenceNumber = helper.get_req_seq(); +bool subscription_delete::set_fields( subscription_helper &helper) +{ + static long update_instance=0;//static variable to update ricInstaceID for sending delete req + unsigned int ie_index; + ie_index = 0; + RICsubscriptionDeleteRequest_IEs_t *ies_ricreq = &IE_array[ie_index]; + ies_ricreq->criticality = Criticality_reject; + ies_ricreq->id = ProtocolIE_ID_id_RICrequestID; + ies_ricreq->value.present = RICsubscriptionDeleteRequest_IEs__value_PR_RICrequestID; + RICrequestID_t *ricrequest_ie = &ies_ricreq->value.choice.RICrequestID; + ricrequest_ie->ricRequestorID = helper.get_request_id(); + update_instance++;//incrementing ricInstanceID by one, each time the bouncer send delete req + ricrequest_ie->ricInstanceID = update_instance; + mdclog_write(MDCLOG_INFO,"instance id for subsdelreq = %d", update_instance); + //ricrequest_ie->ricRequestSequenceNumber = helper.get_req_seq(); - ie_index = 1; - RICsubscriptionDeleteRequest_IEs_t *ies_ranfunc = &IE_array[ie_index]; - ies_ranfunc->criticality = Criticality_reject; - ies_ranfunc->id = ProtocolIE_ID_id_RANfunctionID; - ies_ranfunc->value.present = RICsubscriptionDeleteRequest_IEs__value_PR_RANfunctionID; - RANfunctionID_t *ranfunction_ie = &ies_ranfunc->value.choice.RANfunctionID; - *ranfunction_ie = helper.get_function_id(); - + ie_index = 1; + RICsubscriptionDeleteRequest_IEs_t *ies_ranfunc = &IE_array[ie_index]; + ies_ranfunc->criticality = Criticality_reject; + ies_ranfunc->id = ProtocolIE_ID_id_RANfunctionID; + ies_ranfunc->value.present = RICsubscriptionDeleteRequest_IEs__value_PR_RANfunctionID; + RANfunctionID_t *ranfunction_ie = &ies_ranfunc->value.choice.RANfunctionID; + *ranfunction_ie = helper.get_function_id(); + mdclog_write(MDCLOG_INFO,"ran function id for subsdelreq = %d", helper.get_function_id()); + //*ranfunction_ie =1; - return true; + return true; }; diff --git a/Bouncer/src/xapp-asn/e2ap/subscription_request.cc b/Bouncer/src/xapp-asn/e2ap/subscription_request.cc index 91071b3..4d23bd9 100644 --- a/Bouncer/src/xapp-asn/e2ap/subscription_request.cc +++ b/Bouncer/src/xapp-asn/e2ap/subscription_request.cc @@ -175,6 +175,7 @@ bool subscription_request::set_fields( InitiatingMessage_t * init_msg, subscript ies_ricreq->value.present = RICsubscriptionRequest_IEs__value_PR_RICrequestID; RICrequestID_t *ricrequest_ie = &ies_ricreq->value.choice.RICrequestID; ricrequest_ie->ricRequestorID = helper.get_request_id(); + mdclog_write(MDCLOG_INFO,"instance id for subsreq = %d", ricrequest_ie->ricInstanceID); //ricrequest_ie->ricRequestSequenceNumber = helper.get_req_seq(); result = ASN_SEQUENCE_ADD(&(ric_subscription->protocolIEs), &IE_array[ie_index]); assert(result == 0); diff --git a/Bouncer/src/xapp-mgmt/msgs_proc.cc b/Bouncer/src/xapp-mgmt/msgs_proc.cc index d66f0c8..49b413a 100644 --- a/Bouncer/src/xapp-mgmt/msgs_proc.cc +++ b/Bouncer/src/xapp-mgmt/msgs_proc.cc @@ -136,102 +136,150 @@ bool XappMsgHandler::decode_subscription_response(unsigned char* data_buf, size_ //For processing received messages.XappMsgHandler should mention if resend is required or not. -void XappMsgHandler::operator()(rmr_mbuf_t *message, bool *resend){ +void XappMsgHandler::operator()(rmr_mbuf_t *message, bool *resend) +{ - if (message->len > MAX_RMR_RECV_SIZE){ + if (message->len > MAX_RMR_RECV_SIZE) + { mdclog_write(MDCLOG_ERR, "Error : %s, %d, RMR message larger than %d. Ignoring ...", __FILE__, __LINE__, MAX_RMR_RECV_SIZE); return; } - //a1_policy_helper helper; + //a1_policy_helper helper; bool res=false; E2AP_PDU_t* e2pdu = (E2AP_PDU_t*)calloc(1, sizeof(E2AP_PDU)); int num = 0; - switch(message->mtype){ + switch(message->mtype) + { //need to fix the health check. case (RIC_HEALTH_CHECK_REQ): - message->mtype = RIC_HEALTH_CHECK_RESP; // if we're here we are running and all is ok - message->sub_id = -1; - strncpy( (char*)message->payload, "Bouncer OK\n", rmr_payload_size( message) ); - *resend = true; - break; + message->mtype = RIC_HEALTH_CHECK_RESP; // if we're here we are running and all is ok + message->sub_id = -1; + strncpy( (char*)message->payload, "Bouncer OK\n", rmr_payload_size( message) ); + *resend = true; + break; case (RIC_SUB_RESP): mdclog_write(MDCLOG_INFO, "Received subscription message of type = %d", message->mtype); - unsigned char *me_id; - if( (me_id = (unsigned char *) malloc( sizeof( unsigned char ) * RMR_MAX_MEID )) == NULL ) { - mdclog_write(MDCLOG_ERR, "Error : %s, %d : malloc failed for me_id", __FILE__, __LINE__); - me_id = rmr_get_meid(message, NULL); - } else { - rmr_get_meid(message, me_id); - } - if(me_id == NULL){ - mdclog_write(MDCLOG_ERR, " Error :: %s, %d : rmr_get_meid failed me_id is NULL", __FILE__, __LINE__); - break; - } - mdclog_write(MDCLOG_INFO,"RMR Received MEID: %s",me_id); - if(_ref_sub_handler !=NULL){ - _ref_sub_handler->manage_subscription_response(message->mtype, reinterpret_cast< char const* >(me_id)); - } else { - mdclog_write(MDCLOG_ERR, " Error :: %s, %d : Subscription handler not assigned in message processor !", __FILE__, __LINE__); - } - *resend = false; - if (me_id != NULL) { - mdclog_write(MDCLOG_INFO, "Free RMR Received MEID memory: %s(0x%x)", me_id, me_id); - free(me_id); - } + unsigned char *me_id; + if( (me_id = (unsigned char *) malloc( sizeof( unsigned char ) * RMR_MAX_MEID )) == NULL ) + { + mdclog_write(MDCLOG_ERR, "Error : %s, %d : malloc failed for me_id", __FILE__, __LINE__); + me_id = rmr_get_meid(message, NULL); + } + else + { + rmr_get_meid(message, me_id); + } + if(me_id == NULL) + { + mdclog_write(MDCLOG_ERR, " Error :: %s, %d : rmr_get_meid failed me_id is NULL", __FILE__, __LINE__); + break; + } + mdclog_write(MDCLOG_INFO,"RMR Received MEID: %s",me_id); + if(_ref_sub_handler !=NULL) + { + _ref_sub_handler->manage_subscription_response(message->mtype, reinterpret_cast< char const* >(me_id)); + } + else + { + mdclog_write(MDCLOG_ERR, " Error :: %s, %d : Subscription handler not assigned in message processor !", __FILE__, __LINE__); + } + *resend = false; + if (me_id != NULL) + { + mdclog_write(MDCLOG_INFO, "Free RMR Received MEID memory: %s(0x%x)", me_id, me_id); + free(me_id); + } + break; + + case (RIC_SUB_DEL_RESP): + mdclog_write(MDCLOG_INFO, "Received subscription delete message of type = %d", message->mtype); + //unsigned char *me_id; + if( (me_id = (unsigned char *) malloc( sizeof( unsigned char ) * RMR_MAX_MEID )) == NULL ) + { + mdclog_write(MDCLOG_ERR, "Error : %s, %d : malloc failed for me_id", __FILE__, __LINE__); + me_id = rmr_get_meid(message, NULL); + } + else + + { + rmr_get_meid(message, me_id); + } + if(me_id == NULL) + { + mdclog_write(MDCLOG_ERR, " Error :: %s, %d : rmr_get_meid failed me_id is NULL", __FILE__, __LINE__); break; + } + mdclog_write(MDCLOG_INFO,"RMR Received MEID: %s",me_id); + if(_ref_sub_handler !=NULL) + { + _ref_sub_handler->manage_subscription_response(message->mtype, reinterpret_cast< char const* >(me_id)); + } + else + { + mdclog_write(MDCLOG_ERR, " Error :: %s, %d : Subscription handler not assigned in message processor !", __FILE__, __LINE__); + } + *resend = false; + if (me_id != NULL) + { + mdclog_write(MDCLOG_INFO, "Free RMR Received MEID memory: %s(0x%x)", me_id, me_id); + free(me_id); + } + break; case (RIC_INDICATION): if(message->mtype == 12050) - { - mdclog_write(MDCLOG_INFO, "Decoding indication for msg = %d", message->mtype); - - ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, e2pdu); - asn_transfer_syntax syntax; - syntax = ATS_ALIGNED_BASIC_PER; - - mdclog_write(MDCLOG_INFO, "Data_size = %d", message->len); - - auto rval = asn_decode(nullptr, syntax, &asn_DEF_E2AP_PDU, (void**)&e2pdu, message->payload, message->len); - - if(rval.code == RC_OK) - { - mdclog_write(MDCLOG_INFO, "rval.code = %d ", rval.code); - } - else{ - mdclog_write(MDCLOG_ERR, " rval.code = %d ", rval.code); - break; - } - - asn_fprint(stdout, &asn_DEF_E2AP_PDU, e2pdu); - mdclog_write(MDCLOG_INFO, "Received indication message of type = %d", message->mtype); - num++; - message->mtype = RIC_CONTROL_REQ; // if we're here we are running and all is ok - message->sub_id = -1; - strncpy((char*)message->payload, "Bouncer Control OK\n", rmr_payload_size(message)); - *resend = true; - ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, e2pdu); + { + mdclog_write(MDCLOG_INFO, "Decoding indication for msg = %d", message->mtype); + + ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, e2pdu); + asn_transfer_syntax syntax; + syntax = ATS_ALIGNED_BASIC_PER; + + mdclog_write(MDCLOG_INFO, "Data_size = %d", message->len); + + auto rval = asn_decode(nullptr, syntax, &asn_DEF_E2AP_PDU, (void**)&e2pdu, message->payload, message->len); + + if(rval.code == RC_OK) + { + mdclog_write(MDCLOG_INFO, "rval.code = %d ", rval.code); + } + else + { + mdclog_write(MDCLOG_ERR, " rval.code = %d ", rval.code); + break; + } + + asn_fprint(stdout, &asn_DEF_E2AP_PDU, e2pdu); + mdclog_write(MDCLOG_INFO, "Received indication message of type = %d", message->mtype); + num++; + message->mtype = RIC_CONTROL_REQ; // if we're here we are running and all is ok + message->sub_id = -1; + strncpy((char*)message->payload, "Bouncer Control OK\n", rmr_payload_size(message)); + *resend = true; + ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, e2pdu); } - mdclog_write(MDCLOG_INFO, "Number of Indications Received = %d", num); - break; + mdclog_write(MDCLOG_INFO, "Number of Indications Received = %d", num); + break; - /*case A1_POLICY_REQ: + /*case A1_POLICY_REQ: - mdclog_write(MDCLOG_INFO, "In Message Handler: Received A1_POLICY_REQ."); + mdclog_write(MDCLOG_INFO, "In Message Handler: Received A1_POLICY_REQ."); helper.handler_id = xapp_id; res = a1_policy_handler((char*)message->payload, &message->len, helper); - if(res){ + if(res) + { message->mtype = A1_POLICY_RESP; // if we're here we are running and all is ok message->sub_id = -1; *resend = true; } break;*/ - default: + default: { mdclog_write(MDCLOG_ERR, "Error :: Unknown message type %d received from RMR", message->mtype); *resend = false; diff --git a/Bouncer/src/xapp-mgmt/subs_mgmt.cc b/Bouncer/src/xapp-mgmt/subs_mgmt.cc index 931453f..dc6416e 100644 --- a/Bouncer/src/xapp-mgmt/subs_mgmt.cc +++ b/Bouncer/src/xapp-mgmt/subs_mgmt.cc @@ -116,26 +116,33 @@ bool SubscriptionHandler::is_request_entry(transaction_identifier id){ // Handles subscription responses -void SubscriptionHandler::manage_subscription_response(int message_type, transaction_identifier id){ +void SubscriptionHandler::manage_subscription_response(int message_type, transaction_identifier id) +{ // Make This Thread sleep for 1 Second - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - { - std::unique_lock _local_lock(*(_data_lock.get())); - mdclog_write(MDCLOG_INFO,"Subscription Handler: Status for meid %s WAS: %d",id.c_str(),this->get_request_status(id)); - - //from the message type we can know if its a success/failure etc. - if(message_type==RIC_SUB_RESP) - this->set_request_status(id, request_success); - - if(message_type==RIC_SUB_FAILURE) - this->set_request_status(id,request_failed); - - mdclog_write(MDCLOG_INFO,"Subscription Handler: Status for meid %s IS: %d",id.c_str(),this->get_request_status(id)); - - - //this->print_subscription_status(); - } - //_cv.get()->notify_all(); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + { + std::unique_lock _local_lock(*(_data_lock.get())); + mdclog_write(MDCLOG_INFO,"Subscription Handler: Status for meid %s WAS: %d",id.c_str(),this->get_request_status(id)); + + //from the message type we can know if its a success/failure etc. + if(message_type==RIC_SUB_RESP) + this->set_request_status(id, request_success); + + if(message_type==RIC_SUB_DEL_RESP) + this->set_request_status(id, request_success); + + if(message_type==RIC_SUB_FAILURE) + this->set_request_status(id,request_failed); + + if(message_type==RIC_SUB_DEL_FAILURE) + this->set_request_status(id,request_failed); + + mdclog_write(MDCLOG_INFO,"Subscription Handler: Status for meid %s IS: %d",id.c_str(),this->get_request_status(id)); + + + //this->print_subscription_status(); + } + //_cv.get()->notify_all(); } diff --git a/Bouncer/src/xapp-mgmt/subs_mgmt.hpp b/Bouncer/src/xapp-mgmt/subs_mgmt.hpp index 28cf293..1da8adc 100644 --- a/Bouncer/src/xapp-mgmt/subs_mgmt.hpp +++ b/Bouncer/src/xapp-mgmt/subs_mgmt.hpp @@ -49,7 +49,7 @@ #define SUBSCR_ERR_FAIL -3 #define SUBSCR_ERR_UNKNOWN -4 #define SUBSCR_ERR_DUPLICATE -5 - +#define SUBSCR_ERR_NOT_FOUND -6 using namespace std; class TransmitterBase @@ -165,7 +165,6 @@ int SubscriptionHandler::manage_subscription_request(transaction_identifier rmr_ // put entry in request table { std::lock_guard lock(*(_data_lock.get())); - res = add_request_entry(rmr_trans_id, request_pending); if(! res){ @@ -178,10 +177,8 @@ int SubscriptionHandler::manage_subscription_request(transaction_identifier rmr_ // acquire lock ... std::unique_lock _local_lock(*(_data_lock.get())); - // Send the message bool flg = tx(); - if (!flg){ // clear state delete_request_entry(rmr_trans_id); @@ -205,4 +202,52 @@ int SubscriptionHandler::manage_subscription_request(transaction_identifier rmr_ return res; }; +template +int SubscriptionHandler:: manage_subscription_delete_request(transaction_identifier rmr_trans_id, AppTransmitter && tx) +{ + int res; + // delete entry in request table + { + std::lock_guard lock(*(_data_lock.get())); + res = delete_request_entry(rmr_trans_id); + mdclog_write(MDCLOG_INFO,"res=%d",res); + if(! res) + { + mdclog_write(MDCLOG_ERR, "%s : Error deleting new subscription request %s from queue because request with key doesn't present", __FILE__, __LINE__); + + return SUBSCR_ERR_NOT_FOUND; + } + + } + + + // acquire lock ... + std::unique_lock _local_lock(*(_data_lock.get())); + // Send the message + bool flg = tx(); + + if (!flg) + { + // add state + res = add_request_entry(rmr_trans_id, request_pending); + mdclog_write(MDCLOG_ERR, "%s, %d :: Error transmitting subscription delete request %s", __FILE__, __LINE__, rmr_trans_id.c_str()); + return SUBSCR_ERR_TX; + } + else + { + mdclog_write(MDCLOG_INFO, "%s, %d :: Transmitted subscription delete request for trans_id %s", __FILE__, __LINE__, rmr_trans_id.c_str()); + + } + + // record time stamp .. + auto start = std::chrono::system_clock::now(); + std::chrono::milliseconds t_out(_time_out); + + //the wait functionality has been removed. + + + _local_lock.unlock(); + // std::cout <<"Returning res = " << res << " for request = " << rmr_trans_id << std::endl; + return res; +}; #endif diff --git a/Bouncer/src/xapp.cc b/Bouncer/src/xapp.cc index 94d190e..2a07ff4 100644 --- a/Bouncer/src/xapp.cc +++ b/Bouncer/src/xapp.cc @@ -17,8 +17,21 @@ */ #include "xapp.hpp" +#include +#include +#include +#include +#include +#include +#include +using namespace utility; +using namespace web; +using namespace web::http; +using namespace web::http::client; +using namespace concurrency::streams; +using jsonn = nlohmann::json; #define BUFFER_SIZE 1024 - +extern std::vectorSubscriptionIds; Xapp::Xapp(XappSettings &config, XappRmr &rmr){ rmr_ref = &rmr; @@ -105,35 +118,247 @@ void Xapp::start_xapp_receiver(XappMsgHandler& mp_handler){ } void Xapp::shutdown(){ - return; + + sleep(70); + //send subscriptions delete. + shutdown_subscribe_deletes(); + return; } +void Xapp::shutdown_subscribe_deletes(void ) +{ + + bool res; + size_t data_size = ASN_BUFF_MAX_SIZE; + unsigned char data[data_size]; + //unsigned char meid[RMR_MAX_MEID]; + char meid[RMR_MAX_MEID]; + std::string xapp_id = config_ref->operator [](XappSettings::SettingName::XAPP_ID); + + mdclog_write(MDCLOG_INFO,"Preparing to send subscription Delete in file= %s, line=%d",__FILE__,__LINE__); + + auto gnblist = get_rnib_gnblist(); + + int sz = gnblist.size(); + mdclog_write(MDCLOG_INFO,"GNBList size : %d", sz); + + if(sz <= 0) + mdclog_write(MDCLOG_INFO,"Subscriptions Delete cannot be sent as GNBList in RNIB is NULL"); + + for(int i = 0; i0) + { + auto delJson = pplx::create_task([i,meid]() { + utility::string_t port = U("8088"); + utility::string_t address = U("http://service-ricplt-submgr-http.ricplt.svc.cluster.local:"); + address.append(port); + address.append(U("/ric/v1/subscriptions/")); + address.append( utility::string_t(SubscriptionIds.back())); + SubscriptionIds.pop_back(); + uri_builder uri(address); + auto addr = uri.to_uri().to_string(); + http_client client(addr); + ucout << utility::string_t(U("making requests at: ")) << addr <manage_subscription_delete_request(gnblist[i], transmitter); + + if(result==SUBSCR_SUCCESS) + { + + mdclog_write(MDCLOG_INFO,"Subscription Delete SUCCESSFUL in file= %s, line=%d for MEID %s",__FILE__,__LINE__, meid); + } + else + { + mdclog_write(MDCLOG_ERR,"Subscription Delete FAILED in file= %s, line=%d for MEID %s",__FILE__,__LINE__, meid); + } + */ + } +} 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]; + char meid[RMR_MAX_MEID]; std::string xapp_id = config_ref->operator [](XappSettings::SettingName::XAPP_ID); - + //int a =std::stoi(xapp_id); mdclog_write(MDCLOG_INFO,"Preparing to send subscription in file= %s, line=%d",__FILE__,__LINE__); auto gnblist = get_rnib_gnblist(); int sz = gnblist.size(); - + mdclog_write(MDCLOG_INFO,"GNBList size : %d", sz); if(sz <= 0) mdclog_write(MDCLOG_INFO,"Subscriptions cannot be sent as GNBList in RNIB is NULL"); for(int i = 0; i #include "msgs_proc.hpp" #include "subs_mgmt.hpp" #include "xapp_config.hpp" -- 2.16.6