Skip to content

Commit 4e2e694

Browse files
frankistcodebot
authored andcommitted
f1ap-cu: make the prefix logging consistent with DU
1 parent c70832d commit 4e2e694

File tree

11 files changed

+163
-95
lines changed

11 files changed

+163
-95
lines changed

include/srsran/support/prefixed_logger.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ template <typename Prefix>
2525
class prefixed_logger
2626
{
2727
public:
28-
prefixed_logger(const std::string& log_name, Prefix prefix_) :
29-
logger(srslog::fetch_basic_logger(log_name, false)), prefix(prefix_)
28+
prefixed_logger(const std::string& log_name, Prefix prefix_, const char* prefix_separator_ = "") :
29+
logger(srslog::fetch_basic_logger(log_name, false)), prefix(prefix_), prefix_separator(prefix_separator_)
3030
{
3131
}
3232

@@ -196,6 +196,7 @@ class prefixed_logger
196196
private:
197197
srslog::basic_logger& logger;
198198
Prefix prefix;
199+
const char* prefix_separator;
199200

200201
template <typename... Args>
201202
void log_helper(srslog::log_channel& channel, const char* fmt, Args&&... args) const
@@ -205,7 +206,7 @@ class prefixed_logger
205206
}
206207
fmt::memory_buffer buffer;
207208
fmt::format_to(buffer, fmt, std::forward<Args>(args)...);
208-
channel("{}{}", prefix, to_c_str(buffer));
209+
channel("{}{}{}", prefix, prefix_separator, to_c_str(buffer));
209210
}
210211

211212
template <typename It, typename... Args>
@@ -216,7 +217,7 @@ class prefixed_logger
216217
}
217218
fmt::memory_buffer buffer;
218219
fmt::format_to(buffer, fmt, std::forward<Args>(args)...);
219-
channel(it_begin, it_end, "{}{}", prefix, to_c_str(buffer));
220+
channel(it_begin, it_end, "{}{}{}", prefix, prefix_separator, to_c_str(buffer));
220221
}
221222

222223
template <typename... Args>
@@ -227,7 +228,7 @@ class prefixed_logger
227228
}
228229
fmt::memory_buffer buffer;
229230
fmt::format_to(buffer, fmt, std::forward<Args>(args)...);
230-
channel(msg, len, "{}{}", prefix, to_c_str(buffer));
231+
channel(msg, len, "{}{}{}", prefix, prefix_separator, to_c_str(buffer));
231232
}
232233
};
233234

lib/f1ap/common/proc_logger.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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/f1ap/common/f1ap_ue_id.h"
14+
15+
namespace srsran {
16+
17+
struct f1ap_common_log_prefix {
18+
f1ap_common_log_prefix(gnb_du_ue_f1ap_id_t du_ue_id_, const char* proc_name_ = nullptr) :
19+
du_ue_id(du_ue_id_), proc_name(proc_name_)
20+
{
21+
}
22+
f1ap_common_log_prefix(gnb_du_ue_f1ap_id_t du_ue_id_,
23+
gnb_cu_ue_f1ap_id_t cu_ue_id_,
24+
const char* proc_name_ = nullptr) :
25+
du_ue_id(du_ue_id_), cu_ue_id(cu_ue_id_), proc_name(proc_name_)
26+
{
27+
}
28+
f1ap_common_log_prefix(gnb_cu_ue_f1ap_id_t cu_ue_id_, const char* proc_name_ = nullptr) :
29+
cu_ue_id(cu_ue_id_), proc_name(proc_name_)
30+
{
31+
}
32+
33+
gnb_du_ue_f1ap_id_t du_ue_id = gnb_du_ue_f1ap_id_t::invalid;
34+
gnb_cu_ue_f1ap_id_t cu_ue_id = gnb_cu_ue_f1ap_id_t::invalid;
35+
const char* proc_name = nullptr;
36+
};
37+
38+
} // namespace srsran
39+
namespace fmt {
40+
41+
template <>
42+
struct formatter<srsran::f1ap_common_log_prefix> {
43+
template <typename ParseContext>
44+
auto parse(ParseContext& ctx)
45+
{
46+
return ctx.begin();
47+
}
48+
49+
template <typename FormatContext>
50+
auto format(const srsran::f1ap_common_log_prefix& prefix, FormatContext& ctx)
51+
{
52+
bool first_id = true;
53+
auto get_sep = [&first_id]() { return std::exchange(first_id, false) ? "" : " "; };
54+
if (prefix.du_ue_id != srsran::gnb_du_ue_f1ap_id_t::invalid) {
55+
format_to(ctx.out(), "{}GNB-DU-UE-F1AP-ID={}", get_sep(), prefix.du_ue_id);
56+
}
57+
if (prefix.cu_ue_id != srsran::gnb_cu_ue_f1ap_id_t::invalid) {
58+
format_to(ctx.out(), "{}GNB-CU-UE-F1AP-ID={}", get_sep(), prefix.cu_ue_id);
59+
}
60+
if (prefix.proc_name != nullptr) {
61+
format_to(ctx.out(), "{}proc=\"{}\"", get_sep(), prefix.proc_name);
62+
}
63+
return ctx.out();
64+
}
65+
};
66+
67+
} // namespace fmt

lib/f1ap/cu_cp/procedures/ue_context_modification_procedure.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ ue_context_modification_procedure::ue_context_modification_procedure(
2222
const f1ap_ue_context_modification_request& request_,
2323
f1ap_ue_context& ue_ctxt_,
2424
f1ap_message_notifier& f1ap_notif_) :
25-
request(request_), ue_ctxt(ue_ctxt_), f1ap_notifier(f1ap_notif_)
25+
request(request_), ue_ctxt(ue_ctxt_), f1ap_notifier(f1ap_notif_), logger(srslog::fetch_basic_logger("CU-CP-F1"))
2626
{
2727
}
2828

2929
void ue_context_modification_procedure::operator()(coro_context<async_task<f1ap_ue_context_modification_response>>& ctx)
3030
{
3131
CORO_BEGIN(ctx);
3232

33-
ue_ctxt.logger.log_debug("\"{}\" initialized", name());
33+
logger.debug("{}: Procedure started...", f1ap_ue_log_prefix{ue_ctxt.ue_ids, name()});
3434

3535
// Subscribe to respective publisher to receive UE CONTEXT MODIFICATION RESPONSE/FAILURE message.
3636
transaction_sink.subscribe_to(ue_ctxt.ev_mng.context_modification_outcome);
@@ -60,7 +60,9 @@ void ue_context_modification_procedure::send_ue_context_modification_request()
6060
if (ue_ctxt.logger.get_basic_logger().debug.enabled()) {
6161
asn1::json_writer js;
6262
f1ap_ue_ctxt_mod_request_msg.pdu.to_json(js);
63-
ue_ctxt.logger.log_debug("Containerized UeContextModificationRequest: {}", js.to_string());
63+
logger.debug("{}: Containerized UEContextModificationRequest: {}",
64+
f1ap_ue_log_prefix{ue_ctxt.ue_ids, name()},
65+
js.to_string());
6466
}
6567

6668
// send UE context modification request message
@@ -71,34 +73,27 @@ f1ap_ue_context_modification_response ue_context_modification_procedure::create_
7173
{
7274
f1ap_ue_context_modification_response res{};
7375

76+
auto logger_prefix = f1ap_ue_log_prefix{ue_ctxt.ue_ids, name()};
77+
7478
if (transaction_sink.successful()) {
7579
const asn1::f1ap::ue_context_mod_resp_s& resp = transaction_sink.response();
76-
ue_ctxt.logger.log_debug("Received UeContextModificationResponse");
77-
if (ue_ctxt.logger.get_basic_logger().debug.enabled()) {
78-
asn1::json_writer js;
79-
resp.to_json(js);
80-
ue_ctxt.logger.log_debug("Containerized UeContextModificationResponse: {}", js.to_string());
81-
}
80+
81+
logger.info("{}: Procedure finished successfully", logger_prefix);
82+
8283
fill_f1ap_ue_context_modification_response(res, resp);
8384

84-
ue_ctxt.logger.log_debug("\"{}\" finalized", name());
8585
} else if (transaction_sink.failed()) {
8686
const asn1::f1ap::ue_context_mod_fail_s& fail = transaction_sink.failure();
87-
ue_ctxt.logger.log_debug("Received UeContextModificationFailure cause={}", get_cause_str(fail->cause));
88-
if (ue_ctxt.logger.get_basic_logger().debug.enabled()) {
89-
asn1::json_writer js;
90-
(*transaction_sink.failure()).to_json(js);
91-
ue_ctxt.logger.log_debug("Containerized UeContextModificationFailure: {}", js.to_string());
92-
}
93-
fill_f1ap_ue_context_modification_response(res, fail);
9487

95-
ue_ctxt.logger.log_error("\"{}\" failed", name());
88+
logger.warning("{}: Procedure failed. Cause: {}", logger_prefix, get_cause_str(fail->cause));
89+
90+
fill_f1ap_ue_context_modification_response(res, fail);
9691
} else {
97-
ue_ctxt.logger.log_warning("UeContextModificationResponse timeout");
92+
logger.warning("{}: Procedure failed. Cause: Timeout reached for UEContextModificationResponse reception",
93+
logger_prefix);
94+
9895
res.success = false;
9996
res.cause = cause_misc_t::unspecified;
100-
101-
ue_ctxt.logger.log_error("\"{}\" failed", name());
10297
}
10398

10499
return res;

lib/f1ap/cu_cp/procedures/ue_context_modification_procedure.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class ue_context_modification_procedure
4242
const f1ap_ue_context_modification_request request;
4343
f1ap_ue_context& ue_ctxt;
4444
f1ap_message_notifier& f1ap_notifier;
45+
srslog::basic_logger& logger;
4546

4647
protocol_transaction_outcome_observer<asn1::f1ap::ue_context_mod_resp_s, asn1::f1ap::ue_context_mod_fail_s>
4748
transaction_sink;

lib/f1ap/cu_cp/procedures/ue_context_release_procedure.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ using namespace asn1::f1ap;
2121
ue_context_release_procedure::ue_context_release_procedure(const f1ap_ue_context_release_command& cmd_,
2222
f1ap_ue_context& ue_ctxt_,
2323
f1ap_message_notifier& f1ap_notif_) :
24-
ue_ctxt(ue_ctxt_), f1ap_notifier(f1ap_notif_)
24+
ue_ctxt(ue_ctxt_), f1ap_notifier(f1ap_notif_), logger(srslog::fetch_basic_logger("CU-CP-F1"))
2525
{
2626
command->gnb_cu_ue_f1ap_id = gnb_cu_ue_f1ap_id_to_uint(ue_ctxt.ue_ids.cu_ue_f1ap_id);
2727
command->gnb_du_ue_f1ap_id = gnb_du_ue_f1ap_id_to_uint(ue_ctxt.ue_ids.du_ue_f1ap_id);
@@ -41,7 +41,7 @@ void ue_context_release_procedure::operator()(coro_context<async_task<ue_index_t
4141
{
4242
CORO_BEGIN(ctx);
4343

44-
ue_ctxt.logger.log_debug("\"{}\" initialized", name());
44+
logger.debug("{}: Procedure started...", f1ap_ue_log_prefix{ue_ctxt.ue_ids, name()});
4545

4646
transaction_sink.subscribe_to(ue_ctxt.ev_mng.context_release_complete);
4747

@@ -69,7 +69,8 @@ void ue_context_release_procedure::send_ue_context_release_command()
6969
if (ue_ctxt.logger.get_basic_logger().debug.enabled()) {
7070
asn1::json_writer js;
7171
f1ap_ue_ctxt_rel_msg.pdu.to_json(js);
72-
ue_ctxt.logger.log_debug("Containerized UeContextReleaseCommand: {}", js.to_string());
72+
logger.debug(
73+
"{}: Containerized UEContextReleaseCommand: {}", f1ap_ue_log_prefix{ue_ctxt.ue_ids, name()}, js.to_string());
7374
}
7475

7576
// send UE Context Release Command
@@ -79,15 +80,13 @@ void ue_context_release_procedure::send_ue_context_release_command()
7980
ue_index_t
8081
ue_context_release_procedure::create_ue_context_release_complete(const asn1::f1ap::ue_context_release_complete_s& msg)
8182
{
82-
ue_ctxt.logger.log_debug("Received UeContextReleaseComplete");
83-
8483
ue_index_t ret = ue_index_t::invalid;
8584

8685
if (msg->gnb_du_ue_f1ap_id == gnb_du_ue_f1ap_id_to_uint(ue_ctxt.ue_ids.du_ue_f1ap_id)) {
8786
ret = ue_ctxt.ue_ids.ue_index;
88-
ue_ctxt.logger.log_debug("\"{}\" finalized", name());
87+
logger.info("{}: Procedure finished successfully.", f1ap_ue_log_prefix{ue_ctxt.ue_ids, name()});
8988
} else {
90-
ue_ctxt.logger.log_error("\"{}\" failed", name());
89+
logger.warning("{}: Procedure failed.", f1ap_ue_log_prefix{ue_ctxt.ue_ids, name()});
9190
}
9291

9392
return ret;

lib/f1ap/cu_cp/procedures/ue_context_release_procedure.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class ue_context_release_procedure
4242
f1ap_ue_context& ue_ctxt;
4343
asn1::f1ap::ue_context_release_cmd_s command;
4444
f1ap_message_notifier& f1ap_notifier;
45+
srslog::basic_logger& logger;
4546

4647
protocol_transaction_outcome_observer<asn1::f1ap::ue_context_release_complete_s> transaction_sink;
4748
};

lib/f1ap/cu_cp/procedures/ue_context_setup_procedure.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "ue_context_setup_procedure.h"
1212
#include "../f1ap_asn1_helpers.h"
13+
#include "cu_cp/ue_context/f1ap_ue_logger.h"
1314
#include "srsran/f1ap/common/f1ap_message.h"
1415

1516
using namespace srsran;
@@ -88,7 +89,7 @@ bool ue_context_setup_procedure::allocate_cu_ue_id()
8889

8990
// Create UE context and store it.
9091
f1ap_ue_context& ue_ctxt = ue_ctxt_list.add_ue(request.ue_index, tmp_cu_ue_f1ap_id);
91-
logger.debug("ue={}: Added UE (cu_ue_f1ap_id={}, du_ue_f1ap_id=<n/a>)", ue_ctxt.ue_ids.ue_index, tmp_cu_ue_f1ap_id);
92+
logger.debug("{}: UE successfully created.", f1ap_ue_log_prefix{ue_ctxt.ue_ids, name()});
9293

9394
// Store identifiers.
9495
new_cu_ue_f1ap_id = tmp_cu_ue_f1ap_id;

lib/f1ap/cu_cp/ue_context/f1ap_cu_ue_context.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@
1919
namespace srsran {
2020
namespace srs_cu_cp {
2121

22-
struct f1ap_ue_ids {
23-
const ue_index_t ue_index = ue_index_t::invalid;
24-
const gnb_cu_ue_f1ap_id_t cu_ue_f1ap_id = gnb_cu_ue_f1ap_id_t::invalid;
25-
gnb_du_ue_f1ap_id_t du_ue_f1ap_id = gnb_du_ue_f1ap_id_t::invalid;
26-
};
27-
2822
struct f1ap_ue_context {
2923
f1ap_ue_ids ue_ids;
3024
f1ap_rrc_message_notifier* rrc_notifier = nullptr;
@@ -35,7 +29,7 @@ struct f1ap_ue_context {
3529
f1ap_ue_logger logger;
3630

3731
f1ap_ue_context(ue_index_t ue_index_, gnb_cu_ue_f1ap_id_t cu_ue_f1ap_id_, timer_factory timers_) :
38-
ue_ids({ue_index_, cu_ue_f1ap_id_}), ev_mng(timers_), logger("CU-CP-F1", {ue_index_, cu_ue_f1ap_id_})
32+
ue_ids({ue_index_, cu_ue_f1ap_id_}), ev_mng(timers_), logger("CU-CP-F1", {ue_ids}, " ")
3933
{
4034
}
4135
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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/cu_cp/cu_cp_types.h"
14+
#include "srsran/f1ap/common/f1ap_ue_id.h"
15+
16+
namespace srsran {
17+
namespace srs_cu_cp {
18+
19+
/// Identifiers for a UE in F1AP-CU.
20+
struct f1ap_ue_ids {
21+
const ue_index_t ue_index = ue_index_t::invalid;
22+
const gnb_cu_ue_f1ap_id_t cu_ue_f1ap_id = gnb_cu_ue_f1ap_id_t::invalid;
23+
gnb_du_ue_f1ap_id_t du_ue_f1ap_id = gnb_du_ue_f1ap_id_t::invalid;
24+
};
25+
26+
} // namespace srs_cu_cp
27+
} // namespace srsran

0 commit comments

Comments
 (0)