[RICPLT-1703] - Reset Request + rmr_service refactoring (disabled)
[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 #include <stdbool.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <x2setup_request_wrapper.h>
25
26 void test_build_pack_x2setup_request();
27 void test_build_pack_endc_x2setup_request();
28 void test_unpack(void);
29
30 int
31 main(int argc, char* argv[])
32 {
33     test_build_pack_x2setup_request();
34     test_build_pack_endc_x2setup_request();
35     test_unpack();
36     exit(0);
37 }
38
39 void test_build_pack_x2setup_request(){
40     size_t error_buf_size = 8192;
41     size_t packed_buf_size = 4096;
42     unsigned char responseDataBuf[packed_buf_size];
43     char responseErrorBuf[error_buf_size];
44     uint8_t pLMN_Identity[] = {0xa,0xb,0xc}; 
45     uint8_t ric_flag[] = {0xa,0xd,0xe};
46     uint8_t eNBId[] = {0xab, 0xcd, 0x7/*0xf,0x7,0x2*/};
47     bool result;
48     E2AP_PDU_t *pdu;
49     unsigned int bitqty = 21;
50     /**********************************************************************************/
51
52     printf("\n----- ATS_ALIGNED_BASIC_PER ----\n");
53     packed_buf_size = 4096;
54     result = build_pack_x2setup_request_aux(
55                     pLMN_Identity, eNBId, bitqty , ric_flag,
56                     &packed_buf_size, responseDataBuf, error_buf_size, responseErrorBuf,ATS_ALIGNED_BASIC_PER);
57     if (!result) {
58         printf("#%s failed. Packing error %s\n", __func__, responseErrorBuf);
59         return;
60     }
61     printf("#%s packed size:%lu\nPayload:\n", __func__, packed_buf_size);
62     for (size_t i = 0; i < packed_buf_size; ++i)
63         printf("%02x",responseDataBuf[i]);
64     printf("\n");
65
66     pdu =calloc(1, sizeof(E2AP_PDU_t));
67     if (!unpack_pdu_aux(pdu, packed_buf_size, responseDataBuf,error_buf_size, responseErrorBuf,ATS_ALIGNED_BASIC_PER)){
68         printf("#%s failed. Packing error %s\n", __func__, responseErrorBuf);
69     }
70     responseErrorBuf[0] = 0;
71     asn1_pdu_printer(pdu, sizeof(responseErrorBuf), responseErrorBuf);
72     printf("#%s: 21%s\n", __func__, responseErrorBuf);
73
74     printf("\n----- ATS_UNALIGNED_BASIC_PER ----\n");
75     packed_buf_size = 4096;
76     result = build_pack_x2setup_request_aux(
77                     pLMN_Identity, eNBId, bitqty , ric_flag,
78                     &packed_buf_size, responseDataBuf, error_buf_size, responseErrorBuf,ATS_UNALIGNED_BASIC_PER);
79     if (!result) {
80         printf("#%s failed. Packing error %s\n", __func__, responseErrorBuf);
81         return;
82     }
83     printf("#%s packed size:%lu\nPayload:\n", __func__, packed_buf_size);
84     for (size_t i = 0; i < packed_buf_size; ++i)
85         printf("%02x",responseDataBuf[i]);
86     printf("\n");
87
88     pdu =calloc(1, sizeof(E2AP_PDU_t));
89     if (!unpack_pdu_aux(pdu, packed_buf_size, responseDataBuf,error_buf_size, responseErrorBuf,ATS_UNALIGNED_BASIC_PER)){
90         printf("#%s failed. Packing error %s\n", __func__, responseErrorBuf);
91     }
92     responseErrorBuf[0] = 0;
93     asn1_pdu_printer(pdu, sizeof(responseErrorBuf), responseErrorBuf);
94     printf("#%s: 21%s\n", __func__, responseErrorBuf);
95 }
96
97 void test_build_pack_endc_x2setup_request(){
98         size_t error_buf_size = 8192;
99         size_t packed_buf_size = 4096;
100         unsigned char responseDataBuf[packed_buf_size];
101     uint8_t pLMN_Identity[] = {0xa,0xb,0xc};
102     uint8_t ric_flag[] = {0xa,0xd,0xe};
103     uint8_t eNBId[] = {0xf,0x7,0x2};
104     unsigned int bitqty=18;
105
106         char responseErrorBuf[error_buf_size];
107         bool result = build_pack_endc_x2setup_request(
108                         pLMN_Identity, eNBId, bitqty , ric_flag,
109                         &packed_buf_size, responseDataBuf, error_buf_size, responseErrorBuf);
110     if (!result) {
111         printf("#%s. Packing error %s\n", __func__, responseErrorBuf);
112         return;
113     }
114     printf("#%s packed size:%lu\nPayload:\n", __func__, packed_buf_size);
115     for (size_t i = 0; i < packed_buf_size; ++i)
116         printf("%02x",responseDataBuf[i]);
117     printf("\n");
118 }
119
120 void test_unpack(void)
121 {
122         return; // No need for now.
123         char responseErrorBuf[8192];
124         printf("\n--------------- case #1\n\n");
125         {
126                 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};
127                 E2AP_PDU_t *pdu =calloc(1, sizeof(E2AP_PDU_t));
128                 if (!unpack_pdu_aux(pdu, sizeof(buf), buf ,sizeof(responseErrorBuf), responseErrorBuf,ATS_ALIGNED_BASIC_PER)){
129                         printf("#%s failed. Packing error %s\n", __func__, responseErrorBuf);
130                 }
131
132                 responseErrorBuf[0] = 0;
133                 asn1_pdu_printer(pdu, sizeof(responseErrorBuf), responseErrorBuf);
134                 printf("#%s: %s\n", __func__, responseErrorBuf);
135         }
136
137         printf("\n--------------- case #2\n\n");
138         {
139                 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};
140                 E2AP_PDU_t *pdu =calloc(1, sizeof(E2AP_PDU_t));
141                 if (!unpack_pdu_aux(pdu, sizeof(buf), buf ,sizeof(responseErrorBuf), responseErrorBuf,ATS_ALIGNED_BASIC_PER)){
142                         printf("#%s failed. Packing error %s\n", __func__, responseErrorBuf);
143                 }
144
145                 responseErrorBuf[0] = 0;
146                 asn1_pdu_printer(pdu, sizeof(responseErrorBuf), responseErrorBuf);
147                 printf("#%s: %s\n", __func__, responseErrorBuf);
148         }
149 }