From 3e61448a414a253759bab330734598b232b88a2d Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 25 Nov 2021 12:07:58 +0000 Subject: [PATCH] gnb,ngap: added logging for Rx NGAP messages. --- srsgnb/hdr/stack/ngap/ngap.h | 4 ++++ srsgnb/src/stack/ngap/ngap.cc | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/srsgnb/hdr/stack/ngap/ngap.h b/srsgnb/hdr/stack/ngap/ngap.h index 3c5417afa..27c900781 100644 --- a/srsgnb/hdr/stack/ngap/ngap.h +++ b/srsgnb/hdr/stack/ngap/ngap.h @@ -78,6 +78,10 @@ public: // PCAP void start_pcap(srsran::ngap_pcap* pcap_); + // Logging + typedef enum { Rx = 0, Tx } direction_t; + void log_ngap_message(const asn1::ngap_nr::ngap_pdu_c& msg, const direction_t dir, srsran::const_byte_span pdu); + private: static const int AMF_PORT = 38412; static const int ADDR_FAMILY = AF_INET; diff --git a/srsgnb/src/stack/ngap/ngap.cc b/srsgnb/src/stack/ngap/ngap.cc index 3da0f86e9..bdc3a8a50 100644 --- a/srsgnb/src/stack/ngap/ngap.cc +++ b/srsgnb/src/stack/ngap/ngap.cc @@ -376,6 +376,7 @@ bool ngap::handle_ngap_rx_pdu(srsran::byte_buffer_t* pdu) pcap->write_ngap(pdu->msg, pdu->N_bytes); } + // Unpack ngap_pdu_c rx_pdu; asn1::cbit_ref bref(pdu->msg, pdu->N_bytes); @@ -387,6 +388,10 @@ bool ngap::handle_ngap_rx_pdu(srsran::byte_buffer_t* pdu) return false; } + // Logging + log_ngap_message(rx_pdu, Rx, srsran::make_span(*pdu)); + + // Handle the NGAP message switch (rx_pdu.type().value) { case ngap_pdu_c::types_opts::init_msg: return handle_initiating_message(rx_pdu.init_msg()); @@ -805,4 +810,30 @@ void ngap::start_pcap(srsran::ngap_pcap* pcap_) { pcap = pcap_; } + +void ngap::log_ngap_message(const ngap_pdu_c& msg, const direction_t dir, srsran::const_byte_span pdu) +{ + std::string msg_type = {}; + switch (msg.type().value) { + case ngap_pdu_c::types_opts::init_msg: + msg_type = msg.init_msg().value.type().to_string(); + break; + case ngap_pdu_c::types_opts::successful_outcome: + msg_type = msg.successful_outcome().value.type().to_string(); + break; + case ngap_pdu_c::types_opts::unsuccessful_outcome: + msg_type = msg.unsuccessful_outcome().value.type().to_string(); + break; + default: + return; + } + if (logger.debug.enabled()) { + asn1::json_writer json_writer; + msg.to_json(json_writer); + logger.debug(pdu.data(), pdu.size(), "%s - %s (%d B)", (dir == Rx) ? "Rx" : "Tx", msg_type, pdu.size()); + logger.debug("Content:%s", json_writer.to_string().c_str()); + } else if (logger.info.enabled()) { + logger.info(pdu.data(), pdu.size(), "%s - %s (%d B)", (dir == Rx) ? "Rx" : "Tx", msg_type, pdu.size()); + } +} } // namespace srsenb