From c615df9d1def4dbcb8721ad074423068a5be4cc2 Mon Sep 17 00:00:00 2001 From: Francisco Date: Tue, 2 Nov 2021 10:32:23 +0000 Subject: [PATCH] nr,gnb,mac: prioritize CRNTI CE handling over remaining SDUs and CEs in gNB mac receiver --- lib/include/srsran/mac/mac_sch_pdu_nr.h | 8 +++--- lib/src/mac/mac_sch_pdu_nr.cc | 5 ---- srsenb/hdr/stack/mac/nr/ue_nr.h | 2 +- srsenb/src/stack/mac/nr/ue_nr.cc | 34 +++++++++++++++---------- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/lib/include/srsran/mac/mac_sch_pdu_nr.h b/lib/include/srsran/mac/mac_sch_pdu_nr.h index 12feb6c71..d45389d93 100644 --- a/lib/include/srsran/mac/mac_sch_pdu_nr.h +++ b/lib/include/srsran/mac/mac_sch_pdu_nr.h @@ -29,7 +29,7 @@ class mac_sch_subpdu_nr { public: // 3GPP 38.321 v15.3.0 Combined Tables 6.2.1-1, 6.2.1-2 - typedef enum { + enum nr_lcid_sch_t { // Values for DL-SCH CCCH = 0b000000, DRX_CMD = 0b111100, @@ -44,12 +44,14 @@ public: CCCH_SIZE_64 = 0b000000, SE_PHR = 0b111001, // Single Entry PHR + MIN_LCID = 0b000001, + MAX_LCID = 0b100000, SHORT_BSR = 0b111101, LONG_BSR = 0b111110, // Common PADDING = 0b111111, - } nr_lcid_sch_t; + }; // SDUs up to 256 B can use the short 8-bit L field static const int32_t MAC_SUBHEADER_LEN_THRESHOLD = 256; @@ -188,7 +190,7 @@ public: void pack(); int unpack(const uint8_t* payload, const uint32_t& len); - uint32_t get_num_subpdus(); + uint32_t get_num_subpdus() const { return subpdus.size(); } const mac_sch_subpdu_nr& get_subpdu(const uint32_t& index) const; mac_sch_subpdu_nr& get_subpdu(uint32_t index); bool is_ulsch(); diff --git a/lib/src/mac/mac_sch_pdu_nr.cc b/lib/src/mac/mac_sch_pdu_nr.cc index 98aea245b..e3b189725 100644 --- a/lib/src/mac/mac_sch_pdu_nr.cc +++ b/lib/src/mac/mac_sch_pdu_nr.cc @@ -444,11 +444,6 @@ int mac_sch_pdu_nr::unpack(const uint8_t* payload, const uint32_t& len) return SRSRAN_SUCCESS; } -uint32_t mac_sch_pdu_nr::get_num_subpdus() -{ - return subpdus.size(); -} - const mac_sch_subpdu_nr& mac_sch_pdu_nr::get_subpdu(const uint32_t& index) const { return subpdus.at(index); diff --git a/srsenb/hdr/stack/mac/nr/ue_nr.h b/srsenb/hdr/stack/mac/nr/ue_nr.h index 519f82b38..e5576cbe0 100644 --- a/srsenb/hdr/stack/mac/nr/ue_nr.h +++ b/srsenb/hdr/stack/mac/nr/ue_nr.h @@ -71,7 +71,7 @@ public: private: // helper methods uint32_t buff_size_field_to_bytes(uint32_t buff_size_index, const srsran::bsr_format_nr_t& format); - int process_ce_subpdu(srsran::mac_sch_subpdu_nr& subpdu); + int process_ce_subpdu(const srsran::mac_sch_subpdu_nr& subpdu); rlc_interface_mac* rlc = nullptr; rrc_interface_mac_nr* rrc = nullptr; diff --git a/srsenb/src/stack/mac/nr/ue_nr.cc b/srsenb/src/stack/mac/nr/ue_nr.cc index 3d416d014..50682f40b 100644 --- a/srsenb/src/stack/mac/nr/ue_nr.cc +++ b/srsenb/src/stack/mac/nr/ue_nr.cc @@ -74,29 +74,35 @@ int ue_nr::process_pdu(srsran::unique_byte_buffer_t pdu) logger.info("Rx PDU: rnti=0x%x, %s", rnti, srsran::to_c_str(str_buffer)); } - // First, process MAC CEs in reverse order (CE like C-RNTI get handled first) - for (uint32_t n = mac_pdu_ul.get_num_subpdus(), i = mac_pdu_ul.get_num_subpdus() - 1; n > 0; --n, i = n - 1) { - srsran::mac_sch_subpdu_nr subpdu = mac_pdu_ul.get_subpdu(i); - if (not subpdu.is_sdu()) { + // Process MAC CRNTI CE first, if it exists + uint32_t crnti_ce_pos = mac_pdu_ul.get_num_subpdus(); + for (uint32_t n = mac_pdu_ul.get_num_subpdus(); n > 0; --n) { + srsran::mac_sch_subpdu_nr& subpdu = mac_pdu_ul.get_subpdu(n - 1); + if (subpdu.is_sdu() and subpdu.get_lcid() == srsran::mac_sch_subpdu_nr::nr_lcid_sch_t::CRNTI) { + if (process_ce_subpdu(subpdu) != SRSRAN_SUCCESS) { + return SRSRAN_ERROR; + } + crnti_ce_pos = n - 1; + } + } + + // Process SDUs and remaining MAC CEs + for (uint32_t n = 0; n < mac_pdu_ul.get_num_subpdus(); ++n) { + srsran::mac_sch_subpdu_nr& subpdu = mac_pdu_ul.get_subpdu(n); + if (subpdu.is_sdu()) { + rrc->set_activity_user(rnti); + rlc->write_pdu(rnti, subpdu.get_lcid(), subpdu.get_sdu(), subpdu.get_sdu_length()); + } else if (n != crnti_ce_pos) { if (process_ce_subpdu(subpdu) != SRSRAN_SUCCESS) { return SRSRAN_ERROR; } } } - // Second, handle all SDUs in order to avoid unnecessary reordering at higher layers - for (uint32_t i = 0; i < mac_pdu_ul.get_num_subpdus(); ++i) { - srsran::mac_sch_subpdu_nr subpdu = mac_pdu_ul.get_subpdu(i); - if (subpdu.is_sdu()) { - rrc->set_activity_user(rnti); - rlc->write_pdu(rnti, subpdu.get_lcid(), subpdu.get_sdu(), subpdu.get_sdu_length()); - } - } - return SRSRAN_SUCCESS; } -int ue_nr::process_ce_subpdu(srsran::mac_sch_subpdu_nr& subpdu) +int ue_nr::process_ce_subpdu(const srsran::mac_sch_subpdu_nr& subpdu) { // Handle MAC CEs switch (subpdu.get_lcid()) {