O-RAN E Maintenance Release contribution for ODULOW
[o-du/phy.git] / fhi_lib / test / test_xran / chain_tests.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
20 #include "common.hpp"
21 #include "xran_lib_wrap.hpp"
22 #include "xran_common.h"
23 #include "xran_fh_o_du.h"
24 #include "ethdi.h"
25 #include "ethernet.h"
26 #include "xran_transport.h"
27 #include "xran_cp_api.h"
28
29 #include <stdint.h>
30
31
32
33 const std::string module_name = "C-Plane";
34
35 const uint8_t m_bitmask[] = { 0x00, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };
36
37
38 extern "C"
39 {
40
41 /* external functions in xRAN library */
42 void tx_cp_dl_cb(struct rte_timer *tim, void *arg);
43 void tx_cp_ul_cb(struct rte_timer *tim, void *arg);
44 int xran_process_tx_sym(void *arg);
45 int process_mbuf(struct rte_mbuf *pkt, void *arg, struct xran_eaxc_info *p_cid);
46
47
48 /* wrapper functions for performace tests */
49 void xran_ut_tx_cp_dl()
50 {
51     xranlib->update_tti();
52     tx_cp_dl_cb(nullptr, xranlib->get_timer_ctx());
53 }
54
55 void xran_ut_tx_cp_ul()
56 {
57     xranlib->update_tti();
58     tx_cp_ul_cb(nullptr, xranlib->get_timer_ctx());
59 }
60
61 void xran_ut_tx_up_dl()
62 {
63     xranlib->update_symbol_index();
64     xran_process_tx_sym(xranlib->get_timer_ctx());
65 }
66
67 void xran_ut_tx_cpup_dl()
68 {
69     xranlib->update_symbol_index();
70
71     if(xranlib->get_symbol_index() == 3)
72         tx_cp_dl_cb(nullptr, xranlib->get_timer_ctx());
73
74     xran_process_tx_sym(xranlib->get_timer_ctx());
75 }
76
77 #if 0   /* TBD */
78 void xran_ut_rx_up_ul()
79 {
80     process_mbf(mbuf);
81 }
82 #endif
83
84
85 /* call back functions */
86 int send_mbuf_up(struct rte_mbuf *mbuf, uint16_t type, uint16_t vf_id)
87 {
88     rte_pktmbuf_free(mbuf);
89
90     return (1);
91 }
92
93 int send_mbuf_cp_perf(struct rte_mbuf *mbuf, uint16_t type, uint16_t vf_id)
94 {
95     rte_pktmbuf_free(mbuf);
96     /*  TODO: need to free chained mbufs */
97     return (1);
98 }
99
100 #if 0   /* TBD */
101 int send_mbuf_cp(struct rte_mbuf *mbuf, uint16_t type)
102 {
103 #if 0
104     xran_parse_cp_pkt(m_pTestBuffer, &m_result, &m_pktInfo);
105
106     /* Verify the result */
107     verify_sections();
108 #else
109     printf("cp\n");
110 #endif
111     return (1);
112 }
113 #endif
114
115 void utcp_fh_rx_callback(void *pCallbackTag, xran_status_t status)
116 {
117     return;
118 }
119
120 void utcp_fh_srs_callback(void *pCallbackTag, xran_status_t status)
121 {
122     return;
123 }
124
125 void utcp_fh_rx_prach_callback(void *pCallbackTag, xran_status_t status)
126 {
127     rte_pause();
128 }
129
130 } /* extern "C" */
131
132
133 class TestChain: public KernelTests
134 {
135 protected:
136     struct xran_fh_config   m_xranConf;
137     struct xran_fh_init     m_xranInit;
138
139     bool m_bSub6;
140
141
142     void SetUp() override
143     {
144         int temp;
145         std::string tmpstr;
146
147
148         init_test("TestChain");
149
150         xranlib->get_cfg_fh(&m_xranConf);
151
152         tmpstr = get_input_parameter<std::string>("category");
153         if(tmpstr == "A")
154             m_xranConf.ru_conf.xranCat = XRAN_CATEGORY_A;
155         else if(tmpstr == "B")
156             m_xranConf.ru_conf.xranCat = XRAN_CATEGORY_B;
157         else {
158             std::cout << "*** Invalid RU Category [" << tmpstr << "] !!!" << std::endl;
159             std::cout << "Set it to Category A... " << std::endl;
160             m_xranConf.ru_conf.xranCat = XRAN_CATEGORY_A;
161             }
162
163         m_xranConf.frame_conf.nNumerology = get_input_parameter<int>("mu");
164         if(m_xranConf.frame_conf.nNumerology > 3) {
165             std::cout << "*** Invalid Numerology [" << m_xranConf.frame_conf.nNumerology << "] !!!" << std::endl;
166             m_xranConf.frame_conf.nNumerology   = 0;
167             std::cout << "Set it to " << m_xranConf.frame_conf.nNumerology << "..." << std::endl;
168             }
169
170         tmpstr = get_input_parameter<std::string>("duplex");
171         if(tmpstr == "FDD")
172             m_xranConf.frame_conf.nFrameDuplexType  = 0;
173         else if(tmpstr == "TDD") {
174             m_xranConf.frame_conf.nFrameDuplexType  = 1;
175
176             tmpstr = get_input_parameter<std::string>("slot_config");
177             temp = xranlib->get_slot_config(tmpstr, &m_xranConf.frame_conf);
178             }
179         else {
180             std::cout << "*** Invalid Duplex type [" << tmpstr << "] !!!" << std::endl;
181             std::cout << "Set it to FDD... " << std::endl;
182             m_xranConf.frame_conf.nFrameDuplexType  = 0;
183             }
184
185         m_xranConf.nCC = get_input_parameter<int>("num_cc");
186         if(m_xranConf.nCC > XRAN_MAX_SECTOR_NR) {
187             std::cout << "*** Exceeds maximum number of carriers supported [" << m_xranConf.nCC << "] !!!" << std::endl;
188             m_xranConf.nCC = XRAN_MAX_SECTOR_NR;
189             std::cout << "Set it to " << m_xranConf.nCC << "..." << std::endl;
190             }
191         m_xranConf.neAxc = get_input_parameter<int>("num_eaxc");
192         if(m_xranConf.neAxc > XRAN_MAX_ANTENNA_NR) {
193             std::cout << "*** Exceeds maximum number of antenna supported [" << m_xranConf.neAxc << "] !!!" << std::endl;
194             m_xranConf.neAxc = XRAN_MAX_ANTENNA_NR;
195             std::cout << "Set it to " << m_xranConf.neAxc << "..." << std::endl;
196             }
197
198         m_bSub6     = get_input_parameter<bool>("sub6");
199         temp = get_input_parameter<int>("chbw_dl");
200         m_xranConf.nDLRBs = xranlib->get_num_rbs(m_xranConf.frame_conf.nNumerology, temp, m_bSub6);
201         temp = get_input_parameter<int>("chbw_ul");
202         m_xranConf.nULRBs = xranlib->get_num_rbs(m_xranConf.frame_conf.nNumerology, temp, m_bSub6);
203
204         m_xranConf.nAntElmTRx = get_input_parameter<int>("antelm_trx");
205         m_xranConf.nDLFftSize = get_input_parameter<int>("fftsize_dl");
206         m_xranConf.nULFftSize = get_input_parameter<int>("fftsize_ul");
207
208
209         m_xranConf.ru_conf.iqWidth  = get_input_parameter<int>("iq_width");
210         m_xranConf.ru_conf.compMeth = get_input_parameter<int>("comp_meth");
211
212 #if 0
213         temp = get_input_parameter<int>("fft_size");
214         m_xranConf.ru_conf.fftSize  = 0;
215         while (temp >>= 1)
216             ++m_xranConf.ru_conf.fftSize;
217 #endif
218
219     }
220
221     void TearDown() override
222     {
223     }
224 };
225
226
227
228
229 /***************************************************************************
230  * Performance Test cases
231  ***************************************************************************/
232 /* C-Plane DL chain (tx_cp_dl_cb) only */
233 TEST_P(TestChain, CPlaneDLPerf)
234 {
235     xranlib->Init(0, &m_xranConf);
236     xranlib->Open(0, send_mbuf_cp_perf, send_mbuf_up,
237             (void *)utcp_fh_rx_callback, (void *)utcp_fh_rx_prach_callback, (void *)utcp_fh_srs_callback);
238
239     performance("C", module_name, xran_ut_tx_cp_dl);
240
241     xranlib->Close();
242     xranlib->Cleanup();
243 }
244
245 /* C-Plane UL chain (tx_cp_ul_cb) only */
246 TEST_P(TestChain, CPlaneULPerf)
247 {
248     xranlib->Init(0, &m_xranConf);
249     xranlib->Open(0, send_mbuf_cp_perf, send_mbuf_up,
250             (void *)utcp_fh_rx_callback, (void *)utcp_fh_rx_prach_callback, (void *)utcp_fh_srs_callback);
251
252     performance("C", module_name, xran_ut_tx_cp_ul);
253
254     xranlib->Close();
255     xranlib->Cleanup();
256 }
257
258 /* U-Plane UL chain (process_tx_sym with disable CP) */
259 TEST_P(TestChain, UPlaneDLPerf)
260 {
261     bool flag_cpen;
262
263     xranlib->Init(0, &m_xranConf);
264
265     /* save current CP enable flag */
266     flag_cpen = xranlib->is_cpenable()?true:false;
267
268     /* need to disable CP to make U-Plane work without CP */
269     xranlib->apply_cpenable(false);
270     xranlib->Open(0, send_mbuf_cp_perf, send_mbuf_up,
271             (void *)utcp_fh_rx_callback, (void *)utcp_fh_rx_prach_callback, (void *)utcp_fh_srs_callback);
272
273     performance("C", module_name, xran_ut_tx_up_dl);
274
275     xranlib->Close();
276     xranlib->Cleanup();
277
278     /* restore previous CP enable flag */
279     xranlib->apply_cpenable(flag_cpen);
280 }
281
282 /* C-Plane and U-Plane DL chain, U-Plane will be generated by C-Plane config */
283 TEST_P(TestChain, APlaneDLPerf)
284 {
285     bool flag_cpen;
286
287     xranlib->Init(0, &m_xranConf);
288
289     /* save current CP enable flag */
290     flag_cpen = xranlib->is_cpenable()?true:false;
291
292     /* Enable CP by force to make UP work by CP's section information */
293     xranlib->apply_cpenable(true);
294     xranlib->Open(0, send_mbuf_cp_perf, send_mbuf_up,
295             (void *)utcp_fh_rx_callback, (void *)utcp_fh_rx_prach_callback, (void *)utcp_fh_srs_callback);
296
297     performance("C", module_name, xran_ut_tx_cpup_dl);
298
299     xranlib->Close();
300     xranlib->Cleanup();
301
302     /* restore previous CP enable flag */
303     xranlib->apply_cpenable(flag_cpen);
304 }
305
306 #if 0       /* TBD */
307 TEST_P(TestChain, UPlaneULPerf)
308 {
309 }
310 #endif
311
312
313 INSTANTIATE_TEST_CASE_P(UnitTest, TestChain,
314         testing::ValuesIn(get_sequence(TestChain::get_number_of_cases("TestChain"))));
315