Finished separating the pack/unpack from the main S1AP class.

master
Pedro Alvarez 7 years ago
parent f73d295ae0
commit 0dbddb8a4b

@ -37,22 +37,13 @@
#include <netinet/sctp.h> #include <netinet/sctp.h>
#include <unistd.h> #include <unistd.h>
#include "mme/s1ap_common.h"
#include "mme/s1ap_mngmt_proc.h" #include "mme/s1ap_mngmt_proc.h"
namespace srsepc{ namespace srsepc{
const uint16_t S1MME_PORT = 36412; const uint16_t S1MME_PORT = 36412;
typedef struct{
uint8_t mme_code;
uint16_t mme_group;
uint16_t tac; // 16-bit tac
uint16_t mcc; // BCD-coded with 0xF filler
uint16_t mnc; // BCD-coded with 0xF filler
std::string mme_bind_addr;
std::string mme_name;
} s1ap_args_t;
class s1ap class s1ap
{ {
public: public:
@ -74,7 +65,13 @@ public:
bool send_s1_setup_response(struct sctp_sndrcvinfo *enb_sri); bool send_s1_setup_response(struct sctp_sndrcvinfo *enb_sri);
void print_enb_ctx_info(const enb_ctx_t &enb_ctx);
private: private:
s1ap_args_t m_s1ap_args;
uint32_t m_plmn;
/*
uint8_t m_mme_code; uint8_t m_mme_code;
uint16_t m_mme_group; uint16_t m_mme_group;
uint16_t m_tac; // 16-bit tac uint16_t m_tac; // 16-bit tac
@ -84,7 +81,7 @@ private:
std::string m_mme_bind_addr; std::string m_mme_bind_addr;
std::string m_mme_name; std::string m_mme_name;
*/
srslte::log *m_s1ap_log; srslte::log *m_s1ap_log;
int m_s1mme; int m_s1mme;

@ -28,24 +28,9 @@
#include "srslte/asn1/liblte_s1ap.h" #include "srslte/asn1/liblte_s1ap.h"
#include "srslte/common/common.h" #include "srslte/common/common.h"
namespace srsepc{ #include "mme/s1ap_common.h"
static const uint8_t MAX_TA=255;
static const uint8_t MAX_BPLMN=6;
typedef struct{ namespace srsepc{
bool enb_name_present;
uint32_t enb_id;
uint8_t enb_name[150];
uint16_t mcc, mnc;
uint32_t plmn;
uint8_t nof_supported_ta;
uint16_t tac[MAX_TA];
uint8_t nof_supported_bplmns[MAX_TA];
uint16_t bplmns[MAX_TA][MAX_BPLMN];
LIBLTE_S1AP_PAGINGDRX_ENUM drx;
struct sctp_sndrcvinfo sri;
} enb_ctx_t;
class s1ap_mngmt_proc class s1ap_mngmt_proc
{ {
@ -55,7 +40,7 @@ public:
bool unpack_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRUCT *msg, enb_ctx_t* enb_ctx); bool unpack_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRUCT *msg, enb_ctx_t* enb_ctx);
bool pack_s1_setup_failure(LIBLTE_S1AP_CAUSEMISC_ENUM cause, srslte::byte_buffer_t* msg); bool pack_s1_setup_failure(LIBLTE_S1AP_CAUSEMISC_ENUM cause, srslte::byte_buffer_t* msg);
bool pack_s1_setup_response(LIBLTE_S1AP_S1AP_PDU_STRUCT *pdu); bool pack_s1_setup_response(s1ap_args_t s1ap_args, srslte::byte_buffer_t* msg);
}; };
} //namespace srsepc } //namespace srsepc

@ -43,6 +43,7 @@ s1ap::~s1ap()
int int
s1ap::init(s1ap_args_t s1ap_args, srslte::log *s1ap_log) s1ap::init(s1ap_args_t s1ap_args, srslte::log *s1ap_log)
{ {
/*
m_mme_code = s1ap_args.mme_code ; m_mme_code = s1ap_args.mme_code ;
m_mme_group = s1ap_args.mme_group; m_mme_group = s1ap_args.mme_group;
m_tac = s1ap_args.tac; m_tac = s1ap_args.tac;
@ -50,8 +51,10 @@ s1ap::init(s1ap_args_t s1ap_args, srslte::log *s1ap_log)
m_mnc = s1ap_args.mnc; m_mnc = s1ap_args.mnc;
m_mme_bind_addr = s1ap_args.mme_bind_addr; m_mme_bind_addr = s1ap_args.mme_bind_addr;
m_mme_name = std::string("srsmme0"); m_mme_name = std::string("srsmme0");
*/
m_s1ap_args = s1ap_args;
srslte::s1ap_mccmnc_to_plmn(m_mcc, m_mnc, &m_plmn); srslte::s1ap_mccmnc_to_plmn(s1ap_args.mcc, s1ap_args.mnc, &m_plmn);
m_s1ap_log = s1ap_log; m_s1ap_log = s1ap_log;
@ -101,7 +104,7 @@ s1ap::enb_listen()
//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;
inet_pton(AF_INET, m_mme_bind_addr.c_str(), &(s1mme_addr.sin_addr) ); inet_pton(AF_INET, m_s1ap_args.mme_bind_addr.c_str(), &(s1mme_addr.sin_addr) );
s1mme_addr.sin_port = htons(S1MME_PORT); s1mme_addr.sin_port = htons(S1MME_PORT);
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){
@ -182,120 +185,61 @@ s1ap::handle_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRUCT *msg, st
} }
//Log S1 Setup Request Info //Log S1 Setup Request Info
if(enb_ctx.enb_name_present) print_enb_ctx_info(enb_ctx);
{
m_s1ap_log->console("S1 Setup Request - eNB Name: %s, eNB id: 0x%x\n", enb_ctx.enb_name, enb_ctx.enb_id);
m_s1ap_log->info("S1 Setup Request - eNB Name: %s, eNB id: 0x%x\n", enb_ctx.enb_name, enb_ctx.enb_id);
}
else
{
m_s1ap_log->console("S1 Setup Request - eNB Id 0x%x\n", enb_ctx.enb_id);
m_s1ap_log->info("S1 Setup request - eNB Id 0x%x\n", enb_ctx.enb_id);
}
srslte::mcc_to_string(enb_ctx.mcc, &mcc_str);
srslte::mnc_to_string(enb_ctx.mnc, &mnc_str);
m_s1ap_log->info("S1 Setup Request - MCC:%s, MNC:%s, PLMN: %d\n", mcc_str.c_str(), mnc_str.c_str(), enb_ctx.plmn);
m_s1ap_log->console("S1 Setup Request - MCC:%s, MNC:%s, PLMN: %d\n", mcc_str.c_str(), mnc_str.c_str(), enb_ctx.plmn);
for(int i=0;i<enb_ctx.nof_supported_ta;i++)
{
for(int j=0;i<enb_ctx.nof_supported_ta;i++)
{
m_s1ap_log->info("S1 Setup Request - TAC %d, B-PLMN %d\n",enb_ctx.tac[i],enb_ctx.bplmns[i][j]);
m_s1ap_log->console("S1 Setup Request - TAC %d, B-PLMN %d\n",enb_ctx.tac[i],enb_ctx.bplmns[i][j]);
}
}
m_s1ap_log->console("S1 Setup Request - Paging DRX %d\n",enb_ctx.drx);
//Check matching PLMNs //Check matching PLMNs
if(enb_ctx.plmn!=m_plmn){ if(enb_ctx.plmn!=m_plmn){
m_s1ap_log->console("S1 Setup Failure - Unkown PLMN\n"); m_s1ap_log->console("S1 Setup Failure - Unkown PLMN\n");
m_s1ap_log->info("S1 Setup Failure - Unkown PLMN\n"); m_s1ap_log->info("S1 Setup Failure - Unkown PLMN\n");
m_s1ap_mngmt_proc.pack_s1_setup_failure(LIBLTE_S1AP_CAUSEMISC_UNKNOWN_PLMN,&reply_msg); m_s1ap_mngmt_proc.pack_s1_setup_failure(LIBLTE_S1AP_CAUSEMISC_UNKNOWN_PLMN,&reply_msg);
ssize_t n_sent = sctp_send(m_s1mme,reply_msg.msg, reply_msg.N_bytes, enb_sri, 0); //FIXME
} }
else{ else{
m_s1ap_log->console("S1 Setup Response\n"); m_s1ap_log->console("S1 Setup Response\n");
m_s1ap_log->info("S1 Setup Response\n"); m_s1ap_log->info("S1 Setup Response\n");
//m_s1ap_mngmt_proc.pack_s1_setup_response(,&reply_msg); m_s1ap_mngmt_proc.pack_s1_setup_response(m_s1ap_args, &reply_msg);
send_s1_setup_response(enb_sri);
} }
//Send Reply to eNB //Send Reply to eNB
/* ssize_t n_sent = sctp_send(m_s1mme,reply_msg.msg, reply_msg.N_bytes, enb_sri, 0);
ssize_t n_sent = sctp_send(m_s1mme,msg.msg, msg.N_bytes, enb_sri, 0);
if(n_sent == -1) if(n_sent == -1)
{ {
m_s1ap_log->console("Failed to send S1 Setup Setup Reply"); m_s1ap_log->console("Failed to send S1 Setup Setup Reply");
return false; return false;
} }
*/
return true; return true;
} }
bool void
s1ap::send_s1_setup_response(struct sctp_sndrcvinfo *enb_sri) s1ap::print_enb_ctx_info(const enb_ctx_t &enb_ctx)
{ {
srslte::byte_buffer_t msg; std::string mnc_str, mcc_str;
LIBLTE_S1AP_S1AP_PDU_STRUCT pdu;
bzero(&pdu, sizeof(LIBLTE_S1AP_S1AP_PDU_STRUCT));
pdu.choice_type = LIBLTE_S1AP_S1AP_PDU_CHOICE_SUCCESSFULOUTCOME;
LIBLTE_S1AP_SUCCESSFULOUTCOME_STRUCT *succ = &pdu.choice.successfulOutcome;
succ->procedureCode = LIBLTE_S1AP_PROC_ID_S1SETUP;
succ->criticality = LIBLTE_S1AP_CRITICALITY_IGNORE;
succ->choice_type = LIBLTE_S1AP_SUCCESSFULOUTCOME_CHOICE_S1SETUPRESPONSE;
LIBLTE_S1AP_MESSAGE_S1SETUPRESPONSE_STRUCT* s1_resp=(LIBLTE_S1AP_MESSAGE_S1SETUPRESPONSE_STRUCT*)&succ->choice;
s1_resp->ext=false;
//MME Name
s1_resp->MMEname_present=true;
s1_resp->MMEname.ext=false;
s1_resp->MMEname.n_octets=m_mme_name.length();
memcpy(s1_resp->MMEname.buffer,m_mme_name.c_str(),m_mme_name.length());
//Served GUMEIs
s1_resp->ServedGUMMEIs.len=1;//TODO Only one served GUMMEI supported
LIBLTE_S1AP_SERVEDGUMMEISITEM_STRUCT *serv_gummei = &s1_resp->ServedGUMMEIs.buffer[0];
serv_gummei->ext=false;
//serv_gummei->iE_Extensions=false;
uint32_t plmn=0;
srslte::s1ap_mccmnc_to_plmn(m_mcc, m_mnc, &plmn);
plmn=htonl(plmn);
serv_gummei->servedPLMNs.len = 1; //Only one PLMN supported
serv_gummei->servedPLMNs.buffer[0].buffer[0]=((uint8_t*)&plmn)[1];
serv_gummei->servedPLMNs.buffer[0].buffer[1]=((uint8_t*)&plmn)[2];
serv_gummei->servedPLMNs.buffer[0].buffer[2]=((uint8_t*)&plmn)[3];
serv_gummei->servedGroupIDs.len=1; //LIBLTE_S1AP_SERVEDGROUPIDS_STRUCT
uint16_t tmp=htons(m_mme_group);
serv_gummei->servedGroupIDs.buffer[0].buffer[0]=((uint8_t*)&tmp)[0];
serv_gummei->servedGroupIDs.buffer[0].buffer[1]=((uint8_t*)&tmp)[1];
serv_gummei->servedMMECs.len=1; //Only one MMEC served
serv_gummei->servedMMECs.buffer[0].buffer[0]=m_mme_code;
//Relative MME Capacity
s1_resp->RelativeMMECapacity.RelativeMMECapacity=255;
//Relay Unsupported
s1_resp->MMERelaySupportIndicator_present=false;
liblte_s1ap_pack_s1ap_pdu(&pdu, (LIBLTE_BYTE_MSG_STRUCT*)&msg);
ssize_t n_sent = sctp_send(m_s1mme,msg.msg, msg.N_bytes, enb_sri, 0);
if(n_sent == -1) if(enb_ctx.enb_name_present)
{ {
m_s1ap_log->console("Failed to send S1 Setup Failure"); m_s1ap_log->console("S1 Setup Request - eNB Name: %s, eNB id: 0x%x\n", enb_ctx.enb_name, enb_ctx.enb_id);
return false; m_s1ap_log->info("S1 Setup Request - eNB Name: %s, eNB id: 0x%x\n", enb_ctx.enb_name, enb_ctx.enb_id);
} }
return true; else
{
m_s1ap_log->console("S1 Setup Request - eNB Id 0x%x\n", enb_ctx.enb_id);
m_s1ap_log->info("S1 Setup request - eNB Id 0x%x\n", enb_ctx.enb_id);
}
srslte::mcc_to_string(enb_ctx.mcc, &mcc_str);
srslte::mnc_to_string(enb_ctx.mnc, &mnc_str);
m_s1ap_log->info("S1 Setup Request - MCC:%s, MNC:%s, PLMN: %d\n", mcc_str.c_str(), mnc_str.c_str(), enb_ctx.plmn);
m_s1ap_log->console("S1 Setup Request - MCC:%s, MNC:%s, PLMN: %d\n", mcc_str.c_str(), mnc_str.c_str(), enb_ctx.plmn);
for(int i=0;i<enb_ctx.nof_supported_ta;i++)
{
for(int j=0;i<enb_ctx.nof_supported_ta;i++)
{
m_s1ap_log->info("S1 Setup Request - TAC %d, B-PLMN %d\n",enb_ctx.tac[i],enb_ctx.bplmns[i][j]);
m_s1ap_log->console("S1 Setup Request - TAC %d, B-PLMN %d\n",enb_ctx.tac[i],enb_ctx.bplmns[i][j]);
}
}
m_s1ap_log->console("S1 Setup Request - Paging DRX %d\n",enb_ctx.drx);
return;
} }
} //namespace srsepc } //namespace srsepc

@ -123,16 +123,15 @@ s1ap_mngmt_proc::pack_s1_setup_failure(LIBLTE_S1AP_CAUSEMISC_ENUM cause, srslte:
bool bool
s1ap_mngmt_proc::pack_s1_setup_response(LIBLTE_S1AP_S1AP_PDU_STRUCT *pdu) s1ap_mngmt_proc::pack_s1_setup_response(s1ap_args_t s1ap_args, srslte::byte_buffer_t *msg)
{ {
/*
srslte::byte_buffer_t msg;
//LIBLTE_S1AP_S1AP_PDU_STRUCT pdu;
bzero(pdu, sizeof(LIBLTE_S1AP_S1AP_PDU_STRUCT));
pdu->choice_type = LIBLTE_S1AP_S1AP_PDU_CHOICE_SUCCESSFULOUTCOME; LIBLTE_S1AP_S1AP_PDU_STRUCT pdu;
bzero(&pdu, sizeof(LIBLTE_S1AP_S1AP_PDU_STRUCT));
pdu.choice_type = LIBLTE_S1AP_S1AP_PDU_CHOICE_SUCCESSFULOUTCOME;
LIBLTE_S1AP_SUCCESSFULOUTCOME_STRUCT *succ = &pdu->choice.successfulOutcome; LIBLTE_S1AP_SUCCESSFULOUTCOME_STRUCT *succ = &pdu.choice.successfulOutcome;
succ->procedureCode = LIBLTE_S1AP_PROC_ID_S1SETUP; succ->procedureCode = LIBLTE_S1AP_PROC_ID_S1SETUP;
succ->criticality = LIBLTE_S1AP_CRITICALITY_IGNORE; succ->criticality = LIBLTE_S1AP_CRITICALITY_IGNORE;
succ->choice_type = LIBLTE_S1AP_SUCCESSFULOUTCOME_CHOICE_S1SETUPRESPONSE; succ->choice_type = LIBLTE_S1AP_SUCCESSFULOUTCOME_CHOICE_S1SETUPRESPONSE;
@ -144,8 +143,8 @@ s1ap_mngmt_proc::pack_s1_setup_response(LIBLTE_S1AP_S1AP_PDU_STRUCT *pdu)
//MME Name //MME Name
s1_resp->MMEname_present=true; s1_resp->MMEname_present=true;
s1_resp->MMEname.ext=false; s1_resp->MMEname.ext=false;
s1_resp->MMEname.n_octets=m_mme_name.length(); s1_resp->MMEname.n_octets=s1ap_args.mme_name.length();
memcpy(s1_resp->MMEname.buffer,m_mme_name.c_str(),m_mme_name.length()); memcpy(s1_resp->MMEname.buffer,s1ap_args.mme_name.c_str(),s1ap_args.mme_name.length());
//Served GUMEIs //Served GUMEIs
s1_resp->ServedGUMMEIs.len=1;//TODO Only one served GUMMEI supported s1_resp->ServedGUMMEIs.len=1;//TODO Only one served GUMMEI supported
@ -155,7 +154,7 @@ s1ap_mngmt_proc::pack_s1_setup_response(LIBLTE_S1AP_S1AP_PDU_STRUCT *pdu)
//serv_gummei->iE_Extensions=false; //serv_gummei->iE_Extensions=false;
uint32_t plmn=0; uint32_t plmn=0;
srslte::s1ap_mccmnc_to_plmn(m_mcc, m_mnc, &plmn); srslte::s1ap_mccmnc_to_plmn(s1ap_args.mcc, s1ap_args.mnc, &plmn);
plmn=htonl(plmn); plmn=htonl(plmn);
serv_gummei->servedPLMNs.len = 1; //Only one PLMN supported serv_gummei->servedPLMNs.len = 1; //Only one PLMN supported
serv_gummei->servedPLMNs.buffer[0].buffer[0]=((uint8_t*)&plmn)[1]; serv_gummei->servedPLMNs.buffer[0].buffer[0]=((uint8_t*)&plmn)[1];
@ -163,12 +162,12 @@ s1ap_mngmt_proc::pack_s1_setup_response(LIBLTE_S1AP_S1AP_PDU_STRUCT *pdu)
serv_gummei->servedPLMNs.buffer[0].buffer[2]=((uint8_t*)&plmn)[3]; serv_gummei->servedPLMNs.buffer[0].buffer[2]=((uint8_t*)&plmn)[3];
serv_gummei->servedGroupIDs.len=1; //LIBLTE_S1AP_SERVEDGROUPIDS_STRUCT serv_gummei->servedGroupIDs.len=1; //LIBLTE_S1AP_SERVEDGROUPIDS_STRUCT
uint16_t tmp=htons(m_mme_group); uint16_t tmp=htons(s1ap_args.mme_group);
serv_gummei->servedGroupIDs.buffer[0].buffer[0]=((uint8_t*)&tmp)[0]; serv_gummei->servedGroupIDs.buffer[0].buffer[0]=((uint8_t*)&tmp)[0];
serv_gummei->servedGroupIDs.buffer[0].buffer[1]=((uint8_t*)&tmp)[1]; serv_gummei->servedGroupIDs.buffer[0].buffer[1]=((uint8_t*)&tmp)[1];
serv_gummei->servedMMECs.len=1; //Only one MMEC served serv_gummei->servedMMECs.len=1; //Only one MMEC served
serv_gummei->servedMMECs.buffer[0].buffer[0]=m_mme_code; serv_gummei->servedMMECs.buffer[0].buffer[0]=s1ap_args.mme_code;
//Relative MME Capacity //Relative MME Capacity
s1_resp->RelativeMMECapacity.RelativeMMECapacity=255; s1_resp->RelativeMMECapacity.RelativeMMECapacity=255;
@ -176,8 +175,8 @@ s1ap_mngmt_proc::pack_s1_setup_response(LIBLTE_S1AP_S1AP_PDU_STRUCT *pdu)
//Relay Unsupported //Relay Unsupported
s1_resp->MMERelaySupportIndicator_present=false; s1_resp->MMERelaySupportIndicator_present=false;
liblte_s1ap_pack_s1ap_pdu(pdu, (LIBLTE_BYTE_MSG_STRUCT*)&msg); liblte_s1ap_pack_s1ap_pdu(&pdu, (LIBLTE_BYTE_MSG_STRUCT*)msg);
*/
return true; return true;
} }

Loading…
Cancel
Save