Skip to content

Commit 499c82f

Browse files
frankistcodebot
authored andcommitted
mac: downgrade logging of invalid MAC PDUs from warning to info level
1 parent 8094004 commit 499c82f

File tree

4 files changed

+31
-34
lines changed

4 files changed

+31
-34
lines changed

lib/mac/mac_ul/mac_ul_sch_pdu.cpp

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,17 @@
1313

1414
using namespace srsran;
1515

16-
bool mac_ul_sch_subpdu::unpack(const byte_buffer& subpdu)
16+
error_type<std::string> mac_ul_sch_subpdu::unpack(const byte_buffer& subpdu)
1717
{
1818
byte_buffer_reader reader = subpdu;
1919
return unpack(reader);
2020
}
2121

22-
bool mac_ul_sch_subpdu::unpack(byte_buffer_reader& subpdu_reader)
22+
error_type<std::string> mac_ul_sch_subpdu::unpack(byte_buffer_reader& subpdu_reader)
2323
{
2424
unsigned subpdu_len = subpdu_reader.length();
2525
if (subpdu_len == 0) {
26-
srslog::fetch_basic_logger("MAC", true).info("Invalid UL MAC PDU. Cause: Empty subPDU.");
27-
return false;
26+
return std::string{"Empty subPDU."};
2827
}
2928
payload_view = {};
3029

@@ -35,18 +34,15 @@ bool mac_ul_sch_subpdu::unpack(byte_buffer_reader& subpdu_reader)
3534
header_length = 1;
3635

3736
if (not lcid_val.is_valid_lcid()) {
38-
srslog::fetch_basic_logger("MAC").info("Invalid UL MAC PDU. Cause: Unrecognized lcid={}.", lcid_val);
39-
return false;
37+
return fmt::format("Unrecognized lcid={}.", lcid_val);
4038
}
4139

4240
uint32_t sdu_length = 0;
4341
if (lcid_val.has_length_field()) {
4442
// Variable-sized MAC CEs or SDUs
4543

4644
if (subpdu_len < (F_bit ? 3 : 2)) {
47-
srslog::fetch_basic_logger("MAC").info(
48-
"Invalid UL MAC PDU. Cause: Not enough bytes remaining in PDU to decode length prefix.");
49-
return false;
45+
return fmt::format("Not enough bytes remaining in PDU to decode length prefix.");
5046
}
5147

5248
// Read first length byte
@@ -62,11 +58,8 @@ bool mac_ul_sch_subpdu::unpack(byte_buffer_reader& subpdu_reader)
6258
}
6359

6460
if (subpdu_len < header_length + sdu_length) {
65-
srslog::fetch_basic_logger("MAC").info(
66-
"Invalid UL MAC PDU. Cause: Not enough bytes remaining in PDU to decode SDU payload ({} < {}).",
67-
subpdu_len - header_length,
68-
sdu_length);
69-
return false;
61+
return fmt::format(
62+
"Not enough bytes remaining in PDU to decode SDU payload ({} < {}).", subpdu_len - header_length, sdu_length);
7063
}
7164
payload_view = subpdu_reader.split_and_advance(sdu_length);
7265
} else {
@@ -80,39 +73,39 @@ bool mac_ul_sch_subpdu::unpack(byte_buffer_reader& subpdu_reader)
8073
sdu_length = lcid_val.sizeof_ce();
8174

8275
if (subpdu_len < header_length + sdu_length) {
83-
srslog::fetch_basic_logger("MAC").info(
84-
"Invalid UL MAC PDU. Cause: Not enough bytes remaining in PDU to decode CE payload ({} < {}).",
85-
subpdu_len - header_length,
86-
sdu_length);
87-
return false;
76+
return fmt::format("Not enough bytes remaining in PDU to decode CE payload ({} < {}).",
77+
subpdu_len - header_length,
78+
sdu_length);
8879
}
8980
payload_view = subpdu_reader.split_and_advance(sdu_length);
9081
}
9182
}
92-
return true;
83+
return {};
9384
}
9485

9586
void mac_ul_sch_pdu::clear()
9687
{
9788
subpdus.clear();
9889
}
9990

100-
bool mac_ul_sch_pdu::unpack(const byte_buffer& payload)
91+
error_type<std::string> mac_ul_sch_pdu::unpack(const byte_buffer& payload)
10192
{
10293
byte_buffer_reader reader = payload;
10394
while (not reader.empty()) {
10495
if (subpdus.full()) {
10596
srslog::fetch_basic_logger("MAC", true)
10697
.warning("Maximum number of subPDUs per UL MAC PDU limit of {} was reached.", (unsigned)MAX_SUBPDUS_PER_PDU);
107-
return true;
98+
return {};
10899
}
109-
mac_ul_sch_subpdu& subpdu = subpdus.emplace_back();
110-
if (not subpdu.unpack(reader)) {
100+
101+
mac_ul_sch_subpdu& subpdu = subpdus.emplace_back();
102+
error_type<std::string> ret = subpdu.unpack(reader);
103+
if (ret.is_error()) {
111104
// Discard all decoded subPDUs.
112105
clear();
113-
return false;
106+
return ret;
114107
}
115108
}
116109

117-
return true;
110+
return {};
118111
}

lib/mac/mac_ul/mac_ul_sch_pdu.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ namespace srsran {
2424
class mac_ul_sch_subpdu
2525
{
2626
public:
27-
/// Returns buffer view with begin() pointing at the first byte after the decoded subPDU.
28-
bool unpack(byte_buffer_reader& subpdu_reader);
29-
bool unpack(const byte_buffer& subpdu);
27+
/// \brief Unpacks a subPDU from a byte buffer reader.
28+
error_type<std::string> unpack(byte_buffer_reader& subpdu_reader);
3029

30+
/// \brief Unpacks a subPDU from a byte buffer containing an subPDU.
31+
error_type<std::string> unpack(const byte_buffer& subpdu);
32+
33+
/// Get LCID of the unpacked subPDU.
3134
lcid_ul_sch_t lcid() const { return lcid_val; }
3235
uint32_t total_length() const { return header_length + payload().length(); }
3336
byte_buffer_view payload() const { return payload_view; }
@@ -55,7 +58,7 @@ class mac_ul_sch_pdu
5558

5659
void clear();
5760

58-
bool unpack(const byte_buffer& payload);
61+
error_type<std::string> unpack(const byte_buffer& payload);
5962

6063
mac_ul_sch_subpdu& subpdu(size_t i) { return subpdus[i]; }
6164
const mac_ul_sch_subpdu& subpdu(size_t i) const { return subpdus[i]; }

lib/mac/mac_ul/pdu_rx_handler.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ bool pdu_rx_handler::handle_rx_pdu(slot_point sl_rx, du_cell_index_t cell_index,
7676
du_ue_index_t ue_index = rnti_table[pdu.rnti];
7777

7878
// > Decode MAC UL PDU.
79-
decoded_mac_rx_pdu ctx{sl_rx, cell_index, std::move(pdu), ue_index};
80-
if (not ctx.decoded_subpdus.unpack(ctx.pdu_rx.pdu)) {
81-
logger.warning("{}: Failed to decode PDU", create_prefix(ctx));
79+
decoded_mac_rx_pdu ctx{sl_rx, cell_index, std::move(pdu), ue_index};
80+
error_type<std::string> ret = ctx.decoded_subpdus.unpack(ctx.pdu_rx.pdu);
81+
if (ret.is_error()) {
82+
logger.info("{}: Failed to decode MAC UL PDU. Cause: {}", create_prefix(ctx), ret.error());
8283
return false;
8384
}
8485

tests/unittests/mac/mac_ul_pdu_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ TEST(mac_ul_pdu, handle_the_case_when_a_pdu_has_too_many_subpdus)
590590
}
591591

592592
mac_ul_sch_pdu pdu;
593-
pdu.unpack(msg); // Should not crash.
593+
ASSERT_TRUE(pdu.unpack(msg)); // Should not crash.
594594
ASSERT_GT(pdu.nof_subpdus(), 0);
595595
}
596596

0 commit comments

Comments
 (0)