open5gs/src/epc.c

273 lines
7.9 KiB
C
Raw Normal View History

#include "mme/ogs-sctp.h"
2019-04-27 14:54:30 +00:00
#include "app/context.h"
#include "app/application.h"
2018-08-14 08:28:22 +00:00
2019-06-11 09:28:25 +00:00
#include "app-init.h"
2017-07-11 09:44:59 +00:00
2019-04-27 14:54:30 +00:00
static ogs_proc_mutex_t *pcrf_sem1 = NULL;
static ogs_proc_mutex_t *pcrf_sem2 = NULL;
2017-08-17 05:15:08 +00:00
2019-04-27 14:54:30 +00:00
static ogs_proc_mutex_t *pgw_sem1 = NULL;
static ogs_proc_mutex_t *pgw_sem2 = NULL;
2017-07-11 09:44:59 +00:00
2019-04-27 14:54:30 +00:00
static ogs_proc_mutex_t *sgw_sem1 = NULL;
static ogs_proc_mutex_t *sgw_sem2 = NULL;
2017-08-02 12:11:22 +00:00
2019-04-27 14:54:30 +00:00
static ogs_proc_mutex_t *hss_sem1 = NULL;
static ogs_proc_mutex_t *hss_sem2 = NULL;
2017-07-11 09:44:59 +00:00
2019-04-27 14:54:30 +00:00
int app_initialize(app_param_t *param)
2017-07-11 09:44:59 +00:00
{
2019-04-27 14:54:30 +00:00
param->name = "epc";
return epc_initialize(param);
}
2017-07-11 09:44:59 +00:00
2019-04-27 14:54:30 +00:00
int epc_initialize(app_param_t *param)
{
pid_t pid;
int rv;
2017-07-11 09:44:59 +00:00
2019-04-27 14:54:30 +00:00
rv = app_will_initialize(param);
if (rv != OGS_OK) return rv;
2017-08-17 05:15:08 +00:00
/************************* PCRF Process **********************/
2019-04-27 14:54:30 +00:00
pcrf_sem1 = ogs_proc_mutex_create(0); /* copied to PCRF/PGW/SGW/HSS process */
pcrf_sem2 = ogs_proc_mutex_create(0); /* copied to PCRF/PGW/SGW/HSS process */
2017-08-17 05:15:08 +00:00
2019-04-27 14:54:30 +00:00
if (context_self()->config.parameter.no_pcrf == 0)
2017-08-17 05:15:08 +00:00
{
pid = fork();
2019-04-27 14:54:30 +00:00
ogs_assert(pid >= 0);
2017-08-17 05:15:08 +00:00
if (pid == 0)
{
2019-04-27 14:54:30 +00:00
ogs_info("PCRF try to initialize");
2017-08-17 05:15:08 +00:00
rv = pcrf_initialize();
2019-04-27 14:54:30 +00:00
ogs_assert(rv == OGS_OK);
ogs_info("PCRF initialize...done");
2017-08-17 05:15:08 +00:00
2019-04-27 14:54:30 +00:00
if (pcrf_sem1) ogs_proc_mutex_post(pcrf_sem1);
if (pcrf_sem2) ogs_proc_mutex_wait(pcrf_sem2);
2017-08-17 05:15:08 +00:00
2019-04-27 14:54:30 +00:00
if (rv == OGS_OK)
2017-08-17 05:15:08 +00:00
{
2019-04-27 14:54:30 +00:00
ogs_info("PCRF try to terminate");
2017-08-17 05:15:08 +00:00
pcrf_terminate();
2019-04-27 14:54:30 +00:00
ogs_info("PCRF terminate...done");
2017-08-17 05:15:08 +00:00
}
2019-04-27 14:54:30 +00:00
if (pcrf_sem1) ogs_proc_mutex_post(pcrf_sem1);
2017-08-17 05:15:08 +00:00
/* allocated from parent process */
2019-04-27 14:54:30 +00:00
if (pcrf_sem1) ogs_proc_mutex_delete(pcrf_sem1);
if (pcrf_sem2) ogs_proc_mutex_delete(pcrf_sem2);
2017-08-17 05:15:08 +00:00
context_final();
2019-04-27 14:54:30 +00:00
ogs_core_finalize();
2017-08-17 05:15:08 +00:00
_exit(EXIT_SUCCESS);
}
2019-04-27 14:54:30 +00:00
if (pcrf_sem1) ogs_proc_mutex_wait(pcrf_sem1);
2017-08-17 05:15:08 +00:00
}
/************************* PGW Process **********************/
2019-04-27 14:54:30 +00:00
pgw_sem1 = ogs_proc_mutex_create(0); /* copied to PGW/SGW/HSS process */
pgw_sem2 = ogs_proc_mutex_create(0); /* copied to PGW/SGW/HSS process */
2019-04-27 14:54:30 +00:00
if (context_self()->config.parameter.no_pgw == 0)
{
pid = fork();
2019-04-27 14:54:30 +00:00
ogs_assert(pid >= 0);
if (pid == 0)
{
2017-08-17 05:15:08 +00:00
/* allocated from parent process */
2019-04-27 14:54:30 +00:00
if (pcrf_sem1) ogs_proc_mutex_delete(pcrf_sem1);
if (pcrf_sem2) ogs_proc_mutex_delete(pcrf_sem2);
2017-08-17 05:15:08 +00:00
2019-04-27 14:54:30 +00:00
ogs_info("PGW try to initialize");
rv = pgw_initialize();
2019-04-27 14:54:30 +00:00
ogs_assert(rv == OGS_OK);
ogs_info("PGW initialize...done");
2019-04-27 14:54:30 +00:00
if (pgw_sem1) ogs_proc_mutex_post(pgw_sem1);
if (pgw_sem2) ogs_proc_mutex_wait(pgw_sem2);
2019-04-27 14:54:30 +00:00
if (rv == OGS_OK)
{
2019-04-27 14:54:30 +00:00
ogs_info("PGW try to terminate");
pgw_terminate();
2019-04-27 14:54:30 +00:00
ogs_info("PGW terminate...done");
}
2019-04-27 14:54:30 +00:00
if (pgw_sem1) ogs_proc_mutex_post(pgw_sem1);
2017-08-04 12:55:58 +00:00
/* allocated from parent process */
2019-04-27 14:54:30 +00:00
if (pgw_sem1) ogs_proc_mutex_delete(pgw_sem1);
if (pgw_sem2) ogs_proc_mutex_delete(pgw_sem2);
context_final();
2019-04-27 14:54:30 +00:00
ogs_core_finalize();
_exit(EXIT_SUCCESS);
}
2019-04-27 14:54:30 +00:00
if (pgw_sem1) ogs_proc_mutex_wait(pgw_sem1);
}
2017-07-11 09:44:59 +00:00
/************************* SGW Process **********************/
2019-04-27 14:54:30 +00:00
sgw_sem1 = ogs_proc_mutex_create(0); /* copied to SGW/HSS process */
sgw_sem2 = ogs_proc_mutex_create(0); /* copied to SGW/HSS process */
2019-04-27 14:54:30 +00:00
if (context_self()->config.parameter.no_sgw == 0)
{
pid = fork();
2019-04-27 14:54:30 +00:00
ogs_assert(pid >= 0);
2017-07-11 09:44:59 +00:00
if (pid == 0)
{
2017-08-04 12:55:58 +00:00
/* allocated from parent process */
2019-04-27 14:54:30 +00:00
if (pcrf_sem1) ogs_proc_mutex_delete(pcrf_sem1);
if (pcrf_sem2) ogs_proc_mutex_delete(pcrf_sem2);
if (pgw_sem1) ogs_proc_mutex_delete(pgw_sem1);
if (pgw_sem2) ogs_proc_mutex_delete(pgw_sem2);
2019-04-27 14:54:30 +00:00
ogs_info("SGW try to initialize");
rv = sgw_initialize();
2019-04-27 14:54:30 +00:00
ogs_assert(rv == OGS_OK);
ogs_info("SGW initialize...done");
2019-04-27 14:54:30 +00:00
if (sgw_sem1) ogs_proc_mutex_post(sgw_sem1);
if (sgw_sem2) ogs_proc_mutex_wait(sgw_sem2);
2019-04-27 14:54:30 +00:00
if (rv == OGS_OK)
{
2019-04-27 14:54:30 +00:00
ogs_info("SGW try to terminate");
sgw_terminate();
2019-04-27 14:54:30 +00:00
ogs_info("SGW terminate...done");
}
2019-04-27 14:54:30 +00:00
if (sgw_sem1) ogs_proc_mutex_post(sgw_sem1);
2017-08-04 12:55:58 +00:00
/* allocated from parent process */
2019-04-27 14:54:30 +00:00
if (sgw_sem1) ogs_proc_mutex_delete(sgw_sem1);
if (sgw_sem2) ogs_proc_mutex_delete(sgw_sem2);
context_final();
2019-04-27 14:54:30 +00:00
ogs_core_finalize();
_exit(EXIT_SUCCESS);
}
2019-04-27 14:54:30 +00:00
if (sgw_sem1) ogs_proc_mutex_wait(sgw_sem1);
}
2017-07-11 09:44:59 +00:00
/************************* HSS Process **********************/
2019-04-27 14:54:30 +00:00
hss_sem1 = ogs_proc_mutex_create(0); /* copied to HSS process */
hss_sem2 = ogs_proc_mutex_create(0); /* copied to HSS process */
2017-07-11 09:44:59 +00:00
2019-04-27 14:54:30 +00:00
if (context_self()->config.parameter.no_hss == 0)
{
pid = fork();
2019-04-27 14:54:30 +00:00
ogs_assert(pid >= 0);
2017-07-11 09:44:59 +00:00
if (pid == 0)
{
2017-08-04 12:55:58 +00:00
/* allocated from parent process */
2019-04-27 14:54:30 +00:00
if (pcrf_sem1) ogs_proc_mutex_delete(pcrf_sem1);
if (pcrf_sem2) ogs_proc_mutex_delete(pcrf_sem2);
if (pgw_sem1) ogs_proc_mutex_delete(pgw_sem1);
if (pgw_sem2) ogs_proc_mutex_delete(pgw_sem2);
if (sgw_sem1) ogs_proc_mutex_delete(sgw_sem1);
if (sgw_sem2) ogs_proc_mutex_delete(sgw_sem2);
ogs_info("HSS try to initialize");
rv = hss_initialize();
2019-04-27 14:54:30 +00:00
ogs_assert(rv == OGS_OK);
ogs_info("HSS initialize...done");
2017-07-11 09:44:59 +00:00
2019-04-27 14:54:30 +00:00
if (hss_sem1) ogs_proc_mutex_post(hss_sem1);
if (hss_sem2) ogs_proc_mutex_wait(hss_sem2);
2017-08-02 12:11:22 +00:00
2019-04-27 14:54:30 +00:00
if (rv == OGS_OK)
{
2019-04-27 14:54:30 +00:00
ogs_info("HSS try to terminate");
hss_terminate();
2019-04-27 14:54:30 +00:00
ogs_info("HSS terminate...done");
}
2017-08-02 12:11:22 +00:00
2019-04-27 14:54:30 +00:00
if (hss_sem1) ogs_proc_mutex_post(hss_sem1);
2017-08-02 12:11:22 +00:00
2019-04-27 14:54:30 +00:00
if (hss_sem1) ogs_proc_mutex_delete(hss_sem1);
if (hss_sem2) ogs_proc_mutex_delete(hss_sem2);
2017-08-02 12:11:22 +00:00
context_final();
2019-04-27 14:54:30 +00:00
ogs_core_finalize();
2017-08-02 12:11:22 +00:00
_exit(EXIT_SUCCESS);
}
2017-08-02 12:11:22 +00:00
2019-04-27 14:54:30 +00:00
if (hss_sem1) ogs_proc_mutex_wait(hss_sem1);
}
2017-08-02 12:11:22 +00:00
2019-04-27 14:54:30 +00:00
ogs_info("MME try to initialize");
ogs_sctp_init(context_self()->config.usrsctp.udp_port);
rv = mme_initialize();
2019-04-27 14:54:30 +00:00
ogs_assert(rv == OGS_OK);
ogs_info("MME initialize...done");
2017-08-02 12:11:22 +00:00
2019-06-18 06:32:01 +00:00
rv = app_did_initialize();
if (rv != OGS_OK) return rv;
2019-04-27 14:54:30 +00:00
return OGS_OK;;
2017-08-02 12:11:22 +00:00
}
2019-04-27 14:54:30 +00:00
void epc_terminate(void)
2017-08-02 12:11:22 +00:00
{
app_will_terminate();
2017-08-02 12:11:22 +00:00
2019-04-27 14:54:30 +00:00
ogs_info("MME try to terminate");
mme_terminate();
ogs_sctp_final();
2019-04-27 14:54:30 +00:00
ogs_info("MME terminate...done");
2017-08-02 12:11:22 +00:00
2019-04-27 14:54:30 +00:00
if (context_self()->config.parameter.no_hss == 0)
{
2019-04-27 14:54:30 +00:00
if (hss_sem2) ogs_proc_mutex_post(hss_sem2);
if (hss_sem1) ogs_proc_mutex_wait(hss_sem1);
}
2019-04-27 14:54:30 +00:00
if (hss_sem1) ogs_proc_mutex_delete(hss_sem1);
if (hss_sem2) ogs_proc_mutex_delete(hss_sem2);
2017-08-02 12:11:22 +00:00
2019-04-27 14:54:30 +00:00
if (context_self()->config.parameter.no_sgw == 0)
{
2019-04-27 14:54:30 +00:00
if (sgw_sem2) ogs_proc_mutex_post(sgw_sem2);
if (sgw_sem1) ogs_proc_mutex_wait(sgw_sem1);
}
2019-04-27 14:54:30 +00:00
if (sgw_sem1) ogs_proc_mutex_delete(sgw_sem1);
if (sgw_sem2) ogs_proc_mutex_delete(sgw_sem2);
2017-08-02 12:11:22 +00:00
2019-04-27 14:54:30 +00:00
if (context_self()->config.parameter.no_pgw == 0)
{
2019-04-27 14:54:30 +00:00
if (pgw_sem2) ogs_proc_mutex_post(pgw_sem2);
if (pgw_sem1) ogs_proc_mutex_wait(pgw_sem1);
}
2019-04-27 14:54:30 +00:00
if (pgw_sem1) ogs_proc_mutex_delete(pgw_sem1);
if (pgw_sem2) ogs_proc_mutex_delete(pgw_sem2);
2019-04-27 14:54:30 +00:00
if (context_self()->config.parameter.no_pcrf == 0)
2017-08-17 05:15:08 +00:00
{
2019-04-27 14:54:30 +00:00
if (pcrf_sem2) ogs_proc_mutex_post(pcrf_sem2);
if (pcrf_sem1) ogs_proc_mutex_wait(pcrf_sem1);
2017-08-17 05:15:08 +00:00
}
2019-04-27 14:54:30 +00:00
if (pcrf_sem1) ogs_proc_mutex_delete(pcrf_sem1);
if (pcrf_sem2) ogs_proc_mutex_delete(pcrf_sem2);
2017-08-17 05:15:08 +00:00
app_did_terminate();
2017-07-11 09:44:59 +00:00
}