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