268ba7adf1ab320eae029e7e23e02850eab9a04f
[ric-app/hw.git] / test / test_rmr.h
1 /*
2 ==================================================================================
3
4         Copyright (c) 2018-2019 AT&T Intellectual Property.
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_rmr_healthcheck.h
20  *
21  *  Created on: Mar, 2020
22  *  Author: Shraboni Jana
23  */
24
25 #ifndef TEST_TEST_RMR_H_
26 #define TEST_TEST_RMR_H_
27 #include<iostream>
28 #include<gtest/gtest.h>
29 #include "xapp.hpp"
30
31 #define HC_MSG_SIZE 512
32
33 using namespace std;
34
35 TEST(XappRmr, RMRSender){
36
37         int total_num_msgs = 10;
38         int num_attempts = 5;
39
40         std::unique_ptr<XappRmr> rmr;
41         rmr = std::make_unique<XappRmr>("4560",num_attempts);
42         rmr->xapp_rmr_init();
43
44         xapp_rmr_header hdr;
45         hdr.message_type = RIC_HEALTH_CHECK_REQ;
46     char *strMsg = (char*)malloc(HC_MSG_SIZE);
47
48     for(int i = 0; i < total_num_msgs; i++){
49        snprintf(strMsg,HC_MSG_SIZE, "HelloWorld: RMR Health Check %d", i);
50        clock_gettime(CLOCK_REALTIME, &(hdr.ts));
51        hdr.payload_length = strlen(strMsg);
52
53        bool res = rmr->xapp_rmr_send(&hdr,(void*)strMsg);
54        ASSERT_TRUE(res);
55
56        usleep(10);
57      }
58     delete strMsg;
59
60 }
61  TEST(XappRmr, RMRReceiver){
62          //initialize rmr
63          std::unique_ptr<XappRmr> rmr;
64          rmr = std::make_unique<XappRmr>("5551");
65          rmr->xapp_rmr_init();
66
67          XappSettings config;
68
69          std::unique_ptr<Xapp> hw_xapp = std::make_unique<Xapp>(std::ref(config),std::ref(*rmr));
70
71          std::unique_ptr<XappMsgHandler> mp_handler = std::make_unique<XappMsgHandler>();
72
73          rmr->set_listen(true);
74          hw_xapp->start_xapp_receiver(std::ref(*mp_handler));
75          sleep(2);
76          rmr->~XappRmr();
77
78          ASSERT_TRUE(true);
79  };
80
81  TEST(XappRmr, HC_ReturnToSender){
82
83          int total_num_msgs = 2;
84          int num_attempts = 10;
85
86          std::unique_ptr<XappRmr> rmr;
87          rmr = std::make_unique<XappRmr>("4560",num_attempts);
88          rmr->xapp_rmr_init();
89
90          XappSettings config;
91
92          std::unique_ptr<Xapp> hw_xapp = std::make_unique<Xapp>(std::ref(config),std::ref(*rmr));
93
94          std::unique_ptr<XappMsgHandler> mp_handler = std::make_unique<XappMsgHandler>();
95
96          rmr->set_listen(true);
97          hw_xapp->start_xapp_receiver(std::ref(*mp_handler));
98          sleep(5);
99
100          xapp_rmr_header hdr;
101          hdr.message_type = RIC_HEALTH_CHECK_REQ;
102          char strMsg[HC_MSG_SIZE];
103
104          for(int i = 0; i < total_num_msgs; i++){
105                  snprintf(strMsg,HC_MSG_SIZE, "HelloWorld: RMR Health Check %d", i);
106                  clock_gettime(CLOCK_REALTIME, &(hdr.ts));
107                  hdr.payload_length = strlen(strMsg);
108
109                  bool res = rmr->xapp_rmr_send(&hdr,(void*)strMsg);
110                  usleep(10);
111          }
112
113
114  };
115
116
117
118
119 #endif /* TEST_TEST_RMR_H_ */