From 13595ccb2d94e433067d8eb47c59d1dc2ca7fe80 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 29 Nov 2017 16:34:14 +0000 Subject: [PATCH] Added logging to MME GTP-C. Fixed weird comment bug. --- lib/include/srslte/asn1/gtpc_ies.h | 4 +-- lib/include/srslte/asn1/gtpc_msg.h | 1 + srsenb/enb.conf.example | 4 +-- srsepc/hdr/mme/mme.h | 4 +-- srsepc/hdr/mme/mme_gtpc.h | 11 ++++++--- srsepc/src/main.cc | 7 +++++- srsepc/src/mme/mme.cc | 6 ++--- srsepc/src/mme/mme_gtpc.cc | 39 ++++++++++++++++++++---------- srsepc/src/mme/s1ap.cc | 7 ++++-- srsepc/src/spgw/spgw.cc | 17 +++++++------ 10 files changed, 63 insertions(+), 37 deletions(-) diff --git a/lib/include/srslte/asn1/gtpc_ies.h b/lib/include/srslte/asn1/gtpc_ies.h index ab3e00d43..8c8e5d97e 100644 --- a/lib/include/srslte/asn1/gtpc_ies.h +++ b/lib/include/srslte/asn1/gtpc_ies.h @@ -402,8 +402,8 @@ enum gtpc_interface_type struct gtpc_f_teid_ie { - bool v4_present; - bool v6_present; + bool ipv4_present; + bool ipv6_present; enum gtpc_interface_type interface_type; uint32_t teid; in_addr_t ipv4; diff --git a/lib/include/srslte/asn1/gtpc_msg.h b/lib/include/srslte/asn1/gtpc_msg.h index a72e51ac9..86cf96046 100644 --- a/lib/include/srslte/asn1/gtpc_msg.h +++ b/lib/include/srslte/asn1/gtpc_msg.h @@ -248,6 +248,7 @@ struct gtpc_create_session_response bool sender_f_teid_present; struct gtpc_f_teid_ie sender_f_teid; //C //PGW S5/S8/S2b F-TEID //C + bool paa_present; struct gtpc_pdn_address_allocation_ie paa; //C //apn_restriction //apn_ambr diff --git a/srsenb/enb.conf.example b/srsenb/enb.conf.example index 44e546116..55f983c3c 100644 --- a/srsenb/enb.conf.example +++ b/srsenb/enb.conf.example @@ -22,8 +22,8 @@ phy_cell_id = 1 tac = 0x0007 mcc = 001 mnc = 01 -mme_addr = 127.0.1.100 -gtp_bind_addr = 127.0.1.1 +mme_addr = 127.0.0.1 +gtp_bind_addr = 127.0.0.1 n_prb = 25 ##################################################################### diff --git a/srsepc/hdr/mme/mme.h b/srsepc/hdr/mme/mme.h index 6016ebb75..26296c2c6 100644 --- a/srsepc/hdr/mme/mme.h +++ b/srsepc/hdr/mme/mme.h @@ -66,7 +66,7 @@ class mme: public: static mme* get_instance(void); static void cleanup(void); - int init(mme_args_t* args, srslte::log_filter *s1ap_log); + int init(mme_args_t* args, srslte::log_filter *s1ap_log, srslte::log_filter *mme_gtpc_log); void stop(); int get_s1_mme(); void run_thread(); @@ -84,7 +84,7 @@ private: /*Logs*/ srslte::log_filter *m_s1ap_log; - + srslte::log_filter *m_mme_gtpc_log; }; } // namespace srsepc diff --git a/srsepc/hdr/mme/mme_gtpc.h b/srsepc/hdr/mme/mme_gtpc.h index 3b8ed3901..17cc23189 100644 --- a/srsepc/hdr/mme/mme_gtpc.h +++ b/srsepc/hdr/mme/mme_gtpc.h @@ -26,6 +26,8 @@ #ifndef MME_GTPC_H #define MME_GTPC_H +#include "srslte/common/log.h" +#include "srslte/common/log_filter.h" #include "srslte/common/buffer_pool.h" #include #include "srslte/asn1/gtpc.h" @@ -43,9 +45,9 @@ public: static mme_gtpc* get_instance(void); static void cleanup(void); - bool init(); + bool init(srslte::log_filter *mme_gtpc_log); - uint64_t get_new_ctrl_teid(); + uint32_t get_new_ctrl_teid(); void send_create_session_request(uint64_t imsi, uint32_t mme_s1ap_id); void handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu); @@ -55,14 +57,15 @@ private: virtual ~mme_gtpc(); static mme_gtpc *m_instance; + srslte::log_filter *m_mme_gtpc_log; srslte::byte_buffer_pool *m_pool; s1ap* m_s1ap; spgw* m_spgw; in_addr_t m_mme_gtpc_ip; - uint64_t m_next_ctrl_teid; - std::map m_teid_to_mme_s1ap_id; + uint32_t m_next_ctrl_teid; + std::map m_teid_to_mme_s1ap_id; }; diff --git a/srsepc/src/main.cc b/srsepc/src/main.cc index b0a4b1432..b75fcd32d 100644 --- a/srsepc/src/main.cc +++ b/srsepc/src/main.cc @@ -201,6 +201,11 @@ main (int argc,char * argv[] ) s1ap_log.set_level(srslte::LOG_LEVEL_DEBUG); s1ap_log.set_hex_limit(32); + srslte::log_filter mme_gtpc_log; + mme_gtpc_log.init("GTPC",logger); + mme_gtpc_log.set_level(srslte::LOG_LEVEL_DEBUG); + mme_gtpc_log.set_hex_limit(32); + srslte::log_filter hss_log; hss_log.init("HSS ",logger); hss_log.set_level(srslte::LOG_LEVEL_DEBUG); @@ -212,7 +217,7 @@ main (int argc,char * argv[] ) spgw_log.set_hex_limit(32); mme *mme = mme::get_instance(); - if (mme->init(&args.mme_args, &s1ap_log)) { + if (mme->init(&args.mme_args, &s1ap_log, &mme_gtpc_log)) { cout << "Error initializing MME" << endl; exit(1); } diff --git a/srsepc/src/mme/mme.cc b/srsepc/src/mme/mme.cc index 07016b66d..ab4778c20 100644 --- a/srsepc/src/mme/mme.cc +++ b/srsepc/src/mme/mme.cc @@ -70,12 +70,12 @@ mme::cleanup(void) } int -mme::init(mme_args_t* args, srslte::log_filter *s1ap_log) +mme::init(mme_args_t* args, srslte::log_filter *s1ap_log, srslte::log_filter *mme_gtpc_log) { /*Init logger*/ m_s1ap_log = s1ap_log; - + m_mme_gtpc_log = mme_gtpc_log; /*Init S1AP*/ m_s1ap = s1ap::get_instance(); if(m_s1ap->init(args->s1ap_args, s1ap_log)){ @@ -85,7 +85,7 @@ mme::init(mme_args_t* args, srslte::log_filter *s1ap_log) /*Init GTP-C*/ m_mme_gtpc = mme_gtpc::get_instance(); - if(!m_mme_gtpc->init()) + if(!m_mme_gtpc->init(m_mme_gtpc_log)) { m_s1ap_log->console("Error initializing GTP-C\n"); exit(-1); diff --git a/srsepc/src/mme/mme_gtpc.cc b/srsepc/src/mme/mme_gtpc.cc index 7e5c87d7b..20ed20f50 100644 --- a/srsepc/src/mme/mme_gtpc.cc +++ b/srsepc/src/mme/mme_gtpc.cc @@ -36,7 +36,6 @@ mme_gtpc* mme_gtpc::m_instance = NULL; boost::mutex mme_gtpc_instance_mutex; mme_gtpc::mme_gtpc() - :m_next_ctrl_teid(1) { } @@ -66,16 +65,24 @@ mme_gtpc::cleanup(void) bool -mme_gtpc::init() +mme_gtpc::init(srslte::log_filter *mme_gtpc_log) { + + /*Init log*/ + m_mme_gtpc_log = mme_gtpc_log; + + m_next_ctrl_teid = 1; + 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_spgw = spgw::get_instance(); + m_mme_gtpc_log->info("MME GTP-C Initialized\n"); + m_mme_gtpc_log->console("MME GTP-C Initialized\n"); return true; } -uint64_t +uint32_t mme_gtpc::get_new_ctrl_teid() { return m_next_ctrl_teid++; //FIXME Use a Id pool? @@ -83,6 +90,8 @@ mme_gtpc::get_new_ctrl_teid() void mme_gtpc::send_create_session_request(uint64_t imsi, uint32_t mme_ue_s1ap_id) { + m_mme_gtpc_log->info("Preparing Create Session Request. IMSI %lu\n", imsi); + m_mme_gtpc_log->console("Preparing Create Session Request. IMSI %lu\n", imsi); struct srslte::gtpc_pdu cs_req_pdu; struct srslte::gtpc_create_session_request *cs_req = &cs_req_pdu.choice.create_session_request; @@ -99,19 +108,22 @@ mme_gtpc::send_create_session_request(uint64_t imsi, uint32_t mme_ue_s1ap_id) cs_req_pdu.header.type = srslte::GTPC_MSG_TYPE_CREATE_SESSION_REQUEST; //Setup GTP-C Create Session Request IEs - // Control TEID allocated \\ + // Control TEID allocated cs_req->sender_f_teid.teid = get_new_ctrl_teid(); cs_req->sender_f_teid.ipv4 = m_mme_gtpc_ip; - // APN \\ + + m_mme_gtpc_log->info("Next control TEID: %lu \n", m_next_ctrl_teid); + m_mme_gtpc_log->info("Allocated control TEID: %lu \n", cs_req->sender_f_teid.teid); + m_mme_gtpc_log->console("Allocated control TEID: %lu \n", cs_req->sender_f_teid.teid); + // APN memcpy(cs_req->apn, "internet", sizeof("internet")); - // RAT Type \\ - cs_req->rat_type = GTPC_RAT_TYPE::EUTRAN; + // RAT Type + //cs_req->rat_type = srslte::GTPC_RAT_TYPE::EUTRAN; //Save RX Control TEID - m_teid_to_mme_s1ap_id.insert(std::pair(cs_req->sender_f_teid.teid, mme_ue_s1ap_id)); + m_teid_to_mme_s1ap_id.insert(std::pair(cs_req->sender_f_teid.teid, mme_ue_s1ap_id)); m_spgw->handle_create_session_request(cs_req, &cs_resp_pdu); - handle_create_session_response(&cs_resp_pdu); } @@ -119,24 +131,25 @@ void mme_gtpc::handle_create_session_response(srslte::gtpc_pdu *cs_resp_pdu) { struct srslte::gtpc_create_session_response *cs_resp = & cs_resp_pdu->choice.create_session_response; - + m_mme_gtpc_log->info("Received Create Session Response\n"); if (cs_resp_pdu->header.type != srslte::GTPC_MSG_TYPE_CREATE_SESSION_RESPONSE) { - //m_mme_gtpc_log->warning("Could not create GTPC session.\n"); + m_mme_gtpc_log->warning("Could not create GTPC session. Not a create session response\n"); //TODO Handle err return; } if (cs_resp->cause.cause_value != srslte::GTPC_CAUSE_VALUE_REQUEST_ACCEPTED){ - //m_mme_gtpc_log->warning("Could not create GTPC session.\n"); + m_mme_gtpc_log->warning("Could not create GTPC session. Create Session Request not accepted\n"); //TODO Handle error return; } //Get MME_UE_S1AP_ID from the Ctrl TEID - std::map::iterator id_it = m_teid_to_mme_s1ap_id.find(cs_resp_pdu->header.teid); + std::map::iterator id_it = m_teid_to_mme_s1ap_id.find(cs_resp_pdu->header.teid); if(id_it == m_teid_to_mme_s1ap_id.end()) { //Could not find MME UE S1AP TEID + m_mme_gtpc_log->warning("Could not find MME UE S1AP TEID.\n"); return; } uint32_t mme_s1ap_id = id_it->second; diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index b4064efd6..b562a09cf 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -428,7 +428,7 @@ s1ap::handle_uplink_nas_transport(LIBLTE_S1AP_MESSAGE_UPLINKNASTRANSPORT_STRUCT m_s1ap_log->warning("Could not find UE. MME-UE S1AP id: %lu\n",mme_ue_s1ap_id); return false; } - m_s1ap_log->debug("Found UE. MME-UE S1AP id: %lu",mme_ue_s1ap_id); + m_s1ap_log->debug("Found UE. MME-UE S1AP id: %lu\n",mme_ue_s1ap_id); //Get NAS message type uint8_t pd, msg_type; @@ -564,6 +564,8 @@ s1ap::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, struct srslte: LIBLTE_S1AP_E_RABTOBESETUPITEMCTXTSUREQ_STRUCT *erab_ctxt = &in_ctxt_req->E_RABToBeSetupListCtxtSUReq.buffer[0]; //FIXME support more than one erab srslte::byte_buffer_t *reply_buffer = m_pool->allocate(); + m_s1ap_log->info("Preparing to send Initial Context Setup request\n"); + //Find UE Context std::map::iterator ue_ctx_it = m_active_ues.find(mme_ue_s1ap_id); if(ue_ctx_it == m_active_ues.end()) @@ -622,7 +624,8 @@ s1ap::send_initial_context_setup_request(uint32_t mme_ue_s1ap_id, struct srslte: m_s1ap_log->error("Failed to send Initial Context Setup Request\n"); return false; } - + m_s1ap_log->info("Sent Intial Context Setup Request\n"); + m_s1ap_log->console("Sent Intial Context Setup Request\n"); m_pool->deallocate(reply_buffer); return true; diff --git a/srsepc/src/spgw/spgw.cc b/srsepc/src/spgw/spgw.cc index a9e833b18..cf53686a1 100644 --- a/srsepc/src/spgw/spgw.cc +++ b/srsepc/src/spgw/spgw.cc @@ -313,13 +313,14 @@ spgw::handle_create_session_request(struct srslte::gtpc_create_session_request * srslte::gtpc_header *header = &cs_resp_pdu->header; srslte::gtpc_create_session_response *cs_resp = &cs_resp_pdu->choice.create_session_response; + + m_spgw_log->info("Received Create Session Request\n"); //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 uint64_t spgw_uplink_ctrl_teid = get_new_ctrl_teid(); //Setup uplink user TEID @@ -327,28 +328,28 @@ spgw::handle_create_session_request(struct srslte::gtpc_create_session_request * //Allocate UE IP in_addr_t ue_ip = get_new_ue_ipv4(); - //Save the UE IMSI to Ctrl TEID map //TODO!!! + //Save the UE IP to User TEID map //TODO!!! //Create session response message //Initialize to zero\\ bzero(cs_resp,sizeof(struct srslte::gtpc_create_session_response)); - //Setup Cause\\ + //Setup Cause cs_resp->cause.cause_value = srslte::GTPC_CAUSE_VALUE_REQUEST_ACCEPTED; - //Setup sender F-TEID (ctrl)\\ - cs_resp->sender_f_teid.teid_present = true; + //Setup sender F-TEID (ctrl) + cs_resp->sender_f_teid.ipv4_present = true; cs_resp->sender_f_teid.teid = spgw_uplink_ctrl_teid; cs_resp->sender_f_teid.ipv4 = 0;//FIXME This is not relevant, as the GTP-C is not transmitted over sockets yet. - //Bearer context created\\ + //Bearer context created cs_resp->eps_bearer_context_created.ebi = 5; cs_resp->eps_bearer_context_created.cause.cause_value = srslte::GTPC_CAUSE_VALUE_REQUEST_ACCEPTED; cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid_present=true; cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid.teid = spgw_uplink_user_teid; - //Fill in the PDA\\ + //Fill in the PDA cs_resp->paa_present = true; cs_resp->paa.pdn_type = srslte::GTPC_PDN_TYPE_IPV4; cs_resp->paa.ipv4_present = true; cs_resp->paa.ipv4 = ue_ip; - + m_spgw_log->info("Sending Create Session Response\n"); m_mme_gtpc->handle_create_session_response(cs_resp_pdu); return; }