|
|
|
@ -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(),
|
|
|
|
|