open5gs/src/epc.c

220 lines
5.9 KiB
C
Raw Normal View History

2017-07-11 09:44:59 +00:00
#define TRACE_MODULE _epc_main
#include "core_general.h"
2017-07-11 09:44:59 +00:00
#include "core_debug.h"
#include "core_semaphore.h"
2017-08-02 12:11:22 +00:00
#include "context.h"
2017-07-11 14:38:52 +00:00
#include "app.h"
2017-07-11 09:44:59 +00:00
2017-08-04 12:55:58 +00:00
static semaphore_id pgw_sem1 = 0;
static semaphore_id pgw_sem2 = 0;
2017-07-11 09:44:59 +00:00
2017-08-04 12:55:58 +00:00
static semaphore_id sgw_sem1 = 0;
static semaphore_id sgw_sem2 = 0;
2017-08-02 12:11:22 +00:00
2017-08-04 12:55:58 +00:00
static semaphore_id hss_sem1 = 0;
static semaphore_id hss_sem2 = 0;
2017-07-11 09:44:59 +00:00
2017-07-11 14:38:52 +00:00
status_t app_initialize(char *config_path, char *log_path)
2017-07-11 09:44:59 +00:00
{
pid_t pid;
2017-07-11 09:44:59 +00:00
status_t rv;
2017-08-02 12:11:22 +00:00
int others = 0;
2017-07-11 09:44:59 +00:00
2017-07-12 12:25:10 +00:00
rv = app_will_initialize(config_path, log_path);
if (rv != CORE_OK) return rv;
2017-07-11 09:44:59 +00:00
2017-08-02 12:11:22 +00:00
others = context_self()->trace_level.others;
if (others)
2017-07-11 09:44:59 +00:00
{
2017-08-02 12:11:22 +00:00
d_trace_level(&_epc_main, others);
}
2017-07-11 09:44:59 +00:00
/************************* PGW Process **********************/
semaphore_create(&pgw_sem1, 0); /* copied to PGW/SGW/HSS process */
semaphore_create(&pgw_sem2, 0); /* copied to PGW/SGW/HSS process */
if (context_self()->hidden.disable_pgw == 0)
{
pid = fork();
d_assert(pid >= 0, _exit(EXIT_FAILURE), "fork() failed");
if (pid == 0)
{
d_trace(1, "PGW try to initialize\n");
rv = pgw_initialize();
d_assert(rv == CORE_OK,, "Failed to intialize PGW");
d_trace(1, "PGW initialize...done\n");
if (pgw_sem1) semaphore_post(pgw_sem1);
2017-08-04 12:55:58 +00:00
if (pgw_sem2) semaphore_wait(pgw_sem2);
if (rv == CORE_OK)
{
d_trace(1, "PGW try to terminate\n");
pgw_terminate();
d_trace(1, "PGW terminate...done\n");
}
2017-08-04 12:55:58 +00:00
if (pgw_sem1) semaphore_post(pgw_sem1);
2017-08-04 12:55:58 +00:00
/* allocated from parent process */
if (pgw_sem1) semaphore_delete(pgw_sem1);
if (pgw_sem2) semaphore_delete(pgw_sem2);
app_did_terminate();
core_terminate();
_exit(EXIT_SUCCESS);
}
2017-08-04 12:55:58 +00:00
if (pgw_sem1) semaphore_wait(pgw_sem1);
}
2017-07-11 09:44:59 +00:00
/************************* SGW Process **********************/
semaphore_create(&sgw_sem1, 0); /* copied to SGW/HSS process */
semaphore_create(&sgw_sem2, 0); /* copied to SGW/HSS process */
if (context_self()->hidden.disable_sgw == 0)
{
pid = fork();
d_assert(pid >= 0, _exit(EXIT_FAILURE), "fork() failed");
2017-07-11 09:44:59 +00:00
if (pid == 0)
{
2017-08-04 12:55:58 +00:00
/* allocated from parent process */
if (pgw_sem1) semaphore_delete(pgw_sem1);
if (pgw_sem2) semaphore_delete(pgw_sem2);
d_trace(1, "SGW try to initialize\n");
rv = sgw_initialize();
d_assert(rv == CORE_OK,, "Failed to intialize SGW");
d_trace(1, "SGW initialize...done\n");
if (sgw_sem1) semaphore_post(sgw_sem1);
2017-08-04 12:55:58 +00:00
if (sgw_sem2) semaphore_wait(sgw_sem2);
if (rv == CORE_OK)
{
d_trace(1, "SGW try to terminate\n");
sgw_terminate();
d_trace(1, "SGW terminate...done\n");
}
2017-08-04 12:55:58 +00:00
if (sgw_sem1) semaphore_post(sgw_sem1);
2017-08-04 12:55:58 +00:00
/* allocated from parent process */
if (sgw_sem1) semaphore_delete(sgw_sem1);
if (sgw_sem2) semaphore_delete(sgw_sem2);
app_did_terminate();
core_terminate();
_exit(EXIT_SUCCESS);
}
2017-08-04 12:55:58 +00:00
if (sgw_sem1) semaphore_wait(sgw_sem1);
}
2017-07-11 09:44:59 +00:00
/************************* HSS Process **********************/
2017-07-11 09:44:59 +00:00
semaphore_create(&hss_sem1, 0); /* copied to HSS process */
semaphore_create(&hss_sem2, 0); /* copied to HSS process */
2017-07-11 09:44:59 +00:00
if (context_self()->hidden.disable_hss == 0)
{
pid = fork();
d_assert(pid >= 0, _exit(EXIT_FAILURE), "fork() failed");
2017-07-11 09:44:59 +00:00
if (pid == 0)
{
2017-08-04 12:55:58 +00:00
/* allocated from parent process */
if (pgw_sem1) semaphore_delete(pgw_sem1);
if (pgw_sem2) semaphore_delete(pgw_sem2);
if (sgw_sem1) semaphore_delete(sgw_sem1);
if (sgw_sem2) semaphore_delete(sgw_sem2);
2017-08-02 12:11:22 +00:00
d_trace(1, "HSS try to initialize\n");
rv = hss_initialize();
d_assert(rv == CORE_OK,, "Failed to intialize HSS");
d_trace(1, "HSS initialize...done\n");
2017-07-11 09:44:59 +00:00
if (hss_sem1) semaphore_post(hss_sem1);
2017-08-04 12:55:58 +00:00
if (hss_sem2) semaphore_wait(hss_sem2);
2017-08-02 12:11:22 +00:00
if (rv == CORE_OK)
{
d_trace(1, "HSS try to terminate\n");
hss_terminate();
d_trace(1, "HSS terminate...done\n");
}
2017-08-02 12:11:22 +00:00
2017-08-04 12:55:58 +00:00
if (hss_sem1) semaphore_post(hss_sem1);
2017-08-02 12:11:22 +00:00
2017-08-04 12:55:58 +00:00
if (hss_sem1) semaphore_delete(hss_sem1);
if (hss_sem2) semaphore_delete(hss_sem2);
2017-08-02 12:11:22 +00:00
app_did_terminate();
2017-08-02 12:11:22 +00:00
core_terminate();
2017-08-02 12:11:22 +00:00
_exit(EXIT_SUCCESS);
}
2017-08-02 12:11:22 +00:00
2017-08-04 12:55:58 +00:00
if (hss_sem1) semaphore_wait(hss_sem1);
}
2017-08-02 12:11:22 +00:00
rv = app_did_initialize(config_path, log_path);
if (rv != CORE_OK) return rv;
d_trace(1, "MME try to initialize\n");
rv = mme_initialize();
d_assert(rv == CORE_OK, return rv, "Failed to intialize MME");
d_trace(1, "MME initialize...done\n");
2017-08-02 12:11:22 +00:00
return CORE_OK;;
2017-08-02 12:11:22 +00:00
}
void app_terminate(void)
2017-08-02 12:11:22 +00:00
{
app_will_terminate();
2017-08-02 12:11:22 +00:00
d_trace(1, "MME try to terminate\n");
mme_terminate();
d_trace(1, "MME terminate...done\n");
2017-08-02 12:11:22 +00:00
if (context_self()->hidden.disable_hss == 0)
{
2017-08-04 12:55:58 +00:00
if (hss_sem2) semaphore_post(hss_sem2);
if (hss_sem1) semaphore_wait(hss_sem1);
}
2017-08-04 12:55:58 +00:00
if (hss_sem1) semaphore_delete(hss_sem1);
if (hss_sem2) semaphore_delete(hss_sem2);
2017-08-02 12:11:22 +00:00
if (context_self()->hidden.disable_sgw == 0)
{
2017-08-04 12:55:58 +00:00
if (sgw_sem2) semaphore_post(sgw_sem2);
if (sgw_sem1) semaphore_wait(sgw_sem1);
}
2017-08-04 12:55:58 +00:00
if (sgw_sem1) semaphore_delete(sgw_sem1);
if (sgw_sem2) semaphore_delete(sgw_sem2);
2017-08-02 12:11:22 +00:00
if (context_self()->hidden.disable_pgw == 0)
{
2017-08-04 12:55:58 +00:00
if (pgw_sem2) semaphore_post(pgw_sem2);
if (pgw_sem1) semaphore_wait(pgw_sem1);
}
2017-08-04 12:55:58 +00:00
if (pgw_sem1) semaphore_delete(pgw_sem1);
if (pgw_sem2) semaphore_delete(pgw_sem2);
app_did_terminate();
2017-07-11 09:44:59 +00:00
}