Copy latest code to master
[ric-plt/resource-status-manager.git] / RSM / 3rdparty / asn1codec / src / tests / resource_status_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 <resource_status_request_wrapper.h>
29
30     void test_build_pack_resource_status_request();
31     void test_build_pack_resource_status_request_stop();
32     void test_unpack(void);
33
34     int
35     main(int argc, char* argv[])
36     {
37         test_build_pack_resource_status_request();
38         test_build_pack_resource_status_request_stop();
39         exit(0);
40     }
41
42     /*reportCharacteristics:
43 1)    First Bit = PRB Periodic,
44 2)    Second Bit = TNL load Ind Periodic,
45 3)    Third Bit = HW Load Ind Periodic,
46 4)    Fourth Bit = Composite Available Capacity Periodic, this bit should be set to 1 if at least one of the First, Second
47 or Third bits is set to 1,
48 5)    Fifth Bit = ABS Status Periodic,
49 6)    Sixth Bit = RSRP Measurement Report Periodic,
50 7)    Seventh Bit = CSI Report Periodic
51      */
52     void test_build_pack_resource_status_request(){
53         size_t error_buf_size = 8192;
54         size_t packed_buf_size = 4096;
55         unsigned char outBuf[packed_buf_size];
56         char errorBuf[error_buf_size];
57         const uint8_t pLMN_Identity[] = {0xa,0xb,0xc};
58         const uint8_t eUTRANCellIdentifier[] = {0xab, 0xcd, 0x70, 0};
59         const uint8_t *pLMN_Identities[] = {pLMN_Identity};
60         const uint8_t *eUTRANCellIdentifiers[] = {eUTRANCellIdentifier};
61         E2AP_PDU_t *pdu;
62
63         bool result = build_pack_resource_status_request(
64                         pLMN_Identities, eUTRANCellIdentifiers, 1,
65                         15 /*measurement_ID*/, 0  /*measurement_ID2*/,
66                                 Registration_Request_start /*Registration_Request_start,Registration_Request_stop,Registration_Request_partial_stop, Registration_Request_add*/,
67                         0xf0,
68                                 ReportingPeriodicity_one_thousand_ms /*ReportingPeriodicity_one_thousand_ms, ReportingPeriodicity_two_thousand_ms, ReportingPeriodicity_five_thousand_ms,ReportingPeriodicity_ten_thousand_ms*/,
69                                 PartialSuccessIndicator_partial_success_allowed /*PartialSuccessIndicator_partial_success_allowed*/,
70                                 ReportingPeriodicityRSRPMR_one_hundred_20_ms /*ReportingPeriodicityRSRPMR_one_hundred_20_ms, ReportingPeriodicityRSRPMR_two_hundred_40_ms, ReportingPeriodicityRSRPMR_four_hundred_80_ms,ReportingPeriodicityRSRPMR_six_hundred_40_ms*/,
71                                 ReportingPeriodicityCSIR_ms5 /* ReportingPeriodicityCSIR_ms5, ReportingPeriodicityCSIR_ms10,ReportingPeriodicityCSIR_ms20,ReportingPeriodicityCSIR_ms40,ReportingPeriodicityCSIR_ms80*/,
72                         &packed_buf_size, outBuf, error_buf_size, errorBuf);
73
74         if (!result) {
75             printf("#%s failed. Packing error %s\n", __func__,errorBuf);
76             return;
77         }
78         printf("packed size:%lu\nPayload:\n", packed_buf_size);
79         for (size_t i = 0; i < packed_buf_size; ++i)
80             printf("%02x",outBuf[i]);
81         printf("\n");
82
83         pdu = calloc(1, sizeof(E2AP_PDU_t));
84         if (!unpack_pdu_aux(pdu, packed_buf_size, outBuf,error_buf_size, errorBuf,ATS_ALIGNED_BASIC_PER)){
85                 printf("#%s failed. Unpacking error %s\n", __func__, errorBuf);
86         }
87         errorBuf[0] = 0;
88         asn1_pdu_printer(pdu, sizeof(errorBuf), errorBuf);
89         printf("#%s: %s\n", __func__, errorBuf);
90
91     }
92
93 void test_build_pack_resource_status_request_stop(){
94         size_t error_buf_size = 8192;
95         size_t packed_buf_size = 4096;
96         unsigned char outBuf[packed_buf_size];
97         char errorBuf[error_buf_size];
98         const uint8_t pLMN_Identity[] = {0xa,0xb,0xc};
99         const uint8_t eUTRANCellIdentifier[] = {0xab, 0xcd, 0x70, 0};
100         const uint8_t *pLMN_Identities[] = {pLMN_Identity};
101         const uint8_t *eUTRANCellIdentifiers[] = {eUTRANCellIdentifier};
102         E2AP_PDU_t *pdu;
103
104         bool result = build_pack_resource_status_request(
105                         pLMN_Identities, eUTRANCellIdentifiers, 1,
106                         15 /*measurement_ID*/, 2  /*measurement_ID2*/,
107                                 Registration_Request_stop /*Registration_Request_start,Registration_Request_stop,Registration_Request_partial_stop, Registration_Request_add*/,
108                         0,
109                                 ReportingPeriodicity_one_thousand_ms /*ReportingPeriodicity_one_thousand_ms, ReportingPeriodicity_two_thousand_ms, ReportingPeriodicity_five_thousand_ms,ReportingPeriodicity_ten_thousand_ms*/,
110                                 PartialSuccessIndicator_partial_success_allowed /*PartialSuccessIndicator_partial_success_allowed*/,
111                                 ReportingPeriodicityRSRPMR_one_hundred_20_ms /*ReportingPeriodicityRSRPMR_one_hundred_20_ms, ReportingPeriodicityRSRPMR_two_hundred_40_ms, ReportingPeriodicityRSRPMR_four_hundred_80_ms,ReportingPeriodicityRSRPMR_six_hundred_40_ms*/,
112                                 ReportingPeriodicityCSIR_ms5 /* ReportingPeriodicityCSIR_ms5, ReportingPeriodicityCSIR_ms10,ReportingPeriodicityCSIR_ms20,ReportingPeriodicityCSIR_ms40,ReportingPeriodicityCSIR_ms80*/,
113                         &packed_buf_size, outBuf, error_buf_size, errorBuf);
114
115         if (!result) {
116             printf("#%s failed. Packing error %s\n", __func__,errorBuf);
117             return;
118         }
119         printf("packed size:%lu\nPayload:\n", packed_buf_size);
120         for (size_t i = 0; i < packed_buf_size; ++i)
121             printf("%02x",outBuf[i]);
122         printf("\n");
123
124         pdu = calloc(1, sizeof(E2AP_PDU_t));
125         if (!unpack_pdu_aux(pdu, packed_buf_size, outBuf,error_buf_size, errorBuf,ATS_ALIGNED_BASIC_PER)){
126                 printf("#%s failed. Unpacking error %s\n", __func__, errorBuf);
127         }
128         errorBuf[0] = 0;
129         asn1_pdu_printer(pdu, sizeof(errorBuf), errorBuf);
130         printf("#%s: %s\n", __func__, errorBuf);
131
132     }
133