diff --git a/srsenb/hdr/stack/mac/nr/sched_nr_grant_allocator.h b/srsenb/hdr/stack/mac/nr/sched_nr_grant_allocator.h index 7129e8f57..d69fde6ff 100644 --- a/srsenb/hdr/stack/mac/nr/sched_nr_grant_allocator.h +++ b/srsenb/hdr/stack/mac/nr/sched_nr_grant_allocator.h @@ -92,6 +92,7 @@ public: alloc_result alloc_pusch(slot_ue& ue, const prb_grant& dl_mask); slot_point get_pdcch_tti() const { return pdcch_slot; } + slot_point get_tti_rx() const { return pdcch_slot - TX_ENB_DELAY; } const bwp_res_grid& res_grid() const { return bwp_grid; } const bwp_params& cfg; diff --git a/srsenb/hdr/stack/mac/nr/sched_nr_helpers.h b/srsenb/hdr/stack/mac/nr/sched_nr_helpers.h index 065a06880..baecb2f89 100644 --- a/srsenb/hdr/stack/mac/nr/sched_nr_helpers.h +++ b/srsenb/hdr/stack/mac/nr/sched_nr_helpers.h @@ -19,6 +19,7 @@ namespace srsenb { namespace sched_nr_impl { class slot_ue; +class ul_harq_proc; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/srsenb/hdr/stack/mac/nr/sched_nr_ue.h b/srsenb/hdr/stack/mac/nr/sched_nr_ue.h index 9d3816930..678708486 100644 --- a/srsenb/hdr/stack/mac/nr/sched_nr_ue.h +++ b/srsenb/hdr/stack/mac/nr/sched_nr_ue.h @@ -44,7 +44,8 @@ public: bool pending_sr = false; // UE parameters that are sector specific - const bwp_ue_cfg* cfg = nullptr; + const bwp_ue_cfg* cfg = nullptr; + harq_entity* harq_ent = nullptr; slot_point pdcch_slot; slot_point pdsch_slot; slot_point pusch_slot; diff --git a/srsenb/src/stack/mac/nr/sched_nr_cell.cc b/srsenb/src/stack/mac/nr/sched_nr_cell.cc index 75c192351..0a2e55e4e 100644 --- a/srsenb/src/stack/mac/nr/sched_nr_cell.cc +++ b/srsenb/src/stack/mac/nr/sched_nr_cell.cc @@ -54,9 +54,8 @@ alloc_result ra_sched::allocate_pending_rar(bwp_slot_allocator& slot_grid, void ra_sched::run_slot(bwp_slot_allocator& slot_grid, slot_ue_map_t& slot_ues) { - static const uint32_t PRACH_RAR_OFFSET = 3; - slot_point pdcch_slot = slot_grid.get_pdcch_tti(); - slot_point msg3_slot = pdcch_slot + bwp_cfg->pusch_ra_list[0].msg3_delay; + slot_point pdcch_slot = slot_grid.get_pdcch_tti(); + slot_point msg3_slot = pdcch_slot + bwp_cfg->pusch_ra_list[0].msg3_delay; if (not slot_grid.res_grid()[pdcch_slot].is_dl or not slot_grid.res_grid()[msg3_slot].is_ul) { // RAR only allowed if respective Msg3 slot is available for UL return; @@ -68,8 +67,8 @@ void ra_sched::run_slot(bwp_slot_allocator& slot_grid, slot_ue_map_t& slot_ues) // In case of RAR outside RAR window: // - if window has passed, discard RAR // - if window hasn't started, stop loop, as RARs are ordered by TTI - slot_interval rar_window{rar.prach_slot + PRACH_RAR_OFFSET, - rar.prach_slot + PRACH_RAR_OFFSET + bwp_cfg->cfg.rar_window_size}; + slot_point tti_start{0, rar.prach_slot.sfn(), 0}; + slot_interval rar_window{tti_start, tti_start + 2 * tti_start.nof_slots_per_frame()}; // TODO: use rar_window_size if (not rar_window.contains(pdcch_slot)) { if (pdcch_slot >= rar_window.stop()) { fmt::memory_buffer str_buffer; diff --git a/srsenb/src/stack/mac/nr/sched_nr_grant_allocator.cc b/srsenb/src/stack/mac/nr/sched_nr_grant_allocator.cc index 2f3743516..a664c57b2 100644 --- a/srsenb/src/stack/mac/nr/sched_nr_grant_allocator.cc +++ b/srsenb/src/stack/mac/nr/sched_nr_grant_allocator.cc @@ -133,7 +133,8 @@ alloc_result bwp_slot_allocator::alloc_rar_and_msg3(uint32_t for (const auto& grant : rar.msg3_grant) { slot_ue& ue = ues[grant.temp_crnti]; prb_interval msg3_interv{last_msg3, last_msg3 + msg3_nof_prbs}; - bool success = ue.h_ul->new_tx(msg3_slot, msg3_slot, msg3_interv, mcs, 100, max_harq_msg3_retx); + ue.h_ul = ue.harq_ent->find_empty_ul_harq(); + bool success = ue.h_ul->new_tx(msg3_slot, msg3_slot, msg3_interv, mcs, 100, max_harq_msg3_retx); srsran_assert(success, "Failed to allocate Msg3"); last_msg3 += msg3_nof_prbs; pdcch_ul_t msg3_pdcch; @@ -144,9 +145,7 @@ alloc_result bwp_slot_allocator::alloc_rar_and_msg3(uint32_t success = ue.cfg->phy().get_pusch_cfg(slot_cfg, msg3_pdcch.dci, pusch.sch); srsran_assert(success, "Error converting DCI to PUSCH grant"); pusch.sch.grant.tb[0].softbuffer.rx = ue.h_ul->get_softbuffer().get(); - if (ue.h_ul->nof_retx() > 0) { - bwp_pdcch_slot.ul_pdcchs.push_back(msg3_pdcch); - } + ue.h_ul->set_tbs(pusch.sch.grant.tb[0].tbs); } bwp_msg3_slot.ul_prbs.add(msg3_rbs); diff --git a/srsenb/src/stack/mac/nr/sched_nr_time_rr.cc b/srsenb/src/stack/mac/nr/sched_nr_time_rr.cc index c65a23d7a..4e8941ac5 100644 --- a/srsenb/src/stack/mac/nr/sched_nr_time_rr.cc +++ b/srsenb/src/stack/mac/nr/sched_nr_time_rr.cc @@ -38,7 +38,7 @@ void sched_nr_time_rr::sched_dl_users(slot_ue_map_t& ue_db, bwp_slot_allocator& { // Start with retxs if (round_robin_apply(ue_db, slot_alloc.get_pdcch_tti().to_uint(), [&slot_alloc](slot_ue& ue) { - if (ue.h_dl != nullptr and not ue.h_dl->empty()) { + if (ue.h_dl != nullptr and ue.h_dl->has_pending_retx(slot_alloc.get_tti_rx())) { alloc_result res = slot_alloc.alloc_pdsch(ue, ue.h_dl->prbs()); if (res == alloc_result::success) { return true; @@ -65,7 +65,7 @@ void sched_nr_time_rr::sched_ul_users(slot_ue_map_t& ue_db, bwp_slot_allocator& { // Start with retxs if (round_robin_apply(ue_db, slot_alloc.get_pdcch_tti().to_uint(), [&slot_alloc](slot_ue& ue) { - if (ue.h_ul != nullptr and not ue.h_ul->empty()) { + if (ue.h_ul != nullptr and ue.h_ul->has_pending_retx(slot_alloc.get_tti_rx())) { alloc_result res = slot_alloc.alloc_pusch(ue, ue.h_ul->prbs()); if (res == alloc_result::success) { return true; diff --git a/srsenb/src/stack/mac/nr/sched_nr_ue.cc b/srsenb/src/stack/mac/nr/sched_nr_ue.cc index a2d5a5279..f0ad196d9 100644 --- a/srsenb/src/stack/mac/nr/sched_nr_ue.cc +++ b/srsenb/src/stack/mac/nr/sched_nr_ue.cc @@ -43,6 +43,7 @@ slot_ue ue_carrier::try_reserve(slot_point pdcch_slot) // copy cc-specific parameters and find available HARQs slot_ue sfu(rnti, slot_rx, cc); sfu.cfg = &bwp_cfg; + sfu.harq_ent = &harq_ent; sfu.pdcch_slot = pdcch_slot; const uint32_t k0 = 0; sfu.pdsch_slot = sfu.pdcch_slot + k0; diff --git a/srsenb/test/mac/nr/sched_nr_sim_ue.cc b/srsenb/test/mac/nr/sched_nr_sim_ue.cc index 67ab553b6..cb619aee8 100644 --- a/srsenb/test/mac/nr/sched_nr_sim_ue.cc +++ b/srsenb/test/mac/nr/sched_nr_sim_ue.cc @@ -112,12 +112,23 @@ sched_nr_sim_base::~sched_nr_sim_base() logger.info("=========== End %s ==========\n", test_name.c_str()); } -int sched_nr_sim_base::add_user(uint16_t rnti, const sched_nr_interface::ue_cfg_t& ue_cfg_, uint32_t preamble_idx) +int sched_nr_sim_base::add_user(uint16_t rnti, + const sched_nr_interface::ue_cfg_t& ue_cfg_, + slot_point tti_rx, + uint32_t preamble_idx) { TESTASSERT(ue_db.count(rnti) == 0); sched_ptr->ue_cfg(rnti, ue_cfg_); ue_db.insert(std::make_pair(rnti, sched_nr_ue_sim(rnti, ue_cfg_, current_slot_tx, preamble_idx))); + + sched_nr_interface::dl_sched_rar_info_t rach_info{}; + rach_info.temp_crnti = rnti; + rach_info.prach_slot = tti_rx; + rach_info.preamble_idx = preamble_idx; + rach_info.msg3_size = 7; + sched_ptr->dl_rach_info(ue_cfg_.carriers[0].cc, rach_info); + return SRSRAN_SUCCESS; } diff --git a/srsenb/test/mac/nr/sched_nr_sim_ue.h b/srsenb/test/mac/nr/sched_nr_sim_ue.h index 4bb54c437..7a75a7912 100644 --- a/srsenb/test/mac/nr/sched_nr_sim_ue.h +++ b/srsenb/test/mac/nr/sched_nr_sim_ue.h @@ -106,7 +106,7 @@ public: std::string test_name); virtual ~sched_nr_sim_base(); - int add_user(uint16_t rnti, const sched_nr_interface::ue_cfg_t& ue_cfg_, uint32_t preamble_idx); + int add_user(uint16_t rnti, const sched_nr_interface::ue_cfg_t& ue_cfg_, slot_point tti_rx, uint32_t preamble_idx); void new_slot(slot_point slot_tx); void update(sched_nr_cc_output_res_t& cc_out); diff --git a/srsenb/test/mac/nr/sched_nr_test.cc b/srsenb/test/mac/nr/sched_nr_test.cc index 0ae8588d4..fbf8faa80 100644 --- a/srsenb/test/mac/nr/sched_nr_test.cc +++ b/srsenb/test/mac/nr/sched_nr_test.cc @@ -88,7 +88,7 @@ void sched_nr_cfg_serialized_test() sched_nr_interface::ue_cfg_t uecfg = get_default_ue_cfg(nof_sectors); uecfg.fixed_dl_mcs = 15; uecfg.fixed_ul_mcs = 15; - sched_tester.add_user(0x46, uecfg, 0); + sched_tester.add_user(0x46, uecfg, slot_point{0, 0}, 0); std::vector count_per_cc(nof_sectors, 0); for (uint32_t nof_slots = 0; nof_slots < max_nof_ttis; ++nof_slots) { @@ -136,7 +136,7 @@ void sched_nr_cfg_parallel_cc_test() sched_nr_interface::ue_cfg_t uecfg = get_default_ue_cfg(cells_cfg.size()); uecfg.fixed_dl_mcs = 15; uecfg.fixed_ul_mcs = 15; - sched_tester.add_user(0x46, uecfg, 0); + sched_tester.add_user(0x46, uecfg, slot_point{0, 0}, 0); std::array, SRSRAN_MAX_CARRIERS> nano_count{}; for (uint32_t nof_slots = 0; nof_slots < max_nof_ttis; ++nof_slots) {