mac,phy: refactor NR MAC/PHY UL data passing interface

inspired by accepted (but not yet merged) PR to include the
(unique_)byte_buffer_t for MAC/PHY interfacing, this patch adds
a few more useful bits to that. Buffer management for UL data is now
done in MAC and only a pointer to the data is passed in the UL action.

* Move Tx softbuffer to MAC (until UL HARQ class is ready)
* Remove temparal data member in cc_worker
* Remove memcpy after packing MAC PDU
master
Andre Puschmann 4 years ago
parent fc9d5befda
commit 9c4146442a

@ -46,6 +46,19 @@ public:
uint32_t tbs;
} mac_nr_grant_ul_t;
/// For UL, payload buffer remains in MAC
typedef struct {
bool enabled;
uint32_t rv;
srslte::byte_buffer_t* payload;
srslte_softbuffer_tx_t* softbuffer;
} tb_ul_t;
/// Struct provided by MAC with all necessary information for PHY
typedef struct {
tb_ul_t tb; // only single TB in UL
} tb_action_ul_t;
virtual int sf_indication(const uint32_t tti) = 0; ///< FIXME: rename to slot indication
// Query the MAC for the current RNTI to look for
@ -59,10 +72,16 @@ public:
/// Indicate succussfully received TB to MAC. The TB buffer is allocated in the PHY and handed as unique_ptr to MAC
virtual void tb_decoded(const uint32_t cc_idx, mac_nr_grant_dl_t& grant) = 0;
/// Indicate reception of UL grant (only TBS is provided). Buffer for resulting MAC PDU is provided by MAC and is
/// passed as pointer to PHY during tx_reuqest
virtual void
new_grant_ul(const uint32_t cc_idx, const mac_nr_grant_ul_t& grant, srslte::byte_buffer_t* phy_tx_pdu) = 0;
/**
* @brief Indicate reception of UL grant to MAC
*
* Buffer for resulting MAC PDU is provided and managed (owned) by MAC and is passed as pointer in ul_action
*
* @param cc_idx The carrier index on which the grant has been received
* @param grant Reference to the grant
* @param action Pointer to the TB action to be filled by MAC
*/
virtual void new_grant_ul(const uint32_t cc_idx, const mac_nr_grant_ul_t& grant, tb_action_ul_t* action) = 0;
/**
* @brief Indicate the successful transmission of a PRACH.

@ -217,8 +217,9 @@ int srslte_basic_vnf::handle_ul_ind(basic_vnf_api::ul_ind_msg_t* msg)
ul_grant.tti = msg->tti;
ul_grant.tbs = msg->pdus.length;
ul_grant.rnti = msg->rnti;
srslte::unique_byte_buffer_t tx_pdu = srslte::make_byte_buffer();
m_ue_stack->new_grant_ul(cc_idx, ul_grant, tx_pdu.get());
srsue::stack_interface_phy_nr::tb_action_ul_t ul_action = {};
m_ue_stack->new_grant_ul(cc_idx, ul_grant, &ul_action);
return SRSLTE_SUCCESS;
}

@ -51,9 +51,7 @@ private:
srslog::basic_logger& logger;
// Temporal attributes
srslte_softbuffer_tx_t softbuffer_tx = {};
srslte_softbuffer_rx_t softbuffer_rx = {};
std::vector<uint8_t> tx_data;
// Methods for DL...
void decode_pdcch_ul();

@ -50,7 +50,7 @@ public:
int sf_indication(const uint32_t tti);
void tb_decoded(const uint32_t cc_idx, mac_nr_grant_dl_t& grant);
void new_grant_ul(const uint32_t cc_idx, const mac_nr_grant_ul_t& grant, srslte::byte_buffer_t* tx_pdu);
void new_grant_ul(const uint32_t cc_idx, const mac_nr_grant_ul_t& grant, tb_action_ul_t* action);
void prach_sent(const uint32_t tti,
const uint32_t s_id,
const uint32_t t_id,
@ -134,6 +134,7 @@ private:
srslte::mac_sch_pdu_nr tx_pdu;
srslte::unique_byte_buffer_t tx_buffer = nullptr;
srslte::unique_byte_buffer_t rlc_buffer = nullptr;
srslte_softbuffer_tx_t softbuffer_tx = {}; /// UL HARQ (temporal)
srslte::task_multiqueue::queue_handle stack_task_dispatch_queue;

@ -91,7 +91,7 @@ public:
sched_rnti_t get_dl_sched_rnti_nr(uint32_t tti) final { return mac_nr.get_dl_sched_rnti_nr(tti); }
sched_rnti_t get_ul_sched_rnti_nr(uint32_t tti) final { return mac_nr.get_ul_sched_rnti_nr(tti); }
void new_grant_ul(uint32_t cc_idx, mac_grant_ul_t grant, tb_action_ul_t* action) final
void new_grant_ul(uint32_t cc_idx, mac_grant_ul_t grant, mac_interface_phy_lte::tb_action_ul_t* action) final
{
mac.new_grant_ul(cc_idx, grant, action);
}
@ -126,7 +126,12 @@ public:
int sf_indication(const uint32_t tti) final { return SRSLTE_SUCCESS; }
void tb_decoded(const uint32_t cc_idx, mac_nr_grant_dl_t& grant) final { mac_nr.tb_decoded(cc_idx, grant); }
void new_grant_ul(const uint32_t cc_idx, const mac_nr_grant_ul_t& grant, srslte::byte_buffer_t* tx_pdu) final { mac_nr.new_grant_ul(cc_idx, grant, tx_pdu); }
void new_grant_ul(const uint32_t cc_idx,
const mac_nr_grant_ul_t& grant,
mac_interface_phy_nr::tb_action_ul_t* action) final
{
mac_nr.new_grant_ul(cc_idx, grant, action);
}
void run_tti(const uint32_t tti) final
{

@ -82,7 +82,10 @@ public:
return SRSLTE_SUCCESS;
}
void tb_decoded(const uint32_t cc_idx, mac_nr_grant_dl_t& grant) final { mac->tb_decoded(cc_idx, grant); }
void new_grant_ul(const uint32_t cc_idx, const mac_nr_grant_ul_t& grant, srslte::byte_buffer_t* phy_tx_pdu) final { mac->new_grant_ul(cc_idx, grant, phy_tx_pdu); }
void new_grant_ul(const uint32_t cc_idx, const mac_nr_grant_ul_t& grant, tb_action_ul_t* action) final
{
mac->new_grant_ul(cc_idx, grant, action);
}
void prach_sent(uint32_t tti, uint32_t s_id, uint32_t t_id, uint32_t f_id, uint32_t ul_carrier_id)
{
mac->prach_sent(tti, s_id, t_id, f_id, ul_carrier_id);

@ -38,23 +38,11 @@ cc_worker::cc_worker(uint32_t cc_idx_, srslog::basic_logger& log, state* phy_sta
return;
}
if (srslte_softbuffer_tx_init_guru(&softbuffer_tx, SRSLTE_SCH_NR_MAX_NOF_CB_LDPC, SRSLTE_LDPC_MAX_LEN_ENCODED_CB) <
SRSLTE_SUCCESS) {
ERROR("Error init soft-buffer");
return;
}
if (srslte_softbuffer_rx_init_guru(&softbuffer_rx, SRSLTE_SCH_NR_MAX_NOF_CB_LDPC, SRSLTE_LDPC_MAX_LEN_ENCODED_CB) <
SRSLTE_SUCCESS) {
ERROR("Error init soft-buffer");
return;
}
// Initialise data with numbers
tx_data.resize(SRSLTE_SCH_NR_MAX_NOF_CB_LDPC * SRSLTE_LDPC_MAX_LEN_ENCODED_CB / 8);
for (uint32_t i = 0; i < SRSLTE_SCH_NR_MAX_NOF_CB_LDPC * SRSLTE_LDPC_MAX_LEN_ENCODED_CB / 8; i++) {
tx_data[i] = i % 255U;
}
}
cc_worker::~cc_worker()
@ -282,22 +270,20 @@ bool cc_worker::work_ul()
if (has_pusch_grant) {
// Notify MAC about PUSCH found grant
mac_interface_phy_nr::tb_action_ul_t ul_action = {};
mac_interface_phy_nr::mac_nr_grant_ul_t mac_ul_grant = {};
mac_ul_grant.pid = pid;
mac_ul_grant.rnti = pusch_cfg.grant.rnti;
mac_ul_grant.tti = ul_slot_cfg.idx;
mac_ul_grant.tbs = pusch_cfg.grant.tb[0].tbs;
srslte::unique_byte_buffer_t tx_pdu = srslte::make_byte_buffer();
phy->stack->new_grant_ul(0, mac_ul_grant, tx_pdu.get());
// Provisional reset and assign Tx softbuffer
srslte_softbuffer_tx_reset(&softbuffer_tx);
pusch_cfg.grant.tb[0].softbuffer.tx = &softbuffer_tx;
// TODO: Use here PDU, after that, remove tx_data attribute
uint8_t* tx_data_ptr = tx_pdu.get()->msg;
phy->stack->new_grant_ul(0, mac_ul_grant, &ul_action);
// Assignning MAC provided values to PUSCH config structs
pusch_cfg.grant.tb[0].softbuffer.tx = ul_action.tb.softbuffer;
// Encode PUSCH transmission
if (srslte_ue_ul_nr_encode_pusch(&ue_ul, &ul_slot_cfg, &pusch_cfg, tx_data_ptr) < SRSLTE_SUCCESS) {
if (srslte_ue_ul_nr_encode_pusch(&ue_ul, &ul_slot_cfg, &pusch_cfg, ul_action.tb.payload->msg) < SRSLTE_SUCCESS) {
ERROR("Encoding PUSCH");
return false;
}
@ -306,7 +292,7 @@ bool cc_worker::work_ul()
if (logger.info.enabled()) {
std::array<char, 512> str;
srslte_ue_ul_nr_pusch_info(&ue_ul, &pusch_cfg, str.data(), str.size());
logger.info(tx_data_ptr,
logger.info(ul_action.tb.payload->msg,
pusch_cfg.grant.tb[0].tbs / 8,
"PUSCH (NR): cc=%d, %s, tti_tx=%d",
cc_idx,

@ -47,6 +47,12 @@ int mac_nr::init(const mac_nr_args_t& args_, phy_interface_mac_nr* phy_, rlc_int
mux.init();
if (srslte_softbuffer_tx_init_guru(&softbuffer_tx, SRSLTE_SCH_NR_MAX_NOF_CB_LDPC, SRSLTE_LDPC_MAX_LEN_ENCODED_CB) <
SRSLTE_SUCCESS) {
ERROR("Error init soft-buffer");
return SRSLTE_ERROR;
}
started = true;
return SRSLTE_SUCCESS;
@ -200,13 +206,22 @@ void mac_nr::tb_decoded(const uint32_t cc_idx, mac_nr_grant_dl_t& grant)
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, srslte::byte_buffer_t* phy_tx_pdu)
void mac_nr::new_grant_ul(const uint32_t cc_idx, const mac_nr_grant_ul_t& grant, tb_action_ul_t* action)
{
// if proc ra is in contention resolution and c_rnti == grant.c_rnti resolve contention resolution
if (proc_ra.is_contention_resolution() && grant.rnti == c_rnti) {
proc_ra.pdcch_to_crnti();
}
get_ul_data(grant, phy_tx_pdu);
// fill TB action (goes into UL harq eventually)
action->tb.payload = tx_buffer.get();
action->tb.enabled = true;
action->tb.rv = 0;
action->tb.softbuffer = &softbuffer_tx;
srslte_softbuffer_tx_reset(&softbuffer_tx);
// Pack MAC PDU
get_ul_data(grant, action->tb.payload);
metrics[cc_idx].tx_pkts++;
}
@ -214,8 +229,8 @@ void mac_nr::new_grant_ul(const uint32_t cc_idx, const mac_nr_grant_ul_t& grant,
void mac_nr::get_ul_data(const mac_nr_grant_ul_t& grant, srslte::byte_buffer_t* phy_tx_pdu)
{
// initialize MAC PDU
tx_buffer->clear();
tx_pdu.init_tx(tx_buffer.get(), grant.tbs / 8U, true);
phy_tx_pdu->clear();
tx_pdu.init_tx(phy_tx_pdu, grant.tbs / 8U, true);
if (mux.msg3_is_pending()) {
// If message 3 is pending pack message 3 for uplink transmission
@ -254,13 +269,10 @@ void mac_nr::get_ul_data(const mac_nr_grant_ul_t& grant, srslte::byte_buffer_t*
// Pack PDU
tx_pdu.pack();
logger.info(tx_buffer->msg, tx_buffer->N_bytes, "Generated MAC PDU (%d B)", tx_buffer->N_bytes);
memcpy(phy_tx_pdu->msg, tx_buffer->msg, tx_buffer->N_bytes);
phy_tx_pdu->N_bytes = tx_buffer->N_bytes;
logger.info(phy_tx_pdu->msg, phy_tx_pdu->N_bytes, "Generated MAC PDU (%d B)", phy_tx_pdu->N_bytes);
if (pcap) {
pcap->write_ul_crnti_nr(tx_buffer->msg, tx_buffer->N_bytes, grant.rnti, grant.pid, grant.tti);
pcap->write_ul_crnti_nr(phy_tx_pdu->msg, phy_tx_pdu->N_bytes, grant.rnti, grant.pid, grant.tti);
}
}

Loading…
Cancel
Save