open5gs/src/mme/mme_init.c

108 lines
2.2 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-02-21 07:16:35 +00:00
static thread_id mme_sm_thread;
void *THREAD_FUNC mme_sm_main(thread_id id, void *data);
2017-02-02 11:34:37 +00:00
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;
2017-02-27 12:29:32 +00:00
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-04-04 02:00:25 +00:00
ret = mme_s6a_init();
2017-03-04 15:20:09 +00:00
if (ret != 0) return -1;
2017-02-27 04:56:13 +00:00
2017-03-04 14:48:04 +00:00
rv = thread_create(&mme_sm_thread, NULL, mme_sm_main, NULL);
if (rv != CORE_OK) return rv;
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
{
2017-03-04 14:48:04 +00:00
thread_delete(mme_sm_thread);
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
void *THREAD_FUNC mme_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;
}
void *THREAD_FUNC mme_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;
}