From 6359a2d94848c020e6606786004da7cb0492cd26 Mon Sep 17 00:00:00 2001 From: faluco Date: Tue, 9 Feb 2021 17:57:45 +0100 Subject: [PATCH] - Upgrade the gtpu class in lib dir to srslog. - Propagate old log elimination through all the dependencies of gtpu. --- lib/include/srslte/upper/gtpu.h | 16 ++++++++-------- lib/src/upper/gtpu.cc | 33 ++++++++++++++++++--------------- srsenb/hdr/stack/upper/gtpu.h | 2 -- srsenb/src/stack/upper/gtpu.cc | 21 ++++++++++----------- srsenb/test/upper/gtpu_test.cc | 13 ++++++------- srsepc/hdr/mbms-gw/mbms-gw.h | 3 +-- srsepc/hdr/spgw/gtpu.h | 4 +--- srsepc/hdr/spgw/spgw.h | 2 +- srsepc/src/main.cc | 2 +- srsepc/src/mbms-gw/main.cc | 3 +-- srsepc/src/mbms-gw/mbms-gw.cc | 7 ++----- srsepc/src/spgw/gtpu.cc | 9 +++------ srsepc/src/spgw/spgw.cc | 4 ++-- 13 files changed, 54 insertions(+), 65 deletions(-) diff --git a/lib/include/srslte/upper/gtpu.h b/lib/include/srslte/upper/gtpu.h index 88c5d40d2..324893c35 100644 --- a/lib/include/srslte/upper/gtpu.h +++ b/lib/include/srslte/upper/gtpu.h @@ -70,35 +70,35 @@ struct gtpu_header_t { std::vector ext_buffer; }; -bool gtpu_read_header(srslte::byte_buffer_t* pdu, gtpu_header_t* header, srslte::log_ref gtpu_log); -bool gtpu_write_header(gtpu_header_t* header, srslte::byte_buffer_t* pdu, srslte::log_ref gtpu_log); +bool gtpu_read_header(srslte::byte_buffer_t* pdu, gtpu_header_t* header, srslog::basic_logger& logger); +bool gtpu_write_header(gtpu_header_t* header, srslte::byte_buffer_t* pdu, srslog::basic_logger& logger); std::string gtpu_ntoa(uint32_t addr); -inline bool gtpu_supported_flags_check(gtpu_header_t* header, srslte::log_ref gtpu_log) +inline bool gtpu_supported_flags_check(gtpu_header_t* header, srslog::basic_logger& logger) { // flags if ((header->flags & GTPU_FLAGS_VERSION_MASK) != GTPU_FLAGS_VERSION_V1) { - gtpu_log->error("gtpu_header - Unhandled GTP-U Version. Flags: 0x%x\n", header->flags); + logger.error("gtpu_header - Unhandled GTP-U Version. Flags: 0x%x", header->flags); return false; } if (!(header->flags & GTPU_FLAGS_GTP_PROTOCOL)) { - gtpu_log->error("gtpu_header - Unhandled Protocol Type. Flags: 0x%x\n\n", header->flags); + logger.error("gtpu_header - Unhandled Protocol Type. Flags: 0x%x", header->flags); return false; } if (header->flags & GTPU_FLAGS_PACKET_NUM) { - gtpu_log->error("gtpu_header - Unhandled Packet Number. Flags: 0x%x\n\n", header->flags); + logger.error("gtpu_header - Unhandled Packet Number. Flags: 0x%x", header->flags); return false; } return true; } -inline bool gtpu_supported_msg_type_check(gtpu_header_t* header, srslte::log_ref gtpu_log) +inline bool gtpu_supported_msg_type_check(gtpu_header_t* header, srslog::basic_logger& logger) { // msg_tpye if (header->message_type != GTPU_MSG_DATA_PDU && header->message_type != GTPU_MSG_ECHO_REQUEST && header->message_type != GTPU_MSG_ECHO_RESPONSE && header->message_type != GTPU_MSG_ERROR_INDICATION && header->message_type != GTPU_MSG_END_MARKER) { - gtpu_log->error("gtpu_header - Unhandled message type: 0x%x\n", header->message_type); + logger.error("gtpu_header - Unhandled message type: 0x%x", header->message_type); return false; } return true; diff --git a/lib/src/upper/gtpu.cc b/lib/src/upper/gtpu.cc index 223090023..7282809d6 100644 --- a/lib/src/upper/gtpu.cc +++ b/lib/src/upper/gtpu.cc @@ -23,24 +23,24 @@ const static size_t HEADER_PDCP_PDU_NUMBER_SIZE = 4; * Header pack/unpack helper functions * Ref: 3GPP TS 29.281 v10.1.0 Section 5 ***************************************************************************/ -bool gtpu_write_header(gtpu_header_t* header, srslte::byte_buffer_t* pdu, srslte::log_ref gtpu_log) +bool gtpu_write_header(gtpu_header_t* header, srslte::byte_buffer_t* pdu, srslog::basic_logger& logger) { // flags - if (!gtpu_supported_flags_check(header, gtpu_log)) { - gtpu_log->error("gtpu_write_header - Unhandled GTP-U Flags. Flags: 0x%x\n", header->flags); + if (!gtpu_supported_flags_check(header, logger)) { + logger.error("gtpu_write_header - Unhandled GTP-U Flags. Flags: 0x%x", header->flags); return false; } // msg type - if (!gtpu_supported_msg_type_check(header, gtpu_log)) { - gtpu_log->error("gtpu_write_header - Unhandled GTP-U Message Type. Message Type: 0x%x\n", header->message_type); + if (!gtpu_supported_msg_type_check(header, logger)) { + logger.error("gtpu_write_header - Unhandled GTP-U Message Type. Message Type: 0x%x", header->message_type); return false; } // If E, S or PN are set, the header is longer if (header->flags & (GTPU_FLAGS_EXTENDED_HDR | GTPU_FLAGS_SEQUENCE | GTPU_FLAGS_PACKET_NUM)) { if (pdu->get_headroom() < GTPU_EXTENDED_HEADER_LEN) { - gtpu_log->error("gtpu_write_header - No room in PDU for header\n"); + logger.error("gtpu_write_header - No room in PDU for header"); return false; } pdu->msg -= GTPU_EXTENDED_HEADER_LEN; @@ -51,7 +51,7 @@ bool gtpu_write_header(gtpu_header_t* header, srslte::byte_buffer_t* pdu, srslte } } else { if (pdu->get_headroom() < GTPU_BASE_HEADER_LEN) { - gtpu_log->error("gtpu_write_header - No room in PDU for header\n"); + logger.error("gtpu_write_header - No room in PDU for header"); return false; } pdu->msg -= GTPU_BASE_HEADER_LEN; @@ -101,7 +101,10 @@ bool gtpu_write_header(gtpu_header_t* header, srslte::byte_buffer_t* pdu, srslte return true; } -bool gtpu_read_ext_header(srslte::byte_buffer_t* pdu, uint8_t** ptr, gtpu_header_t* header, srslte::log_ref gtpu_log) +bool gtpu_read_ext_header(srslte::byte_buffer_t* pdu, + uint8_t** ptr, + gtpu_header_t* header, + srslog::basic_logger& logger) { if ((header->flags & GTPU_FLAGS_EXTENDED_HDR) == 0 or header->next_ext_hdr_type == 0) { return true; @@ -116,13 +119,13 @@ bool gtpu_read_ext_header(srslte::byte_buffer_t* pdu, uint8_t** ptr, gtpu_header (*ptr)++; } } else { - gtpu_log->error("gtpu_read_header - Unhandled GTP-U Extension Header Type: 0x%x\n", header->next_ext_hdr_type); + logger.error("gtpu_read_header - Unhandled GTP-U Extension Header Type: 0x%x", header->next_ext_hdr_type); return false; } return true; } -bool gtpu_read_header(srslte::byte_buffer_t* pdu, gtpu_header_t* header, srslte::log_ref gtpu_log) +bool gtpu_read_header(srslte::byte_buffer_t* pdu, gtpu_header_t* header, srslog::basic_logger& logger) { uint8_t* ptr = pdu->msg; @@ -136,14 +139,14 @@ bool gtpu_read_header(srslte::byte_buffer_t* pdu, gtpu_header_t* header, srslte: ptr += 4; // flags - if (!gtpu_supported_flags_check(header, gtpu_log)) { - gtpu_log->error("gtpu_read_header - Unhandled GTP-U Flags. Flags: 0x%x\n", header->flags); + if (!gtpu_supported_flags_check(header, logger)) { + logger.error("gtpu_read_header - Unhandled GTP-U Flags. Flags: 0x%x", header->flags); return false; } // message_type - if (!gtpu_supported_msg_type_check(header, gtpu_log)) { - gtpu_log->error("gtpu_read_header - Unhandled GTP-U Message Type. Flags: 0x%x\n", header->message_type); + if (!gtpu_supported_msg_type_check(header, logger)) { + logger.error("gtpu_read_header - Unhandled GTP-U Message Type. Flags: 0x%x", header->message_type); return false; } @@ -161,7 +164,7 @@ bool gtpu_read_header(srslte::byte_buffer_t* pdu, gtpu_header_t* header, srslte: header->next_ext_hdr_type = *ptr; ptr++; - if (not gtpu_read_ext_header(pdu, &ptr, header, gtpu_log)) { + if (not gtpu_read_ext_header(pdu, &ptr, header, logger)) { return false; } } else { diff --git a/srsenb/hdr/stack/upper/gtpu.h b/srsenb/hdr/stack/upper/gtpu.h index 13336e254..a01e4e479 100644 --- a/srsenb/hdr/stack/upper/gtpu.h +++ b/srsenb/hdr/stack/upper/gtpu.h @@ -69,7 +69,6 @@ private: std::string gtp_bind_addr; std::string mme_addr; srsenb::pdcp_interface_gtpu* pdcp = nullptr; - srslte::log_ref gtpu_log; srslog::basic_logger& logger; // Class to create @@ -88,7 +87,6 @@ private: private: gtpu* parent = nullptr; pdcp_interface_gtpu* pdcp = nullptr; - srslte::log_ref gtpu_log; srslog::basic_logger& logger; std::string m1u_multiaddr; std::string m1u_if_addr; diff --git a/srsenb/src/stack/upper/gtpu.cc b/srsenb/src/stack/upper/gtpu.cc index d6b67866e..d630e477b 100644 --- a/srsenb/src/stack/upper/gtpu.cc +++ b/srsenb/src/stack/upper/gtpu.cc @@ -21,7 +21,7 @@ using namespace srslte; namespace srsenb { -gtpu::gtpu(srslog::basic_logger& logger) : m1u(this), gtpu_log("GTPU"), logger(logger) {} +gtpu::gtpu(srslog::basic_logger& logger) : m1u(this), logger(logger) {} int gtpu::init(std::string gtp_bind_addr_, std::string mme_addr_, @@ -128,7 +128,7 @@ void gtpu::send_pdu_to_tunnel(tunnel& tx_tun, srslte::unique_byte_buffer_t pdu, servaddr.sin_addr.s_addr = htonl(tx_tun.spgw_addr); servaddr.sin_port = htons(GTPU_PORT); - if (!gtpu_write_header(&header, pdu.get(), gtpu_log)) { + if (!gtpu_write_header(&header, pdu.get(), logger)) { logger.error("Error writing GTP-U Header. Flags 0x%x, Message Type 0x%x", header.flags, header.message_type); return; } @@ -225,12 +225,12 @@ void gtpu::mod_bearer_rnti(uint16_t old_rnti, uint16_t new_rnti) logger.info("Modifying bearer rnti. Old rnti: 0x%x, new rnti: 0x%x", old_rnti, new_rnti); if (ue_teidin_db.count(new_rnti) != 0) { - gtpu_log->error("New rnti already exists, aborting.\n"); + logger.error("New rnti already exists, aborting."); return; } auto old_it = ue_teidin_db.find(old_rnti); if (old_it == ue_teidin_db.end()) { - gtpu_log->error("Old rnti does not exist, aborting.\n"); + logger.error("Old rnti does not exist, aborting."); return; } @@ -285,7 +285,7 @@ void gtpu::handle_gtpu_s1u_rx_packet(srslte::unique_byte_buffer_t pdu, const soc pdu->set_timestamp(); gtpu_header_t header; - if (not gtpu_read_header(pdu.get(), &header, gtpu_log)) { + if (not gtpu_read_header(pdu.get(), &header, logger)) { return; } @@ -416,7 +416,7 @@ void gtpu::error_indication(in_addr_t addr, in_port_t port, uint32_t err_teid) header.n_pdu = 0; header.next_ext_hdr_type = 0; - gtpu_write_header(&header, pdu.get(), gtpu_log); + gtpu_write_header(&header, pdu.get(), logger); struct sockaddr_in servaddr; servaddr.sin_family = AF_INET; @@ -446,7 +446,7 @@ void gtpu::echo_response(in_addr_t addr, in_port_t port, uint16_t seq) header.n_pdu = 0; header.next_ext_hdr_type = 0; - gtpu_write_header(&header, pdu.get(), gtpu_log); + gtpu_write_header(&header, pdu.get(), logger); struct sockaddr_in servaddr; servaddr.sin_family = AF_INET; @@ -473,7 +473,7 @@ void gtpu::end_marker(uint32_t teidin) header.teid = tunnel.teid_out; header.length = 0; - gtpu_write_header(&header, pdu.get(), gtpu_log); + gtpu_write_header(&header, pdu.get(), logger); struct sockaddr_in servaddr = {}; servaddr.sin_family = AF_INET; @@ -502,7 +502,7 @@ srslte::span gtpu::get_lcid_teids(uint16_t rnti, uint32_t lcid) auto ue_it = ue_teidin_db.find(rnti); if (ue_it == ue_teidin_db.end() or lcid < SRSENB_N_SRB or lcid >= SRSENB_N_RADIO_BEARERS or ue_it->second[lcid].empty()) { - logger.error("Could not find bearer rnti=0x%x, lcid=%d\n", rnti, lcid); + logger.error("Could not find bearer rnti=0x%x, lcid=%d", rnti, lcid); return {}; } return ue_it->second[lcid]; @@ -572,7 +572,6 @@ bool gtpu::m1u_handler::init(std::string m1u_multiaddr_, std::string m1u_if_addr m1u_multiaddr = std::move(m1u_multiaddr_); m1u_if_addr = std::move(m1u_if_addr_); pdcp = parent->pdcp; - gtpu_log = parent->gtpu_log; // Set up sink socket struct sockaddr_in bindaddr = {}; @@ -616,7 +615,7 @@ void gtpu::m1u_handler::handle_rx_packet(srslte::unique_byte_buffer_t pdu, const logger.debug("Received %d bytes from M1-U interface", pdu->N_bytes); gtpu_header_t header; - gtpu_read_header(pdu.get(), &header, gtpu_log); + gtpu_read_header(pdu.get(), &header, logger); pdcp->write_sdu(SRSLTE_MRNTI, lcid_counter, std::move(pdu)); } diff --git a/srsenb/test/upper/gtpu_test.cc b/srsenb/test/upper/gtpu_test.cc index 438832f76..0efefa671 100644 --- a/srsenb/test/upper/gtpu_test.cc +++ b/srsenb/test/upper/gtpu_test.cc @@ -98,7 +98,7 @@ srslte::unique_byte_buffer_t encode_gtpu_packet(srslte::span data, header.length = pdu->N_bytes; header.teid = teid; - gtpu_write_header(&header, pdu.get(), srslte::log_ref("GTPU")); + gtpu_write_header(&header, pdu.get(), srslog::fetch_basic_logger("GTPU")); return pdu; } @@ -113,7 +113,7 @@ srslte::unique_byte_buffer_t encode_end_marker(uint32_t teid) header.length = 0; header.teid = teid; - gtpu_write_header(&header, pdu.get(), srslte::log_ref("GTPU")); + gtpu_write_header(&header, pdu.get(), srslog::fetch_basic_logger("GTPU")); return pdu; } @@ -247,17 +247,16 @@ int test_gtpu_direct_tunneling() int main() { // Setup logging. - srslog::sink& log_sink = srslog::fetch_stdout_sink(); - srslog::log_channel* chan = srslog::create_log_channel("gtpu_test", log_sink); - srslte::srslog_wrapper log_wrapper(*chan); + auto& logger = srslog::fetch_basic_logger("GTPU", false); + logger.set_level(srslog::basic_levels::debug); + logger.set_hex_dump_max_size(-1); // Start the log backend. srslog::init(); - srslte::logmap::set_default_log_level(srslte::LOG_LEVEL_DEBUG); - srslte::logmap::set_default_hex_limit(100000); TESTASSERT(srsenb::test_gtpu_direct_tunneling() == SRSLTE_SUCCESS); srslog::flush(); + srslte::console("Success"); } diff --git a/srsepc/hdr/mbms-gw/mbms-gw.h b/srsepc/hdr/mbms-gw/mbms-gw.h index b949fab67..7c6cbceab 100644 --- a/srsepc/hdr/mbms-gw/mbms-gw.h +++ b/srsepc/hdr/mbms-gw/mbms-gw.h @@ -55,7 +55,7 @@ class mbms_gw : public srslte::thread public: static mbms_gw* get_instance(void); static void cleanup(void); - int init(mbms_gw_args_t* args, srslte::log_ref mbms_gw_log); + int init(mbms_gw_args_t* args); void stop(); void run_thread(); @@ -72,7 +72,6 @@ private: /* Members */ bool m_running; - srslte::log_ref m_mbms_gw_log; srslog::basic_logger& m_logger = srslog::fetch_basic_logger("MBMS"); bool m_sgi_mb_up; diff --git a/srsepc/hdr/spgw/gtpu.h b/srsepc/hdr/spgw/gtpu.h index d7e570c74..7d79b5f19 100644 --- a/srsepc/hdr/spgw/gtpu.h +++ b/srsepc/hdr/spgw/gtpu.h @@ -29,7 +29,7 @@ class spgw::gtpu : public gtpu_interface_gtpc public: gtpu(); virtual ~gtpu(); - int init(spgw_args_t* args, spgw* spgw, gtpc_interface_gtpu* gtpc, srslte::log_ref gtpu_log); + int init(spgw_args_t* args, spgw* spgw, gtpc_interface_gtpu* gtpc); void stop(); int init_sgi(spgw_args_t* args); @@ -65,8 +65,6 @@ public: // for downlink notifications. srslog::basic_logger& m_logger = srslog::fetch_basic_logger("GTPU"); - //:TODO: remove this once srslte common code loggers have been upgraded. - srslte::log_ref m_gtpu_log; }; inline int spgw::gtpu::get_sgi() diff --git a/srsepc/hdr/spgw/spgw.h b/srsepc/hdr/spgw/spgw.h index 460acbfb6..baff8d17e 100644 --- a/srsepc/hdr/spgw/spgw.h +++ b/srsepc/hdr/spgw/spgw.h @@ -61,7 +61,7 @@ class spgw : public srslte::thread public: static spgw* get_instance(void); static void cleanup(void); - int init(spgw_args_t* args, srslte::log_ref gtpu_log, const std::map& ip_to_imsi); + int init(spgw_args_t* args, const std::map& ip_to_imsi); void stop(); void run_thread(); diff --git a/srsepc/src/main.cc b/srsepc/src/main.cc index 5830ace2c..241b19ff8 100644 --- a/srsepc/src/main.cc +++ b/srsepc/src/main.cc @@ -472,7 +472,7 @@ int main(int argc, char* argv[]) } spgw* spgw = spgw::get_instance(); - if (spgw->init(&args.spgw_args, gtpu_log, hss->get_ip_to_imsi())) { + if (spgw->init(&args.spgw_args, hss->get_ip_to_imsi())) { cout << "Error initializing SP-GW" << endl; exit(1); } diff --git a/srsepc/src/mbms-gw/main.cc b/srsepc/src/mbms-gw/main.cc index 53494570d..d3bf88256 100644 --- a/srsepc/src/mbms-gw/main.cc +++ b/srsepc/src/mbms-gw/main.cc @@ -67,7 +67,6 @@ string config_file; void parse_args(all_args_t* args, int argc, char* argv[]) { - string mbms_gw_name; string mbms_gw_sgi_mb_if_name; string mbms_gw_sgi_mb_if_addr; @@ -216,7 +215,7 @@ int main(int argc, char* argv[]) mbms_gw_logger.set_hex_dump_max_size(args.log_args.mbms_gw_hex_limit); mbms_gw* mbms_gw = mbms_gw::get_instance(); - if (mbms_gw->init(&args.mbms_gw_args, mbms_gw_log)) { + if (mbms_gw->init(&args.mbms_gw_args)) { cout << "Error initializing MBMS-GW" << endl; exit(1); } diff --git a/srsepc/src/mbms-gw/mbms-gw.cc b/srsepc/src/mbms-gw/mbms-gw.cc index ea4c4b0c0..63967d150 100644 --- a/srsepc/src/mbms-gw/mbms-gw.cc +++ b/srsepc/src/mbms-gw/mbms-gw.cc @@ -60,13 +60,10 @@ void mbms_gw::cleanup(void) pthread_mutex_unlock(&mbms_gw_instance_mutex); } -int mbms_gw::init(mbms_gw_args_t* args, srslte::log_ref mbms_gw_log) +int mbms_gw::init(mbms_gw_args_t* args) { int err; - // Init log - m_mbms_gw_log = mbms_gw_log; - err = init_sgi_mb_if(args); if (err != SRSLTE_SUCCESS) { srslte::console("Error initializing SGi-MB.\n"); @@ -275,7 +272,7 @@ void mbms_gw::handle_sgi_md_pdu(srslte::byte_buffer_t* msg) } // Write GTP-U header into packet - if (!srslte::gtpu_write_header(&header, msg, m_mbms_gw_log)) { + if (!srslte::gtpu_write_header(&header, msg, m_logger)) { srslte::console("Error writing GTP-U header on PDU\n"); } diff --git a/srsepc/src/spgw/gtpu.cc b/srsepc/src/spgw/gtpu.cc index ba3a2ab04..cf749272c 100644 --- a/srsepc/src/spgw/gtpu.cc +++ b/srsepc/src/spgw/gtpu.cc @@ -43,13 +43,10 @@ spgw::gtpu::~gtpu() return; } -int spgw::gtpu::init(spgw_args_t* args, spgw* spgw, gtpc_interface_gtpu* gtpc, srslte::log_ref gtpu_log) +int spgw::gtpu::init(spgw_args_t* args, spgw* spgw, gtpc_interface_gtpu* gtpc) { int err; - // Init log - m_gtpu_log = gtpu_log; - // Store interfaces m_spgw = spgw; m_gtpc = gtpc; @@ -243,7 +240,7 @@ void spgw::gtpu::handle_sgi_pdu(srslte::unique_byte_buffer_t msg) void spgw::gtpu::handle_s1u_pdu(srslte::byte_buffer_t* msg) { srslte::gtpu_header_t header; - srslte::gtpu_read_header(msg, &header, m_gtpu_log); + srslte::gtpu_read_header(msg, &header, m_logger); m_logger.debug("Received PDU from S1-U. Bytes=%d", msg->N_bytes); m_logger.debug("TEID 0x%x. Bytes=%d", header.teid, msg->N_bytes); @@ -276,7 +273,7 @@ void spgw::gtpu::send_s1u_pdu(srslte::gtp_fteid_t enb_fteid, srslte::byte_buffer // Write header into packet int n; - if (!srslte::gtpu_write_header(&header, msg, m_gtpu_log)) { + if (!srslte::gtpu_write_header(&header, msg, m_logger)) { m_logger.error("Error writing GTP-U header on PDU"); goto out; } diff --git a/srsepc/src/spgw/spgw.cc b/srsepc/src/spgw/spgw.cc index d07d72739..829defaa1 100644 --- a/srsepc/src/spgw/spgw.cc +++ b/srsepc/src/spgw/spgw.cc @@ -56,12 +56,12 @@ void spgw::cleanup() pthread_mutex_unlock(&spgw_instance_mutex); } -int spgw::init(spgw_args_t* args, srslte::log_ref gtpu_log, const std::map& ip_to_imsi) +int spgw::init(spgw_args_t* args, const std::map& ip_to_imsi) { int err; // Init GTP-U - if (m_gtpu->init(args, this, m_gtpc, gtpu_log) != SRSLTE_SUCCESS) { + if (m_gtpu->init(args, this, m_gtpc) != SRSLTE_SUCCESS) { srslte::console("Could not initialize the SPGW's GTP-U.\n"); return SRSLTE_ERROR_CANT_START; }