mac_nr: fix packing order of SDU and CEs

SDUs need to go first in the MAC PDU, followed by CEs
master
Andre Puschmann 4 years ago
parent 399954a970
commit cf696138d3

@ -62,12 +62,12 @@ private:
typedef enum { none, pending, transmitted } msg3_state_t;
msg3_state_t msg3_state = none;
static constexpr uint32_t MIN_RLC_PDU_LEN =
static constexpr int32_t MIN_RLC_PDU_LEN =
5; ///< minimum bytes that need to be available in a MAC PDU for attempting to add another RLC SDU
srsran::unique_byte_buffer_t rlc_buff = nullptr;
srsran::mac_sch_pdu_nr tx_pdu;
srsran::mac_sch_pdu_nr tx_pdu; /// single MAC PDU for packing
enum { no_bsr, sbsr_ce, lbsr_ce } add_bsr_ce = no_bsr; /// BSR procedure requests MUX to add a BSR CE

@ -70,25 +70,32 @@ srsran::unique_byte_buffer_t mux_nr::get_pdu(uint32_t max_pdu_len)
msg3_transmitted();
} else {
// Pack normal UL data PDU
int32_t remaining_len = tx_pdu.get_remaing_len(); // local variable to reserv space for CEs
if (add_bsr_ce == sbsr_ce) {
tx_pdu.add_sbsr_ce(mac.generate_sbsr());
add_bsr_ce = no_bsr;
// reserve space for SBSR
remaining_len -= 2;
}
// TODO: Add proper priority handling
// First add MAC SDUs
for (const auto& lc : logical_channels) {
while (tx_pdu.get_remaing_len() >= MIN_RLC_PDU_LEN) {
// TODO: Add proper priority handling
logger.debug("Adding SDUs for LCID=%d (max %d B)", lc.lcid, remaining_len);
while (remaining_len >= MIN_RLC_PDU_LEN) {
// read RLC PDU
rlc_buff->clear();
uint8_t* rd = rlc_buff->msg;
// Determine space for RLC
uint32_t rlc_opportunity = tx_pdu.get_remaing_len();
rlc_opportunity -= tx_pdu.get_remaing_len() >= srsran::mac_sch_subpdu_nr::MAC_SUBHEADER_LEN_THRESHOLD ? 3 : 2;
remaining_len -= remaining_len >= srsran::mac_sch_subpdu_nr::MAC_SUBHEADER_LEN_THRESHOLD ? 3 : 2;
// Read PDU from RLC
int pdu_len = rlc->read_pdu(lc.lcid, rd, rlc_opportunity);
int pdu_len = rlc->read_pdu(lc.lcid, rd, remaining_len);
if (pdu_len > remaining_len) {
logger.error("Can't add SDU of %d B. Available space %d B", pdu_len, remaining_len);
break;
} else {
// Add SDU if RLC has something to tx
if (pdu_len > 0) {
rlc_buff->N_bytes = pdu_len;
@ -102,10 +109,22 @@ srsran::unique_byte_buffer_t mux_nr::get_pdu(uint32_t max_pdu_len)
} else {
break;
}
remaining_len -= pdu_len;
logger.debug("%d B remaining PDU", remaining_len);
}
}
}
// Second add fixed-sized MAC CEs (e.g. SBSR)
if (add_bsr_ce == sbsr_ce) {
tx_pdu.add_sbsr_ce(mac.generate_sbsr());
add_bsr_ce = no_bsr;
}
// Lastly, add variable-sized MAC CEs
}
// Pack PDU
tx_pdu.pack();

@ -325,9 +325,9 @@ int mac_nr_ul_logical_channel_prioritization_test2()
int mac_nr_ul_periodic_bsr_test()
{
// PDU layout (10 B in total)
// - SBSR
// - 6B LCID=4
const uint8_t tv1[] = {0x3d, 0xd1, 0x04, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04};
// - 6B LCID=4 (+2B header, 8 B total)
// - 2B SBSR
const uint8_t tv1[] = {0x04, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x3d, 0xd1};
// PDU layout (10 B in total)
// - 8B LCID=4

Loading…
Cancel
Save