diff --git a/lib/include/srslte/common/basic_pnf.h b/lib/include/srslte/common/basic_pnf.h index 5db0e32f8..b7cf59b85 100644 --- a/lib/include/srslte/common/basic_pnf.h +++ b/lib/include/srslte/common/basic_pnf.h @@ -19,6 +19,7 @@ #include "srslte/common/block_queue.h" #include "srslte/common/buffer_pool.h" #include "srslte/common/logmap.h" +#include "srslte/srslog/srslog.h" #include #include #include @@ -74,7 +75,8 @@ public: rand_gen(RAND_SEED), rand_dist(MIN_TB_LEN, MAX_TB_LEN) { - log_h->set_level(srslte::LOG_LEVEL_WARNING); + logger.set_level(srslog::basic_levels::warning); + logger.set_hex_dump_max_size(-1); } ~srslte_basic_pnf() { stop(); }; @@ -314,7 +316,7 @@ private: { basic_vnf_api::msg_header_t* header = (basic_vnf_api::msg_header_t*)buffer; - log_h->debug("Received %s (%d B) in TTI\n", basic_vnf_api::msg_type_text[header->type], len); + logger.debug("Received %s (%d B) in TTI", basic_vnf_api::msg_type_text[header->type], len); switch (header->type) { case basic_vnf_api::SF_IND: @@ -452,8 +454,8 @@ private: dl_ind.pdus[i].type = tx_req->pdus[i].type; memcpy(dl_ind.pdus[i].data, tx_req->pdus[i].data, dl_ind.pdus[i].length); tot_bytes += dl_ind.pdus[i].length; - log_h->info_hex( - dl_ind.pdus[i].data, dl_ind.pdus[i].length, "Sending to UE a PDU (%d bytes)\n", dl_ind.pdus[i].length); + logger.info( + dl_ind.pdus[i].data, dl_ind.pdus[i].length, "Sending to UE a PDU (%d bytes)", dl_ind.pdus[i].length); } } } else { @@ -470,7 +472,7 @@ private: tot_bytes = N_bytes; } - log_h->info_hex(dl_ind.pdus[0].data, N_bytes, "Sending to UE a TB (%d bytes)\n", N_bytes); + logger.info(dl_ind.pdus[0].data, N_bytes, "Sending to UE a TB (%d bytes)", N_bytes); } if (tot_bytes > 0 and tot_bytes < tb_size) { @@ -510,7 +512,7 @@ private: std::string tx_thread_name = "TX_PNF", rx_thread_name = "RX_PNF"; bool running = false; srslte::byte_buffer_pool* pool = srslte::byte_buffer_pool::get_instance(); - srslte::log_ref log_h{"PNF"}; + srslog::basic_logger& logger = srslog::fetch_basic_logger("PNF", false); std::mutex mutex; std::atomic tti; diff --git a/lib/include/srslte/common/basic_vnf.h b/lib/include/srslte/common/basic_vnf.h index 0a5831f5d..686c25dd0 100644 --- a/lib/include/srslte/common/basic_vnf.h +++ b/lib/include/srslte/common/basic_vnf.h @@ -19,6 +19,7 @@ #include "srslte/common/threads.h" #include "srslte/interfaces/gnb_interfaces.h" #include "srslte/interfaces/ue_nr_interfaces.h" +#include "srslte/srslog/srslog.h" #include #include #include @@ -35,7 +36,7 @@ namespace srslte { class srslte_basic_vnf : public thread { public: - srslte_basic_vnf(const vnf_args_t& args_, srslte::logger* logger_, stack_interface_phy_nr* stack_); + srslte_basic_vnf(const vnf_args_t& args_, stack_interface_phy_nr* stack_); ~srslte_basic_vnf(); bool stop(); @@ -60,8 +61,7 @@ private: // helpers uint32_t calc_full_msg_len(const basic_vnf_api::tx_request_msg_t& msg); - srslte::logger* m_logger = nullptr; - srslte::log_ref log_h; + srslog::basic_logger& logger = srslog::fetch_basic_logger("VNF", false); srsenb::stack_interface_phy_nr* m_gnb_stack = nullptr; srsue::stack_interface_phy_nr* m_ue_stack = nullptr; srslte::byte_buffer_pool* m_pool = nullptr; diff --git a/lib/src/common/basic_vnf.cc b/lib/src/common/basic_vnf.cc index 6466578bd..bf07c31fd 100644 --- a/lib/src/common/basic_vnf.cc +++ b/lib/src/common/basic_vnf.cc @@ -27,16 +27,14 @@ struct srslte_pnf_info_t { struct srslte_vnf_info_t {}; -srslte_basic_vnf::srslte_basic_vnf(const vnf_args_t& args_, srslte::logger* logger_, stack_interface_phy_nr* stack_) : +srslte_basic_vnf::srslte_basic_vnf(const vnf_args_t& args_, stack_interface_phy_nr* stack_) : m_args(args_), - m_logger(logger_), thread("BASIC_VNF_P7"), m_tx_req_msg(new basic_vnf_api::tx_request_msg_t), - log_h("VNF"), m_pool(srslte::byte_buffer_pool::get_instance()) { - log_h->set_level(m_args.log_level); - log_h->set_hex_limit(m_args.log_hex_limit); + logger.set_level(srslog::str_to_basic_level(m_args.log_level)); + logger.set_hex_dump_max_size(m_args.log_hex_limit); if (m_args.type == "gnb" || m_args.type == "ue") { if (m_args.type == "gnb") { @@ -45,10 +43,10 @@ srslte_basic_vnf::srslte_basic_vnf(const vnf_args_t& args_, srslte::logger* logg m_ue_stack = (srsue::stack_interface_phy_nr*)stack_; } - log_h->info("Initializing VNF for gNB\n"); + logger.info("Initializing VNF for gNB"); start(); } else { - log_h->error("Unknown VNF type. Exiting\n."); + logger.error("Unknown VNF type. Exiting."); } } @@ -98,7 +96,7 @@ void srslte_basic_vnf::run_thread() running = true; - log_h->info("Started VNF handler listening on %s:%d\n", m_args.bind_addr.c_str(), m_args.bind_port); + logger.info("Started VNF handler listening on %s:%d", m_args.bind_addr.c_str(), m_args.bind_port); while (running) { int ret = poll(&fd, 1, RX_TIMEOUT_MS); @@ -118,14 +116,14 @@ void srslte_basic_vnf::run_thread() break; } } - log_h->info("VNF thread stopped\n"); + logger.info("VNF thread stopped"); } int srslte_basic_vnf::handle_msg(const uint8_t* buffer, const uint32_t len) { basic_vnf_api::msg_header_t* header = (basic_vnf_api::msg_header_t*)buffer; - log_h->info("Received %s (%d B)\n", basic_vnf_api::msg_type_text[header->type], len); + logger.info("Received %s (%d B)", basic_vnf_api::msg_type_text[header->type], len); switch (header->type) { case basic_vnf_api::SF_IND: @@ -153,7 +151,7 @@ int srslte_basic_vnf::handle_msg(const uint8_t* buffer, const uint32_t len) int srslte_basic_vnf::handle_sf_ind(basic_vnf_api::sf_ind_msg_t* msg) { int ret = SRSLTE_SUCCESS; - log_h->info("Received %s for TTI=%d\n", basic_vnf_api::msg_type_text[msg->header.type], msg->tti); + logger.info("Received %s for TTI=%d", basic_vnf_api::msg_type_text[msg->header.type], msg->tti); // store Rx timestamp last_sf_indication_time = msg->t1; @@ -172,7 +170,7 @@ int srslte_basic_vnf::handle_sf_ind(basic_vnf_api::sf_ind_msg_t* msg) int srslte_basic_vnf::handle_dl_ind(basic_vnf_api::dl_ind_msg_t* msg) { int ret = SRSLTE_ERROR; - log_h->info("Received %s for TTI=%d\n", basic_vnf_api::msg_type_text[msg->header.type], msg->tti); + logger.info("Received %s for TTI=%d", basic_vnf_api::msg_type_text[msg->header.type], msg->tti); uint32_t cc_idx = 0; @@ -181,7 +179,7 @@ int srslte_basic_vnf::handle_dl_ind(basic_vnf_api::dl_ind_msg_t* msg) dl_grant.tti = msg->tti; if (msg->nof_pdus > SRSLTE_MAX_TB) { - log_h->error("Too many TBs (%d > %d)\n", msg->nof_pdus, SRSLTE_MAX_TB); + logger.error("Too many TBs (%d > %d)", msg->nof_pdus, SRSLTE_MAX_TB); goto exit; } @@ -194,7 +192,7 @@ int srslte_basic_vnf::handle_dl_ind(basic_vnf_api::dl_ind_msg_t* msg) m_ue_stack->tb_decoded(cc_idx, dl_grant); } } else { - log_h->error("TB too big to fit into buffer (%d > %d)\n", msg->pdus[i].length, dl_grant.tb[i]->get_tailroom()); + logger.error("TB too big to fit into buffer (%d > %d)", msg->pdus[i].length, dl_grant.tb[i]->get_tailroom()); } } @@ -207,10 +205,10 @@ exit: int srslte_basic_vnf::handle_ul_ind(basic_vnf_api::ul_ind_msg_t* msg) { - log_h->info("Received %s for TTI=%d\n", basic_vnf_api::msg_type_text[msg->header.type], msg->tti); + logger.info("Received %s for TTI=%d", basic_vnf_api::msg_type_text[msg->header.type], msg->tti); if (msg->pdus.type != basic_vnf_api::PUSCH) { - log_h->error("Received UL indication for wrong PDU type\n"); + logger.error("Received UL indication for wrong PDU type"); return SRSLTE_ERROR; } @@ -228,10 +226,10 @@ int srslte_basic_vnf::handle_ul_ind(basic_vnf_api::ul_ind_msg_t* msg) int srslte_basic_vnf::handle_rx_data_ind(basic_vnf_api::rx_data_ind_msg_t* msg) { - log_h->info("Received %s for TTI=%d\n", basic_vnf_api::msg_type_text[msg->header.type], msg->sfn); + logger.info("Received %s for TTI=%d", basic_vnf_api::msg_type_text[msg->header.type], msg->sfn); if (msg->nof_pdus != 1 || msg->pdus[0].type != basic_vnf_api::PUSCH) { - log_h->error("Received UL indication for wrong PDU type\n"); + logger.error("Received UL indication for wrong PDU type"); return SRSLTE_ERROR; } @@ -267,10 +265,10 @@ int srslte_basic_vnf::dl_config_request(const srsenb::phy_interface_stack_nr::dl uint32_t len = sizeof(dl_conf); // Send it to PNF - log_h->info("Sending %s (%d B)\n", basic_vnf_api::msg_type_text[dl_conf.header.type], len); + logger.info("Sending %s (%d B)", basic_vnf_api::msg_type_text[dl_conf.header.type], len); int n = 0; if ((n = sendto(sockfd, &dl_conf, len, MSG_CONFIRM, (struct sockaddr*)&client_addr, sizeof(client_addr))) < 0) { - log_h->error("sendto failed, ret=%d\n", n); + logger.error("sendto failed, ret=%d", n); } return 0; @@ -294,7 +292,7 @@ int srslte_basic_vnf::tx_request(const srsue::phy_interface_stack_nr::tx_request // copy data from TB0 memcpy(m_tx_req_msg->pdus[0].data, request.data, request.tb_len); } else { - log_h->error("Trying to send %d B PDU. Maximum size is %d B\n", request.tb_len, MAX_PDU_SIZE); + logger.error("Trying to send %d B PDU. Maximum size is %d B", request.tb_len, MAX_PDU_SIZE); } // calculate actual length of @@ -304,11 +302,11 @@ int srslte_basic_vnf::tx_request(const srsue::phy_interface_stack_nr::tx_request m_tx_req_msg->header.msg_len = len - sizeof(basic_vnf_api::msg_header_t); // Send it to PNF - log_h->info("Sending %s (%d B)\n", basic_vnf_api::msg_type_text[m_tx_req_msg->header.type], len); + logger.info("Sending %s (%d B)", basic_vnf_api::msg_type_text[m_tx_req_msg->header.type], len); int n = 0; if ((n = sendto(sockfd, m_tx_req_msg.get(), len, MSG_CONFIRM, (struct sockaddr*)&client_addr, sizeof(client_addr))) < 0) { - log_h->error("sendto failed, ret=%d\n", n); + logger.error("sendto failed, ret=%d", n); } return 0; @@ -317,7 +315,7 @@ int srslte_basic_vnf::tx_request(const srsue::phy_interface_stack_nr::tx_request int srslte_basic_vnf::tx_request(const srsenb::phy_interface_stack_nr::tx_request_t& request) { if (request.nof_pdus > MAX_NUM_PDUS) { - log_h->error("Trying to send %d PDUs but only %d supported\n", request.nof_pdus, MAX_NUM_PDUS); + logger.error("Trying to send %d PDUs but only %d supported", request.nof_pdus, MAX_NUM_PDUS); return SRSLTE_ERROR; } if (request.nof_pdus == 0) { @@ -339,7 +337,7 @@ int srslte_basic_vnf::tx_request(const srsenb::phy_interface_stack_nr::tx_reques // copy data from TB0 memcpy(m_tx_req_msg->pdus[i].data, request.pdus[i].data[0], m_tx_req_msg->pdus[i].length); } else { - log_h->error("Trying to send %d B PDU. Maximum size is %d B\n", request.pdus[i].length, MAX_PDU_SIZE); + logger.error("Trying to send %d B PDU. Maximum size is %d B", request.pdus[i].length, MAX_PDU_SIZE); } } @@ -350,21 +348,21 @@ int srslte_basic_vnf::tx_request(const srsenb::phy_interface_stack_nr::tx_reques m_tx_req_msg->header.msg_len = len - sizeof(basic_vnf_api::msg_header_t); // Send it to PNF - log_h->info("Sending %s (%d B)\n", basic_vnf_api::msg_type_text[m_tx_req_msg->header.type], len); - if (log_h->get_level() == LOG_LEVEL_DEBUG) { + logger.info("Sending %s (%d B)", basic_vnf_api::msg_type_text[m_tx_req_msg->header.type], len); + if (logger.debug.enabled()) { for (uint32_t i = 0; i < m_tx_req_msg->nof_pdus; ++i) { - log_h->debug_hex(m_tx_req_msg->pdus[i].data, - m_tx_req_msg->pdus[i].length, - "Sending PDU %s:%d (%d bytes)\n", - basic_vnf_api::msg_type_text[m_tx_req_msg->header.type], - m_tx_req_msg->pdus[i].index, - m_tx_req_msg->pdus[i].length); + logger.debug(m_tx_req_msg->pdus[i].data, + m_tx_req_msg->pdus[i].length, + "Sending PDU %s:%d (%d bytes)", + basic_vnf_api::msg_type_text[m_tx_req_msg->header.type], + m_tx_req_msg->pdus[i].index, + m_tx_req_msg->pdus[i].length); } } int n = 0; if ((n = sendto(sockfd, m_tx_req_msg.get(), len, MSG_CONFIRM, (struct sockaddr*)&client_addr, sizeof(client_addr))) < 0) { - log_h->error("sendto failed, ret=%d\n", n); + logger.error("sendto failed, ret=%d", n); } return 0; diff --git a/srsenb/src/phy/vnf_phy_nr.cc b/srsenb/src/phy/vnf_phy_nr.cc index 886e217eb..02a71af3a 100644 --- a/srsenb/src/phy/vnf_phy_nr.cc +++ b/srsenb/src/phy/vnf_phy_nr.cc @@ -42,7 +42,7 @@ int vnf_phy_nr::init(const srsenb::phy_args_t& args, const nr_phy_cfg_t& cfg, sr mlockall(MCL_CURRENT | MCL_FUTURE); // create VNF - vnf = std::unique_ptr(new srslte::srslte_basic_vnf(args.vnf_args, logger, stack_)); + vnf = std::unique_ptr(new srslte::srslte_basic_vnf(args.vnf_args, stack_)); initialized = true; diff --git a/srsue/src/phy/vnf_phy_nr.cc b/srsue/src/phy/vnf_phy_nr.cc index f27208f8e..91d6f5568 100644 --- a/srsue/src/phy/vnf_phy_nr.cc +++ b/srsue/src/phy/vnf_phy_nr.cc @@ -44,7 +44,7 @@ int vnf_phy_nr::init(const srsue::phy_args_t& args_, srsue::stack_interface_phy_ int vnf_phy_nr::init(const srsue::phy_args_t& args_) { // create VNF - vnf = std::unique_ptr(new srslte::srslte_basic_vnf(args_.vnf_args, logger, stack)); + vnf = std::unique_ptr(new srslte::srslte_basic_vnf(args_.vnf_args, stack)); initialized = true; return SRSLTE_SUCCESS; }