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);
void stop();
int get_s1_mme();
private:

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

@ -24,6 +24,8 @@
*
*/
#include <iostream>
#include <errno.h>
#include <signal.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
@ -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 <<endl;
cout << "Flags:" << msg_flags <<endl;
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;
printf("Error: %s\n", strerror(errno));
return -1;
}
else if (rd_sz == -1 && errno == EAGAIN){
cout << "Timeout reached" << endl;
}
else{
cout<< "Received SCTP msg." << endl;
cout << "\tSize: " << rd_sz <<endl;
cout << "\tMsg: " << readbuf << endl;
}
}
mme->stop();
mme->cleanup();
cout << "--- exiting ---" << endl;
return 0;
}

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

@ -31,11 +31,13 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/sctp.h>
#include <unistd.h>
#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

Loading…
Cancel
Save