From 336af1ed93da8489305349b09bba439761cd16ad Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 5 Feb 2018 12:26:23 +0000 Subject: [PATCH] Adding functions to get context from IMSI or MME UE S1AP Id. --- srsepc/hdr/mme/s1ap.h | 7 +++-- srsepc/src/mme/s1ap.cc | 65 +++++++++++++++++++++++++++++++++--------- 2 files changed, 56 insertions(+), 16 deletions(-) diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index fc4dd3d49..0f4be8d9b 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -81,6 +81,8 @@ public: void add_new_enb_ctx(const enb_ctx_t &enb_ctx, const struct sctp_sndrcvinfo* enb_sri); ue_ctx_t* find_ue_ctx(uint32_t mme_ue_s1ap_id); void add_new_ue_ctx(const ue_ctx_t &ue_ctx); + ue_ctx_t* find_ue_ctx_from_imsi(uint64_t imsi); + ue_ctx_t* find_ue_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id); bool delete_ue_ctx(ue_ctx_t *ue_ctx); uint32_t allocate_m_tmsi(uint32_t mme_ue_s1ap_id); @@ -107,12 +109,13 @@ private: int m_s1mme; std::map m_active_enbs; std::map m_sctp_to_enb_id; - std::map m_active_ues; + std::map m_imsi_to_ue_ctx; + std::map m_mme_ue_s1ap_id_to_imsi; std::map > m_enb_id_to_ue_ids; uint32_t m_next_mme_ue_s1ap_id; uint32_t m_next_m_tmsi; - //FIXME the GTP-C should be moved to the MME class, the the packaging of GTP-C messages is done. + //FIXME the GTP-C should be moved to the MME class, when the packaging of GTP-C messages is done. mme_gtpc *m_mme_gtpc; }; diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index d91b4c4c5..877912e8d 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -120,16 +120,19 @@ s1ap::stop() return; } - - - - int s1ap::get_s1_mme() { return m_s1mme; } +uint32_t +s1ap::get_next_mme_ue_s1ap_id() +{ + return m_next_mme_ue_s1ap_id++; +} + + int s1ap::enb_listen() { @@ -246,7 +249,7 @@ s1ap::handle_initiating_message(LIBLTE_S1AP_INITIATINGMESSAGE_STRUCT *msg, stru 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\n"); + m_s1ap_log->console("Failed to send S1AP Initiating Message Reply\n"); m_pool->deallocate(reply_buffer); return false; } @@ -327,6 +330,31 @@ s1ap::delete_enb_ctx(int32_t assoc_id) //UE Context Management void s1ap::add_new_ue_ctx(const ue_ctx_t &ue_ctx) +{ + ue_ctx_t *ue_ptr = new ue_ctx_t; + memcpy(ue_ptr,&ue_ctx,sizeof(ue_ctx)); + + //This map will store the context of previously registered UEs + m_imsi_to_ue_ctx.insert(std::pair(ue_ptr->imsi,ue_ptr)); + + //This will map UE's MME S1AP Id to the UE's IMSI, when they are not in the EMM-DERGISTERED state. + m_mme_ue_s1ap_id_to_imsi.insert(std::pair(ue_ptr->mme_ue_s1ap_id,ue_ptr->imsi)); + + //Store which enb currently holds the UE + std::map::iterator it_enb = m_sctp_to_enb_id.find(ue_ptr->enb_sri.sinfo_assoc_id); + uint16_t enb_id = it_enb->second; + std::map >::iterator it_ue_id = m_enb_id_to_ue_ids.find(enb_id); + if(it_ue_id==m_enb_id_to_ue_ids.end()) + { + m_s1ap_log->error("Could not find eNB's UEs\n"); + return; + } + it_ue_id->second.insert(ue_ptr->mme_ue_s1ap_id); + +} + /* +void +s1ap::add_new_ue_ctx(const ue_ctx_t &ue_ctx) { ue_ctx_t *ue_ptr = new ue_ctx_t; memcpy(ue_ptr,&ue_ctx,sizeof(ue_ctx)); @@ -343,12 +371,12 @@ s1ap::add_new_ue_ctx(const ue_ctx_t &ue_ctx) it_ue_id->second.insert(ue_ptr->mme_ue_s1ap_id); return; } - + */ ue_ctx_t* -s1ap::find_ue_ctx(uint32_t mme_ue_s1ap_id) +s1ap::find_ue_ctx_from_imsi(uint64_t imsi) { - std::map::iterator it = m_active_ues.find(mme_ue_s1ap_id); - if(it == m_active_ues.end()) + std::map::iterator it = m_imsi_to_ue_ctx.find(imsi); + if(it == m_imsi_to_ue_ctx.end()) { return NULL; } @@ -358,6 +386,19 @@ s1ap::find_ue_ctx(uint32_t mme_ue_s1ap_id) } } +ue_ctx_t* +s1ap::find_ue_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id) +{ + std::map::iterator imsi_it = m_mme_ue_s1ap_id_to_imsi.find(mme_ue_s1ap_id); + if(imsi_it == m_mme_ue_s1ap_id_to_imsi.find(mme_ue_s1ap_id)) + { + return NULL; + } + else + { + return find_ue_ctx_from_imsi(imsi_it->second); + } +} void s1ap::delete_ues_in_enb(uint16_t enb_id) { @@ -417,11 +458,7 @@ s1ap::delete_ue_ctx(ue_ctx_t *ue_ctx) -uint32_t -s1ap::get_next_mme_ue_s1ap_id() -{ - return m_next_mme_ue_s1ap_id++; -} + void s1ap::activate_eps_bearer(uint32_t mme_s1ap_id, uint8_t ebi)