open5gs/src/mme/mme-init.c

160 lines
3.8 KiB
C
Raw Normal View History

2019-07-11 12:53:54 +00:00
/*
* Copyright (C) 2019-2023 by Sukchan Lee <acetcom@gmail.com>
2019-07-11 12:53:54 +00:00
*
* 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-05-31 05:05:45 +00:00
#include "ogs-sctp.h"
2019-09-13 12:07:47 +00:00
#include "ogs-gtp.h"
2019-04-27 14:54:30 +00:00
2019-06-11 13:10:47 +00:00
#include "mme-context.h"
#include "mme-sm.h"
#include "mme-event.h"
2019-07-20 02:20:09 +00:00
#include "mme-timer.h"
2017-02-13 00:58:55 +00:00
2019-06-11 13:10:47 +00:00
#include "mme-fd-path.h"
#include "s1ap-path.h"
#include "sgsap-path.h"
#include "mme-gtp-path.h"
2022-06-08 21:23:51 +00:00
#include "metrics.h"
2017-03-04 15:20:09 +00:00
2019-04-27 14:54:30 +00:00
static ogs_thread_t *thread;
static void mme_main(void *data);
2017-02-02 11:34:37 +00:00
static int initialized = 0;
2023-04-04 12:53:39 +00:00
int mme_initialize(void)
2017-02-02 11:34:37 +00:00
{
2019-04-27 14:54:30 +00:00
int rv;
#define APP_NAME "mme"
rv = ogs_app_parse_local_conf(APP_NAME);
if (rv != OGS_OK) return rv;
mme_metrics_init();
2021-03-15 01:01:55 +00:00
ogs_gtp_context_init(OGS_MAX_NUM_OF_GTPU_RESOURCE);
2019-05-06 11:43:50 +00:00
mme_context_init();
rv = ogs_gtp_xact_init();
2019-04-27 14:54:30 +00:00
if (rv != OGS_OK) return rv;
2017-02-26 12:16:03 +00:00
rv = ogs_gtp_context_parse_config(APP_NAME, "sgwc");
2021-03-15 01:01:55 +00:00
if (rv != OGS_OK) return rv;
rv = ogs_metrics_context_parse_config(APP_NAME);
2022-06-08 21:23:51 +00:00
if (rv != OGS_OK) return rv;
2017-07-14 10:00:26 +00:00
rv = mme_context_parse_config();
2019-04-27 14:54:30 +00:00
if (rv != OGS_OK) return rv;
2017-07-14 10:00:26 +00:00
rv = ogs_log_config_domain(
ogs_app()->logger.domain, ogs_app()->logger.level);
2019-04-27 14:54:30 +00:00
if (rv != OGS_OK) return rv;
2017-07-31 13:35:25 +00:00
ogs_metrics_context_open(ogs_metrics_self());
2018-01-10 05:15:00 +00:00
rv = mme_fd_init();
2019-04-27 14:54:30 +00:00
if (rv != OGS_OK) return OGS_ERROR;
2017-02-27 04:56:13 +00:00
rv = mme_gtp_open();
if (rv != OGS_OK) return OGS_ERROR;
rv = sgsap_open();
if (rv != OGS_OK) return OGS_ERROR;
rv = s1ap_open();
if (rv != OGS_OK) return OGS_ERROR;
2019-04-27 14:54:30 +00:00
thread = ogs_thread_create(mme_main, NULL);
if (!thread) return OGS_ERROR;
initialized = 1;
2017-03-04 14:48:04 +00:00
2019-04-27 14:54:30 +00:00
return OGS_OK;
2017-02-02 11:34:37 +00:00
}
2017-03-04 14:48:04 +00:00
void mme_terminate(void)
2017-02-02 11:34:37 +00:00
{
if (!initialized) return;
2019-04-27 14:54:30 +00:00
mme_event_term();
ogs_thread_destroy(thread);
2017-03-04 14:48:04 +00:00
mme_gtp_close();
sgsap_close();
s1ap_close();
ogs_metrics_context_close(ogs_metrics_self());
2017-08-25 11:31:08 +00:00
mme_fd_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
2021-03-15 01:01:55 +00:00
ogs_gtp_context_final();
2019-09-13 12:07:47 +00:00
ogs_gtp_xact_final();
2022-06-08 21:23:51 +00:00
mme_metrics_final();
2017-02-02 11:34:37 +00:00
}
2017-02-13 04:19:53 +00:00
2019-04-27 14:54:30 +00:00
static void mme_main(void *data)
2017-02-13 04:19:53 +00:00
{
2019-04-27 14:54:30 +00:00
ogs_fsm_t mme_sm;
int rv;
2017-02-13 04:19:53 +00:00
ogs_fsm_init(&mme_sm, mme_state_initial, mme_state_final, 0);
2017-02-13 04:19:53 +00:00
2019-07-11 12:53:54 +00:00
for ( ;; ) {
ogs_pollset_poll(ogs_app()->pollset,
ogs_timer_mgr_next(ogs_app()->timer_mgr));
2017-02-13 04:19:53 +00:00
2020-07-14 01:53:41 +00:00
/*
* After ogs_pollset_poll(), ogs_timer_mgr_expire() must be called.
*
2020-07-14 01:53:41 +00:00
* The reason is why ogs_timer_mgr_next() can get the corrent value
* when ogs_timer_stop() is called internally in ogs_timer_mgr_expire().
*
* You should not use event-queue before ogs_timer_mgr_expire().
* In this case, ogs_timer_mgr_expire() does not work
* because 'if rv == OGS_DONE' statement is exiting and
* not calling ogs_timer_mgr_expire().
*/
ogs_timer_mgr_expire(ogs_app()->timer_mgr);
2017-02-13 04:19:53 +00:00
2019-07-11 12:53:54 +00:00
for ( ;; ) {
2019-04-27 14:54:30 +00:00
mme_event_t *e = NULL;
2017-02-13 04:19:53 +00:00
rv = ogs_queue_trypop(ogs_app()->queue, (void**)&e);
2019-04-27 14:54:30 +00:00
ogs_assert(rv != OGS_ERROR);
2017-02-13 04:19:53 +00:00
2019-04-27 14:54:30 +00:00
if (rv == OGS_DONE)
goto done;
2017-02-13 04:19:53 +00:00
2019-04-27 14:54:30 +00:00
if (rv == OGS_RETRY)
break;
2017-02-13 04:19:53 +00:00
2019-04-27 14:54:30 +00:00
ogs_assert(e);
ogs_fsm_dispatch(&mme_sm, e);
mme_event_free(e);
}
2017-02-13 04:19:53 +00:00
}
2019-04-27 14:54:30 +00:00
done:
2017-02-13 04:19:53 +00:00
2019-04-27 14:54:30 +00:00
ogs_fsm_fini(&mme_sm, 0);
2017-02-13 04:19:53 +00:00
}