From 7145cd235804618daea7bb02118c83ac0cae7396 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Tue, 25 Jun 2019 15:37:47 +0200 Subject: [PATCH] fix padding BSR generation and add test for it --- srsue/src/stack/mac/proc_bsr.cc | 5 +-- srsue/test/mac_test.cc | 60 +++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/srsue/src/stack/mac/proc_bsr.cc b/srsue/src/stack/mac/proc_bsr.cc index 7dee8b025..0d33f9216 100644 --- a/srsue/src/stack/mac/proc_bsr.cc +++ b/srsue/src/stack/mac/proc_bsr.cc @@ -369,8 +369,9 @@ bool bsr_proc::generate_padding_bsr(uint32_t nof_padding_bytes, bsr_t* bsr) pthread_mutex_lock(&mutex); - if (triggered_bsr_type != NONE && nof_padding_bytes >= 2) { - + if (triggered_bsr_type == NONE && nof_padding_bytes >= 2) { + // generate padding BSR + triggered_bsr_type = PADDING; generate_bsr(bsr, nof_padding_bytes); ret = true; diff --git a/srsue/test/mac_test.cc b/srsue/test/mac_test.cc index ed9b37e81..57185e91a 100644 --- a/srsue/test/mac_test.cc +++ b/srsue/test/mac_test.cc @@ -644,6 +644,61 @@ int mac_ul_sch_pdu_with_short_bsr_test() return SRSLTE_SUCCESS; } +// PDU with only padding BSR (long BSR) and the rest padding +int mac_ul_sch_pdu_with_padding_bsr_test() +{ + const uint8_t tv[] = {0x3e, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + + srslte::log_filter mac_log("MAC"); + mac_log.set_level(srslte::LOG_LEVEL_DEBUG); + mac_log.set_hex_limit(100000); + + srslte::log_filter rlc_log("RLC"); + rlc_log.set_level(srslte::LOG_LEVEL_DEBUG); + rlc_log.set_hex_limit(100000); + + // dummy layers + phy_dummy phy; + rlc_dummy rlc(&rlc_log); + rrc_dummy rrc; + + // the actual MAC + mac mac; + mac.init(&phy, &rlc, &rrc, &mac_log); + const uint16_t crnti = 0x1001; + mac.set_ho_rnti(crnti, 0); + + // create UL action and grant and push MAC PDU + { + mac_interface_phy_lte::tb_action_ul_t ul_action = {}; + mac_interface_phy_lte::mac_grant_ul_t mac_grant = {}; + + mac_grant.rnti = crnti; // make sure MAC picks it up as valid UL grant + mac_grant.tb.ndi_present = true; + mac_grant.tb.ndi = true; + mac_grant.tb.tbs = 10; // give enough room for Padding BSR + int cc_idx = 0; + + // Send grant to MAC and get action for this TB, then call tb_decoded to unlock MAC + mac.new_grant_ul(cc_idx, mac_grant, &ul_action); + + // print generated PDU + mac_log.info_hex(ul_action.tb.payload, mac_grant.tb.tbs, "Generated PDU (%d B)\n", mac_grant.tb.tbs); +#if HAVE_PCAP + pcap_handle->write_ul_crnti(ul_action.tb.payload, mac_grant.tb.tbs, 0x1001, true, 1); +#endif + + TESTASSERT(memcmp(ul_action.tb.payload, tv, sizeof(tv)) == 0); + } + + // make sure MAC PDU thread picks up before stopping + sleep(1); + mac.run_tti(0); + mac.stop(); + + return SRSLTE_SUCCESS; +} + int main(int argc, char** argv) { #if HAVE_PCAP @@ -681,5 +736,10 @@ int main(int argc, char** argv) return -1; } + if (mac_ul_sch_pdu_with_padding_bsr_test()) { + printf("mac_ul_sch_pdu_with_padding_bsr_test() test failed.\n"); + return -1; + } + return 0; }