X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Ftest_rmr.h;h=fc4bf860971b6d15210de684ac3bca557ecf2334;hb=ea129fa14c89d8f5cedacd9afc1e4dd7a30f1ae4;hp=268ba7adf1ab320eae029e7e23e02850eab9a04f;hpb=d63f834656922171ffa04347e34c7bce8a0d41be;p=ric-app%2Fhw.git diff --git a/test/test_rmr.h b/test/test_rmr.h index 268ba7a..fc4bf86 100644 --- a/test/test_rmr.h +++ b/test/test_rmr.h @@ -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. @@ -28,92 +28,80 @@ #include #include "xapp.hpp" -#define HC_MSG_SIZE 512 - using namespace std; -TEST(XappRmr, RMRSender){ +TEST(RMR, Sender){ - int total_num_msgs = 10; - int num_attempts = 5; + int total_num_msgs = 2; + int num_attempts = 10; std::unique_ptr rmr; rmr = std::make_unique("4560",num_attempts); - rmr->xapp_rmr_init(); + rmr->xapp_rmr_init(false); xapp_rmr_header hdr; hdr.message_type = RIC_HEALTH_CHECK_REQ; - char *strMsg = (char*)malloc(HC_MSG_SIZE); - for(int i = 0; i < total_num_msgs; i++){ - snprintf(strMsg,HC_MSG_SIZE, "HelloWorld: RMR Health Check %d", i); - clock_gettime(CLOCK_REALTIME, &(hdr.ts)); - hdr.payload_length = strlen(strMsg); + for(int i = 0; i < total_num_msgs; i++){ + std::string temp="HelloWorld: RMR Health Check"+ std::to_string(i); + int n = temp.length(); + char strMsg[n+1]; + std::strcpy(strMsg,temp.c_str()); - bool res = rmr->xapp_rmr_send(&hdr,(void*)strMsg); - ASSERT_TRUE(res); + clock_gettime(CLOCK_REALTIME, &(hdr.ts)); + hdr.payload_length = n+1; - usleep(10); + bool res = rmr->xapp_rmr_send(&hdr,(void*)strMsg); + ASSERT_TRUE(res); + usleep(1); } - delete strMsg; - + ASSERT_TRUE(true); } - TEST(XappRmr, RMRReceiver){ + TEST(RMR, Receiver){ //initialize rmr - std::unique_ptr rmr; - rmr = std::make_unique("5551"); - rmr->xapp_rmr_init(); - - XappSettings config; - - std::unique_ptr hw_xapp = std::make_unique(std::ref(config),std::ref(*rmr)); - - std::unique_ptr mp_handler = std::make_unique(); - - rmr->set_listen(true); - hw_xapp->start_xapp_receiver(std::ref(*mp_handler)); - sleep(2); - rmr->~XappRmr(); + std::unique_ptr mp_handler = std::make_unique("HW-Xapp-id"); + XappRmr *rmr = new XappRmr("4560"); + rmr->xapp_rmr_init(false); + sleep(10); + rmr->xapp_rmr_receive(std::move(*mp_handler), rmr); ASSERT_TRUE(true); }; - TEST(XappRmr, HC_ReturnToSender){ - - int total_num_msgs = 2; - int num_attempts = 10; - - std::unique_ptr rmr; - rmr = std::make_unique("4560",num_attempts); - rmr->xapp_rmr_init(); - - XappSettings config; - - std::unique_ptr hw_xapp = std::make_unique(std::ref(config),std::ref(*rmr)); - - std::unique_ptr mp_handler = std::make_unique(); - - rmr->set_listen(true); - hw_xapp->start_xapp_receiver(std::ref(*mp_handler)); - sleep(5); - - xapp_rmr_header hdr; - hdr.message_type = RIC_HEALTH_CHECK_REQ; - char strMsg[HC_MSG_SIZE]; - - for(int i = 0; i < total_num_msgs; i++){ - snprintf(strMsg,HC_MSG_SIZE, "HelloWorld: RMR Health Check %d", i); - clock_gettime(CLOCK_REALTIME, &(hdr.ts)); - hdr.payload_length = strlen(strMsg); - - bool res = rmr->xapp_rmr_send(&hdr,(void*)strMsg); - usleep(10); - } - - - }; - +TEST(RMR, SendReceiveWithMEID) { + XappSettings config; + int total_num_msgs = 2; + int num_attempts = 10; + std::unique_ptr rmr; + rmr = std::make_unique("4560",num_attempts); + rmr->xapp_rmr_init(true); + std::unique_ptr hw_xapp = std::make_unique(config,std::ref(*rmr)); + std::unique_ptr mp_handler = std::make_unique("HW-Xapp_ID"); + hw_xapp->start_xapp_receiver(std::ref(*mp_handler)); + xapp_rmr_header hdr; + //can be any message type. using as an example + hdr.message_type = RIC_SUB_RESP; + memset(hdr.meid,0,32); + string meid = "NYC123"; + strcpy(reinterpret_cast(hdr.meid), meid.c_str()); + + for(int i = 0; i < total_num_msgs; i++){ + std::string temp="HelloWorld: RMR Health Check"+ std::to_string(i); + int n = temp.length(); + char strMsg[n+1]; + std::strcpy(strMsg,temp.c_str()); + + clock_gettime(CLOCK_REALTIME, &(hdr.ts)); + hdr.payload_length = n+1; + + bool res = rmr->xapp_rmr_send(&hdr,(void*)strMsg); + ASSERT_TRUE(res); + usleep(1); + } + sleep(1); + hw_xapp->stop(); +} #endif /* TEST_TEST_RMR_H_ */