Skip to content

Commit c9d23b1

Browse files
AlaiaLcodebot
authored andcommitted
unit: use free function to add options to cli
1 parent 023fe33 commit c9d23b1

File tree

2 files changed

+89
-77
lines changed

2 files changed

+89
-77
lines changed

apps/units/cu_cp/cu_cp_unit_config_cli11_schema.cpp

Lines changed: 88 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -17,53 +17,59 @@ using namespace srsran;
1717

1818
static void configure_cli11_report_args(CLI::App& app, cu_cp_report_unit_config& report_params)
1919
{
20-
app.add_option("--report_cfg_id", report_params.report_cfg_id, "Report configuration id to be configured")
20+
add_option(app, "--report_cfg_id", report_params.report_cfg_id, "Report configuration id to be configured")
2121
->check(CLI::Range(1, 64));
22-
app.add_option("--report_type", report_params.report_type, "Type of the report configuration")
22+
add_option(app, "--report_type", report_params.report_type, "Type of the report configuration")
2323
->check(CLI::IsMember({"periodical", "event_triggered"}));
24-
app.add_option("--report_interval_ms", report_params.report_interval_ms, "Report interval in ms")
24+
add_option(app, "--report_interval_ms", report_params.report_interval_ms, "Report interval in ms")
2525
->check(
2626
CLI::IsMember({120, 240, 480, 640, 1024, 2048, 5120, 10240, 20480, 40960, 60000, 360000, 720000, 1800000}));
27-
app.add_option("--a3_report_type", report_params.a3_report_type, "A3 report type")
27+
add_option(app, "--a3_report_type", report_params.a3_report_type, "A3 report type")
2828
->check(CLI::IsMember({"rsrp", "rsrq", "sinr"}));
29-
app.add_option("--a3_offset_db",
30-
report_params.a3_offset_db,
31-
"A3 offset in dB used for measurement report trigger. Note the actual value is field value * 0.5 dB")
29+
add_option(app,
30+
"--a3_offset_db",
31+
report_params.a3_offset_db,
32+
"A3 offset in dB used for measurement report trigger. Note the actual value is field value * 0.5 dB")
3233
->check(CLI::Range(-30, 30));
33-
app.add_option(
34-
"--a3_hysteresis_db",
35-
report_params.a3_hysteresis_db,
36-
"A3 hysteresis in dB used for measurement report trigger. Note the actual value is field value * 0.5 dB")
34+
add_option(app,
35+
"--a3_hysteresis_db",
36+
report_params.a3_hysteresis_db,
37+
"A3 hysteresis in dB used for measurement report trigger. Note the actual value is field value * 0.5 dB")
3738
->check(CLI::Range(0, 30));
38-
app.add_option("--a3_time_to_trigger_ms",
39-
report_params.a3_time_to_trigger_ms,
40-
"Time in ms during which A3 condition must be met before measurement report trigger")
39+
add_option(app,
40+
"--a3_time_to_trigger_ms",
41+
report_params.a3_time_to_trigger_ms,
42+
"Time in ms during which A3 condition must be met before measurement report trigger")
4143
->check(CLI::IsMember({0, 40, 64, 80, 100, 128, 160, 256, 320, 480, 512, 640, 1024, 1280, 2560, 5120}));
4244
}
4345

4446
static void configure_cli11_ncell_args(CLI::App& app, cu_cp_neighbor_cell_unit_config_item& config)
4547
{
46-
app.add_option("--nr_cell_id", config.nr_cell_id, "Neighbor cell id");
47-
app.add_option(
48-
"--report_configs", config.report_cfg_ids, "Report configurations to configure for this neighbor cell");
48+
add_option(app, "--nr_cell_id", config.nr_cell_id, "Neighbor cell id");
49+
add_option(
50+
app, "--report_configs", config.report_cfg_ids, "Report configurations to configure for this neighbor cell");
4951
}
5052

5153
static void configure_cli11_cells_args(CLI::App& app, cu_cp_cell_unit_config_item& config)
5254
{
53-
app.add_option("--nr_cell_id", config.nr_cell_id, "Cell id to be configured");
54-
app.add_option("--periodic_report_cfg_id",
55-
config.periodic_report_cfg_id,
56-
"Periodical report configuration for the serving cell")
55+
add_option(app, "--nr_cell_id", config.nr_cell_id, "Cell id to be configured");
56+
add_option(app,
57+
"--periodic_report_cfg_id",
58+
config.periodic_report_cfg_id,
59+
"Periodical report configuration for the serving cell")
5760
->check(CLI::Range(1, 64));
61+
5862
add_auto_enum_option(app, "--band", config.band, "NR frequency band");
59-
app.add_option("--gnb_id_bit_length", config.gnb_id_bit_length, "gNodeB identifier bit length")
63+
64+
add_option(app, "--gnb_id_bit_length", config.gnb_id_bit_length, "gNodeB identifier bit length")
6065
->check(CLI::Range(22, 32));
61-
app.add_option("--pci", config.pci, "Physical Cell Id")->check(CLI::Range(0, 1007));
62-
app.add_option("--ssb_arfcn", config.ssb_arfcn, "SSB ARFCN");
63-
app.add_option("--ssb_scs", config.ssb_scs, "SSB subcarrier spacing")->check(CLI::IsMember({15, 30, 60, 120, 240}));
64-
app.add_option("--ssb_period", config.ssb_period, "SSB period in ms")->check(CLI::IsMember({5, 10, 20, 40, 80, 160}));
65-
app.add_option("--ssb_offset", config.ssb_offset, "SSB offset");
66-
app.add_option("--ssb_duration", config.ssb_duration, "SSB duration")->check(CLI::IsMember({1, 2, 3, 4, 5}));
66+
add_option(app, "--pci", config.pci, "Physical Cell Id")->check(CLI::Range(0, 1007));
67+
add_option(app, "--ssb_arfcn", config.ssb_arfcn, "SSB ARFCN");
68+
add_option(app, "--ssb_scs", config.ssb_scs, "SSB subcarrier spacing")->check(CLI::IsMember({15, 30, 60, 120, 240}));
69+
add_option(app, "--ssb_period", config.ssb_period, "SSB period in ms")
70+
->check(CLI::IsMember({5, 10, 20, 40, 80, 160}));
71+
add_option(app, "--ssb_offset", config.ssb_offset, "SSB offset");
72+
add_option(app, "--ssb_duration", config.ssb_duration, "SSB duration")->check(CLI::IsMember({1, 2, 3, 4, 5}));
6773

6874
// report configuration parameters.
6975
app.add_option_function<std::vector<std::string>>(
@@ -85,9 +91,10 @@ static void configure_cli11_cells_args(CLI::App& app, cu_cp_cell_unit_config_ite
8591

8692
static void configure_cli11_mobility_args(CLI::App& app, mobility_unit_config& config)
8793
{
88-
app.add_option("--trigger_handover_from_measurements",
89-
config.trigger_handover_from_measurements,
90-
"Whether to start HO if neighbor cells become stronger")
94+
add_option(app,
95+
"--trigger_handover_from_measurements",
96+
config.trigger_handover_from_measurements,
97+
"Whether to start HO if neighbor cells become stronger")
9198
->capture_default_str();
9299

93100
// Cell map parameters.
@@ -127,16 +134,18 @@ static void configure_cli11_mobility_args(CLI::App& app, mobility_unit_config& c
127134

128135
static void configure_cli11_rrc_args(CLI::App& app, rrc_appconfig& config)
129136
{
130-
app.add_option("--force_reestablishment_fallback",
131-
config.force_reestablishment_fallback,
132-
"Force RRC re-establishment fallback to RRC setup")
137+
add_option(app,
138+
"--force_reestablishment_fallback",
139+
config.force_reestablishment_fallback,
140+
"Force RRC re-establishment fallback to RRC setup")
133141
->capture_default_str();
134142

135-
app.add_option(
136-
"--rrc_procedure_timeout_ms",
137-
config.rrc_procedure_timeout_ms,
138-
"Timeout in ms used for RRC message exchange with UE. It needs to suit the expected communication delay and "
139-
"account for potential retransmissions UE processing delays, SR delays, etc.")
143+
add_option(
144+
app,
145+
"--rrc_procedure_timeout_ms",
146+
config.rrc_procedure_timeout_ms,
147+
"Timeout in ms used for RRC message exchange with UE. It needs to suit the expected communication delay and "
148+
"account for potential retransmissions UE processing delays, SR delays, etc.")
140149
->capture_default_str();
141150
}
142151

@@ -149,49 +158,57 @@ static void configure_cli11_security_args(CLI::App& app, security_unit_config& c
149158
return "Security indication value not supported. Accepted values [required,preferred,not_needed]";
150159
};
151160

152-
app.add_option("--integrity", config.integrity_protection, "Default integrity protection indication for DRBs")
161+
add_option(app, "--integrity", config.integrity_protection, "Default integrity protection indication for DRBs")
153162
->capture_default_str()
154163
->check(sec_check);
155164

156-
app.add_option("--confidentiality",
157-
config.confidentiality_protection,
158-
"Default confidentiality protection indication for DRBs")
165+
add_option(app,
166+
"--confidentiality",
167+
config.confidentiality_protection,
168+
"Default confidentiality protection indication for DRBs")
159169
->capture_default_str()
160170
->check(sec_check);
161171

162-
app.add_option("--nea_pref_list",
163-
config.nea_preference_list,
164-
"Ordered preference list for the selection of encryption algorithm (NEA) (default: NEA0, NEA2, NEA1)");
172+
add_option(app,
173+
"--nea_pref_list",
174+
config.nea_preference_list,
175+
"Ordered preference list for the selection of encryption algorithm (NEA) (default: NEA0, NEA2, NEA1)");
165176

166-
app.add_option("--nia_pref_list",
167-
config.nia_preference_list,
168-
"Ordered preference list for the selection of encryption algorithm (NIA) (default: NIA2, NIA1)")
177+
add_option(app,
178+
"--nia_pref_list",
179+
config.nia_preference_list,
180+
"Ordered preference list for the selection of encryption algorithm (NIA) (default: NIA2, NIA1)")
169181
->capture_default_str();
170182
}
171183

172184
static void configure_cli11_f1ap_args(CLI::App& app, f1ap_cu_unit_config& f1ap_params)
173185
{
174-
app.add_option(
175-
"--ue_context_setup_timeout", f1ap_params.ue_context_setup_timeout, "UE context setup timeout in milliseconds")
186+
add_option(app,
187+
"--ue_context_setup_timeout",
188+
f1ap_params.ue_context_setup_timeout,
189+
"UE context setup timeout in milliseconds")
176190
->capture_default_str();
177191
}
178192

179193
static void configure_cli11_cu_cp_args(CLI::App& app, cu_cp_unit_config& cu_cp_params)
180194
{
181-
app.add_option(
182-
"--max_nof_dus", cu_cp_params.max_nof_dus, "Maximum number of DU connections that the CU-CP may accept");
195+
add_option(
196+
app, "--max_nof_dus", cu_cp_params.max_nof_dus, "Maximum number of DU connections that the CU-CP may accept");
183197

184-
app.add_option(
185-
"--max_nof_cu_ups", cu_cp_params.max_nof_cu_ups, "Maximum number of CU-UP connections that the CU-CP may accept");
198+
add_option(app,
199+
"--max_nof_cu_ups",
200+
cu_cp_params.max_nof_cu_ups,
201+
"Maximum number of CU-UP connections that the CU-CP may accept");
186202

187-
app.add_option("--inactivity_timer", cu_cp_params.inactivity_timer, "UE/PDU Session/DRB inactivity timer in seconds")
203+
add_option(app, "--inactivity_timer", cu_cp_params.inactivity_timer, "UE/PDU Session/DRB inactivity timer in seconds")
188204
->capture_default_str()
189205
->check(CLI::Range(1, 7200));
190206

191-
app.add_option("--pdu_session_setup_timeout",
192-
cu_cp_params.pdu_session_setup_timeout,
193-
"Timeout for the setup of a PDU session after an InitialUeMessage was sent to the core, in "
194-
"seconds. The timeout must be larger than T310. If the value is reached, the UE will be released")
207+
add_option(app,
208+
"--pdu_session_setup_timeout",
209+
cu_cp_params.pdu_session_setup_timeout,
210+
"Timeout for the setup of a PDU session after an InitialUeMessage was sent to the core, in "
211+
"seconds. The timeout must be larger than T310. If the value is reached, the UE will be released")
195212
->capture_default_str();
196213

197214
CLI::App* mobility_subcmd = app.add_subcommand("mobility", "Mobility configuration");
@@ -216,35 +233,31 @@ static void configure_cli11_log_args(CLI::App& app, cu_cp_log_unit_config& log_p
216233
return "Log level value not supported. Accepted values [info,debug,warning,error]";
217234
};
218235

219-
app.add_option("--pdcp_level", log_params.pdcp_level, "PDCP log level")->capture_default_str()->check(level_check);
220-
app.add_option("--rrc_level", log_params.rrc_level, "RRC log level")->capture_default_str()->check(level_check);
221-
app.add_option("--ngap_level", log_params.ngap_level, "NGAP log level")->capture_default_str()->check(level_check);
222-
app.add_option("--f1ap_level", log_params.f1ap_level, "F1AP log level")->capture_default_str()->check(level_check);
223-
app.add_option("--cu_level", log_params.cu_level, "Log level for the CU")->capture_default_str()->check(level_check);
224-
app.add_option("--sec_level", log_params.sec_level, "Security functions log level")
236+
add_option(app, "--pdcp_level", log_params.pdcp_level, "PDCP log level")->capture_default_str()->check(level_check);
237+
add_option(app, "--rrc_level", log_params.rrc_level, "RRC log level")->capture_default_str()->check(level_check);
238+
add_option(app, "--ngap_level", log_params.ngap_level, "NGAP log level")->capture_default_str()->check(level_check);
239+
add_option(app, "--f1ap_level", log_params.f1ap_level, "F1AP log level")->capture_default_str()->check(level_check);
240+
add_option(app, "--cu_level", log_params.cu_level, "Log level for the CU")->capture_default_str()->check(level_check);
241+
add_option(app, "--sec_level", log_params.sec_level, "Security functions log level")
225242
->capture_default_str()
226243
->check(level_check);
227244

228-
app.add_option(
229-
"--hex_max_size", log_params.hex_max_size, "Maximum number of bytes to print in hex (zero for no hex dumps)")
245+
add_option(
246+
app, "--hex_max_size", log_params.hex_max_size, "Maximum number of bytes to print in hex (zero for no hex dumps)")
230247
->capture_default_str()
231248
->check(CLI::Range(0, 1024));
232249

233-
app.add_option("--f1ap_json_enabled", log_params.f1ap_json_enabled, "Enable JSON logging of F1AP PDUs")
250+
add_option(app, "--f1ap_json_enabled", log_params.f1ap_json_enabled, "Enable JSON logging of F1AP PDUs")
234251
->always_capture_default();
235252
}
236253

237254
void configure_cli11_with_cu_cp_unit_config_schema(CLI::App& app, cu_cp_unit_config& parsed_cfg)
238255
{
239256
// CU-CP section
240-
CLI::App* cu_cp_subcmd = app.add_subcommand("cu_cp", "CU-CP parameters")->configurable();
257+
CLI::App* cu_cp_subcmd = add_subcommand(app, "cu_cp", "CU-CP parameters")->configurable();
241258
configure_cli11_cu_cp_args(*cu_cp_subcmd, parsed_cfg);
242259

243260
// Loggers section.
244-
CLI::App* log_subcmd = app.get_subcommand("log");
245-
if (!log_subcmd) {
246-
log_subcmd = app.add_subcommand("log", "Logging configuration")->configurable();
247-
}
248-
261+
CLI::App* log_subcmd = add_subcommand(app, "log", "Logging configuration")->configurable();
249262
configure_cli11_log_args(*log_subcmd, parsed_cfg.loggers);
250263
}

include/srsran/support/cli11_utils.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ namespace srsran {
2525
/// \return A pointer to the subcommand added to the application.
2626
CLI::App* add_subcommand(CLI::App& app, const std::string& name, const std::string& desc)
2727
{
28-
CLI::App* subcommand = app.get_subcommand(name);
29-
if (subcommand) {
28+
if (CLI::App* subcommand = app.get_subcommand(name)) {
3029
return subcommand;
3130
}
3231

0 commit comments

Comments
 (0)