diff --git a/lib/include/srsran/interfaces/enb_mac_interfaces.h b/lib/include/srsran/interfaces/enb_mac_interfaces.h index 4dd8fbf38..5bd493f88 100644 --- a/lib/include/srsran/interfaces/enb_mac_interfaces.h +++ b/lib/include/srsran/interfaces/enb_mac_interfaces.h @@ -212,8 +212,8 @@ public: virtual int cell_cfg(const std::vector& cell_cfg) = 0; /* Manages UE configuration context */ - virtual int ue_cfg(uint16_t rnti, sched_interface::ue_cfg_t* cfg) = 0; - virtual int ue_rem(uint16_t rnti) = 0; + virtual int ue_cfg(uint16_t rnti, const sched_interface::ue_cfg_t* cfg) = 0; + virtual int ue_rem(uint16_t rnti) = 0; /** * Called after Msg3 reception to set the UE C-RNTI, resolve contention, and alter the UE's configuration in the @@ -223,7 +223,7 @@ public: * @param crnti chosen C-RNTI for the UE * @param cfg new UE scheduler configuration */ - virtual int ue_set_crnti(uint16_t temp_crnti, uint16_t crnti, sched_interface::ue_cfg_t* cfg) = 0; + virtual int ue_set_crnti(uint16_t temp_crnti, uint16_t crnti, const sched_interface::ue_cfg_t& cfg) = 0; /* Manages UE bearers and associated configuration */ virtual int bearer_ue_cfg(uint16_t rnti, uint32_t lc_id, sched_interface::ue_bearer_cfg_t* cfg) = 0; diff --git a/srsenb/hdr/stack/mac/mac.h b/srsenb/hdr/stack/mac/mac.h index f7a8e50e7..23b40a658 100644 --- a/srsenb/hdr/stack/mac/mac.h +++ b/srsenb/hdr/stack/mac/mac.h @@ -77,9 +77,9 @@ public: int cell_cfg(const std::vector& cell_cfg) override; /* Manages UE scheduling context */ - int ue_cfg(uint16_t rnti, sched_interface::ue_cfg_t* cfg) override; + int ue_cfg(uint16_t rnti, const sched_interface::ue_cfg_t* cfg) override; int ue_rem(uint16_t rnti) override; - int ue_set_crnti(uint16_t temp_crnti, uint16_t crnti, sched_interface::ue_cfg_t* cfg) override; + int ue_set_crnti(uint16_t temp_crnti, uint16_t crnti, const sched_interface::ue_cfg_t& cfg) override; // Indicates that the PHY config dedicated has been enabled or not void phy_config_enabled(uint16_t rnti, bool enabled) override; diff --git a/srsenb/hdr/stack/mac/ue.h b/srsenb/hdr/stack/mac/ue.h index 3e247b97d..77d7354a5 100644 --- a/srsenb/hdr/stack/mac/ue.h +++ b/srsenb/hdr/stack/mac/ue.h @@ -132,9 +132,11 @@ public: srsran::obj_pool_itf* softbuffer_pool); virtual ~ue(); - void reset(); - void start_pcap(srsran::mac_pcap* pcap_); - void start_pcap_net(srsran::mac_pcap_net* pcap_net_); + void reset(); + void start_pcap(srsran::mac_pcap* pcap_); + void start_pcap_net(srsran::mac_pcap_net* pcap_net_); + void ue_cfg(const sched_interface::ue_cfg_t& ue_cfg); + void set_tti(uint32_t tti); uint16_t get_rnti() const { return rnti; } uint32_t set_ta(int ta) override; @@ -214,7 +216,7 @@ private: std::mutex mutex; std::mutex rx_buffers_mutex; - const uint8_t UL_CC_IDX = 0; ///< Passed to write CC index in PCAP (TODO: use actual CC idx) + static const uint8_t UL_CC_IDX = 0; ///< Passed to write CC index in PCAP }; } // namespace srsenb diff --git a/srsenb/src/stack/mac/mac.cc b/srsenb/src/stack/mac/mac.cc index 2a2c246a2..144e2dd5b 100644 --- a/srsenb/src/stack/mac/mac.cc +++ b/srsenb/src/stack/mac/mac.cc @@ -165,7 +165,7 @@ void mac::phy_config_enabled(uint16_t rnti, bool enabled) } // Update UE configuration -int mac::ue_cfg(uint16_t rnti, sched_interface::ue_cfg_t* cfg) +int mac::ue_cfg(uint16_t rnti, const sched_interface::ue_cfg_t* cfg) { srsran::rwlock_read_guard lock(rwlock); if (not check_ue_active(rnti)) { @@ -177,10 +177,12 @@ int mac::ue_cfg(uint16_t rnti, sched_interface::ue_cfg_t* cfg) ue_ptr->start_ta(); // Update Scheduler configuration - if (cfg != nullptr and scheduler.ue_cfg(rnti, *cfg) == SRSRAN_ERROR) { - logger.error("Registering new UE rnti=0x%x to SCHED", rnti); + if (scheduler.ue_cfg(rnti, *cfg) == SRSRAN_ERROR) { + logger.error("Registering UE rnti=0x%x to SCHED", rnti); return SRSRAN_ERROR; } + ue_ptr->ue_cfg(*cfg); + return SRSRAN_SUCCESS; } @@ -211,7 +213,7 @@ int mac::ue_rem(uint16_t rnti) } // Called after Msg3 -int mac::ue_set_crnti(uint16_t temp_crnti, uint16_t crnti, sched_interface::ue_cfg_t* cfg) +int mac::ue_set_crnti(uint16_t temp_crnti, uint16_t crnti, const sched_interface::ue_cfg_t& cfg) { srsran::rwlock_read_guard lock(rwlock); if (temp_crnti != crnti) { @@ -221,7 +223,7 @@ int mac::ue_set_crnti(uint16_t temp_crnti, uint16_t crnti, sched_interface::ue_c // Schedule ConRes Msg4 scheduler.dl_mac_buffer_state(crnti, (uint32_t)srsran::dl_sch_lcid::CON_RES_ID); } - return ue_cfg(crnti, cfg); + return ue_cfg(crnti, &cfg); } int mac::cell_cfg(const std::vector& cell_cfg_) @@ -493,19 +495,17 @@ uint16_t mac::allocate_ue(uint32_t enb_cc_idx) return rnti; } -uint16_t mac::reserve_new_crnti(const sched_interface::ue_cfg_t& ue_cfg) +uint16_t mac::reserve_new_crnti(const sched_interface::ue_cfg_t& uecfg) { - uint16_t rnti = allocate_ue(ue_cfg.supported_cc_list[0].enb_cc_idx); + uint16_t rnti = allocate_ue(uecfg.supported_cc_list[0].enb_cc_idx); if (rnti == SRSRAN_INVALID_RNTI) { return rnti; } // Add new user to the scheduler so that it can RX/TX SRB0 - if (scheduler.ue_cfg(rnti, ue_cfg) != SRSRAN_SUCCESS) { - logger.error("Registering new user rnti=0x%x to SCHED", rnti); + if (ue_cfg(rnti, &uecfg) != SRSRAN_SUCCESS) { return SRSRAN_INVALID_RNTI; } - return rnti; } @@ -534,20 +534,18 @@ void mac::rach_detected(uint32_t tti, uint32_t enb_cc_idx, uint32_t preamble_idx ++detected_rachs[enb_cc_idx]; // Add new user to the scheduler so that it can RX/TX SRB0 - sched_interface::ue_cfg_t ue_cfg = {}; - ue_cfg.supported_cc_list.emplace_back(); - ue_cfg.supported_cc_list.back().active = true; - ue_cfg.supported_cc_list.back().enb_cc_idx = enb_cc_idx; - ue_cfg.ue_bearers[0].direction = srsenb::sched_interface::ue_bearer_cfg_t::BOTH; - ue_cfg.supported_cc_list[0].dl_cfg.tm = SRSRAN_TM1; - if (scheduler.ue_cfg(rnti, ue_cfg) != SRSRAN_SUCCESS) { - logger.error("Registering new user rnti=0x%x to SCHED", rnti); - ue_rem(rnti); + sched_interface::ue_cfg_t uecfg = {}; + uecfg.supported_cc_list.emplace_back(); + uecfg.supported_cc_list.back().active = true; + uecfg.supported_cc_list.back().enb_cc_idx = enb_cc_idx; + uecfg.ue_bearers[0].direction = srsenb::sched_interface::ue_bearer_cfg_t::BOTH; + uecfg.supported_cc_list[0].dl_cfg.tm = SRSRAN_TM1; + if (ue_cfg(rnti, &uecfg) != SRSRAN_SUCCESS) { return; } // Register new user in RRC - if (rrc_h->add_user(rnti, ue_cfg) == SRSRAN_ERROR) { + if (rrc_h->add_user(rnti, uecfg) == SRSRAN_ERROR) { ue_rem(rnti); return; } @@ -924,6 +922,7 @@ int mac::get_ul_sched(uint32_t tti_tx_ul, ul_sched_list_t& ul_sched_res_list) // If the Rx soft-buffer is not given, abort reception if (phy_ul_sched_res->pusch[n].softbuffer_rx == nullptr) { + logger.warning("Failed to retrieve UL softbuffer for tti=%d, cc=%d", tti_tx_ul, enb_cc_idx); continue; } diff --git a/srsenb/src/stack/mac/ue.cc b/srsenb/src/stack/mac/ue.cc index 00e8c9287..0772a1491 100644 --- a/srsenb/src/stack/mac/ue.cc +++ b/srsenb/src/stack/mac/ue.cc @@ -220,6 +220,16 @@ void ue::start_pcap(srsran::mac_pcap* pcap_) pcap = pcap_; } +void ue::ue_cfg(const sched_interface::ue_cfg_t& ue_cfg) +{ + for (const auto& ue_cc : ue_cfg.supported_cc_list) { + // Allocate and initialize Rx/Tx softbuffers for new carriers (exclude PCell) + if (ue_cc.active and cc_buffers[ue_cc.enb_cc_idx].empty()) { + cc_buffers[ue_cc.enb_cc_idx].allocate_cc(softbuffer_pool->make()); + } + } +} + srsran_softbuffer_rx_t* ue::get_rx_softbuffer(uint32_t enb_cc_idx, uint32_t tti) { if ((size_t)enb_cc_idx >= cc_buffers.size() or cc_buffers[enb_cc_idx].empty()) { @@ -509,12 +519,6 @@ void ue::allocate_ce(srsran::sch_pdu* pdu, uint32_t lcid) } if (pdu->get()->set_scell_activation_cmd(active_scell_list)) { phy->set_activation_deactivation_scell(rnti, active_scell_list); - // Allocate and initialize Rx/Tx softbuffers for new carriers (exclude PCell) - for (size_t cc = 0; cc < cc_buffers.size(); ++cc) { - if (active_ccs[cc] >= 0 and cc_buffers[cc].empty()) { - cc_buffers[cc].allocate_cc(softbuffer_pool->make()); - } - } } else { logger.error("CE: Setting SCell Activation CE"); } diff --git a/srsenb/src/stack/rrc/mac_controller.cc b/srsenb/src/stack/rrc/mac_controller.cc index e42414597..1f36d2ef8 100644 --- a/srsenb/src/stack/rrc/mac_controller.cc +++ b/srsenb/src/stack/rrc/mac_controller.cc @@ -116,7 +116,7 @@ void mac_controller::handle_con_reject() if (not crnti_set) { crnti_set = true; // Need to schedule ConRes CE for UE to see the Reject message - mac->ue_set_crnti(rnti, rnti, ¤t_sched_ue_cfg); + mac->ue_set_crnti(rnti, rnti, current_sched_ue_cfg); } } @@ -137,7 +137,7 @@ int mac_controller::handle_crnti_ce(uint32_t temp_crnti) current_sched_ue_cfg.ue_bearers[i] = next_sched_ue_cfg.ue_bearers[i]; } - return mac->ue_set_crnti(temp_crnti, rnti, ¤t_sched_ue_cfg); + return mac->ue_set_crnti(temp_crnti, rnti, current_sched_ue_cfg); } int mac_controller::apply_basic_conn_cfg(const asn1::rrc::rr_cfg_ded_s& rr_cfg) @@ -183,7 +183,7 @@ int mac_controller::apply_basic_conn_cfg(const asn1::rrc::rr_cfg_ded_s& rr_cfg) // In case of RRC Connection Setup/Reest message (Msg4), we need to resolve the contention by sending a ConRes CE mac->phy_config_enabled(rnti, false); crnti_set = true; - return mac->ue_set_crnti(rnti, rnti, ¤t_sched_ue_cfg); + return mac->ue_set_crnti(rnti, rnti, current_sched_ue_cfg); } void mac_controller::handle_con_setup_complete() diff --git a/srsenb/test/common/dummy_classes.h b/srsenb/test/common/dummy_classes.h index 68c50baa8..9338f1484 100644 --- a/srsenb/test/common/dummy_classes.h +++ b/srsenb/test/common/dummy_classes.h @@ -28,9 +28,9 @@ class mac_dummy : public mac_interface_rrc { public: int cell_cfg(const std::vector& cell_cfg) override { return 0; } - int ue_cfg(uint16_t rnti, sched_interface::ue_cfg_t* cfg) override { return 0; } + int ue_cfg(uint16_t rnti, const sched_interface::ue_cfg_t* cfg) override { return 0; } int ue_rem(uint16_t rnti) override { return 0; } - int ue_set_crnti(uint16_t temp_crnti, uint16_t crnti, sched_interface::ue_cfg_t* cfg) override { return 0; } + int ue_set_crnti(uint16_t temp_crnti, uint16_t crnti, const sched_interface::ue_cfg_t& cfg) override { return 0; } int bearer_ue_cfg(uint16_t rnti, uint32_t lc_id, sched_interface::ue_bearer_cfg_t* cfg) override { return 0; } int bearer_ue_rem(uint16_t rnti, uint32_t lc_id) override { return 0; } void phy_config_enabled(uint16_t rnti, bool enabled) override {} diff --git a/srsenb/test/rrc/test_helpers.h b/srsenb/test/rrc/test_helpers.h index cadd06e94..ecd0823e6 100644 --- a/srsenb/test/rrc/test_helpers.h +++ b/srsenb/test/rrc/test_helpers.h @@ -175,14 +175,14 @@ public: class mac_mobility_dummy : public mac_dummy { public: - int ue_cfg(uint16_t rnti, sched_interface::ue_cfg_t* cfg) override + int ue_cfg(uint16_t rnti, const sched_interface::ue_cfg_t* cfg) override { ue_db[rnti] = *cfg; return 0; } - int ue_set_crnti(uint16_t temp_crnti, uint16_t crnti, sched_interface::ue_cfg_t* cfg) override + int ue_set_crnti(uint16_t temp_crnti, uint16_t crnti, const sched_interface::ue_cfg_t& cfg) override { - ue_db[crnti] = *cfg; + ue_db[crnti] = cfg; return 0; } std::map ue_db;