using an interface between the stack and lower mac to process demux pdus.

master
Francisco Paisana 5 years ago committed by Andre Puschmann
parent 57317fab7c
commit 946ead06e8

@ -630,6 +630,13 @@ class gw_interface_stack : public gw_interface_nas, public gw_interface_rrc, pub
{
};
// STACK interface for MAC
class stack_interface_mac
{
public:
virtual void process_pdus() = 0;
};
// Combined interface for PHY to access stack (MAC and RRC)
class stack_interface_phy_lte : public mac_interface_phy_lte, public rrc_interface_phy_lte
{

@ -51,7 +51,11 @@ class mac : public mac_interface_phy_lte,
public:
mac(srslte::log* log_);
~mac();
bool init(phy_interface_mac_lte* phy, rlc_interface_mac* rlc, rrc_interface_mac* rrc, srslte::timers* timers_);
bool init(phy_interface_mac_lte* phy,
rlc_interface_mac* rlc,
rrc_interface_mac* rrc,
srslte::timers* timers_,
stack_interface_mac* stack);
void stop();
void get_metrics(mac_metrics_t m[SRSLTE_MAX_CARRIERS]);
@ -95,9 +99,11 @@ public:
void start_noncont_ho(uint32_t preamble_index, uint32_t prach_mask);
void start_cont_ho();
void get_rntis(ue_rnti_t *rntis);
void get_rntis(ue_rnti_t* rntis);
void set_ho_rnti(uint16_t crnti, uint16_t target_pci);
void process_pdus();
void start_pcap(srslte::mac_pcap* pcap);
// Timer callback interface
@ -118,11 +124,12 @@ private:
static const int MAC_MAIN_THREAD_PRIO = -1; // Use default high-priority below UHD
static const int MAC_PDU_THREAD_PRIO = 5;
// Interaction with PHY
phy_interface_mac_lte *phy_h;
rlc_interface_mac *rlc_h;
rrc_interface_mac *rrc_h;
srslte::log *log_h;
// Interaction with PHY
phy_interface_mac_lte* phy_h = nullptr;
rlc_interface_mac* rlc_h = nullptr;
rrc_interface_mac* rrc_h = nullptr;
stack_interface_mac* stack_h = nullptr;
srslte::log* log_h;
mac_interface_phy_lte::mac_phy_cfg_mbsfn_t phy_mbsfn_cfg;
// RNTI search window scheduling
@ -172,23 +179,6 @@ private:
mac_metrics_t metrics[SRSLTE_MAX_CARRIERS] = {};
bool initialized = false;
/* Class to process MAC PDUs from DEMUX unit */
class pdu_process : public thread {
public:
explicit pdu_process(demux* demux_unit);
~pdu_process();
void notify();
void stop();
private:
void run_thread() final;
bool running = false;
bool have_data = false;
std::mutex mutex;
std::condition_variable cvar;
demux* demux_unit = nullptr;
};
pdu_process pdu_process_thread;
};
} // namespace srsue

@ -52,6 +52,7 @@ namespace srsue {
class ue_stack_lte final : public ue_stack_base,
public stack_interface_phy_lte,
public stack_interface_gw,
public stack_interface_mac,
public thread
{
public:
@ -111,6 +112,9 @@ public:
bool is_lcid_enabled(uint32_t lcid) final { return pdcp.is_lcid_enabled(lcid); }
// Interface to upper MAC
void process_pdus() final;
private:
void run_thread() final;
void run_tti_impl(uint32_t tti);
@ -158,7 +162,7 @@ private:
void operator()() { func(this); }
};
srslte::multiqueue_handler<task_t> pending_tasks;
int sync_queue_id = -1, ue_queue_id = -1, gw_queue_id = -1;
int sync_queue_id = -1, ue_queue_id = -1, gw_queue_id = -1, mac_queue_id = -1;
};
} // namespace srsue

@ -37,13 +37,7 @@ using namespace asn1::rrc;
namespace srsue {
mac::mac(srslte::log* log_) :
pdu_process_thread(&demux_unit),
mch_msg(10, log_),
mux_unit(log_),
demux_unit(log_),
pcap(nullptr),
log_h(log_)
mac::mac(srslte::log* log_) : mch_msg(10, log_), mux_unit(log_), demux_unit(log_), pcap(nullptr), log_h(log_)
{
// Create PCell HARQ entities
auto ul = ul_harq_entity_ptr(new ul_harq_entity());
@ -71,12 +65,17 @@ mac::~mac()
srslte_softbuffer_rx_free(&mch_softbuffer);
}
bool mac::init(phy_interface_mac_lte* phy, rlc_interface_mac* rlc, rrc_interface_mac* rrc, srslte::timers* timers_)
bool mac::init(phy_interface_mac_lte* phy,
rlc_interface_mac* rlc,
rrc_interface_mac* rrc,
srslte::timers* timers_,
stack_interface_mac* stack_)
{
phy_h = phy;
rlc_h = rlc;
rrc_h = rrc;
timers = timers_;
phy_h = phy;
rlc_h = rlc;
rrc_h = rrc;
timers = timers_;
stack_h = stack_;
timer_alignment = timers->get_unique_id();
uint32_t contention_resolution_timer = timers->get_unique_id();
@ -107,7 +106,6 @@ bool mac::init(phy_interface_mac_lte* phy, rlc_interface_mac* rlc, rrc_interface
void mac::stop()
{
if (initialized) {
pdu_process_thread.stop();
run_tti(0); // make sure it's not locked after last TTI
initialized = false;
}
@ -388,7 +386,7 @@ void mac::mch_decoded(uint32_t len, bool crc)
}
demux_unit.push_pdu_mch(mch_payload_buffer, len);
pdu_process_thread.notify();
stack_h->process_pdus();
if (pcap) {
pcap->write_dl_mch(mch_payload_buffer, len, true, phy_h->get_current_tti());
}
@ -415,7 +413,7 @@ void mac::tb_decoded(uint32_t cc_idx, mac_grant_dl_t grant, bool ack[SRSLTE_MAX_
} else {
dl_harq.at(cc_idx)->tb_decoded(grant, ack);
pdu_process_thread.notify();
stack_h->process_pdus();
for (uint32_t tb = 0; tb < SRSLTE_MAX_CODEWORDS; tb++) {
if (grant.tb[tb].tbs) {
@ -461,6 +459,14 @@ void mac::new_grant_dl(uint32_t cc_idx,
}
}
void mac::process_pdus()
{
bool have_data = true;
while (initialized and have_data) {
have_data = demux_unit.process_pdus();
}
}
uint32_t mac::get_current_tti()
{
return phy_h->get_current_tti();
@ -619,9 +625,7 @@ void mac::get_metrics(mac_metrics_t m[SRSLTE_MAX_CARRIERS])
int rx_brate = 0;
int ul_buffer = 0;
float dl_avg_ret = 0;
float ul_avg_ret = 0;
int dl_avg_ret_count = 0;
int ul_avg_ret_count = 0;
for (uint32_t r = 0; r < dl_harq.size(); r++) {
tx_pkts += metrics[r].tx_pkts;
@ -674,58 +678,4 @@ uint32_t mac::timer_get_unique_id()
return timers->get_unique_id();
}
/********************************************************
*
* Class that runs a thread to process DL MAC PDUs from
* DEMUX unit
*
*******************************************************/
mac::pdu_process::pdu_process(demux* demux_unit_) : thread("MAC_PDU_PROCESS"), demux_unit(demux_unit_)
{
running = true;
start(MAC_PDU_THREAD_PRIO);
}
mac::pdu_process::~pdu_process()
{
if (running) {
stop();
}
}
void mac::pdu_process::stop()
{
if (running) {
{
std::lock_guard<std::mutex> ul(mutex);
running = false;
cvar.notify_all();
}
wait_thread_finish();
}
}
void mac::pdu_process::notify()
{
std::unique_lock<std::mutex> ul(mutex);
have_data = true;
cvar.notify_all();
}
void mac::pdu_process::run_thread()
{
while(running) {
have_data = demux_unit->process_pdus();
if (!have_data) {
std::unique_lock<std::mutex> ul(mutex);
while(!have_data && running) {
cvar.wait(ul);
}
}
}
}
}
} // namespace srsue

@ -44,6 +44,7 @@ ue_stack_lte::ue_stack_lte() :
ue_queue_id = pending_tasks.add_queue();
sync_queue_id = pending_tasks.add_queue();
gw_queue_id = pending_tasks.add_queue();
mac_queue_id = pending_tasks.add_queue();
}
ue_stack_lte::~ue_stack_lte()
@ -119,7 +120,7 @@ int ue_stack_lte::init(const stack_args_t& args_, srslte::logger* logger_)
return SRSLTE_ERROR;
}
mac.init(phy, &rlc, &rrc, &timers);
mac.init(phy, &rlc, &rrc, &timers, this);
rlc.init(&pdcp, &rrc, &timers, 0 /* RB_ID_SRB0 */);
pdcp.init(&rlc, &rrc, gw);
nas.init(usim.get(), &rrc, gw, args.nas);
@ -269,4 +270,13 @@ void ue_stack_lte::run_tti_impl(uint32_t tti)
timers.step_all();
}
/********************
* low MAC Interface
*******************/
void ue_stack_lte::process_pdus()
{
pending_tasks.push(mac_queue_id, task_t{[this](task_t*) { mac.process_pdus(); }});
}
} // namespace srsue

@ -326,6 +326,11 @@ public:
uint32_t rach_problem = 0;
};
class stack_dummy : public stack_interface_mac
{
void process_pdus() final {}
};
} // namespace srslte
int mac_unpack_test()
@ -358,13 +363,14 @@ int mac_unpack_test()
rlc_log.set_hex_limit(100000);
// dummy layers
phy_dummy phy;
rlc_dummy rlc(&rlc_log);
rrc_dummy rrc;
phy_dummy phy;
rlc_dummy rlc(&rlc_log);
rrc_dummy rrc;
stack_dummy stack;
// the actual MAC
mac mac(&mac_log);
mac.init(&phy, &rlc, &rrc, &timers);
mac.init(&phy, &rlc, &rrc, &timers, &stack);
// create dummy DL action and grant and push MAC PDU
mac_interface_phy_lte::tb_action_dl_t dl_action;
@ -415,13 +421,14 @@ int mac_ul_sch_pdu_test1()
srslte::timers timers(64);
// dummy layers
phy_dummy phy;
rlc_dummy rlc(&rlc_log);
rrc_dummy rrc;
phy_dummy phy;
rlc_dummy rlc(&rlc_log);
rrc_dummy rrc;
stack_dummy stack;
// the actual MAC
mac mac(&mac_log);
mac.init(&phy, &rlc, &rrc, &timers);
mac.init(&phy, &rlc, &rrc, &timers, &stack);
const uint16_t crnti = 0x1001;
mac.set_ho_rnti(crnti, 0);
@ -483,13 +490,14 @@ int mac_ul_logical_channel_prioritization_test1()
srslte::timers timers(64);
// dummy layers
phy_dummy phy;
rlc_dummy rlc(&rlc_log);
rrc_dummy rrc;
phy_dummy phy;
rlc_dummy rlc(&rlc_log);
rrc_dummy rrc;
stack_dummy stack;
// the actual MAC
mac mac(&mac_log);
mac.init(&phy, &rlc, &rrc, &timers);
mac.init(&phy, &rlc, &rrc, &timers, &stack);
const uint16_t crnti = 0x1001;
mac.set_ho_rnti(crnti, 0);
@ -596,13 +604,14 @@ int mac_ul_logical_channel_prioritization_test2()
srslte::timers timers(64);
// dummy layers
phy_dummy phy;
rlc_dummy rlc(&rlc_log);
rrc_dummy rrc;
phy_dummy phy;
rlc_dummy rlc(&rlc_log);
rrc_dummy rrc;
stack_dummy stack;
// the actual MAC
mac mac(&mac_log);
mac.init(&phy, &rlc, &rrc, &timers);
mac.init(&phy, &rlc, &rrc, &timers, &stack);
const uint16_t crnti = 0x1001;
mac.set_ho_rnti(crnti, 0);
@ -696,13 +705,14 @@ int mac_ul_logical_channel_prioritization_test3()
srslte::timers timers(64);
// dummy layers
phy_dummy phy;
rlc_dummy rlc(&rlc_log);
rrc_dummy rrc;
phy_dummy phy;
rlc_dummy rlc(&rlc_log);
rrc_dummy rrc;
stack_dummy stack;
// the actual MAC
mac mac(&mac_log);
mac.init(&phy, &rlc, &rrc, &timers);
mac.init(&phy, &rlc, &rrc, &timers, &stack);
const uint16_t crnti = 0x1001;
mac.set_ho_rnti(crnti, 0);
@ -784,13 +794,14 @@ int mac_ul_sch_pdu_with_short_bsr_test()
srslte::timers timers(64);
// dummy layers
phy_dummy phy;
rlc_dummy rlc(&rlc_log);
rrc_dummy rrc;
phy_dummy phy;
rlc_dummy rlc(&rlc_log);
rrc_dummy rrc;
stack_dummy stack;
// the actual MAC
mac mac(&mac_log);
mac.init(&phy, &rlc, &rrc, &timers);
mac.init(&phy, &rlc, &rrc, &timers, &stack);
const uint16_t crnti = 0x1001;
mac.set_ho_rnti(crnti, 0);
@ -870,13 +881,14 @@ int mac_ul_sch_pdu_with_padding_bsr_test()
srslte::timers timers(64);
// dummy layers
phy_dummy phy;
rlc_dummy rlc(&rlc_log);
rrc_dummy rrc;
phy_dummy phy;
rlc_dummy rlc(&rlc_log);
rrc_dummy rrc;
stack_dummy stack;
// the actual MAC
mac mac(&mac_log);
mac.init(&phy, &rlc, &rrc, &timers);
mac.init(&phy, &rlc, &rrc, &timers, &stack);
const uint16_t crnti = 0x1001;
mac.set_ho_rnti(crnti, 0);
@ -965,13 +977,14 @@ int mac_ul_sch_pdu_one_byte_test()
srslte::timers timers(64);
// dummy layers
phy_dummy phy;
rlc_dummy rlc(&rlc_log);
rrc_dummy rrc;
phy_dummy phy;
rlc_dummy rlc(&rlc_log);
rrc_dummy rrc;
stack_dummy stack;
// the actual MAC
mac mac(&mac_log);
mac.init(&phy, &rlc, &rrc, &timers);
mac.init(&phy, &rlc, &rrc, &timers, &stack);
const uint16_t crnti = 0x1001;
mac.set_ho_rnti(crnti, 0);
@ -1025,13 +1038,14 @@ int mac_ul_sch_pdu_two_byte_test()
srslte::timers timers(64);
// dummy layers
phy_dummy phy;
rlc_dummy rlc(&rlc_log);
rrc_dummy rrc;
phy_dummy phy;
rlc_dummy rlc(&rlc_log);
rrc_dummy rrc;
stack_dummy stack;
// the actual MAC
mac mac(&mac_log);
mac.init(&phy, &rlc, &rrc, &timers);
mac.init(&phy, &rlc, &rrc, &timers, &stack);
const uint16_t crnti = 0x1001;
mac.set_ho_rnti(crnti, 0);
@ -1085,13 +1099,14 @@ int mac_ul_sch_pdu_three_byte_test()
srslte::timers timers(64);
// dummy layers
phy_dummy phy;
rlc_dummy rlc(&rlc_log);
rrc_dummy rrc;
phy_dummy phy;
rlc_dummy rlc(&rlc_log);
rrc_dummy rrc;
stack_dummy stack;
// the actual MAC
mac mac(&mac_log);
mac.init(&phy, &rlc, &rrc, &timers);
mac.init(&phy, &rlc, &rrc, &timers, &stack);
const uint16_t crnti = 0x1001;
mac.set_ho_rnti(crnti, 0);
@ -1329,11 +1344,12 @@ int mac_random_access_test()
// dummy layers
phy_dummy phy;
phy.set_log(&phy_log);
rlc_dummy rlc(&rlc_log);
rrc_dummy rrc;
rlc_dummy rlc(&rlc_log);
rrc_dummy rrc;
stack_dummy stack;
// Configure default RACH parameters
asn1::rrc::rach_cfg_common_s rach_cfg = {};
asn1::rrc::rach_cfg_common_s rach_cfg = {};
rach_cfg.preamb_info.nof_ra_preambs = asn1::rrc::rach_cfg_common_s::preamb_info_s_::nof_ra_preambs_opts::n12;
rach_cfg.ra_supervision_info.preamb_trans_max = asn1::rrc::preamb_trans_max_opts::n8;
rach_cfg.ra_supervision_info.ra_resp_win_size =
@ -1344,7 +1360,7 @@ int mac_random_access_test()
// Configure MAC
mac mac(&mac_log);
mac.init(&phy, &rlc, &rrc, &timers);
mac.init(&phy, &rlc, &rrc, &timers, &stack);
srslte::mac_cfg_t mac_cfg;
set_mac_cfg_t_rach_cfg_common(&mac_cfg, rach_cfg);
mac.set_config(mac_cfg);

Loading…
Cancel
Save