blob: 7e98043a54080ec89d9288157b58d30e57b80a61 [file] [log] [blame]
sjana65ac2f82020-03-31 12:20:25 -04001/*
2==================================================================================
3
sjana23dad812020-05-08 14:13:38 -04004 Copyright (c) 2019-2020 AT&T Intellectual Property.
sjana65ac2f82020-03-31 12:20:25 -04005
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
sjana23dad812020-05-08 14:13:38 -040033
sjana65ac2f82020-03-31 12:20:25 -040034using namespace std;
35TEST(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);
sjana23dad812020-05-08 14:13:38 -040042 rmr->xapp_rmr_init(true);
sjana65ac2f82020-03-31 12:20:25 -040043
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 }
sjana23dad812020-05-08 14:13:38 -040065 sleep(2);
sjana65ac2f82020-03-31 12:20:25 -040066 hw_xapp->stop();
sjana23dad812020-05-08 14:13:38 -040067
68};
sjana65ac2f82020-03-31 12:20:25 -040069
70TEST(Xapp, A1HealthCheck){
71
72 //Read the json file and send it using rmr.
sjana572205b2020-06-03 21:20:10 -040073 //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}}";
sjana65ac2f82020-03-31 12:20:25 -040075 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);
sjana23dad812020-05-08 14:13:38 -040085 rmr->xapp_rmr_init(true);
sjana65ac2f82020-03-31 12:20:25 -040086
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
sjana23dad812020-05-08 14:13:38 -0400111 sleep(2);
sjana65ac2f82020-03-31 12:20:25 -0400112 hw_xapp->stop();
sjana65ac2f82020-03-31 12:20:25 -0400113}