Changed S1AP to singleton. Continuing to work on the intial context setup request. Added a TEID to MME_UE_S1AP_ID map.

master
Pedro Alvarez 7 years ago
parent 3c839c1c9b
commit fd6baaf15c

@ -72,6 +72,7 @@ const uint8_t GTPC_V2 = 2;
typedef union gtpc_msg_choice typedef union gtpc_msg_choice
{ {
struct gtpc_create_session_request create_session_request; struct gtpc_create_session_request create_session_request;
struct gtpc_create_session_response create_session_response;
} gtpc_msg_choice_t; } gtpc_msg_choice_t;
/**************************************************************************** /****************************************************************************

@ -76,7 +76,7 @@ private:
mme(); mme();
virtual ~mme(); virtual ~mme();
static mme *m_instance; static mme *m_instance;
s1ap m_s1ap; s1ap *m_s1ap;
bool m_running; bool m_running;
srslte::byte_buffer_pool *m_pool; srslte::byte_buffer_pool *m_pool;

@ -28,11 +28,14 @@
#include "srslte/common/buffer_pool.h" #include "srslte/common/buffer_pool.h"
#include <boost/thread/mutex.hpp> #include <boost/thread/mutex.hpp>
#include "spgw/spgw.h"
#include "srslte/asn1/gtpc.h" #include "srslte/asn1/gtpc.h"
namespace srsepc namespace srsepc
{ {
class spgw;
class s1ap;
class mme_gtpc class mme_gtpc
{ {
public: public:
@ -41,8 +44,10 @@ public:
static void cleanup(void); static void cleanup(void);
void init(); void init();
void send_create_session_request(uint64_t imsi, struct srslte::gtpc_create_session_response *cs_resp);
uint64_t get_new_ctrl_teid(); uint64_t get_new_ctrl_teid();
void send_create_session_request(uint64_t imsi, struct srslte::gtpc_pdu *cs_resp_pdu);
void handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu);
private: private:
@ -52,10 +57,13 @@ private:
srslte::byte_buffer_pool *m_pool; srslte::byte_buffer_pool *m_pool;
s1ap* m_s1ap;
spgw* m_spgw; spgw* m_spgw;
in_addr_t m_mme_gtpc_ip; in_addr_t m_mme_gtpc_ip;
uint64_t m_next_ctrl_teid; uint64_t m_next_ctrl_teid;
std::map<uint64_t,uint32_t> m_teid_to_mme_s1ap_id;
}; };
} }

@ -26,6 +26,7 @@
#ifndef S1AP_H #ifndef S1AP_H
#define S1AP_H #define S1AP_H
#include "srslte/asn1/gtpc.h"
#include "srslte/asn1/liblte_s1ap.h" #include "srslte/asn1/liblte_s1ap.h"
#include "srslte/asn1/liblte_mme.h" #include "srslte/asn1/liblte_mme.h"
#include "srslte/common/common.h" #include "srslte/common/common.h"
@ -54,6 +55,10 @@ class s1ap
public: public:
s1ap(); s1ap();
virtual ~s1ap(); virtual ~s1ap();
static s1ap* get_instance();
static void cleanup();
int enb_listen(); int enb_listen();
int init(s1ap_args_t s1ap_args, srslte::log_filter *s1ap_log); int init(s1ap_args_t s1ap_args, srslte::log_filter *s1ap_log);
void stop(); void stop();
@ -76,11 +81,14 @@ public:
bool handle_nas_authentication_response(srslte::byte_buffer_t *nas_buffer, srslte::byte_buffer_t *reply_buffer, ue_ctx_t *ue_ctx); bool handle_nas_authentication_response(srslte::byte_buffer_t *nas_buffer, srslte::byte_buffer_t *reply_buffer, ue_ctx_t *ue_ctx);
bool handle_nas_security_mode_complete(srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_msg, ue_ctx_t *ue_ctx); bool handle_nas_security_mode_complete(srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_msg, ue_ctx_t *ue_ctx);
bool send_initial_context_setup_request(struct srslte::gtpc_create_session_response *cs_resp);
void print_enb_ctx_info(const enb_ctx_t &enb_ctx); void print_enb_ctx_info(const enb_ctx_t &enb_ctx);
private: private:
static s1ap *m_instance;
s1ap_args_t m_s1ap_args; s1ap_args_t m_s1ap_args;
uint32_t m_plmn; uint32_t m_plmn;
srslte::byte_buffer_pool *m_pool; srslte::byte_buffer_pool *m_pool;

@ -43,6 +43,8 @@
namespace srsepc{ namespace srsepc{
class mme_gtpc;
const uint16_t GTPU_RX_PORT = 2152; const uint16_t GTPU_RX_PORT = 2152;
typedef struct { typedef struct {
@ -70,7 +72,7 @@ public:
void stop(); void stop();
void run_thread(); void run_thread();
void handle_create_session_request(struct srslte::gtpc_create_session_request *cs_req, struct srslte::gtpc_create_session_response *cs_resp); void handle_create_session_request(struct srslte::gtpc_create_session_request *cs_req, struct srslte::gtpc_pdu *cs_resp_pdu);
private: private:
@ -86,6 +88,8 @@ private:
bool m_running; bool m_running;
srslte::byte_buffer_pool *m_pool; srslte::byte_buffer_pool *m_pool;
mme_gtpc *m_mme_gtpc;
bool m_sgi_up; bool m_sgi_up;
int m_sgi_if; int m_sgi_if;
@ -96,6 +100,7 @@ private:
uint64_t m_next_ctrl_teid; uint64_t m_next_ctrl_teid;
uint64_t m_next_user_teid; uint64_t m_next_user_teid;
/*Logs*/ /*Logs*/
srslte::log_filter *m_spgw_log; srslte::log_filter *m_spgw_log;

@ -72,9 +72,10 @@ mme::cleanup(void)
int int
mme::init(mme_args_t* args, srslte::log_filter *s1ap_log) mme::init(mme_args_t* args, srslte::log_filter *s1ap_log)
{ {
/*Init S1AP*/ /*Init S1AP*/
if(m_s1ap.init(args->s1ap_args, s1ap_log)){ m_s1ap = s1ap::get_instance();
if(m_s1ap->init(args->s1ap_args, s1ap_log)){
m_s1ap_log->error("Error initializing MME S1APP\n"); m_s1ap_log->error("Error initializing MME S1APP\n");
exit(-1); exit(-1);
} }
@ -91,7 +92,8 @@ mme::stop()
{ {
if(m_running) if(m_running)
{ {
m_s1ap.stop(); m_s1ap->stop();
m_s1ap->cleanup();
m_running = false; m_running = false;
thread_cancel(); thread_cancel();
wait_thread_finish(); wait_thread_finish();
@ -116,7 +118,7 @@ mme::run_thread()
m_running=true; m_running=true;
//Get S1-MME socket //Get S1-MME socket
int s1mme = m_s1ap.get_s1_mme(); int s1mme = m_s1ap->get_s1_mme();
while(m_running) while(m_running)
{ {
m_s1ap_log->debug("Waiting for SCTP Msg\n"); m_s1ap_log->debug("Waiting for SCTP Msg\n");
@ -138,7 +140,7 @@ mme::run_thread()
{ {
m_s1ap_log->info("SCTP Association Shutdown. Association: %d\n",sri.sinfo_assoc_id); m_s1ap_log->info("SCTP Association Shutdown. Association: %d\n",sri.sinfo_assoc_id);
m_s1ap_log->console("SCTP Association Shutdown. Association: %d\n",sri.sinfo_assoc_id); m_s1ap_log->console("SCTP Association Shutdown. Association: %d\n",sri.sinfo_assoc_id);
m_s1ap.delete_enb_ctx(sri.sinfo_assoc_id); m_s1ap->delete_enb_ctx(sri.sinfo_assoc_id);
} }
} }
else else
@ -146,7 +148,7 @@ mme::run_thread()
//Received data //Received data
pdu->N_bytes = rd_sz; pdu->N_bytes = rd_sz;
m_s1ap_log->info("Received S1AP msg. Size: %d\n", pdu->N_bytes); m_s1ap_log->info("Received S1AP msg. Size: %d\n", pdu->N_bytes);
m_s1ap.handle_s1ap_rx_pdu(pdu,&sri); m_s1ap->handle_s1ap_rx_pdu(pdu,&sri);
} }
} }
} }

@ -27,6 +27,8 @@
#include <iostream> #include <iostream>
#include "srslte/asn1/gtpc.h" #include "srslte/asn1/gtpc.h"
#include "mme/mme_gtpc.h" #include "mme/mme_gtpc.h"
#include "mme/s1ap.h"
#include "spgw/spgw.h"
namespace srsepc{ namespace srsepc{
@ -66,6 +68,7 @@ mme_gtpc::cleanup(void)
void void
mme_gtpc::init() mme_gtpc::init()
{ {
m_s1ap = s1ap::get_instance();
m_mme_gtpc_ip = inet_addr("127.0.0.1");//FIXME At the moment, the GTP-C messages are not sent over the wire. So this parameter is not used. m_mme_gtpc_ip = inet_addr("127.0.0.1");//FIXME At the moment, the GTP-C messages are not sent over the wire. So this parameter is not used.
m_spgw = spgw::get_instance(); m_spgw = spgw::get_instance();
} }
@ -76,7 +79,7 @@ mme_gtpc::get_new_ctrl_teid()
return m_next_ctrl_teid++; //FIXME Use a Id pool? return m_next_ctrl_teid++; //FIXME Use a Id pool?
} }
void void
mme_gtpc::send_create_session_request(uint64_t imsi, struct srslte::gtpc_create_session_response *cs_resp) mme_gtpc::send_create_session_request(uint64_t imsi, struct srslte::gtpc_pdu *cs_resp_pdu)
{ {
struct srslte::gtpc_pdu cs_req_pdu; struct srslte::gtpc_pdu cs_req_pdu;
struct srslte::gtpc_create_session_request *cs_req = &cs_req_pdu.choice.create_session_request; struct srslte::gtpc_create_session_request *cs_req = &cs_req_pdu.choice.create_session_request;
@ -102,7 +105,18 @@ mme_gtpc::send_create_session_request(uint64_t imsi, struct srslte::gtpc_create_
//Save RX Control TEID //Save RX Control TEID
//create_rx_control_teid(cs_req->sender_f_teid); //create_rx_control_teid(cs_req->sender_f_teid);
m_spgw->handle_create_session_request(cs_req, cs_resp); m_spgw->handle_create_session_request(cs_req, cs_resp_pdu);
return; return;
} }
void
mme_gtpc::handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu)
{
//Get MME_UE_S1AP_ID from the Ctrl TEID
std::map<uint64_t,uint32_t>::iterator id_it = m_teid_to_mme_s1ap_id.find(cs_resp_pdu->header.teid);
uint32_t mme_s1ap_id = id_it->second;
m_s1ap->send_intial_context_setup_request(mme_s1ap_id, &cs_resp_pdu->choice.create_session_request);
}
} //namespace srsepc } //namespace srsepc

@ -32,6 +32,9 @@
namespace srsepc{ namespace srsepc{
s1ap* s1ap::m_instance = NULL;
boost::mutex s1ap_instance_mutex;
s1ap::s1ap(): s1ap::s1ap():
m_s1mme(-1), m_s1mme(-1),
m_next_mme_ue_s1ap_id(1) m_next_mme_ue_s1ap_id(1)
@ -42,6 +45,27 @@ s1ap::~s1ap()
{ {
} }
s1ap*
s1ap::get_instance(void)
{
boost::mutex::scoped_lock lock(s1ap_instance_mutex);
if(NULL == m_instance) {
m_instance = new mme();
}
return(m_instance);
}
void
s1ap::cleanup(void)
{
boost::mutex::scoped_lock lock(s1ap_instance_mutex);
if(NULL != m_instance) {
delete m_instance;
m_instance = NULL;
}
}
int int
s1ap::init(s1ap_args_t s1ap_args, srslte::log_filter *s1ap_log) s1ap::init(s1ap_args_t s1ap_args, srslte::log_filter *s1ap_log)
{ {
@ -514,26 +538,29 @@ s1ap::handle_nas_security_mode_complete(srslte::byte_buffer_t *nas_msg, srslte::
//FIXME The packging of GTP-C messages is not ready. //FIXME The packging of GTP-C messages is not ready.
//This means that GTP-U tunnels are created with function calls, as opposed to GTP-C. //This means that GTP-U tunnels are created with function calls, as opposed to GTP-C.
struct srslte::gtpc_create_session_response cs_resp; struct srslte::gtpc_pdu cs_resp_pdu;
m_mme_gtpc->send_create_session_request(ue_ctx->imsi, &cs_resp); struct srslte::gtpc_create_session_response *cs_resp = & cs_resp_pdu.choice.create_session_response;
if (cs_resp.cause.cause_value != srslte::GTPC_CAUSE_VALUE_REQUEST_ACCEPTED){
m_mme_gtpc->send_create_session_request(ue_ctx->imsi, &cs_resp_pdu);
if (cs_resp->cause.cause_value != srslte::GTPC_CAUSE_VALUE_REQUEST_ACCEPTED){
m_s1ap_log->warning("Could not create GTPC session.\n"); m_s1ap_log->warning("Could not create GTPC session.\n");
//TODO Handle error //TODO Handle error
} }
else{ else{
send_initial_context_setup_request(&cs_resp); send_initial_context_setup_request(cs_resp);
} }
return true; return true;
} }
bool bool
s1ap::send_initial_context_setup_request(struct srslte::create_session_response *cs_resp) s1ap::send_initial_context_setup_request(struct srslte::gtpc_create_session_response *cs_resp)
{ {
LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPREQUEST_STRUCT in_ctxt_req; LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPREQUEST_STRUCT in_ctxt_req;
uint64_t imsi = m_mme_gtpc->ctrl_teid_to_imsi();
bzero(&in_ctxt_req, sizeof(in_ctxt_req)); bzero(&in_ctxt_req, sizeof(in_ctxt_req));
in_ctxt_req.MME_UE_S1AP_ID =; in_ctxt_req.MME_UE_S1AP_ID = ;
in_ctxt_req.eNB_UE_S1AP_ID =; in_ctxt_req.eNB_UE_S1AP_ID =;
in_ctxt_req.uEaggregateMaximumBitrate =; in_ctxt_req.uEaggregateMaximumBitrate =;

@ -34,6 +34,7 @@
#include <linux/if.h> #include <linux/if.h>
#include <linux/if_tun.h> #include <linux/if_tun.h>
#include "spgw/spgw.h" #include "spgw/spgw.h"
#include "mme/mme_gtpc.h"
namespace srsepc{ namespace srsepc{
@ -86,6 +87,7 @@ spgw::init(spgw_args_t* args, srslte::log_filter *spgw_log)
//Init log //Init log
m_spgw_log = spgw_log; m_spgw_log = spgw_log;
m_mme_gtpc = mme_gtpc::get_instance();
//Init SGi interface //Init SGi interface
err = init_sgi_if(args); err = init_sgi_if(args);
@ -306,8 +308,18 @@ spgw::get_new_ue_ipv4()
} }
void void
spgw::handle_create_session_request(struct srslte::gtpc_create_session_request *cs_req, struct srslte::gtpc_create_session_response *cs_resp) spgw::handle_create_session_request(struct srslte::gtpc_create_session_request *cs_req, struct srslte::gtpc_pdu *cs_resp_pdu)
{ {
srslte::gtpc_header *header = &cs_resp_pdu->header;
srslte::gtpc_create_session_response *cs_resp = &cs_resp_pdu->choice.create_session_response;
//Setup GTP-C header
header->piggyback = false;
header->teid_present = true;
header->teid = cs_req->sender_f_teid.teid; //Send create session requesponse to the CS Request TEID
header->type = srslte::GTPC_MSG_TYPE_CREATE_SESSION_RESPONSE;
//Setup uplink control TEID //Setup uplink control TEID
uint64_t spgw_uplink_ctrl_teid = get_new_ctrl_teid(); uint64_t spgw_uplink_ctrl_teid = get_new_ctrl_teid();
//Setup uplink user TEID //Setup uplink user TEID
@ -315,7 +327,7 @@ spgw::handle_create_session_request(struct srslte::gtpc_create_session_request *
//Allocate UE IP //Allocate UE IP
in_addr_t ue_ip = get_new_ue_ipv4(); in_addr_t ue_ip = get_new_ue_ipv4();
//Save the UE context //TODO!!! //Save the UE IMSI to Ctrl TEID map //TODO!!!
//Create session response message //Create session response message
//Initialize to zero\\ //Initialize to zero\\
@ -337,7 +349,10 @@ spgw::handle_create_session_request(struct srslte::gtpc_create_session_request *
cs_resp->paa.ipv4_present = true; cs_resp->paa.ipv4_present = true;
cs_resp->paa.ipv4 = ue_ip; cs_resp->paa.ipv4 = ue_ip;
m_mme_gtpc->handle_create_session_response(cs_resp_pdu);
return; return;
} }
} //namespace srsepc } //namespace srsepc

Loading…
Cancel
Save