diff --git a/lib/src/common/logger_file.cc b/lib/src/common/logger_file.cc index 94e5e8405..c1c31523e 100644 --- a/lib/src/common/logger_file.cc +++ b/lib/src/common/logger_file.cc @@ -40,7 +40,7 @@ logger_file::logger_file() logger_file::~logger_file() { not_done = false; - log(new std::string("Closing log")); + log(new std::string("Closing log\n")); if(inited) { wait_thread_finish(); flush(); diff --git a/srsepc/hdr/hss/hss.h b/srsepc/hdr/hss/hss.h index df19aed4e..f8a23809d 100644 --- a/srsepc/hdr/hss/hss.h +++ b/srsepc/hdr/hss/hss.h @@ -53,7 +53,7 @@ class hss public: static hss* get_instance(void); static void cleanup(void); - int init(hss_args_t *hss_args, srslte::logger* logger); + int init(hss_args_t *hss_args, srslte::log_filter* hss_log); void get_sqn(uint8_t sqn[6]); void gen_rand(uint8_t rand_[16]); @@ -66,15 +66,11 @@ private: virtual ~hss(); static hss *m_instance; - uint64_t m_sqn; //48 bits + uint64_t m_sqn; //48 bits srslte::byte_buffer_pool *m_pool; /*Logs*/ - srslte::logger_stdout m_logger_stdout; - srslte::logger_file m_logger_file; - srslte::logger *m_logger; - - srslte::log_filter m_hss_log; + srslte::log_filter *m_hss_log; }; diff --git a/srsepc/hdr/mme/mme.h b/srsepc/hdr/mme/mme.h index 74c74afed..2fec2a23a 100644 --- a/srsepc/hdr/mme/mme.h +++ b/srsepc/hdr/mme/mme.h @@ -66,7 +66,7 @@ class mme: public: static mme* get_instance(void); static void cleanup(void); - int init(mme_args_t* args, srslte::logger *logger); + int init(mme_args_t* args, srslte::log_filter *s1ap_log); void stop(); int get_s1_mme(); void run_thread(); @@ -82,11 +82,7 @@ private: srslte::byte_buffer_pool *m_pool; /*Logs*/ - //srslte::logger_stdout m_logger_stdout; - //srslte::logger_file m_logger_file; - srslte::logger *m_logger; - - srslte::log_filter m_s1ap_log; + srslte::log_filter *m_s1ap_log; }; diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index 2887938da..454c31b4d 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -53,7 +53,7 @@ public: s1ap(); virtual ~s1ap(); int enb_listen(); - int init(s1ap_args_t s1ap_args, srslte::log *s1ap_log); + int init(s1ap_args_t s1ap_args, srslte::log_filter *s1ap_log); void stop(); int get_s1_mme(); @@ -79,7 +79,8 @@ private: s1ap_args_t m_s1ap_args; uint32_t m_plmn; srslte::byte_buffer_pool *m_pool; - srslte::log *m_s1ap_log; + srslte::logger *m_logger; + srslte::log_filter *m_s1ap_log; hss *m_hss; int m_s1mme; diff --git a/srsepc/src/hss/hss.cc b/srsepc/src/hss/hss.cc index 4a21f2614..28d70ca69 100644 --- a/srsepc/src/hss/hss.cc +++ b/srsepc/src/hss/hss.cc @@ -71,18 +71,14 @@ hss::cleanup(void) } int -hss::init(hss_args_t *hss_args, srslte::logger *logger) +hss::init(hss_args_t *hss_args, srslte::log_filter *hss_log) { /*Init loggers*/ - m_logger=logger; - m_hss_log.init("HSS", m_logger); - m_hss_log.set_level(srslte::LOG_LEVEL_DEBUG); - m_hss_log.set_hex_limit(32); - srand(time(NULL)); - m_hss_log.info("Initialized HSS\n"); - m_hss_log.console("Initialized HSS\n"); + m_hss_log = hss_log; + m_hss_log->info("HSS Initialized\n"); + m_hss_log->console("HSS Initialized\n"); return 0; } @@ -169,7 +165,7 @@ hss::gen_auth_info_answer_milenage(uint64_t imsi, uint8_t *k_asme, uint8_t *autn } std::cout<console("AUTN: %s", autn_str.c_str()); return true; } @@ -183,11 +179,11 @@ hss::get_k_amf_op(uint64_t imsi, uint8_t *k, uint8_t *amf, uint8_t *op ) if(imsi != 1010123456789) { - m_hss_log.console("Usernot found. IMSI: %015lu\n",imsi); + m_hss_log->console("User not found. IMSI: %015lu\n",imsi); return false; } - m_hss_log.console("Found User %015lu\n",imsi); + m_hss_log->console("Found User %015lu\n",imsi); memcpy(k,k_tmp,16); memcpy(amf,amf_tmp,2); memcpy(op,op_tmp,16); diff --git a/srsepc/src/main.cc b/srsepc/src/main.cc index d75bc14d2..bcf9e70c6 100644 --- a/srsepc/src/main.cc +++ b/srsepc/src/main.cc @@ -159,7 +159,7 @@ main (int argc,char * argv[] ) /*Init logger*/ - args.log_args.filename = std::string("/tmp/epc.log"); //FIXME + args.log_args.filename = std::string("/tmp/epc.log"); if (!args.log_args.filename.compare("stdout")) { logger = &logger_stdout; } else { @@ -168,17 +168,29 @@ main (int argc,char * argv[] ) logger = &logger_file; } + srslte::log_filter s1ap_log; + s1ap_log.init("S1AP",logger); + s1ap_log.set_level(srslte::LOG_LEVEL_DEBUG); + s1ap_log.set_hex_limit(32); + + srslte::log_filter hss_log; + hss_log.init("HSS ",logger); + hss_log.set_level(srslte::LOG_LEVEL_DEBUG); + hss_log.set_hex_limit(32); + mme *mme = mme::get_instance(); - if (mme->init(&args.mme_args, logger)) { + if (mme->init(&args.mme_args, &s1ap_log)) { cout << "Error initializing MME" << endl; exit(1); } + hss *hss = hss::get_instance(); - if (hss->init(&args.hss_args,logger)) { + if (hss->init(&args.hss_args,&hss_log)) { cout << "Error initializing HSS" << endl; exit(1); } - + + mme->start(); while(running) { @@ -187,7 +199,8 @@ main (int argc,char * argv[] ) mme->stop(); mme->cleanup(); - + + cout << "--- exiting ---" << endl; return 0; } diff --git a/srsepc/src/mme/mme.cc b/srsepc/src/mme/mme.cc index 9cc19030d..bc9e7ea39 100644 --- a/srsepc/src/mme/mme.cc +++ b/srsepc/src/mme/mme.cc @@ -70,27 +70,19 @@ mme::cleanup(void) } int -mme::init(mme_args_t* args, srslte::logger *logger) +mme::init(mme_args_t* args, srslte::log_filter *s1ap_log) { - /*Init loggers*/ - /* - if (!args->log_args.filename.compare("stdout")) { - m_logger = &m_logger_stdout; - } else { - m_logger_file.init(args->log_args.filename); - m_logger_file.log("\n--- Software Radio Systems MME log ---\n\n"); - m_logger = &m_logger_file; - } - */ - m_s1ap_log.init("S1AP", m_logger); - m_s1ap_log.set_level(srslte::LOG_LEVEL_DEBUG); - m_s1ap_log.set_hex_limit(32); - if(m_s1ap.init(args->s1ap_args, &m_s1ap_log)){ - m_s1ap_log.error("Error initializing MME S1APP\n"); + + /*Init S1AP*/ + if(m_s1ap.init(args->s1ap_args, s1ap_log)){ + m_s1ap_log->error("Error initializing MME S1APP\n"); exit(-1); } - m_s1ap_log.info("Initialized S1-MME\n"); - m_s1ap_log.console("Initialized S1-MME\n"); + + /*Init logger*/ + m_s1ap_log = s1ap_log; + m_s1ap_log->info("MME Initialized\n"); + m_s1ap_log->console("MME Initialized\n"); return 0; } @@ -127,30 +119,30 @@ mme::run_thread() int s1mme = m_s1ap.get_s1_mme(); while(m_running) { - m_s1ap_log.debug("Waiting for SCTP Msg\n"); + m_s1ap_log->debug("Waiting for SCTP Msg\n"); pdu->reset(); rd_sz = sctp_recvmsg(s1mme, pdu->msg, sz,(struct sockaddr*) &enb_addr, &fromlen, &sri, &msg_flags); if (rd_sz == -1 && errno != EAGAIN){ - m_s1ap_log.error("Error reading from SCTP socket: %s", strerror(errno)); + m_s1ap_log->error("Error reading from SCTP socket: %s", strerror(errno)); } else if (rd_sz == -1 && errno == EAGAIN){ - m_s1ap_log.debug("Socket timeout reached"); + m_s1ap_log->debug("Socket timeout reached"); } else{ if(msg_flags & MSG_NOTIFICATION) { //Received notification - m_s1ap_log.console("SCTP Notification %d\n", ((union sctp_notification*)pdu->msg)->sn_header.sn_type); + m_s1ap_log->console("SCTP Notification %d\n", ((union sctp_notification*)pdu->msg)->sn_header.sn_type); if (((union sctp_notification*)pdu->msg)->sn_header.sn_type == SCTP_SHUTDOWN_EVENT) { - m_s1ap_log.console("SCTP Association Gracefully Shutdown\n");//TODO + m_s1ap_log->console("SCTP Association Gracefully Shutdown\n");//TODO } } else { //Received data pdu->N_bytes = rd_sz; - m_s1ap_log.info("Received S1AP msg. Size: %d\n", pdu->N_bytes); + m_s1ap_log->info("Received S1AP msg. Size: %d\n", pdu->N_bytes); m_s1ap.handle_s1ap_rx_pdu(pdu,&sri); } } diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 89b0a24f0..b2da4fdaa 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -42,9 +42,9 @@ s1ap::~s1ap() } int -s1ap::init(s1ap_args_t s1ap_args, srslte::log *s1ap_log) +s1ap::init(s1ap_args_t s1ap_args, srslte::log_filter *s1ap_log) { - + m_s1ap_args = s1ap_args; srslte::s1ap_mccmnc_to_plmn(s1ap_args.mcc, s1ap_args.mnc, &m_plmn); @@ -56,6 +56,7 @@ s1ap::init(s1ap_args_t s1ap_args, srslte::log *s1ap_log) m_s1mme = enb_listen(); + m_s1ap_log->info("S1AP Initialized\n"); return 0; } @@ -89,7 +90,7 @@ s1ap::enb_listen() struct sockaddr_in s1mme_addr; struct sctp_event_subscribe evnts; - m_s1ap_log->console("Initializing S1-MME\n"); + m_s1ap_log->info("S1-MME Initializing\n"); sock_fd = socket (AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP); if (sock_fd == -1){ m_s1ap_log->console("Could not create SCTP socket\n");