A bit of code cleanup

master
Pedro Alvarez 7 years ago
parent 4f6fafb66d
commit d8436ea2fc

@ -23,10 +23,22 @@
* and at http://www.gnu.org/licenses/.
*
*/
#ifndef S1AP_H
#define S1AP_H
#include "srslte/asn1/liblte_s1ap.h"
#include "srslte/common/common.h"
#include "srslte/common/log.h"
#include <strings.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/sctp.h>
#include <unistd.h>
#include "mme/s1ap_mngmt_proc.h"
namespace srsepc{
const uint16_t S1MME_PORT = 36412;
@ -54,28 +66,34 @@ public:
bool handle_s1ap_rx_pdu(srslte::byte_buffer_t *pdu, struct sctp_sndrcvinfo *enb_sri);
bool handle_initiatingmessage(LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *msg, struct sctp_sndrcvinfo *enb_sri);
bool handle_initiating_message(LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *msg, struct sctp_sndrcvinfo *enb_sri);
bool handle_s1setuprequest(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRUCT *msg, struct sctp_sndrcvinfo *enb_sri);
bool handle_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRUCT *msg, struct sctp_sndrcvinfo *enb_sri);
bool send_s1setupfailure(struct sctp_sndrcvinfo *enb_sri);
bool send_s1_setup_failure(struct sctp_sndrcvinfo *enb_sri);
bool send_s1setupresponse(struct sctp_sndrcvinfo *enb_sri);
bool send_s1_setup_response(struct sctp_sndrcvinfo *enb_sri);
private:
uint8_t m_mme_code;
uint16_t m_mme_group;
uint16_t m_tac; // 16-bit tac
uint16_t m_mcc; // BCD-coded with 0xF filler
uint16_t m_mnc; // BCD-coded with 0xF filler
uint32_t m_plmn;
std::string m_mme_bind_addr;
std::string m_mme_name;
srslte::log *m_s1ap_log;
int m_s1mme;
s1ap_mngmt_proc m_s1ap_mngmt_proc;
};
} //namespace srsepc
#endif //S1AP_H

@ -77,7 +77,7 @@ mme::init(all_args_t* args)
m_logger = &m_logger_stdout;
} else {
m_logger_file.init(args->log_args.filename);
m_logger_file.log("\n\n");
m_logger_file.log("\n--- Software Radio Systems MME log ---\n\n");
m_logger = &m_logger_file;
}
@ -85,10 +85,11 @@ mme::init(all_args_t* args)
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)){
std::cout << "Error initializing MME S1APP" << std::endl;
m_s1ap_log.error("Error initializing MME S1APP\n");
exit(-1);
}
m_s1ap_log.console("Initialized MME\n");
m_s1ap_log.info("Initialized S1-MME\n");
m_s1ap_log.console("Initialized S1-MME\n");
return 0;
}
@ -131,23 +132,22 @@ mme::run_thread()
int s1mme = m_s1ap.get_s1_mme();
while(m_running)
{
//std::cout << "Waiting for SCTP Msg " << std::endl;
m_s1ap_log.debug("Waiting for SCTP Msg");
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));
}
else if (rd_sz == -1 && errno == EAGAIN){
m_s1ap_log("Socket timeout reached");
m_s1ap_log.debug("Socket timeout reached");
}
else{
pdu->N_bytes = rd_sz;
m_s1ap_log("Received S1AP msg. Size: %d", pdu->N_bytes);
m_s1ap_log.info("Received S1AP msg. Size: %d\n", pdu->N_bytes);
m_s1ap.handle_s1ap_rx_pdu(pdu,&sri);
}
}
return;
}
} //namespace srsepe<
} //namespace srsepc

@ -26,14 +26,6 @@
#include <iostream> //TODO Remove
#include <strings.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/sctp.h>
#include <unistd.h>
//#include "srslte/upper/s1ap_common.h"
#include "srslte/common/bcd_helpers.h"
#include "mme/s1ap.h"
@ -59,11 +51,12 @@ s1ap::init(s1ap_args_t s1ap_args, srslte::log *s1ap_log)
m_mme_bind_addr = s1ap_args.mme_bind_addr;
m_mme_name = std::string("srsmme0");
srslte::s1ap_mccmnc_to_plmn(m_mcc, m_mnc, &m_plmn);
m_s1ap_log = s1ap_log;
m_s1mme = enb_listen();
m_s1ap_log->console("Initialized S1-APP\n");
return 0;
}
@ -109,18 +102,19 @@ s1ap::enb_listen()
bzero(&s1mme_addr, sizeof(s1mme_addr));
s1mme_addr.sin_family = AF_INET;
inet_pton(AF_INET, m_mme_bind_addr.c_str(), &(s1mme_addr.sin_addr) );
//s1mme_addr.sin_addr.s_addr = htonl(INADDR_ANY); //TODO this should use the bindx information
s1mme_addr.sin_port = htons(S1MME_PORT);
err = bind(sock_fd, (struct sockaddr*) &s1mme_addr, sizeof (s1mme_addr));
if (err != 0){
std::cout << "Error binding SCTP socket" << std::endl;
m_s1ap_log->error("Error binding SCTP socket\n");
m_s1ap_log->console("Error binding SCTP socket\n");
return -1;
}
//Listen for connections
err = listen(sock_fd,SOMAXCONN);
if (err != 0){
std::cout << "Error in SCTP socket listen" << std::endl;
m_s1ap_log->error("Error in SCTP socket listen\n");
m_s1ap_log->console("Error in SCTP socket listen\n");
return -1;
}
@ -133,14 +127,14 @@ s1ap::handle_s1ap_rx_pdu(srslte::byte_buffer_t *pdu, struct sctp_sndrcvinfo *enb
LIBLTE_S1AP_S1AP_PDU_STRUCT rx_pdu;
if(liblte_s1ap_unpack_s1ap_pdu((LIBLTE_BYTE_MSG_STRUCT*)pdu, &rx_pdu) != LIBLTE_SUCCESS) {
m_s1ap_log->console("Failed to unpack received PDU\n");
m_s1ap_log->error("Failed to unpack received PDU\n");
return false;
}
switch(rx_pdu.choice_type) {
case LIBLTE_S1AP_S1AP_PDU_CHOICE_INITIATINGMESSAGE:
m_s1ap_log->console("Received initiating PDU\n");
return handle_initiatingmessage(&rx_pdu.choice.initiatingMessage, enb_sri);
return handle_initiating_message(&rx_pdu.choice.initiatingMessage, enb_sri);
break;
case LIBLTE_S1AP_S1AP_PDU_CHOICE_SUCCESSFULOUTCOME:
m_s1ap_log->console("Received Succeseful Outcome PDU\n");
@ -160,21 +154,20 @@ s1ap::handle_s1ap_rx_pdu(srslte::byte_buffer_t *pdu, struct sctp_sndrcvinfo *enb
}
bool
s1ap::handle_initiatingmessage(LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *msg, struct sctp_sndrcvinfo *enb_sri)
s1ap::handle_initiating_message(LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *msg, struct sctp_sndrcvinfo *enb_sri)
{
switch(msg->choice_type) {
case LIBLTE_S1AP_INITIATINGMESSAGE_CHOICE_S1SETUPREQUEST:
std::cout << "Received S1 Setup Request." << std::endl;
return handle_s1setuprequest(&msg->choice.S1SetupRequest, enb_sri);
m_s1ap_log->info("Received S1 Setup Request.\n");
return handle_s1_setup_request(&msg->choice.S1SetupRequest, enb_sri);
default:
std::cout << "Unhandled intiating message" << std::cout;
//s1ap_log->error("Unhandled intiating message: %s\n", liblte_s1ap_initiatingmessage_choice_text[msg->choice_type]);
m_s1ap_log->error("Unhandled intiating message: %s\n", liblte_s1ap_initiatingmessage_choice_text[msg->choice_type]);
}
return true;
}
bool
s1ap::handle_s1setuprequest(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRUCT *msg, struct sctp_sndrcvinfo *enb_sri)
s1ap::handle_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRUCT *msg, struct sctp_sndrcvinfo *enb_sri)
{
uint8_t enb_name[150];
@ -184,8 +177,21 @@ s1ap::handle_s1setuprequest(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRUCT *msg, stru
uint16_t mcc, mnc;
uint16_t tac, bplmn;
uint32_t bplmns[32];
enb_ctx_t enb_ctx;
if(!m_s1ap_mngmt_proc.unpack_s1_setup_request(msg, &enb_ctx)){
m_s1ap_log->error("Malformed S1 Setup Request\n");
return false;
}
if(enb_ctx.enb_name_present){
m_s1ap_log->console("S1 Setup request from eNB %s\n", enb_ctx.enb_name);
}
else{
m_s1ap_log->console("S1 Setup request from eNB id \n");
}
//eNB Name
/*
if(msg->eNBname_present)
{
bzero(enb_name,sizeof(enb_name));
@ -233,14 +239,22 @@ s1ap::handle_s1setuprequest(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRUCT *msg, stru
//Default Paging DRX
LIBLTE_S1AP_PAGINGDRX_ENUM drx = msg->DefaultPagingDRX.e;
std::cout << "Default Paging DRX" << drx << std::endl;
*/
/*
if(plmn!=m_plmn){
send_s1_setup_failure(enb_sri);
}
else{
send_s1_setup_response(enb_sri);
}
*/
//send_s1setupfailure(enb_sri);
send_s1setupresponse(enb_sri);
//send_s1setupresponse(enb_sri);
return true;
}
bool
s1ap::send_s1setupfailure(struct sctp_sndrcvinfo *enb_sri)
s1ap::send_s1_setup_failure(struct sctp_sndrcvinfo *enb_sri)
{
srslte::byte_buffer_t msg;
LIBLTE_S1AP_S1AP_PDU_STRUCT pdu;
@ -276,7 +290,7 @@ s1ap::send_s1setupfailure(struct sctp_sndrcvinfo *enb_sri)
bool
s1ap::send_s1setupresponse(struct sctp_sndrcvinfo *enb_sri)
s1ap::send_s1_setup_response(struct sctp_sndrcvinfo *enb_sri)
{
srslte::byte_buffer_t msg;
LIBLTE_S1AP_S1AP_PDU_STRUCT pdu;
@ -340,12 +354,4 @@ s1ap::send_s1setupresponse(struct sctp_sndrcvinfo *enb_sri)
return true;
}
/*
bool
s1ap::setup_enb_ctx()
{
return false;
}*/
} //namespace srsepc

Loading…
Cancel
Save