2019-07-11 13:09:30 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 by Sukchan Lee <acetcom@gmail.com>
|
|
|
|
*
|
|
|
|
* This file is part of Open5GS.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
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();
|
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
rv = ogs_gtp_xact_init(pgw_self()->timer_mgr, 512);
|
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-08-25 11:15:20 +00:00
|
|
|
rv = ogs_log_config_domain(
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_config()->logger.domain, ogs_config()->logger.level);
|
2019-04-27 14:54:30 +00:00
|
|
|
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
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_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-07-11 13:09:30 +00:00
|
|
|
for ( ;; ) {
|
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-07-20 22:01:45 +00:00
|
|
|
/* Process the MESSAGE FIRST.
|
|
|
|
*
|
|
|
|
* For example, if UE Context Release Complete is received,
|
|
|
|
* the MME_TIMER_UE_CONTEXT_RELEASE is first stopped */
|
|
|
|
for ( ;; ) {
|
|
|
|
pgw_event_t *e = NULL;
|
|
|
|
|
|
|
|
rv = ogs_queue_trypop(pgw_self()->queue, (void**)&e);
|
|
|
|
ogs_assert(rv != OGS_ERROR);
|
|
|
|
|
|
|
|
if (rv == OGS_DONE)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (rv == OGS_RETRY)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ogs_assert(e);
|
|
|
|
ogs_fsm_dispatch(&pgw_sm, e);
|
|
|
|
pgw_event_free(e);
|
|
|
|
}
|
|
|
|
|
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-07-20 22:01:45 +00:00
|
|
|
/* AND THEN, process the TIMER. */
|
2019-07-11 13:09:30 +00:00
|
|
|
for ( ;; ) {
|
2019-04-27 14:54:30 +00:00
|
|
|
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
|
|
|
}
|