From f93335fa50898fd2a1b5a27ce75fb7b87cd71daa Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 11 Oct 2017 12:22:02 +0100 Subject: [PATCH] Fixed bug of not subscribing to sctp_data_io_event --- srsepc/hdr/mme/mme.h | 2 ++ srsepc/hdr/mme/s1ap.h | 4 ++-- srsepc/src/main.cc | 36 +++++++++++++++++++++++++++-------- srsepc/src/mme/mme.cc | 7 +++++++ srsepc/src/mme/s1ap.cc | 43 ++++++++++++++++++++++++++++++++++++------ 5 files changed, 76 insertions(+), 16 deletions(-) diff --git a/srsepc/hdr/mme/mme.h b/srsepc/hdr/mme/mme.h index d9a985b19..7436993da 100644 --- a/srsepc/hdr/mme/mme.h +++ b/srsepc/hdr/mme/mme.h @@ -53,6 +53,8 @@ public: int init(all_args_t* args); + void stop(); + int get_s1_mme(); private: diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index 3a50cc80f..27e275736 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -43,9 +43,9 @@ class s1ap public: s1ap(); virtual ~s1ap(); - int enb_listen(); - + int enb_listen(); int init(s1ap_args_t s1ap_args); + void stop(); int get_s1_mme(); diff --git a/srsepc/src/main.cc b/srsepc/src/main.cc index 48c252da1..67399f9a2 100644 --- a/srsepc/src/main.cc +++ b/srsepc/src/main.cc @@ -24,6 +24,8 @@ * */ #include +#include +#include #include #include #include @@ -37,6 +39,12 @@ namespace bpo = boost::program_options; bool running = true; +void +sig_int_handler(int signo){ + running = false; +} + + /* void parse_args(all_args_t *args, int argc, char* argv[]) { @@ -84,7 +92,7 @@ main (int argc,char * argv[] ) { cout << "--- Software Radio Systems EPC MME ---" << endl << endl; - //signal(SIGINT, sig_int_handler); + signal(SIGINT, sig_int_handler); //TODO these should be passed from config files all_args_t args; @@ -100,7 +108,7 @@ main (int argc,char * argv[] ) struct sctp_sndrcvinfo sri; socklen_t fromlen; int rd_sz; - int msg_flags; + int msg_flags=0; mme *mme = mme::get_instance(); if (mme->init(&args)) { @@ -110,17 +118,29 @@ main (int argc,char * argv[] ) //Initalize S1-MME scoket int s1mme = mme->get_s1_mme(); + cout << "Socket: " << s1mme; while(running) { - cout << "Waiting for SCTP Msg" << endl; + cout << "Waiting for SCTP Msg on: " << s1mme << endl; + //cout << "Sri:" << sri <stop(); + mme->cleanup(); + cout << "--- exiting ---" << endl; return 0; } diff --git a/srsepc/src/mme/mme.cc b/srsepc/src/mme/mme.cc index e42e4f08a..c898d1a73 100644 --- a/srsepc/src/mme/mme.cc +++ b/srsepc/src/mme/mme.cc @@ -73,6 +73,13 @@ mme::init(all_args_t* args) return 0; } +void +mme::stop() +{ + m_s1ap.stop(); + return; +} + int mme::get_s1_mme() { diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index b53fe0479..2e6fc0b2b 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -31,11 +31,13 @@ #include #include #include +#include #include "mme/s1ap.h" namespace srsepc{ -s1ap::s1ap() +s1ap::s1ap(): + m_s1mme(-1) { } @@ -58,12 +60,28 @@ s1ap::init(s1ap_args_t s1ap_args) return 0; } +void +s1ap::stop() +{ + if (m_s1mme != -1){ + close(m_s1mme); + } + return; +} + +int +s1ap::get_s1_mme() +{ + return m_s1mme; +} + int s1ap::enb_listen() { /*This function sets up the SCTP socket for eNBs to connect to*/ int sock_fd, err; struct sockaddr_in s1mme_addr;//TODO make this a configurable class memeber. + struct sctp_event_subscribe evnts; sock_fd = socket (AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP); if (sock_fd == -1){ @@ -71,6 +89,22 @@ s1ap::enb_listen() return -1; } + //Set timeout + struct timeval timeout; + timeout.tv_sec = 1; + timeout.tv_usec = 0; + if (setsockopt (sock_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout)) < 0){ + std::cout << "Set socket timeout failed" << std::endl; + return -1; + } + + bzero (&evnts, sizeof (evnts)) ; + evnts.sctp_data_io_event = 1; + if(setsockopt(sock_fd, IPPROTO_SCTP, SCTP_EVENTS, &evnts, sizeof (evnts))){ + std::cout << "Subscribing to sctp_data_io_events failed" << std::cout; + return -1; + } + //S1-MME bind bzero(&s1mme_addr, sizeof(s1mme_addr)); s1mme_addr.sin_family = AF_INET; @@ -79,21 +113,18 @@ s1ap::enb_listen() err = bind(sock_fd, (struct sockaddr*) &s1mme_addr, sizeof (s1mme_addr)); if (err != 0){ std::cout << "Error binding SCTP socket" << std::endl; + return -1; } //Listen for connections err = listen(sock_fd,SOMAXCONN); if (err != 0){ std::cout << "Error in SCTP socket listen" << std::endl; + return -1; } return sock_fd; } -int -s1ap::get_s1_mme() -{ - return m_s1mme; -} }//namespace srsepc