From 65ac2f814cdd9dc0f71ee35868dc6c75a7f69d6a Mon Sep 17 00:00:00 2001 From: sjana Date: Tue, 31 Mar 2020 12:20:25 -0400 Subject: [PATCH] Testcase for A1 Healthcheck added. Issue-ID: RICAPP-65 Signed-off-by: sjana Change-Id: I40cb9ad09205431ecdf333107ad08c6717522ce5 --- test/Makefile | 6 +-- test/hw_unit_tests.cc | 11 +++-- test/test_db.h | 68 ++++++++++++++++++++++++++++++ test/test_hc.h | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++ test/test_rmr.h | 84 +++++++++---------------------------- 5 files changed, 211 insertions(+), 71 deletions(-) create mode 100644 test/test_db.h create mode 100644 test/test_hc.h diff --git a/test/Makefile b/test/Makefile index aad5855..10089f7 100644 --- a/test/Makefile +++ b/test/Makefile @@ -7,14 +7,14 @@ UTILSRC=../src/xapp-utils MGMTSRC:=../src/xapp-mgmt ASNSRC:=../asn1c_defs -E2APSRC:=../src/xapp-asn/e2ap -E2SMSRC:=../src/xapp-asn/e2sm +E2APSRC:=../src/xapp-formats/e2ap +E2SMSRC:=../src/xapp-formats/e2sm ####### Logging library and flags CLOGFLAGS:= `pkg-config mdclog --cflags` LOG_LIBS:= `pkg-config mdclog --libs` CURL_LIBS:= `pkg-config libcurl --libs` -RNIB_LIBS:= -pthread /usr/local/lib/rnibreader.a +RNIB_LIBS:= -pthread /usr/local/lib/rnibreader_old.a GTEST_LIBS:= -lgtest -lgtest_main ######## Keep include dirs separate so we have transparency diff --git a/test/hw_unit_tests.cc b/test/hw_unit_tests.cc index 73a44d2..a1bd3ca 100644 --- a/test/hw_unit_tests.cc +++ b/test/hw_unit_tests.cc @@ -23,15 +23,18 @@ */ #include -#include +#include #include -#include "test_rmr.h" -#include "test_rnib.h" -#include "test_sdl.h" +#include "test_db.h" +//#include "test_rmr.h" +#include "test_hc.h" + +#define HC_MSG_SIZE 512 using namespace std; + int main(int argc, char* argv[]) { char rmr_seed[80]="RMR_SEED_RT=../src/routes.txt"; diff --git a/test/test_db.h b/test/test_db.h new file mode 100644 index 0000000..e7716b4 --- /dev/null +++ b/test/test_db.h @@ -0,0 +1,68 @@ +/* +================================================================================== + + Copyright (c) 2018-2019 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. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +================================================================================== +/* + * test_rnib.h + * + * Created on: Mar 23, 2020 + * Author: Shraboni Jana + */ + +#ifndef TEST_TEST_DB_H_ +#define TEST_TEST_DB_H_ + +#include +#include +#include "xapp.hpp" + +using namespace std; + +TEST(Xapp, getGNBlist) +{ + XappSettings config; + XappRmr rmr("7001"); + + Xapp hw_xapp(std::ref(config),rmr); + hw_xapp.set_rnib_gnblist(); + + auto gnblist = hw_xapp.get_rnib_gnblist(); + int sz = gnblist.size(); + EXPECT_GE(sz,0); + std::cout << "************gnb ids retrieved using R-NIB**************" << std::endl; + for(int i = 0; i sdl(shareddatalayer::SyncStorage::create()); + bool res = xappsdl.set_data(sdl.get()); + ASSERT_TRUE(res); + + xappsdl.get_data(sdl.get()); + +} + + + +#endif /* TEST_TEST_DB_H_ */ diff --git a/test/test_hc.h b/test/test_hc.h new file mode 100644 index 0000000..cbb8726 --- /dev/null +++ b/test/test_hc.h @@ -0,0 +1,113 @@ +/* +================================================================================== + + Copyright (c) 2018-2019 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. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +================================================================================== +/* + * test_a1.h + * + * Created on: Mar, 2020 + * Author: Shraboni Jana + */ + +#include +#include +#include +#include +#include +#include "xapp.hpp" +#define HC_MSG_SIZE 512 + +using namespace std; +TEST(Xapp, RMRHealthCheck){ + + 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("HW-Xapp-id"); + + 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(1); + } + sleep(10); + hw_xapp->stop(); + sleep(10); + }; + +TEST(Xapp, A1HealthCheck){ + + //Read the json file and send it using rmr. + string json = "{\"policy_type_id\": \"1\",\"policy_instance_id\":\"3d2157af-6a8f-4a7c-810f-38c2f824bf12\",\"operation\": \"CREATE\"}"; + int n = json.length(); + char strMsg[n + 1]; + strcpy(strMsg, json.c_str()); + Document d; + d.Parse(strMsg); + + int num_attempts = 5; + + 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("HW-Xapp-id"); + + hw_xapp->start_xapp_receiver(std::ref(*mp_handler)); + sleep(5); + + xapp_rmr_header hdr; + hdr.message_type = A1_POLICY_REQ; + clock_gettime(CLOCK_REALTIME, &(hdr.ts)); + + + hdr.payload_length = strlen(strMsg); + + bool res_msg1 = rmr->xapp_rmr_send(&hdr,(void*)strMsg); + ASSERT_TRUE(res_msg1); + + usleep(1); + + bool res_msg2 = rmr->xapp_rmr_send(&hdr,(void*)strMsg); + ASSERT_TRUE(res_msg2); + + sleep(10); + hw_xapp->stop(); + sleep(10); + +} diff --git a/test/test_rmr.h b/test/test_rmr.h index 268ba7a..a85c8c5 100644 --- a/test/test_rmr.h +++ b/test/test_rmr.h @@ -32,88 +32,44 @@ 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->set_listen(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); + 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"); + std::unique_ptr mp_handler = std::make_unique("HW-Xapp-id"); + XappRmr *rmr = new XappRmr("4560"); 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(); - + sleep(10); + rmr->set_listen(false); + 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); - } - - - }; - - - #endif /* TEST_TEST_RMR_H_ */ -- 2.16.6