From e859d622c71e91131f53ca544ffb80942e273257 Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Thu, 27 Feb 2020 12:41:38 +0000 Subject: [PATCH] added logref class to forbid logmap pointer invalidation. Created a test for the logref, and introduced it in the scheduler, rrc and nas --- lib/include/srslte/common/log.h | 4 +- lib/include/srslte/common/logmap.h | 122 +++++++++++++++------- lib/test/asn1/ngap_asn1_test.cc | 6 +- lib/test/asn1/rrc_asn1_test.cc | 8 +- lib/test/asn1/s1ap_test.cc | 4 +- lib/test/common/log_filter_test.cc | 27 +++-- lib/test/common/pdu_test.cc | 11 +- lib/test/common/test_common_test.cc | 8 +- srsenb/hdr/stack/mac/scheduler.h | 2 +- srsenb/hdr/stack/mac/scheduler_carrier.h | 10 +- srsenb/hdr/stack/mac/scheduler_grid.h | 8 +- srsenb/hdr/stack/mac/scheduler_harq.h | 2 +- srsenb/hdr/stack/mac/scheduler_metric.h | 8 +- srsenb/hdr/stack/mac/scheduler_ue.h | 8 +- srsenb/hdr/stack/rrc/rrc_mobility.h | 7 +- srsenb/hdr/stack/upper/s1ap.h | 12 +-- srsenb/src/stack/enb_stack_lte.cc | 2 +- srsenb/src/stack/mac/scheduler.cc | 2 +- srsenb/src/stack/mac/scheduler_carrier.cc | 6 +- srsenb/src/stack/rrc/rrc.cc | 2 +- srsenb/src/stack/rrc/rrc_mobility.cc | 10 +- srsenb/src/stack/upper/s1ap.cc | 4 +- srsenb/test/mac/scheduler_test_rand.cc | 2 +- srsenb/test/upper/erab_setup_test.cc | 2 +- srsenb/test/upper/rrc_mobility_test.cc | 10 +- srsue/hdr/stack/upper/nas.h | 12 +-- srsue/src/main.cc | 2 +- srsue/src/stack/ue_stack_lte.cc | 2 +- srsue/test/ttcn3/src/ttcn3_dut.cc | 2 +- srsue/test/upper/nas_test.cc | 4 +- 30 files changed, 181 insertions(+), 128 deletions(-) diff --git a/lib/include/srslte/common/log.h b/lib/include/srslte/common/log.h index a28a5aff5..0c8c9cce2 100644 --- a/lib/include/srslte/common/log.h +++ b/lib/include/srslte/common/log.h @@ -112,8 +112,8 @@ public: } } - LOG_LEVEL_ENUM get_level() { return level; } - std::string get_service_name() { return service_name; } + LOG_LEVEL_ENUM get_level() { return level; } + const std::string& get_service_name() const { return service_name; } void set_hex_limit(int limit) { hex_limit = limit; } int get_hex_limit() { return hex_limit; } diff --git a/lib/include/srslte/common/logmap.h b/lib/include/srslte/common/logmap.h index 06a861789..b86810b63 100644 --- a/lib/include/srslte/common/logmap.h +++ b/lib/include/srslte/common/logmap.h @@ -34,74 +34,116 @@ namespace srslte { class log_filter; +class log_ref +{ + using ptr_type = std::unique_ptr*; + +public: + log_ref() = default; + explicit log_ref(ptr_type p) : ptr_(p) {} + + // works like a log* + log* operator->() { return ptr_->get(); } + log* operator->() const { return ptr_->get(); } + + // in case we want to obtain log* + log* operator*() { return ptr_->get(); } + log* get() { return ptr_->get(); } + + // identity defined by ref address + bool operator==(const log_ref& l) { return ptr_ == l.ptr_; } + + // to do checks like if(log_ref) + operator bool() { return ptr_ != nullptr; } + +private: + ptr_type ptr_ = nullptr; +}; + class logmap : public singleton_t { + static const size_t servicename_minimum_length = 4; + using it_t = std::unordered_map >::iterator; + public: // Access to log map by servicename. If servicename does not exist, create a new log_filter with default cfg // Access to the map is protected by a mutex - static log* get(const std::string& servicename) + static log_ref get(std::string servicename) { - logmap* pool = get_instance(); - std::lock_guard lock(pool->mutex); - auto it = pool->log_map.find(servicename); - if (it == pool->log_map.end()) { - // create a new logger with default cfg - std::unique_ptr filter(new log_filter{servicename, pool->default_logger}); - filter->set_level(pool->default_log_level); - filter->set_hex_limit(pool->default_hex_limit); - auto ret = pool->log_map.insert(std::make_pair(servicename, std::move(filter))); - std::unique_ptr& inserted = ret.first->second; - return inserted.get(); + logmap* pool = get_instance(); + if (servicename.size() < servicename_minimum_length) { + // pad right of string with spaces + servicename.insert(servicename.end(), servicename_minimum_length - servicename.length(), ' '); } - return it->second.get(); + return pool->get_impl(std::move(servicename)); } - // set default logger - void set_default_logger(logger* logger_) + // register manually created log + static void register_log(std::unique_ptr log_ptr) { - std::lock_guard lock(mutex); - default_logger = logger_; + logmap* pool = get_instance(); + std::lock_guard lock(pool->mutex); + if (log_ptr != nullptr) { + pool->log_map[log_ptr->get_service_name()] = std::move(log_ptr); + } } - // set default log level - void set_default_log_level(LOG_LEVEL_ENUM l) + static std::unique_ptr deregister_log(const std::string& servicename) { - std::lock_guard lock(mutex); - default_log_level = l; + logmap* pool = get_instance(); + std::unique_ptr ret; + std::lock_guard lock(pool->mutex); + auto it = pool->log_map.find(servicename); + if (it != pool->log_map.end()) { + ret = std::move(it->second); + pool->log_map.erase(it); + } + return ret; } - // set default hex limit - void set_default_hex_limit(int hex_limit) + // set default logger + static void set_default_logger(logger* logger_) { - std::lock_guard lock(mutex); - default_hex_limit = hex_limit; + logmap* pool = get_instance(); + std::lock_guard lock(pool->mutex); + pool->default_logger = logger_; } - // register manually created log - void register_log(std::unique_ptr log_ptr) + // set default log level + static void set_default_log_level(LOG_LEVEL_ENUM l) { - std::lock_guard lock(mutex); - if (log_ptr != nullptr) { - log_map[log_ptr->get_service_name()] = std::move(log_ptr); - } + logmap* pool = get_instance(); + std::lock_guard lock(pool->mutex); + pool->default_log_level = l; } - std::unique_ptr deregister_log(const std::string& servicename) + // set default hex limit + static void set_default_hex_limit(int hex_limit) { - std::unique_ptr ret; - std::lock_guard lock(mutex); - auto it = log_map.find(servicename); - if (it != log_map.end()) { - ret = std::move(it->second); - log_map.erase(it); - } - return ret; + logmap* pool = get_instance(); + std::lock_guard lock(pool->mutex); + pool->default_hex_limit = hex_limit; } protected: logmap() : default_logger(&logger_stdout_val) {} private: + log_ref get_impl(std::string servicename) + { + std::lock_guard lock(mutex); + auto it = log_map.find(servicename); + if (it == log_map.end()) { + // create a new logger with default cfg + std::unique_ptr filter(new log_filter{std::move(servicename), default_logger}); + filter->set_level(default_log_level); + filter->set_hex_limit(default_hex_limit); + auto ret = log_map.insert(std::make_pair(filter->get_service_name(), std::move(filter))); + return log_ref{&ret.first->second}; + } + return log_ref{&it->second}; + } + // consts logger_stdout logger_stdout_val; diff --git a/lib/test/asn1/ngap_asn1_test.cc b/lib/test/asn1/ngap_asn1_test.cc index 53f0cacb0..5a322fe72 100644 --- a/lib/test/asn1/ngap_asn1_test.cc +++ b/lib/test/asn1/ngap_asn1_test.cc @@ -345,9 +345,9 @@ int test_session_res_setup_request() int main() { - srslte::logmap::get_instance()->set_default_log_level(LOG_LEVEL_DEBUG); - srsasn_log_register_handler(srslte::logmap::get("ASN1")); - ngap_nr_log_register_handler(srslte::logmap::get("NGAP")); + srslte::logmap::set_default_log_level(LOG_LEVEL_DEBUG); + srsasn_log_register_handler(srslte::logmap::get("ASN1").get()); + ngap_nr_log_register_handler(srslte::logmap::get("NGAP").get()); TESTASSERT(test_amf_upd() == 0); TESTASSERT(test_ngsetup_request() == 0); diff --git a/lib/test/asn1/rrc_asn1_test.cc b/lib/test/asn1/rrc_asn1_test.cc index f957a1d16..af800fb20 100644 --- a/lib/test/asn1/rrc_asn1_test.cc +++ b/lib/test/asn1/rrc_asn1_test.cc @@ -44,7 +44,7 @@ int test_generic() TESTASSERT(null_log.last_log_msg == test_str); TESTASSERT(null_log.last_log_level == LOG_LEVEL_INFO); // go back to original logger - rrc_log_register_handler(srslte::logmap::get("RRC ")); + rrc_log_register_handler(srslte::logmap::get("RRC ").get()); } // Test deep copy of choice types @@ -599,9 +599,9 @@ int test_rrc_conn_reconf_r15_2() int main() { - srslte::logmap::get_instance()->set_default_log_level(LOG_LEVEL_DEBUG); - srsasn_log_register_handler(srslte::logmap::get("ASN1")); - rrc_log_register_handler(srslte::logmap::get("RRC ")); + srslte::logmap::set_default_log_level(LOG_LEVEL_DEBUG); + srsasn_log_register_handler(srslte::logmap::get("ASN1").get()); + rrc_log_register_handler(srslte::logmap::get("RRC ").get()); TESTASSERT(test_generic() == 0); TESTASSERT(test_json_printer() == 0); diff --git a/lib/test/asn1/s1ap_test.cc b/lib/test/asn1/s1ap_test.cc index 65d921b43..03b72c010 100644 --- a/lib/test/asn1/s1ap_test.cc +++ b/lib/test/asn1/s1ap_test.cc @@ -133,8 +133,8 @@ int test_eci_pack() int main() { - srslte::logmap::get_instance()->set_default_log_level(LOG_LEVEL_DEBUG); - srslte::logmap::get_instance()->set_default_hex_limit(1024); + srslte::logmap::set_default_log_level(LOG_LEVEL_DEBUG); + srslte::logmap::set_default_hex_limit(1024); TESTASSERT(unpack_test_served_gummeis_with_multiple_plmns() == SRSLTE_SUCCESS); TESTASSERT(test_initial_ctxt_setup_response() == SRSLTE_SUCCESS); diff --git a/lib/test/common/log_filter_test.cc b/lib/test/common/log_filter_test.cc index ddeec5f15..ab97e1481 100644 --- a/lib/test/common/log_filter_test.cc +++ b/lib/test/common/log_filter_test.cc @@ -142,17 +142,27 @@ int basic_hex_test() int test_log_singleton() { - srslte::logmap::get_instance()->set_default_log_level(LOG_LEVEL_DEBUG); - srslte::log* log_ptr = srslte::logmap::get("LAYER1"); - TESTASSERT(log_ptr->get_service_name() == "LAYER1"); - TESTASSERT(log_ptr->get_level() == LOG_LEVEL_DEBUG); - // register logger manually + srslte::logmap::set_default_log_level(LOG_LEVEL_DEBUG); + + // TEST: Check if default setters are working + srslte::log_ref log1 = srslte::logmap::get("LAYER1"); + TESTASSERT(log1->get_service_name() == "LAYER1"); + TESTASSERT(log1->get_level() == LOG_LEVEL_DEBUG); + + // TEST: register logger manually. Verify log_ref stays valid after overwrite std::unique_ptr log_ptr2(new srslte::log_filter("LAYER2")); log_ptr2->set_level(LOG_LEVEL_WARNING); - TESTASSERT(srslte::logmap::get("LAYER2")->get_level() == LOG_LEVEL_DEBUG); - srslte::logmap::get_instance()->register_log(std::move(log_ptr2)); - TESTASSERT(srslte::logmap::get("LAYER2")->get_level() == LOG_LEVEL_WARNING); + srslte::log_ref old_ref = srslte::logmap::get("LAYER2"); + TESTASSERT(old_ref->get_level() == LOG_LEVEL_DEBUG); + srslte::logmap::register_log(std::move(log_ptr2)); + srslte::log_ref new_ref = srslte::logmap::get("LAYER2"); + TESTASSERT(new_ref->get_level() == LOG_LEVEL_WARNING); + TESTASSERT(old_ref == new_ref); + // TEST: padding working correctly + TESTASSERT(srslte::logmap::get("MAC").get() == srslte::logmap::get("MAC ").get()); + + log1->info("logmap test finished successfully\n"); return SRSLTE_SUCCESS; } @@ -175,6 +185,7 @@ int full_test() return SRSLTE_SUCCESS; } + int main(int argc, char** argv) { TESTASSERT(basic_hex_test() == SRSLTE_SUCCESS); diff --git a/lib/test/common/pdu_test.cc b/lib/test/common/pdu_test.cc index c13f63848..8a2fa56af 100644 --- a/lib/test/common/pdu_test.cc +++ b/lib/test/common/pdu_test.cc @@ -21,7 +21,6 @@ #include "srslte/common/common.h" #include "srslte/common/interfaces_common.h" -#include "srslte/common/log_filter.h" #include "srslte/common/logmap.h" #include "srslte/common/mac_pcap.h" #include "srslte/common/pdu.h" @@ -547,10 +546,10 @@ int mac_sch_pdu_pack_test7() // Test Packing of SCell Activation CE command int mac_sch_pdu_pack_test8() { - srslte::log* log_h = logmap::get("MAC"); + srslte::log_ref log_h = logmap::get("MAC"); const uint32_t pdu_size = 2; - srslte::sch_pdu pdu(10, log_h); + srslte::sch_pdu pdu(10, log_h.get()); std::bitset<8> cc_mask(uniform_dist_u8(rand_gen)); // subheader: R|F2|E|LCID = 0|0|0|11011 @@ -571,7 +570,7 @@ int mac_sch_pdu_pack_test8() TESTASSERT(pdu.get()->set_scell_activation_cmd(cc_mask)); // write PDU - pdu.write_packet(log_h); + pdu.write_packet(log_h.get()); // compare with tv TESTASSERT(memcmp(buffer.msg, tv, buffer.N_bytes) == 0); @@ -752,8 +751,8 @@ int main(int argc, char** argv) pcap_handle = std::unique_ptr(new srslte::mac_pcap()); pcap_handle->open("mac_pdu_test.pcap"); #endif - logmap::get_instance()->set_default_hex_limit(32); - logmap::get_instance()->set_default_log_level(LOG_LEVEL_DEBUG); + logmap::set_default_hex_limit(100000); + logmap::set_default_log_level(LOG_LEVEL_DEBUG); if (mac_rar_pdu_unpack_test1()) { fprintf(stderr, "mac_rar_pdu_unpack_test1 failed.\n"); diff --git a/lib/test/common/test_common_test.cc b/lib/test/common/test_common_test.cc index dd618771a..4b1666268 100644 --- a/lib/test/common/test_common_test.cc +++ b/lib/test/common/test_common_test.cc @@ -31,7 +31,7 @@ int test_nullsink_log() // without contaminating the console/log file, and to check what error message was stored scoped_log null_log("TEST"); - TESTASSERT(srslte::logmap::get("TEST") == null_log.get()); + TESTASSERT(srslte::logmap::get("TEST").get() == null_log.get()); TESTASSERT(null_log->error_counter == 0); TESTASSERT(null_log->last_log_level == srslte::LOG_LEVEL_NONE); TESTASSERT(null_log->last_log_msg.empty()); @@ -50,7 +50,7 @@ int test_log_scoping() // This behavior is useful for the cases we have one generic logger for all tests, but in a specific test // we want to use a different one scoped_log log1("TEST"); - TESTASSERT(srslte::logmap::get("TEST") == log1.get()); + TESTASSERT(srslte::logmap::get("TEST").get() == log1.get()); log1->error("message1"); log1->error("message2"); @@ -60,7 +60,7 @@ int test_log_scoping() { // the global test log should be overwriten here, and used by TESTASSERT macro scoped_log log2("TEST"); - TESTASSERT(srslte::logmap::get("TEST") == log2.get()); + TESTASSERT(srslte::logmap::get("TEST").get() == log2.get()); TESTASSERT(log2->error_counter == 0); log2->error("error message in logger2\n"); TESTASSERT(log2->last_log_msg == "error message in logger2\n"); @@ -68,7 +68,7 @@ int test_log_scoping() } // the last logger should be recovered - TESTASSERT(srslte::logmap::get("TEST") == log1.get()); + TESTASSERT(srslte::logmap::get("TEST").get() == log1.get()); TESTASSERT(log1->error_counter == 2); return 0; } diff --git a/srsenb/hdr/stack/mac/scheduler.h b/srsenb/hdr/stack/mac/scheduler.h index aceb4023c..c572fb3bb 100644 --- a/srsenb/hdr/stack/mac/scheduler.h +++ b/srsenb/hdr/stack/mac/scheduler.h @@ -183,7 +183,7 @@ public: class carrier_sched; protected: - srslte::log* log_h = nullptr; + srslte::log_ref log_h; rrc_interface_mac* rrc = nullptr; sched_args_t sched_cfg = {}; std::vector sched_cell_params; diff --git a/srsenb/hdr/stack/mac/scheduler_carrier.h b/srsenb/hdr/stack/mac/scheduler_carrier.h index 8ffd7df2c..f9916c8cb 100644 --- a/srsenb/hdr/stack/mac/scheduler_carrier.h +++ b/srsenb/hdr/stack/mac/scheduler_carrier.h @@ -52,9 +52,9 @@ private: // args const sched_cell_params_t* cc_cfg = nullptr; - srslte::log* log_h = nullptr; - rrc_interface_mac* rrc = nullptr; - std::map* ue_db = nullptr; + srslte::log_ref log_h; + rrc_interface_mac* rrc = nullptr; + std::map* ue_db = nullptr; std::unique_ptr dl_metric; std::unique_ptr ul_metric; const uint32_t enb_cc_idx; @@ -114,7 +114,7 @@ public: using dl_sched_rar_t = sched_interface::dl_sched_rar_t; using dl_sched_rar_grant_t = sched_interface::dl_sched_rar_grant_t; - explicit ra_sched(const sched_cell_params_t& cfg_, srslte::log* log_, std::map& ue_db_); + explicit ra_sched(const sched_cell_params_t& cfg_, std::map& ue_db_); void dl_sched(sf_sched* tti_sched); void ul_sched(sf_sched* tti_sched); int dl_rach_info(dl_sched_rar_info_t rar_info); @@ -123,7 +123,7 @@ public: private: // args - srslte::log* log_h = nullptr; + srslte::log_ref log_h; const sched_cell_params_t* cc_cfg = nullptr; std::map* ue_db = nullptr; diff --git a/srsenb/hdr/stack/mac/scheduler_grid.h b/srsenb/hdr/stack/mac/scheduler_grid.h index 1973a8cfc..f7babc564 100644 --- a/srsenb/hdr/stack/mac/scheduler_grid.h +++ b/srsenb/hdr/stack/mac/scheduler_grid.h @@ -94,7 +94,7 @@ private: // consts const sched_cell_params_t* cc_cfg = nullptr; - srslte::log* log_h = nullptr; + srslte::log_ref log_h; // tti vars const tti_params_t* tti_params = nullptr; @@ -131,8 +131,8 @@ private: alloc_outcome_t alloc_dl(uint32_t aggr_lvl, alloc_type_t alloc_type, rbgmask_t alloc_mask, sched_ue* user = nullptr); // consts - const sched_cell_params_t* cc_cfg = nullptr; - srslte::log* log_h = nullptr; + const sched_cell_params_t* cc_cfg = nullptr; + srslte::log_ref log_h; uint32_t nof_rbgs = 0; uint32_t si_n_rbg = 0, rar_n_rbg = 0; @@ -286,7 +286,7 @@ private: // consts const sched_cell_params_t* cc_cfg = nullptr; - srslte::log* log_h = nullptr; + srslte::log_ref log_h; // internal state tti_params_t tti_params{10241}; diff --git a/srsenb/hdr/stack/mac/scheduler_harq.h b/srsenb/hdr/stack/mac/scheduler_harq.h index de1b264c8..7e335c0da 100644 --- a/srsenb/hdr/stack/mac/scheduler_harq.h +++ b/srsenb/hdr/stack/mac/scheduler_harq.h @@ -90,7 +90,7 @@ protected: int last_mcs[SRSLTE_MAX_TB]; int last_tbs[SRSLTE_MAX_TB]; - srslte::log* log_h = nullptr; + srslte::log_ref log_h; }; typedef srslte::bounded_bitset<25, true> rbgmask_t; diff --git a/srsenb/hdr/stack/mac/scheduler_metric.h b/srsenb/hdr/stack/mac/scheduler_metric.h index 0b2fb2c95..926591e48 100644 --- a/srsenb/hdr/stack/mac/scheduler_metric.h +++ b/srsenb/hdr/stack/mac/scheduler_metric.h @@ -38,8 +38,8 @@ private: bool find_allocation(uint32_t nof_rbg, rbgmask_t* rbgmask); dl_harq_proc* allocate_user(sched_ue* user); - const sched_cell_params_t* cc_cfg = nullptr; - srslte::log* log_h = nullptr; + const sched_cell_params_t* cc_cfg = nullptr; + srslte::log_ref log_h; dl_sf_sched_itf* tti_alloc = nullptr; }; @@ -54,8 +54,8 @@ private: ul_harq_proc* allocate_user_newtx_prbs(sched_ue* user); ul_harq_proc* allocate_user_retx_prbs(sched_ue* user); - const sched_cell_params_t* cc_cfg = nullptr; - srslte::log* log_h = nullptr; + const sched_cell_params_t* cc_cfg = nullptr; + srslte::log_ref log_h; ul_sf_sched_itf* tti_alloc = nullptr; uint32_t current_tti = 0; }; diff --git a/srsenb/hdr/stack/mac/scheduler_ue.h b/srsenb/hdr/stack/mac/scheduler_ue.h index 4c0a2dfd6..1ed9fd814 100644 --- a/srsenb/hdr/stack/mac/scheduler_ue.h +++ b/srsenb/hdr/stack/mac/scheduler_ue.h @@ -89,7 +89,7 @@ struct sched_ue_carrier { private: // config - srslte::log* log_h = nullptr; + srslte::log_ref log_h; const sched_interface::ue_cfg_t* cfg = nullptr; const sched_cell_params_t* cell_params = nullptr; uint16_t rnti; @@ -259,9 +259,9 @@ private: bool is_first_dl_tx(); /* Args */ - sched_interface::ue_cfg_t cfg = {}; - srslte_cell_t cell = {}; - srslte::log* log_h = nullptr; + sched_interface::ue_cfg_t cfg = {}; + srslte_cell_t cell = {}; + srslte::log_ref log_h; const std::vector* cell_params_list = nullptr; const sched_cell_params_t* main_cc_params = nullptr; diff --git a/srsenb/hdr/stack/rrc/rrc_mobility.h b/srsenb/hdr/stack/rrc/rrc_mobility.h index 1ae378a35..29ed359d0 100644 --- a/srsenb/hdr/stack/rrc/rrc_mobility.h +++ b/srsenb/hdr/stack/rrc/rrc_mobility.h @@ -23,6 +23,7 @@ #define SRSENB_RRC_MOBILITY_H #include "rrc.h" +#include "srslte/common/logmap.h" #include namespace srsenb { @@ -34,12 +35,12 @@ namespace srsenb { class var_meas_cfg_t { public: - explicit var_meas_cfg_t(srslte::log* log_) : rrc_log(log_) {} using meas_cell_t = asn1::rrc::cells_to_add_mod_s; using meas_id_t = asn1::rrc::meas_id_to_add_mod_s; using meas_obj_t = asn1::rrc::meas_obj_to_add_mod_s; using report_cfg_t = asn1::rrc::report_cfg_to_add_mod_s; + var_meas_cfg_t() : rrc_log(srslte::logmap::get("RRC")) {} std::tuple add_cell_cfg(const meas_cell_cfg_t& cellcfg); report_cfg_t* add_report_cfg(const asn1::rrc::report_cfg_eutra_s& reportcfg); meas_id_t* add_measid_cfg(uint8_t measobjid, uint8_t repid); @@ -64,13 +65,13 @@ public: private: asn1::rrc::var_meas_cfg_s var_meas; - srslte::log* rrc_log = nullptr; + srslte::log_ref rrc_log; }; class rrc::mobility_cfg { public: - explicit mobility_cfg(const rrc_cfg_t* cfg_, srslte::log* log_); + explicit mobility_cfg(const rrc_cfg_t* cfg_); std::shared_ptr current_meas_cfg; ///< const to enable ptr comparison as identity comparison diff --git a/srsenb/hdr/stack/upper/s1ap.h b/srsenb/hdr/stack/upper/s1ap.h index 34b6cf942..5a9c3f1bf 100644 --- a/srsenb/hdr/stack/upper/s1ap.h +++ b/srsenb/hdr/stack/upper/s1ap.h @@ -27,7 +27,7 @@ #include "common_enb.h" #include "srslte/common/buffer_pool.h" #include "srslte/common/common.h" -#include "srslte/common/log.h" +#include "srslte/common/logmap.h" #include "srslte/common/threads.h" #include "srslte/interfaces/enb_interfaces.h" @@ -98,9 +98,9 @@ private: // args rrc_interface_s1ap* rrc = nullptr; s1ap_args_t args; - srslte::log* s1ap_log = nullptr; - srslte::byte_buffer_pool* pool = nullptr; - srsenb::stack_interface_s1ap_lte* stack = nullptr; + srslte::log_ref s1ap_log; + srslte::byte_buffer_pool* pool = nullptr; + srsenb::stack_interface_s1ap_lte* stack = nullptr; srslte::socket_handler_t s1ap_socket; struct sockaddr_in mme_addr = {}; // MME address @@ -198,8 +198,8 @@ private: //! TS 36.413, Section 8.4.6 - eNB Status Transfer procedure // args - s1ap* s1ap_ptr; - srslte::log* s1ap_log; + s1ap* s1ap_ptr; + srslte::log_ref s1ap_log; // state bool release_requested = false; diff --git a/srsenb/src/stack/enb_stack_lte.cc b/srsenb/src/stack/enb_stack_lte.cc index f4c447238..e0605069e 100644 --- a/srsenb/src/stack/enb_stack_lte.cc +++ b/srsenb/src/stack/enb_stack_lte.cc @@ -70,7 +70,7 @@ int enb_stack_lte::init(const stack_args_t& args_, const rrc_cfg_t& rrc_cfg_) rrc_cfg = rrc_cfg_; // setup logging for each layer - srslte::logmap::get_instance()->set_default_logger(logger); + srslte::logmap::set_default_logger(logger); mac_log.init("MAC ", logger, true); rlc_log.init("RLC ", logger); pdcp_log.init("PDCP", logger); diff --git a/srsenb/src/stack/mac/scheduler.cc b/srsenb/src/stack/mac/scheduler.cc index 2fcc9765c..be13a1543 100644 --- a/srsenb/src/stack/mac/scheduler.cc +++ b/srsenb/src/stack/mac/scheduler.cc @@ -139,7 +139,7 @@ sched::~sched() void sched::init(rrc_interface_mac* rrc_) { - log_h = srslte::logmap::get("MAC "); + log_h = srslte::logmap::get("MAC"); rrc = rrc_; // Initialize first carrier scheduler diff --git a/srsenb/src/stack/mac/scheduler_carrier.cc b/srsenb/src/stack/mac/scheduler_carrier.cc index d6f10c342..ce117a869 100644 --- a/srsenb/src/stack/mac/scheduler_carrier.cc +++ b/srsenb/src/stack/mac/scheduler_carrier.cc @@ -136,9 +136,9 @@ void bc_sched::reset() * RAR scheduling *******************************************************/ -ra_sched::ra_sched(const sched_cell_params_t& cfg_, srslte::log* log_, std::map& ue_db_) : +ra_sched::ra_sched(const sched_cell_params_t& cfg_, std::map& ue_db_) : cc_cfg(&cfg_), - log_h(log_), + log_h(srslte::logmap::get("MAC")), ue_db(&ue_db_) { } @@ -311,7 +311,7 @@ void sched::carrier_sched::carrier_cfg(const sched_cell_params_t& cell_params_) // init Broadcast/RA schedulers bc_sched_ptr.reset(new bc_sched{*cc_cfg, rrc}); - ra_sched_ptr.reset(new ra_sched{*cc_cfg, log_h, *ue_db}); + ra_sched_ptr.reset(new ra_sched{*cc_cfg, *ue_db}); // Setup data scheduling algorithms dl_metric.reset(new srsenb::dl_metric_rr{}); diff --git a/srsenb/src/stack/rrc/rrc.cc b/srsenb/src/stack/rrc/rrc.cc index 755497914..ce337fd05 100644 --- a/srsenb/src/stack/rrc/rrc.cc +++ b/srsenb/src/stack/rrc/rrc.cc @@ -76,7 +76,7 @@ void rrc::init(rrc_cfg_t* cfg_, nof_si_messages = generate_sibs(); config_mac(); - enb_mobility_cfg.reset(new mobility_cfg(&cfg, log_rrc)); + enb_mobility_cfg.reset(new mobility_cfg(&cfg)); pthread_mutex_init(&user_mutex, nullptr); pthread_mutex_init(&paging_mutex, nullptr); diff --git a/srsenb/src/stack/rrc/rrc_mobility.cc b/srsenb/src/stack/rrc/rrc_mobility.cc index e86081c75..9ba1ee0af 100644 --- a/srsenb/src/stack/rrc/rrc_mobility.cc +++ b/srsenb/src/stack/rrc/rrc_mobility.cc @@ -610,9 +610,9 @@ void var_meas_cfg_t::compute_diff_quant_cfg(const var_meas_cfg_t& target_cfg, as * mobility_cfg class ************************************************************************************************/ -rrc::mobility_cfg::mobility_cfg(const rrc_cfg_t* cfg_, srslte::log* log_) : cfg(cfg_) +rrc::mobility_cfg::mobility_cfg(const rrc_cfg_t* cfg_) : cfg(cfg_) { - var_meas_cfg_t var_meas{log_}; + var_meas_cfg_t var_meas{}; if (cfg->meas_cfg_present) { // inserts all neighbor cells @@ -650,9 +650,9 @@ rrc::ue::rrc_mobility::rrc_mobility(rrc::ue* outer_ue) : cfg(outer_ue->parent->enb_mobility_cfg.get()), pool(outer_ue->pool), rrc_log(outer_ue->parent->rrc_log), - source_ho_proc(this) + source_ho_proc(this), + ue_var_meas(std::make_shared()) { - ue_var_meas = std::make_shared(outer_ue->parent->rrc_log); } //! Method to add Mobility Info to a RRC Connection Reconfiguration Message @@ -803,7 +803,7 @@ bool rrc::ue::rrc_mobility::start_ho_preparation(uint32_t target_eci, /*** fill AS-Config ***/ hoprep_r8.as_cfg_present = true; // NOTE: set source_meas_cnfg equal to the UE's current var_meas_cfg - var_meas_cfg_t empty_meascfg{rrc_log}, target_var_meas = *ue_var_meas; + var_meas_cfg_t empty_meascfg{}, target_var_meas = *ue_var_meas; // // however, reset the MeasObjToAdd Cells, so that the UE does not measure again the target eNB // meas_obj_to_add_mod_s* obj = rrc_details::binary_find(target_var_meas.meas_objs(), measobj_id); // obj->meas_obj.meas_obj_eutra().cells_to_add_mod_list.resize(0); diff --git a/srsenb/src/stack/upper/s1ap.cc b/srsenb/src/stack/upper/s1ap.cc index 33c6a344a..88473701f 100644 --- a/srsenb/src/stack/upper/s1ap.cc +++ b/srsenb/src/stack/upper/s1ap.cc @@ -432,12 +432,12 @@ bool s1ap::connect_mme() // Init SCTP socket and bind it if (not srslte::net_utils::sctp_init_client( - &s1ap_socket, srslte::net_utils::socket_type::seqpacket, args.s1c_bind_addr.c_str(), s1ap_log)) { + &s1ap_socket, srslte::net_utils::socket_type::seqpacket, args.s1c_bind_addr.c_str(), s1ap_log.get())) { return false; } // Connect to the MME address - if (not s1ap_socket.connect_to(args.mme_addr.c_str(), MME_PORT, &mme_addr, s1ap_log)) { + if (not s1ap_socket.connect_to(args.mme_addr.c_str(), MME_PORT, &mme_addr, s1ap_log.get())) { return false; } diff --git a/srsenb/test/mac/scheduler_test_rand.cc b/srsenb/test/mac/scheduler_test_rand.cc index 8ddfb9cb2..f4c0d89a3 100644 --- a/srsenb/test/mac/scheduler_test_rand.cc +++ b/srsenb/test/mac/scheduler_test_rand.cc @@ -1041,7 +1041,7 @@ sched_sim_args rand_sim_params(const srsenb::sched_interface::cell_cfg_t& cell_c int main() { - srslte::logmap::get_instance()->set_default_log_level(srslte::LOG_LEVEL_INFO); + srslte::logmap::set_default_log_level(srslte::LOG_LEVEL_INFO); printf("[TESTER] This is the chosen seed: %u\n", seed); /* initialize random seed: */ uint32_t N_runs = 1, nof_ttis = 10240 + 10; diff --git a/srsenb/test/upper/erab_setup_test.cc b/srsenb/test/upper/erab_setup_test.cc index eea4600ed..6435cbed5 100644 --- a/srsenb/test/upper/erab_setup_test.cc +++ b/srsenb/test/upper/erab_setup_test.cc @@ -108,7 +108,7 @@ int test_erab_setup(bool qci_exists) int main(int argc, char** argv) { - srslte::logmap::get_instance()->set_default_log_level(srslte::LOG_LEVEL_INFO); + srslte::logmap::set_default_log_level(srslte::LOG_LEVEL_INFO); if (argc < 3) { argparse::usage(argv[0]); diff --git a/srsenb/test/upper/rrc_mobility_test.cc b/srsenb/test/upper/rrc_mobility_test.cc index 3500cb4a7..5d3a2e5e5 100644 --- a/srsenb/test/upper/rrc_mobility_test.cc +++ b/srsenb/test/upper/rrc_mobility_test.cc @@ -76,7 +76,7 @@ int test_correct_insertion() // TEST 1: cell/rep insertion in empty varMeasCfg { - var_meas_cfg_t var_cfg(srslte::logmap::get("RRC ")); + var_meas_cfg_t var_cfg; auto ret = var_cfg.add_cell_cfg(cell1); TESTASSERT(std::get<0>(ret) and std::get<1>(ret) != nullptr); const auto& objs = var_cfg.meas_objs(); @@ -94,7 +94,7 @@ int test_correct_insertion() } { - var_meas_cfg_t var_cfg(srslte::logmap::get("RRC ")); + var_meas_cfg_t var_cfg; const auto& objs = var_cfg.meas_objs(); // TEST 2: insertion of out-of-order cell ids in same earfcn @@ -133,7 +133,7 @@ int test_correct_insertion() int test_correct_meascfg_calculation() { - var_meas_cfg_t src_var(srslte::logmap::get("RRC ")), target_var(srslte::logmap::get("RRC ")); + var_meas_cfg_t src_var, target_var; meas_cell_cfg_t cell1{}, cell2{}; cell1.earfcn = 3400; @@ -213,7 +213,7 @@ int test_correct_meascfg_calculation() // TEST: Removal of cell/rep from target propagates to the resulting meas_cfg_s src_var = target_var; - target_var = var_meas_cfg_t{srslte::logmap::get("RRC ")}; + target_var = var_meas_cfg_t{}; target_var.add_cell_cfg(cell2); target_var.add_report_cfg(rep1); target_var.add_report_cfg(rep3); @@ -363,7 +363,7 @@ int test_mobility_class(mobility_test_params test_params) int main(int argc, char** argv) { - srslte::logmap::get_instance()->set_default_log_level(srslte::LOG_LEVEL_INFO); + srslte::logmap::set_default_log_level(srslte::LOG_LEVEL_INFO); if (argc < 3) { argparse::usage(argv[0]); diff --git a/srsue/hdr/stack/upper/nas.h b/srsue/hdr/stack/upper/nas.h index 5148878e0..6a55e7cab 100644 --- a/srsue/hdr/stack/upper/nas.h +++ b/srsue/hdr/stack/upper/nas.h @@ -25,7 +25,7 @@ #include "srslte/asn1/liblte_mme.h" #include "srslte/common/buffer_pool.h" #include "srslte/common/common.h" -#include "srslte/common/log.h" +#include "srslte/common/logmap.h" #include "srslte/common/nas_pcap.h" #include "srslte/common/security.h" #include "srslte/common/stack_procedure.h" @@ -74,11 +74,11 @@ public: void start_pcap(srslte::nas_pcap* pcap_); private: - srslte::byte_buffer_pool* pool = nullptr; - srslte::log* nas_log = nullptr; - rrc_interface_nas* rrc = nullptr; - usim_interface_nas* usim = nullptr; - gw_interface_nas* gw = nullptr; + srslte::byte_buffer_pool* pool = nullptr; + srslte::log_ref nas_log; + rrc_interface_nas* rrc = nullptr; + usim_interface_nas* usim = nullptr; + gw_interface_nas* gw = nullptr; nas_args_t cfg = {}; diff --git a/srsue/src/main.cc b/srsue/src/main.cc index b787b07e1..3d7b9c21f 100644 --- a/srsue/src/main.cc +++ b/srsue/src/main.cc @@ -573,7 +573,7 @@ int main(int argc, char* argv[]) logger_file.init(args.log.filename, args.log.file_max_size); logger = &logger_file; } - srslte::logmap::get_instance()->set_default_logger(logger); + srslte::logmap::set_default_logger(logger); // Create UE instance srsue::ue ue; diff --git a/srsue/src/stack/ue_stack_lte.cc b/srsue/src/stack/ue_stack_lte.cc index 3fa33dcee..17688ebc3 100644 --- a/srsue/src/stack/ue_stack_lte.cc +++ b/srsue/src/stack/ue_stack_lte.cc @@ -114,7 +114,7 @@ int ue_stack_lte::init(const stack_args_t& args_, srslte::logger* logger_) asn1::rrc::rrc_log_register_handler(&rrc_log); // Set NAS log - srslte::log* log_ptr = logmap::get("NAS "); + srslte::log_ref log_ptr = logmap::get("NAS"); log_ptr->set_level(args.log.nas_level); log_ptr->set_hex_limit(args.log.nas_hex_limit); diff --git a/srsue/test/ttcn3/src/ttcn3_dut.cc b/srsue/test/ttcn3/src/ttcn3_dut.cc index 2c6f42aa0..84e49abe8 100644 --- a/srsue/test/ttcn3/src/ttcn3_dut.cc +++ b/srsue/test/ttcn3/src/ttcn3_dut.cc @@ -118,7 +118,7 @@ int main(int argc, char** argv) // Instantiate file logger srslte::logger_file logger_file; - srslte::logmap::get_instance()->set_default_logger(&logger_file); + srslte::logmap::set_default_logger(&logger_file); // Create UE object unique_ptr ue = std::unique_ptr(new ttcn3_ue()); diff --git a/srsue/test/upper/nas_test.cc b/srsue/test/upper/nas_test.cc index 6e6c76940..fee7970f4 100644 --- a/srsue/test/upper/nas_test.cc +++ b/srsue/test/upper/nas_test.cc @@ -478,8 +478,8 @@ int dedicated_eps_bearer_test() int main(int argc, char** argv) { - srslte::logmap::get_instance()->set_default_log_level(LOG_LEVEL_DEBUG); - srslte::logmap::get_instance()->set_default_hex_limit(100000); + srslte::logmap::set_default_log_level(LOG_LEVEL_DEBUG); + srslte::logmap::set_default_hex_limit(100000); if (security_command_test()) { printf("Security command test failed.\n");