Skip to content

Commit 3acaede

Browse files
Pavel Harbanaucodebot
authored andcommitted
ofh: add RU emulator application
1 parent 6cc2635 commit 3acaede

File tree

7 files changed

+970
-83
lines changed

7 files changed

+970
-83
lines changed

tests/integrationtests/ofh/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,14 @@ add_executable(ofh_integration_test ofh_integration_test.cpp)
1212
target_link_libraries(ofh_integration_test srslog srsran_ru_ofh srsran_phy_support srsran_support)
1313
add_test(ofh_integration_test ofh_integration_test)
1414
set_tests_properties(ofh_integration_test PROPERTIES LABELS "tsan;NO_MEMCHECK")
15+
16+
if (DPDK_FOUND)
17+
add_executable(ru_emulator ru_emulator_cli11_schema.cpp ru_emulator.cpp)
18+
target_compile_options(ru_emulator PRIVATE ${DPDK_CFLAGS})
19+
20+
target_link_libraries(ru_emulator srslog srsran_ofh_dpdk_ethernet
21+
srsran_phy_support srsran_support hal_dpdk ${DPDK_LIBRARIES})
22+
23+
target_include_directories(ru_emulator PRIVATE ${CMAKE_SOURCE_DIR})
24+
include_directories(${CMAKE_SOURCE_DIR}/external)
25+
endif (DPDK_FOUND)
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
*
3+
* Copyright 2021-2024 Software Radio Systems Limited
4+
*
5+
* By using this file, you agree to the terms and conditions set
6+
* forth in the LICENSE file which can be found at the top level of
7+
* the distribution.
8+
*
9+
*/
10+
11+
#pragma once
12+
13+
#include "srsran/adt/span.h"
14+
#include "srsran/ofh/ethernet/ethernet_mac_address.h"
15+
#include "srsran/ran/bs_channel_bandwidth.h"
16+
#include "srsran/ru/ru_ofh_configuration.h"
17+
18+
using namespace srsran;
19+
20+
/// Helper function to convert array of port indexes to string.
21+
inline std::string port_ids_to_str(span<unsigned> ports)
22+
{
23+
fmt::memory_buffer str_buffer;
24+
fmt::format_to(str_buffer, "{");
25+
for (unsigned i = 0, e = ports.size(); i != e; ++i) {
26+
fmt::format_to(str_buffer, "{}{}", ports[i], (i == (e - 1)) ? "}" : ", ");
27+
}
28+
return to_string(str_buffer);
29+
}
30+
31+
/// Helper function to parse list of ports provided as a string.
32+
inline std::vector<unsigned> parse_port_id(const std::string& port_id_str)
33+
{
34+
std::vector<unsigned> port_ids;
35+
size_t start_pos = port_id_str.find('{');
36+
size_t end_pos = port_id_str.find('}');
37+
if (start_pos == std::string::npos || end_pos == std::string::npos) {
38+
return port_ids;
39+
}
40+
std::string ports_comma_separated = port_id_str.substr(start_pos + 1, end_pos - 1);
41+
std::stringstream ss(ports_comma_separated);
42+
int port;
43+
while (ss >> port) {
44+
port_ids.push_back(port);
45+
if (ss.peek() == ',' || ss.peek() == ' ') {
46+
ss.ignore();
47+
}
48+
}
49+
return port_ids;
50+
}
51+
52+
/// Parses the string containing Ethernet MAC address.
53+
inline bool parse_mac_address(const std::string& mac_str, ether::mac_address& mac)
54+
{
55+
std::array<unsigned, 6> data = {};
56+
int bytes_read = std::sscanf(
57+
mac_str.c_str(), "%02x:%02x:%02x:%02x:%02x:%02x", &data[0], &data[1], &data[2], &data[3], &data[4], &data[5]);
58+
if (bytes_read != ether::ETH_ADDR_LEN) {
59+
fmt::print("Invalid MAC address provided: {}\n", mac_str);
60+
return false;
61+
}
62+
63+
std::copy(data.begin(), data.end(), mac.begin());
64+
65+
return true;
66+
}
67+
68+
/// Validates the bandwidth argument provided as a user input.
69+
inline bool is_valid_bw(unsigned bandwidth)
70+
{
71+
// Bandwidth cannot be less than 5MHz.
72+
if (bandwidth < 5U) {
73+
return false;
74+
}
75+
76+
// Check from [5-25] in steps of 5.
77+
if (bandwidth < 26U) {
78+
return ((bandwidth % 5) == 0);
79+
}
80+
81+
// Check from [30-100] in steps of 10.
82+
if (bandwidth < 101U) {
83+
return ((bandwidth % 10) == 0);
84+
}
85+
86+
return false;
87+
}

tests/integrationtests/ofh/ofh_integration_test.cpp

Lines changed: 4 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
#include "../../../lib/phy/support/resource_grid_impl.h"
12+
#include "helpers.h"
1213
#include "srsran/adt/bounded_bitset.h"
1314
#include "srsran/adt/circular_map.h"
1415
#include "srsran/ofh/ecpri/ecpri_constants.h"
@@ -102,39 +103,6 @@ class dummy_ru_error_notifier : public ru_error_notifier
102103

103104
static test_parameters test_params;
104105

105-
/// Helper function to convert array of port indexes to string.
106-
static std::string port_ids_to_str(span<unsigned> ports)
107-
{
108-
std::stringstream ss;
109-
ss << "{";
110-
for (unsigned i = 0, e = ports.size() - 1; i != e; ++i) {
111-
ss << ports[i] << ", ";
112-
}
113-
ss << ports[ports.size() - 1] << "}";
114-
return ss.str();
115-
}
116-
117-
/// Helper function to parse list of ports provided as a string.
118-
static std::vector<unsigned> parse_port_id(const std::string& port_id_str)
119-
{
120-
std::vector<unsigned> port_ids;
121-
size_t start_pos = port_id_str.find('{');
122-
size_t end_pos = port_id_str.find('}');
123-
if (start_pos == std::string::npos || end_pos == std::string::npos) {
124-
return port_ids;
125-
}
126-
std::string ports_comma_separated = port_id_str.substr(start_pos + 1, end_pos - 1);
127-
std::stringstream ss(ports_comma_separated);
128-
int port;
129-
while (ss >> port) {
130-
port_ids.push_back(port);
131-
if (ss.peek() == ',' || ss.peek() == ' ') {
132-
ss.ignore();
133-
}
134-
}
135-
return port_ids;
136-
}
137-
138106
/// Prints usage information of the app.
139107
static void usage(const char* prog)
140108
{
@@ -169,55 +137,6 @@ static void usage(const char* prog)
169137
fmt::print("\t-h Show this message\n");
170138
}
171139

172-
/// Validates the bandwidth argument provided as a user input.
173-
static bool validate_bw(unsigned bandwidth)
174-
{
175-
switch (bandwidth) {
176-
case bs_channel_bandwidth_to_MHz(bs_channel_bandwidth_fr1::MHz5):
177-
test_params.bw = bs_channel_bandwidth_fr1::MHz5;
178-
break;
179-
case bs_channel_bandwidth_to_MHz(bs_channel_bandwidth_fr1::MHz10):
180-
test_params.bw = bs_channel_bandwidth_fr1::MHz10;
181-
break;
182-
case bs_channel_bandwidth_to_MHz(bs_channel_bandwidth_fr1::MHz15):
183-
test_params.bw = bs_channel_bandwidth_fr1::MHz15;
184-
break;
185-
case bs_channel_bandwidth_to_MHz(bs_channel_bandwidth_fr1::MHz20):
186-
test_params.bw = bs_channel_bandwidth_fr1::MHz20;
187-
break;
188-
case bs_channel_bandwidth_to_MHz(bs_channel_bandwidth_fr1::MHz25):
189-
test_params.bw = bs_channel_bandwidth_fr1::MHz25;
190-
break;
191-
case bs_channel_bandwidth_to_MHz(bs_channel_bandwidth_fr1::MHz30):
192-
test_params.bw = bs_channel_bandwidth_fr1::MHz30;
193-
break;
194-
case bs_channel_bandwidth_to_MHz(bs_channel_bandwidth_fr1::MHz40):
195-
test_params.bw = bs_channel_bandwidth_fr1::MHz40;
196-
break;
197-
case bs_channel_bandwidth_to_MHz(bs_channel_bandwidth_fr1::MHz50):
198-
test_params.bw = bs_channel_bandwidth_fr1::MHz50;
199-
break;
200-
case bs_channel_bandwidth_to_MHz(bs_channel_bandwidth_fr1::MHz60):
201-
test_params.bw = bs_channel_bandwidth_fr1::MHz60;
202-
break;
203-
case bs_channel_bandwidth_to_MHz(bs_channel_bandwidth_fr1::MHz70):
204-
test_params.bw = bs_channel_bandwidth_fr1::MHz70;
205-
break;
206-
case bs_channel_bandwidth_to_MHz(bs_channel_bandwidth_fr1::MHz80):
207-
test_params.bw = bs_channel_bandwidth_fr1::MHz80;
208-
break;
209-
case bs_channel_bandwidth_to_MHz(bs_channel_bandwidth_fr1::MHz90):
210-
test_params.bw = bs_channel_bandwidth_fr1::MHz90;
211-
break;
212-
case bs_channel_bandwidth_to_MHz(bs_channel_bandwidth_fr1::MHz100):
213-
test_params.bw = bs_channel_bandwidth_fr1::MHz100;
214-
break;
215-
default:
216-
return false;
217-
}
218-
return true;
219-
}
220-
221140
/// Parses arguments of the app.
222141
static void parse_args(int argc, char** argv)
223142
{
@@ -255,9 +174,11 @@ static void parse_args(int argc, char** argv)
255174
break;
256175
case 'w':
257176
if (optarg != nullptr) {
258-
if (!validate_bw(std::strtol(optarg, nullptr, 10))) {
177+
if (!is_valid_bw(std::strtol(optarg, nullptr, 10))) {
259178
fmt::print("Invalid bandwidth\n");
260179
invalid_arg = true;
180+
} else {
181+
test_params.bw = MHz_to_bs_channel_bandwidth(std::strtol(optarg, nullptr, 10));
261182
}
262183
}
263184
break;

0 commit comments

Comments
 (0)