From ad63115f310477038dd5b3198ef6b68940446ba8 Mon Sep 17 00:00:00 2001 From: Piotr Gawlowicz Date: Fri, 31 Mar 2023 13:15:36 +0200 Subject: [PATCH] e2sm_kpm: measurement collection triggered by timer every granul_period from action def --- srsgnb/hdr/stack/ric/e2sm.h | 15 +++++- srsgnb/hdr/stack/ric/e2sm_kpm.h | 2 +- .../hdr/stack/ric/e2sm_kpm_report_service.h | 14 ++++-- srsgnb/src/stack/ric/e2ap.cc | 2 +- srsgnb/src/stack/ric/e2sm_kpm.cc | 9 ++-- .../src/stack/ric/e2sm_kpm_report_service.cc | 49 ++++++++++++++++++- 6 files changed, 76 insertions(+), 15 deletions(-) diff --git a/srsgnb/hdr/stack/ric/e2sm.h b/srsgnb/hdr/stack/ric/e2sm.h index c3e975ed6..5fcb50e10 100644 --- a/srsgnb/hdr/stack/ric/e2sm.h +++ b/srsgnb/hdr/stack/ric/e2sm.h @@ -13,6 +13,7 @@ #include "srsran/asn1/e2ap.h" #include "srsran/common/byte_buffer.h" +#include "srsran/common/task_scheduler.h" #include "srsran/interfaces/enb_metrics_interface.h" #include "srsran/srsran.h" @@ -52,8 +53,16 @@ class e2sm { public: e2sm(); - e2sm(std::string short_name, std::string oid, std::string func_description, uint32_t revision) : - _short_name(short_name), _oid(oid), _func_description(func_description), _revision(revision){}; + e2sm(std::string short_name, + std::string oid, + std::string func_description, + uint32_t revision, + srsran::task_scheduler* _task_sched_ptr) : + _short_name(short_name), + _oid(oid), + _func_description(func_description), + _revision(revision), + task_sched_ptr(_task_sched_ptr){}; virtual ~e2sm() = default; std::string get_short_name() { return _short_name; }; @@ -75,6 +84,8 @@ protected: uint32_t _get_local_action_id() { return _registered_action_id_gen; }; uint32_t _generate_new_local_action_id() { return _registered_action_id_gen++; }; + srsran::task_scheduler* task_sched_ptr = nullptr; + private: const std::string _short_name; const std::string _oid; diff --git a/srsgnb/hdr/stack/ric/e2sm_kpm.h b/srsgnb/hdr/stack/ric/e2sm_kpm.h index cc087e3f0..f36ceba83 100644 --- a/srsgnb/hdr/stack/ric/e2sm_kpm.h +++ b/srsgnb/hdr/stack/ric/e2sm_kpm.h @@ -33,7 +33,7 @@ public: static const std::string func_description; static const uint32_t revision; - e2sm_kpm(srslog::basic_logger& logger_); + e2sm_kpm(srslog::basic_logger& logger_, srsran::task_scheduler* _task_sched_ptr); ~e2sm_kpm() = default; virtual bool generate_ran_function_description(RANfunction_description& desc, ra_nfunction_item_s& ran_func); diff --git a/srsgnb/hdr/stack/ric/e2sm_kpm_report_service.h b/srsgnb/hdr/stack/ric/e2sm_kpm_report_service.h index 6463b77bd..65b4d66cd 100644 --- a/srsgnb/hdr/stack/ric/e2sm_kpm_report_service.h +++ b/srsgnb/hdr/stack/ric/e2sm_kpm_report_service.h @@ -16,6 +16,7 @@ #include "srsran/asn1/e2ap.h" #include "srsran/asn1/e2sm.h" #include "srsran/asn1/e2sm_kpm_v2.h" +#include "srsran/common/timers.h" #include "srsran/srsran.h" #ifndef SRSRAN_E2SM_KPM_ACTION_DATA_H @@ -37,6 +38,11 @@ public: virtual bool is_ric_ind_ready() = 0; virtual bool clear_collected_data() = 0; + virtual bool _start_meas_collection(); + bool stop(); + virtual bool _stop_meas_collection(); + virtual bool _reschedule_meas_collection(); + std::vector _get_present_labels(const meas_info_item_s& action_meas_info_item); meas_record_item_c::types _get_meas_data_type(std::string meas_name, e2sm_kpm_label_enum label, meas_record_l& meas_record_list); @@ -51,12 +57,14 @@ public: e2_sm_kpm_ind_hdr_s ric_ind_header_generic; e2_sm_kpm_ind_msg_s ric_ind_message_generic; - uint64_t granul_period = 0; - bool cell_global_id_present = false; - cgi_c cell_global_id; + bool cell_global_id_present = false; + cgi_c cell_global_id; // hdr format 1 in base class, as all types use it e2_sm_kpm_ind_hdr_format1_s& ric_ind_header; + + uint32_t granul_period = 0; + srsran::unique_timer meas_collection_timer; // for measurements collection }; class e2sm_kpm_report_service_style1 : public e2sm_kpm_report_service diff --git a/srsgnb/src/stack/ric/e2ap.cc b/srsgnb/src/stack/ric/e2ap.cc index 6b8b40dbc..5e20e795a 100644 --- a/srsgnb/src/stack/ric/e2ap.cc +++ b/srsgnb/src/stack/ric/e2ap.cc @@ -5,7 +5,7 @@ e2ap::e2ap(srslog::basic_logger& logger, srsenb::e2_interface_metrics* _gnb_metrics, srsran::task_scheduler* _task_sched_ptr) : - logger(logger), e2sm_(logger), task_sched_ptr(_task_sched_ptr) + logger(logger), e2sm_(logger, _task_sched_ptr), task_sched_ptr(_task_sched_ptr) { gnb_metrics = _gnb_metrics; e2_procedure_timeout = task_sched_ptr->get_unique_timer(); diff --git a/srsgnb/src/stack/ric/e2sm_kpm.cc b/srsgnb/src/stack/ric/e2sm_kpm.cc index da5873feb..2ae84f57d 100644 --- a/srsgnb/src/stack/ric/e2sm_kpm.cc +++ b/srsgnb/src/stack/ric/e2sm_kpm.cc @@ -21,7 +21,8 @@ const std::string e2sm_kpm::oid = "1.3.6.1.4.1.53148.1.2.2.2"; const std::string e2sm_kpm::func_description = "KPM Monitor"; const uint32_t e2sm_kpm::revision = 0; -e2sm_kpm::e2sm_kpm(srslog::basic_logger& logger_) : e2sm(short_name, oid, func_description, revision), logger(logger_) +e2sm_kpm::e2sm_kpm(srslog::basic_logger& logger_, srsran::task_scheduler* _task_sched_ptr) : + e2sm(short_name, oid, func_description, revision, _task_sched_ptr), logger(logger_) { random_gen = srsran_random_init(1234); @@ -215,6 +216,7 @@ bool e2sm_kpm::process_ric_action_definition(ri_caction_to_be_setup_item_s ric_a bool e2sm_kpm::remove_ric_action_definition(E2AP_RIC_action_t& action_entry) { if (registered_actions_data.count(action_entry.sm_local_ric_action_id)) { + registered_actions_data.at(action_entry.sm_local_ric_action_id)->stop(); delete registered_actions_data.at(action_entry.sm_local_ric_action_id); registered_actions_data.erase(action_entry.sm_local_ric_action_id); return true; @@ -295,11 +297,6 @@ void e2sm_kpm::receive_e2_metrics_callback(const enb_metrics_t& m) { last_enb_metrics = m; logger.debug("e2sm_kpm received new enb metrics, CPU0 Load: %.1f", last_enb_metrics.sys.cpu_load[0]); - - for (auto& it : registered_actions_data) { - e2sm_kpm_report_service* report_service = it.second; - report_service->collect_meas_data(); - } } bool e2sm_kpm::_collect_integer_type_meas_value(E2SM_KPM_meas_def_t& meas_value, meas_record_item_c& item) diff --git a/srsgnb/src/stack/ric/e2sm_kpm_report_service.cc b/srsgnb/src/stack/ric/e2sm_kpm_report_service.cc index c55a6bea3..d342bcaae 100644 --- a/srsgnb/src/stack/ric/e2sm_kpm_report_service.cc +++ b/srsgnb/src/stack/ric/e2sm_kpm_report_service.cc @@ -20,7 +20,8 @@ e2sm_kpm_report_service::e2sm_kpm_report_service(e2sm_kpm* e action_id(action_id), action_def_generic(action_definition), ric_ind_header_generic(), - ric_ind_header(ric_ind_header_generic.ind_hdr_formats.ind_hdr_format1()) + ric_ind_header(ric_ind_header_generic.ind_hdr_formats.ind_hdr_format1()), + meas_collection_timer(parent->task_sched_ptr->get_unique_timer()) { } @@ -84,6 +85,43 @@ meas_record_item_c::types e2sm_kpm_report_service::_get_meas_data_type(std::stri return data_type; } +bool e2sm_kpm_report_service::_start_meas_collection() +{ + if (granul_period) { + printf("Start collecting measurements every %i ms\n", granul_period); + parent->logger.debug("Start collecting measurements every every %i ms", granul_period); + meas_collection_timer.set(granul_period, [this](uint32_t tid) { this->collect_meas_data(); }); + meas_collection_timer.run(); + return true; + } + return false; +} + +bool e2sm_kpm_report_service::stop() +{ + return _stop_meas_collection(); +} + +bool e2sm_kpm_report_service::_stop_meas_collection() +{ + if (meas_collection_timer.is_running()) { + printf("Stop collecting measurements every %i ms\n", granul_period); + parent->logger.debug("Stop collecting measurements every %i ms\n", granul_period); + meas_collection_timer.stop(); + return true; + } + return false; +} + +bool e2sm_kpm_report_service::_reschedule_meas_collection() +{ + if (granul_period) { + meas_collection_timer.run(); + return true; + } + return false; +} + e2sm_kpm_report_service_style1::e2sm_kpm_report_service_style1(e2sm_kpm* e2sm_kpm, uint16_t action_id, e2_sm_kpm_action_definition_s action_definition) : @@ -100,13 +138,17 @@ e2sm_kpm_report_service_style1::e2sm_kpm_report_service_style1(e2sm_kpm* this->_initialize_ric_ind_hdr(); this->_initialize_ric_ind_msg(); + + granul_period = 1000; // TODO: overwrite for testing + _start_meas_collection(); } bool e2sm_kpm_report_service_style1::_initialize_ric_ind_msg() { meas_info_list_l action_meas_info_list = action_def.meas_info_list; - // ric_ind_message.granul_period = action.granul_period; // not implemented by flexric and crashes it + // ric_ind_message.granul_period_present = true; + // ric_ind_message.granul_period = granul_period; // TODO: our asn1 has some issues with this field ric_ind_message.granul_period = 0; ric_ind_message.meas_info_list.resize(action_meas_info_list.size()); ric_ind_message.meas_data.resize(action_meas_info_list.size()); @@ -354,6 +396,9 @@ bool e2sm_kpm_report_service_style1::collect_meas_data() meas_data_item.meas_record.push_back(item); } } + + // reschedule measurement collection + _reschedule_meas_collection(); return true; }