* INTC Contribution to the O-RAN F Release for O-DU Low
[o-du/phy.git] / fhi_lib / test / test_xran / u_plane_functional.cc
1 /******************************************************************************
2 *
3 *   Copyright (c) 2020 Intel.
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 #include "common.hpp"
20 #include "xran_common.h"
21 #include "xran_up_api.h"
22 #include "xran_fh_o_du.h"
23 #include "ethernet.h"
24
25 #include <stdint.h>
26
27 const std::string module_name = "u-plane";
28
29 class U_planeCheck : public KernelTests
30 {
31 protected:
32     struct rte_mbuf *test_buffer;
33     char * iq_offset;
34     struct rte_mempool *test_eth_mbuf_pool;
35
36     void SetUp() override
37     {
38         init_test("u_plane_functional");
39         test_buffer = (struct rte_mbuf*)rte_pktmbuf_alloc(_eth_mbuf_pool);
40
41         if(test_buffer == NULL) {
42             std::cout << __func__ << ":" << __LINE__ << " Failed to allocatte a packet buffer!" << std::endl;
43             return;
44         }
45         iq_offset = rte_pktmbuf_mtod(test_buffer, char * );
46         iq_offset = iq_offset + sizeof(struct rte_ether_hdr) +
47                                     sizeof (struct xran_ecpri_hdr) +
48                                     sizeof (struct radio_app_common_hdr) +
49                                     sizeof(struct data_section_hdr);
50     }
51
52     /* It's called after an execution of the each test case.*/
53     void TearDown() override
54     {
55         rte_pktmbuf_free(test_buffer);
56     }
57 };
58
59 /* simple test of DL and UL functionality */
60 TEST_P(U_planeCheck, Test_DLUL)
61 {
62     enum xran_pkt_dir direction =  XRAN_DIR_DL;
63     uint16_t section_id = 7;
64     uint16_t num_sections = 1;
65     enum xran_input_byte_order iq_buf_byte_order = XRAN_CPU_LE_BYTE_ORDER;
66     uint8_t frame_id = 99;
67     uint8_t subframe_id  = 9;
68     uint8_t slot_id = 10;
69     uint8_t symbol_no = 7;
70     int prb_start = 0;
71     int prb_num = 66;
72     uint8_t CC_ID = 0;
73     uint8_t RU_Port_ID = 0;
74     uint8_t seq_id =0;
75     uint32_t do_copy = 0;
76     uint8_t compMeth = 0;
77     enum xran_comp_hdr_type staticEn = XRAN_COMP_HDR_TYPE_DYNAMIC;
78     uint8_t iqWidth =  16;
79
80     int32_t prep_bytes;
81     struct xran_ecpri_hdr *ecpri_hdr = NULL;
82     struct radio_app_common_hdr *app_hdr = NULL;
83     struct data_section_hdr *section_hdr = NULL;
84
85     char *pChar = NULL;
86     uint16_t payl_size = 0;
87     struct data_section_hdr res_sect;
88
89     prep_bytes = prepare_symbol_ex(direction,
90                                 section_id,
91                                 test_buffer,
92                                 (uint8_t *)iq_offset,
93                                 compMeth,
94                                 iqWidth,
95                                 iq_buf_byte_order,
96                                 frame_id,
97                                 subframe_id,
98                                 slot_id,
99                                 symbol_no,
100                                 prb_start,
101                                 prb_num,
102                                 CC_ID,
103                                 RU_Port_ID,
104                                 seq_id,
105                                 do_copy,
106                                 staticEn,
107                                 num_sections,
108                                 0);
109
110     ASSERT_EQ(prep_bytes, 3168);
111
112     pChar = rte_pktmbuf_mtod(test_buffer, char*);
113
114     ecpri_hdr = (struct xran_ecpri_hdr *)(pChar + sizeof(struct rte_ether_hdr));
115     app_hdr = (struct radio_app_common_hdr *)(pChar + sizeof(struct rte_ether_hdr)
116                                               + sizeof (struct xran_ecpri_hdr));
117     section_hdr = (struct data_section_hdr *)(pChar + sizeof(struct rte_ether_hdr) +
118                                             sizeof (struct xran_ecpri_hdr) +
119                                             sizeof(struct radio_app_common_hdr));
120
121     ASSERT_EQ (ecpri_hdr->cmnhdr.bits.ecpri_mesg_type,  ECPRI_IQ_DATA);
122     payl_size =  rte_be_to_cpu_16(ecpri_hdr->cmnhdr.bits.ecpri_payl_size);
123     ASSERT_EQ (payl_size,  3180);
124
125     ASSERT_EQ(app_hdr->data_feature.data_direction, direction);
126     ASSERT_EQ(app_hdr->frame_id, frame_id);
127
128     res_sect.fields.all_bits = rte_be_to_cpu_32(section_hdr->fields.all_bits);
129     ASSERT_EQ(res_sect.fields.num_prbu, prb_num);
130     ASSERT_EQ(res_sect.fields.sect_id, section_id);
131
132     {
133         /* UL direction */
134         void *iq_samp_buf;
135         union ecpri_seq_id seq;
136         int num_bytes = 0;
137
138         uint8_t CC_ID = 0;
139         uint8_t Ant_ID = 0;
140         uint8_t frame_id = 0;
141         uint8_t subframe_id = 0;
142         uint8_t slot_id = 0;
143         uint8_t symb_id = 0;
144
145         uint8_t compMeth = 0;
146         uint8_t iqWidth = 0;
147
148
149         uint16_t num_prbu;
150         uint16_t start_prbu;
151         uint16_t sym_inc;
152         uint16_t rb;
153         uint16_t sect_id;
154
155         int32_t prep_bytes;
156
157         char *pChar = NULL;
158
159
160         num_bytes = xran_extract_iq_samples(test_buffer,
161                                 &iq_samp_buf,
162                                 &CC_ID,
163                                 &Ant_ID,
164                                 &frame_id,
165                                 &subframe_id,
166                                 &slot_id,
167                                 &symb_id,
168                                 &seq,
169                                 &num_prbu,
170                                 &start_prbu,
171                                 &sym_inc,
172                                 &rb,
173                                 &sect_id,
174                                 0,
175                                 XRAN_COMP_HDR_TYPE_DYNAMIC,
176                                 &compMeth,
177                                 &iqWidth);
178
179         ASSERT_EQ(num_bytes, 3182);
180         ASSERT_EQ(prb_num, 66);
181         ASSERT_EQ(CC_ID, 0);
182     }
183 }
184
185 INSTANTIATE_TEST_CASE_P(UnitTest, U_planeCheck,
186                         testing::ValuesIn(get_sequence(U_planeCheck::get_number_of_cases("u_plane_functional"))));
187
188