Added IndicationMessage
[ric-app/hw.git] / test / test_rmr.h
1 /*
2 ==================================================================================
3
4         Copyright (c) 2019-2020 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 using namespace std;
32
33 TEST(RMR, Sender){
34
35         int total_num_msgs = 2;
36         int num_attempts = 10;
37
38         std::unique_ptr<XappRmr> rmr;
39         rmr = std::make_unique<XappRmr>("4560",num_attempts);
40         rmr->xapp_rmr_init(false);
41
42         xapp_rmr_header hdr;
43         hdr.message_type = RIC_HEALTH_CHECK_REQ;
44
45         for(int i = 0; i < total_num_msgs; i++){
46         std::string temp="HelloWorld: RMR Health Check"+ std::to_string(i);
47         int n = temp.length();
48         char strMsg[n+1];
49         std::strcpy(strMsg,temp.c_str());
50
51         clock_gettime(CLOCK_REALTIME, &(hdr.ts));
52         hdr.payload_length = n+1;
53
54         bool res = rmr->xapp_rmr_send(&hdr,(void*)strMsg);
55         ASSERT_TRUE(res);
56         usleep(1);
57      }
58     ASSERT_TRUE(true);
59 }
60  TEST(RMR, Receiver){
61          //initialize rmr
62          std::unique_ptr<XappMsgHandler> mp_handler = std::make_unique<XappMsgHandler>("HW-Xapp-id");
63          XappRmr *rmr = new XappRmr("4560");
64          rmr->xapp_rmr_init(false);
65          sleep(10);
66
67          rmr->xapp_rmr_receive(std::move(*mp_handler), rmr);
68          ASSERT_TRUE(true);
69  };
70
71 TEST(RMR, SendReceiveWithMEID) {
72     XappSettings config;
73         int total_num_msgs = 2;
74         int num_attempts = 10;
75
76         std::unique_ptr<XappRmr> rmr;
77         rmr = std::make_unique<XappRmr>("4560",num_attempts);
78         rmr->xapp_rmr_init(true);
79
80         std::unique_ptr<Xapp> hw_xapp = std::make_unique<Xapp>(config,std::ref(*rmr));
81         std::unique_ptr<XappMsgHandler> mp_handler = std::make_unique<XappMsgHandler>("HW-Xapp_ID");
82         hw_xapp->start_xapp_receiver(std::ref(*mp_handler));
83
84         xapp_rmr_header hdr;
85         //can be any message type. using as an example
86         hdr.message_type = RIC_SUB_RESP;
87         memset(hdr.meid,0,32);
88         string meid = "NYC123";
89         strcpy(reinterpret_cast<char*>(hdr.meid), meid.c_str());
90
91         for(int i = 0; i < total_num_msgs; i++){
92         std::string temp="HelloWorld: RMR Health Check"+ std::to_string(i);
93         int n = temp.length();
94         char strMsg[n+1];
95         std::strcpy(strMsg,temp.c_str());
96
97         clock_gettime(CLOCK_REALTIME, &(hdr.ts));
98         hdr.payload_length = n+1;
99
100         bool res = rmr->xapp_rmr_send(&hdr,(void*)strMsg);
101         ASSERT_TRUE(res);
102         usleep(1);
103      }
104           sleep(1);
105       hw_xapp->stop();
106 }
107 #endif /* TEST_TEST_RMR_H_ */