diff --git a/src/hss/hss_context.c b/src/hss/hss_context.c index dd3ec8652..49798464c 100644 --- a/src/hss/hss_context.c +++ b/src/hss/hss_context.c @@ -24,10 +24,10 @@ status_t hss_context_init(void) char buf[HSS_KEY_LEN]; hss_ue_t *ue; - pool_init(&hss_ue_pool, MAX_NUM_OF_UE); - memset(&self, 0, sizeof(hss_context_t)); + pool_init(&hss_ue_pool, MAX_NUM_OF_UE); + memcpy(self.op, CORE_HEX(OP, strlen(OP), buf), HSS_KEY_LEN); memcpy(self.amf, CORE_HEX(AMF, strlen(AMF), buf), HSS_AMF_LEN); diff --git a/src/mme/mme_context.c b/src/mme/mme_context.c index 2ffd2fe0e..3003c48aa 100644 --- a/src/mme/mme_context.c +++ b/src/mme/mme_context.c @@ -29,6 +29,9 @@ status_t mme_context_init() d_assert(context_initialized == 0, return CORE_ERROR, "MME context already has been context_initialized"); + /* Initialize MME context */ + memset(&self, 0, sizeof(mme_context_t)); + pool_init(&mme_sgw_pool, MAX_NUM_OF_SGW); pool_init(&mme_enb_pool, MAX_NUM_OF_ENB); pool_init(&mme_ue_pool, MAX_NUM_OF_UE); @@ -36,8 +39,7 @@ status_t mme_context_init() list_init(&self.sgw_list); list_init(&self.enb_list); - /* Initialize MME context */ - memset(&self, 0, sizeof(mme_context_t)); + self.mme_ue_s1ap_id_hash = hash_make(); self.s1ap_addr = inet_addr("127.0.0.1"); self.s1ap_port = S1AP_SCTP_PORT; @@ -82,6 +84,9 @@ status_t mme_context_final() mme_sgw_remove_all(); mme_enb_remove_all(); + d_assert(self.mme_ue_s1ap_id_hash, , "Null param"); + hash_destroy(self.mme_ue_s1ap_id_hash); + pool_final(&mme_sgw_pool); pool_final(&mme_enb_pool); pool_final(&mme_ue_pool); @@ -186,7 +191,7 @@ status_t mme_enb_remove(mme_enb_t *enb) { d_assert(enb, return CORE_ERROR, "Null param"); - mme_ue_remove_all(enb); + mme_ue_remove_in_enb(enb); list_remove(&self.enb_list, enb); pool_free_node(&mme_enb_pool, enb); @@ -257,6 +262,7 @@ mme_ue_t* mme_ue_add(mme_enb_t *enb) { mme_ue_t *ue = NULL; + d_assert(self.mme_ue_s1ap_id_hash, return NULL, "Null param"); d_assert(enb, return NULL, "Null param"); pool_alloc_node(&mme_ue_pool, &ue); @@ -267,6 +273,8 @@ mme_ue_t* mme_ue_add(mme_enb_t *enb) ue->enb = enb; ue->mme_ue_s1ap_id = NEXT_ID(self.mme_ue_s1ap_id, 0xffffffff); + hash_set(self.mme_ue_s1ap_id_hash, &ue->mme_ue_s1ap_id, + sizeof(ue->mme_ue_s1ap_id), ue); list_append(&enb->ue_list, ue); @@ -275,6 +283,7 @@ mme_ue_t* mme_ue_add(mme_enb_t *enb) status_t mme_ue_remove(mme_ue_t *ue) { + d_assert(self.mme_ue_s1ap_id_hash, return CORE_ERROR, "Null param"); d_assert(ue, return CORE_ERROR, "Null param"); d_assert(ue->enb, return CORE_ERROR, "Null param"); @@ -290,19 +299,66 @@ status_t mme_ue_remove(mme_ue_t *ue) } list_remove(&ue->enb->ue_list, ue); + hash_set(self.mme_ue_s1ap_id_hash, &ue->mme_ue_s1ap_id, + sizeof(ue->mme_ue_s1ap_id), NULL); + pool_free_node(&mme_ue_pool, ue); return CORE_OK; } -status_t mme_ue_remove_all(mme_enb_t *enb) +status_t mme_ue_remove_all() +{ + hash_index_t *hi = NULL; + mme_ue_t *ue = NULL; + + for (hi = mme_ue_first(); hi; hi = mme_ue_next(hi)) + { + ue = mme_ue_this(hi); + mme_ue_remove(ue); + } + + return CORE_OK; +} + +mme_ue_t* mme_ue_find_by_mme_ue_s1ap_id(c_uint32_t mme_ue_s1ap_id) +{ + d_assert(self.mme_ue_s1ap_id_hash, return NULL, "Null param"); + return hash_get(self.mme_ue_s1ap_id_hash, + &mme_ue_s1ap_id, sizeof(mme_ue_s1ap_id)); +} + +hash_index_t *mme_ue_first() +{ + d_assert(self.mme_ue_s1ap_id_hash, return NULL, "Null param"); + return hash_first(self.mme_ue_s1ap_id_hash); +} + +hash_index_t *mme_ue_next(hash_index_t *hi) +{ + return hash_next(hi); +} + +mme_ue_t *mme_ue_this(hash_index_t *hi) +{ + d_assert(hi, return NULL, "Null param"); + return hash_this_val(hi); +} + +unsigned int mme_ue_count() +{ + d_assert(self.mme_ue_s1ap_id_hash, return 0, "Null param"); + return hash_count(self.mme_ue_s1ap_id_hash); +} + +status_t mme_ue_remove_in_enb(mme_enb_t *enb) { mme_ue_t *ue = NULL, *next_ue = NULL; - ue = mme_ue_first(enb); + ue = mme_ue_first_in_enb(enb); while (ue) { - next_ue = mme_ue_next(ue); + next_ue = mme_ue_next_in_enb(ue); mme_ue_remove(ue); @@ -317,24 +373,24 @@ mme_ue_t* mme_ue_find_by_enb_ue_s1ap_id( { mme_ue_t *ue = NULL; - ue = mme_ue_first(enb); + ue = mme_ue_first_in_enb(enb); while (ue) { if (enb_ue_s1ap_id == ue->enb_ue_s1ap_id) break; - ue = mme_ue_next(ue); + ue = mme_ue_next_in_enb(ue); } return ue; } -mme_ue_t* mme_ue_first(mme_enb_t *enb) +mme_ue_t* mme_ue_first_in_enb(mme_enb_t *enb) { return list_first(&enb->ue_list); } -mme_ue_t* mme_ue_next(mme_ue_t *ue) +mme_ue_t* mme_ue_next_in_enb(mme_ue_t *ue) { return list_next(ue); } diff --git a/src/mme/mme_context.h b/src/mme/mme_context.h index 9c2489cba..d1743e066 100644 --- a/src/mme/mme_context.h +++ b/src/mme/mme_context.h @@ -5,6 +5,7 @@ #include "core_errno.h" #include "core_net.h" #include "core_sha2.h" +#include "core_hash.h" #include "3gpp_common.h" #include "nas_types.h" @@ -69,6 +70,8 @@ typedef struct _mme_context_t { list_t sgw_list; list_t enb_list; + + hash_t *mme_ue_s1ap_id_hash; /* hash table for MME-UE-S1AP-ID */ } mme_context_t; typedef struct _mme_sgw_t { @@ -144,11 +147,18 @@ CORE_DECLARE(mme_enb_t*) mme_enb_next(mme_enb_t *enb); CORE_DECLARE(mme_ue_t*) mme_ue_add(mme_enb_t *enb); CORE_DECLARE(status_t) mme_ue_remove(mme_ue_t *ue); -CORE_DECLARE(status_t) mme_ue_remove_all(mme_enb_t *enb); +CORE_DECLARE(status_t) mme_ue_remove_all(); +CORE_DECLARE(mme_ue_t*) mme_ue_find_by_mme_ue_s1ap_id( + c_uint32_t mme_ue_s1ap_id); +CORE_DECLARE(hash_index_t *) mme_ue_first(); +CORE_DECLARE(hash_index_t *) mme_ue_next(hash_index_t *hi); +CORE_DECLARE(mme_ue_t *) mme_ue_this(hash_index_t *hi); +CORE_DECLARE(unsigned int) mme_ue_count(); +CORE_DECLARE(status_t) mme_ue_remove_in_enb(mme_enb_t *enb); CORE_DECLARE(mme_ue_t*) mme_ue_find_by_enb_ue_s1ap_id( mme_enb_t *enb, c_uint32_t enb_ue_s1ap_id); -CORE_DECLARE(mme_ue_t*) mme_ue_first(mme_enb_t *enb); -CORE_DECLARE(mme_ue_t*) mme_ue_next(mme_ue_t *ue); +CORE_DECLARE(mme_ue_t*) mme_ue_first_in_enb(mme_enb_t *enb); +CORE_DECLARE(mme_ue_t*) mme_ue_next_in_enb(mme_ue_t *ue); #ifdef __cplusplus } diff --git a/src/pgw/pgw_context.c b/src/pgw/pgw_context.c index c195cd6b1..af4c5bd2f 100644 --- a/src/pgw/pgw_context.c +++ b/src/pgw/pgw_context.c @@ -10,11 +10,11 @@ static pgw_context_t self; -static int ctx_initialized = 0; +static int context_initiaized = 0; status_t pgw_context_init() { - d_assert(ctx_initialized == 0, return CORE_ERROR, + d_assert(context_initiaized == 0, return CORE_ERROR, "MME context already has been initialized"); memset(&self, 0, sizeof(pgw_context_t)); @@ -31,17 +31,17 @@ status_t pgw_context_init() self.s5u_node.addr = inet_addr("127.0.0.1"); self.s5u_node.port = GTPV1_U_UDP_PORT; - ctx_initialized = 1; + context_initiaized = 1; return CORE_OK; } status_t pgw_context_final() { - d_assert(ctx_initialized == 1, return CORE_ERROR, + d_assert(context_initiaized == 1, return CORE_ERROR, "HyperCell context already has been finalized"); - ctx_initialized = 0; + context_initiaized = 0; return CORE_OK; } diff --git a/src/sgw/sgw_context.c b/src/sgw/sgw_context.c index 38aa20e3c..dbe31e564 100644 --- a/src/sgw/sgw_context.c +++ b/src/sgw/sgw_context.c @@ -22,6 +22,10 @@ status_t sgw_context_init() memset(&self, 0, sizeof(sgw_context_t)); + pool_init(&sgw_gtpc_pool, MAX_NUM_OF_UE); + + self.gtpc_hash = hash_make(); + self.s11_addr = inet_addr("127.0.0.1"); self.s11_port = GTPV2_C_UDP_PORT + 1; self.s11_node.addr = inet_addr("127.0.0.1"); @@ -41,10 +45,6 @@ status_t sgw_context_init() self.s5u_node.addr = inet_addr("127.0.0.1"); self.s5u_node.port = GTPV1_U_UDP_PORT + 1; - pool_init(&sgw_gtpc_pool, MAX_NUM_OF_UE); - - self.gtpc_hash = hash_make(); - context_initialized = 1; return CORE_OK;