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