General code cleanup

master
Pedro Alvarez 7 years ago
parent 4307a5aef2
commit 4f6fafb66d

@ -38,6 +38,7 @@
#include "srslte/common/logger_file.h" #include "srslte/common/logger_file.h"
#include "srslte/common/log_filter.h" #include "srslte/common/log_filter.h"
#include "srslte/common/buffer_pool.h" #include "srslte/common/buffer_pool.h"
#include "srslte/common/threads.h"
#include "s1ap.h" #include "s1ap.h"
@ -57,20 +58,16 @@ typedef struct{
} all_args_t; } all_args_t;
class mme class mme:
public thread
{ {
public: public:
static mme* get_instance(void); static mme* get_instance(void);
static void cleanup(void); static void cleanup(void);
int init(all_args_t* args); int init(all_args_t* args);
void stop(); void stop();
int get_s1_mme(); int get_s1_mme();
void run_thread();
void main_loop();
private: private:
@ -79,6 +76,7 @@ private:
static mme *m_instance; static mme *m_instance;
s1ap m_s1ap; s1ap m_s1ap;
bool m_running;
srslte::byte_buffer_pool *m_pool; srslte::byte_buffer_pool *m_pool;
/*Logs*/ /*Logs*/

@ -134,7 +134,7 @@ int
main (int argc,char * argv[] ) main (int argc,char * argv[] )
{ {
cout << "--- Software Radio Systems EPC ---" << endl << endl; cout << "--- Software Radio Systems EPC ---" << endl << endl;
signal(SIGINT, sig_int_handler); signal(SIGINT, sig_int_handler);
all_args_t args; all_args_t args;
parse_args(&args, argc, argv); parse_args(&args, argc, argv);
@ -146,11 +146,15 @@ main (int argc,char * argv[] )
cout << "Error initializing MME" << endl; cout << "Error initializing MME" << endl;
exit(1); exit(1);
} }
mme->start();
mme->main_loop(); while(running) {
sleep(0.5);
}
mme->stop(); mme->stop();
mme->cleanup(); mme->cleanup();
cout << "--- exiting ---" << endl; cout << "--- exiting ---" << endl;
return 0; return 0;
} }

@ -37,7 +37,8 @@ namespace srsepc{
mme* mme::m_instance = NULL; mme* mme::m_instance = NULL;
boost::mutex mme_instance_mutex; boost::mutex mme_instance_mutex;
mme::mme() mme::mme():
m_running(false)
{ {
m_pool = srslte::byte_buffer_pool::get_instance(); m_pool = srslte::byte_buffer_pool::get_instance();
return; return;
@ -71,7 +72,6 @@ mme::cleanup(void)
int int
mme::init(all_args_t* args) mme::init(all_args_t* args)
{ {
/*Init loggers*/ /*Init loggers*/
if (!args->log_args.filename.compare("stdout")) { if (!args->log_args.filename.compare("stdout")) {
m_logger = &m_logger_stdout; m_logger = &m_logger_stdout;
@ -95,6 +95,12 @@ mme::init(all_args_t* args)
void void
mme::stop() mme::stop()
{ {
if(m_running)
{
m_running = false;
thread_cancel();
wait_thread_finish();
}
m_s1ap.stop(); m_s1ap.stop();
return; return;
} }
@ -106,7 +112,7 @@ mme::get_s1_mme()
} }
void void
mme::main_loop() mme::run_thread()
{ {
srslte::byte_buffer_t *pdu = m_pool->allocate(); srslte::byte_buffer_t *pdu = m_pool->allocate();
uint32_t sz = SRSLTE_MAX_BUFFER_SIZE_BYTES - SRSLTE_BUFFER_HEADER_OFFSET; uint32_t sz = SRSLTE_MAX_BUFFER_SIZE_BYTES - SRSLTE_BUFFER_HEADER_OFFSET;
@ -118,29 +124,30 @@ mme::main_loop()
int rd_sz; int rd_sz;
int msg_flags=0; int msg_flags=0;
//Mark the thread as running
m_running=true;
//Get S1-MME socket //Get S1-MME socket
int s1mme = m_s1ap.get_s1_mme(); int s1mme = m_s1ap.get_s1_mme();
while(true) while(m_running)
{ {
std::cout << "Waiting for SCTP Msg " << std::endl; //std::cout << "Waiting for SCTP Msg " << std::endl;
m_s1ap_log.debug("Waiting for SCTP Msg");
pdu->reset(); pdu->reset();
rd_sz = sctp_recvmsg(s1mme, pdu->msg, sz,(struct sockaddr*) &enb_addr, &fromlen, &sri, &msg_flags); rd_sz = sctp_recvmsg(s1mme, pdu->msg, sz,(struct sockaddr*) &enb_addr, &fromlen, &sri, &msg_flags);
if (rd_sz == -1 && errno != EAGAIN){ if (rd_sz == -1 && errno != EAGAIN){
std::cout<< "Error reading from SCTP socket" << std::endl; m_s1ap_log.error("Error reading from SCTP socket: %s", strerror(errno));
printf("Error: %s\n", strerror(errno));
} }
else if (rd_sz == -1 && errno == EAGAIN){ else if (rd_sz == -1 && errno == EAGAIN){
std::cout << "Timeout reached" << std::endl; m_s1ap_log("Socket timeout reached");
} }
else{ else{
pdu->N_bytes = rd_sz; pdu->N_bytes = rd_sz;
std::cout<< "Received SCTP msg." << std::endl; m_s1ap_log("Received S1AP msg. Size: %d", pdu->N_bytes);
std::cout << "\tSize: " << pdu->N_bytes << std::endl;
std::cout << "\tMsg: " << pdu->msg << std::endl;
m_s1ap.handle_s1ap_rx_pdu(pdu,&sri); m_s1ap.handle_s1ap_rx_pdu(pdu,&sri);
} }
} }
return;
} }
} //namespace srsepe< } //namespace srsepe<

Loading…
Cancel
Save