From 9c7c1900742dd8e1977be02fbc35a97fa9d6c7b8 Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Wed, 13 Jan 2021 17:51:47 +0000 Subject: [PATCH] when the rrc fails to allocate the ue cell resources, it should erase the ue from all stack layers --- .../srslte/interfaces/enb_interfaces.h | 2 +- srsenb/hdr/stack/rrc/rrc.h | 2 +- srsenb/hdr/stack/rrc/rrc_ue.h | 1 + srsenb/src/stack/mac/mac.cc | 6 ++++- srsenb/src/stack/rrc/rrc.cc | 23 +++++++++---------- srsenb/src/stack/rrc/rrc_ue.cc | 15 +++++++----- 6 files changed, 28 insertions(+), 21 deletions(-) diff --git a/lib/include/srslte/interfaces/enb_interfaces.h b/lib/include/srslte/interfaces/enb_interfaces.h index 5f32ed787..b7945afb2 100644 --- a/lib/include/srslte/interfaces/enb_interfaces.h +++ b/lib/include/srslte/interfaces/enb_interfaces.h @@ -400,7 +400,7 @@ class rrc_interface_mac { public: /* Radio Link failure */ - virtual void add_user(uint16_t rnti, const sched_interface::ue_cfg_t& init_ue_cfg) = 0; + virtual int add_user(uint16_t rnti, const sched_interface::ue_cfg_t& init_ue_cfg) = 0; virtual void upd_user(uint16_t new_rnti, uint16_t old_rnti) = 0; virtual void set_activity_user(uint16_t rnti) = 0; virtual bool is_paging_opportunity(uint32_t tti, uint32_t* payload_len) = 0; diff --git a/srsenb/hdr/stack/rrc/rrc.h b/srsenb/hdr/stack/rrc/rrc.h index ffd65e5c2..6aa21fc1b 100644 --- a/srsenb/hdr/stack/rrc/rrc.h +++ b/srsenb/hdr/stack/rrc/rrc.h @@ -61,7 +61,7 @@ public: void tti_clock(); // rrc_interface_mac - void add_user(uint16_t rnti, const sched_interface::ue_cfg_t& init_ue_cfg) override; + int add_user(uint16_t rnti, const sched_interface::ue_cfg_t& init_ue_cfg) override; void upd_user(uint16_t new_rnti, uint16_t old_rnti) override; void set_activity_user(uint16_t rnti) override; bool is_paging_opportunity(uint32_t tti, uint32_t* payload_len) override; diff --git a/srsenb/hdr/stack/rrc/rrc_ue.h b/srsenb/hdr/stack/rrc/rrc_ue.h index 34f78b680..34591fd8b 100644 --- a/srsenb/hdr/stack/rrc/rrc_ue.h +++ b/srsenb/hdr/stack/rrc/rrc_ue.h @@ -25,6 +25,7 @@ public: ue(rrc* outer_rrc, uint16_t rnti, const sched_interface::ue_cfg_t& ue_cfg); ~ue(); + int init(); bool is_connected(); bool is_idle(); diff --git a/srsenb/src/stack/mac/mac.cc b/srsenb/src/stack/mac/mac.cc index eebe7c2d7..84d527614 100644 --- a/srsenb/src/stack/mac/mac.cc +++ b/srsenb/src/stack/mac/mac.cc @@ -525,11 +525,15 @@ void mac::rach_detected(uint32_t tti, uint32_t enb_cc_idx, uint32_t preamble_idx ue_cfg.supported_cc_list[0].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); + ue_rem(rnti); return; } // Register new user in RRC - rrc_h->add_user(rnti, ue_cfg); + if (rrc_h->add_user(rnti, ue_cfg) == SRSLTE_ERROR) { + ue_rem(rnti); + return; + } // Trigger scheduler RACH scheduler.dl_rach_info(enb_cc_idx, rar_info); diff --git a/srsenb/src/stack/rrc/rrc.cc b/srsenb/src/stack/rrc/rrc.cc index f597de0d3..4d8c183cb 100644 --- a/srsenb/src/stack/rrc/rrc.cc +++ b/srsenb/src/stack/rrc/rrc.cc @@ -144,27 +144,25 @@ uint32_t rrc::get_nof_users() void rrc::max_retx_attempted(uint16_t rnti) {} // This function is called from PRACH worker (can wait) -void rrc::add_user(uint16_t rnti, const sched_interface::ue_cfg_t& sched_ue_cfg) +int rrc::add_user(uint16_t rnti, const sched_interface::ue_cfg_t& sched_ue_cfg) { auto user_it = users.find(rnti); if (user_it == users.end()) { - bool rnti_added = true; if (rnti != SRSLTE_MRNTI) { // only non-eMBMS RNTIs are present in user map - auto p = users.insert(std::make_pair(rnti, std::unique_ptr{new ue(this, rnti, sched_ue_cfg)})); + std::unique_ptr u{new ue(this, rnti, sched_ue_cfg)}; + if (not u->init()) { + rrc_log->error("Adding user rnti=0x%x - Failed to allocate user resources\n", rnti); + return SRSLTE_ERROR; + } if (ue_pool.capacity() <= 4) { task_sched.defer_task([]() { rrc::ue_pool.reserve(16); }); } - rnti_added = p.second and p.first->second->is_allocated(); - } - if (rnti_added) { - rlc->add_user(rnti); - pdcp->add_user(rnti); - rrc_log->info("Added new user rnti=0x%x\n", rnti); - } else { - mac->bearer_ue_rem(rnti, 0); - rrc_log->error("Adding user rnti=0x%x - Failed to allocate user resources\n", rnti); + users.insert(std::make_pair(rnti, std::move(u))); } + rlc->add_user(rnti); + pdcp->add_user(rnti); + rrc_log->info("Added new user rnti=0x%x\n", rnti); } else { rrc_log->error("Adding user rnti=0x%x (already exists)\n", rnti); } @@ -181,6 +179,7 @@ void rrc::add_user(uint16_t rnti, const sched_interface::ue_cfg_t& sched_ue_cfg) teid_in = gtpu->add_bearer(SRSLTE_MRNTI, lcid, 1, 1); } } + return SRSLTE_SUCCESS; } /* Function called by MAC after the reception of a C-RNTI CE indicating that the UE still has a diff --git a/srsenb/src/stack/rrc/rrc_ue.cc b/srsenb/src/stack/rrc/rrc_ue.cc index 0ac96cdae..1d1de8995 100644 --- a/srsenb/src/stack/rrc/rrc_ue.cc +++ b/srsenb/src/stack/rrc/rrc_ue.cc @@ -39,24 +39,27 @@ rrc::ue::ue(rrc* outer_rrc, uint16_t rnti_, const sched_interface::ue_cfg_t& sch bearer_list(rnti_, parent->cfg), ue_security_cfg(parent->cfg), mac_ctrl(rnti, ue_cell_list, bearer_list, parent->cfg, parent->mac, *parent->cell_common_list, sched_ue_cfg) -{ +{} + +rrc::ue::~ue() {} +int rrc::ue::init() +{ // Allocate cell and PUCCH resources - if (ue_cell_list.add_cell(sched_ue_cfg.supported_cc_list[0].enb_cc_idx) == nullptr) { - return; + if (ue_cell_list.add_cell(mac_ctrl.get_ue_sched_cfg().supported_cc_list[0].enb_cc_idx) == nullptr) { + return SRSLTE_ERROR; } // Configure apply_setup_phy_common(parent->cfg.sibs[1].sib2().rr_cfg_common, true); - activity_timer = outer_rrc->task_sched.get_unique_timer(); + activity_timer = parent->task_sched.get_unique_timer(); set_activity_timeout(MSG3_RX_TIMEOUT); // next UE response is Msg3 mobility_handler.reset(new rrc_mobility(this)); + return SRSLTE_SUCCESS; } -rrc::ue::~ue() {} - void* rrc::ue::operator new(size_t sz) { assert(sz == sizeof(ue));