open5gs/src/mme/mme_init.c

123 lines
2.6 KiB
C
Raw Normal View History

2017-03-04 14:48:04 +00:00
#define TRACE_MODULE _mme_init
2017-02-02 11:34:37 +00:00
#include "core_debug.h"
2017-02-13 00:58:55 +00:00
#include "core_thread.h"
2017-04-04 01:49:19 +00:00
#include "mme_event.h"
2017-02-13 00:58:55 +00:00
2017-04-04 02:00:25 +00:00
#include "mme_s6a_handler.h"
2017-03-04 15:20:09 +00:00
2017-08-02 12:11:22 +00:00
static thread_id sm_thread;
static void *THREAD_FUNC sm_main(thread_id id, void *data);
static thread_id net_thread;
static void *THREAD_FUNC net_main(thread_id id, void *data);
2017-02-02 11:34:37 +00:00
static int initialized = 0;
2017-03-04 14:48:04 +00:00
status_t mme_initialize()
2017-02-02 11:34:37 +00:00
{
2017-02-06 11:54:31 +00:00
status_t rv;
int ret;
2017-02-02 11:34:37 +00:00
2017-04-06 11:10:00 +00:00
rv = mme_context_init();
2017-02-26 12:16:03 +00:00
if (rv != CORE_OK) return rv;
2017-07-14 10:00:26 +00:00
rv = mme_context_parse_config();
if (rv != CORE_OK) return rv;
2017-07-31 13:35:25 +00:00
rv = mme_context_setup_trace_module();
if (rv != CORE_OK) return rv;
ret = mme_s6a_init();
if (ret != 0) return CORE_ERROR;
2017-02-27 04:56:13 +00:00
2017-08-02 12:11:22 +00:00
rv = thread_create(&sm_thread, NULL, sm_main, NULL);
if (rv != CORE_OK) return rv;
rv = thread_create(&net_thread, NULL, net_main, NULL);
2017-03-04 14:48:04 +00:00
if (rv != CORE_OK) return rv;
initialized = 1;
2017-03-04 14:48:04 +00:00
2017-02-02 11:34:37 +00:00
return CORE_OK;
}
2017-03-04 14:48:04 +00:00
void mme_terminate(void)
2017-02-02 11:34:37 +00:00
{
if (!initialized) return;
2017-08-02 12:11:22 +00:00
thread_delete(net_thread);
thread_delete(sm_thread);
2017-03-04 14:48:04 +00:00
2017-04-04 02:00:25 +00:00
mme_s6a_final();
2017-03-04 15:20:09 +00:00
2017-04-06 11:10:00 +00:00
mme_context_final();
2017-04-11 13:44:57 +00:00
gtp_xact_final();
2017-02-02 11:34:37 +00:00
}
2017-02-13 04:19:53 +00:00
2017-08-02 12:11:22 +00:00
static void *THREAD_FUNC sm_main(thread_id id, void *data)
2017-02-13 04:19:53 +00:00
{
event_t event;
2017-04-11 00:32:34 +00:00
fsm_t mme_sm;
2017-02-13 04:19:53 +00:00
c_time_t prev_tm, now_tm;
2017-03-27 01:22:30 +00:00
status_t rv;
2017-02-13 04:19:53 +00:00
memset(&event, 0, sizeof(event_t));
2017-03-06 08:55:50 +00:00
mme_self()->queue_id = event_create();
d_assert(mme_self()->queue_id, return NULL,
"MME event queue creation failed");
2017-03-28 07:35:57 +00:00
tm_service_init(&mme_self()->tm_service);
2017-04-01 14:28:22 +00:00
gtp_xact_init(&mme_self()->gtp_xact_ctx,
2017-04-13 10:32:56 +00:00
&mme_self()->tm_service, MME_EVT_S11_TRANSACTION_T3);
2017-02-13 04:19:53 +00:00
2017-04-11 00:32:34 +00:00
fsm_create(&mme_sm, mme_state_initial, mme_state_final);
fsm_init(&mme_sm, 0);
2017-02-13 04:19:53 +00:00
prev_tm = time_now();
2017-02-15 00:17:44 +00:00
while ((!thread_should_stop()))
2017-02-13 04:19:53 +00:00
{
2017-03-27 01:22:30 +00:00
rv = event_timedrecv(mme_self()->queue_id, &event, EVENT_WAIT_TIMEOUT);
2017-02-13 04:19:53 +00:00
2017-03-27 01:22:30 +00:00
d_assert(rv != CORE_ERROR, continue,
2017-02-13 04:19:53 +00:00
"While receiving a event message, error occurs");
now_tm = time_now();
/* if the gap is over 10 ms, execute preriodic jobs */
if (now_tm - prev_tm > EVENT_WAIT_TIMEOUT)
{
2017-03-24 05:18:30 +00:00
tm_execute_tm_service(
&mme_self()->tm_service, mme_self()->queue_id);
2017-02-13 04:19:53 +00:00
prev_tm = now_tm;
}
2017-03-27 01:22:30 +00:00
if (rv == CORE_TIMEUP)
2017-02-13 04:19:53 +00:00
{
continue;
}
2017-04-11 00:32:34 +00:00
fsm_dispatch(&mme_sm, (fsm_event_t*)&event);
2017-02-13 04:19:53 +00:00
}
2017-04-11 00:32:34 +00:00
fsm_final(&mme_sm, 0);
fsm_clear(&mme_sm);
2017-02-13 04:19:53 +00:00
2017-03-06 08:55:50 +00:00
event_delete(mme_self()->queue_id);
2017-02-13 04:19:53 +00:00
return NULL;
}
2017-08-02 12:11:22 +00:00
static void *THREAD_FUNC net_main(thread_id id, void *data)
2017-02-13 04:19:53 +00:00
{
while (!thread_should_stop())
{
net_fds_read_run(50);
}
return NULL;
}