From d9da1f84f01244b0a66ccadf65c9c61fe67e1c87 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 5 Feb 2018 15:33:16 +0000 Subject: [PATCH] Continuing to separate EMM and ECM context --- srsepc/hdr/mme/s1ap.h | 18 ++++-- srsepc/hdr/mme/s1ap_common.h | 2 +- srsepc/src/mme/s1ap.cc | 112 ++++++++++++++++++----------------- 3 files changed, 73 insertions(+), 59 deletions(-) diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index 0f4be8d9b..9e23868e8 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -79,11 +79,17 @@ public: uint32_t get_next_mme_ue_s1ap_id(); enb_ctx_t* find_enb_ctx(uint16_t enb_id); 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); + + void add_new_ue_emm_ctx(const ue_emm_ctx_t &ue_emm_ctx); + void add_new_ue_ecm_ctx(const ue_ecm_ctx_t &ue_ecm_ctx); + ue_emm_ctx_t* find_ue_emm_ctx_from_imsi(uint64_t imsi); + ue_ecm_ctx_t* find_ue_ecm_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id); + bool delete_ue_emm_ctx(ue_emm_ctx_t *ue_emm_ctx); + bool delete_ue_ecm_ctx(uint32_t mme_ue_s1ap_id); + void delete_ues_ecm_ctx_in_enb(uint16_t enb_id); uint32_t allocate_m_tmsi(uint32_t mme_ue_s1ap_id); @@ -109,9 +115,11 @@ private: int m_s1mme; std::map m_active_enbs; std::map m_sctp_to_enb_id; - std::map m_imsi_to_ue_ctx; - std::map m_mme_ue_s1ap_id_to_imsi; std::map > m_enb_id_to_ue_ids; + + std::map m_imsi_to_ue_emm_ctx; + std::map m_mme_ue_s1ap_id_to_ue_ecm_ctx; + uint32_t m_next_mme_ue_s1ap_id; uint32_t m_next_m_tmsi; diff --git a/srsepc/hdr/mme/s1ap_common.h b/srsepc/hdr/mme/s1ap_common.h index b252df586..7a76f7eb9 100644 --- a/srsepc/hdr/mme/s1ap_common.h +++ b/srsepc/hdr/mme/s1ap_common.h @@ -143,7 +143,7 @@ typedef struct{ ecm_state_t ecm_state; bool eit; erab_ctx_t erabs_ctx[MAX_ERABS_PER_UE]; -} ue_esm_ctx_t; +} ue_ecm_ctx_t; typedef struct{ diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 0db79a8fb..0b2379571 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -328,6 +328,38 @@ s1ap::delete_enb_ctx(int32_t assoc_id) //UE Context Management + +void +s1ap::add_new_ue_emm_ctx(const ue_emm_ctx_t &ue_emm_ctx) +{ + ue_emm_ctx_t *ue_ptr = new ue_emm_ctx_t; + memcpy(ue_ptr,&ue_emm_ctx,sizeof(ue_emm_ctx)); + + //This map will store UEs EMM context + m_imsi_to_ue_emm_ctx.insert(std::pair(ue_ptr->imsi,ue_ptr)); +} + +void +s1ap::add_new_ue_ecm_ctx(const ue_ecm_ctx_t &ue_ecm_ctx) +{ + ue_ecm_ctx_t *ue_ptr = new ue_ecm_ctx_t; + memcpy(ue_ptr,&ue_ecm_ctx,sizeof(ue_ecm_ctx)); + + //This map will store UE's ECM context. + m_mme_ue_s1ap_id_to_ue_ecm_ctx.insert(std::pair(ue_ptr->mme_ue_s1ap_id,ue_ptr)); + //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) { @@ -351,7 +383,7 @@ s1ap::add_new_ue_ctx(const ue_ctx_t &ue_ctx) } it_ue_id->second.insert(ue_ptr->mme_ue_s1ap_id); -} +}*/ /* void s1ap::add_new_ue_ctx(const ue_ctx_t &ue_ctx) @@ -372,11 +404,11 @@ s1ap::add_new_ue_ctx(const ue_ctx_t &ue_ctx) return; } */ -ue_ctx_t* -s1ap::find_ue_ctx_from_imsi(uint64_t imsi) +ue_emm_ctx_t* +s1ap::find_ue_emm_ctx_from_imsi(uint64_t imsi) { - std::map::iterator it = m_imsi_to_ue_ctx.find(imsi); - if(it == m_imsi_to_ue_ctx.end()) + std::map::iterator it = m_imsi_to_ue_emm_ctx.find(imsi); + if(it == m_imsi_to_ue_emm_ctx.end()) { return NULL; } @@ -386,33 +418,33 @@ s1ap::find_ue_ctx_from_imsi(uint64_t imsi) } } -ue_ctx_t* -s1ap::find_ue_ctx_from_mme_ue_s1ap_id(uint32_t mme_ue_s1ap_id) +ue_ecm_ctx_t* +s1ap::find_ue_ecm_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)) + std::map::iterator it = m_mme_ue_s1ap_id_to_ue_ecm_ctx.find(mme_ue_s1ap_id); + if(it == m_mme_ue_s1ap_id_to_ue_ecm_ctx.end()) { return NULL; } else { - return find_ue_ctx_from_imsi(imsi_it->second); + return it->second; } } bool -s1ap::delete_ue_esm_ctx(uint32_t mme_ue_s1ap_id) +s1ap::delete_ue_ecm_ctx(uint32_t mme_ue_s1ap_id) { - uint32_t mme_ue_s1ap_id = ue_ctx->mme_ue_s1ap_id; - std::map::iterator ue_ctx_it = m_active_ues.find(mme_ue_s1ap_id); - if(ue_ctx_it == m_active_ues.end() ) + std::map::iterator ue_ecm_ctx_it = m_mme_ue_s1ap_id_to_ue_ecm_ctx.find(mme_ue_s1ap_id); + if(ue_ecm_ctx_it == m_mme_ue_s1ap_id_to_ue_ecm_ctx.end()) { - m_s1ap_log->info("UE not found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); + m_s1ap_log->info("Cannot delete UE ECM context, UE not found. MME-UE S1AP Id: %d\n", mme_ue_s1ap_id); return false; } + ue_ecm_ctx_t* ue_ecm_ctx = ue_ecm_ctx_it->second; //Delete UE within eNB UE set - std::map::iterator it = m_sctp_to_enb_id.find(ue_ctx->enb_sri.sinfo_assoc_id); + std::map::iterator it = m_sctp_to_enb_id.find(ue_ecm_ctx->enb_sri.sinfo_assoc_id); if(it == m_sctp_to_enb_id.end() ) { m_s1ap_log->error("Could not find eNB for this request.\n"); @@ -428,67 +460,41 @@ s1ap::delete_ue_esm_ctx(uint32_t mme_ue_s1ap_id) ue_set->second.erase(mme_ue_s1ap_id); //Delete UE context - delete ue_ctx; - m_active_ues.erase(ue_ctx_it); + m_mme_ue_s1ap_id_to_ue_ecm_ctx.erase(ue_ecm_ctx_it); + delete ue_ecm_ctx; m_s1ap_log->info("Deleted UE Context.\n"); return true; } -void -s1ap::delete_ues_esm_ctx_in_enb(uint16_t enb_id) -{ - //delete UEs ctx - std::map >::iterator ues_in_enb = m_enb_id_to_ue_ids.find(enb_id); - std::set::iterator ue_id = ues_in_enb->second.begin(); - while(ue_id != ues_in_enb->second.end() ) - { - std::map::iterator ue_ctx = m_active_ues.find(*ue_id); - m_s1ap_log->info("Deleting UE context. UE IMSI: %lu\n", ue_ctx->second->imsi); - m_s1ap_log->console("Deleting UE context. UE IMSI: %lu\n", ue_ctx->second->imsi); - delete ue_ctx->second; //delete UE context - m_active_ues.erase(ue_ctx); //remove from general MME map - ues_in_enb->second.erase(ue_id++); //erase from the eNB's UE set - } -} void -s1ap::delete_ues_in_enb(uint16_t enb_id) +s1ap::delete_ues_ecm_ctx_in_enb(uint16_t enb_id) { //delete UEs ctx std::map >::iterator ues_in_enb = m_enb_id_to_ue_ids.find(enb_id); std::set::iterator ue_id = ues_in_enb->second.begin(); while(ue_id != ues_in_enb->second.end() ) { - std::map::iterator ue_ctx = m_active_ues.find(*ue_id); - m_s1ap_log->info("Deleting UE context. UE IMSI: %lu\n", ue_ctx->second->imsi); - m_s1ap_log->console("Deleting UE context. UE IMSI: %lu\n", ue_ctx->second->imsi); + std::map::iterator ue_ctx = m_mme_ue_s1ap_id_to_ue_ecm_ctx.find(*ue_id); + m_s1ap_log->info("Deleting UE context. UE-MME S1AP Id: %d\n", ue_ctx->second->mme_ue_s1ap_id); + m_s1ap_log->console("Deleting UE context. UE-MME S1AP Id: %d\n", ue_ctx->second->mme_ue_s1ap_id); + m_mme_ue_s1ap_id_to_ue_ecm_ctx.erase(ue_ctx); //remove from general MME map delete ue_ctx->second; //delete UE context - m_active_ues.erase(ue_ctx); //remove from general MME map ues_in_enb->second.erase(ue_id++); //erase from the eNB's UE set } - } - - - - - - - - - - +//UE Bearer Managment void s1ap::activate_eps_bearer(uint32_t mme_s1ap_id, uint8_t ebi) { - std::map::iterator ue_ctx_it = m_active_ues.find(mme_s1ap_id); - if(ue_ctx_it == m_active_ues.end()) + std::map::iterator ue_ctx_it = m_mme_ue_s1ap_id_to_ue_ecm_ctx.find(mme_s1ap_id); + if(ue_ctx_it == m_mme_ue_s1ap_id_to_ue_ecm_ctx.end()) { m_s1ap_log->error("Could not find UE context\n"); return; } - ue_ctx_t * ue_ctx = ue_ctx_it->second; + ue_ecm_ctx_t * ue_ctx = ue_ctx_it->second; if (ue_ctx->erabs_ctx[ebi].state != ERAB_CTX_SETUP) { m_s1ap_log->error("EPS Bearer could not be activated. MME S1AP Id %d, EPS Bearer id %d, state %d\n",mme_s1ap_id,ebi,ue_ctx->erabs_ctx[ebi].state);