Updated documentation for mock a1 tool
[ric-app/admin.git] / test / unit_test_e2ap_control.cc
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
20 #define CATCH_CONFIG_MAIN
21 #include <catch2/catch.hpp>
22
23 #include <stdbool.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <e2ap_control.hpp>
27 #include <e2ap_control_response.hpp>
28 #include <unistd.h>
29 #include <inttypes.h>
30
31
32 #define BUFFER_SIZE 512
33
34 TEST_CASE("E2AP Control Request", "Encoding/Decoding"){
35
36   ric_control_helper dinput ;
37   ric_control_helper  dout;
38   ric_control_request control_request_pdu;
39   
40   mdclog_attr_t *attr;
41   mdclog_attr_init(&attr);
42   mdclog_attr_set_ident(attr, "UNIT TEST E2AP INDICATION");
43   mdclog_init(attr);
44   mdclog_level_set(MDCLOG_ERR);
45   mdclog_attr_destroy(attr);
46
47   unsigned char buf_header[BUFFER_SIZE];
48   unsigned char buf_msg[BUFFER_SIZE];
49   unsigned char buf_callproc[BUFFER_SIZE];
50   
51   SECTION("Verify E2AP Control Encoding/Decoding Successful"){
52     
53     dinput.func_id = 10;
54     dinput.req_id = 6;
55     dinput.req_seq_no = 11;
56     dinput.control_ack = 1;
57   
58     strcpy((char *)buf_header, "hello world");
59     strcpy((char *)buf_msg, "something out there");
60     strcpy((char *)buf_callproc, "Call Process ID = 20");
61     
62     dinput.control_header = buf_header;
63     dinput.control_header_size = strlen((const char *)buf_header);
64     
65     dinput.control_msg = buf_msg;
66     dinput.control_msg_size = strlen((const char *)buf_msg);
67     
68     dinput.call_process_id = buf_callproc;
69     dinput.call_process_id_size = strlen((const char *)buf_callproc);
70     
71     
72     /* encoding */
73     size_t data_size = 4096;
74     unsigned char       data[data_size];
75   
76     bool res = control_request_pdu.encode_e2ap_control_request(&data[0], &data_size, dinput);
77     REQUIRE(res == true);
78
79     E2N_E2AP_PDU_t * e2ap_recv = 0;
80     asn_dec_rval_t dec_res  = asn_decode(0,ATS_ALIGNED_BASIC_PER, &asn_DEF_E2N_E2AP_PDU, (void**)&(e2ap_recv), data, data_size);
81     if(dec_res.code != RC_OK)
82       std::cerr <<"Error = " << strerror(errno) << std::endl;
83
84     REQUIRE(dec_res.code == RC_OK);
85     
86     res = control_request_pdu.get_fields(e2ap_recv->choice.initiatingMessage, dout);
87     REQUIRE (res == true);
88
89     REQUIRE(dinput.func_id == dout.func_id);
90     REQUIRE(dinput.req_id == dout.req_id);
91     REQUIRE(dinput.req_seq_no == dout.req_seq_no);
92     REQUIRE(dinput.control_ack == dout.control_ack);
93
94     std::string din_string;
95     std::string dout_string;
96
97     din_string.assign((char *)dinput.control_header, dout.control_header_size);
98     dout_string.assign((char *)dout.control_header, dout.control_header_size);
99     REQUIRE(din_string == dout_string);
100
101     din_string.assign((char *)dinput.control_msg, dout.control_msg_size);
102     dout_string.assign((char *)dout.control_msg, dout.control_msg_size);
103     REQUIRE(din_string == dout_string);
104
105     din_string.assign((char *)dinput.call_process_id, dout.call_process_id_size);
106     dout_string.assign((char *)dout.call_process_id, dout.call_process_id_size);
107     REQUIRE(din_string == dout_string);
108
109     
110    
111     ASN_STRUCT_FREE(asn_DEF_E2N_E2AP_PDU, e2ap_recv); 
112     
113   }
114
115   SECTION("Negative Cases"){
116     bool res = control_request_pdu.get_fields(NULL, dout);
117     REQUIRE(res == false);
118   }
119 }
120
121
122 TEST_CASE("E2AP Control Response", "Encoding/Decoding"){
123
124   ric_control_helper dinput ;
125   ric_control_helper  dout;
126   ric_control_response control_response_pdu;
127   
128   mdclog_attr_t *attr;
129   mdclog_attr_init(&attr);
130   mdclog_attr_set_ident(attr, "UNIT TEST E2AP INDICATION");
131   mdclog_init(attr);
132   mdclog_level_set(MDCLOG_INFO);
133   mdclog_attr_destroy(attr);
134
135   ric_control_response test_check;
136
137   SECTION("Verify E2AP Control Response Successful Outcome Encoding/Decoding"){
138     
139     dinput.func_id = 10;
140     dinput.req_id = 6;
141     dinput.req_seq_no = 11;
142     dinput.control_status = 1;
143     dinput.cause = 1;
144     dinput.sub_cause = 2;
145
146
147     ric_control_helper dout;
148     unsigned char buf_proc_id[4] = "25";
149
150     dinput.call_process_id = buf_proc_id;
151     dinput.call_process_id_size = strlen((const char *)buf_proc_id);
152     
153     /* encoding */
154     size_t data_size = 4096;
155     unsigned char data[data_size];
156     
157     ric_control_response control_response_pdu;
158
159     bool res = control_response_pdu.encode_e2ap_control_response(&data[0], &data_size, dinput, true);
160
161     REQUIRE(res == true);
162     
163     /* decoding */
164     E2N_E2AP_PDU_t * e2ap_recv = 0;
165     asn_dec_rval_t dec_res  = asn_decode(0,ATS_ALIGNED_BASIC_PER, &asn_DEF_E2N_E2AP_PDU, (void**)&(e2ap_recv), data, data_size);
166     REQUIRE(dec_res.code == RC_OK);
167     REQUIRE(e2ap_recv->present ==  E2N_E2AP_PDU_PR_successfulOutcome);
168     res =   control_response_pdu.get_fields(e2ap_recv->choice.successfulOutcome, dout);
169     REQUIRE(res == true);
170     REQUIRE(dout.func_id == dinput.func_id);
171     REQUIRE(dout.req_id == dinput.req_id);
172     REQUIRE(dout.control_status == dinput.control_status);
173     
174     ASN_STRUCT_FREE(asn_DEF_E2N_E2AP_PDU, e2ap_recv);
175   }
176
177   
178   SECTION("Verify E2AP Control Response UnSuccessful Outcome Encoding/Decoding"){
179     
180     dinput.func_id = 10;
181     dinput.req_id = 6;
182     dinput.req_seq_no = 11;
183     dinput.control_status = 1;
184     dinput.cause = 1;
185     dinput.sub_cause = 2;
186
187
188     ric_control_helper dout;
189     unsigned char buf_proc_id[4] = "25";
190
191     dinput.call_process_id = buf_proc_id;
192     dinput.call_process_id_size = strlen((const char *)buf_proc_id);
193     
194     /* encoding */
195     size_t data_size = 4096;
196     unsigned char data[data_size];
197     
198     ric_control_response control_response_pdu;
199     bool res = control_response_pdu.encode_e2ap_control_response(&data[0], &data_size, dinput, false);
200     REQUIRE(res == true);
201     
202     /* decoding */
203     E2N_E2AP_PDU_t * e2ap_recv = 0;
204     asn_dec_rval_t dec_res  = asn_decode(0,ATS_ALIGNED_BASIC_PER, &asn_DEF_E2N_E2AP_PDU, (void**)&(e2ap_recv), data, data_size);
205     REQUIRE(dec_res.code == RC_OK);
206     REQUIRE(e2ap_recv->present ==  E2N_E2AP_PDU_PR_unsuccessfulOutcome);
207     res =   control_response_pdu.get_fields(e2ap_recv->choice.unsuccessfulOutcome, dout);
208
209     REQUIRE(res == true);
210     REQUIRE(dout.func_id == dinput.func_id);
211     REQUIRE(dout.req_id == dinput.req_id);
212     REQUIRE(dout.control_status == dinput.control_status);
213     REQUIRE(dout.cause == dinput.cause);
214     REQUIRE(dout.sub_cause == dinput.sub_cause);
215     ASN_STRUCT_FREE(asn_DEF_E2N_E2AP_PDU, e2ap_recv);
216   }
217
218 }