sjana | 65ac2f8 | 2020-03-31 12:20:25 -0400 | [diff] [blame] | 1 | /* |
| 2 | ================================================================================== |
| 3 | |
sjana | 23dad81 | 2020-05-08 14:13:38 -0400 | [diff] [blame] | 4 | Copyright (c) 2019-2020 AT&T Intellectual Property. |
sjana | 65ac2f8 | 2020-03-31 12:20:25 -0400 | [diff] [blame] | 5 | |
| 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 |
| 9 | |
| 10 | http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | |
| 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 | ================================================================================== |
| 18 | /* |
| 19 | * test_a1.h |
| 20 | * |
| 21 | * Created on: Mar, 2020 |
| 22 | * Author: Shraboni Jana |
| 23 | */ |
| 24 | |
| 25 | #include<iostream> |
| 26 | #include<gtest/gtest.h> |
| 27 | #include<rapidjson/stringbuffer.h> |
| 28 | #include<rapidjson/writer.h> |
| 29 | #include<string.h> |
| 30 | #include "xapp.hpp" |
| 31 | #define HC_MSG_SIZE 512 |
| 32 | |
sjana | 23dad81 | 2020-05-08 14:13:38 -0400 | [diff] [blame] | 33 | |
sjana | 65ac2f8 | 2020-03-31 12:20:25 -0400 | [diff] [blame] | 34 | using namespace std; |
| 35 | TEST(Xapp, RMRHealthCheck){ |
| 36 | |
| 37 | int total_num_msgs = 2; |
| 38 | int num_attempts = 10; |
| 39 | |
| 40 | std::unique_ptr<XappRmr> rmr; |
| 41 | rmr = std::make_unique<XappRmr>("4560",num_attempts); |
sjana | 23dad81 | 2020-05-08 14:13:38 -0400 | [diff] [blame] | 42 | rmr->xapp_rmr_init(true); |
sjana | 65ac2f8 | 2020-03-31 12:20:25 -0400 | [diff] [blame] | 43 | |
| 44 | XappSettings config; |
| 45 | |
| 46 | std::unique_ptr<Xapp> hw_xapp = std::make_unique<Xapp>(std::ref(config),std::ref(*rmr)); |
| 47 | |
| 48 | std::unique_ptr<XappMsgHandler> mp_handler = std::make_unique<XappMsgHandler>("HW-Xapp-id"); |
| 49 | |
| 50 | hw_xapp->start_xapp_receiver(std::ref(*mp_handler)); |
| 51 | sleep(5); |
| 52 | |
| 53 | xapp_rmr_header hdr; |
| 54 | hdr.message_type = RIC_HEALTH_CHECK_REQ; |
| 55 | char strMsg[HC_MSG_SIZE]; |
| 56 | |
| 57 | for(int i = 0; i < total_num_msgs; i++){ |
| 58 | snprintf(strMsg,HC_MSG_SIZE, "HelloWorld: RMR Health Check %d", i); |
| 59 | clock_gettime(CLOCK_REALTIME, &(hdr.ts)); |
| 60 | hdr.payload_length = strlen(strMsg); |
| 61 | |
| 62 | bool res = rmr->xapp_rmr_send(&hdr,(void*)strMsg); |
| 63 | usleep(1); |
| 64 | } |
sjana | 23dad81 | 2020-05-08 14:13:38 -0400 | [diff] [blame] | 65 | sleep(2); |
sjana | 65ac2f8 | 2020-03-31 12:20:25 -0400 | [diff] [blame] | 66 | hw_xapp->stop(); |
sjana | 23dad81 | 2020-05-08 14:13:38 -0400 | [diff] [blame] | 67 | |
| 68 | }; |
sjana | 65ac2f8 | 2020-03-31 12:20:25 -0400 | [diff] [blame] | 69 | |
| 70 | TEST(Xapp, A1HealthCheck){ |
| 71 | |
| 72 | //Read the json file and send it using rmr. |
sjana | 572205b | 2020-06-03 21:20:10 -0400 | [diff] [blame] | 73 | //string json = "{\"policy_type_id\": \"1\",\"policy_instance_id\":\"3d2157af-6a8f-4a7c-810f-38c2f824bf12\",\"operation\": \"CREATE\"}"; |
| 74 | string json = "{\"operation\": \"CREATE\", \"policy_type_id\": 1, \"policy_instance_id\": \"hwpolicy321\", \"payload\": {\"threshold\": 5}}"; |
sjana | 65ac2f8 | 2020-03-31 12:20:25 -0400 | [diff] [blame] | 75 | int n = json.length(); |
| 76 | char strMsg[n + 1]; |
| 77 | strcpy(strMsg, json.c_str()); |
| 78 | Document d; |
| 79 | d.Parse(strMsg); |
| 80 | |
| 81 | int num_attempts = 5; |
| 82 | |
| 83 | std::unique_ptr<XappRmr> rmr; |
| 84 | rmr = std::make_unique<XappRmr>("4560",num_attempts); |
sjana | 23dad81 | 2020-05-08 14:13:38 -0400 | [diff] [blame] | 85 | rmr->xapp_rmr_init(true); |
sjana | 65ac2f8 | 2020-03-31 12:20:25 -0400 | [diff] [blame] | 86 | |
| 87 | XappSettings config; |
| 88 | |
| 89 | std::unique_ptr<Xapp> hw_xapp = std::make_unique<Xapp>(std::ref(config),std::ref(*rmr)); |
| 90 | |
| 91 | std::unique_ptr<XappMsgHandler> mp_handler = std::make_unique<XappMsgHandler>("HW-Xapp-id"); |
| 92 | |
| 93 | hw_xapp->start_xapp_receiver(std::ref(*mp_handler)); |
| 94 | sleep(5); |
| 95 | |
| 96 | xapp_rmr_header hdr; |
| 97 | hdr.message_type = A1_POLICY_REQ; |
| 98 | clock_gettime(CLOCK_REALTIME, &(hdr.ts)); |
| 99 | |
| 100 | |
| 101 | hdr.payload_length = strlen(strMsg); |
| 102 | |
| 103 | bool res_msg1 = rmr->xapp_rmr_send(&hdr,(void*)strMsg); |
| 104 | ASSERT_TRUE(res_msg1); |
| 105 | |
| 106 | usleep(1); |
| 107 | |
| 108 | bool res_msg2 = rmr->xapp_rmr_send(&hdr,(void*)strMsg); |
| 109 | ASSERT_TRUE(res_msg2); |
| 110 | |
sjana | 23dad81 | 2020-05-08 14:13:38 -0400 | [diff] [blame] | 111 | sleep(2); |
sjana | 65ac2f8 | 2020-03-31 12:20:25 -0400 | [diff] [blame] | 112 | hw_xapp->stop(); |
sjana | 65ac2f8 | 2020-03-31 12:20:25 -0400 | [diff] [blame] | 113 | } |