7164074257b78ce8c2384582e77b089843d15ab7
[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   
50   SECTION("Verify E2AP Control Encoding/Decoding Successful"){
51     
52     dinput.func_id = 10;
53     dinput.req_id = 6;
54     dinput.req_seq_no = 11;
55     dinput.control_ack = 1;
56   
57     strcpy((char *)buf_header, "hello world");
58     strcpy((char *)buf_msg, "something out there");
59     unsigned char buf_proc_id[4] = "25";
60   
61     dinput.control_header = buf_header;
62     dinput.control_header_size = strlen((const char *)buf_header);
63     
64     dinput.control_msg = buf_msg;
65     dinput.control_msg_size = strlen((const char *)buf_msg);
66     
67     dinput.call_process_id = buf_proc_id;
68     dinput.call_process_id_size = strlen((const char *)buf_proc_id);
69     
70     /* encoding */
71     size_t data_size = 4096;
72     unsigned char       data[data_size];
73   
74     bool res = control_request_pdu.encode_e2ap_control_request(&data[0], &data_size, dinput);
75     REQUIRE(res == true);
76
77     E2N_E2AP_PDU_t * e2ap_recv = 0;
78     asn_dec_rval_t dec_res  = asn_decode(0,ATS_ALIGNED_BASIC_PER, &asn_DEF_E2N_E2AP_PDU, (void**)&(e2ap_recv), data, data_size);
79     REQUIRE(dec_res.code == RC_OK);
80     
81     res = control_request_pdu.get_fields(e2ap_recv->choice.initiatingMessage, dout);
82     REQUIRE (res == true);
83
84     REQUIRE(dinput.func_id == dout.func_id);
85     REQUIRE(dinput.req_id == dout.req_id);
86     REQUIRE(dinput.req_seq_no == dout.req_seq_no);
87     REQUIRE(dinput.control_ack == dout.control_ack);
88
89     std::string din_string;
90     std::string dout_string;
91
92     din_string.assign((char *)dinput.control_header, dout.control_header_size);
93     dout_string.assign((char *)dout.control_header, dout.control_header_size);
94     REQUIRE(din_string == dout_string);
95    
96     ASN_STRUCT_FREE(asn_DEF_E2N_E2AP_PDU, e2ap_recv); 
97     
98   }
99
100   SECTION("Negative Cases"){
101     bool res = control_request_pdu.get_fields(NULL, dout);
102     REQUIRE(res == false);
103   }
104 }
105
106
107 TEST_CASE("E2AP Control Response", "Encoding/Decoding"){
108
109   ric_control_helper dinput ;
110   ric_control_helper  dout;
111   ric_control_response control_response_pdu;
112   
113   mdclog_attr_t *attr;
114   mdclog_attr_init(&attr);
115   mdclog_attr_set_ident(attr, "UNIT TEST E2AP INDICATION");
116   mdclog_init(attr);
117   mdclog_level_set(MDCLOG_INFO);
118   mdclog_attr_destroy(attr);
119
120   ric_control_response test_check;
121
122   SECTION("Verify E2AP Control Response Successful Outcome Encoding/Decoding"){
123     
124     dinput.func_id = 10;
125     dinput.req_id = 6;
126     dinput.req_seq_no = 11;
127     dinput.control_status = 1;
128     dinput.cause = 1;
129     dinput.sub_cause = 2;
130
131
132     ric_control_helper dout;
133     unsigned char buf_proc_id[4] = "25";
134
135     dinput.call_process_id = buf_proc_id;
136     dinput.call_process_id_size = strlen((const char *)buf_proc_id);
137     
138     /* encoding */
139     size_t data_size = 4096;
140     unsigned char data[data_size];
141     
142     ric_control_response control_response_pdu;
143
144     bool res = control_response_pdu.encode_e2ap_control_response(&data[0], &data_size, dinput, true);
145
146     REQUIRE(res == true);
147     
148     /* decoding */
149     E2N_E2AP_PDU_t * e2ap_recv = 0;
150     asn_dec_rval_t dec_res  = asn_decode(0,ATS_ALIGNED_BASIC_PER, &asn_DEF_E2N_E2AP_PDU, (void**)&(e2ap_recv), data, data_size);
151     REQUIRE(dec_res.code == RC_OK);
152     REQUIRE(e2ap_recv->present ==  E2N_E2AP_PDU_PR_successfulOutcome);
153     res =   control_response_pdu.get_fields(e2ap_recv->choice.successfulOutcome, dout);
154     REQUIRE(res == true);
155     REQUIRE(dout.func_id == dinput.func_id);
156     REQUIRE(dout.req_id == dinput.req_id);
157     REQUIRE(dout.control_status == dinput.control_status);
158     
159     ASN_STRUCT_FREE(asn_DEF_E2N_E2AP_PDU, e2ap_recv);
160   }
161
162   
163   SECTION("Verify E2AP Control Response UnSuccessful Outcome Encoding/Decoding"){
164     
165     dinput.func_id = 10;
166     dinput.req_id = 6;
167     dinput.req_seq_no = 11;
168     dinput.control_status = 1;
169     dinput.cause = 1;
170     dinput.sub_cause = 2;
171
172
173     ric_control_helper dout;
174     unsigned char buf_proc_id[4] = "25";
175
176     dinput.call_process_id = buf_proc_id;
177     dinput.call_process_id_size = strlen((const char *)buf_proc_id);
178     
179     /* encoding */
180     size_t data_size = 4096;
181     unsigned char data[data_size];
182     
183     ric_control_response control_response_pdu;
184     bool res = control_response_pdu.encode_e2ap_control_response(&data[0], &data_size, dinput, false);
185     REQUIRE(res == true);
186     
187     /* decoding */
188     E2N_E2AP_PDU_t * e2ap_recv = 0;
189     asn_dec_rval_t dec_res  = asn_decode(0,ATS_ALIGNED_BASIC_PER, &asn_DEF_E2N_E2AP_PDU, (void**)&(e2ap_recv), data, data_size);
190     REQUIRE(dec_res.code == RC_OK);
191     REQUIRE(e2ap_recv->present ==  E2N_E2AP_PDU_PR_unsuccessfulOutcome);
192     res =   control_response_pdu.get_fields(e2ap_recv->choice.unsuccessfulOutcome, dout);
193
194     REQUIRE(res == true);
195     REQUIRE(dout.func_id == dinput.func_id);
196     REQUIRE(dout.req_id == dinput.req_id);
197     REQUIRE(dout.control_status == dinput.control_status);
198     REQUIRE(dout.cause == dinput.cause);
199     REQUIRE(dout.sub_cause == dinput.sub_cause);
200     ASN_STRUCT_FREE(asn_DEF_E2N_E2AP_PDU, e2ap_recv);
201   }
202
203 }