From 88a22e7dbfab3e4d347763378372de7f9a82df4a Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Fri, 31 Jan 2020 16:44:35 +0000 Subject: [PATCH] support cc cfg from rrc --- .../srslte/interfaces/sched_interface.h | 7 ++- srsenb/hdr/stack/mac/scheduler.h | 2 +- srsenb/hdr/stack/mac/scheduler_ue.h | 9 ++- srsenb/src/stack/mac/mac.cc | 17 +++--- srsenb/src/stack/mac/scheduler.cc | 9 ++- srsenb/src/stack/mac/scheduler_ue.cc | 55 +++++++++++++------ srsenb/src/stack/rrc/rrc.cc | 48 ++++++++-------- srsenb/test/mac/scheduler_test.cc | 8 +-- srsenb/test/mac/scheduler_test_rand.cc | 10 ++-- 9 files changed, 97 insertions(+), 68 deletions(-) diff --git a/lib/include/srslte/interfaces/sched_interface.h b/lib/include/srslte/interfaces/sched_interface.h index 907fa14d8..b699bce63 100644 --- a/lib/include/srslte/interfaces/sched_interface.h +++ b/lib/include/srslte/interfaces/sched_interface.h @@ -118,6 +118,7 @@ public: uint32_t aperiodic_cqi_period; // if 0 is periodic CQI srslte_dl_cfg_t dl_cfg; ue_bearer_cfg_t ue_bearers[MAX_LC]; + std::vector supported_cc_idxs; }; typedef struct { @@ -216,9 +217,9 @@ public: virtual int reset() = 0; /* Manages UE scheduling context */ - virtual int ue_cfg(uint16_t rnti, uint32_t enb_cc_idx, ue_cfg_t* cfg) = 0; - virtual int ue_rem(uint16_t rnti) = 0; - virtual bool ue_exists(uint16_t rnti) = 0; + virtual int ue_cfg(uint16_t rnti, ue_cfg_t* cfg) = 0; + virtual int ue_rem(uint16_t rnti) = 0; + virtual bool ue_exists(uint16_t rnti) = 0; /* Manages UE bearers and associated configuration */ virtual int bearer_ue_cfg(uint16_t rnti, uint32_t lc_id, ue_bearer_cfg_t* cfg) = 0; diff --git a/srsenb/hdr/stack/mac/scheduler.h b/srsenb/hdr/stack/mac/scheduler.h index a8800499e..640b2957d 100644 --- a/srsenb/hdr/stack/mac/scheduler.h +++ b/srsenb/hdr/stack/mac/scheduler.h @@ -128,7 +128,7 @@ public: void set_sched_cfg(sched_args_t* sched_cfg); int reset() final; - int ue_cfg(uint16_t rnti, uint32_t enb_cc_idx, ue_cfg_t* ue_cfg) final; + int ue_cfg(uint16_t rnti, ue_cfg_t* ue_cfg) final; int ue_rem(uint16_t rnti) final; bool ue_exists(uint16_t rnti) final; void ue_needs_ta_cmd(uint16_t rnti, uint32_t nof_ta_cmd); diff --git a/srsenb/hdr/stack/mac/scheduler_ue.h b/srsenb/hdr/stack/mac/scheduler_ue.h index a0b1a8bce..bb856d5d2 100644 --- a/srsenb/hdr/stack/mac/scheduler_ue.h +++ b/srsenb/hdr/stack/mac/scheduler_ue.h @@ -44,7 +44,7 @@ struct sched_dci_cce_t { struct sched_ue_carrier { const static int SCHED_MAX_HARQ_PROC = SRSLTE_FDD_NOF_HARQ; - sched_ue_carrier(sched_interface::ue_cfg_t* cfg_, const sched_cell_params_t* cell_cfg_, uint16_t rnti_); + sched_ue_carrier(sched_interface::ue_cfg_t* cfg_, const sched_cell_params_t& cell_cfg_, uint16_t rnti_); void reset(); // Harq access @@ -104,10 +104,8 @@ public: sched_ue(); void reset(); void phy_config_enabled(uint32_t tti, bool enabled); - void set_cfg(uint16_t rnti, - const std::vector& cell_list_params_, - sched_interface::ue_cfg_t* cfg, - uint32_t primary_cc_idx_); + void init(uint16_t rnti, const std::vector& cell_list_params_); + void set_cfg(sched_interface::ue_cfg_t* cfg); void set_bearer_cfg(uint32_t lc_id, srsenb::sched_interface::ue_bearer_cfg_t* cfg); void rem_bearer(uint32_t lc_id); @@ -270,6 +268,7 @@ private: uint32_t max_msg3retx = 0; /* User State */ + bool configured = false; bool conres_ce_pending = true; uint32_t nof_ta_cmd = 0; diff --git a/srsenb/src/stack/mac/mac.cc b/srsenb/src/stack/mac/mac.cc index fa705449b..901d7e7ff 100644 --- a/srsenb/src/stack/mac/mac.cc +++ b/srsenb/src/stack/mac/mac.cc @@ -200,7 +200,7 @@ int mac::ue_cfg(uint16_t rnti, sched_interface::ue_cfg_t* cfg) { int ret = -1; pthread_rwlock_rdlock(&rwlock); - if (ue_db.count(rnti)) { + if (ue_db.count(rnti) > 0) { // Add RNTI to the PHY (pregerate signals) now instead of after PRACH if (!ue_db[rnti]->is_phy_added) { @@ -214,7 +214,7 @@ int mac::ue_cfg(uint16_t rnti, sched_interface::ue_cfg_t* cfg) } // Update Scheduler configuration - if ((cfg != nullptr) ? scheduler.ue_cfg(rnti, 0, cfg) : false) { // TODO: provide enb_cc_idx + if ((cfg != nullptr) ? (scheduler.ue_cfg(rnti, cfg) != SRSLTE_SUCCESS) : false) { Error("Registering new UE rnti=0x%x to SCHED\n", rnti); } else { ret = 0; @@ -458,12 +458,12 @@ int mac::rach_detected(uint32_t tti, uint32_t enb_cc_idx, uint32_t preamble_idx, { log_h->step(tti); - pthread_rwlock_rdlock(&rwlock); + pthread_rwlock_wrlock(&rwlock); uint32_t rnti = last_rnti; // Create new UE - if (!ue_db.count(rnti)) { + if (ue_db.count(rnti) == 0) { ue_db[rnti] = new ue(rnti, cell.nof_prb, &scheduler, rrc_h, rlc_h, log_h, SRSLTE_FDD_NOF_HARQ); } @@ -483,10 +483,11 @@ int mac::rach_detected(uint32_t tti, uint32_t enb_cc_idx, uint32_t preamble_idx, rar_info.prach_tti = tti; // Add new user to the scheduler so that it can RX/TX SRB0 - sched_interface::ue_cfg_t uecfg; - bzero(&uecfg, sizeof(sched_interface::ue_cfg_t)); - uecfg.ue_bearers[0].direction = srsenb::sched_interface::ue_bearer_cfg_t::BOTH; - if (scheduler.ue_cfg(rnti, enb_cc_idx, &uecfg)) { + sched_interface::ue_cfg_t ue_cfg = {}; + ue_cfg.supported_cc_idxs.push_back(enb_cc_idx); + ue_cfg.ue_bearers[0].direction = srsenb::sched_interface::ue_bearer_cfg_t::BOTH; + ue_cfg.dl_cfg.tm = SRSLTE_TM1; + if (scheduler.ue_cfg(rnti, &ue_cfg) != SRSLTE_SUCCESS) { Error("Registering new user rnti=0x%x to SCHED\n", rnti); return -1; } diff --git a/srsenb/src/stack/mac/scheduler.cc b/srsenb/src/stack/mac/scheduler.cc index ef173284a..54c71ab3f 100644 --- a/srsenb/src/stack/mac/scheduler.cc +++ b/srsenb/src/stack/mac/scheduler.cc @@ -200,11 +200,14 @@ int sched::cell_cfg(const std::vector& cell_cfg) * *******************************************************/ -int sched::ue_cfg(uint16_t rnti, uint32_t enb_cc_idx, sched_interface::ue_cfg_t* ue_cfg) +int sched::ue_cfg(uint16_t rnti, sched_interface::ue_cfg_t* ue_cfg) { // Add or config user - pthread_rwlock_wrlock(&rwlock); - ue_db[rnti].set_cfg(rnti, sched_cell_params, ue_cfg, enb_cc_idx); + pthread_rwlock_rdlock(&rwlock); + if (ue_db.count(rnti) == 0) { + ue_db[rnti].init(rnti, sched_cell_params); + } + ue_db[rnti].set_cfg(ue_cfg); pthread_rwlock_unlock(&rwlock); return 0; diff --git a/srsenb/src/stack/mac/scheduler_ue.cc b/srsenb/src/stack/mac/scheduler_ue.cc index d4a73afdf..2af2cd669 100644 --- a/srsenb/src/stack/mac/scheduler_ue.cc +++ b/srsenb/src/stack/mac/scheduler_ue.cc @@ -60,32 +60,49 @@ sched_ue::sched_ue() reset(); } -void sched_ue::set_cfg(uint16_t rnti_, - const std::vector& cell_list_params_, - sched_interface::ue_cfg_t* cfg_, - uint32_t primary_cc_idx_) +void sched_ue::init(uint16_t rnti_, const std::vector& cell_list_params_) { - reset(); - { std::lock_guard lock(mutex); rnti = rnti_; cell_params_list = &cell_list_params_; - main_cc_params = &(*cell_params_list)[primary_cc_idx_]; - cell = main_cc_params->cfg.cell; + } + Info("SCHED: Added user rnti=0x%x\n", rnti); +} - max_msg3retx = main_cc_params->cfg.maxharq_msg3tx; +void sched_ue::set_cfg(sched_interface::ue_cfg_t* cfg_) +{ + { + std::lock_guard lock(mutex); + // store previous supported cc idxs + std::vector prev_cc_idxs(std::move(cfg.supported_cc_idxs)); cfg = *cfg_; - // Initialize TM - cfg.dl_cfg.tm = SRSLTE_TM1; + // if no list of supported cc idxs is provided, we keep the previous one + if (cfg.supported_cc_idxs.empty()) { + if (prev_cc_idxs.empty()) { + Warning("SCHED: Primary cc idx was not set for user rnti=0x%x. Defaulting to first cc.\n", rnti); + cfg.supported_cc_idxs.push_back(0); + } else { + cfg.supported_cc_idxs = prev_cc_idxs; + } + } - Info("SCHED: Added user rnti=0x%x\n", rnti); + // if primary cc has changed + if (prev_cc_idxs.empty() or prev_cc_idxs[0] != cfg.supported_cc_idxs[0]) { + main_cc_params = &(*cell_params_list)[cfg.supported_cc_idxs[0]]; + cell = main_cc_params->cfg.cell; + max_msg3retx = main_cc_params->cfg.maxharq_msg3tx; + } - // Init sched_ue carriers - carriers.emplace_back(&cfg, main_cc_params, rnti); - enb_ue_cellindex_map[primary_cc_idx_] = 0; + // setup sched_ue carriers + carriers.clear(); + enb_ue_cellindex_map.clear(); + for (uint32_t i = 0; i < cfg.supported_cc_idxs.size(); ++i) { + carriers.emplace_back(&cfg, (*cell_params_list)[cfg.supported_cc_idxs[i]], rnti); + enb_ue_cellindex_map[cfg.supported_cc_idxs[i]] = i; + } } for (int i = 0; i < sched_interface::MAX_LC; i++) { @@ -96,13 +113,14 @@ void sched_ue::set_cfg(uint16_t rnti_, main_cc_params->sched_cfg->pdsch_max_mcs, main_cc_params->sched_cfg->max_aggr_level); set_fixed_mcs(main_cc_params->sched_cfg->pusch_mcs, main_cc_params->sched_cfg->pdsch_mcs); + configured = true; } void sched_ue::reset() { { std::lock_guard lock(mutex); - bzero(&cfg, sizeof(sched_interface::ue_cfg_t)); + cfg = {}; sr = false; next_tpc_pusch = 1; next_tpc_pucch = 1; @@ -112,6 +130,7 @@ void sched_ue::reset() cqi_request_tti = 0; conres_ce_pending = true; carriers.clear(); + enb_ue_cellindex_map.clear(); } for (int i = 0; i < sched_interface::MAX_LC; i++) { @@ -1075,10 +1094,10 @@ int sched_ue::cqi_to_tbs(uint32_t cqi, ***********************************************************************************************/ sched_ue_carrier::sched_ue_carrier(sched_interface::ue_cfg_t* cfg_, - const sched_cell_params_t* cell_cfg_, + const sched_cell_params_t& cell_cfg_, uint16_t rnti_) : cfg(cfg_), - cell_params(cell_cfg_), + cell_params(&cell_cfg_), rnti(rnti_), log_h(srslte::logmap::get("MAC ")) { diff --git a/srsenb/src/stack/rrc/rrc.cc b/srsenb/src/stack/rrc/rrc.cc index ac9558da7..1bfab8ed3 100644 --- a/srsenb/src/stack/rrc/rrc.cc +++ b/srsenb/src/stack/rrc/rrc.cc @@ -1580,32 +1580,36 @@ void rrc::ue::send_connection_setup(bool is_setup) phy_cfg->cqi_report_cfg.nom_pdsch_rs_epre_offset = 0; // Add SRB1 to Scheduler - srsenb::sched_interface::ue_cfg_t sched_cfg; - bzero(&sched_cfg, sizeof(srsenb::sched_interface::ue_cfg_t)); - sched_cfg.maxharq_tx = parent->cfg.mac_cnfg.ul_sch_cfg.max_harq_tx.to_number(); - sched_cfg.continuous_pusch = false; - sched_cfg.aperiodic_cqi_period = - parent->cfg.cqi_cfg.mode == RRC_CFG_CQI_MODE_APERIODIC ? parent->cfg.cqi_cfg.period : 0; - sched_cfg.ue_bearers[0].direction = srsenb::sched_interface::ue_bearer_cfg_t::BOTH; - sched_cfg.ue_bearers[1].direction = srsenb::sched_interface::ue_bearer_cfg_t::BOTH; + srsenb::sched_interface::ue_cfg_t ue_cfg = {}; + ue_cfg.maxharq_tx = parent->cfg.mac_cnfg.ul_sch_cfg.max_harq_tx.to_number(); + ue_cfg.continuous_pusch = false; + ue_cfg.aperiodic_cqi_period = parent->cfg.cqi_cfg.mode == RRC_CFG_CQI_MODE_APERIODIC ? parent->cfg.cqi_cfg.period : 0; + ue_cfg.ue_bearers[0].direction = srsenb::sched_interface::ue_bearer_cfg_t::BOTH; + ue_cfg.ue_bearers[1].direction = srsenb::sched_interface::ue_bearer_cfg_t::BOTH; if (parent->cfg.cqi_cfg.mode == RRC_CFG_CQI_MODE_APERIODIC) { - sched_cfg.aperiodic_cqi_period = parent->cfg.cqi_cfg.mode == parent->cfg.cqi_cfg.period; - sched_cfg.dl_cfg.cqi_report.aperiodic_configured = true; + ue_cfg.aperiodic_cqi_period = parent->cfg.cqi_cfg.mode == parent->cfg.cqi_cfg.period; + ue_cfg.dl_cfg.cqi_report.aperiodic_configured = true; } else { - sched_cfg.dl_cfg.cqi_report.pmi_idx = cqi_idx; - sched_cfg.dl_cfg.cqi_report.periodic_configured = true; - } - sched_cfg.pucch_cfg.I_sr = sr_I; - sched_cfg.pucch_cfg.n_pucch_sr = sr_N_pucch; - sched_cfg.pucch_cfg.sr_configured = true; - sched_cfg.pucch_cfg.n_pucch = cqi_pucch; - sched_cfg.pucch_cfg.delta_pucch_shift = parent->sib2.rr_cfg_common.pucch_cfg_common.delta_pucch_shift.to_number(); - sched_cfg.pucch_cfg.N_cs = parent->sib2.rr_cfg_common.pucch_cfg_common.ncs_an; - sched_cfg.pucch_cfg.n_rb_2 = parent->sib2.rr_cfg_common.pucch_cfg_common.nrb_cqi; - sched_cfg.pucch_cfg.N_pucch_1 = parent->sib2.rr_cfg_common.pucch_cfg_common.n1_pucch_an; + ue_cfg.dl_cfg.cqi_report.pmi_idx = cqi_idx; + ue_cfg.dl_cfg.cqi_report.periodic_configured = true; + } + ue_cfg.dl_cfg.tm = SRSLTE_TM1; + ue_cfg.pucch_cfg.I_sr = sr_I; + ue_cfg.pucch_cfg.n_pucch_sr = sr_N_pucch; + ue_cfg.pucch_cfg.sr_configured = true; + ue_cfg.pucch_cfg.n_pucch = cqi_pucch; + ue_cfg.pucch_cfg.delta_pucch_shift = parent->sib2.rr_cfg_common.pucch_cfg_common.delta_pucch_shift.to_number(); + ue_cfg.pucch_cfg.N_cs = parent->sib2.rr_cfg_common.pucch_cfg_common.ncs_an; + ue_cfg.pucch_cfg.n_rb_2 = parent->sib2.rr_cfg_common.pucch_cfg_common.nrb_cqi; + ue_cfg.pucch_cfg.N_pucch_1 = parent->sib2.rr_cfg_common.pucch_cfg_common.n1_pucch_an; + // TODO: For now the ue supports all cc + ue_cfg.supported_cc_idxs.resize(parent->cfg.cell_list.size()); + for (uint32_t i = 0; i < ue_cfg.supported_cc_idxs.size(); ++i) { + ue_cfg.supported_cc_idxs[i] = i; + } // Configure MAC - parent->mac->ue_cfg(rnti, &sched_cfg); + parent->mac->ue_cfg(rnti, &ue_cfg); // Configure SRB1 in RLC parent->rlc->add_bearer(rnti, 1, srslte::rlc_config_t::srb_config(1)); diff --git a/srsenb/test/mac/scheduler_test.cc b/srsenb/test/mac/scheduler_test.cc index aa9601e22..571ccbba2 100644 --- a/srsenb/test/mac/scheduler_test.cc +++ b/srsenb/test/mac/scheduler_test.cc @@ -107,9 +107,9 @@ int main(int argc, char* argv[]) srsenb::sched_interface::dl_sched_res_t sched_result_dl; srsenb::sched_interface::ul_sched_res_t sched_result_ul; - srsenb::sched_interface::ue_cfg_t ue_cfg; - bzero(&ue_cfg, sizeof(srsenb::sched_interface::ue_cfg_t)); - uint16_t rnti = 30; + srsenb::sched_interface::ue_cfg_t ue_cfg = {}; + ue_cfg.supported_cc_idxs = {0}; + uint16_t rnti = 30; ue_cfg.aperiodic_cqi_period = 40; ue_cfg.maxharq_tx = 5; @@ -118,7 +118,7 @@ int main(int argc, char* argv[]) bzero(&bearer_cfg, sizeof(srsenb::sched_interface::ue_bearer_cfg_t)); bearer_cfg.direction = srsenb::sched_interface::ue_bearer_cfg_t::BOTH; - my_sched.ue_cfg(rnti, 0, &ue_cfg); + my_sched.ue_cfg(rnti, &ue_cfg); my_sched.bearer_ue_cfg(rnti, 0, &bearer_cfg); // my_sched.dl_rlc_buffer_state(rnti, 0, 1e6, 0); my_sched.ul_bsr(rnti, 0, 1e6f, true); diff --git a/srsenb/test/mac/scheduler_test_rand.cc b/srsenb/test/mac/scheduler_test_rand.cc index 5986ada07..efa775ca6 100644 --- a/srsenb/test/mac/scheduler_test_rand.cc +++ b/srsenb/test/mac/scheduler_test_rand.cc @@ -255,9 +255,8 @@ int sched_tester::add_user(uint16_t rnti, info.preamble_idx = tti_data.nof_prachs++; tester_ues.insert(std::make_pair(rnti, info)); - if (ue_cfg(rnti, CARRIER_IDX, &ue_cfg_) != SRSLTE_SUCCESS) { - TESTERROR("[TESTER] Registering new user rnti=0x%x to SCHED\n", rnti); - } + CONDERROR(ue_cfg(rnti, &ue_cfg_) != SRSLTE_SUCCESS, "[TESTER] Configuring new user rnti=0x%x to sched\n", rnti); + dl_sched_rar_info_t rar_info = {}; rar_info.prach_tti = tti_data.tti_rx; rar_info.temp_crnti = rnti; @@ -980,9 +979,12 @@ sched_sim_args rand_sim_params(const srsenb::sched_interface::cell_cfg_t& cell_c uint32_t max_nof_users = 5; std::uniform_int_distribution<> connection_dur_dist(min_conn_dur, max_conn_dur); - bzero(&sim_args.ue_cfg, sizeof(srsenb::sched_interface::ue_cfg_t)); + sim_args.ue_cfg = {}; sim_args.ue_cfg.aperiodic_cqi_period = 40; sim_args.ue_cfg.maxharq_tx = 5; + sim_args.ue_cfg.dl_cfg.tm = SRSLTE_TM1; + sim_args.ue_cfg.supported_cc_idxs.push_back(0); + sim_args.ue_cfg.ue_bearers[0].direction = srsenb::sched_interface::ue_bearer_cfg_t::BOTH; bzero(&sim_args.bearer_cfg, sizeof(srsenb::sched_interface::ue_bearer_cfg_t)); sim_args.bearer_cfg.direction = srsenb::sched_interface::ue_bearer_cfg_t::BOTH;