2019-06-11 09:28:25 +00:00
|
|
|
#include "gtp/gtp-xact.h"
|
2017-11-30 11:13:15 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
#include "app/context.h"
|
2019-06-11 13:10:47 +00:00
|
|
|
#include "pgw-context.h"
|
|
|
|
#include "pgw-event.h"
|
|
|
|
#include "pgw-sm.h"
|
2017-03-30 15:15:13 +00:00
|
|
|
|
2019-06-11 13:10:47 +00:00
|
|
|
#include "pgw-fd-path.h"
|
2017-08-16 14:40:35 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
static ogs_thread_t *thread;
|
|
|
|
static void pgw_main(void *data);
|
2017-03-30 15:15:13 +00:00
|
|
|
|
2017-08-02 15:11:09 +00:00
|
|
|
static int initialized = 0;
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
int pgw_initialize()
|
2017-03-30 15:15:13 +00:00
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
int rv;
|
2017-03-30 15:15:13 +00:00
|
|
|
|
2019-05-06 11:43:50 +00:00
|
|
|
pgw_context_init();
|
|
|
|
pgw_event_init();
|
|
|
|
|
|
|
|
rv = gtp_xact_init(pgw_self()->timer_mgr);
|
2019-04-27 14:54:30 +00:00
|
|
|
if (rv != OGS_OK) return rv;
|
2017-03-30 15:15:13 +00:00
|
|
|
|
2017-07-17 10:04:10 +00:00
|
|
|
rv = pgw_context_parse_config();
|
2019-04-27 14:54:30 +00:00
|
|
|
if (rv != OGS_OK) return rv;
|
2017-07-17 10:04:10 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
rv = context_setup_log_module();
|
|
|
|
if (rv != OGS_OK) return rv;
|
2017-12-12 14:50:38 +00:00
|
|
|
|
|
|
|
rv = pgw_ue_pool_generate();
|
2019-04-27 14:54:30 +00:00
|
|
|
if (rv != OGS_OK) return rv;
|
2017-07-31 13:35:25 +00:00
|
|
|
|
2018-01-10 03:45:58 +00:00
|
|
|
rv = pgw_fd_init();
|
2019-04-27 14:54:30 +00:00
|
|
|
if (rv != 0) return OGS_ERROR;
|
2017-08-16 14:40:35 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
thread = ogs_thread_create(pgw_main, NULL);
|
|
|
|
if (!thread) return OGS_ERROR;
|
2017-03-30 15:15:13 +00:00
|
|
|
|
2017-08-02 15:11:09 +00:00
|
|
|
initialized = 1;
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_OK;
|
2017-03-30 15:15:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pgw_terminate(void)
|
|
|
|
{
|
2017-08-02 15:11:09 +00:00
|
|
|
if (!initialized) return;
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
pgw_event_term();
|
|
|
|
|
|
|
|
ogs_thread_destroy(thread);
|
2017-03-30 15:15:13 +00:00
|
|
|
|
2017-08-22 15:51:57 +00:00
|
|
|
pgw_fd_final();
|
2017-08-16 14:40:35 +00:00
|
|
|
|
2017-04-06 11:44:52 +00:00
|
|
|
pgw_context_final();
|
2017-04-11 13:44:57 +00:00
|
|
|
|
|
|
|
gtp_xact_final();
|
2019-04-27 14:54:30 +00:00
|
|
|
|
|
|
|
pgw_event_final();
|
2017-03-30 15:15:13 +00:00
|
|
|
}
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
static void pgw_main(void *data)
|
2017-03-30 15:15:13 +00:00
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_fsm_t pgw_sm;
|
|
|
|
int rv;
|
2017-03-30 15:15:13 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_fsm_create(&pgw_sm, pgw_state_initial, pgw_state_final);
|
|
|
|
ogs_fsm_init(&pgw_sm, 0);
|
2017-03-30 15:15:13 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
for ( ;; )
|
2017-03-30 15:15:13 +00:00
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_pollset_poll(pgw_self()->pollset,
|
|
|
|
ogs_timer_mgr_next(pgw_self()->timer_mgr));
|
2017-03-30 15:15:13 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_timer_mgr_expire(pgw_self()->timer_mgr);
|
2017-03-30 15:15:13 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
for ( ;; )
|
|
|
|
{
|
|
|
|
pgw_event_t *e = NULL;
|
2017-03-30 15:15:13 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
rv = ogs_queue_trypop(pgw_self()->queue, (void**)&e);
|
|
|
|
ogs_assert(rv != OGS_ERROR);
|
2017-03-30 15:15:13 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
if (rv == OGS_DONE)
|
|
|
|
goto done;
|
2017-03-30 15:15:13 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
if (rv == OGS_RETRY)
|
|
|
|
break;
|
2017-03-30 15:15:13 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(e);
|
|
|
|
ogs_fsm_dispatch(&pgw_sm, e);
|
|
|
|
pgw_event_free(e);
|
|
|
|
}
|
2017-03-30 15:15:13 +00:00
|
|
|
}
|
2019-04-27 14:54:30 +00:00
|
|
|
done:
|
2017-03-30 15:15:13 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_fsm_fini(&pgw_sm, 0);
|
|
|
|
ogs_fsm_delete(&pgw_sm);
|
2017-03-30 15:15:13 +00:00
|
|
|
}
|