|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "sbi-path.h" |
|
|
|
|
|
static ausf_context_t self; |
|
|
|
|
|
int __ausf_log_domain; |
|
|
|
|
|
static OGS_POOL(ausf_ue_pool, ausf_ue_t); |
|
|
|
|
|
static int context_initialized = 0; |
|
|
|
|
|
void ausf_context_init(void) |
|
|
{ |
|
|
ogs_assert(context_initialized == 0); |
|
|
|
|
|
|
|
|
memset(&self, 0, sizeof(ausf_context_t)); |
|
|
|
|
|
ogs_log_install_domain(&__ausf_log_domain, "ausf", ogs_core()->log.level); |
|
|
|
|
|
ogs_pool_init(&ausf_ue_pool, ogs_global_conf()->max.ue); |
|
|
|
|
|
ogs_list_init(&self.ausf_ue_list); |
|
|
self.suci_hash = ogs_hash_make(); |
|
|
ogs_assert(self.suci_hash); |
|
|
self.supi_hash = ogs_hash_make(); |
|
|
ogs_assert(self.supi_hash); |
|
|
|
|
|
context_initialized = 1; |
|
|
} |
|
|
|
|
|
void ausf_context_final(void) |
|
|
{ |
|
|
ogs_assert(context_initialized == 1); |
|
|
|
|
|
ausf_ue_remove_all(); |
|
|
|
|
|
ogs_assert(self.suci_hash); |
|
|
ogs_hash_destroy(self.suci_hash); |
|
|
ogs_assert(self.supi_hash); |
|
|
ogs_hash_destroy(self.supi_hash); |
|
|
|
|
|
ogs_pool_final(&ausf_ue_pool); |
|
|
|
|
|
context_initialized = 0; |
|
|
} |
|
|
|
|
|
ausf_context_t *ausf_self(void) |
|
|
{ |
|
|
return &self; |
|
|
} |
|
|
|
|
|
static int ausf_context_prepare(void) |
|
|
{ |
|
|
return OGS_OK; |
|
|
} |
|
|
|
|
|
static int ausf_context_validation(void) |
|
|
{ |
|
|
return OGS_OK; |
|
|
} |
|
|
|
|
|
int ausf_context_parse_config(void) |
|
|
{ |
|
|
int rv; |
|
|
yaml_document_t *document = NULL; |
|
|
ogs_yaml_iter_t root_iter; |
|
|
|
|
|
document = ogs_app()->document; |
|
|
ogs_assert(document); |
|
|
|
|
|
rv = ausf_context_prepare(); |
|
|
if (rv != OGS_OK) return rv; |
|
|
|
|
|
ogs_yaml_iter_init(&root_iter, document); |
|
|
while (ogs_yaml_iter_next(&root_iter)) { |
|
|
const char *root_key = ogs_yaml_iter_key(&root_iter); |
|
|
ogs_assert(root_key); |
|
|
if (!strcmp(root_key, "ausf")) { |
|
|
ogs_yaml_iter_t ausf_iter; |
|
|
ogs_yaml_iter_recurse(&root_iter, &ausf_iter); |
|
|
while (ogs_yaml_iter_next(&ausf_iter)) { |
|
|
const char *ausf_key = ogs_yaml_iter_key(&ausf_iter); |
|
|
ogs_assert(ausf_key); |
|
|
if (!strcmp(ausf_key, "default")) { |
|
|
|
|
|
} else if (!strcmp(ausf_key, "sbi")) { |
|
|
|
|
|
} else if (!strcmp(ausf_key, "nrf")) { |
|
|
|
|
|
} else if (!strcmp(ausf_key, "scp")) { |
|
|
|
|
|
} else if (!strcmp(ausf_key, "service_name")) { |
|
|
|
|
|
} else if (!strcmp(ausf_key, "discovery")) { |
|
|
|
|
|
} else |
|
|
ogs_warn("unknown key `%s`", ausf_key); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
rv = ausf_context_validation(); |
|
|
if (rv != OGS_OK) return rv; |
|
|
|
|
|
return OGS_OK; |
|
|
} |
|
|
|
|
|
ausf_ue_t *ausf_ue_add(char *suci) |
|
|
{ |
|
|
ausf_event_t e; |
|
|
ausf_ue_t *ausf_ue = NULL; |
|
|
|
|
|
ogs_assert(suci); |
|
|
|
|
|
ogs_pool_id_calloc(&ausf_ue_pool, &ausf_ue); |
|
|
if (!ausf_ue) { |
|
|
ogs_error("ogs_pool_id_calloc() failed"); |
|
|
return NULL; |
|
|
} |
|
|
|
|
|
ausf_ue->ctx_id = |
|
|
ogs_msprintf("%d", (int)ogs_pool_index(&ausf_ue_pool, ausf_ue)); |
|
|
ogs_assert(ausf_ue->ctx_id); |
|
|
|
|
|
ausf_ue->suci = ogs_strdup(suci); |
|
|
ogs_assert(ausf_ue->suci); |
|
|
ogs_hash_set(self.suci_hash, ausf_ue->suci, strlen(ausf_ue->suci), ausf_ue); |
|
|
|
|
|
memset(&e, 0, sizeof(e)); |
|
|
e.ausf_ue_id = ausf_ue->id; |
|
|
ogs_fsm_init(&ausf_ue->sm, ausf_ue_state_initial, ausf_ue_state_final, &e); |
|
|
|
|
|
ogs_list_add(&self.ausf_ue_list, ausf_ue); |
|
|
|
|
|
return ausf_ue; |
|
|
} |
|
|
|
|
|
void ausf_ue_remove(ausf_ue_t *ausf_ue) |
|
|
{ |
|
|
ausf_event_t e; |
|
|
|
|
|
ogs_assert(ausf_ue); |
|
|
|
|
|
ogs_list_remove(&self.ausf_ue_list, ausf_ue); |
|
|
|
|
|
memset(&e, 0, sizeof(e)); |
|
|
e.ausf_ue_id = ausf_ue->id; |
|
|
ogs_fsm_fini(&ausf_ue->sm, &e); |
|
|
|
|
|
|
|
|
ogs_sbi_object_free(&ausf_ue->sbi); |
|
|
|
|
|
ogs_assert(ausf_ue->ctx_id); |
|
|
ogs_free(ausf_ue->ctx_id); |
|
|
|
|
|
ogs_assert(ausf_ue->suci); |
|
|
ogs_hash_set(self.suci_hash, ausf_ue->suci, strlen(ausf_ue->suci), NULL); |
|
|
ogs_free(ausf_ue->suci); |
|
|
|
|
|
if (ausf_ue->supi) { |
|
|
ogs_hash_set(self.supi_hash, |
|
|
ausf_ue->supi, strlen(ausf_ue->supi), NULL); |
|
|
ogs_free(ausf_ue->supi); |
|
|
} |
|
|
|
|
|
AUTH_EVENT_CLEAR(ausf_ue); |
|
|
if (ausf_ue->auth_event.client) |
|
|
ogs_sbi_client_remove(ausf_ue->auth_event.client); |
|
|
|
|
|
if (ausf_ue->serving_network_name) |
|
|
ogs_free(ausf_ue->serving_network_name); |
|
|
|
|
|
ogs_pool_id_free(&ausf_ue_pool, ausf_ue); |
|
|
} |
|
|
|
|
|
void ausf_ue_remove_all(void) |
|
|
{ |
|
|
ausf_ue_t *ausf_ue = NULL, *next = NULL;; |
|
|
|
|
|
ogs_list_for_each_safe(&self.ausf_ue_list, next, ausf_ue) |
|
|
ausf_ue_remove(ausf_ue); |
|
|
} |
|
|
|
|
|
ausf_ue_t *ausf_ue_find_by_suci(char *suci) |
|
|
{ |
|
|
ogs_assert(suci); |
|
|
return (ausf_ue_t *)ogs_hash_get(self.suci_hash, suci, strlen(suci)); |
|
|
} |
|
|
|
|
|
ausf_ue_t *ausf_ue_find_by_supi(char *supi) |
|
|
{ |
|
|
ogs_assert(supi); |
|
|
return (ausf_ue_t *)ogs_hash_get(self.supi_hash, supi, strlen(supi)); |
|
|
} |
|
|
|
|
|
ausf_ue_t *ausf_ue_find_by_suci_or_supi(char *suci_or_supi) |
|
|
{ |
|
|
ogs_assert(suci_or_supi); |
|
|
if (strncmp(suci_or_supi, "suci-", strlen("suci-")) == 0) |
|
|
return ausf_ue_find_by_suci(suci_or_supi); |
|
|
else |
|
|
return ausf_ue_find_by_supi(suci_or_supi); |
|
|
} |
|
|
|
|
|
ausf_ue_t *ausf_ue_find_by_ctx_id(char *ctx_id) |
|
|
{ |
|
|
ogs_assert(ctx_id); |
|
|
return ogs_pool_find(&ausf_ue_pool, atoll(ctx_id)); |
|
|
} |
|
|
|
|
|
ausf_ue_t *ausf_ue_find_by_id(ogs_pool_id_t id) |
|
|
{ |
|
|
return ogs_pool_find_by_id(&ausf_ue_pool, id); |
|
|
} |
|
|
|
|
|
int get_ue_load(void) |
|
|
{ |
|
|
return (((ogs_pool_size(&ausf_ue_pool) - |
|
|
ogs_pool_avail(&ausf_ue_pool)) * 100) / |
|
|
ogs_pool_size(&ausf_ue_pool)); |
|
|
} |
|
|
|