From 9df6c6b9367431fa7984613b0749c042e6de1be7 Mon Sep 17 00:00:00 2001 From: Francisco Date: Thu, 14 Oct 2021 16:45:18 +0100 Subject: [PATCH] sched,nr: ensure the ue_cfg_t passed to the scheduler in NR FDD mode has the correct harq delay --- .../srsran/interfaces/gnb_interfaces.h | 8 ++++-- .../srsran/interfaces/gnb_mac_interfaces.h | 2 +- srsenb/hdr/stack/mac/nr/mac_nr.h | 2 +- srsenb/hdr/stack/mac/nr/sched_nr_interface.h | 25 +++++++++-------- srsenb/hdr/stack/rrc/rrc_nr.h | 4 +-- srsenb/src/stack/mac/nr/mac_nr.cc | 28 +++++++++++-------- srsenb/src/stack/rrc/rrc_nr.cc | 24 ++++++++++++---- srsenb/test/common/dummy_classes_nr.h | 4 +-- test/phy/dummy_gnb_stack.h | 5 ++-- 9 files changed, 63 insertions(+), 39 deletions(-) diff --git a/lib/include/srsran/interfaces/gnb_interfaces.h b/lib/include/srsran/interfaces/gnb_interfaces.h index 48ab3d340..c3c5bc3f1 100644 --- a/lib/include/srsran/interfaces/gnb_interfaces.h +++ b/lib/include/srsran/interfaces/gnb_interfaces.h @@ -27,6 +27,8 @@ namespace srsenb { +struct sched_nr_ue_cfg_t; + /***************************** * RLC INTERFACES ****************************/ @@ -134,9 +136,9 @@ public: virtual int read_pdu_bcch_dlsch(uint32_t sib_index, srsran::unique_byte_buffer_t& buffer) = 0; /// User management - virtual int add_user(uint16_t rnti) = 0; - virtual int update_user(uint16_t new_rnti, uint16_t old_rnti) = 0; - virtual void set_activity_user(uint16_t rnti) = 0; + virtual int add_user(uint16_t rnti, const sched_nr_ue_cfg_t& uecfg) = 0; + virtual int update_user(uint16_t new_rnti, uint16_t old_rnti) = 0; + virtual void set_activity_user(uint16_t rnti) = 0; }; // NR interface is almost identical to EUTRA version diff --git a/lib/include/srsran/interfaces/gnb_mac_interfaces.h b/lib/include/srsran/interfaces/gnb_mac_interfaces.h index 482909617..bd1f29136 100644 --- a/lib/include/srsran/interfaces/gnb_mac_interfaces.h +++ b/lib/include/srsran/interfaces/gnb_mac_interfaces.h @@ -24,7 +24,7 @@ public: virtual int cell_cfg(const std::vector& nr_cells) = 0; /// Allocates a new user/RNTI at MAC. Returns RNTI on success or SRSRAN_INVALID_RNTI otherwise. - virtual uint16_t reserve_rnti(uint32_t enb_cc_idx) = 0; + virtual uint16_t reserve_rnti(uint32_t enb_cc_idx, const sched_nr_interface::ue_cfg_t& uecfg) = 0; virtual int ue_cfg(uint16_t rnti, const sched_nr_interface::ue_cfg_t& ue_cfg) = 0; diff --git a/srsenb/hdr/stack/mac/nr/mac_nr.h b/srsenb/hdr/stack/mac/nr/mac_nr.h index e11a0e32f..33f0d08de 100644 --- a/srsenb/hdr/stack/mac/nr/mac_nr.h +++ b/srsenb/hdr/stack/mac/nr/mac_nr.h @@ -53,7 +53,7 @@ public: // MAC interface for RRC int cell_cfg(const std::vector& nr_cells) override; - uint16_t reserve_rnti(uint32_t enb_cc_idx) override; + uint16_t reserve_rnti(uint32_t enb_cc_idx, const sched_nr_interface::ue_cfg_t& uecfg) override; int read_pdu_bcch_bch(uint8_t* payload); int ue_cfg(uint16_t rnti, const sched_nr_interface::ue_cfg_t& ue_cfg) override; int remove_ue(uint16_t rnti) override; diff --git a/srsenb/hdr/stack/mac/nr/sched_nr_interface.h b/srsenb/hdr/stack/mac/nr/sched_nr_interface.h index c3a6f0551..46f70270f 100644 --- a/srsenb/hdr/stack/mac/nr/sched_nr_interface.h +++ b/srsenb/hdr/stack/mac/nr/sched_nr_interface.h @@ -33,6 +33,18 @@ const static size_t SCHED_NR_MAX_BWP_PER_CELL = 2; const static size_t SCHED_NR_MAX_LCID = 32; const static size_t SCHED_NR_MAX_LC_GROUP = 7; +struct sched_nr_ue_cc_cfg_t { + bool active = false; + uint32_t cc = 0; +}; + +struct sched_nr_ue_cfg_t { + uint32_t maxharq_tx = 4; + srsran::bounded_vector carriers; + std::array ue_bearers = {}; + srsran::phy_cfg_nr_t phy_cfg = {}; +}; + class sched_nr_interface { public: @@ -76,17 +88,8 @@ public: std::string logger_name = "MAC-NR"; }; - struct ue_cc_cfg_t { - bool active = false; - uint32_t cc = 0; - }; - - struct ue_cfg_t { - uint32_t maxharq_tx = 4; - srsran::bounded_vector carriers; - std::array ue_bearers = {}; - srsran::phy_cfg_nr_t phy_cfg = {}; - }; + using ue_cc_cfg_t = sched_nr_ue_cc_cfg_t; + using ue_cfg_t = sched_nr_ue_cfg_t; ////// RA procedure ////// diff --git a/srsenb/hdr/stack/rrc/rrc_nr.h b/srsenb/hdr/stack/rrc/rrc_nr.h index 394a657f8..8f2ff2316 100644 --- a/srsenb/hdr/stack/rrc/rrc_nr.h +++ b/srsenb/hdr/stack/rrc/rrc_nr.h @@ -69,7 +69,7 @@ public: int read_pdu_bcch_dlsch(uint32_t sib_index, srsran::unique_byte_buffer_t& buffer) final; /// User manegement - int add_user(uint16_t rnti); + int add_user(uint16_t rnti, const sched_nr_ue_cfg_t& uecfg); void rem_user(uint16_t rnti); int update_user(uint16_t new_rnti, uint16_t old_rnti); void set_activity_user(uint16_t rnti); @@ -104,7 +104,7 @@ public: class ue { public: - ue(rrc_nr* parent_, uint16_t rnti_); + ue(rrc_nr* parent_, uint16_t rnti_, const sched_nr_ue_cfg_t& uecfg); void send_connection_setup(); void send_dl_ccch(asn1::rrc_nr::dl_ccch_msg_s* dl_dcch_msg); diff --git a/srsenb/src/stack/mac/nr/mac_nr.cc b/srsenb/src/stack/mac/nr/mac_nr.cc index 6d5411286..23c59c594 100644 --- a/srsenb/src/stack/mac/nr/mac_nr.cc +++ b/srsenb/src/stack/mac/nr/mac_nr.cc @@ -136,21 +136,13 @@ int mac_nr::ue_cfg(uint16_t rnti, const sched_nr_interface::ue_cfg_t& ue_cfg) return SRSRAN_SUCCESS; } -uint16_t mac_nr::reserve_rnti(uint32_t enb_cc_idx) +uint16_t mac_nr::reserve_rnti(uint32_t enb_cc_idx, const sched_nr_ue_cfg_t& uecfg) { uint16_t rnti = alloc_ue(enb_cc_idx); if (rnti == SRSRAN_INVALID_RNTI) { return rnti; } - // Add new user to the scheduler so that it can RX/TX SRB0 - srsenb::sched_nr_interface::ue_cfg_t uecfg = {}; - uecfg.carriers.resize(1); - uecfg.carriers[0].active = true; - uecfg.carriers[0].cc = 0; - uecfg.ue_bearers[0].direction = mac_lc_ch_cfg_t::BOTH; - uecfg.phy_cfg = srsran::phy_cfg_nr_default_t{srsran::phy_cfg_nr_default_t::reference_cfg_t{}}; - uecfg.phy_cfg.csi = {}; // disable CSI until RA is complete sched.ue_cfg(rnti, uecfg); return rnti; @@ -165,7 +157,21 @@ void mac_nr::rach_detected(const rach_info_t& rach_info) uint32_t enb_cc_idx = 0; stack_task_queue.push([this, rach_info, enb_cc_idx, rach_tprof_meas]() mutable { rach_tprof_meas.defer_stop(); - uint16_t rnti = reserve_rnti(enb_cc_idx); + + // Add new user to the scheduler so that it can RX/TX SRB0 + sched_nr_ue_cfg_t uecfg = {}; + uecfg.carriers.resize(1); + uecfg.carriers[0].active = true; + uecfg.carriers[0].cc = 0; + uecfg.ue_bearers[0].direction = mac_lc_ch_cfg_t::BOTH; + srsran::phy_cfg_nr_default_t::reference_cfg_t ref_args{}; + ref_args.duplex = cell_config[0].duplex.mode == SRSRAN_DUPLEX_MODE_TDD + ? srsran::phy_cfg_nr_default_t::reference_cfg_t::R_DUPLEX_TDD_CUSTOM_6_4 + : srsran::phy_cfg_nr_default_t::reference_cfg_t::R_DUPLEX_FDD; + uecfg.phy_cfg = srsran::phy_cfg_nr_default_t{ref_args}; + uecfg.phy_cfg.csi = {}; // disable CSI until RA is complete + + uint16_t rnti = reserve_rnti(enb_cc_idx, uecfg); // Log this event. ++detected_rachs[enb_cc_idx]; @@ -178,7 +184,7 @@ void mac_nr::rach_detected(const rach_info_t& rach_info) rar_info.prach_slot = slot_point{NUMEROLOGY_IDX, rach_info.slot_index}; // TODO: fill remaining fields as required sched.dl_rach_info(enb_cc_idx, rar_info); - rrc->add_user(rnti); + rrc->add_user(rnti, uecfg); logger.info("RACH: slot=%d, cc=%d, preamble=%d, offset=%d, temp_crnti=0x%x", rach_info.slot_index, diff --git a/srsenb/src/stack/rrc/rrc_nr.cc b/srsenb/src/stack/rrc/rrc_nr.cc index e496b01b2..10e1a6904 100644 --- a/srsenb/src/stack/rrc/rrc_nr.cc +++ b/srsenb/src/stack/rrc/rrc_nr.cc @@ -145,10 +145,10 @@ rrc_nr_cfg_t rrc_nr::update_default_cfg(const rrc_nr_cfg_t& current) } // This function is called from PRACH worker (can wait) -int rrc_nr::add_user(uint16_t rnti) +int rrc_nr::add_user(uint16_t rnti, const sched_nr_ue_cfg_t& uecfg) { if (users.count(rnti) == 0) { - users.insert(std::make_pair(rnti, std::unique_ptr(new ue(this, rnti)))); + users.insert(std::make_pair(rnti, std::unique_ptr(new ue(this, rnti, uecfg)))); rlc->add_user(rnti); pdcp->add_user(rnti); logger.info("Added new user rnti=0x%x", rnti); @@ -478,14 +478,26 @@ int rrc_nr::sgnb_addition_request(uint16_t eutra_rnti, const sgnb_addition_req_p { task_sched.defer_task([this, eutra_rnti, params]() { // try to allocate new user - uint16_t nr_rnti = mac->reserve_rnti(0); + sched_nr_ue_cfg_t uecfg{}; + uecfg.carriers.resize(1); + uecfg.carriers[0].active = true; + uecfg.carriers[0].cc = 0; + uecfg.ue_bearers[0].direction = mac_lc_ch_cfg_t::BOTH; + srsran::phy_cfg_nr_default_t::reference_cfg_t ref_args{}; + ref_args.duplex = cfg.cell_list[0].duplex_mode == SRSRAN_DUPLEX_MODE_TDD + ? srsran::phy_cfg_nr_default_t::reference_cfg_t::R_DUPLEX_TDD_CUSTOM_6_4 + : srsran::phy_cfg_nr_default_t::reference_cfg_t::R_DUPLEX_FDD; + uecfg.phy_cfg = srsran::phy_cfg_nr_default_t{ref_args}; + uecfg.phy_cfg.csi = {}; // disable CSI until RA is complete + + uint16_t nr_rnti = mac->reserve_rnti(0, uecfg); if (nr_rnti == SRSRAN_INVALID_RNTI) { logger.error("Failed to allocate RNTI at MAC"); rrc_eutra->sgnb_addition_reject(eutra_rnti); return; } - if (add_user(nr_rnti) != SRSRAN_SUCCESS) { + if (add_user(nr_rnti, uecfg) != SRSRAN_SUCCESS) { logger.error("Failed to allocate RNTI at RRC"); rrc_eutra->sgnb_addition_reject(eutra_rnti); return; @@ -527,7 +539,9 @@ int rrc_nr::sgnb_release_request(uint16_t nr_rnti) Every function in UE class is called from a mutex environment thus does not need extra protection. *******************************************************************************/ -rrc_nr::ue::ue(rrc_nr* parent_, uint16_t rnti_) : parent(parent_), rnti(rnti_), uecfg(srsenb::get_rach_ue_cfg(0)) {} +rrc_nr::ue::ue(rrc_nr* parent_, uint16_t rnti_, const sched_nr_ue_cfg_t& uecfg_) : + parent(parent_), rnti(rnti_), uecfg(uecfg_) +{} void rrc_nr::ue::send_connection_setup() { diff --git a/srsenb/test/common/dummy_classes_nr.h b/srsenb/test/common/dummy_classes_nr.h index 2148aa810..018599afa 100644 --- a/srsenb/test/common/dummy_classes_nr.h +++ b/srsenb/test/common/dummy_classes_nr.h @@ -23,7 +23,7 @@ class rrc_nr_dummy : public rrc_interface_mac_nr public: int read_pdu_bcch_bch(const uint32_t tti, srsran::unique_byte_buffer_t& buffer) { return SRSRAN_SUCCESS; } int read_pdu_bcch_dlsch(uint32_t sib_index, srsran::unique_byte_buffer_t& buffer) { return SRSRAN_SUCCESS; } - int add_user(uint16_t rnti) { return SRSRAN_SUCCESS; } + int add_user(uint16_t rnti, const sched_nr_ue_cfg_t& uecfg) { return SRSRAN_SUCCESS; } int update_user(uint16_t new_rnti, uint16_t old_rnti) { return SRSRAN_SUCCESS; } void set_activity_user(uint16_t rnti) {} }; @@ -40,7 +40,7 @@ class mac_nr_dummy : public mac_interface_rrc_nr { public: int cell_cfg(const std::vector& nr_cells) override { return SRSRAN_SUCCESS; } - uint16_t reserve_rnti(uint32_t enb_cc_idx) override { return 0x4601; } + uint16_t reserve_rnti(uint32_t enb_cc_idx, const sched_nr_ue_cfg_t& uecfg) override { return 0x4601; } int ue_cfg(uint16_t rnti, const sched_nr_interface::ue_cfg_t& ue_cfg) override { return SRSRAN_SUCCESS; } diff --git a/test/phy/dummy_gnb_stack.h b/test/phy/dummy_gnb_stack.h index 4f70c6269..c0f470b44 100644 --- a/test/phy/dummy_gnb_stack.h +++ b/test/phy/dummy_gnb_stack.h @@ -374,11 +374,10 @@ public: // add UE to scheduler if (not use_dummy_mac and not args.wait_preamble) { - mac->reserve_rnti(0); - srsenb::sched_nr_interface::ue_cfg_t ue_cfg = srsenb::get_default_ue_cfg(1, phy_cfg); ue_cfg.ue_bearers[4].direction = srsenb::mac_lc_ch_cfg_t::BOTH; - mac->ue_cfg(args.rnti, ue_cfg); + + mac->reserve_rnti(0, ue_cfg); } dl.mcs = args.pdsch.mcs;