From 11532aa66cc3778d7f644b521f7c1c2b6a9db3ee Mon Sep 17 00:00:00 2001 From: Piotr Gawlowicz Date: Tue, 4 Apr 2023 10:26:17 +0200 Subject: [PATCH] e2ap: move ric_subscription from ric_client to e2ap --- srsgnb/hdr/stack/ric/e2ap.h | 38 ++++++++++++------ srsgnb/hdr/stack/ric/ric_client.h | 7 +--- srsgnb/hdr/stack/ric/ric_subscription.h | 13 +++--- srsgnb/src/stack/ric/e2ap.cc | 51 +++++++++++++++++++++--- srsgnb/src/stack/ric/ric_client.cc | 33 +++++---------- srsgnb/src/stack/ric/ric_subscription.cc | 46 +++++++++------------ srsgnb/src/stack/ric/test/e2ap_test.cc | 8 ++-- 7 files changed, 113 insertions(+), 83 deletions(-) diff --git a/srsgnb/hdr/stack/ric/e2ap.h b/srsgnb/hdr/stack/ric/e2ap.h index 0ff57e664..6c7e707ef 100644 --- a/srsgnb/hdr/stack/ric/e2ap.h +++ b/srsgnb/hdr/stack/ric/e2ap.h @@ -22,6 +22,7 @@ #ifndef RIC_E2AP_H #define RIC_E2AP_H +namespace srsenb { using namespace asn1::e2ap; using namespace asn1::e2sm_kpm; @@ -45,16 +46,22 @@ typedef struct { std::vector not_admitted_actions; } ric_subscription_reponse_t; +class ric_client; + class e2ap { public: e2ap(srslog::basic_logger& logger, + ric_client* _ric_client, srsenb::e2_interface_metrics* _gnb_metrics, srsran::task_scheduler* _task_sched_ptr); + ~e2ap(); + e2_ap_pdu_c generate_setup_request(); int process_setup_response(e2setup_resp_s setup_response); int process_setup_failure(); int process_subscription_request(ricsubscription_request_s subscription_request); + int process_ric_subscription_delete_request(ricsubscription_delete_request_s ricsubscription_delete_request); e2_ap_pdu_c generate_subscription_response(ric_subscription_reponse_t ric_subscription_reponse); e2_ap_pdu_c generate_subscription_failure(ric_subscription_reponse_t ric_subscription_reponse); e2_ap_pdu_c generate_subscription_delete_response(ric_subscription_reponse_t ric_subscription_reponse); @@ -75,19 +82,24 @@ public: int process_e2_node_config_update_failure(e2node_cfg_upd_fail_s e2node_config_update_failure); int process_e2_removal_failure(e2_removal_fail_s e2_remove_failure); - int get_reset_id(); - bool get_func_desc(uint32_t ran_func_id, RANfunction_description& fdesc); - bool send_setup_request() { return !e2_established && pending_e2_setup; } + bool queue_send_e2ap_pdu(e2_ap_pdu_c e2ap_pdu); + + int get_reset_id(); + bool get_func_desc(uint32_t ran_func_id, RANfunction_description& fdesc); + bool send_setup_request() { return !e2_established && pending_e2_setup; } + + class ric_subscription; private: - srslog::basic_logger& logger; - e2sm_kpm e2sm_; - bool e2_established = false; - srsran::unique_timer e2_procedure_timeout; - bool pending_e2_setup = true; - bool pending_e2_node_config_update = false; - bool pending_ric_service_update = false; - bool pending_e2_removal = false; + srslog::basic_logger& logger; + ric_client* _ric_client; + e2sm_kpm e2sm_; + bool e2_established = false; + srsran::unique_timer e2_procedure_timeout; + bool pending_e2_setup = true; + bool pending_e2_node_config_update = false; + bool pending_ric_service_update = false; + bool pending_e2_removal = false; int setup_procedure_transaction_id = 0; uint64_t plmn_id = 0x05f510; @@ -100,6 +112,8 @@ private: int reset_transaction_id = 1; cause_c reset_cause = cause_c(); int reset_id = 1; -}; + std::vector > active_subscriptions; +}; +} // namespace srsenb #endif /* RIC_E2AP_H */ diff --git a/srsgnb/hdr/stack/ric/ric_client.h b/srsgnb/hdr/stack/ric/ric_client.h index c99821539..28c998d66 100644 --- a/srsgnb/hdr/stack/ric/ric_client.h +++ b/srsgnb/hdr/stack/ric/ric_client.h @@ -43,6 +43,7 @@ class ric_client : public srsran::thread { public: ric_client(srslog::basic_logger& logger, srsenb::e2_interface_metrics* _gnb_metrics); + ~ric_client() = default; // Initiate and Stop bool init(ric_args_t args); @@ -69,8 +70,6 @@ public: bool handle_reset_response(reset_resp_s& reset_response); bool handle_reset_request(reset_request_s& reset_request); - class ric_subscription; - private: srsran::task_scheduler task_sched; srsran::task_queue_handle ric_rece_task_queue; @@ -80,10 +79,8 @@ private: struct sockaddr_in ric_addr = {}; // RIC address bool running = false; - e2ap e2ap_; srsenb::e2_interface_metrics* gnb_metrics = nullptr; - - std::vector > active_subscriptions; + e2ap e2ap_; }; } // namespace srsenb diff --git a/srsgnb/hdr/stack/ric/ric_subscription.h b/srsgnb/hdr/stack/ric/ric_subscription.h index 24d45567a..7ebbc79e9 100644 --- a/srsgnb/hdr/stack/ric/ric_subscription.h +++ b/srsgnb/hdr/stack/ric/ric_subscription.h @@ -14,19 +14,18 @@ #ifndef SRSRAN_RIC_SUBSCRIPTION_H #define SRSRAN_RIC_SUBSCRIPTION_H -#include "srsgnb/hdr/stack/ric/e2ap.h" -#include "srsgnb/hdr/stack/ric/ric_client.h" +#include "e2ap.h" #include "srsran/common/task_scheduler.h" #include "srsran/common/threads.h" #include "srsran/srsran.h" namespace srsenb { -class ric_client::ric_subscription +class e2ap::ric_subscription { public: - ric_subscription(ric_client* ric_client, ricsubscription_request_s ric_subscription_request); - virtual ~ric_subscription() = default; + ric_subscription(e2ap* e2ap, ricsubscription_request_s ric_subscription_request); + virtual ~ric_subscription() { parent = nullptr; }; uint32_t get_ric_requestor_id() { return ric_requestor_id; }; uint32_t get_ric_instance_id() { return ric_instance_id; }; @@ -45,8 +44,8 @@ private: void _send_ric_indication(); uint32_t _generate_ric_indication_sn(); - ric_client* parent = nullptr; - bool initialized = false; + e2ap* parent = nullptr; + bool initialized = false; uint32_t ric_requestor_id; uint32_t ric_instance_id; diff --git a/srsgnb/src/stack/ric/e2ap.cc b/srsgnb/src/stack/ric/e2ap.cc index 5e20e795a..9b08a4f2e 100644 --- a/srsgnb/src/stack/ric/e2ap.cc +++ b/srsgnb/src/stack/ric/e2ap.cc @@ -1,13 +1,15 @@ #include "srsgnb/hdr/stack/ric/e2ap.h" -#include "stdint.h" +#include "srsgnb/hdr/stack/ric/ric_client.h" +#include "srsgnb/hdr/stack/ric/ric_subscription.h" e2ap::e2ap(srslog::basic_logger& logger, + ric_client* _ric_client, srsenb::e2_interface_metrics* _gnb_metrics, srsran::task_scheduler* _task_sched_ptr) : - logger(logger), e2sm_(logger, _task_sched_ptr), task_sched_ptr(_task_sched_ptr) + logger(logger), _ric_client(_ric_client), e2sm_(logger, _task_sched_ptr), task_sched_ptr(_task_sched_ptr) { - gnb_metrics = _gnb_metrics; + gnb_metrics = _gnb_metrics; e2_procedure_timeout = task_sched_ptr->get_unique_timer(); // register SM to receive enb metrics @@ -21,6 +23,8 @@ e2ap::e2ap(srslog::basic_logger& logger, ran_functions[local_ran_function_id] = add_func; } +e2ap::~e2ap(){}; + bool e2ap::get_func_desc(uint32_t ran_func_id, RANfunction_description& fdesc) { if (ran_functions.count(ran_func_id)) { @@ -30,6 +34,14 @@ bool e2ap::get_func_desc(uint32_t ran_func_id, RANfunction_description& fdesc) return false; } +bool e2ap::queue_send_e2ap_pdu(e2_ap_pdu_c e2ap_pdu) +{ + if (_ric_client) { + _ric_client->queue_send_e2ap_pdu(e2ap_pdu); + } + return true; +} + e2_ap_pdu_c e2ap::generate_setup_request() { e2_ap_pdu_c pdu; @@ -233,9 +245,38 @@ int e2ap::process_setup_response(e2setup_resp_s setup_response) return SRSRAN_SUCCESS; } -int e2ap::process_subscription_request(ricsubscription_request_s subscription_request) +int e2ap::process_subscription_request(ricsubscription_request_s ric_subscription_request) +{ + std::unique_ptr new_ric_subs = + std::make_unique(this, ric_subscription_request); + + if (new_ric_subs->is_initialized()) { + new_ric_subs->start_subscription(); + active_subscriptions.push_back(std::move(new_ric_subs)); + } else { + return false; + } + + return SRSRAN_SUCCESS; +} + +int e2ap::process_ric_subscription_delete_request(ricsubscription_delete_request_s ricsubscription_delete_request) { - // TODO: this function seems to be not needed + bool ric_subs_found = false; + for (auto it = active_subscriptions.begin(); it != active_subscriptions.end(); it++) { + if ((**it).get_ric_requestor_id() == ricsubscription_delete_request->ri_crequest_id->ric_requestor_id and + (**it).get_ric_instance_id() == ricsubscription_delete_request->ri_crequest_id->ric_instance_id) { + ric_subs_found = true; + (**it).delete_subscription(); + active_subscriptions.erase(it); + break; + } + } + + if (not ric_subs_found) { + // TODO: send failure + } + return SRSRAN_SUCCESS; } diff --git a/srsgnb/src/stack/ric/ric_client.cc b/srsgnb/src/stack/ric/ric_client.cc index 010dea651..6d6257c1f 100644 --- a/srsgnb/src/stack/ric/ric_client.cc +++ b/srsgnb/src/stack/ric/ric_client.cc @@ -11,13 +11,15 @@ */ #include "srsgnb/hdr/stack/ric/ric_client.h" -#include "srsgnb/hdr/stack/ric/ric_subscription.h" #include "srsran/asn1/e2ap.h" -#include "stdint.h" using namespace srsenb; ric_client::ric_client(srslog::basic_logger& logger, e2_interface_metrics* _gnb_metrics) : - task_sched(), logger(logger), rx_sockets(), thread("RIC_CLIENT_THREAD"), e2ap_(logger, _gnb_metrics, &task_sched) + task_sched(), + logger(logger), + rx_sockets(), + thread("RIC_CLIENT_THREAD"), + e2ap_(logger, this, _gnb_metrics, &task_sched) { gnb_metrics = _gnb_metrics; } @@ -299,13 +301,8 @@ bool ric_client::handle_ric_subscription_request(ricsubscription_request_s ric_s ric_subscription_request->ri_crequest_id->ric_instance_id, ric_subscription_request->ra_nfunction_id->value); - std::unique_ptr new_ric_subs = - std::make_unique(this, ric_subscription_request); - - if (new_ric_subs->is_initialized()) { - new_ric_subs->start_subscription(); - active_subscriptions.push_back(std::move(new_ric_subs)); - } else { + if (e2ap_.process_subscription_request(ric_subscription_request)) { + logger.error("Failed to process RIC subscription request \n"); return false; } @@ -319,19 +316,9 @@ bool ric_client::handle_ric_subscription_delete_request(ricsubscription_delete_r ricsubscription_delete_request->ri_crequest_id->ric_instance_id, ricsubscription_delete_request->ra_nfunction_id->value); - bool ric_subs_found = false; - for (auto it = active_subscriptions.begin(); it != active_subscriptions.end(); it++) { - if ((**it).get_ric_requestor_id() == ricsubscription_delete_request->ri_crequest_id->ric_requestor_id and - (**it).get_ric_instance_id() == ricsubscription_delete_request->ri_crequest_id->ric_instance_id) { - ric_subs_found = true; - (**it).delete_subscription(); - active_subscriptions.erase(it); - break; - } - } - - if (not ric_subs_found) { - // TODO: send failure + if (e2ap_.process_ric_subscription_delete_request(ricsubscription_delete_request)) { + logger.error("Failed to process RIC subscription delete request \n"); + return false; } return true; diff --git a/srsgnb/src/stack/ric/ric_subscription.cc b/srsgnb/src/stack/ric/ric_subscription.cc index 5c8d5e430..301c870d5 100644 --- a/srsgnb/src/stack/ric/ric_subscription.cc +++ b/srsgnb/src/stack/ric/ric_subscription.cc @@ -13,19 +13,16 @@ #include "srsgnb/hdr/stack/ric/ric_subscription.h" -namespace srsenb { - -ric_client::ric_subscription::ric_subscription(ric_client* ric_client, - ricsubscription_request_s ric_subscription_request) : - parent(ric_client), +e2ap::ric_subscription::ric_subscription(e2ap* e2ap, ricsubscription_request_s ric_subscription_request) : + parent(e2ap), initialized(false), ric_requestor_id(ric_subscription_request->ri_crequest_id->ric_requestor_id), ric_instance_id(ric_subscription_request->ri_crequest_id->ric_instance_id), ra_nfunction_id(ric_subscription_request->ra_nfunction_id->value), - reporting_timer(parent->task_sched.get_unique_timer()) + reporting_timer(parent->task_sched_ptr->get_unique_timer()) { RANfunction_description ran_func_desc; - if (!parent->e2ap_.get_func_desc(ra_nfunction_id, ran_func_desc)) { + if (!parent->get_func_desc(ra_nfunction_id, ran_func_desc)) { parent->logger.debug("Cannot find RAN function with ID: %i\n", ra_nfunction_id); this->_send_subscription_failure(); return; @@ -91,7 +88,7 @@ ric_client::ric_subscription::ric_subscription(ric_client* ric_cli initialized = true; } -void ric_client::ric_subscription::start_subscription() +void e2ap::ric_subscription::start_subscription() { this->_send_subscription_response(); @@ -103,7 +100,7 @@ void ric_client::ric_subscription::start_subscription() } } -void ric_client::ric_subscription::_send_subscription_response() +void e2ap::ric_subscription::_send_subscription_response() { parent->logger.debug("Send RIC Subscription Response to RIC Requestor ID: %i\n", ric_requestor_id); ric_subscription_reponse_t ric_subscription_reponse; @@ -119,11 +116,11 @@ void ric_client::ric_subscription::_send_subscription_response() ric_subscription_reponse.not_admitted_actions.push_back(action); } - e2_ap_pdu_c send_pdu = parent->e2ap_.generate_subscription_response(ric_subscription_reponse); + e2_ap_pdu_c send_pdu = parent->generate_subscription_response(ric_subscription_reponse); parent->queue_send_e2ap_pdu(send_pdu); } -void ric_client::ric_subscription::_send_subscription_failure() +void e2ap::ric_subscription::_send_subscription_failure() { parent->logger.debug("Send RIC Subscription Failure Response to RIC Requestor ID: %i\n", ric_requestor_id); ric_subscription_reponse_t ric_subscription_reponse; @@ -131,11 +128,11 @@ void ric_client::ric_subscription::_send_subscription_failure() ric_subscription_reponse.ric_instance_id = ric_instance_id; ric_subscription_reponse.ra_nfunction_id = ra_nfunction_id; - e2_ap_pdu_c send_pdu = parent->e2ap_.generate_subscription_failure(ric_subscription_reponse); + e2_ap_pdu_c send_pdu = parent->generate_subscription_failure(ric_subscription_reponse); parent->queue_send_e2ap_pdu(send_pdu); } -void ric_client::ric_subscription::delete_subscription() +void e2ap::ric_subscription::delete_subscription() { if (reporting_timer.is_running()) { parent->logger.debug("Stop sending RIC indication msgs"); @@ -153,39 +150,36 @@ void ric_client::ric_subscription::delete_subscription() sm_ptr->remove_ric_action_definition(action); } } else { - e2_ap_pdu_c send_pdu = parent->e2ap_.generate_subscription_delete_failure(ric_subscription_reponse); + e2_ap_pdu_c send_pdu = parent->generate_subscription_delete_failure(ric_subscription_reponse); parent->queue_send_e2ap_pdu(send_pdu); return; } parent->logger.debug("Send RIC Subscription Delete Response to RIC Requestor ID: %i\n", ric_requestor_id); - e2_ap_pdu_c send_pdu = parent->e2ap_.generate_subscription_delete_response(ric_subscription_reponse); + e2_ap_pdu_c send_pdu = parent->generate_subscription_delete_response(ric_subscription_reponse); parent->queue_send_e2ap_pdu(send_pdu); } -bool ric_client::ric_subscription::handle_subscription_modification_request( - uint32_t ric_subscription_modification_request) +bool e2ap::ric_subscription::handle_subscription_modification_request(uint32_t ric_subscription_modification_request) { // TODO: available in e2ap-v3 return false; } -bool ric_client::ric_subscription::handle_subscription_modification_confirm( - uint32_t ric_subscription_modification_confirm) +bool e2ap::ric_subscription::handle_subscription_modification_confirm(uint32_t ric_subscription_modification_confirm) { // TODO: available in e2ap-v3 return false; } -bool ric_client::ric_subscription::handle_subscription_modification_refuse( - uint32_t ric_subscription_modification_refuse) +bool e2ap::ric_subscription::handle_subscription_modification_refuse(uint32_t ric_subscription_modification_refuse) { // TODO: available in e2ap-v3 return false; } -uint32_t ric_client::ric_subscription::_generate_ric_indication_sn() +uint32_t e2ap::ric_subscription::_generate_ric_indication_sn() { uint32_t sn = _ric_indication_sn_gen; _ric_indication_sn_gen++; @@ -195,7 +189,7 @@ uint32_t ric_client::ric_subscription::_generate_ric_indication_sn() return sn; }; -void ric_client::ric_subscription::_send_ric_indication() +void e2ap::ric_subscription::_send_ric_indication() { if (sm_ptr == nullptr) { parent->logger.error("SM pointer not set in subscription: %i\n", ric_requestor_id); @@ -212,7 +206,7 @@ void ric_client::ric_subscription::_send_ric_indication() ric_indication.ri_indication_sn_present = true; ric_indication.ri_indication_sn = _generate_ric_indication_sn(); if (sm_ptr->generate_ric_indication_content(action, ric_indication)) { - e2_ap_pdu_c send_pdu = parent->e2ap_.generate_indication(ric_indication); + e2_ap_pdu_c send_pdu = parent->generate_indication(ric_indication); parent->queue_send_e2ap_pdu(send_pdu); } } @@ -221,6 +215,4 @@ void ric_client::ric_subscription::_send_ric_indication() if (reporting_period) { reporting_timer.run(); } -} - -} // namespace srsenb \ No newline at end of file +} \ No newline at end of file diff --git a/srsgnb/src/stack/ric/test/e2ap_test.cc b/srsgnb/src/stack/ric/test/e2ap_test.cc index 4a8e3ebe9..d34dfc6ba 100644 --- a/srsgnb/src/stack/ric/test/e2ap_test.cc +++ b/srsgnb/src/stack/ric/test/e2ap_test.cc @@ -105,7 +105,7 @@ void test_native_e2ap_setup_request() e2_ap_pdu_c pdu, pdu2; srslog::basic_logger& logger = srslog::fetch_basic_logger("E2AP"); dummy_metrics_interface dummy_metrics; - e2ap e2ap_(logger, &dummy_metrics, NULL); + e2ap e2ap_(logger, nullptr, &dummy_metrics, NULL); pdu = e2ap_.generate_setup_request(); asn1::bit_ref bref(buf->msg, buf->get_tailroom()); @@ -141,7 +141,7 @@ void test_native_e2ap_subscription_response() e2_ap_pdu_c pdu, pdu2; srslog::basic_logger& logger = srslog::fetch_basic_logger("E2AP"); dummy_metrics_interface dummy_metrics; - e2ap e2ap_(logger, &dummy_metrics, NULL); + e2ap e2ap_(logger, nullptr, &dummy_metrics, NULL); ric_subscription_reponse_t ric_subscription_reponse; ric_subscription_reponse.ric_requestor_id = 1021; @@ -169,7 +169,7 @@ void test_native_e2ap_reset_request() e2_ap_pdu_c pdu, pdu2; srslog::basic_logger& logger = srslog::fetch_basic_logger("E2AP"); dummy_metrics_interface dummy_metrics; - e2ap e2ap_(logger, &dummy_metrics, NULL); + e2ap e2ap_(logger, nullptr, &dummy_metrics, NULL); pdu = e2ap_.generate_reset_request(); asn1::bit_ref bref(buf->msg, buf->get_tailroom()); @@ -190,7 +190,7 @@ void test_native_e2ap_reset_response() e2_ap_pdu_c pdu, pdu2; srslog::basic_logger& logger = srslog::fetch_basic_logger("E2AP"); dummy_metrics_interface dummy_metrics; - e2ap e2ap_(logger, &dummy_metrics, NULL); + e2ap e2ap_(logger, nullptr, &dummy_metrics, NULL); pdu = e2ap_.generate_reset_response(); asn1::bit_ref bref(buf->msg, buf->get_tailroom());