[RICPLT-1739] Extract and build Load Information Message
[ric-plt/e2mgr.git] / E2Manager / asn1codec / src / tests / x2setup_request_wrapper_test.c
1 /*
2  *
3  * Copyright 2019 AT&T Intellectual Property
4  * Copyright 2019 Nokia
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 //
21 // Copyright 2019 AT&T Intellectual Property
22 // Copyright 2019 Nokia
23 //
24 // Licensed under the Apache License, Version 2.0 (the "License");
25 // you may not use this file except in compliance with the License.
26 // You may obtain a copy of the License at
27 //
28 //      http://www.apache.org/licenses/LICENSE-2.0
29 //
30 // Unless required by applicable law or agreed to in writing, software
31 // distributed under the License is distributed on an "AS IS" BASIS,
32 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 // See the License for the specific language governing permissions and
34 // limitations under the License.
35 //
36 #include <stdbool.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <x2setup_request_wrapper.h>
40
41 void test_build_pack_x2setup_request();
42 void test_build_pack_endc_x2setup_request();
43 void test_unpack(void);
44
45 int
46 main(int argc, char* argv[])
47 {
48     test_build_pack_x2setup_request();
49     test_build_pack_endc_x2setup_request();
50     test_unpack();
51     exit(0);
52 }
53
54 void test_build_pack_x2setup_request(){
55     size_t error_buf_size = 8192;
56     size_t packed_buf_size = 4096;
57     unsigned char responseDataBuf[packed_buf_size];
58     char responseErrorBuf[error_buf_size];
59     uint8_t pLMN_Identity[] = {0xa,0xb,0xc}; 
60     uint8_t ric_flag[] = {0xa,0xd,0xe};
61     uint8_t eNBId[] = {0xab, 0xcd, 0x7/*0xf,0x7,0x2*/};
62     bool result;
63     E2AP_PDU_t *pdu;
64     unsigned int bitqty = 21;
65     /**********************************************************************************/
66
67     printf("\n----- ATS_ALIGNED_BASIC_PER ----\n");
68     packed_buf_size = 4096;
69     result = build_pack_x2setup_request_aux(
70                     pLMN_Identity, eNBId, bitqty , ric_flag,
71                     &packed_buf_size, responseDataBuf, error_buf_size, responseErrorBuf,ATS_ALIGNED_BASIC_PER);
72     if (!result) {
73         printf("#%s failed. Packing error %s\n", __func__, responseErrorBuf);
74         return;
75     }
76     printf("#%s packed size:%lu\nPayload:\n", __func__, packed_buf_size);
77     for (size_t i = 0; i < packed_buf_size; ++i)
78         printf("%02x",responseDataBuf[i]);
79     printf("\n");
80
81     pdu =calloc(1, sizeof(E2AP_PDU_t));
82     if (!unpack_pdu_aux(pdu, packed_buf_size, responseDataBuf,error_buf_size, responseErrorBuf,ATS_ALIGNED_BASIC_PER)){
83         printf("#%s failed. Packing error %s\n", __func__, responseErrorBuf);
84     }
85     responseErrorBuf[0] = 0;
86     asn1_pdu_printer(pdu, sizeof(responseErrorBuf), responseErrorBuf);
87     printf("#%s: 21%s\n", __func__, responseErrorBuf);
88
89     printf("\n----- ATS_UNALIGNED_BASIC_PER ----\n");
90     packed_buf_size = 4096;
91     result = build_pack_x2setup_request_aux(
92                     pLMN_Identity, eNBId, bitqty , ric_flag,
93                     &packed_buf_size, responseDataBuf, error_buf_size, responseErrorBuf,ATS_UNALIGNED_BASIC_PER);
94     if (!result) {
95         printf("#%s failed. Packing error %s\n", __func__, responseErrorBuf);
96         return;
97     }
98     printf("#%s packed size:%lu\nPayload:\n", __func__, packed_buf_size);
99     for (size_t i = 0; i < packed_buf_size; ++i)
100         printf("%02x",responseDataBuf[i]);
101     printf("\n");
102
103     pdu =calloc(1, sizeof(E2AP_PDU_t));
104     if (!unpack_pdu_aux(pdu, packed_buf_size, responseDataBuf,error_buf_size, responseErrorBuf,ATS_UNALIGNED_BASIC_PER)){
105         printf("#%s failed. Packing error %s\n", __func__, responseErrorBuf);
106     }
107     responseErrorBuf[0] = 0;
108     asn1_pdu_printer(pdu, sizeof(responseErrorBuf), responseErrorBuf);
109     printf("#%s: 21%s\n", __func__, responseErrorBuf);
110 }
111
112 void test_build_pack_endc_x2setup_request(){
113         size_t error_buf_size = 8192;
114         size_t packed_buf_size = 4096;
115         unsigned char responseDataBuf[packed_buf_size];
116     uint8_t pLMN_Identity[] = {0xa,0xb,0xc};
117     uint8_t ric_flag[] = {0xa,0xd,0xe};
118     uint8_t eNBId[] = {0xf,0x7,0x2};
119     unsigned int bitqty=18;
120
121         char responseErrorBuf[error_buf_size];
122         bool result = build_pack_endc_x2setup_request(
123                         pLMN_Identity, eNBId, bitqty , ric_flag,
124                         &packed_buf_size, responseDataBuf, error_buf_size, responseErrorBuf);
125     if (!result) {
126         printf("#%s. Packing error %s\n", __func__, responseErrorBuf);
127         return;
128     }
129     printf("#%s packed size:%lu\nPayload:\n", __func__, packed_buf_size);
130     for (size_t i = 0; i < packed_buf_size; ++i)
131         printf("%02x",responseDataBuf[i]);
132     printf("\n");
133 }
134
135 void test_unpack(void)
136 {
137         return; // No need for now.
138         char responseErrorBuf[8192];
139         printf("\n--------------- case #1\n\n");
140         {
141                 uint8_t buf[] = {0x00,0x24,0x00,0x32,0x00,0x00,0x01,0x00,0xf4,0x00,0x2b,0x00,0x00,0x02,0x00,0x15,0x00,0x09,0x00,0xbb,0xbc,0xcc,0x80,0x03,0xab,0xcd,0x80,0x00,0xfa,0x00,0x17,0x00,0x00,0x01,0xf7,0x00,0xbb,0xbc,0xcc,0xab,0xcd,0x80,0x00,0x00,0x00,0xbb,0xbc,0xcc,0x00,0x00,0x00,0x00,0x00,0x01};
142                 E2AP_PDU_t *pdu =calloc(1, sizeof(E2AP_PDU_t));
143                 if (!unpack_pdu_aux(pdu, sizeof(buf), buf ,sizeof(responseErrorBuf), responseErrorBuf,ATS_ALIGNED_BASIC_PER)){
144                         printf("#%s failed. Packing error %s\n", __func__, responseErrorBuf);
145                 }
146
147                 responseErrorBuf[0] = 0;
148                 asn1_pdu_printer(pdu, sizeof(responseErrorBuf), responseErrorBuf);
149                 printf("#%s: %s\n", __func__, responseErrorBuf);
150         }
151
152         printf("\n--------------- case #2\n\n");
153         {
154                 uint8_t buf[] = {0x00,0x06,0x00,0x2b,0x00,0x00,0x02,0x00,0x15,0x00,0x09,0x00,0x0a,0x0b,0x0c,0x81,0x03,0xab,0xcd,0xc0,0x00,0x14,0x00,0x17,0x00,0x00,0x01,0xf7,0x00,0x0a,0x0b,0x0c,0xab,0xcd,0xc0,0x00,0x00,0x00,0x0a,0x0d,0x0e,0x00,0x00,0x00,0x00,0x00,0x01};
155                 E2AP_PDU_t *pdu =calloc(1, sizeof(E2AP_PDU_t));
156                 if (!unpack_pdu_aux(pdu, sizeof(buf), buf ,sizeof(responseErrorBuf), responseErrorBuf,ATS_ALIGNED_BASIC_PER)){
157                         printf("#%s failed. Packing error %s\n", __func__, responseErrorBuf);
158                 }
159
160                 responseErrorBuf[0] = 0;
161                 asn1_pdu_printer(pdu, sizeof(responseErrorBuf), responseErrorBuf);
162                 printf("#%s: %s\n", __func__, responseErrorBuf);
163         }
164 }