From 67d6a25194deabdabf2cb8e71c43aeddbd4f9f29 Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Wed, 4 Sep 2019 14:28:09 +0100 Subject: [PATCH] Moving mac timers to stack timers (#638) * first step towards moving MAC timers to stack. Mac is still using its own timers. srslte::timers class can be restructured. * moved timers out of the UE MAC --- lib/include/srslte/common/timers.h | 15 +-- lib/include/srslte/upper/rlc.h | 11 +- lib/include/srslte/upper/rlc_am.h | 25 ++-- lib/include/srslte/upper/rlc_tm.h | 12 +- lib/include/srslte/upper/rlc_um.h | 24 ++-- lib/src/upper/rlc.cc | 18 +-- lib/src/upper/rlc_am.cc | 40 +++--- lib/src/upper/rlc_tm.cc | 12 +- lib/src/upper/rlc_um.cc | 24 ++-- lib/test/upper/rlc_am_test.cc | 107 +++++++--------- lib/test/upper/rlc_common_test.cc | 16 +-- lib/test/upper/rlc_stress_test.cc | 35 ++---- lib/test/upper/rlc_um_test.cc | 56 +++------ srsenb/hdr/stack/enb_stack_lte.h | 7 +- srsenb/hdr/stack/upper/rlc.h | 22 ++-- srsenb/src/stack/enb_stack_lte.cc | 4 +- srsenb/src/stack/upper/rlc.cc | 27 ++-- srsepc/hdr/mme/mme.h | 2 +- srsepc/src/mme/mme.cc | 16 +-- srsue/hdr/stack/mac/mac.h | 4 +- srsue/hdr/stack/rrc/rrc.h | 34 ++--- srsue/hdr/stack/ue_stack_lte.h | 3 + srsue/src/stack/mac/mac.cc | 45 +++---- srsue/src/stack/rrc/rrc.cc | 175 ++++++++++++-------------- srsue/src/stack/rrc/rrc_procedures.cc | 10 +- srsue/src/stack/ue_stack_lte.cc | 8 +- srsue/test/mac_test.cc | 80 ++++++++---- 27 files changed, 394 insertions(+), 438 deletions(-) diff --git a/lib/include/srslte/common/timers.h b/lib/include/srslte/common/timers.h index f2029acd1..a2f335107 100644 --- a/lib/include/srslte/common/timers.h +++ b/lib/include/srslte/common/timers.h @@ -93,14 +93,15 @@ public: timer_callback *callback; uint32_t timeout; uint32_t counter; - bool running; + bool running; }; - - timers(uint32_t nof_timers_) : timer_list(nof_timers_),used_timers(nof_timers_) { - nof_timers = nof_timers_; - next_timer = 0; + + timers(uint32_t nof_timers_) : timer_list(nof_timers_), used_timers(nof_timers_) + { + nof_timers = nof_timers_; + next_timer = 0; nof_used_timers = 0; - for (uint32_t i=0;i rlc_map_t; + typedef std::map rlc_map_t; typedef std::pair rlc_map_pair_t; rlc_map_t rlc_array, rlc_array_mrb; diff --git a/lib/include/srslte/upper/rlc_am.h b/lib/include/srslte/upper/rlc_am.h index e41a3d70a..be7e223e3 100644 --- a/lib/include/srslte/upper/rlc_am.h +++ b/lib/include/srslte/upper/rlc_am.h @@ -64,12 +64,11 @@ struct rlc_amd_retx_t{ class rlc_am : public rlc_common { public: - rlc_am(srslte::log* log_, - uint32_t lcid_, - srsue::pdcp_interface_rlc* pdcp_, - srsue::rrc_interface_rlc* rrc_, - srslte::mac_interface_timers* mac_timers_); - ~rlc_am(); + rlc_am(srslte::log* log_, + uint32_t lcid_, + srsue::pdcp_interface_rlc* pdcp_, + srsue::rrc_interface_rlc* rrc_, + srslte::timers* timers_); bool configure(rlc_config_t cfg_); void reestablish(); void stop(); @@ -276,13 +275,13 @@ private: }; // Common variables needed/provided by parent class - srsue::rrc_interface_rlc* rrc = nullptr; - srslte::log* log = nullptr; - srsue::pdcp_interface_rlc* pdcp = nullptr; - mac_interface_timers* mac_timers = nullptr; - uint32_t lcid = 0; - rlc_config_t cfg = {}; - std::string rb_name; + srsue::rrc_interface_rlc* rrc = nullptr; + srslte::log* log = nullptr; + srsue::pdcp_interface_rlc* pdcp = nullptr; + srslte::timers* timers = nullptr; + uint32_t lcid = 0; + rlc_config_t cfg = {}; + std::string rb_name; static const int poll_periodicity = 8; // After how many data PDUs a status PDU shall be requested diff --git a/lib/include/srslte/upper/rlc_tm.h b/lib/include/srslte/upper/rlc_tm.h index 23dda1f82..4a39ec122 100644 --- a/lib/include/srslte/upper/rlc_tm.h +++ b/lib/include/srslte/upper/rlc_tm.h @@ -34,12 +34,12 @@ namespace srslte { class rlc_tm : public rlc_common { public: - rlc_tm(srslte::log* log_, - uint32_t lcid_, - srsue::pdcp_interface_rlc* pdcp_, - srsue::rrc_interface_rlc* rrc_, - srslte::mac_interface_timers* mac_timers_, - uint32_t queue_len = 16); + rlc_tm(srslte::log* log_, + uint32_t lcid_, + srsue::pdcp_interface_rlc* pdcp_, + srsue::rrc_interface_rlc* rrc_, + srslte::timers* timers_, + uint32_t queue_len = 16); ~rlc_tm(); bool configure(rlc_config_t cnfg); void stop(); diff --git a/lib/include/srslte/upper/rlc_um.h b/lib/include/srslte/upper/rlc_um.h index b40769147..3be20a831 100644 --- a/lib/include/srslte/upper/rlc_um.h +++ b/lib/include/srslte/upper/rlc_um.h @@ -47,7 +47,7 @@ public: uint32_t lcid_, srsue::pdcp_interface_rlc* pdcp_, srsue::rrc_interface_rlc* rrc_, - mac_interface_timers* mac_timers_); + srslte::timers* timers_); ~rlc_um(); bool configure(rlc_config_t cnfg); void reestablish(); @@ -128,14 +128,14 @@ private: // Receiver sub-class class rlc_um_rx : public timer_callback { public: - rlc_um_rx(srslte::log* log_, - uint32_t lcid_, - srsue::pdcp_interface_rlc* pdcp_, - srsue::rrc_interface_rlc* rrc_, - srslte::mac_interface_timers* mac_timers_); + rlc_um_rx(srslte::log* log_, + uint32_t lcid_, + srsue::pdcp_interface_rlc* pdcp_, + srsue::rrc_interface_rlc* rrc_, + srslte::timers* timers_); ~rlc_um_rx(); - void stop(); - void reestablish(); + void stop(); + void reestablish(); bool configure(rlc_config_t cfg, std::string rb_name); void handle_data_pdu(uint8_t *payload, uint32_t nof_bytes); void reassemble_rx_sdus(); @@ -150,10 +150,10 @@ private: private: void reset(); - byte_buffer_pool* pool = nullptr; - srslte::log* log = nullptr; - mac_interface_timers* mac_timers = nullptr; - std::string rb_name; + byte_buffer_pool* pool = nullptr; + srslte::log* log = nullptr; + srslte::timers* timers = nullptr; + std::string rb_name; /**************************************************************************** * Configurable parameters diff --git a/lib/src/upper/rlc.cc b/lib/src/upper/rlc.cc index f68273661..e1bf69b52 100644 --- a/lib/src/upper/rlc.cc +++ b/lib/src/upper/rlc.cc @@ -53,12 +53,12 @@ rlc::~rlc() void rlc::init(srsue::pdcp_interface_rlc* pdcp_, srsue::rrc_interface_rlc* rrc_, - mac_interface_timers* mac_timers_, + srslte::timers* timers_, uint32_t lcid_) { - pdcp = pdcp_; - rrc = rrc_; - mac_timers = mac_timers_; + pdcp = pdcp_; + rrc = rrc_; + timers = timers_; default_lcid = lcid_; gettimeofday(&metrics_time[1], NULL); @@ -384,13 +384,13 @@ void rlc::add_bearer(uint32_t lcid, rlc_config_t cnfg) if (not valid_lcid(lcid)) { switch (cnfg.rlc_mode) { case rlc_mode_t::tm: - rlc_entity = new rlc_tm(rlc_log, lcid, pdcp, rrc, mac_timers); + rlc_entity = new rlc_tm(rlc_log, lcid, pdcp, rrc, timers); break; case rlc_mode_t::am: - rlc_entity = new rlc_am(rlc_log, lcid, pdcp, rrc, mac_timers); + rlc_entity = new rlc_am(rlc_log, lcid, pdcp, rrc, timers); break; case rlc_mode_t::um: - rlc_entity = new rlc_um(rlc_log, lcid, pdcp, rrc, mac_timers); + rlc_entity = new rlc_um(rlc_log, lcid, pdcp, rrc, timers); break; default: rlc_log->error("Cannot add RLC entity - invalid mode\n"); @@ -428,10 +428,10 @@ unlock_and_exit: void rlc::add_bearer_mrb(uint32_t lcid) { pthread_rwlock_wrlock(&rwlock); - rlc_common *rlc_entity = NULL; + rlc_common* rlc_entity = NULL; if (not valid_lcid_mrb(lcid)) { - rlc_entity = new rlc_um(rlc_log, lcid, pdcp, rrc, mac_timers); + rlc_entity = new rlc_um(rlc_log, lcid, pdcp, rrc, timers); // configure and add to array if (not rlc_entity->configure(rlc_config_t::mch_config())) { rlc_log->error("Error configuring RLC entity\n."); diff --git a/lib/src/upper/rlc_am.cc b/lib/src/upper/rlc_am.cc index cf188cb92..4741e7802 100644 --- a/lib/src/upper/rlc_am.cc +++ b/lib/src/upper/rlc_am.cc @@ -32,25 +32,21 @@ namespace srslte { -rlc_am::rlc_am(srslte::log* log_, - uint32_t lcid_, - srsue::pdcp_interface_rlc* pdcp_, - srsue::rrc_interface_rlc* rrc_, - srslte::mac_interface_timers* mac_timers_) : +rlc_am::rlc_am(srslte::log* log_, + uint32_t lcid_, + srsue::pdcp_interface_rlc* pdcp_, + srsue::rrc_interface_rlc* rrc_, + srslte::timers* timers_) : log(log_), rrc(rrc_), pdcp(pdcp_), - mac_timers(mac_timers_), + timers(timers_), lcid(lcid_), tx(this), rx(this) { } -rlc_am::~rlc_am() -{ -} - // Applies new configuration. Must be just reestablished or initiated bool rlc_am::configure(rlc_config_t cfg_) { @@ -170,11 +166,11 @@ rlc_am::rlc_am_tx::rlc_am_tx(rlc_am* parent_) : log(parent_->log), pool(byte_buffer_pool::get_instance()) { - poll_retx_timer_id = parent->mac_timers->timer_get_unique_id(); - poll_retx_timer = parent->mac_timers->timer_get(poll_retx_timer_id); + poll_retx_timer_id = parent->timers->get_unique_id(); + poll_retx_timer = parent->timers->get(poll_retx_timer_id); - status_prohibit_timer_id = parent->mac_timers->timer_get_unique_id(); - status_prohibit_timer = parent->mac_timers->timer_get(status_prohibit_timer_id); + status_prohibit_timer_id = parent->timers->get_unique_id(); + status_prohibit_timer = parent->timers->get(status_prohibit_timer_id); pthread_mutex_init(&mutex, NULL); } @@ -182,10 +178,10 @@ rlc_am::rlc_am_tx::rlc_am_tx(rlc_am* parent_) : rlc_am::rlc_am_tx::~rlc_am_tx() { poll_retx_timer->stop(); - parent->mac_timers->timer_release_id(poll_retx_timer_id); + parent->timers->release_id(poll_retx_timer_id); status_prohibit_timer->stop(); - parent->mac_timers->timer_release_id(status_prohibit_timer_id); + parent->timers->release_id(status_prohibit_timer_id); pthread_mutex_destroy(&mutex); } @@ -225,11 +221,11 @@ void rlc_am::rlc_am_tx::stop() tx_enabled = false; - if (parent->mac_timers != NULL && poll_retx_timer != NULL) { + if (parent->timers != NULL && poll_retx_timer != NULL) { poll_retx_timer->stop(); } - if (parent->mac_timers != NULL && status_prohibit_timer != NULL) { + if (parent->timers != NULL && status_prohibit_timer != NULL) { status_prohibit_timer->stop(); } @@ -1124,8 +1120,8 @@ rlc_am::rlc_am_rx::rlc_am_rx(rlc_am* parent_) : pool(byte_buffer_pool::get_instance()), log(parent_->log) { - reordering_timer_id = parent->mac_timers->timer_get_unique_id(); - reordering_timer = parent->mac_timers->timer_get(reordering_timer_id); + reordering_timer_id = parent->timers->get_unique_id(); + reordering_timer = parent->timers->get(reordering_timer_id); pthread_mutex_init(&mutex, NULL); } @@ -1133,7 +1129,7 @@ rlc_am::rlc_am_rx::rlc_am_rx(rlc_am* parent_) : rlc_am::rlc_am_rx::~rlc_am_rx() { reordering_timer->stop(); - parent->mac_timers->timer_release_id(reordering_timer_id); + parent->timers->release_id(reordering_timer_id); pthread_mutex_destroy(&mutex); } @@ -1166,7 +1162,7 @@ void rlc_am::rlc_am_rx::stop() { pthread_mutex_lock(&mutex); - if (parent->mac_timers != NULL && reordering_timer != NULL) { + if (parent->timers != NULL && reordering_timer != NULL) { reordering_timer->stop(); } diff --git a/lib/src/upper/rlc_tm.cc b/lib/src/upper/rlc_tm.cc index 360db02bb..33099fc1d 100644 --- a/lib/src/upper/rlc_tm.cc +++ b/lib/src/upper/rlc_tm.cc @@ -23,12 +23,12 @@ namespace srslte { -rlc_tm::rlc_tm(srslte::log* log_, - uint32_t lcid_, - srsue::pdcp_interface_rlc* pdcp_, - srsue::rrc_interface_rlc* rrc_, - srslte::mac_interface_timers* mac_timers_, - uint32_t queue_len_) : +rlc_tm::rlc_tm(srslte::log* log_, + uint32_t lcid_, + srsue::pdcp_interface_rlc* pdcp_, + srsue::rrc_interface_rlc* rrc_, + srslte::timers* timers_, + uint32_t queue_len_) : ul_queue(queue_len_), log(log_), pdcp(pdcp_), diff --git a/lib/src/upper/rlc_um.cc b/lib/src/upper/rlc_um.cc index 79e3d74fd..2c33410ef 100644 --- a/lib/src/upper/rlc_um.cc +++ b/lib/src/upper/rlc_um.cc @@ -32,13 +32,13 @@ rlc_um::rlc_um(srslte::log* log_, uint32_t lcid_, srsue::pdcp_interface_rlc* pdcp_, srsue::rrc_interface_rlc* rrc_, - mac_interface_timers* mac_timers_) : + srslte::timers* timers_) : lcid(lcid_), pool(byte_buffer_pool::get_instance()), rrc(rrc_), log(log_), tx(log_), - rx(log_, lcid_, pdcp_, rrc_, mac_timers_) + rx(log_, lcid_, pdcp_, rrc_, timers_) { } @@ -479,34 +479,32 @@ void rlc_um::rlc_um_tx::debug_state() * Rx subclass implementation ***************************************************************************/ -rlc_um::rlc_um_rx::rlc_um_rx(srslte::log* log_, - uint32_t lcid_, - srsue::pdcp_interface_rlc* pdcp_, - srsue::rrc_interface_rlc* rrc_, - srslte::mac_interface_timers* mac_timers_) : +rlc_um::rlc_um_rx::rlc_um_rx(srslte::log* log_, + uint32_t lcid_, + srsue::pdcp_interface_rlc* pdcp_, + srsue::rrc_interface_rlc* rrc_, + srslte::timers* timers_) : pool(byte_buffer_pool::get_instance()), log(log_), pdcp(pdcp_), rrc(rrc_), - mac_timers(mac_timers_), + timers(timers_), lcid(lcid_) { - reordering_timer_id = mac_timers->timer_get_unique_id(); - reordering_timer = mac_timers->timer_get(reordering_timer_id); + reordering_timer_id = timers->get_unique_id(); + reordering_timer = timers->get(reordering_timer_id); pthread_mutex_init(&mutex, NULL); } - rlc_um::rlc_um_rx::~rlc_um_rx() { reordering_timer->stop(); - mac_timers->timer_release_id(reordering_timer_id); + timers->release_id(reordering_timer_id); pthread_mutex_destroy(&mutex); } - void rlc_um::rlc_um_rx::reestablish() { // try to reassemble any SDUs if possible diff --git a/lib/test/upper/rlc_am_test.cc b/lib/test/upper/rlc_am_test.cc index ea4ec4c09..51901e776 100644 --- a/lib/test/upper/rlc_am_test.cc +++ b/lib/test/upper/rlc_am_test.cc @@ -34,30 +34,7 @@ using namespace srsue; using namespace srslte; using namespace asn1::rrc; -class mac_dummy_timers - :public srslte::mac_interface_timers -{ -public: - mac_dummy_timers() : timers(8) {} - srslte::timers::timer* timer_get(uint32_t timer_id) { - return timers.get(timer_id); - } - void timer_release_id(uint32_t timer_id) { - timers.release_id(timer_id); - } - uint32_t timer_get_unique_id() { - return timers.get_unique_id(); - } - void step_all() { - timers.step_all(); - } -private: - srslte::timers timers; -}; - -class rlc_am_tester - :public pdcp_interface_rlc - ,public rrc_interface_rlc +class rlc_am_tester : public pdcp_interface_rlc, public rrc_interface_rlc { public: rlc_am_tester(rlc_pcap *pcap_ = NULL) @@ -162,9 +139,9 @@ bool basic_test() log1.set_hex_limit(-1); log2.set_hex_limit(-1); - rlc_am_tester tester; - mac_dummy_timers timers; - byte_buffer_t pdu_bufs[NBUFS]; + rlc_am_tester tester; + timers timers(8); + byte_buffer_t pdu_bufs[NBUFS]; rlc_am rlc1(&log1, 1, &tester, &tester, &timers); rlc_am rlc2(&log2, 1, &tester, &tester, &timers); @@ -222,8 +199,8 @@ bool concat_test() log2.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(-1); log2.set_hex_limit(-1); - rlc_am_tester tester; - mac_dummy_timers timers; + rlc_am_tester tester; + srslte::timers timers(8); rlc_am rlc1(&log1, 1, &tester, &tester, &timers); rlc_am rlc2(&log2, 1, &tester, &tester, &timers); @@ -287,9 +264,9 @@ bool segment_test(bool in_seq_rx) log2.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(-1); log2.set_hex_limit(-1); - rlc_am_tester tester; - mac_dummy_timers timers; - int len = 0; + rlc_am_tester tester; + srslte::timers timers(8); + int len = 0; rlc_am rlc1(&log1, 1, &tester, &tester, &timers); rlc_am rlc2(&log2, 1, &tester, &tester, &timers); @@ -381,9 +358,9 @@ bool retx_test() log2.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(-1); log2.set_hex_limit(-1); - rlc_am_tester tester; - mac_dummy_timers timers; - int len = 0; + rlc_am_tester tester; + timers timers(8); + int len = 0; rlc_am rlc1(&log1, 1, &tester, &tester, &timers); rlc_am rlc2(&log2, 1, &tester, &tester, &timers); @@ -475,9 +452,9 @@ bool resegment_test_1() log2.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(-1); log2.set_hex_limit(-1); - rlc_am_tester tester; - mac_dummy_timers timers; - int len = 0; + rlc_am_tester tester; + timers timers(8); + int len = 0; rlc_am rlc1(&log1, 1, &tester, &tester, &timers); rlc_am rlc2(&log2, 1, &tester, &tester, &timers); @@ -581,9 +558,9 @@ bool resegment_test_2() log2.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(-1); log2.set_hex_limit(-1); - rlc_am_tester tester; - mac_dummy_timers timers; - int len = 0; + rlc_am_tester tester; + timers timers(8); + int len = 0; rlc_am rlc1(&log1, 1, &tester, &tester, &timers); rlc_am rlc2(&log2, 1, &tester, &tester, &timers); @@ -684,8 +661,8 @@ bool resegment_test_3() log2.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(-1); log2.set_hex_limit(-1); - rlc_am_tester tester; - mac_dummy_timers timers; + rlc_am_tester tester; + srslte::timers timers(8); rlc_am rlc1(&log1, 1, &tester, &tester, &timers); rlc_am rlc2(&log2, 1, &tester, &tester, &timers); @@ -781,8 +758,8 @@ bool resegment_test_4() log2.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(-1); log2.set_hex_limit(-1); - rlc_am_tester tester; - mac_dummy_timers timers; + rlc_am_tester tester; + srslte::timers timers(8); rlc_am rlc1(&log1, 1, &tester, &tester, &timers); rlc_am rlc2(&log2, 1, &tester, &tester, &timers); @@ -880,8 +857,8 @@ bool resegment_test_5() log2.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(-1); log2.set_hex_limit(-1); - rlc_am_tester tester; - mac_dummy_timers timers; + rlc_am_tester tester; + srslte::timers timers(8); rlc_am rlc1(&log1, 1, &tester, &tester, &timers); rlc_am rlc2(&log2, 1, &tester, &tester, &timers); @@ -979,9 +956,9 @@ bool resegment_test_6() log2.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(-1); log2.set_hex_limit(-1); - rlc_am_tester tester; - mac_dummy_timers timers; - int len = 0; + rlc_am_tester tester; + srslte::timers timers(8); + int len = 0; rlc_am rlc1(&log1, 1, &tester, &tester, &timers); rlc_am rlc2(&log2, 1, &tester, &tester, &timers); @@ -1115,9 +1092,9 @@ bool resegment_test_7() pcap.open("rlc_am_test7.pcap", 0); rlc_am_tester tester(&pcap); #else - rlc_am_tester tester(NULL); + rlc_am_tester tester(NULL); #endif - mac_dummy_timers timers; + srslte::timers timers(8); rlc_am rlc1(&log1, 1, &tester, &tester, &timers); rlc_am rlc2(&log2, 1, &tester, &tester, &timers); @@ -1288,9 +1265,9 @@ bool resegment_test_8() pcap.open("rlc_am_test8.pcap", 0); rlc_am_tester tester(&pcap); #else - rlc_am_tester tester(NULL); + rlc_am_tester tester(NULL); #endif - mac_dummy_timers timers; + srslte::timers timers(8); rlc_am rlc1(&log1, 1, &tester, &tester, &timers); rlc_am rlc2(&log2, 1, &tester, &tester, &timers); @@ -1433,9 +1410,9 @@ bool reset_test() srslte::log_filter log1("RLC_AM_1"); log1.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(-1); - rlc_am_tester tester; - mac_dummy_timers timers; - int len = 0; + rlc_am_tester tester; + srslte::timers timers(8); + int len = 0; rlc_am rlc1(&log1, 1, &tester, &tester, &timers); @@ -1478,9 +1455,9 @@ bool resume_test() srslte::log_filter log1("RLC_AM_1"); log1.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(-1); - rlc_am_tester tester; - mac_dummy_timers timers; - int len = 0; + rlc_am_tester tester; + srslte::timers timers(8); + int len = 0; rlc_am rlc1(&log1, 1, &tester, &tester, &timers); @@ -1523,8 +1500,8 @@ bool stop_test() srslte::log_filter log1("RLC_AM_1"); log1.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(-1); - rlc_am_tester tester; - mac_dummy_timers timers; + rlc_am_tester tester; + srslte::timers timers(8); rlc_am rlc1(&log1, 1, &tester, &tester, &timers); @@ -1555,9 +1532,9 @@ bool status_pdu_test() log2.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(-1); log2.set_hex_limit(-1); - rlc_am_tester tester; - mac_dummy_timers timers; - int len = 0; + rlc_am_tester tester; + srslte::timers timers(8); + int len = 0; rlc_am rlc1(&log1, 1, &tester, &tester, &timers); rlc_am rlc2(&log2, 1, &tester, &tester, &timers); diff --git a/lib/test/upper/rlc_common_test.cc b/lib/test/upper/rlc_common_test.cc index d54261907..781ca06db 100644 --- a/lib/test/upper/rlc_common_test.cc +++ b/lib/test/upper/rlc_common_test.cc @@ -37,18 +37,6 @@ using namespace srslte; using namespace asn1::rrc; -class mac_dummy_timers : public srslte::mac_interface_timers -{ -public: - srslte::timers::timer* timer_get(uint32_t timer_id) { return &t; } - uint32_t timer_get_unique_id() { return 0; } - void step() { t.step(); } - void timer_release_id(uint32_t timer_id) {} - -private: - srslte::timers::timer t; -}; - class rlc_tester : public srsue::pdcp_interface_rlc, public srsue::rrc_interface_rlc { public: @@ -91,8 +79,8 @@ int basic_test() log2.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(-1); log2.set_hex_limit(-1); - rlc_tester tester; - mac_dummy_timers timers; + rlc_tester tester; + srslte::timers timers(1); int len = 0; diff --git a/lib/test/upper/rlc_stress_test.cc b/lib/test/upper/rlc_stress_test.cc index 0a2526408..7caf6f586 100644 --- a/lib/test/upper/rlc_stress_test.cc +++ b/lib/test/upper/rlc_stress_test.cc @@ -111,21 +111,6 @@ void parse_args(stress_test_args_t *args, int argc, char *argv[]) { } } -// To provide timer services to RLC -class stack_dummy : public srslte::mac_interface_timers -{ -public: - stack_dummy() : timers(8) {} - - srslte::timers::timer* timer_get(uint32_t timer_id) { return timers.get(timer_id); } - uint32_t timer_get_unique_id() { return timers.get_unique_id(); } - void timer_release_id(uint32_t timer_id) { timers.release_id(timer_id); } - void step_timer() { timers.step_all(); } - -private: - srslte::timers timers; -}; - class mac_dummy : public thread { public: @@ -133,7 +118,7 @@ public: rlc_interface_mac* rlc2_, stress_test_args_t args_, uint32_t lcid_, - stack_dummy* stack_, + timers* timers_, rlc_pcap* pcap_ = NULL) : run_enable(true), rlc1(rlc1_), @@ -141,7 +126,7 @@ public: args(args_), pcap(pcap_), lcid(lcid_), - stack(stack_), + timers(timers_), log("MAC "), thread("MAC_DUMMY"), real_dist(0.0, 1.0) @@ -207,7 +192,7 @@ private: run_tti(rlc2, rlc1, false); // step timer - stack->step_timer(); + timers->step_all(); } } @@ -216,10 +201,10 @@ private: bool run_enable; stress_test_args_t args; - rlc_pcap *pcap; - uint32_t lcid; + rlc_pcap* pcap; + uint32_t lcid; srslte::log_filter log; - stack_dummy* stack = nullptr; + srslte::timers* timers = nullptr; std::mt19937 mt19937; std::uniform_real_distribution real_dist; @@ -354,17 +339,17 @@ void stress_test(stress_test_args_t args) exit(-1); } - stack_dummy stack; + srslte::timers timers(8); rlc rlc1(&log1); rlc rlc2(&log2); rlc_tester tester1(&rlc1, "tester1", args, lcid); rlc_tester tester2(&rlc2, "tester2", args, lcid); - mac_dummy mac(&rlc1, &rlc2, args, lcid, &stack, &pcap); + mac_dummy mac(&rlc1, &rlc2, args, lcid, &timers, &pcap); - rlc1.init(&tester1, &tester1, &stack, 0); - rlc2.init(&tester2, &tester2, &stack, 0); + rlc1.init(&tester1, &tester1, &timers, 0); + rlc2.init(&tester2, &tester2, &timers, 0); // only add AM and UM bearers if (args.mode != "TM") { diff --git a/lib/test/upper/rlc_um_test.cc b/lib/test/upper/rlc_um_test.cc index 55d0abc74..6f7190683 100644 --- a/lib/test/upper/rlc_um_test.cc +++ b/lib/test/upper/rlc_um_test.cc @@ -38,27 +38,7 @@ using namespace srslte; using namespace srsue; using namespace asn1::rrc; -class mac_dummy_timers - :public srslte::mac_interface_timers -{ -public: - srslte::timers::timer* timer_get(uint32_t timer_id) - { - return &t; - } - uint32_t timer_get_unique_id(){return 0;} - void step() - { - t.step(); - } - void timer_release_id(uint32_t timer_id) {} -private: - srslte::timers::timer t; -}; - -class rlc_um_tester - :public pdcp_interface_rlc - ,public rrc_interface_rlc +class rlc_um_tester : public pdcp_interface_rlc, public rrc_interface_rlc { public: rlc_um_tester(){ @@ -103,9 +83,9 @@ int basic_test() log2.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(-1); log2.set_hex_limit(-1); - rlc_um_tester tester; - mac_dummy_timers timers; - int len = 0; + rlc_um_tester tester; + srslte::timers timers(16); + int len = 0; rlc_um rlc1(&log1, 3, &tester, &tester, &timers); rlc_um rlc2(&log2, 3, &tester, &tester, &timers); @@ -173,9 +153,9 @@ int loss_test() log2.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(-1); log2.set_hex_limit(-1); - rlc_um_tester tester; - mac_dummy_timers timers; - int len = 0; + rlc_um_tester tester; + srslte::timers timers(16); + int len = 0; rlc_um rlc1(&log1, 3, &tester, &tester, &timers); rlc_um rlc2(&log2, 3, &tester, &tester, &timers); @@ -218,8 +198,8 @@ int loss_test() } // Step the reordering timer until expiry - while(!timers.timer_get(1)->is_expired()) - timers.timer_get(1)->step(); + while (!timers.get(1)->is_expired()) + timers.get(1)->step(); TESTASSERT(NBUFS - 1 == tester.n_sdus); @@ -234,9 +214,9 @@ int basic_mbsfn_test() log2.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(-1); log2.set_hex_limit(-1); - rlc_um_tester tester; - mac_dummy_timers timers; - int len = 0; + rlc_um_tester tester; + srslte::timers timers(16); + int len = 0; rlc_um rlc1(&log1, 3, &tester, &tester, &timers); rlc_um rlc2(&log2, 3, &tester, &tester, &timers); @@ -306,9 +286,9 @@ int reassmble_test() log2.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(-1); log2.set_hex_limit(-1); - rlc_um_tester tester; - mac_dummy_timers timers; - int len = 0; + rlc_um_tester tester; + srslte::timers timers(16); + int len = 0; rlc_um rlc1(&log1, 3, &tester, &tester, &timers); rlc_um rlc2(&log2, 3, &tester, &tester, &timers); @@ -415,9 +395,9 @@ int reassmble_test2() log2.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(-1); log2.set_hex_limit(-1); - rlc_um_tester tester; - mac_dummy_timers timers; - int len = 0; + rlc_um_tester tester; + srslte::timers timers(16); + int len = 0; rlc_um rlc1(&log1, 3, &tester, &tester, &timers); rlc_um rlc2(&log2, 3, &tester, &tester, &timers); diff --git a/srsenb/hdr/stack/enb_stack_lte.h b/srsenb/hdr/stack/enb_stack_lte.h index 218f31e30..b4bd56417 100644 --- a/srsenb/hdr/stack/enb_stack_lte.h +++ b/srsenb/hdr/stack/enb_stack_lte.h @@ -86,7 +86,11 @@ public: // Radio-Link status void rl_failure(uint16_t rnti) final { mac.rl_failure(rnti); } void rl_ok(uint16_t rnti) final { mac.rl_ok(rnti); } - void tti_clock() final { mac.tti_clock(); } + void tti_clock() final + { + timers.step_all(); + mac.tti_clock(); + } private: stack_args_t args = {}; @@ -102,6 +106,7 @@ private: srsenb::s1ap s1ap; srslte::logger* logger = nullptr; + srslte::timers timers; // Radio and PHY log are in enb.cc srslte::log_filter mac_log; diff --git a/srsenb/hdr/stack/upper/rlc.h b/srsenb/hdr/stack/upper/rlc.h index 2a93e05e4..234eebb1a 100644 --- a/srsenb/hdr/stack/upper/rlc.h +++ b/srsenb/hdr/stack/upper/rlc.h @@ -41,11 +41,13 @@ class rlc : public rlc_interface_mac, public rlc_interface_pdcp { public: - - void init(pdcp_interface_rlc *pdcp_, rrc_interface_rlc *rrc_, mac_interface_rlc *mac_, - srslte::mac_interface_timers *mac_timers_, srslte::log *log_h); - void stop(); - + void init(pdcp_interface_rlc* pdcp_, + rrc_interface_rlc* rrc_, + mac_interface_rlc* mac_, + srslte::timers* timers_, + srslte::log* log_h); + void stop(); + // rlc_interface_rrc void clear_buffer(uint16_t rnti); void add_user(uint16_t rnti); @@ -90,12 +92,12 @@ private: mac_interface_rlc *mac; pdcp_interface_rlc *pdcp; - rrc_interface_rlc *rrc; - srslte::log *log_h; - srslte::byte_buffer_pool *pool; - srslte::mac_interface_timers *mac_timers; + rrc_interface_rlc* rrc; + srslte::log* log_h; + srslte::byte_buffer_pool* pool; + srslte::timers* timers; }; -} +} // namespace srsenb #endif // SRSENB_RLC_H diff --git a/srsenb/src/stack/enb_stack_lte.cc b/srsenb/src/stack/enb_stack_lte.cc index af5719d1c..b44dfc608 100644 --- a/srsenb/src/stack/enb_stack_lte.cc +++ b/srsenb/src/stack/enb_stack_lte.cc @@ -28,7 +28,7 @@ using namespace srslte; namespace srsenb { -enb_stack_lte::enb_stack_lte(srslte::logger* logger_) : logger(logger_), pdcp(&pdcp_log) {} +enb_stack_lte::enb_stack_lte(srslte::logger* logger_) : logger(logger_), pdcp(&pdcp_log), timers(128) {} enb_stack_lte::~enb_stack_lte() { @@ -115,7 +115,7 @@ int enb_stack_lte::init(const stack_args_t& args_, const rrc_cfg_t& rrc_cfg_) // Init all layers mac.init(args.mac, &cell_cfg, phy, &rlc, &rrc, &mac_log); - rlc.init(&pdcp, &rrc, &mac, &mac, &rlc_log); + rlc.init(&pdcp, &rrc, &mac, &timers, &rlc_log); pdcp.init(&rlc, &rrc, >pu); rrc.init(&rrc_cfg, phy, &mac, &rlc, &pdcp, &s1ap, >pu, &rrc_log); s1ap.init(args.s1ap, &rrc, &s1ap_log); diff --git a/srsenb/src/stack/upper/rlc.cc b/srsenb/src/stack/upper/rlc.cc index 4b63db6b7..ecf0cc40d 100644 --- a/srsenb/src/stack/upper/rlc.cc +++ b/srsenb/src/stack/upper/rlc.cc @@ -23,17 +23,20 @@ #include "srsenb/hdr/stack/upper/common_enb.h" namespace srsenb { - -void rlc::init(pdcp_interface_rlc* pdcp_, rrc_interface_rlc* rrc_, mac_interface_rlc *mac_, - srslte::mac_interface_timers *mac_timers_, srslte::log* log_h_) + +void rlc::init(pdcp_interface_rlc* pdcp_, + rrc_interface_rlc* rrc_, + mac_interface_rlc* mac_, + srslte::timers* timers_, + srslte::log* log_h_) { - pdcp = pdcp_; - rrc = rrc_, - log_h = log_h_; - mac = mac_; - mac_timers = mac_timers_; + pdcp = pdcp_; + rrc = rrc_; + log_h = log_h_; + mac = mac_; + timers = timers_; - pool = srslte::byte_buffer_pool::get_instance(); + pool = srslte::byte_buffer_pool::get_instance(); pthread_rwlock_init(&rwlock, NULL); } @@ -54,9 +57,9 @@ void rlc::add_user(uint16_t rnti) pthread_rwlock_rdlock(&rwlock); if (users.count(rnti) == 0) { std::unique_ptr obj(new srslte::rlc(log_h)); - obj->init(&users[rnti], &users[rnti], mac_timers, RB_ID_SRB0); - users[rnti].rnti = rnti; - users[rnti].pdcp = pdcp; + obj->init(&users[rnti], &users[rnti], timers, RB_ID_SRB0); + users[rnti].rnti = rnti; + users[rnti].pdcp = pdcp; users[rnti].rrc = rrc; users[rnti].rlc = std::move(obj); users[rnti].parent = this; diff --git a/srsepc/hdr/mme/mme.h b/srsepc/hdr/mme/mme.h index c3f9ac0c2..84db27013 100644 --- a/srsepc/hdr/mme/mme.h +++ b/srsepc/hdr/mme/mme.h @@ -81,7 +81,7 @@ private: fd_set m_set; // Timer map - std::vector m_timers; + std::vector timers; // Timer Methods void handle_timer_expire(int timer_fd); diff --git a/srsepc/src/mme/mme.cc b/srsepc/src/mme/mme.cc index 6f480d5ef..2f3495263 100644 --- a/srsepc/src/mme/mme.cc +++ b/srsepc/src/mme/mme.cc @@ -132,7 +132,7 @@ void mme::run_thread() FD_SET(s11, &m_set); // Add timers to select - for (std::vector::iterator it = m_timers.begin(); it != m_timers.end(); ++it) { + for (std::vector::iterator it = timers.begin(); it != timers.end(); ++it) { FD_SET(it->fd, &m_set); max_fd = std::max(max_fd, it->fd); m_s1ap_log->debug("Adding Timer fd %d to fd_set\n", it->fd); @@ -174,14 +174,14 @@ void mme::run_thread() m_mme_gtpc->handle_s11_pdu(pdu); } // Handle NAS Timers - for (std::vector::iterator it = m_timers.begin(); it != m_timers.end();) { + for (std::vector::iterator it = timers.begin(); it != timers.end();) { if (FD_ISSET(it->fd, &m_set)) { m_s1ap_log->info("Timer expired\n"); uint64_t exp; rd_sz = read(it->fd, &exp, sizeof(uint64_t)); m_s1ap->expire_nas_timer(it->type, it->imsi); close(it->fd); - m_timers.erase(it); + timers.erase(it); } else { ++it; } @@ -205,14 +205,14 @@ bool mme::add_nas_timer(int timer_fd, nas_timer_type type, uint64_t imsi) timer.type = type; timer.imsi = imsi; - m_timers.push_back(timer); + timers.push_back(timer); return true; } bool mme::is_nas_timer_running(nas_timer_type type, uint64_t imsi) { std::vector::iterator it; - for (it = m_timers.begin(); it != m_timers.end(); ++it) { + for (it = timers.begin(); it != timers.end(); ++it) { if (it->type == type && it->imsi == imsi) { return true; // found timer } @@ -223,12 +223,12 @@ bool mme::is_nas_timer_running(nas_timer_type type, uint64_t imsi) bool mme::remove_nas_timer(nas_timer_type type, uint64_t imsi) { std::vector::iterator it; - for (it = m_timers.begin(); it != m_timers.end(); ++it) { + for (it = timers.begin(); it != timers.end(); ++it) { if (it->type == type && it->imsi == imsi) { break; // found timer to remove } } - if (it == m_timers.end()) { + if (it == timers.end()) { m_s1ap_log->warning("Could not find timer to remove. IMSI %" PRIu64 ", Type %d\n", imsi, type); return false; } @@ -237,7 +237,7 @@ bool mme::remove_nas_timer(nas_timer_type type, uint64_t imsi) m_s1ap_log->debug("Removing NAS timer from MME. IMSI %" PRIu64 ", Type %d, Fd: %d\n", imsi, type, it->fd); FD_CLR(it->fd, &m_set); close(it->fd); - m_timers.erase(it); + timers.erase(it); return true; } diff --git a/srsue/hdr/stack/mac/mac.h b/srsue/hdr/stack/mac/mac.h index 18e373453..822372bed 100644 --- a/srsue/hdr/stack/mac/mac.h +++ b/srsue/hdr/stack/mac/mac.h @@ -51,7 +51,7 @@ 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); + bool init(phy_interface_mac_lte* phy, rlc_interface_mac* rlc, rrc_interface_mac* rrc, srslte::timers* timers_); void stop(); void get_metrics(mac_metrics_t m[SRSLTE_MAX_CARRIERS]); @@ -163,7 +163,7 @@ private: uint32_t timer_alignment = 0; void setup_timers(int time_alignment_timer); void timer_alignment_expire(); - srslte::timers timers; + srslte::timers* timers = nullptr; // pointer to MAC PCAP object srslte::mac_pcap* pcap = nullptr; diff --git a/srsue/hdr/stack/rrc/rrc.h b/srsue/hdr/stack/rrc/rrc.h index 42311791f..f9077cc18 100644 --- a/srsue/hdr/stack/rrc/rrc.h +++ b/srsue/hdr/stack/rrc/rrc.h @@ -289,15 +289,15 @@ public: rrc(srslte::log* rrc_log_); ~rrc(); - void init(phy_interface_rrc_lte* phy_, - mac_interface_rrc* mac_, - rlc_interface_rrc* rlc_, - pdcp_interface_rrc* pdcp_, - nas_interface_rrc* nas_, - usim_interface_rrc* usim_, - gw_interface_rrc* gw_, - srslte::mac_interface_timers* mac_timers_, - const rrc_args_t& args_); + void init(phy_interface_rrc_lte* phy_, + mac_interface_rrc* mac_, + rlc_interface_rrc* rlc_, + pdcp_interface_rrc* pdcp_, + nas_interface_rrc* nas_, + usim_interface_rrc* usim_, + gw_interface_rrc* gw_, + srslte::timers* timers_, + const rrc_args_t& args_); void stop(); @@ -407,10 +407,10 @@ private: std::map drbs; // RRC constants and timers - srslte::mac_interface_timers* mac_timers = nullptr; - uint32_t n310_cnt, N310 = 0; - uint32_t n311_cnt, N311 = 0; - uint32_t t300, t301, t302, t310, t311, t304 = 0; + srslte::timers* timers = nullptr; + uint32_t n310_cnt, N310 = 0; + uint32_t n311_cnt, N311 = 0; + uint32_t t300, t301, t302, t310, t311, t304 = 0; // Radio bearers typedef enum{ @@ -523,10 +523,10 @@ private: std::map reports_cfg; std::map active; - rrc* parent = nullptr; - srslte::log* log_h = nullptr; - phy_interface_rrc_lte* phy = nullptr; - srslte::mac_interface_timers* mac_timers = nullptr; + rrc* parent = nullptr; + srslte::log* log_h = nullptr; + phy_interface_rrc_lte* phy = nullptr; + srslte::timers* timers = nullptr; uint32_t filter_k_rsrp, filter_k_rsrq = 0; float filter_a[NOF_MEASUREMENTS] = {}; diff --git a/srsue/hdr/stack/ue_stack_lte.h b/srsue/hdr/stack/ue_stack_lte.h index 89b79147c..928c7500d 100644 --- a/srsue/hdr/stack/ue_stack_lte.h +++ b/srsue/hdr/stack/ue_stack_lte.h @@ -121,6 +121,9 @@ private: bool running; srsue::stack_args_t args; + // timers + srslte::timers timers; + // UE stack logging srslte::logger* logger = nullptr; srslte::log_filter mac_log; diff --git a/srsue/src/stack/mac/mac.cc b/srsue/src/stack/mac/mac.cc index ea42c43bf..2949cc70f 100644 --- a/srsue/src/stack/mac/mac.cc +++ b/srsue/src/stack/mac/mac.cc @@ -38,7 +38,6 @@ using namespace asn1::rrc; namespace srsue { mac::mac(srslte::log* log_) : - timers(64), pdu_process_thread(&demux_unit), mch_msg(10, log_), mux_unit(log_), @@ -72,26 +71,27 @@ mac::~mac() srslte_softbuffer_rx_free(&mch_softbuffer); } -bool mac::init(phy_interface_mac_lte* phy, rlc_interface_mac* rlc, rrc_interface_mac* rrc) +bool mac::init(phy_interface_mac_lte* phy, rlc_interface_mac* rlc, rrc_interface_mac* rrc, srslte::timers* timers_) { - phy_h = phy; - rlc_h = rlc; - rrc_h = rrc; + phy_h = phy; + rlc_h = rlc; + rrc_h = rrc; + timers = timers_; - timer_alignment = timers.get_unique_id(); - uint32_t contention_resolution_timer = timers.get_unique_id(); + timer_alignment = timers->get_unique_id(); + uint32_t contention_resolution_timer = timers->get_unique_id(); - bsr_procedure.init(rlc_h, log_h, &timers); - phr_procedure.init(phy_h, log_h, &timers); + bsr_procedure.init(rlc_h, log_h, timers); + phr_procedure.init(phy_h, log_h, timers); mux_unit.init(rlc_h, &bsr_procedure, &phr_procedure); - demux_unit.init(phy_h, rlc_h, this, timers.get(timer_alignment)); + demux_unit.init(phy_h, rlc_h, this, timers->get(timer_alignment)); ra_procedure.init( - phy_h, rrc, log_h, &uernti, timers.get(timer_alignment), timers.get(contention_resolution_timer), &mux_unit); + phy_h, rrc, log_h, &uernti, timers->get(timer_alignment), timers->get(contention_resolution_timer), &mux_unit); sr_procedure.init(phy_h, rrc, log_h); // Create UL/DL unique HARQ pointers ul_harq.at(0)->init(log_h, &uernti, &ra_procedure, &mux_unit); - dl_harq.at(0)->init(log_h, &uernti, timers.get(timer_alignment), &demux_unit); + dl_harq.at(0)->init(log_h, &uernti, timers->get(timer_alignment), &demux_unit); reset(); @@ -135,7 +135,7 @@ void mac::reconfiguration(const uint32_t& cc_idx, const bool& enable) } while (dl_harq.size() < cc_idx + 1) { auto dl = dl_harq_entity_ptr(new dl_harq_entity()); - dl->init(log_h, &uernti, timers.get(timer_alignment), &demux_unit); + dl->init(log_h, &uernti, timers->get(timer_alignment), &demux_unit); if (pcap) { dl->start_pcap(pcap); @@ -162,7 +162,7 @@ void mac::reset() Info("Resetting MAC\n"); - timers.get(timer_alignment)->stop(); + timers->get(timer_alignment)->stop(); timer_alignment_expire(); @@ -233,7 +233,6 @@ void mac::run_tti(const uint32_t tti) ra_window_start = -1; ra_window_length = -1; ra_procedure.update_rar_window(&ra_window_start, &ra_window_length); - timers.step_all(); } void mac::bcch_start_rx(int si_window_start, int si_window_length) @@ -509,12 +508,12 @@ void mac::new_mch_dl(srslte_pdsch_grant_t phy_grant, tb_action_dl_t* action) void mac::setup_timers(int time_alignment_timer) { // stop currently running time alignment timer - if (timers.get(timer_alignment)->is_running()) { - timers.get(timer_alignment)->stop(); + if (timers->get(timer_alignment)->is_running()) { + timers->get(timer_alignment)->stop(); } if (time_alignment_timer > 0) { - timers.get(timer_alignment)->set(this, time_alignment_timer); + timers->get(timer_alignment)->set(this, time_alignment_timer); } } @@ -651,9 +650,6 @@ void mac::get_metrics(mac_metrics_t m[SRSLTE_MAX_CARRIERS]) bzero(&metrics, sizeof(mac_metrics_t) * SRSLTE_MAX_CARRIERS); } - - - /******************************************************** * * Interface for timers used by upper layers @@ -661,20 +657,19 @@ void mac::get_metrics(mac_metrics_t m[SRSLTE_MAX_CARRIERS]) *******************************************************/ srslte::timers::timer* mac::timer_get(uint32_t timer_id) { - return timers.get(timer_id); + return timers->get(timer_id); } void mac::timer_release_id(uint32_t timer_id) { - timers.release_id(timer_id); + timers->release_id(timer_id); } uint32_t mac::timer_get_unique_id() { - return timers.get_unique_id(); + return timers->get_unique_id(); } - /******************************************************** * * Class that runs a thread to process DL MAC PDUs from diff --git a/srsue/src/stack/rrc/rrc.cc b/srsue/src/stack/rrc/rrc.cc index 67e78e312..dc4ded341 100644 --- a/srsue/src/stack/rrc/rrc.cc +++ b/srsue/src/stack/rrc/rrc.cc @@ -118,7 +118,7 @@ void rrc::init(phy_interface_rrc_lte* phy_, nas_interface_rrc* nas_, usim_interface_rrc* usim_, gw_interface_rrc* gw_, - mac_interface_timers* mac_timers_, + srslte::timers* timers_, const rrc_args_t& args_) { pool = byte_buffer_pool::get_instance(); @@ -133,19 +133,18 @@ void rrc::init(phy_interface_rrc_lte* phy_, args = args_; // Use MAC timers - mac_timers = mac_timers_; + timers = timers_; state = RRC_STATE_IDLE; plmn_is_selected = false; security_is_activated = false; - - t300 = mac_timers->timer_get_unique_id(); - t301 = mac_timers->timer_get_unique_id(); - t302 = mac_timers->timer_get_unique_id(); - t310 = mac_timers->timer_get_unique_id(); - t311 = mac_timers->timer_get_unique_id(); - t304 = mac_timers->timer_get_unique_id(); + t300 = timers->get_unique_id(); + t301 = timers->get_unique_id(); + t302 = timers->get_unique_id(); + t310 = timers->get_unique_id(); + t311 = timers->get_unique_id(); + t304 = timers->get_unique_id(); ue_identity_configured = false; @@ -448,20 +447,20 @@ void rrc::out_of_sync() // upon receiving N310 consecutive "out-of-sync" indications for the PCell from lower layers while neither T300, // T301, T304 nor T311 is running: if (state == RRC_STATE_CONNECTED) { - if (!mac_timers->timer_get(t300)->is_running() && !mac_timers->timer_get(t301)->is_running() && - !mac_timers->timer_get(t304)->is_running() && !mac_timers->timer_get(t310)->is_running() && - !mac_timers->timer_get(t311)->is_running()) { + if (!timers->get(t300)->is_running() && !timers->get(t301)->is_running() && !timers->get(t304)->is_running() && + !timers->get(t310)->is_running() && !timers->get(t311)->is_running()) { rrc_log->info("Received out-of-sync while in state %s. n310=%d, t311=%s, t310=%s\n", rrc_state_text[state], n310_cnt, - mac_timers->timer_get(t311)->is_running() ? "running" : "stop", - mac_timers->timer_get(t310)->is_running() ? "running" : "stop"); + timers->get(t311)->is_running() ? "running" : "stop", + timers->get(t310)->is_running() ? "running" : "stop"); n310_cnt++; if (n310_cnt == N310) { rrc_log->info("Detected %d out-of-sync from PHY. Trying to resync. Starting T310 timer %d ms\n", - N310, mac_timers->timer_get(t310)->get_timeout()); - mac_timers->timer_get(t310)->reset(); - mac_timers->timer_get(t310)->run(); + N310, + timers->get(t310)->get_timeout()); + timers->get(t310)->reset(); + timers->get(t310)->run(); n310_cnt = 0; } } @@ -473,10 +472,10 @@ void rrc::in_sync() { // CAUTION: We do not lock in this function since they are called from real-time threads serving_cell->in_sync = true; - if (mac_timers->timer_get(t310)->is_running()) { + if (timers->get(t310)->is_running()) { n311_cnt++; if (n311_cnt == N311) { - mac_timers->timer_get(t310)->stop(); + timers->get(t310)->stop(); n311_cnt = 0; rrc_log->info("Detected %d in-sync from PHY. Stopping T310 timer\n", N311); } @@ -1063,8 +1062,8 @@ bool rrc::ho_prepare() } // Section 5.3.5.4 - mac_timers->timer_get(t310)->stop(); - mac_timers->timer_get(t304)->set(this, mob_ctrl_info->t304.to_number()); + timers->get(t310)->stop(); + timers->get(t304)->set(this, mob_ctrl_info->t304.to_number()); // Save serving cell and current configuration ho_src_cell = *serving_cell; @@ -1148,7 +1147,7 @@ void rrc::ho_ra_completed(bool ra_successful) measurements.parse_meas_config(&mob_reconf_r8->meas_cfg); } - mac_timers->timer_get(t304)->stop(); + timers->get(t304)->stop(); } // T304 will expiry and send ho_failure @@ -1343,11 +1342,11 @@ void rrc::leave_connected() void rrc::stop_timers() { - mac_timers->timer_get(t300)->stop(); - mac_timers->timer_get(t301)->stop(); - mac_timers->timer_get(t310)->stop(); - mac_timers->timer_get(t311)->stop(); - mac_timers->timer_get(t304)->stop(); + timers->get(t300)->stop(); + timers->get(t301)->stop(); + timers->get(t310)->stop(); + timers->get(t311)->stop(); + timers->get(t304)->stop(); } /* Implementation of procedure in 3GPP 36.331 Section 5.3.7.2: Initiation @@ -1395,11 +1394,11 @@ void rrc::proc_con_restablish_request() rrc_log->info("Resetting timers and MAC in RRC Connection Reestablishment Procedure\n"); // stop timer T310, if running; - mac_timers->timer_get(t310)->stop(); + timers->get(t310)->stop(); // start timer T311; - mac_timers->timer_get(t311)->reset(); - mac_timers->timer_get(t311)->run(); + timers->get(t311)->reset(); + timers->get(t311)->run(); // Suspend all RB except SRB0 for (int i = 1; i < SRSLTE_N_RADIO_BEARERS; i++) { @@ -1425,7 +1424,7 @@ void rrc::proc_con_restablish_request() } // Check timer... - if (mac_timers->timer_get(t311)->is_running()) { + if (timers->get(t311)->is_running()) { // Check for synchronism if (serving_cell->in_sync) { // Perform cell selection in accordance to 36.304 @@ -1433,16 +1432,16 @@ void rrc::proc_con_restablish_request() // Actions following cell reselection while T311 is running 5.3.7.3 // Upon selecting a suitable E-UTRA cell, the UE shall: rrc_log->info("Cell Selection criteria passed after %dms. Sending RRC Connection Reestablishment Request\n", - mac_timers->timer_get(t311)->value()); + timers->get(t311)->value()); // stop timer T311; - mac_timers->timer_get(t301)->reset(); + timers->get(t301)->reset(); // start timer T301; - mac_timers->timer_get(t301)->run(); + timers->get(t301)->run(); // apply the timeAlignmentTimerCommon included in SystemInformationBlockType2; - mac_timers->timer_get(t311)->stop(); + timers->get(t311)->stop(); // initiate transmission of the RRCConnectionReestablishmentRequest message in accordance with 5.3.7.4; send_con_restablish_request(); @@ -1644,20 +1643,20 @@ void rrc::handle_sib2() log_rr_config_common(); - mac_timers->timer_get(t300)->set(this, sib2->ue_timers_and_consts.t300.to_number()); - mac_timers->timer_get(t301)->set(this, sib2->ue_timers_and_consts.t301.to_number()); - mac_timers->timer_get(t310)->set(this, sib2->ue_timers_and_consts.t310.to_number()); - mac_timers->timer_get(t311)->set(this, sib2->ue_timers_and_consts.t311.to_number()); + timers->get(t300)->set(this, sib2->ue_timers_and_consts.t300.to_number()); + timers->get(t301)->set(this, sib2->ue_timers_and_consts.t301.to_number()); + timers->get(t310)->set(this, sib2->ue_timers_and_consts.t310.to_number()); + timers->get(t311)->set(this, sib2->ue_timers_and_consts.t311.to_number()); N310 = sib2->ue_timers_and_consts.n310.to_number(); N311 = sib2->ue_timers_and_consts.n311.to_number(); rrc_log->info("Set Constants and Timers: N310=%d, N311=%d, t300=%d, t301=%d, t310=%d, t311=%d\n", N310, N311, - mac_timers->timer_get(t300)->get_timeout(), - mac_timers->timer_get(t301)->get_timeout(), - mac_timers->timer_get(t310)->get_timeout(), - mac_timers->timer_get(t311)->get_timeout()); + timers->get(t300)->get_timeout(), + timers->get(t301)->get_timeout(), + timers->get(t310)->get_timeout(), + timers->get(t311)->get_timeout()); } void rrc::handle_sib3() @@ -1899,12 +1898,12 @@ void rrc::parse_dl_ccch(unique_byte_buffer_t pdu) rrc_log->info("Received ConnectionReject. Wait time: %d\n", reject_r8->wait_time); rrc_log->console("Received ConnectionReject. Wait time: %d\n", reject_r8->wait_time); - mac_timers->timer_get(t300)->stop(); + timers->get(t300)->stop(); if (reject_r8->wait_time) { nas->set_barring(nas_interface_rrc::BARRING_ALL); - mac_timers->timer_get(t302)->set(this, reject_r8->wait_time * 1000u); - mac_timers->timer_get(t302)->run(); + timers->get(t302)->set(this, reject_r8->wait_time * 1000u); + timers->get(t302)->run(); } else { // Perform the actions upon expiry of T302 if wait time is zero nas->set_barring(nas_interface_rrc::BARRING_NONE); @@ -2623,18 +2622,22 @@ bool rrc::apply_rr_config_dedicated(rr_cfg_ded_s* cnfg) } if (cnfg->sps_cfg_present) { - //TODO + // TODO } if (cnfg->rlf_timers_and_consts_r9.is_present() and cnfg->rlf_timers_and_consts_r9->type() == setup_e::setup) { - mac_timers->timer_get(t301)->set(this, cnfg->rlf_timers_and_consts_r9->setup().t301_r9.to_number()); - mac_timers->timer_get(t310)->set(this, cnfg->rlf_timers_and_consts_r9->setup().t310_r9.to_number()); - mac_timers->timer_get(t311)->set(this, cnfg->rlf_timers_and_consts_r9->setup().t311_r9.to_number()); + timers->get(t301)->set(this, cnfg->rlf_timers_and_consts_r9->setup().t301_r9.to_number()); + timers->get(t310)->set(this, cnfg->rlf_timers_and_consts_r9->setup().t310_r9.to_number()); + timers->get(t311)->set(this, cnfg->rlf_timers_and_consts_r9->setup().t311_r9.to_number()); N310 = cnfg->rlf_timers_and_consts_r9->setup().n310_r9.to_number(); N311 = cnfg->rlf_timers_and_consts_r9->setup().n311_r9.to_number(); rrc_log->info("Updated Constants and Timers: N310=%d, N311=%d, t300=%u, t301=%u, t310=%u, t311=%u\n", - N310, N311, mac_timers->timer_get(t300)->get_timeout(), mac_timers->timer_get(t301)->get_timeout(), - mac_timers->timer_get(t310)->get_timeout(), mac_timers->timer_get(t311)->get_timeout()); + N310, + N311, + timers->get(t300)->get_timeout(), + timers->get(t301)->get_timeout(), + timers->get(t310)->get_timeout(), + timers->get(t311)->get_timeout()); } for (uint32_t i = 0; i < cnfg->srb_to_add_mod_list.size(); i++) { // TODO: handle SRB modification @@ -2714,8 +2717,8 @@ void rrc::handle_con_setup(rrc_conn_setup_s* setup) { // Must enter CONNECT before stopping T300 state = RRC_STATE_CONNECTED; - mac_timers->timer_get(t300)->stop(); - mac_timers->timer_get(t302)->stop(); + timers->get(t300)->stop(); + timers->get(t302)->stop(); rrc_log->console("RRC Connected\n"); // Apply the Radio Resource configuration @@ -2734,7 +2737,7 @@ void rrc::handle_con_setup(rrc_conn_setup_s* setup) void rrc::handle_con_reest(rrc_conn_reest_s* setup) { - mac_timers->timer_get(t301)->stop(); + timers->get(t301)->stop(); // Reestablish PDCP and RLC for SRB1 pdcp->reestablish(1); @@ -2938,31 +2941,14 @@ void rrc::set_mac_default() { apply_mac_config_dedicated_default(); } -void rrc::set_rrc_default() { +void rrc::set_rrc_default() +{ N310 = 1; N311 = 1; - mac_timers->timer_get(t310)->set(this, 1000); - mac_timers->timer_get(t311)->set(this, 1000); + timers->get(t310)->set(this, 1000); + timers->get(t311)->set(this, 1000); } - - - - - - - - - - - - - - - - - - /************************************************************************ * * @@ -2975,7 +2961,7 @@ void rrc::rrc_meas::init(rrc *parent) { this->parent = parent; this->log_h = parent->rrc_log; this->phy = parent->phy; - this->mac_timers = parent->mac_timers; + this->timers = parent->timers; s_measure_enabled = false; reset(); } @@ -3138,11 +3124,11 @@ void rrc::rrc_meas::generate_report(uint32_t meas_id) report->meas_result_neigh_cells_present = neigh_list.size() > 0; m->nof_reports_sent++; - mac_timers->timer_get(m->periodic_timer)->stop(); + timers->get(m->periodic_timer)->stop(); if (m->nof_reports_sent < cfg->amount) { - mac_timers->timer_get(m->periodic_timer)->reset(); - mac_timers->timer_get(m->periodic_timer)->run(); + timers->get(m->periodic_timer)->reset(); + timers->get(m->periodic_timer)->run(); } else { if (cfg->trigger_type == report_cfg_t::PERIODIC) { m->triggered = false; @@ -3173,9 +3159,9 @@ bool rrc::rrc_meas::process_event(eutra_event_s* event, uint32_t tti, bool enter cell->timer_exit_triggered = true; cell->exit_tti = tti; } else if (srslte_tti_interval(tti, cell->exit_tti) >= event->time_to_trigger) { - m->triggered = false; - cell->triggered = false; - mac_timers->timer_get(m->periodic_timer)->stop(); + m->triggered = false; + cell->triggered = false; + timers->get(m->periodic_timer)->stop(); if (event) { if (event->event_id.type() == eutra_event_s::event_id_c_::types::event_a3 && event->event_id.event_a3().report_on_leave) { @@ -3351,8 +3337,9 @@ bool rrc::rrc_meas::timer_expired(uint32_t timer_id) { return false; } -void rrc::rrc_meas::stop_reports(meas_t *m) { - mac_timers->timer_get(m->periodic_timer)->stop(); +void rrc::rrc_meas::stop_reports(meas_t* m) +{ + timers->get(m->periodic_timer)->stop(); m->triggered = false; } @@ -3386,10 +3373,11 @@ void rrc::rrc_meas::remove_meas_report(uint32_t report_id) { } } -void rrc::rrc_meas::remove_meas_id(uint32_t measId) { +void rrc::rrc_meas::remove_meas_id(uint32_t measId) +{ if (active.count(measId)) { - mac_timers->timer_get(active[measId].periodic_timer)->stop(); - mac_timers->timer_release_id(active[measId].periodic_timer); + timers->get(active[measId].periodic_timer)->stop(); + timers->release_id(active[measId].periodic_timer); log_h->info("MEAS: Removed measId=%d\n", measId); active.erase(measId); } else { @@ -3397,9 +3385,10 @@ void rrc::rrc_meas::remove_meas_id(uint32_t measId) { } } -void rrc::rrc_meas::remove_meas_id(std::map::iterator it) { - mac_timers->timer_get(it->second.periodic_timer)->stop(); - mac_timers->timer_release_id(it->second.periodic_timer); +void rrc::rrc_meas::remove_meas_id(std::map::iterator it) +{ + timers->get(it->second.periodic_timer)->stop(); + timers->release_id(it->second.periodic_timer); log_h->info("MEAS: Removed measId=%d\n", it->first); active.erase(it); } @@ -3548,10 +3537,10 @@ bool rrc::rrc_meas::parse_meas_config(meas_cfg_s* cfg) // Stop the timer if the entry exists or create the timer if not bool is_new = false; if (active.count(meas_id->meas_id)) { - mac_timers->timer_get(active[meas_id->meas_id].periodic_timer)->stop(); + timers->get(active[meas_id->meas_id].periodic_timer)->stop(); } else { is_new = true; - active[meas_id->meas_id].periodic_timer = mac_timers->timer_get_unique_id(); + active[meas_id->meas_id].periodic_timer = timers->get_unique_id(); } active[meas_id->meas_id].object_id = meas_id->meas_obj_id; active[meas_id->meas_id].report_id = meas_id->report_cfg_id; diff --git a/srsue/src/stack/rrc/rrc_procedures.cc b/srsue/src/stack/rrc/rrc_procedures.cc index 061e75a78..dc884385a 100644 --- a/srsue/src/stack/rrc/rrc_procedures.cc +++ b/srsue/src/stack/rrc/rrc_procedures.cc @@ -546,7 +546,7 @@ proc_outcome_t rrc::connection_request_proc::init(rrc* return proc_outcome_t::error; } - if (rrc_ptr->mac_timers->timer_get(rrc_ptr->t302)->is_running()) { + if (rrc_ptr->timers->get(rrc_ptr->t302)->is_running()) { Info("Requested RRC connection establishment while T302 is running\n"); rrc_ptr->nas->set_barring(nas_interface_rrc::BARRING_MO_DATA); return proc_outcome_t::error; @@ -620,8 +620,8 @@ proc_outcome_t rrc::connection_request_proc::step() return proc_outcome_t::error; } - rrc_ptr->mac_timers->timer_get(rrc_ptr->t300)->reset(); - rrc_ptr->mac_timers->timer_get(rrc_ptr->t300)->run(); + rrc_ptr->timers->get(rrc_ptr->t300)->reset(); + rrc_ptr->timers->get(rrc_ptr->t300)->run(); // Send connectionRequest message to lower layers rrc_ptr->send_con_request(cause); @@ -638,14 +638,14 @@ proc_outcome_t rrc::connection_request_proc::step() } else if (state == state_t::wait_t300) { // Wait until t300 stops due to RRCConnectionSetup/Reject or expiry - if (rrc_ptr->mac_timers->timer_get(rrc_ptr->t300)->is_running()) { + if (rrc_ptr->timers->get(rrc_ptr->t300)->is_running()) { return proc_outcome_t::yield; } if (rrc_ptr->state == RRC_STATE_CONNECTED) { // Received ConnectionSetup return proc_outcome_t::success; - } else if (rrc_ptr->mac_timers->timer_get(rrc_ptr->t300)->is_expired()) { + } else if (rrc_ptr->timers->get(rrc_ptr->t300)->is_expired()) { // T300 is expired: 5.3.3.6 Info("Timer T300 expired: ConnectionRequest timed out\n"); rrc_ptr->mac->reset(); diff --git a/srsue/src/stack/ue_stack_lte.cc b/srsue/src/stack/ue_stack_lte.cc index fe5e95cad..864d4a697 100644 --- a/srsue/src/stack/ue_stack_lte.cc +++ b/srsue/src/stack/ue_stack_lte.cc @@ -27,6 +27,7 @@ using namespace srslte; namespace srsue { ue_stack_lte::ue_stack_lte() : + timers(64), running(false), args(), logger(nullptr), @@ -114,11 +115,11 @@ int ue_stack_lte::init(const stack_args_t& args_, srslte::logger* logger_) return SRSLTE_ERROR; } - mac.init(phy, &rlc, &rrc); - rlc.init(&pdcp, &rrc, &mac, 0 /* RB_ID_SRB0 */); + mac.init(phy, &rlc, &rrc, &timers); + rlc.init(&pdcp, &rrc, &timers, 0 /* RB_ID_SRB0 */); pdcp.init(&rlc, &rrc, gw); nas.init(usim.get(), &rrc, gw, args.nas); - rrc.init(phy, &mac, &rlc, &pdcp, &nas, usim.get(), gw, &mac, args.rrc); + rrc.init(phy, &mac, &rlc, &pdcp, &nas, usim.get(), gw, &timers, args.rrc); running = true; start(STACK_MAIN_THREAD_PRIO); @@ -227,6 +228,7 @@ void ue_stack_lte::run_tti_impl(uint32_t tti) mac.run_tti(tti); rrc.run_tti(tti); nas.run_tti(tti); + timers.step_all(); } } // namespace srsue diff --git a/srsue/test/mac_test.cc b/srsue/test/mac_test.cc index d0fdfb57b..51817698d 100644 --- a/srsue/test/mac_test.cc +++ b/srsue/test/mac_test.cc @@ -349,6 +349,7 @@ int mac_unpack_test() srslte::log_filter rlc_log("RLC"); srslte::log_filter mac_log("MAC"); + srslte::timers timers(64); mac_log.set_level(srslte::LOG_LEVEL_DEBUG); mac_log.set_hex_limit(100000); @@ -362,7 +363,7 @@ int mac_unpack_test() // the actual MAC mac mac(&mac_log); - mac.init(&phy, &rlc, &rrc); + mac.init(&phy, &rlc, &rrc, &timers); // create dummy DL action and grant and push MAC PDU mac_interface_phy_lte::tb_action_dl_t dl_action; @@ -385,6 +386,7 @@ int mac_unpack_test() // make sure MAC PDU thread picks up before stopping sleep(1); mac.run_tti(0); + timers.step_all(); mac.stop(); // check length of both received RLC PDUs @@ -409,6 +411,8 @@ int mac_ul_sch_pdu_test1() rlc_log.set_level(srslte::LOG_LEVEL_DEBUG); rlc_log.set_hex_limit(100000); + srslte::timers timers(64); + // dummy layers phy_dummy phy; rlc_dummy rlc(&rlc_log); @@ -416,7 +420,7 @@ int mac_ul_sch_pdu_test1() // the actual MAC mac mac(&mac_log); - mac.init(&phy, &rlc, &rrc); + mac.init(&phy, &rlc, &rrc, &timers); const uint16_t crnti = 0x1001; mac.set_ho_rnti(crnti, 0); @@ -475,6 +479,8 @@ int mac_ul_logical_channel_prioritization_test1() rlc_log.set_level(srslte::LOG_LEVEL_DEBUG); rlc_log.set_hex_limit(100000); + srslte::timers timers(64); + // dummy layers phy_dummy phy; rlc_dummy rlc(&rlc_log); @@ -482,7 +488,7 @@ int mac_ul_logical_channel_prioritization_test1() // the actual MAC mac mac(&mac_log); - mac.init(&phy, &rlc, &rrc); + mac.init(&phy, &rlc, &rrc, &timers); const uint16_t crnti = 0x1001; mac.set_ho_rnti(crnti, 0); @@ -586,6 +592,8 @@ int mac_ul_logical_channel_prioritization_test2() rlc_log.set_level(srslte::LOG_LEVEL_DEBUG); rlc_log.set_hex_limit(100000); + srslte::timers timers(64); + // dummy layers phy_dummy phy; rlc_dummy rlc(&rlc_log); @@ -593,7 +601,7 @@ int mac_ul_logical_channel_prioritization_test2() // the actual MAC mac mac(&mac_log); - mac.init(&phy, &rlc, &rrc); + mac.init(&phy, &rlc, &rrc, &timers); const uint16_t crnti = 0x1001; mac.set_ho_rnti(crnti, 0); @@ -684,6 +692,8 @@ int mac_ul_logical_channel_prioritization_test3() rlc_log.set_level(srslte::LOG_LEVEL_DEBUG); rlc_log.set_hex_limit(100000); + srslte::timers timers(64); + // dummy layers phy_dummy phy; rlc_dummy rlc(&rlc_log); @@ -691,7 +701,7 @@ int mac_ul_logical_channel_prioritization_test3() // the actual MAC mac mac(&mac_log); - mac.init(&phy, &rlc, &rrc); + mac.init(&phy, &rlc, &rrc, &timers); const uint16_t crnti = 0x1001; mac.set_ho_rnti(crnti, 0); @@ -770,6 +780,8 @@ int mac_ul_sch_pdu_with_short_bsr_test() rlc_log.set_level(srslte::LOG_LEVEL_DEBUG); rlc_log.set_hex_limit(100000); + srslte::timers timers(64); + // dummy layers phy_dummy phy; rlc_dummy rlc(&rlc_log); @@ -777,7 +789,7 @@ int mac_ul_sch_pdu_with_short_bsr_test() // the actual MAC mac mac(&mac_log); - mac.init(&phy, &rlc, &rrc); + mac.init(&phy, &rlc, &rrc, &timers); const uint16_t crnti = 0x1001; mac.set_ho_rnti(crnti, 0); @@ -854,6 +866,8 @@ int mac_ul_sch_pdu_with_padding_bsr_test() rlc_log.set_level(srslte::LOG_LEVEL_DEBUG); rlc_log.set_hex_limit(100000); + srslte::timers timers(64); + // dummy layers phy_dummy phy; rlc_dummy rlc(&rlc_log); @@ -861,7 +875,7 @@ int mac_ul_sch_pdu_with_padding_bsr_test() // the actual MAC mac mac(&mac_log); - mac.init(&phy, &rlc, &rrc); + mac.init(&phy, &rlc, &rrc, &timers); const uint16_t crnti = 0x1001; mac.set_ho_rnti(crnti, 0); @@ -947,6 +961,8 @@ int mac_ul_sch_pdu_one_byte_test() rlc_log.set_level(srslte::LOG_LEVEL_DEBUG); rlc_log.set_hex_limit(100000); + srslte::timers timers(64); + // dummy layers phy_dummy phy; rlc_dummy rlc(&rlc_log); @@ -954,7 +970,7 @@ int mac_ul_sch_pdu_one_byte_test() // the actual MAC mac mac(&mac_log); - mac.init(&phy, &rlc, &rrc); + mac.init(&phy, &rlc, &rrc, &timers); const uint16_t crnti = 0x1001; mac.set_ho_rnti(crnti, 0); @@ -1005,6 +1021,8 @@ int mac_ul_sch_pdu_two_byte_test() rlc_log.set_level(srslte::LOG_LEVEL_DEBUG); rlc_log.set_hex_limit(100000); + srslte::timers timers(64); + // dummy layers phy_dummy phy; rlc_dummy rlc(&rlc_log); @@ -1012,7 +1030,7 @@ int mac_ul_sch_pdu_two_byte_test() // the actual MAC mac mac(&mac_log); - mac.init(&phy, &rlc, &rrc); + mac.init(&phy, &rlc, &rrc, &timers); const uint16_t crnti = 0x1001; mac.set_ho_rnti(crnti, 0); @@ -1063,6 +1081,8 @@ int mac_ul_sch_pdu_three_byte_test() rlc_log.set_level(srslte::LOG_LEVEL_DEBUG); rlc_log.set_hex_limit(100000); + srslte::timers timers(64); + // dummy layers phy_dummy phy; rlc_dummy rlc(&rlc_log); @@ -1070,7 +1090,7 @@ int mac_ul_sch_pdu_three_byte_test() // the actual MAC mac mac(&mac_log); - mac.init(&phy, &rlc, &rrc); + mac.init(&phy, &rlc, &rrc, &timers); const uint16_t crnti = 0x1001; mac.set_ho_rnti(crnti, 0); @@ -1126,7 +1146,7 @@ struct ra_test { struct ra_test test; -int run_mac_ra_test(struct ra_test test, mac* mac, phy_dummy* phy, uint32_t* tti_state) +int run_mac_ra_test(struct ra_test test, mac* mac, phy_dummy* phy, uint32_t* tti_state, srslte::timers* timers) { uint32_t tti = *tti_state; @@ -1148,6 +1168,7 @@ int run_mac_ra_test(struct ra_test test, mac* mac, phy_dummy* phy, uint32_t* tti if (test.assume_prach_transmitted != (int)j) { phy->set_prach_tti(tti + phy->prach_delay); mac->run_tti(tti++); + timers->step_all(); } // Check MAC instructs PHY to transmit PRACH @@ -1167,6 +1188,7 @@ int run_mac_ra_test(struct ra_test test, mac* mac, phy_dummy* phy, uint32_t* tti mac->run_tti(tti); TESTASSERT(!SRSLTE_RNTI_ISRAR(mac->get_dl_sched_rnti(tti))); tti++; + timers->step_all(); } bool rapid_found = false; @@ -1175,6 +1197,7 @@ int run_mac_ra_test(struct ra_test test, mac* mac, phy_dummy* phy, uint32_t* tti mac->run_tti(tti); TESTASSERT(mac->get_dl_sched_rnti(tti) == phy->get_rar_rnti()); tti++; + timers->step_all(); // Receive RAR if (test.rar_nof_rapid > 0) { @@ -1200,6 +1223,7 @@ int run_mac_ra_test(struct ra_test test, mac* mac, phy_dummy* phy, uint32_t* tti mac->run_tti(tti); TESTASSERT(mac->get_dl_sched_rnti(tti) == (test.crnti ? test.crnti : test.temp_rnti)); tti++; + timers->step_all(); } if (i == test.rach_cfg.max_harq_msg3_tx) { @@ -1222,6 +1246,7 @@ int run_mac_ra_test(struct ra_test test, mac* mac, phy_dummy* phy, uint32_t* tti mac->run_tti(tti); TESTASSERT(mac->get_dl_sched_rnti(tti) == (test.crnti ? test.crnti : test.temp_rnti)); tti++; + timers->step_all(); if (test.msg4_enable) { if (test.crnti) { @@ -1258,6 +1283,7 @@ int run_mac_ra_test(struct ra_test test, mac* mac, phy_dummy* phy, uint32_t* tti phy->set_prach_tti(tti + phy->prach_delay, false); TESTASSERT(mac->get_dl_sched_rnti(tti) != temp_rnti); mac->run_tti(tti++); + timers->step_all(); } } @@ -1267,6 +1293,7 @@ int run_mac_ra_test(struct ra_test test, mac* mac, phy_dummy* phy, uint32_t* tti TESTASSERT(phy->get_crnti() == (test.crnti ? test.crnti : test.temp_rnti)); TESTASSERT(mac->get_dl_sched_rnti(tti) == (test.crnti ? test.crnti : test.temp_rnti)); tti++; + timers->step_all(); } *tti_state = tti; @@ -1296,6 +1323,8 @@ int mac_random_access_test() rlc_log.set_level(srslte::LOG_LEVEL_DEBUG); rlc_log.set_hex_limit(100000); + srslte::timers timers(64); + // dummy layers phy_dummy phy; phy.set_log(&phy_log); @@ -1314,7 +1343,7 @@ int mac_random_access_test() // Configure MAC mac mac(&mac_log); - mac.init(&phy, &rlc, &rrc); + mac.init(&phy, &rlc, &rrc, &timers); mac_interface_rrc::mac_cfg_t mac_cfg; mac_cfg.set_rach_cfg_common(rach_cfg); mac.set_config(mac_cfg); @@ -1353,11 +1382,12 @@ int mac_random_access_test() mac_log.info("\n=========== Test %d =============\n", test_id++); my_test.rach_cfg = rach_cfg; my_test.nof_prachs = rach_cfg.ra_supervision_info.preamb_trans_max.to_number(); - TESTASSERT(!run_mac_ra_test(my_test, &mac, &phy, &tti)); + TESTASSERT(!run_mac_ra_test(my_test, &mac, &phy, &tti, &timers)); // Make sure it triggers RRC signal mac.run_tti(tti++); TESTASSERT(rrc.rach_problem == 1); + timers.step_all(); // Reset MAC mac.reset(); @@ -1371,7 +1401,7 @@ int mac_random_access_test() my_test.rar_nof_rapid = 1; my_test.nof_prachs = 1; my_test.rar_nof_invalid_rapid = rach_cfg.ra_supervision_info.ra_resp_win_size.to_number(); - TESTASSERT(!run_mac_ra_test(my_test, &mac, &phy, &tti)); + TESTASSERT(!run_mac_ra_test(my_test, &mac, &phy, &tti, &timers)); // Test 3: RAR received but no matching RAPID. Test Msg3 retransmissions // On each HARQ retx, contention resolution timer must be restarted (5.1.5) @@ -1379,7 +1409,7 @@ int mac_random_access_test() mac_log.info("\n=========== Test %d =============\n", test_id++); my_test.rar_nof_invalid_rapid = 0; my_test.nof_msg3_retx = rach_cfg.max_harq_msg3_tx; - TESTASSERT(!run_mac_ra_test(my_test, &mac, &phy, &tti)); + TESTASSERT(!run_mac_ra_test(my_test, &mac, &phy, &tti, &timers)); // Test 4: RAR with valid RAPID. Msg3 transmitted, Msg4 received but invalid ConRes // Contention resolution is defined in 5.1.5. If ConResID does not match, the ConRes is considered @@ -1388,7 +1418,7 @@ int mac_random_access_test() phy.reset(); my_test.nof_msg3_retx = 0; my_test.msg4_enable = true; - TESTASSERT(!run_mac_ra_test(my_test, &mac, &phy, &tti)); + TESTASSERT(!run_mac_ra_test(my_test, &mac, &phy, &tti, &timers)); // Test 5: Msg4 received and valid ConRes. In this case a valid ConResID is received and RA procedure is successful mac_log.info("\n=========== Test %d =============\n", test_id++); @@ -1396,7 +1426,7 @@ int mac_random_access_test() my_test.msg4_valid_conres = true; my_test.check_ra_successful = true; my_test.assume_prach_transmitted = 0; - TESTASSERT(!run_mac_ra_test(my_test, &mac, &phy, &tti)); + TESTASSERT(!run_mac_ra_test(my_test, &mac, &phy, &tti, &timers)); // Test 6: RA with existing C-RNTI (Sends C-RNTI MAC CE) // The transmission of C-RNTI MAC CE is only done if no CCCH is present (5.1.4). @@ -1408,7 +1438,7 @@ int mac_random_access_test() my_test.temp_rnti++; // Temporal C-RNTI has to change to avoid duplicate my_test.assume_prach_transmitted = -1; my_test.send_valid_ul_grant = true; - TESTASSERT(!run_mac_ra_test(my_test, &mac, &phy, &tti)); + TESTASSERT(!run_mac_ra_test(my_test, &mac, &phy, &tti, &timers)); // Test 7: Test Contention based Random Access. This is used eg in HO where preamble is chosen by UE. // It is similar to Test 5 because C-RNTI is available to the UE when start the RA but @@ -1419,6 +1449,7 @@ int mac_random_access_test() phy.set_crnti(0); mac.start_cont_ho(); mac.run_tti(tti++); + timers.step_all(); rrc.ho_finish = false; my_test.nof_prachs = rach_cfg.ra_supervision_info.preamb_trans_max.to_number(); my_test.temp_rnti++; // Temporal C-RNTI has to change to avoid duplicate @@ -1426,7 +1457,7 @@ int mac_random_access_test() my_test.assume_prach_transmitted = 0; my_test.check_ra_successful = false; my_test.send_valid_ul_grant = false; - TESTASSERT(!run_mac_ra_test(my_test, &mac, &phy, &tti)); + TESTASSERT(!run_mac_ra_test(my_test, &mac, &phy, &tti, &timers)); TESTASSERT(!rrc.ho_finish_successful && rrc.ho_finish); // Test 8: Test Contention based Random Access. Same as above but we let the procedure finish successfully. @@ -1435,11 +1466,12 @@ int mac_random_access_test() phy.set_crnti(0); mac.start_cont_ho(); mac.run_tti(tti++); + timers.step_all(); rrc.ho_finish = false; my_test.nof_prachs = 1; my_test.temp_rnti++; // Temporal C-RNTI has to change to avoid duplicate my_test.send_valid_ul_grant = true; - TESTASSERT(!run_mac_ra_test(my_test, &mac, &phy, &tti)); + TESTASSERT(!run_mac_ra_test(my_test, &mac, &phy, &tti, &timers)); TESTASSERT(rrc.ho_finish_successful && rrc.ho_finish); // Test 9: Test non-Contention based HO. Used in HO but preamble is given by the network. In addition to checking @@ -1448,6 +1480,7 @@ int mac_random_access_test() mac_log.info("\n=========== Test %d =============\n", test_id++); phy.set_prach_tti(tti + phy.prach_delay); mac.run_tti(tti++); + timers.step_all(); phy.set_crnti(0); rrc.ho_finish = false; my_test.preamble_idx = 3; @@ -1455,8 +1488,9 @@ int mac_random_access_test() my_test.nof_prachs = rach_cfg.ra_supervision_info.preamb_trans_max.to_number(); my_test.rar_nof_invalid_rapid = rach_cfg.ra_supervision_info.ra_resp_win_size.to_number(); my_test.temp_rnti++; // Temporal C-RNTI has to change to avoid duplicate - TESTASSERT(!run_mac_ra_test(my_test, &mac, &phy, &tti)); + TESTASSERT(!run_mac_ra_test(my_test, &mac, &phy, &tti, &timers)); mac.run_tti(tti++); + timers.step_all(); TESTASSERT(!rrc.ho_finish_successful && rrc.ho_finish); // Test 10: Test non-Contention based HO. Used in HO but preamble is given by the network. We check that @@ -1464,6 +1498,7 @@ int mac_random_access_test() mac_log.info("\n=========== Test %d =============\n", test_id++); phy.set_prach_tti(tti + phy.prach_delay); mac.run_tti(tti++); + timers.step_all(); phy.set_crnti(0); rrc.ho_finish = false; my_test.preamble_idx = 3; @@ -1472,8 +1507,9 @@ int mac_random_access_test() my_test.rar_nof_invalid_rapid = 0; my_test.check_ra_successful = true; my_test.temp_rnti++; // Temporal C-RNTI has to change to avoid duplicate - TESTASSERT(!run_mac_ra_test(my_test, &mac, &phy, &tti)); + TESTASSERT(!run_mac_ra_test(my_test, &mac, &phy, &tti, &timers)); mac.run_tti(tti++); + timers.step_all(); TESTASSERT(rrc.ho_finish_successful && rrc.ho_finish); mac.stop();