* INTC Contribution to the O-RAN F Release for O-DU Low
[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_bfw_callback(void *pCallbackTag, xran_status_t status)
121 {
122     return;
123 }
124
125 void utcp_fh_srs_callback(void *pCallbackTag, xran_status_t status)
126 {
127     return;
128 }
129
130 void utcp_fh_rx_prach_callback(void *pCallbackTag, xran_status_t status)
131 {
132     rte_pause();
133 }
134
135 } /* extern "C" */
136
137
138 class TestChain: public KernelTests
139 {
140 protected:
141     struct xran_fh_config   m_xranConf;
142     struct xran_fh_init     m_xranInit;
143
144     bool m_bSub6;
145
146
147     void SetUp() override
148     {
149         int temp;
150         std::string tmpstr;
151
152
153         init_test("TestChain");
154
155         xranlib->get_cfg_fh(&m_xranConf);
156
157         tmpstr = get_input_parameter<std::string>("category");
158         if(tmpstr == "A")
159             m_xranConf.ru_conf.xranCat = XRAN_CATEGORY_A;
160         else if(tmpstr == "B")
161             m_xranConf.ru_conf.xranCat = XRAN_CATEGORY_B;
162         else {
163             std::cout << "*** Invalid RU Category [" << tmpstr << "] !!!" << std::endl;
164             std::cout << "Set it to Category A... " << std::endl;
165             m_xranConf.ru_conf.xranCat = XRAN_CATEGORY_A;
166             }
167
168         m_xranConf.frame_conf.nNumerology = get_input_parameter<int>("mu");
169         if(m_xranConf.frame_conf.nNumerology > 3) {
170             std::cout << "*** Invalid Numerology [" << m_xranConf.frame_conf.nNumerology << "] !!!" << std::endl;
171             m_xranConf.frame_conf.nNumerology   = 0;
172             std::cout << "Set it to " << m_xranConf.frame_conf.nNumerology << "..." << std::endl;
173             }
174
175         tmpstr = get_input_parameter<std::string>("duplex");
176         if(tmpstr == "FDD")
177             m_xranConf.frame_conf.nFrameDuplexType  = 0;
178         else if(tmpstr == "TDD") {
179             m_xranConf.frame_conf.nFrameDuplexType  = 1;
180
181             tmpstr = get_input_parameter<std::string>("slot_config");
182             temp = xranlib->get_slot_config(tmpstr, &m_xranConf.frame_conf);
183             }
184         else {
185             std::cout << "*** Invalid Duplex type [" << tmpstr << "] !!!" << std::endl;
186             std::cout << "Set it to FDD... " << std::endl;
187             m_xranConf.frame_conf.nFrameDuplexType  = 0;
188             }
189
190         m_xranConf.nCC = get_input_parameter<int>("num_cc");
191         if(m_xranConf.nCC > XRAN_MAX_SECTOR_NR) {
192             std::cout << "*** Exceeds maximum number of carriers supported [" << m_xranConf.nCC << "] !!!" << std::endl;
193             m_xranConf.nCC = XRAN_MAX_SECTOR_NR;
194             std::cout << "Set it to " << m_xranConf.nCC << "..." << std::endl;
195             }
196         m_xranConf.neAxc = get_input_parameter<int>("num_eaxc");
197         if(m_xranConf.neAxc > XRAN_MAX_ANTENNA_NR) {
198             std::cout << "*** Exceeds maximum number of antenna supported [" << m_xranConf.neAxc << "] !!!" << std::endl;
199             m_xranConf.neAxc = XRAN_MAX_ANTENNA_NR;
200             std::cout << "Set it to " << m_xranConf.neAxc << "..." << std::endl;
201             }
202
203         m_bSub6     = get_input_parameter<bool>("sub6");
204         temp = get_input_parameter<int>("chbw_dl");
205         m_xranConf.nDLRBs = xranlib->get_num_rbs(m_xranConf.frame_conf.nNumerology, temp, m_bSub6);
206         temp = get_input_parameter<int>("chbw_ul");
207         m_xranConf.nULRBs = xranlib->get_num_rbs(m_xranConf.frame_conf.nNumerology, temp, m_bSub6);
208
209         m_xranConf.nAntElmTRx = get_input_parameter<int>("antelm_trx");
210         m_xranConf.nDLFftSize = get_input_parameter<int>("fftsize_dl");
211         m_xranConf.nULFftSize = get_input_parameter<int>("fftsize_ul");
212
213
214         m_xranConf.ru_conf.iqWidth  = get_input_parameter<int>("iq_width");
215         m_xranConf.ru_conf.compMeth = get_input_parameter<int>("comp_meth");
216
217 #if 0
218         temp = get_input_parameter<int>("fft_size");
219         m_xranConf.ru_conf.fftSize  = 0;
220         while (temp >>= 1)
221             ++m_xranConf.ru_conf.fftSize;
222 #endif
223
224     }
225
226     void TearDown() override
227     {
228     }
229 };
230
231
232
233
234 /***************************************************************************
235  * Performance Test cases
236  ***************************************************************************/
237 /* C-Plane DL chain (tx_cp_dl_cb) only */
238 TEST_P(TestChain, CPlaneDLPerf)
239 {
240     xranlib->Init(0, &m_xranConf);
241     xranlib->Open(0, send_mbuf_cp_perf, send_mbuf_up,
242             (void *)utcp_fh_rx_callback, (void *)utcp_fh_bfw_callback, (void *)utcp_fh_rx_prach_callback, (void *)utcp_fh_srs_callback);
243
244     performance("C", module_name, xran_ut_tx_cp_dl);
245
246     xranlib->Close();
247     xranlib->Cleanup();
248 }
249
250 /* C-Plane UL chain (tx_cp_ul_cb) only */
251 TEST_P(TestChain, CPlaneULPerf)
252 {
253     xranlib->Init(0, &m_xranConf);
254     xranlib->Open(0, send_mbuf_cp_perf, send_mbuf_up,
255             (void *)utcp_fh_rx_callback, (void *)utcp_fh_bfw_callback, (void *)utcp_fh_rx_prach_callback, (void *)utcp_fh_srs_callback);
256
257     performance("C", module_name, xran_ut_tx_cp_ul);
258
259     xranlib->Close();
260     xranlib->Cleanup();
261 }
262
263 /* U-Plane UL chain (process_tx_sym with disable CP) */
264 TEST_P(TestChain, UPlaneDLPerf)
265 {
266     bool flag_cpen;
267
268     xranlib->Init(0, &m_xranConf);
269
270     /* save current CP enable flag */
271     flag_cpen = xranlib->is_cpenable()?true:false;
272
273     /* need to disable CP to make U-Plane work without CP */
274     xranlib->apply_cpenable(false);
275     xranlib->Open(0, send_mbuf_cp_perf, send_mbuf_up,
276             (void *)utcp_fh_rx_callback, (void *)utcp_fh_bfw_callback, (void *)utcp_fh_rx_prach_callback, (void *)utcp_fh_srs_callback);
277
278     performance("C", module_name, xran_ut_tx_up_dl);
279
280     xranlib->Close();
281     xranlib->Cleanup();
282
283     /* restore previous CP enable flag */
284     xranlib->apply_cpenable(flag_cpen);
285 }
286
287 /* C-Plane and U-Plane DL chain, U-Plane will be generated by C-Plane config */
288 TEST_P(TestChain, APlaneDLPerf)
289 {
290     bool flag_cpen;
291
292     xranlib->Init(0, &m_xranConf);
293
294     /* save current CP enable flag */
295     flag_cpen = xranlib->is_cpenable()?true:false;
296
297     /* Enable CP by force to make UP work by CP's section information */
298     xranlib->apply_cpenable(true);
299     xranlib->Open(0, send_mbuf_cp_perf, send_mbuf_up,
300             (void *)utcp_fh_rx_callback, (void *)utcp_fh_bfw_callback, (void *)utcp_fh_rx_prach_callback, (void *)utcp_fh_srs_callback);
301
302     performance("C", module_name, xran_ut_tx_cpup_dl);
303
304     xranlib->Close();
305     xranlib->Cleanup();
306
307     /* restore previous CP enable flag */
308     xranlib->apply_cpenable(flag_cpen);
309 }
310
311 #if 0       /* TBD */
312 TEST_P(TestChain, UPlaneULPerf)
313 {
314 }
315 #endif
316
317
318 INSTANTIATE_TEST_CASE_P(UnitTest, TestChain,
319         testing::ValuesIn(get_sequence(TestChain::get_number_of_cases("TestChain"))));
320