From eeddbe69cedc1d49addd118f484ed8161a2d894c Mon Sep 17 00:00:00 2001 From: David Rupprecht Date: Mon, 12 Apr 2021 16:52:06 +0200 Subject: [PATCH] Fixes repeating proc RA due to SR trigger --- srsue/hdr/stack/mac_nr/mac_nr.h | 4 + srsue/hdr/stack/mac_nr/mac_nr_interfaces.h | 12 +- srsue/hdr/stack/mac_nr/proc_sr_nr.h | 9 +- srsue/src/stack/mac_nr/mac_nr.cc | 2 +- srsue/src/stack/mac_nr/proc_bsr_nr.cc | 2 +- srsue/src/stack/mac_nr/proc_sr_nr.cc | 11 +- srsue/src/stack/mac_nr/test/CMakeLists.txt | 4 + .../src/stack/mac_nr/test/proc_sr_nr_test.cc | 104 ++++++++++++++++++ 8 files changed, 135 insertions(+), 13 deletions(-) create mode 100644 srsue/src/stack/mac_nr/test/proc_sr_nr_test.cc diff --git a/srsue/hdr/stack/mac_nr/mac_nr.h b/srsue/hdr/stack/mac_nr/mac_nr.h index 5e4dd84c2..e782973cd 100644 --- a/srsue/hdr/stack/mac_nr/mac_nr.h +++ b/srsue/hdr/stack/mac_nr/mac_nr.h @@ -35,6 +35,7 @@ struct mac_nr_args_t {}; class mac_nr final : public mac_interface_phy_nr, public mac_interface_rrc_nr, public mac_interface_proc_ra_nr, + public mac_interface_sr_nr, public mac_interface_mux_nr { public: @@ -85,6 +86,9 @@ public: uint64_t get_contention_id(); uint16_t get_crnti(); + /// procedure sr nr interface + void start_ra() { proc_ra.start_by_mac(); } + /// Interface for MUX srsran::mac_sch_subpdu_nr::lcg_bsr_t generate_sbsr(); diff --git a/srsue/hdr/stack/mac_nr/mac_nr_interfaces.h b/srsue/hdr/stack/mac_nr/mac_nr_interfaces.h index a4c673157..e791bd002 100644 --- a/srsue/hdr/stack/mac_nr/mac_nr_interfaces.h +++ b/srsue/hdr/stack/mac_nr/mac_nr_interfaces.h @@ -39,7 +39,17 @@ public: }; /** - * @brief Interface from MAC NR parent class to mux ubclass + * @brief Interface from MAC NR parent class to SR subclass + */ +class mac_interface_sr_nr +{ +public: + // MUX can query MAC for current C-RNTI for Msg3 transmission + virtual void start_ra() = 0; +}; + +/** + * @brief Interface from MAC NR parent class to mux subclass */ class mac_interface_mux_nr { diff --git a/srsue/hdr/stack/mac_nr/proc_sr_nr.h b/srsue/hdr/stack/mac_nr/proc_sr_nr.h index e88bc1165..1d0224350 100644 --- a/srsue/hdr/stack/mac_nr/proc_sr_nr.h +++ b/srsue/hdr/stack/mac_nr/proc_sr_nr.h @@ -13,7 +13,9 @@ #ifndef SRSUE_PROC_SR_NR_H #define SRSUE_PROC_SR_NR_H +#include "srsue/hdr/stack/mac_nr/mac_nr_interfaces.h" #include "srsran/interfaces/ue_mac_interfaces.h" +#include "srsran/interfaces/ue_nr_interfaces.h" #include "srsran/srslog/srslog.h" #include @@ -23,14 +25,13 @@ namespace srsue { class proc_ra_nr; -class phy_interface_mac_nr; class rrc_interface_mac; class proc_sr_nr { public: explicit proc_sr_nr(srslog::basic_logger& logger); - int32_t init(proc_ra_nr* ra_, phy_interface_mac_nr* phy_, rrc_interface_mac* rrc_); + int32_t init(mac_interface_sr_nr* mac_, phy_interface_mac_nr* phy_, rrc_interface_mac* rrc_); void step(uint32_t tti); int32_t set_config(const srsran::sr_cfg_nr_t& cfg); void reset(); @@ -39,11 +40,11 @@ public: private: int sr_counter = 0; - bool is_pending_sr = 0; + bool is_pending_sr = false; srsran::sr_cfg_nr_t cfg = {}; - proc_ra_nr* ra = nullptr; + mac_interface_sr_nr* mac = nullptr; rrc_interface_mac* rrc = nullptr; phy_interface_mac_nr* phy = nullptr; srslog::basic_logger& logger; diff --git a/srsue/src/stack/mac_nr/mac_nr.cc b/srsue/src/stack/mac_nr/mac_nr.cc index 18cea6d1f..f452eff67 100644 --- a/srsue/src/stack/mac_nr/mac_nr.cc +++ b/srsue/src/stack/mac_nr/mac_nr.cc @@ -47,7 +47,7 @@ int mac_nr::init(const mac_nr_args_t& args_, // Init MAC sub procedures proc_ra.init(phy, &task_sched); - proc_sr.init(&proc_ra, phy, rrc); + proc_sr.init(this, phy, rrc); if (proc_bsr.init(&proc_sr, &mux, rlc, &task_sched) != SRSRAN_SUCCESS) { logger.error("Couldn't initialize BSR procedure."); diff --git a/srsue/src/stack/mac_nr/proc_bsr_nr.cc b/srsue/src/stack/mac_nr/proc_bsr_nr.cc index eb5dc3d8f..afb6aca56 100644 --- a/srsue/src/stack/mac_nr/proc_bsr_nr.cc +++ b/srsue/src/stack/mac_nr/proc_bsr_nr.cc @@ -114,7 +114,7 @@ void proc_bsr_nr::set_trigger(bsr_trigger_type_t new_trigger) // Trigger SR always when Regular BSR is triggered in the current TTI. Will be cancelled if a grant is received if (triggered_bsr_type == REGULAR) { logger.debug("BSR: Triggering SR procedure"); - // sr->start(); + sr->start(); } } diff --git a/srsue/src/stack/mac_nr/proc_sr_nr.cc b/srsue/src/stack/mac_nr/proc_sr_nr.cc index 7a1f8921f..23d0cef76 100644 --- a/srsue/src/stack/mac_nr/proc_sr_nr.cc +++ b/srsue/src/stack/mac_nr/proc_sr_nr.cc @@ -14,16 +14,15 @@ #include "srsran/common/standard_streams.h" #include "srsran/interfaces/ue_phy_interfaces.h" #include "srsran/interfaces/ue_rrc_interfaces.h" -#include "srsue/hdr/stack/mac_nr/proc_ra_nr.h" namespace srsue { proc_sr_nr::proc_sr_nr(srslog::basic_logger& logger) : logger(logger) {} -int32_t proc_sr_nr::init(proc_ra_nr* ra_, phy_interface_mac_nr* phy_, rrc_interface_mac* rrc_) +int32_t proc_sr_nr::init(mac_interface_sr_nr* mac_, phy_interface_mac_nr* phy_, rrc_interface_mac* rrc_) { rrc = rrc_; - ra = ra_; + mac = mac_; phy = phy_; initiated = true; sr_counter = 0; @@ -77,10 +76,10 @@ void proc_sr_nr::step(uint32_t tti) } // 1> if the MAC entity has no valid PUCCH resource configured for the pending SR: - if (!cfg.enabled || not phy->has_valid_sr_resource(0)) { + if (not phy->has_valid_sr_resource(cfg.item[0].sched_request_id)) { // 2> initiate a Random Access procedure (see clause 5.1) on the SpCell and cancel the pending SR. logger.info("SR: PUCCH not configured. Starting RA procedure"); - ra->start_by_mac(); + mac->start_ra(); reset(); return; } @@ -98,7 +97,7 @@ void proc_sr_nr::step(uint32_t tti) // 4> clear any PUSCH resources for semi-persistent CSI reporting; // ... TODO - ra->start_by_mac(); + mac->start_ra(); reset(); } } diff --git a/srsue/src/stack/mac_nr/test/CMakeLists.txt b/srsue/src/stack/mac_nr/test/CMakeLists.txt index 3d4dd8f87..d9039c278 100644 --- a/srsue/src/stack/mac_nr/test/CMakeLists.txt +++ b/srsue/src/stack/mac_nr/test/CMakeLists.txt @@ -14,6 +14,10 @@ add_executable(proc_bsr_nr_test proc_bsr_nr_test.cc) target_link_libraries(proc_bsr_nr_test srsue_mac_nr srsran_common) add_test(proc_bsr_nr_test proc_bsr_nr_test) +add_executable(proc_sr_nr_test proc_sr_nr_test.cc) +target_link_libraries(proc_sr_nr_test srsue_mac_nr srsran_common) +add_test(proc_sr_nr_test proc_sr_nr_test) + add_executable(mac_nr_test mac_nr_test.cc) target_link_libraries(mac_nr_test srsue_mac_nr srsran_common) add_test(mac_nr_test mac_nr_test) \ No newline at end of file diff --git a/srsue/src/stack/mac_nr/test/proc_sr_nr_test.cc b/srsue/src/stack/mac_nr/test/proc_sr_nr_test.cc new file mode 100644 index 000000000..666bce515 --- /dev/null +++ b/srsue/src/stack/mac_nr/test/proc_sr_nr_test.cc @@ -0,0 +1,104 @@ +/** + * + * \section COPYRIGHT + * + * Copyright 2013-2021 Software Radio Systems Limited + * + * By using this file, you agree to the terms and conditions set + * forth in the LICENSE file which can be found at the top level of + * the distribution. + * + */ +#include "srsran/common/buffer_pool.h" +#include "srsran/common/common.h" +#include "srsran/common/test_common.h" +#include "srsue/hdr/stack/mac_nr/proc_sr_nr.h" +#include "srsran/interfaces/ue_rrc_interfaces.h" + +using namespace srsue; + +class dummy_phy : public phy_interface_mac_nr +{ +public: + dummy_phy() {} + void send_prach(const uint32_t prach_occasion_, + const int preamble_index_, + const float preamble_received_target_power_, + const float ta_base_sec_ = 0.0f) override + { + prach_occasion = prach_occasion_; + preamble_index = preamble_index_; + preamble_received_target_power = preamble_received_target_power_; + } + int tx_request(const tx_request_t& request) override { return 0; } + int set_ul_grant(std::array, uint16_t rnti, srsran_rnti_type_t rnti_type) override + { + return 0; + } + + void get_last_send_prach(uint32_t* prach_occasion_, uint32_t* preamble_index_, int* preamble_received_target_power_) + { + *prach_occasion_ = prach_occasion; + *preamble_index_ = preamble_index; + *preamble_received_target_power_ = preamble_received_target_power; + } + bool has_valid_sr_resource(uint32_t sr_id) override { return false; } + void clear_pending_grants() override {} + +private: + uint32_t prach_occasion = 0; + uint32_t preamble_index = 0; + int preamble_received_target_power = 0; +}; + +class dummy_rrc : public rrc_interface_mac +{ + void ra_completed() {} + void ra_problem() {} + void release_pucch_srs() {} +}; + +class dummy_mac : public mac_interface_sr_nr +{ +public: + void start_ra() { ra_started = true; } + bool check_ra_started() { return ra_started; } + void reset_ra_started() { ra_started = false; } + +private: + bool ra_started = false; +}; + +int proc_sr_basic_test() +{ + proc_sr_nr proc_sr_nr(srslog::fetch_basic_logger("MAC")); + dummy_rrc dummy_rrc; + dummy_phy dummy_phy; + dummy_mac dummy_mac; + + srsran::sr_cfg_nr_t cfg; + cfg.enabled = true; + cfg.num_items = 1; + cfg.item[0].prohibit_timer = 0; + cfg.item[0].sched_request_id = 0; + cfg.item[0].trans_max = 64; + proc_sr_nr.init(&dummy_mac, &dummy_phy, &dummy_rrc); + proc_sr_nr.set_config(cfg); + proc_sr_nr.start(); + + proc_sr_nr.step(0); + TESTASSERT(dummy_mac.check_ra_started() == true); + + return SRSRAN_SUCCESS; +} + +int main() +{ + srslog::init(); + + auto& mac_logger = srslog::fetch_basic_logger("MAC"); + mac_logger.set_level(srslog::basic_levels::debug); + mac_logger.set_hex_dump_max_size(-1); + TESTASSERT(proc_sr_basic_test() == SRSRAN_SUCCESS); + return SRSRAN_SUCCESS; +} \ No newline at end of file