diff --git a/lib/include/srslte/interfaces/ue_interfaces.h b/lib/include/srslte/interfaces/ue_interfaces.h index 859a46e83..1c530329a 100644 --- a/lib/include/srslte/interfaces/ue_interfaces.h +++ b/lib/include/srslte/interfaces/ue_interfaces.h @@ -598,8 +598,19 @@ class gw_interface_stack : public gw_interface_nas, public gw_interface_rrc, pub { }; +// Generic Task Management + Timer interface for upper stack +class task_handler_interface_lte +{ +public: + virtual srslte::timer_handler::unique_timer get_unique_timer() = 0; + virtual srslte::task_multiqueue::queue_handler make_task_queue() = 0; + virtual void enqueue_background_task(std::function task) = 0; + virtual void notify_background_task_result(srslte::move_task_t task) = 0; + virtual void defer_callback(uint32_t duration_ms, std::function func) = 0; +}; + // STACK interface for MAC -class stack_interface_mac +class stack_interface_mac : public task_handler_interface_lte { public: virtual void process_pdus() = 0; @@ -607,11 +618,9 @@ public: virtual void start_prach_configuration() = 0; }; -// Generic Task Management + Timer interface for upper stack -class task_handler_interface_lte +// STACK interface for MAC +class stack_interface_nas : public task_handler_interface_lte { -public: - virtual srslte::timer_handler::unique_timer get_unique_timer() = 0; }; // STACK interface for RRC diff --git a/srsue/hdr/stack/ue_stack_lte.h b/srsue/hdr/stack/ue_stack_lte.h index 1f49811ed..710d81dc9 100644 --- a/srsue/hdr/stack/ue_stack_lte.h +++ b/srsue/hdr/stack/ue_stack_lte.h @@ -56,6 +56,7 @@ class ue_stack_lte final : public ue_stack_base, public stack_interface_gw, public stack_interface_mac, public stack_interface_rrc, + public stack_interface_nas, public srslte::thread { public: @@ -128,13 +129,16 @@ public: tti_point get_current_tti() final { return current_tti; } // Task Handling interface - srslte::timer_handler::unique_timer get_unique_timer() override { return timers.get_unique_timer(); } + srslte::timer_handler::unique_timer get_unique_timer() final { return timers.get_unique_timer(); } + srslte::task_multiqueue::queue_handler make_task_queue() final { return pending_tasks.get_queue_handler(); } + void enqueue_background_task(std::function f) final; + void notify_background_task_result(srslte::move_task_t task) final; + void defer_callback(uint32_t duration_ms, std::function func) final; private: - void run_thread() final; - void run_tti_impl(uint32_t tti, uint32_t tti_jump); - void calc_tti_stats(const uint32_t duration_us);; - void stop_impl(); + void run_thread() final; + void run_tti_impl(uint32_t tti, uint32_t tti_jump); + void stop_impl(); const uint32_t TTI_STAT_PERIOD = 1024; const std::chrono::milliseconds TTI_WARN_THRESHOLD_MS{5}; diff --git a/srsue/hdr/stack/upper/nas.h b/srsue/hdr/stack/upper/nas.h index ac949a4df..204a05606 100644 --- a/srsue/hdr/stack/upper/nas.h +++ b/srsue/hdr/stack/upper/nas.h @@ -40,7 +40,7 @@ namespace srsue { class nas : public nas_interface_rrc, public nas_interface_ue, public srslte::timer_callback { public: - nas(srsue::task_handler_interface_lte* task_handler_); + explicit nas(srsue::stack_interface_nas* task_handler_); void init(usim_interface_nas* usim_, rrc_interface_nas* rrc_, gw_interface_nas* gw_, const nas_args_t& args_); void stop(); void run_tti(); diff --git a/srsue/src/stack/ue_stack_lte.cc b/srsue/src/stack/ue_stack_lte.cc index 6aaed23a6..7dad7714b 100644 --- a/srsue/src/stack/ue_stack_lte.cc +++ b/srsue/src/stack/ue_stack_lte.cc @@ -357,6 +357,26 @@ void ue_stack_lte::start_prach_configuration() }); } +/*************************** + * Task Handling Interface + **************************/ + +void ue_stack_lte::enqueue_background_task(std::function f) +{ + background_tasks.push_task(std::move(f)); +} + +void ue_stack_lte::notify_background_task_result(srslte::move_task_t task) +{ + // run the notification in the stack thread + pending_tasks.push(background_queue_id, std::move(task)); +} + +void ue_stack_lte::defer_callback(uint32_t duration_ms, std::function func) +{ + timers.defer_callback(duration_ms, func); +} + /******************** * RRC Interface *******************/ diff --git a/srsue/src/stack/upper/nas.cc b/srsue/src/stack/upper/nas.cc index 81f7d91ad..6dccee1ff 100644 --- a/srsue/src/stack/upper/nas.cc +++ b/srsue/src/stack/upper/nas.cc @@ -235,7 +235,7 @@ proc_outcome_t nas::rrc_connect_proc::react(nas::rrc_connect_proc::connection_re * NAS ********************************************************************/ -nas::nas(srsue::task_handler_interface_lte* task_handler_) : +nas::nas(srsue::stack_interface_nas* task_handler_) : pool(byte_buffer_pool::get_instance()), plmn_searcher(this), rrc_connector(this), diff --git a/srsue/test/common/dummy_classes.h b/srsue/test/common/dummy_classes.h index b709de6af..7f0d576d0 100644 --- a/srsue/test/common/dummy_classes.h +++ b/srsue/test/common/dummy_classes.h @@ -26,13 +26,23 @@ namespace srsue { -class stack_dummy_interface : public stack_interface_rrc +class stack_dummy_interface : public stack_interface_rrc, public stack_interface_mac, public stack_interface_nas { public: srslte::timer_handler::unique_timer get_unique_timer() override { return timers.get_unique_timer(); } void start_cell_search() override {} void start_cell_select(const phy_interface_rrc_lte::phy_cell_t* cell) override {} srslte::tti_point get_current_tti() override { return srslte::tti_point{timers.get_cur_time() % 10240}; } + srslte::task_multiqueue::queue_handler make_task_queue() final { return pending_tasks.get_queue_handler(); } + void enqueue_background_task(std::function f) override { f(0); } + void notify_background_task_result(srslte::move_task_t task) override { task(); } + void defer_callback(uint32_t duration_ms, std::function func) final + { + timers.defer_callback(duration_ms, func); + } + void process_pdus() override {} + void wait_ra_completion(uint16_t rnti) override {} + void start_prach_configuration() override {} srslte::timer_handler timers{100}; srslte::task_multiqueue pending_tasks; diff --git a/srsue/test/mac_test.cc b/srsue/test/mac_test.cc index 6af250498..f4b29b480 100644 --- a/srsue/test/mac_test.cc +++ b/srsue/test/mac_test.cc @@ -335,7 +335,7 @@ public: uint32_t rach_problem = 0; }; -class stack_dummy : public stack_interface_mac +class stack_dummy : public stack_dummy_interface { public: void init(mac* mac_, phy_interface_mac_lte* phy_) diff --git a/srsue/test/upper/rrc_meas_test.cc b/srsue/test/upper/rrc_meas_test.cc index f90b3f505..f71779de4 100644 --- a/srsue/test/upper/rrc_meas_test.cc +++ b/srsue/test/upper/rrc_meas_test.cc @@ -108,7 +108,7 @@ private: class nas_test : public srsue::nas { public: - nas_test(srsue::task_handler_interface_lte* t) : srsue::nas(t) {} + nas_test(srsue::stack_interface_nas* t) : srsue::nas(t) {} bool is_attached() override { return false; } }; @@ -118,7 +118,7 @@ public: pdcp_test(srslte::log* log_, srslte::timer_handler* t) : srslte::pdcp(t, log_) {} void write_sdu(uint32_t lcid, srslte::unique_byte_buffer_t sdu, bool blocking = false) override { - ul_dcch_msg_s ul_dcch_msg; + ul_dcch_msg_s ul_dcch_msg; asn1::cbit_ref bref(sdu->msg, sdu->N_bytes); if (ul_dcch_msg.unpack(bref) != asn1::SRSASN_SUCCESS or ul_dcch_msg.msg.type().value != ul_dcch_msg_type_c::types_opts::c1) { @@ -259,8 +259,8 @@ public: private: std::unique_ptr pdcptest; std::unique_ptr nastest; - uint32_t tti = 0; - srslte::byte_buffer_pool* pool = nullptr; + uint32_t tti = 0; + srslte::byte_buffer_pool* pool = nullptr; }; // Test Cell sear