From 70fe48a5ab6c95412ca8259f518a89ed93a8c82b Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Thu, 23 Sep 2021 15:50:07 +0200 Subject: [PATCH] sched,nr: change NR sched configuration api --- srsenb/hdr/stack/mac/nr/mac_nr.h | 2 +- srsenb/hdr/stack/mac/nr/sched_nr.h | 6 +++--- srsenb/hdr/stack/mac/nr/sched_nr_cfg.h | 3 ++- srsenb/hdr/stack/mac/nr/sched_nr_interface.h | 14 ++++++------- srsenb/src/stack/mac/nr/mac_nr.cc | 22 +++++++++----------- srsenb/src/stack/mac/nr/sched_nr.cc | 15 ++++++------- srsenb/test/mac/nr/sched_nr_sim_ue.cc | 4 ++-- 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/srsenb/hdr/stack/mac/nr/mac_nr.h b/srsenb/hdr/stack/mac/nr/mac_nr.h index 5d8cdac40..fb7de2523 100644 --- a/srsenb/hdr/stack/mac/nr/mac_nr.h +++ b/srsenb/hdr/stack/mac/nr/mac_nr.h @@ -105,7 +105,7 @@ private: const static uint32_t NUMEROLOGY_IDX = 0; /// only 15kHz supported at this stage srsran::slot_point pdsch_slot, pusch_slot; - std::unique_ptr sched; + srsenb::sched_nr sched; std::vector cell_config; // Map of active UEs diff --git a/srsenb/hdr/stack/mac/nr/sched_nr.h b/srsenb/hdr/stack/mac/nr/sched_nr.h index 6249dd9c1..8608f7e00 100644 --- a/srsenb/hdr/stack/mac/nr/sched_nr.h +++ b/srsenb/hdr/stack/mac/nr/sched_nr.h @@ -36,9 +36,9 @@ class ul_sched_result_buffer; class sched_nr final : public sched_nr_interface { public: - explicit sched_nr(const sched_cfg_t& sched_cfg); + explicit sched_nr(); ~sched_nr() override; - int cell_cfg(srsran::const_span cell_list) override; + int config(const sched_cfg_t& sched_cfg, srsran::const_span cell_list) override; void ue_cfg(uint16_t rnti, const ue_cfg_t& cfg) override; void ue_rem(uint16_t rnti) override; bool ue_exists(uint16_t rnti) override; @@ -59,7 +59,7 @@ private: // args sched_nr_impl::sched_params cfg; - srslog::basic_logger& logger; + srslog::basic_logger* logger = nullptr; using sched_worker_manager = sched_nr_impl::sched_worker_manager; std::unique_ptr sched_workers; diff --git a/srsenb/hdr/stack/mac/nr/sched_nr_cfg.h b/srsenb/hdr/stack/mac/nr/sched_nr_cfg.h index be7e2657c..210e34921 100644 --- a/srsenb/hdr/stack/mac/nr/sched_nr_cfg.h +++ b/srsenb/hdr/stack/mac/nr/sched_nr_cfg.h @@ -93,9 +93,10 @@ struct sched_cell_params { }; struct sched_params { - const sched_cfg_t sched_cfg; + sched_cfg_t sched_cfg; std::vector cells; + sched_params() = default; explicit sched_params(const sched_cfg_t& sched_cfg_); }; diff --git a/srsenb/hdr/stack/mac/nr/sched_nr_interface.h b/srsenb/hdr/stack/mac/nr/sched_nr_interface.h index fa9e30e26..ddf73d661 100644 --- a/srsenb/hdr/stack/mac/nr/sched_nr_interface.h +++ b/srsenb/hdr/stack/mac/nr/sched_nr_interface.h @@ -115,13 +115,13 @@ public: dl_sched_t dl_sched; }; - virtual ~sched_nr_interface() = default; - virtual int cell_cfg(srsran::const_span ue_cfg) = 0; - virtual void ue_cfg(uint16_t rnti, const ue_cfg_t& ue_cfg) = 0; - virtual void ue_rem(uint16_t rnti) = 0; - virtual bool ue_exists(uint16_t rnti) = 0; - virtual int get_dl_sched(slot_point slot_rx, uint32_t cc, dl_sched_res_t& result) = 0; - virtual int get_ul_sched(slot_point slot_rx, uint32_t cc, ul_sched_t& result) = 0; + virtual ~sched_nr_interface() = default; + virtual int config(const sched_cfg_t& sched_cfg, srsran::const_span ue_cfg) = 0; + virtual void ue_cfg(uint16_t rnti, const ue_cfg_t& ue_cfg) = 0; + virtual void ue_rem(uint16_t rnti) = 0; + virtual bool ue_exists(uint16_t rnti) = 0; + virtual int get_dl_sched(slot_point slot_rx, uint32_t cc, dl_sched_res_t& result) = 0; + virtual int get_ul_sched(slot_point slot_rx, uint32_t cc, ul_sched_t& result) = 0; virtual void dl_ack_info(uint16_t rnti, uint32_t cc, uint32_t pid, uint32_t tb_idx, bool ack) = 0; virtual void ul_crc_info(uint16_t rnti, uint32_t cc, uint32_t pid, bool crc) = 0; diff --git a/srsenb/src/stack/mac/nr/mac_nr.cc b/srsenb/src/stack/mac/nr/mac_nr.cc index a7075bd6e..65da81474 100644 --- a/srsenb/src/stack/mac/nr/mac_nr.cc +++ b/srsenb/src/stack/mac/nr/mac_nr.cc @@ -48,7 +48,6 @@ int mac_nr::init(const mac_nr_args_t& args_, { args = args_; - sched.reset(new sched_nr{args.sched_cfg}); phy = phy_; stack = stack_; rlc = rlc_; @@ -82,7 +81,7 @@ void mac_nr::get_metrics(srsenb::mac_metrics_t& metrics) srsran::rwlock_read_guard lock(rwlock); metrics.ues.reserve(ue_db.size()); for (auto& u : ue_db) { - if (not sched->ue_exists(u.first)) { + if (not sched.ue_exists(u.first)) { continue; } metrics.ues.emplace_back(); @@ -98,7 +97,7 @@ void mac_nr::get_metrics(srsenb::mac_metrics_t& metrics) int mac_nr::cell_cfg(const std::vector& nr_cells) { cell_config = nr_cells; - sched->cell_cfg(nr_cells); + sched.config(args.sched_cfg, nr_cells); detected_rachs.resize(nr_cells.size()); // read SIBs from RRC (SIB1 for now only) @@ -127,7 +126,7 @@ int mac_nr::cell_cfg(const std::vector& int mac_nr::ue_cfg(uint16_t rnti, const sched_nr_interface::ue_cfg_t& ue_cfg) { - sched->ue_cfg(rnti, ue_cfg); + sched.ue_cfg(rnti, ue_cfg); return SRSRAN_SUCCESS; } @@ -148,7 +147,7 @@ uint16_t mac_nr::reserve_rnti(uint32_t enb_cc_idx) srsenb::sched_nr_interface::ue_cfg_t ue_cfg = srsenb::get_default_ue_cfg(1); ue_cfg.fixed_dl_mcs = args.fixed_dl_mcs; ue_cfg.fixed_ul_mcs = args.fixed_ul_mcs; - sched->ue_cfg(rnti, ue_cfg); + sched.ue_cfg(rnti, ue_cfg); return rnti; } @@ -174,7 +173,7 @@ void mac_nr::rach_detected(const rach_info_t& rach_info) rar_info.ta_cmd = rach_info.time_adv; 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); + sched.dl_rach_info(enb_cc_idx, rar_info); rrc->add_user(rnti); logger.info("RACH: slot=%d, cc=%d, preamble=%d, offset=%d, temp_crnti=0x%x", @@ -210,8 +209,7 @@ uint16_t mac_nr::alloc_ue(uint32_t enb_cc_idx) } // Allocate and initialize UE object - std::unique_ptr ue_ptr = - std::unique_ptr(new ue_nr(rnti, enb_cc_idx, sched.get(), rrc, rlc, phy, logger)); + std::unique_ptr ue_ptr = std::unique_ptr(new ue_nr(rnti, enb_cc_idx, &sched, rrc, rlc, phy, logger)); // Add UE to rnti map srsran::rwlock_write_guard rw_lock(rwlock); @@ -285,7 +283,7 @@ int mac_nr::get_dl_sched(const srsran_slot_cfg_t& slot_cfg, dl_sched_t& dl_sched } sched_nr_interface::dl_sched_res_t dl_res; - int ret = sched->get_dl_sched(pdsch_slot, 0, dl_res); + int ret = sched.get_dl_sched(pdsch_slot, 0, dl_res); if (ret != SRSRAN_SUCCESS) { return ret; } @@ -327,7 +325,7 @@ int mac_nr::get_ul_sched(const srsran_slot_cfg_t& slot_cfg, ul_sched_t& ul_sched pusch_slot++; } - return sched->get_ul_sched(pusch_slot, 0, ul_sched); + return sched.get_ul_sched(pusch_slot, 0, ul_sched); } int mac_nr::pucch_info(const srsran_slot_cfg_t& slot_cfg, const mac_interface_phy_nr::pucch_info_t& pucch_info) @@ -345,7 +343,7 @@ bool mac_nr::handle_uci_data(const uint16_t rnti, const srsran_uci_cfg_nr_t& cfg for (uint32_t i = 0; i < cfg_.ack.count; i++) { const srsran_harq_ack_bit_t* ack_bit = &cfg_.ack.bits[i]; bool is_ok = (value.ack[i] == 1) and value.valid; - sched->dl_ack_info(rnti, 0, ack_bit->pid, 0, is_ok); + sched.dl_ack_info(rnti, 0, ack_bit->pid, 0, is_ok); } // Process SR @@ -365,7 +363,7 @@ int mac_nr::pusch_info(const srsran_slot_cfg_t& slot_cfg, mac_interface_phy_nr:: return SRSRAN_ERROR; } - sched->ul_crc_info(rnti, 0, pusch_info.pid, pusch_info.pusch_data.tb[0].crc); + sched.ul_crc_info(rnti, 0, pusch_info.pid, pusch_info.pusch_data.tb[0].crc); // process only PDUs with CRC=OK if (pusch_info.pusch_data.tb[0].crc) { diff --git a/srsenb/src/stack/mac/nr/sched_nr.cc b/srsenb/src/stack/mac/nr/sched_nr.cc index 65df395e4..967ef774e 100644 --- a/srsenb/src/stack/mac/nr/sched_nr.cc +++ b/srsenb/src/stack/mac/nr/sched_nr.cc @@ -65,14 +65,15 @@ private: /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -sched_nr::sched_nr(const sched_cfg_t& sched_cfg) : - cfg(sched_cfg), logger(srslog::fetch_basic_logger(sched_cfg.logger_name)) -{} +sched_nr::sched_nr() : logger(&srslog::fetch_basic_logger("MAC-NR")) {} sched_nr::~sched_nr() {} -int sched_nr::cell_cfg(srsran::const_span cell_list) +int sched_nr::config(const sched_cfg_t& sched_cfg, srsran::const_span cell_list) { + cfg = sched_params{sched_cfg}; + logger = &srslog::fetch_basic_logger(sched_cfg.logger_name); + // Initiate Common Sched Configuration cfg.cells.reserve(cell_list.size()); for (uint32_t cc = 0; cc < cell_list.size(); ++cc) { @@ -112,9 +113,9 @@ void sched_nr::ue_cfg_impl(uint16_t rnti, const ue_cfg_t& uecfg) if (not ue_db.contains(rnti)) { auto ret = ue_db.insert(rnti, std::unique_ptr(new ue{rnti, uecfg, cfg})); if (ret.has_value()) { - logger.info("SCHED: New user rnti=0x%x, cc=%d", rnti, cfg.cells[0].cc); + logger->info("SCHED: New user rnti=0x%x, cc=%d", rnti, cfg.cells[0].cc); } else { - logger.error("SCHED: Failed to create new user rnti=0x%x", rnti); + logger->error("SCHED: Failed to create new user rnti=0x%x", rnti); } } else { ue_db[rnti]->set_cfg(uecfg); @@ -197,4 +198,4 @@ int assert_ue_cfg_valid(uint16_t rnti, const sched_nr_interface::ue_cfg_t& uecfg return SRSRAN_SUCCESS; } -} // namespace srsenb \ No newline at end of file +} // namespace srsenb diff --git a/srsenb/test/mac/nr/sched_nr_sim_ue.cc b/srsenb/test/mac/nr/sched_nr_sim_ue.cc index 89287467f..e57f61563 100644 --- a/srsenb/test/mac/nr/sched_nr_sim_ue.cc +++ b/srsenb/test/mac/nr/sched_nr_sim_ue.cc @@ -95,7 +95,7 @@ sched_nr_sim_base::sched_nr_sim_base(const sched_nr_interface::sched_cfg_t& std::string test_name_) : logger(srslog::fetch_basic_logger("TEST")), mac_logger(srslog::fetch_basic_logger("MAC")), - sched_ptr(new sched_nr(sched_args)), + sched_ptr(new sched_nr()), test_name(std::move(test_name_)) { logger.info("\n=========== Start %s ===========", test_name.c_str()); @@ -103,7 +103,7 @@ sched_nr_sim_base::sched_nr_sim_base(const sched_nr_interface::sched_cfg_t& for (uint32_t cc = 0; cc < cell_cfg_list.size(); ++cc) { cell_params.emplace_back(cc, cell_cfg_list[cc], sched_args); } - sched_ptr->cell_cfg(cell_cfg_list); // call parent cfg + sched_ptr->config(sched_args, cell_cfg_list); // call parent cfg TESTASSERT(cell_params.size() > 0); }