Fixed bug of not subscribing to sctp_data_io_event

master
Pedro Alvarez 7 years ago
parent 396335afee
commit f93335fa50

@ -53,6 +53,8 @@ public:
int init(all_args_t* args); int init(all_args_t* args);
void stop();
int get_s1_mme(); int get_s1_mme();
private: private:

@ -44,8 +44,8 @@ public:
s1ap(); s1ap();
virtual ~s1ap(); virtual ~s1ap();
int enb_listen(); int enb_listen();
int init(s1ap_args_t s1ap_args); int init(s1ap_args_t s1ap_args);
void stop();
int get_s1_mme(); int get_s1_mme();

@ -24,6 +24,8 @@
* *
*/ */
#include <iostream> #include <iostream>
#include <errno.h>
#include <signal.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
@ -37,6 +39,12 @@ namespace bpo = boost::program_options;
bool running = true; bool running = true;
void
sig_int_handler(int signo){
running = false;
}
/* /*
void void
parse_args(all_args_t *args, int argc, char* argv[]) { 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; 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 //TODO these should be passed from config files
all_args_t args; all_args_t args;
@ -100,7 +108,7 @@ main (int argc,char * argv[] )
struct sctp_sndrcvinfo sri; struct sctp_sndrcvinfo sri;
socklen_t fromlen; socklen_t fromlen;
int rd_sz; int rd_sz;
int msg_flags; int msg_flags=0;
mme *mme = mme::get_instance(); mme *mme = mme::get_instance();
if (mme->init(&args)) { if (mme->init(&args)) {
@ -110,17 +118,29 @@ main (int argc,char * argv[] )
//Initalize S1-MME scoket //Initalize S1-MME scoket
int s1mme = mme->get_s1_mme(); int s1mme = mme->get_s1_mme();
cout << "Socket: " << s1mme;
while(running) while(running)
{ {
cout << "Waiting for SCTP Msg" << endl; cout << "Waiting for SCTP Msg on: " << s1mme << endl;
//cout << "Sri:" << sri <<endl;
cout << "Flags:" << msg_flags <<endl;
rd_sz = sctp_recvmsg(s1mme, (void*) readbuf, sizeof(readbuf),(struct sockaddr*) &enb_addr, &fromlen, &sri, &msg_flags); rd_sz = sctp_recvmsg(s1mme, (void*) readbuf, sizeof(readbuf),(struct sockaddr*) &enb_addr, &fromlen, &sri, &msg_flags);
if (rd_sz == -1){ if (rd_sz == -1 && errno != EAGAIN){
cout<< "Error reading from SCTP socket"<<endl; cout<< "Error reading from SCTP socket"<<endl;
printf("Error: %s\n", strerror(errno));
return -1;
} }
cout << "Received SCTP msg." << endl; else if (rd_sz == -1 && errno == EAGAIN){
cout << "Timeout reached" << endl;
}
else{
cout<< "Received SCTP msg." << endl;
cout << "\tSize: " << rd_sz <<endl; cout << "\tSize: " << rd_sz <<endl;
cout << "\tMsg: " << readbuf << endl; cout << "\tMsg: " << readbuf << endl;
} }
}
mme->stop();
mme->cleanup();
cout << "--- exiting ---" << endl;
return 0; return 0;
} }

@ -73,6 +73,13 @@ mme::init(all_args_t* args)
return 0; return 0;
} }
void
mme::stop()
{
m_s1ap.stop();
return;
}
int int
mme::get_s1_mme() mme::get_s1_mme()
{ {

@ -31,11 +31,13 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/sctp.h> #include <netinet/sctp.h>
#include <unistd.h>
#include "mme/s1ap.h" #include "mme/s1ap.h"
namespace srsepc{ namespace srsepc{
s1ap::s1ap() s1ap::s1ap():
m_s1mme(-1)
{ {
} }
@ -58,12 +60,28 @@ s1ap::init(s1ap_args_t s1ap_args)
return 0; return 0;
} }
void
s1ap::stop()
{
if (m_s1mme != -1){
close(m_s1mme);
}
return;
}
int
s1ap::get_s1_mme()
{
return m_s1mme;
}
int int
s1ap::enb_listen() s1ap::enb_listen()
{ {
/*This function sets up the SCTP socket for eNBs to connect to*/ /*This function sets up the SCTP socket for eNBs to connect to*/
int sock_fd, err; int sock_fd, err;
struct sockaddr_in s1mme_addr;//TODO make this a configurable class memeber. 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); sock_fd = socket (AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);
if (sock_fd == -1){ if (sock_fd == -1){
@ -71,6 +89,22 @@ s1ap::enb_listen()
return -1; 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 //S1-MME bind
bzero(&s1mme_addr, sizeof(s1mme_addr)); bzero(&s1mme_addr, sizeof(s1mme_addr));
s1mme_addr.sin_family = AF_INET; s1mme_addr.sin_family = AF_INET;
@ -79,21 +113,18 @@ s1ap::enb_listen()
err = bind(sock_fd, (struct sockaddr*) &s1mme_addr, sizeof (s1mme_addr)); err = bind(sock_fd, (struct sockaddr*) &s1mme_addr, sizeof (s1mme_addr));
if (err != 0){ if (err != 0){
std::cout << "Error binding SCTP socket" << std::endl; std::cout << "Error binding SCTP socket" << std::endl;
return -1;
} }
//Listen for connections //Listen for connections
err = listen(sock_fd,SOMAXCONN); err = listen(sock_fd,SOMAXCONN);
if (err != 0){ if (err != 0){
std::cout << "Error in SCTP socket listen" << std::endl; std::cout << "Error in SCTP socket listen" << std::endl;
return -1;
} }
return sock_fd; return sock_fd;
} }
int
s1ap::get_s1_mme()
{
return m_s1mme;
}
}//namespace srsepc }//namespace srsepc

Loading…
Cancel
Save