From b89ad628e244f15e04cf4961d4b1e6ffbad93ac8 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 10 Jul 2018 14:23:21 +0100 Subject: [PATCH] Added config option to enable pcap. --- srsepc/epc.conf.example | 17 +++++++++-- srsepc/hdr/mme/s1ap.h | 1 + srsepc/hdr/mme/s1ap_common.h | 2 ++ srsepc/src/main.cc | 55 +++++++++++++++++++----------------- srsepc/src/mme/s1ap.cc | 19 +++++++++---- 5 files changed, 61 insertions(+), 33 deletions(-) diff --git a/srsepc/epc.conf.example b/srsepc/epc.conf.example index 02ef797ef..cc322a90f 100644 --- a/srsepc/epc.conf.example +++ b/srsepc/epc.conf.example @@ -45,8 +45,21 @@ db_file = user_db.csv ##################################################################### [spgw] -gtpu_bind_addr=127.0.1.100 -sgi_if_addr=172.16.0.1 +gtpu_bind_addr = 127.0.1.100 +sgi_if_addr = 172.16.0.1 + +#################################################################### +# PCAP configuration +# +# Enable PCAP tracing of S1AP packets +# +# enable: Enable or disable the PCAP. +# filename: File name where to save the PCAP. +# +#################################################################### +[pcap] +enable = false +filename = /tmp/epc.pcap #################################################################### # Log configuration diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index 61c78c664..f8c6cee28 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -128,6 +128,7 @@ private: mme_gtpc *m_mme_gtpc; //PCAP + bool m_pcap_enable; srslte::s1ap_pcap m_pcap; }; diff --git a/srsepc/hdr/mme/s1ap_common.h b/srsepc/hdr/mme/s1ap_common.h index 262d034b1..e5c198748 100644 --- a/srsepc/hdr/mme/s1ap_common.h +++ b/srsepc/hdr/mme/s1ap_common.h @@ -93,6 +93,8 @@ typedef struct{ std::string mme_name; std::string dns_addr; std::string mme_apn; + bool pcap_enable; + std::string pcap_filename; } s1ap_args_t; typedef struct{ diff --git a/srsepc/src/main.cc b/srsepc/src/main.cc index 27b365a49..e5c998ed7 100644 --- a/srsepc/src/main.cc +++ b/srsepc/src/main.cc @@ -100,35 +100,38 @@ parse_args(all_args_t *args, int argc, char* argv[]) { bpo::options_description common("Configuration options"); common.add_options() - ("mme.mme_code", bpo::value(&mme_code)->default_value("0x01"), "MME Code") - ("mme.name", bpo::value(&mme_name)->default_value("srsmme01"), "MME Name") - ("mme.mme_group", bpo::value(&mme_group)->default_value("0x01"), "Cell ID") - ("mme.tac", bpo::value(&tac)->default_value("0x0"), "Tracking Area Code") - ("mme.mcc", bpo::value(&mcc)->default_value("001"), "Mobile Country Code") - ("mme.mnc", bpo::value(&mnc)->default_value("01"), "Mobile Network Code") - ("mme.mme_bind_addr", bpo::value(&mme_bind_addr)->default_value("127.0.0.1"),"IP address of MME for S1 connnection") - ("mme.dns_addr", bpo::value(&dns_addr)->default_value("8.8.8.8"),"IP address of the DNS server for the UEs") - ("mme.apn", bpo::value(&mme_apn)->default_value(""), "Set Access Point Name (APN) for data services") - ("hss.db_file", bpo::value(&hss_db_file)->default_value("ue_db.csv"),".csv file that stores UE's keys") - ("hss.auth_algo", bpo::value(&hss_auth_algo)->default_value("milenage"),"HSS uthentication algorithm.") - ("spgw.gtpu_bind_addr", bpo::value(&spgw_bind_addr)->default_value("127.0.0.1"),"IP address of SP-GW for the S1-U connection") - ("spgw.sgi_if_addr", bpo::value(&sgi_if_addr)->default_value("176.16.0.1"),"IP address of TUN interface for the SGi connection") - - ("log.s1ap_level", bpo::value(&args->log_args.s1ap_level), "MME S1AP log level") - ("log.s1ap_hex_limit", bpo::value(&args->log_args.s1ap_hex_limit), "MME S1AP log hex dump limit") - ("log.gtpc_level", bpo::value(&args->log_args.gtpc_level), "MME GTPC log level") - ("log.gtpc_hex_limit", bpo::value(&args->log_args.gtpc_hex_limit), "MME GTPC log hex dump limit") - ("log.spgw_level", bpo::value(&args->log_args.spgw_level), "SPGW log level") - ("log.spgw_hex_limit", bpo::value(&args->log_args.spgw_hex_limit), "SPGW log hex dump limit") + ("mme.mme_code", bpo::value(&mme_code)->default_value("0x01"), "MME Code") + ("mme.name", bpo::value(&mme_name)->default_value("srsmme01"), "MME Name") + ("mme.mme_group", bpo::value(&mme_group)->default_value("0x01"), "Cell ID") + ("mme.tac", bpo::value(&tac)->default_value("0x0"), "Tracking Area Code") + ("mme.mcc", bpo::value(&mcc)->default_value("001"), "Mobile Country Code") + ("mme.mnc", bpo::value(&mnc)->default_value("01"), "Mobile Network Code") + ("mme.mme_bind_addr", bpo::value(&mme_bind_addr)->default_value("127.0.0.1"), "IP address of MME for S1 connnection") + ("mme.dns_addr", bpo::value(&dns_addr)->default_value("8.8.8.8"), "IP address of the DNS server for the UEs") + ("mme.apn", bpo::value(&mme_apn)->default_value(""), "Set Access Point Name (APN) for data services") + ("hss.db_file", bpo::value(&hss_db_file)->default_value("ue_db.csv"), ".csv file that stores UE's keys") + ("hss.auth_algo", bpo::value(&hss_auth_algo)->default_value("milenage"), "HSS uthentication algorithm.") + ("spgw.gtpu_bind_addr", bpo::value(&spgw_bind_addr)->default_value("127.0.0.1"), "IP address of SP-GW for the S1-U connection") + ("spgw.sgi_if_addr", bpo::value(&sgi_if_addr)->default_value("176.16.0.1"), "IP address of TUN interface for the SGi connection") + + ("pcap.enable", bpo::value(&args->mme_args.s1ap_args.pcap_enable)->default_value(false), "Enable S1AP PCAP") + ("pcap.filename", bpo::value(&args->mme_args.s1ap_args.pcap_filename)->default_value("/tmp/epc.pcap"), "PCAP filename") + + ("log.s1ap_level", bpo::value(&args->log_args.s1ap_level), "MME S1AP log level") + ("log.s1ap_hex_limit", bpo::value(&args->log_args.s1ap_hex_limit), "MME S1AP log hex dump limit") + ("log.gtpc_level", bpo::value(&args->log_args.gtpc_level), "MME GTPC log level") + ("log.gtpc_hex_limit", bpo::value(&args->log_args.gtpc_hex_limit), "MME GTPC log hex dump limit") + ("log.spgw_level", bpo::value(&args->log_args.spgw_level), "SPGW log level") + ("log.spgw_hex_limit", bpo::value(&args->log_args.spgw_hex_limit), "SPGW log hex dump limit") //("log.gtpu_level", bpo::value(&args->log.gtpu_level), "GTPU log level") - ("log.hss_level", bpo::value(&args->log_args.hss_level), "HSS log level") - ("log.hss_hex_limit", bpo::value(&args->log_args.hss_hex_limit), "HSS log hex dump limit") + ("log.hss_level", bpo::value(&args->log_args.hss_level), "HSS log level") + ("log.hss_hex_limit", bpo::value(&args->log_args.hss_hex_limit), "HSS log hex dump limit") //("log.gtpu_hex_limit",bpo::value(&args->log.gtpu_hex_limit), "GTPU log hex dump limit") - ("log.all_level", bpo::value(&args->log_args.all_level)->default_value("info"), "ALL log level") - ("log.all_hex_limit", bpo::value(&args->log_args.all_hex_limit)->default_value(32), "ALL log hex dump limit") + ("log.all_level", bpo::value(&args->log_args.all_level)->default_value("info"), "ALL log level") + ("log.all_hex_limit", bpo::value(&args->log_args.all_hex_limit)->default_value(32), "ALL log hex dump limit") - ("log.filename", bpo::value(&args->log_args.filename)->default_value("/tmp/epc.log"),"Log filename") + ("log.filename", bpo::value(&args->log_args.filename)->default_value("/tmp/epc.log"),"Log filename") ; // Positional options - config file location @@ -141,7 +144,7 @@ parse_args(all_args_t *args, int argc, char* argv[]) { // these options are allowed on the command line bpo::options_description cmdline_options; - cmdline_options.add(common).add(position).add(general); + cmdline_options.add(common).add(position).add(general); // parse the command line and store result in vm bpo::variables_map vm; diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 05949fa45..1dcf756e7 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -100,8 +100,12 @@ s1ap::init(s1ap_args_t s1ap_args, srslte::log_filter *s1ap_log, hss_interface_s1 m_s1mme = enb_listen(); //Init PCAP - m_pcap.open("/tmp/epc.pcap"); - m_s1ap_log->info("S1AP Initialized\n"); + m_pcap_enable = s1ap_args.pcap_enable; + if(m_pcap_enable) + { + m_pcap.open(s1ap_args.pcap_filename.c_str()); + m_s1ap_log->info("S1AP Initialized\n"); + } return 0; } @@ -134,7 +138,10 @@ s1ap::stop() s1ap_ctx_mngmt_proc::cleanup(); //PCAP - m_pcap.close(); + if(m_pcap_enable) + { + m_pcap.close(); + } return; } @@ -213,7 +220,9 @@ s1ap::handle_s1ap_rx_pdu(srslte::byte_buffer_t *pdu, struct sctp_sndrcvinfo *enb return false; } - m_pcap.write_s1ap(pdu->msg,pdu->N_bytes); + if(m_pcap_enable){ + m_pcap.write_s1ap(pdu->msg,pdu->N_bytes); + } switch(rx_pdu.choice_type) { case LIBLTE_S1AP_S1AP_PDU_CHOICE_INITIATINGMESSAGE: @@ -503,7 +512,7 @@ s1ap::release_ue_ecm_ctx(uint32_t mme_ue_s1ap_id) m_s1ap_log->error("Could not find eNB for UE release request.\n"); return false; } - uint16_t enb_id = it->second; + uint16_t enb_id = it->second; std::map >::iterator ue_set = m_enb_assoc_to_ue_ids.find(ecm_ctx->enb_sri.sinfo_assoc_id); if(ue_set == m_enb_assoc_to_ue_ids.end()) {