From 1fb304ddd3ec463971067b109ac3c9a2277fcbf1 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 20 Dec 2017 10:45:55 +0000 Subject: [PATCH] Continuing to clean up. Moved S1 setup request to s1ap_mngmnt_proc --- srsepc/hdr/mme/s1ap.h | 14 +++++-- srsepc/hdr/mme/s1ap_mngmt_proc.h | 8 +++- srsepc/src/mme/s1ap.cc | 67 +++++++++++++++++++++++++------ srsepc/src/mme/s1ap_mngmt_proc.cc | 53 ++++++++++-------------- 4 files changed, 92 insertions(+), 50 deletions(-) diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index 2d0d14924..b8f0ff730 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -89,8 +89,13 @@ public: bool pack_esm_information_request(srslte::byte_buffer_t* reply_msg, srsepc::ue_ctx_t* ue_ctx); bool handle_esm_information_response(srslte::byte_buffer_t *nas_msg, srslte::byte_buffer_t *reply_msg, ue_ctx_t* ue_ctx); - void print_enb_ctx_info(const enb_ctx_t &enb_ctx); + void print_enb_ctx_info(const std::string &prefix, const enb_ctx_t &enb_ctx); + uint32_t get_plmn(); + enb_ctx_t* find_enb_ctx(uint16_t enb_id); + void add_enb_ctx(const enb_ctx_t &enb_ctx, const struct sctp_sndrcvinfo* enb_sri); + + s1ap_args_t m_s1ap_args; srslte::log_filter *m_s1ap_log; private: @@ -99,7 +104,6 @@ private: static s1ap *m_instance; - s1ap_args_t m_s1ap_args; uint32_t m_plmn; srslte::byte_buffer_pool *m_pool; @@ -118,7 +122,11 @@ private: mme_gtpc *m_mme_gtpc; }; - +inline uint32_t +s1ap::get_plmn() +{ + return m_plmn; +} } //namespace srsepc diff --git a/srsepc/hdr/mme/s1ap_mngmt_proc.h b/srsepc/hdr/mme/s1ap_mngmt_proc.h index ec38c66cc..7f5771676 100644 --- a/srsepc/hdr/mme/s1ap_mngmt_proc.h +++ b/srsepc/hdr/mme/s1ap_mngmt_proc.h @@ -43,9 +43,10 @@ public: static s1ap_mngmt_proc* get_instance(void); static void cleanup(void); - void init(void); + bool handle_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRUCT *msg, sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag); + //Packing/unpacking helper functions 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); @@ -55,8 +56,11 @@ private: s1ap_mngmt_proc(); virtual ~s1ap_mngmt_proc(); - s1ap* m_parent; + s1ap* m_s1ap; srslte::log_filter *m_s1ap_log; + + int m_s1mme; + s1ap_args_t m_s1ap_args; }; } //namespace srsepc diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index b4df6883d..a75c8ebd5 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -254,10 +254,13 @@ s1ap::handle_s1ap_rx_pdu(srslte::byte_buffer_t *pdu, struct sctp_sndrcvinfo *enb bool s1ap::handle_initiating_message(LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *msg, struct sctp_sndrcvinfo *enb_sri) { + bool reply_flag = false; + srslte::byte_buffer_t * reply_buffer = m_pool->allocate(); + switch(msg->choice_type) { case LIBLTE_S1AP_INITIATINGMESSAGE_CHOICE_S1SETUPREQUEST: m_s1ap_log->info("Received S1 Setup Request.\n"); - return handle_s1_setup_request(&msg->choice.S1SetupRequest, enb_sri); + m_s1ap_mngmt_proc->handle_s1_setup_request(&msg->choice.S1SetupRequest, enb_sri, reply_buffer, &reply_flag); case LIBLTE_S1AP_INITIATINGMESSAGE_CHOICE_INITIALUEMESSAGE: m_s1ap_log->info("Received Initial UE Message.\n"); return handle_initial_ue_message(&msg->choice.InitialUEMessage, enb_sri); @@ -270,6 +273,18 @@ s1ap::handle_initiating_message(LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *msg, stru default: m_s1ap_log->error("Unhandled intiating message: %s\n", liblte_s1ap_initiatingmessage_choice_text[msg->choice_type]); } + //Send Reply to eNB + if(reply_flag == true) + { + ssize_t n_sent = sctp_send(m_s1mme,reply_buffer->msg, reply_buffer->N_bytes, enb_sri, 0); + if(n_sent == -1) + { + m_s1ap_log->console("Failed to send S1 Setup Setup Reply"); + m_pool->deallocate(reply_buffer); + return false; + } + } + m_pool->deallocate(reply_buffer); return true; } @@ -286,7 +301,7 @@ s1ap::handle_successful_outcome(LIBLTE_S1AP_SUCCESSFULOUTCOME_STRUCT *msg) return true; } - + /* bool s1ap::handle_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRUCT *msg, struct sctp_sndrcvinfo *enb_sri) { @@ -345,7 +360,7 @@ s1ap::handle_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRUCT *msg, st } return true; } - + */ bool s1ap::handle_initial_ue_message(LIBLTE_S1AP_MESSAGE_INITIALUEMESSAGE_STRUCT *init_ue, struct sctp_sndrcvinfo *enb_sri) { @@ -1005,6 +1020,32 @@ s1ap::handle_ue_context_release_request(LIBLTE_S1AP_MESSAGE_UECONTEXTRELEASEREQU return true; } + +enb_ctx_t* +s1ap::find_enb_ctx(uint16_t enb_id) +{ + std::map::iterator it = m_active_enbs.find(enb_id); + if(it == m_active_enbs.end()) + { + return NULL; + } + else + { + return it->second; + } +} + +void +s1ap::add_enb_ctx(const enb_ctx_t &enb_ctx, const struct sctp_sndrcvinfo *enb_sri) +{ + std::set ue_set; + enb_ctx_t *enb_ptr = new enb_ctx_t; + memcpy(enb_ptr,&enb_ctx,sizeof(enb_ctx_t)); + m_active_enbs.insert(std::pair(enb_ptr->enb_id,enb_ptr)); + m_sctp_to_enb_id.insert(std::pair(enb_sri->sinfo_assoc_id, enb_ptr->enb_id)); + m_enb_id_to_ue_ids.insert(std::pair >(enb_ptr->enb_id,ue_set)); +} + void s1ap::activate_eps_bearer(uint32_t mme_s1ap_id, uint8_t ebi) { @@ -1028,33 +1069,33 @@ s1ap::activate_eps_bearer(uint32_t mme_s1ap_id, uint8_t ebi) } void -s1ap::print_enb_ctx_info(const enb_ctx_t &enb_ctx) +s1ap::print_enb_ctx_info(const std::string &prefix, const enb_ctx_t &enb_ctx) { std::string mnc_str, mcc_str; if(enb_ctx.enb_name_present) { - 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); + m_s1ap_log->console("%s - eNB Name: %s, eNB id: 0x%x\n",prefix.c_str(), enb_ctx.enb_name, enb_ctx.enb_id); + m_s1ap_log->info("%s - eNB Name: %s, eNB id: 0x%x\n", prefix.c_str(), 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); + m_s1ap_log->console("%s - eNB Id 0x%x\n",prefix.c_str(), enb_ctx.enb_id); + m_s1ap_log->info("%s - eNB Id 0x%x\n", prefix.c_str(), 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); + m_s1ap_log->info("%s - MCC:%s, MNC:%s, PLMN: %d\n", prefix.c_str(), mcc_str.c_str(), mnc_str.c_str(), enb_ctx.plmn); + m_s1ap_log->console("%s - MCC:%s, MNC:%s, PLMN: %d\n", prefix.c_str(), mcc_str.c_str(), mnc_str.c_str(), enb_ctx.plmn); for(int i=0;iinfo("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->info("%s - TAC %d, B-PLMN %d\n",prefix.c_str(), enb_ctx.tac[i],enb_ctx.bplmns[i][j]); + m_s1ap_log->console("%s - TAC %d, B-PLMN %d\n",prefix.c_str(), enb_ctx.tac[i],enb_ctx.bplmns[i][j]); } } - m_s1ap_log->console("S1 Setup Request - Paging DRX %d\n",enb_ctx.drx); + m_s1ap_log->console("%s - Paging DRX %d\n",prefix.c_str(),enb_ctx.drx); return; } diff --git a/srsepc/src/mme/s1ap_mngmt_proc.cc b/srsepc/src/mme/s1ap_mngmt_proc.cc index 2f1123dcd..296952d7b 100644 --- a/srsepc/src/mme/s1ap_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_mngmt_proc.cc @@ -66,39 +66,39 @@ s1ap_mngmt_proc::cleanup(void) void s1ap_mngmt_proc::init(void) { - m_parent = s1ap::get_instance(); - m_s1ap_log = m_parent->m_s1ap_log; + m_s1ap = s1ap::get_instance(); + m_s1ap_log = m_s1ap->m_s1ap_log; + m_s1mme = m_s1ap->get_s1_mme(); + m_s1ap_args = m_s1ap->m_s1ap_args; } - /* -bool -s1ap_mngmt_proc::handle_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRUCT *msg, struct sctp_sndrcvinfo *enb_sri) + +bool +s1ap_mngmt_proc::handle_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRUCT *msg, struct sctp_sndrcvinfo *enb_sri, srslte::byte_buffer_t *reply_buffer, bool *reply_flag) { - - std::string mnc_str, mcc_str; - enb_ctx_t enb_ctx; - srslte::byte_buffer_t reply_msg; + enb_ctx_t enb_ctx; LIBLTE_S1AP_S1AP_PDU_STRUCT reply_pdu; - if(!m_s1ap_mngmt_proc.unpack_s1_setup_request(msg, &enb_ctx)) + if(!unpack_s1_setup_request(msg, &enb_ctx)) { m_s1ap_log->error("Malformed S1 Setup Request\n"); return false; } //Log S1 Setup Request Info - m_s1ap_log->console("Received S1 Setup Request. Association: %d\n",enb_sri->sinfo_assoc_id); - print_enb_ctx_info(enb_ctx); + m_s1ap_log->console("Received S1 Setup Request."); + m_s1ap->print_enb_ctx_info(std::string("S1 Setup Request"),enb_ctx); //Check matching PLMNs - if(enb_ctx.plmn!=m_plmn){ + if(enb_ctx.plmn!=m_s1ap->get_plmn()){ + m_s1ap_log->console("Sending S1 Setup Failure - Unkown PLMN\n"); - m_s1ap_log->info("Sending S1 Setup Failure - Unkown PLMN\n"); - m_s1ap_mngmt_proc.pack_s1_setup_failure(LIBLTE_S1AP_CAUSEMISC_UNKNOWN_PLMN,&reply_msg); + m_s1ap_log->warning("Sending S1 Setup Failure - Unkown PLMN\n"); + pack_s1_setup_failure(LIBLTE_S1AP_CAUSEMISC_UNKNOWN_PLMN,reply_buffer); } else{ - std::map::iterator it = m_active_enbs.find(enb_ctx.enb_id); - if(it != m_active_enbs.end()) + enb_ctx_t *enb_ptr = m_s1ap->find_enb_ctx(enb_ctx.enb_id); + if(enb_ptr == NULL) { //eNB already registered //TODO replace enb_ctx @@ -106,29 +106,18 @@ s1ap_mngmt_proc::handle_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRU else { //new eNB - std::set ue_set; - enb_ctx_t *enb_ptr = new enb_ctx_t; - memcpy(enb_ptr,&enb_ctx,sizeof(enb_ctx)); - m_active_enbs.insert(std::pair(enb_ptr->enb_id,enb_ptr)); - m_sctp_to_enb_id.insert(std::pair(enb_sri->sinfo_assoc_id, enb_ptr->enb_id)); - m_enb_id_to_ue_ids.insert(std::pair >(enb_ptr->enb_id,ue_set)); + m_s1ap->add_enb_ctx(enb_ctx,enb_sri); } - m_s1ap_mngmt_proc.pack_s1_setup_response(m_s1ap_args, &reply_msg); + pack_s1_setup_response(m_s1ap_args, reply_buffer); m_s1ap_log->console("Sending S1 Setup Response\n"); m_s1ap_log->info("Sending S1 Setup Response\n"); } - //Send Reply to eNB - ssize_t n_sent = sctp_send(m_s1mme,reply_msg.msg, reply_msg.N_bytes, enb_sri, 0); - if(n_sent == -1) - { - m_s1ap_log->console("Failed to send S1 Setup Setup Reply"); - return false; - } + *reply_flag = true; return true; } - */ + /* * Packing/Unpacking helper functions.