From 2b114cb7b9dd8ec00d9d2701d54fbd331bbfc5a4 Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Tue, 24 Aug 2021 11:17:55 +0200 Subject: [PATCH] sched,nr: create simple NR scheduler RAR test --- srsenb/src/stack/mac/nr/sched_nr_cell.cc | 1 + srsenb/test/mac/nr/CMakeLists.txt | 3 + srsenb/test/mac/nr/sched_nr_cfg_generators.h | 3 +- srsenb/test/mac/nr/sched_nr_rar_test.cc | 101 +++++++++++++++++++ 4 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 srsenb/test/mac/nr/sched_nr_rar_test.cc diff --git a/srsenb/src/stack/mac/nr/sched_nr_cell.cc b/srsenb/src/stack/mac/nr/sched_nr_cell.cc index fa49c69ac..9eddfc0ed 100644 --- a/srsenb/src/stack/mac/nr/sched_nr_cell.cc +++ b/srsenb/src/stack/mac/nr/sched_nr_cell.cc @@ -209,6 +209,7 @@ int ra_sched::dl_rach_info(const dl_sched_rar_info_t& rar_info) for (slot_point t = rar_info.prach_slot + prach_duration; t < rar_info.prach_slot + bwp_cfg->slots.size(); ++t) { if (bwp_cfg->slots[t.slot_idx()].is_dl) { p.rar_win = {t, t + bwp_cfg->cfg.rar_window_size}; + break; } } p.msg3_grant.push_back(rar_info); diff --git a/srsenb/test/mac/nr/CMakeLists.txt b/srsenb/test/mac/nr/CMakeLists.txt index 528a9e3e2..9af588f18 100644 --- a/srsenb/test/mac/nr/CMakeLists.txt +++ b/srsenb/test/mac/nr/CMakeLists.txt @@ -21,3 +21,6 @@ target_link_libraries(sched_nr_prb_test ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) add_test(sched_nr_prb_test sched_nr_prb_test) + +add_executable(sched_nr_rar_test sched_nr_rar_test.cc) +target_link_libraries(sched_nr_rar_test srsgnb_mac srsran_common) \ No newline at end of file diff --git a/srsenb/test/mac/nr/sched_nr_cfg_generators.h b/srsenb/test/mac/nr/sched_nr_cfg_generators.h index 65698c402..498f2a578 100644 --- a/srsenb/test/mac/nr/sched_nr_cfg_generators.h +++ b/srsenb/test/mac/nr/sched_nr_cfg_generators.h @@ -30,7 +30,8 @@ srsran_coreset_t get_default_coreset0(uint32_t nof_prb) return coreset; } -sched_nr_interface::cell_cfg_t get_default_cell_cfg(const srsran::phy_cfg_nr_t& phy_cfg) +sched_nr_interface::cell_cfg_t get_default_cell_cfg(const srsran::phy_cfg_nr_t& phy_cfg = srsran::phy_cfg_nr_default_t{ + srsran::phy_cfg_nr_default_t::reference_cfg_t{}}) { sched_nr_interface::cell_cfg_t cell_cfg{}; diff --git a/srsenb/test/mac/nr/sched_nr_rar_test.cc b/srsenb/test/mac/nr/sched_nr_rar_test.cc new file mode 100644 index 000000000..cf9b5b431 --- /dev/null +++ b/srsenb/test/mac/nr/sched_nr_rar_test.cc @@ -0,0 +1,101 @@ +/** + * + * \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 "sched_nr_cfg_generators.h" +#include "srsenb/hdr/stack/mac/nr/sched_nr_cell.h" +#include "srsran/common/test_common.h" +#include "srsran/support/srsran_test.h" +#include + +namespace srsenb { + +void test_single_prach() +{ + using namespace sched_nr_impl; + const uint16_t rnti = 0x1234; + static srslog::basic_logger& mac_logger = srslog::fetch_basic_logger("MAC"); + std::random_device r; + std::default_random_engine rgen(r()); + + sched_nr_interface::sched_cfg_t sched_cfg{}; + std::vector cells_cfg = get_default_cells_cfg(1); + sched_params schedparams{sched_cfg}; + schedparams.cells.emplace_back(0, cells_cfg[0], sched_cfg); + bwp_params bwp_cfg(cells_cfg[0], sched_cfg, 0, 0); + slot_ue_map_t slot_ues; + + ra_sched rasched(bwp_cfg); + TESTASSERT(rasched.empty()); + + std::unique_ptr res_grid(new bwp_res_grid{bwp_cfg}); + bwp_slot_allocator alloc(*res_grid); + + // Create UE + sched_nr_interface::ue_cfg_t uecfg = get_default_ue_cfg(1); + ue u(rnti, uecfg, schedparams); + + slot_point pdcch_slot{0, TX_ENB_DELAY}; + slot_point prach_slot{0, std::uniform_int_distribution{TX_ENB_DELAY, 20}(rgen)}; + + const bwp_slot_grid* result = nullptr; + auto run_slot = [&alloc, &rasched, &pdcch_slot, &slot_ues, &u]() -> const bwp_slot_grid* { + mac_logger.set_context(pdcch_slot.to_uint()); + slot_ues.clear(); + slot_ues.insert(rnti, u.try_reserve(pdcch_slot, 0)); + alloc.new_slot(pdcch_slot); + rasched.run_slot(alloc, slot_ues); + ++pdcch_slot; + return &alloc.res_grid()[alloc.get_pdcch_tti()]; + }; + + // Start Run + + for (; pdcch_slot - TX_ENB_DELAY < prach_slot;) { + result = run_slot(); + TESTASSERT(result->dl_pdcchs.empty()); + } + + sched_nr_interface::dl_sched_rar_info_t rainfo{}; + rainfo.preamble_idx = 10; + rainfo.temp_crnti = rnti; + rainfo.prach_slot = prach_slot; + rainfo.msg3_size = 7; + TESTASSERT_SUCCESS(rasched.dl_rach_info(rainfo)); + uint16_t ra_rnti = 1 + rainfo.ofdm_symbol_idx + 14 * rainfo.prach_slot.slot_idx() + 14 * 80 * rainfo.freq_idx; + + while (true) { + result = run_slot(); + if (result->is_dl()) { + TESTASSERT(result->dl_pdcchs.size() == 1); + const auto& pdcch = result->dl_pdcchs[0]; + TESTASSERT_EQ(pdcch.dci.ctx.rnti, ra_rnti); + TESTASSERT_EQ(pdcch.dci.ctx.rnti_type, srsran_rnti_type_ra); + break; + } else { + TESTASSERT(result->dl_pdcchs.empty()); + } + } +} + +} // namespace srsenb + +int main(int argc, char** argv) +{ + auto& test_logger = srslog::fetch_basic_logger("TEST"); + test_logger.set_level(srslog::basic_levels::info); + auto& mac_logger = srslog::fetch_basic_logger("MAC"); + mac_logger.set_level(srslog::basic_levels::info); + + srsran::test_init(argc, argv); + + srsenb::test_single_prach(); +}