From 1aadc5c53e118a752d59ca811b784cc2055de91b Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Sun, 31 Jan 2021 18:02:25 +0100 Subject: [PATCH] mac_nr: tiny cleanups of MAC class, use of new logger --- srsue/hdr/stack/mac_nr/mac_nr.h | 10 +++- srsue/src/stack/mac_nr/mac_nr.cc | 95 ++++++++++++++++++++++---------- 2 files changed, 75 insertions(+), 30 deletions(-) diff --git a/srsue/hdr/stack/mac_nr/mac_nr.h b/srsue/hdr/stack/mac_nr/mac_nr.h index eca1bdd55..a4c7ec031 100644 --- a/srsue/hdr/stack/mac_nr/mac_nr.h +++ b/srsue/hdr/stack/mac_nr/mac_nr.h @@ -14,11 +14,11 @@ #define SRSUE_MAC_NR_H #include "srslte/common/block_queue.h" -#include "srslte/common/logmap.h" #include "srslte/common/mac_nr_pcap.h" #include "srslte/interfaces/mac_interface_types.h" #include "srslte/interfaces/ue_nr_interfaces.h" #include "srslte/mac/mac_sch_pdu_nr.h" +#include "srslte/srslog/srslog.h" #include "srsue/hdr/stack/mac/mux.h" #include "srsue/hdr/stack/ue_stack_base.h" @@ -71,13 +71,19 @@ private: void handle_pdu(srslte::unique_byte_buffer_t pdu); void get_ul_data(const mac_nr_grant_ul_t& grant, phy_interface_stack_nr::tx_request_t* tx_request); + bool is_si_opportunity(); + bool is_paging_opportunity(); + + bool has_crnti(); + uint16_t get_crnti(); + /// Interaction with rest of the stack phy_interface_mac_nr* phy = nullptr; rlc_interface_mac* rlc = nullptr; srslte::ext_task_sched_handle task_sched; std::unique_ptr pcap = nullptr; - srslte::log_ref log_h; + srslog::basic_logger& logger; srslte::byte_buffer_pool* pool = nullptr; mac_nr_args_t args = {}; diff --git a/srsue/src/stack/mac_nr/mac_nr.cc b/srsue/src/stack/mac_nr/mac_nr.cc index b0697a12b..61b48d164 100644 --- a/srsue/src/stack/mac_nr/mac_nr.cc +++ b/srsue/src/stack/mac_nr/mac_nr.cc @@ -11,14 +11,11 @@ */ #include "srsue/hdr/stack/mac_nr/mac_nr.h" -#include "srslte/common/log_helper.h" - -using namespace asn1::rrc; namespace srsue { mac_nr::mac_nr(srslte::ext_task_sched_handle task_sched_) : - pool(srslte::byte_buffer_pool::get_instance()), log_h("MAC"), task_sched(task_sched_) + pool(srslte::byte_buffer_pool::get_instance()), task_sched(task_sched_), logger(srslog::fetch_basic_logger("MAC")) { tx_buffer = srslte::allocate_unique_buffer(*pool); rlc_buffer = srslte::allocate_unique_buffer(*pool); @@ -63,15 +60,13 @@ void mac_nr::stop() // Implement Section 5.9 void mac_nr::reset() { - Info("Resetting MAC"); + logger.info("Resetting MAC-NR"); } void mac_nr::run_tti(const uint32_t tti) { - log_h->step(tti); - // Step all procedures - Debug("Running MAC tti=%d", tti); + logger.debug("Running MAC tti=%d", tti); } uint16_t mac_nr::get_ul_sched_rnti(uint32_t tti) @@ -79,7 +74,53 @@ uint16_t mac_nr::get_ul_sched_rnti(uint32_t tti) return crnti; } +bool mac_nr::is_si_opportunity() +{ + // TODO: ask RRC if we need SI + return false; +} + +bool mac_nr::is_paging_opportunity() +{ + return false; +} + uint16_t mac_nr::get_dl_sched_rnti(uint32_t tti) +{ + // Priority: SI-RNTI, P-RNTI, RA-RNTI, Temp-RNTI, CRNTI + if (is_si_opportunity()) { + return SRSLTE_SIRNTI; + } + + if (is_paging_opportunity()) { + return SRSLTE_PRNTI; + } + + // TODO: add new RA proc shortly +#if 0 + if (proc_ra->is_rar_opportunity()) { + return proc_ra->get_rar_rnti(); + } + + if (proc_ra->has_temp_rnti() && has_crnti() == false) { + return proc_ra->get_temp_rnti(); + } +#endif + + if (has_crnti()) { + return get_crnti(); + } + + // turn off DCI search for this TTI + return SRSLTE_INVALID_RNTI; +} + +bool mac_nr::has_crnti() +{ + return crnti != SRSLTE_INVALID_RNTI; +} + +uint16_t mac_nr::get_crnti() { return crnti; } @@ -126,13 +167,11 @@ void mac_nr::tb_decoded(const uint32_t cc_idx, mac_nr_grant_dl_t& grant) pcap->write_dl_crnti(grant.tb[i]->msg, grant.tb[i]->N_bytes, grant.rnti, true, grant.tti); } pdu_queue.push(std::move(grant.tb[i])); - - metrics[cc_idx].rx_pkts++; } } - - stack_task_dispatch_queue.push([this]() { process_pdus(); }); } + metrics[cc_idx].rx_pkts++; + stack_task_dispatch_queue.push([this]() { process_pdus(); }); } void mac_nr::new_grant_ul(const uint32_t cc_idx, const mac_nr_grant_ul_t& grant) @@ -165,11 +204,11 @@ void mac_nr::get_ul_data(const mac_nr_grant_ul_t& grant, phy_interface_stack_nr: // Add SDU if RLC has something to tx if (pdu_len > 0) { rlc_buffer->N_bytes = pdu_len; - log_h->info_hex(rlc_buffer->msg, rlc_buffer->N_bytes, "Read %d B from RLC", rlc_buffer->N_bytes); + logger.info(rlc_buffer->msg, rlc_buffer->N_bytes, "Read %d B from RLC", rlc_buffer->N_bytes); // add to MAC PDU and pack if (tx_pdu.add_sdu(args.drb_lcid, rlc_buffer->msg, rlc_buffer->N_bytes) != SRSLTE_SUCCESS) { - log_h->error("Error packing MAC PDU"); + logger.error("Error packing MAC PDU"); } } else { break; @@ -179,7 +218,7 @@ void mac_nr::get_ul_data(const mac_nr_grant_ul_t& grant, phy_interface_stack_nr: // Pack PDU tx_pdu.pack(); - log_h->info_hex(tx_buffer->msg, tx_buffer->N_bytes, "Generated MAC PDU (%d B)", tx_buffer->N_bytes); + logger.info(tx_buffer->msg, tx_buffer->N_bytes, "Generated MAC PDU (%d B)", tx_buffer->N_bytes); tx_request->data = tx_buffer->msg; tx_request->tb_len = tx_buffer->N_bytes; @@ -196,27 +235,27 @@ void mac_nr::timer_expired(uint32_t timer_id) void mac_nr::setup_lcid(const srslte::logical_channel_config_t& config) { - Info("Logical Channel Setup: LCID=%d, LCG=%d, priority=%d, PBR=%d, BSD=%dms, bucket_size=%d", - config.lcid, - config.lcg, - config.priority, - config.PBR, - config.BSD, - config.bucket_size); + logger.info("Logical Channel Setup: LCID=%d, LCG=%d, priority=%d, PBR=%d, BSD=%dms, bucket_size=%d", + config.lcid, + config.lcg, + config.priority, + config.PBR, + config.BSD, + config.bucket_size); // mux_unit.setup_lcid(config); // bsr_procedure.setup_lcid(config.lcid, config.lcg, config.priority); } void mac_nr::set_config(const srslte::bsr_cfg_t& bsr_cfg) { - Info("BSR config periodic timer %d retx timer %d", bsr_cfg.periodic_timer, bsr_cfg.retx_timer); - Warning("Not handling BSR config yet"); + logger.info("BSR config periodic timer %d retx timer %d", bsr_cfg.periodic_timer, bsr_cfg.retx_timer); + logger.warning("Not handling BSR config yet"); } void mac_nr::set_config(const srslte::sr_cfg_t& sr_cfg) { - Info("Scheduling Request Config DSR tansmax %d", sr_cfg.dsr_transmax); - Warning("Not Scheduling Request Config yet"); + logger.info("Scheduling Request Config DSR tansmax %d", sr_cfg.dsr_transmax); + logger.warning("Not Scheduling Request Config yet"); } void mac_nr::get_metrics(mac_metrics_t m[SRSLTE_MAX_CARRIERS]) {} @@ -235,14 +274,14 @@ void mac_nr::process_pdus() void mac_nr::handle_pdu(srslte::unique_byte_buffer_t pdu) { - log_h->info_hex(pdu->msg, pdu->N_bytes, "Handling MAC PDU (%d B)", pdu->N_bytes); + logger.info(pdu->msg, pdu->N_bytes, "Handling MAC PDU (%d B)", pdu->N_bytes); rx_pdu.init_rx(); rx_pdu.unpack(pdu->msg, pdu->N_bytes); for (uint32_t i = 0; i < rx_pdu.get_num_subpdus(); ++i) { srslte::mac_sch_subpdu_nr subpdu = rx_pdu.get_subpdu(i); - log_h->info("Handling subPDU %d/%d: lcid=%d, sdu_len=%d", + logger.info("Handling subPDU %d/%d: lcid=%d, sdu_len=%d", i, rx_pdu.get_num_subpdus(), subpdu.get_lcid(),