Control Message Encode/Decode
[ric-app/hw.git] / test / test_e2sm.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_e2sm.h
20  *
21  *  Created on: Apr, 2020
22  *      Author: Shraboni Jana
23  */
24
25 #ifndef TEST_TEST_ASN_H_
26 #define TEST_TEST_ASN_H_
27 #include<iostream>
28 #include<gtest/gtest.h>
29
30 #include "e2ap_control_request.hpp"
31 #include "xapp.hpp"
32 #include "e2sm_control.hpp"
33 #include "e2ap_indication.hpp"
34 #include "e2sm_indication.hpp"
35
36 using namespace std;
37 TEST(E2SM, IndicationMessageEncode)
38 {
39         unsigned char buff[1024];
40         size_t buf_len = 1024;
41
42
43         HWIndicationHeader headerObj;
44         headerObj.set_ricIndicationHeader(1);
45         std::cout << headerObj.get_error() << std::endl;
46
47         HWIndicationMessage messageObj;
48         messageObj.set_hw_message("HelloWorld-E2SM");
49         std::cout << messageObj.get_error() << std::endl;
50
51         E2APIndication<HWIndicationHeader,HWIndicationMessage>::IndicationIEs infoObj;
52         infoObj.set_ranFunctionID(1);
53         infoObj.set_ricActionID(1);
54         infoObj.set_ricRequestorID(1);
55         infoObj.set_ricIndicationHeader(headerObj);
56         infoObj.set_ricIndicationMessage(messageObj);
57
58         E2APIndication<HWIndicationHeader,HWIndicationMessage> e2obj(infoObj);
59
60         bool res = e2obj.encode(buff, &buf_len);
61         if(!res)
62         {
63                 std::cout << e2obj.get_error() << std::endl;
64         }
65         ASSERT_TRUE(res);
66
67
68         FILE * pFile;
69         pFile = fopen ("indication2.per","w");
70         if (pFile!=NULL)
71          {
72                   fwrite (buff , sizeof(char), buf_len, pFile);
73               sleep(2);
74                   fclose (pFile);
75           }
76
77 }
78 TEST(E2SM, IndicationMessageDecode)
79 {
80        unsigned char e2ap_buff[4096];
81        char filename[100] = "indication2.per";
82        FILE *fp;
83        fp = fopen(filename,"rb");
84        if(!fp) {
85                      perror(filename);
86                      exit(1); }
87
88            size_t e2ap_buff_size = fread(e2ap_buff, 1, 4096, fp);
89            fclose(fp);
90        if(!e2ap_buff_size){
91              fprintf(stderr, "%s: Empty or broken\n", filename);
92               exit(1);
93            } else {
94               fprintf(stderr, "e2ap buffer size: %ld \n", e2ap_buff_size);
95        }
96
97     bool decode_status = true;
98     try{
99         E2APIndication<HWIndicationHeader,HWIndicationMessage> e2obj(&e2ap_buff[0],&e2ap_buff_size);
100         E2APIndication<HWIndicationHeader,HWIndicationMessage>::IndicationIEs indIEs = e2obj.getIndicationIEs();
101         std::cout << indIEs.get_ricRequestorID() << std::endl;
102
103         size_t hsize = indIEs.get_ricIndicationHeader_size();
104         unsigned char* hvalue = (unsigned char*)indIEs.get_ricIndicationHeader();
105         HWIndicationHeader headerObj(&hvalue[0], &hsize);
106
107           size_t msize = indIEs.get_ricIndicationMessage_size();
108           auto mvalue = (unsigned char*)indIEs.get_ricIndicationMessage();
109           HWIndicationMessage msgObj(&mvalue[0], &msize);
110
111     } catch(const char* e){
112                 decode_status = false;
113                 std::cout << "Error Message: " << e << std::endl;
114         }
115
116
117         ASSERT_TRUE(decode_status);
118
119 }
120
121 TEST(E2SM, ControlMessage)
122 {
123
124         unsigned char buff[1024];
125         size_t buf_len = 1024;
126
127
128
129         HWControlMessage msgObj;
130         msgObj.set_ricControlMessage("ControlMessage");
131
132         HWControlHeader headObj;
133         headObj.set_ricControlHeader(1);
134
135         E2APControlMessage<HWControlHeader,HWControlMessage>::ControlRequestIEs infoObj;
136         infoObj.set_ranFunctionID(1);
137         infoObj.set_ricRequestorID(1);
138         infoObj.set_ricControlHeader(headObj);
139         infoObj.set_ricControlMessage(msgObj);
140         infoObj.set_ricCallProcessID("ProcessID");
141
142         E2APControlMessage<HWControlHeader,HWControlMessage>  cntrlObj(infoObj);
143
144         bool res = cntrlObj.encode(buff, &buf_len);
145                 if(!res)
146                 {
147                         std::cout << cntrlObj.get_error() << std::endl;
148                 }
149                 ASSERT_TRUE(res);
150 }
151
152 #endif /* TEST_TEST_ASN_H_ */