From 5d79e89a3d47fa9f38550caabc0fe5b342cde517 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 5 Oct 2022 14:38:31 +0100 Subject: [PATCH] s1ap: run connect in background thread to avoid blocking --- srsenb/hdr/stack/s1ap/s1ap.h | 8 +++++-- srsenb/src/stack/s1ap/s1ap.cc | 41 +++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/srsenb/hdr/stack/s1ap/s1ap.h b/srsenb/hdr/stack/s1ap/s1ap.h index 15951086f..fcfc14b9e 100644 --- a/srsenb/hdr/stack/s1ap/s1ap.h +++ b/srsenb/hdr/stack/s1ap/s1ap.h @@ -108,7 +108,7 @@ public: // Stack interface bool - handle_mme_rx_msg(srsran::unique_byte_buffer_t pdu, const sockaddr_in& from, const sctp_sndrcvinfo& sri, int flags); + handle_mme_rx_msg(srsran::unique_byte_buffer_t pdu, const sockaddr_in& from, const sctp_sndrcvinfo& sri, int flags); void start_pcap(srsran::s1ap_pcap* pcap_); private: @@ -263,7 +263,7 @@ private: bool was_uectxtrelease_requested() const { return release_requested; } void - set_state(s1ap_proc_id_t state, const erab_id_list& erabs_updated, const erab_item_list& erabs_failed_to_update); + set_state(s1ap_proc_id_t state, const erab_id_list& erabs_updated, const erab_item_list& erabs_failed_to_update); s1ap_proc_id_t get_state() const { return current_state; } ue_ctxt_t ctxt = {}; @@ -330,10 +330,14 @@ private: bool success = false; enum class cause_t { timeout, failure } cause; }; + struct s1connectresult { + bool success = false; + }; explicit s1_setup_proc_t(s1ap* s1ap_) : s1ap_ptr(s1ap_) {} srsran::proc_outcome_t init(); srsran::proc_outcome_t step() { return srsran::proc_outcome_t::yield; } + srsran::proc_outcome_t react(const s1connectresult& event); srsran::proc_outcome_t react(const s1setupresult& event); void then(const srsran::proc_state_t& result); const char* name() const { return "MME Connection"; } diff --git a/srsenb/src/stack/s1ap/s1ap.cc b/srsenb/src/stack/s1ap/s1ap.cc index 0a4e9e547..1fba0eae2 100644 --- a/srsenb/src/stack/s1ap/s1ap.cc +++ b/srsenb/src/stack/s1ap/s1ap.cc @@ -237,21 +237,38 @@ srsran::proc_outcome_t s1ap::s1_setup_proc_t::start_mme_connection() return srsran::proc_outcome_t::success; } - if (not s1ap_ptr->connect_mme()) { - procInfo("Could not connect to MME"); - return srsran::proc_outcome_t::error; - } + auto connect_callback = [this]() { + bool connected = s1ap_ptr->connect_mme(); + + auto notify_result = [this, connected]() { + s1_setup_proc_t::s1connectresult res; + res.success = connected; + s1ap_ptr->s1setup_proc.trigger(res); + }; + s1ap_ptr->task_sched.notify_background_task_result(notify_result); + }; + srsran::get_background_workers().push_task(connect_callback); - if (not s1ap_ptr->setup_s1()) { - procError("S1 setup failed. Exiting..."); - srsran::console("S1 setup failed\n"); - s1ap_ptr->running = false; - return srsran::proc_outcome_t::error; + return srsran::proc_outcome_t::yield; +} + +srsran::proc_outcome_t s1ap::s1_setup_proc_t::react(const srsenb::s1ap::s1_setup_proc_t::s1connectresult& event) +{ + if (event.success) { + procInfo("Connected to MME. Sending S1 setup request."); + s1ap_ptr->s1setup_timeout.run(); + if (not s1ap_ptr->setup_s1()) { + procError("S1 setup failed. Exiting..."); + srsran::console("S1 setup failed\n"); + s1ap_ptr->running = false; + return srsran::proc_outcome_t::error; + } + procInfo("S1 setup request sent. Waiting for response."); + return srsran::proc_outcome_t::yield; } - s1ap_ptr->s1setup_timeout.run(); - procInfo("S1SetupRequest sent. Waiting for response..."); - return srsran::proc_outcome_t::yield; + procInfo("Could not connected to MME. Aborting"); + return srsran::proc_outcome_t::error; } srsran::proc_outcome_t s1ap::s1_setup_proc_t::react(const srsenb::s1ap::s1_setup_proc_t::s1setupresult& event)