From d183d64409422425a11ca7cefe5738a3ed9617a3 Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Fri, 17 Apr 2020 12:10:31 +0100 Subject: [PATCH] added allocate_rnti method to mac. Useful both during PRACH and handover UE resource allocation --- .../srslte/interfaces/enb_interfaces.h | 9 ++-- srsenb/hdr/stack/mac/mac.h | 5 ++ srsenb/hdr/stack/mac/scheduler_ue.h | 2 +- srsenb/src/stack/mac/mac.cc | 49 +++++++++++-------- srsenb/src/stack/mac/scheduler_ue.cc | 10 ++-- 5 files changed, 44 insertions(+), 31 deletions(-) diff --git a/lib/include/srslte/interfaces/enb_interfaces.h b/lib/include/srslte/interfaces/enb_interfaces.h index f27844c91..f4258fcc6 100644 --- a/lib/include/srslte/interfaces/enb_interfaces.h +++ b/lib/include/srslte/interfaces/enb_interfaces.h @@ -282,6 +282,9 @@ public: virtual void phy_config_enabled(uint16_t rnti, bool enabled) = 0; virtual void write_mcch(asn1::rrc::sib_type2_s* sib2, asn1::rrc::sib_type13_r9_s* sib13, asn1::rrc::mcch_msg_s* mcch) = 0; + + /* Allocation of C-RNTI during HO */ + virtual uint16_t allocate_rnti() = 0; }; class mac_interface_rlc @@ -487,8 +490,7 @@ public: // Combined interface for stack (MAC and RRC) to access PHY class phy_interface_stack_lte : public phy_interface_mac_lte, public phy_interface_rrc_lte -{ -}; +{}; typedef struct { uint32_t enb_id; // 20-bit id (lsb bits) @@ -524,8 +526,7 @@ public: // STACK interface for MAC class stack_interface_mac_lte : public srslte::task_handler_interface -{ -}; +{}; } // namespace srsenb diff --git a/srsenb/hdr/stack/mac/mac.h b/srsenb/hdr/stack/mac/mac.h index 3de182d2a..959374b5d 100644 --- a/srsenb/hdr/stack/mac/mac.h +++ b/srsenb/hdr/stack/mac/mac.h @@ -99,11 +99,16 @@ public: void write_mcch(asn1::rrc::sib_type2_s* sib2, asn1::rrc::sib_type13_r9_s* sib13, asn1::rrc::mcch_msg_s* mcch) override; + /* Allocate C-RNTI */ + uint16_t allocate_rnti() final; + private: static const int MAX_LOCATIONS = 20; static const uint32_t cfi = 3; srslte_dci_location_t locations[MAX_LOCATIONS] = {}; + std::mutex rnti_mutex; + // We use a rwlock in MAC to allow multiple workers to access MAC simultaneously. No conflicts will happen since // access for different TTIs pthread_rwlock_t rwlock = {}; diff --git a/srsenb/hdr/stack/mac/scheduler_ue.h b/srsenb/hdr/stack/mac/scheduler_ue.h index 616bcba63..d5f6b3ed0 100644 --- a/srsenb/hdr/stack/mac/scheduler_ue.h +++ b/srsenb/hdr/stack/mac/scheduler_ue.h @@ -212,7 +212,7 @@ private: uint32_t cfi, const srslte_dci_dl_t& dci); - static bool bearer_is_ul(ue_bearer_t* lch); + static bool bearer_is_ul(const ue_bearer_t* lch); static bool bearer_is_dl(const ue_bearer_t* lch); uint32_t get_pending_ul_old_data_unlocked(uint32_t cc_idx); diff --git a/srsenb/src/stack/mac/mac.cc b/srsenb/src/stack/mac/mac.cc index 8dc1cdcd8..157fefeab 100644 --- a/srsenb/src/stack/mac/mac.cc +++ b/srsenb/src/stack/mac/mac.cc @@ -37,7 +37,10 @@ using namespace asn1::rrc; namespace srsenb { mac::mac() : - last_rnti(0), rar_pdu_msg(sched_interface::MAX_RAR_LIST), rar_payload(), common_buffers(SRSLTE_MAX_CARRIERS) + last_rnti(0), + rar_pdu_msg(sched_interface::MAX_RAR_LIST), + rar_payload(), + common_buffers(SRSLTE_MAX_CARRIERS) { pthread_rwlock_init(&rwlock, nullptr); } @@ -445,34 +448,38 @@ int mac::sr_detected(uint32_t tti, uint16_t rnti) return ret; } +uint16_t mac::allocate_rnti() +{ + std::lock_guard lock(rnti_mutex); + + // Assign a c-rnti + uint16_t rnti = last_rnti++; + if (last_rnti >= 60000) { + last_rnti = 70; + } + + return rnti; +} + void mac::rach_detected(uint32_t tti, uint32_t enb_cc_idx, uint32_t preamble_idx, uint32_t time_adv) { static srslte::mutexed_tprof rach_tprof("rach_tprof", "MAC", 1); log_h->step(tti); - uint16_t rnti; - auto rach_tprof_meas = rach_tprof.start(); + auto rach_tprof_meas = rach_tprof.start(); - { - srslte::rwlock_write_guard lock(rwlock); + uint16_t rnti = allocate_rnti(); - rnti = last_rnti; + // Create new UE + std::unique_ptr ue_ptr{new ue(rnti, args.nof_prb, &scheduler, rrc_h, rlc_h, phy_h, log_h, cells.size())}; - // Create new UE - if (ue_db.count(rnti) == 0) { - ue_db[rnti] = - std::unique_ptr{new ue(rnti, args.nof_prb, &scheduler, rrc_h, rlc_h, phy_h, log_h, cells.size())}; - } - - // Set PCAP if available - if (pcap != nullptr) { - ue_db[rnti]->start_pcap(pcap); - } + // Set PCAP if available + if (pcap != nullptr) { + ue_ptr->start_pcap(pcap); + } - // Increase RNTI counter - last_rnti++; - if (last_rnti >= 60000) { - last_rnti = 70; - } + { + srslte::rwlock_write_guard lock(rwlock); + ue_db[rnti] = std::move(ue_ptr); } stack_task_queue.push([this, rnti, tti, enb_cc_idx, preamble_idx, time_adv, rach_tprof_meas]() mutable { diff --git a/srsenb/src/stack/mac/scheduler_ue.cc b/srsenb/src/stack/mac/scheduler_ue.cc index fde3f60d8..317fcab11 100644 --- a/srsenb/src/stack/mac/scheduler_ue.cc +++ b/srsenb/src/stack/mac/scheduler_ue.cc @@ -748,7 +748,7 @@ int sched_ue::generate_format0(sched_interface::ul_sched_data_t* data, * *******************************************************/ -bool sched_ue::bearer_is_ul(ue_bearer_t* lch) +bool sched_ue::bearer_is_ul(const ue_bearer_t* lch) { return lch->cfg.direction == sched_interface::ue_bearer_cfg_t::UL || lch->cfg.direction == sched_interface::ue_bearer_cfg_t::BOTH; @@ -1186,8 +1186,8 @@ int sched_ue::cqi_to_tbs(uint32_t cqi, coderate = srslte_coderate(tbs, nof_re); srslte_mod_t mod = (is_ul) ? srslte_ra_ul_mod_from_mcs(sel_mcs) : srslte_ra_dl_mod_from_mcs(sel_mcs, use_tbs_index_alt); - Qm = SRSLTE_MIN(max_Qm, srslte_mod_bits_x_symbol(mod)); - eff_coderate = coderate / Qm; + Qm = SRSLTE_MIN(max_Qm, srslte_mod_bits_x_symbol(mod)); + eff_coderate = coderate / Qm; } while ((sel_mcs > 0 && coderate > max_coderate) || eff_coderate > 0.930); if (mcs != nullptr) { @@ -1217,8 +1217,8 @@ sched_ue_carrier::sched_ue_carrier(const sched_interface::ue_cfg_t& cfg_, dl_cqi = (ue_cc_idx == 0) ? cell_params->cfg.initial_dl_cqi : 0; // set max mcs - max_mcs_ul = cell_params->sched_cfg->pusch_max_mcs >= 0 ? cell_params->sched_cfg->pusch_max_mcs : 28; - max_mcs_dl = cell_params->sched_cfg->pdsch_max_mcs >= 0 ? cell_params->sched_cfg->pdsch_max_mcs : 28; + max_mcs_ul = cell_params->sched_cfg->pusch_max_mcs >= 0 ? cell_params->sched_cfg->pusch_max_mcs : 28; + max_mcs_dl = cell_params->sched_cfg->pdsch_max_mcs >= 0 ? cell_params->sched_cfg->pdsch_max_mcs : 28; max_mcs_dl_alt = cell_params->sched_cfg->pdsch_max_mcs >= 0 ? SRSLTE_MIN(cell_params->sched_cfg->pdsch_max_mcs, 27) : 27; max_aggr_level = cell_params->sched_cfg->max_aggr_level >= 0 ? cell_params->sched_cfg->max_aggr_level : 3;