update it

This commit is contained in:
Sukchan Lee 2017-08-02 21:11:22 +09:00
parent 13175e9e41
commit fae9cad5dc
7 changed files with 176 additions and 125 deletions

View File

@ -11,27 +11,12 @@
#include "core_semaphore.h"
#include "core_signal.h"
struct proc_stop_info {
pid_t proc;
semaphore_id semaphore;
};
pool_declare(proc_pool, proc_t, MAX_NUM_OF_PROC);
static struct proc_stop_info proc_stop_info;
int proc_should_stop(void)
{
return (proc_stop_info.proc == getpid());
}
status_t proc_init(void)
{
pool_init(&proc_pool, MAX_NUM_OF_PROC);
memset(&proc_stop_info, 0, sizeof(proc_stop_info));
semaphore_create(&proc_stop_info.semaphore, 0);
return CORE_OK;
}
@ -39,7 +24,6 @@ status_t proc_final(void)
{
pool_final(&proc_pool);
semaphore_delete(proc_stop_info.semaphore);
return CORE_OK;
}
@ -50,16 +34,12 @@ static void *dummy_worker(void *opaque)
proc->proc = getpid();
semaphore_post(proc->semaphore);
d_trace(3, "[%d] dummy_worker post semaphore\n", proc->proc);
d_trace(3, "[%d] dummy_worker post semaphore for creating\n", proc->proc);
if (!proc_should_stop())
func = proc->func((proc_id)proc, proc->data);
func = proc->func((proc_id)proc, proc->data);
d_trace(3, "[%d] proc stopped = %d\n",
proc->proc, proc_should_stop());
semaphore_post(proc_stop_info.semaphore);
d_trace(3, "[%d] post semaphore for proc_stop_info.semaphore\n",
proc->proc);
semaphore_post(proc->semaphore);
d_trace(3, "[%d] dummy_worker post semaphore for deleting\n", proc->proc);
return func;
}
@ -78,14 +58,11 @@ status_t proc_create(proc_id *id, proc_start_t func, void *data)
semaphore_create(&new->semaphore, 0);
d_trace_level(&_proc, 100);
new->proc = fork();
d_assert(new->proc >= 0, _exit(EXIT_FAILURE), "fork() failed");
if (new->proc == 0)
{
d_trace_level(&_proc, 100);
dummy_worker(new);
_exit(EXIT_SUCCESS);
@ -104,13 +81,13 @@ status_t proc_delete(proc_id id)
{
proc_t *proc = (proc_t *)id;
proc_stop_info.proc = proc->proc;
d_trace(3, "proc_stop_info.proc for %d\n", proc_stop_info.proc);
core_kill(proc_stop_info.proc, SIGTERM);
d_trace(3, "core_kill for %d\n", proc_stop_info.proc);
semaphore_wait(proc_stop_info.semaphore);
d_trace(3, "semaphore_wait done\n");
proc_stop_info.proc = 0;
d_trace(3, "core_kill for %d\n", proc->proc);
core_kill(proc->proc, SIGTERM);
d_trace(3, "core_kill done for %d\n", proc->proc);
d_trace(3, "proc_delete wait\n");
semaphore_wait(proc->semaphore);
d_trace(3, "proc_delete done\n");
semaphore_delete(proc->semaphore);
pool_free_node(&proc_pool, proc);

160
src/epc.c
View File

@ -3,52 +3,56 @@
#include "core_debug.h"
#include "core_signal.h"
#include "core_semaphore.h"
#include "core_proc.h"
#include "context.h"
#include "app.h"
static pid_t hss_pid = 0;
static proc_id pgw_proc;
static semaphore_id pgw_sem;
static void *PROC_FUNC pgw_main(proc_id id, void *data);
static int check_signal(int signum);
static proc_id sgw_proc;
static semaphore_id sgw_sem;
static void *PROC_FUNC sgw_main(proc_id id, void *data);
static proc_id hss_proc;
static semaphore_id hss_sem;
static void *PROC_FUNC hss_main(proc_id id, void *data);
status_t app_initialize(char *config_path, char *log_path)
{
status_t rv;
semaphore_id semaphore;
int others = 0;
rv = app_will_initialize(config_path, log_path);
if (rv != CORE_OK) return rv;
d_assert(semaphore_create(&semaphore, 0) == CORE_OK,
return rv, "semaphore_create() failed");
hss_pid = fork();
d_assert(hss_pid >= 0, _exit(EXIT_FAILURE), "fork() failed");
if (hss_pid == 0)
others = context_self()->trace_level.others;
if (others)
{
/* Child */
d_assert(semaphore_wait(semaphore) == CORE_OK,
_exit(EXIT_FAILURE), "semaphore_wait() failed");
d_assert(semaphore_delete(semaphore) == CORE_OK,
_exit(EXIT_FAILURE), "semaphore_delete() failed");
rv = hss_initialize();
if (rv != CORE_OK) _exit(EXIT_FAILURE);
signal_thread(check_signal);
hss_terminate();
_exit(EXIT_SUCCESS);
d_trace_level(&_epc_main, others);
}
/* Parent */
rv = CORE_OK;
if (pgw_initialize() != CORE_OK) rv = CORE_ERROR;
if (sgw_initialize() != CORE_OK) rv = CORE_ERROR;
if (mme_initialize() != CORE_OK) rv = CORE_ERROR;
d_assert(semaphore_create(&pgw_sem, 0) == CORE_OK,
return CORE_ERROR, "semaphore_create() failed");
rv = proc_create(&pgw_proc, pgw_main, NULL);
if (rv != CORE_OK) return rv;
d_assert(semaphore_post(semaphore) == CORE_OK,,
"semaphore_post() failed");
d_assert(semaphore_create(&sgw_sem, 0) == CORE_OK,
return CORE_ERROR, "semaphore_create() failed");
rv = proc_create(&sgw_proc, sgw_main, NULL);
if (rv != CORE_OK) return rv;
d_assert(semaphore_create(&hss_sem, 0) == CORE_OK,
return CORE_ERROR, "semaphore_create() failed");
rv = proc_create(&hss_proc, hss_main, NULL);
if (rv != CORE_OK) return rv;
d_trace(1, "MME try to initialize\n");
rv = mme_initialize();
if (rv != CORE_OK) return rv;
d_trace(1, "MME initialize...done\n");
if (app_did_initialize(config_path, log_path) != CORE_OK) rv = CORE_ERROR;
@ -59,34 +63,84 @@ void app_terminate(void)
{
app_will_terminate();
if (hss_pid)
core_kill(hss_pid, SIGTERM);
d_trace(1, "MME try to terminate\n");
mme_terminate();
sgw_terminate();
pgw_terminate();
d_trace(1, "MME terminate...done\n");
d_assert(semaphore_post(hss_sem) == CORE_OK,,
"semaphore_post() failed");
proc_delete(hss_proc);
d_assert(semaphore_post(sgw_sem) == CORE_OK,,
"semaphore_post() failed");
proc_delete(sgw_proc);
d_assert(semaphore_post(pgw_sem) == CORE_OK,,
"semaphore_post() failed");
proc_delete(pgw_proc);
app_did_terminate();
}
static int check_signal(int signum)
static void *PROC_FUNC pgw_main(proc_id id, void *data)
{
switch (signum)
{
case SIGTERM:
case SIGINT:
{
d_info("%s received",
signum == SIGTERM ? "SIGTERM" : "SIGINT");
status_t rv;
return 1;
}
default:
{
d_error("Unknown signal number = %d\n", signum);
break;
}
}
return 0;
d_trace(1, "PGW try to initialize\n");
rv = pgw_initialize();
if (rv != CORE_OK) return NULL;
d_trace(1, "PGW initialize...done\n");
d_assert(semaphore_wait(pgw_sem) == CORE_OK, return NULL,
"semaphore_wait() failed");
d_assert(semaphore_delete(pgw_sem) == CORE_OK, return NULL,
"semaphore_delete() failed");
d_trace(1, "PGW try to terminate\n");
pgw_terminate();
d_trace(1, "PGW terminate...done\n");
return NULL;
}
static void *PROC_FUNC sgw_main(proc_id id, void *data)
{
status_t rv;
d_trace(1, "SGW try to initialize\n");
rv = sgw_initialize();
if (rv != CORE_OK) return NULL;
d_trace(1, "SGW initialize...done\n");
d_assert(semaphore_wait(sgw_sem) == CORE_OK, return NULL,
"semaphore_wait() failed");
d_assert(semaphore_delete(sgw_sem) == CORE_OK, return NULL,
"semaphore_delete() failed");
d_trace(1, "SGW try to terminate\n");
sgw_terminate();
d_trace(1, "SGW terminate...done\n");
return NULL;
}
static void *PROC_FUNC hss_main(proc_id id, void *data)
{
status_t rv;
d_trace(1, "HSS try to initialize\n");
rv = hss_initialize();
if (rv != CORE_OK) return NULL;
d_trace(1, "HSS initialize...done\n");
d_assert(semaphore_wait(hss_sem) == CORE_OK, return NULL,
"semaphore_wait() failed");
d_assert(semaphore_delete(hss_sem) == CORE_OK, return NULL,
"semaphore_delete() failed");
d_trace(1, "HSS try to terminate\n");
hss_terminate();
d_trace(1, "HSS terminate...done\n");
return NULL;
}

View File

@ -11,9 +11,6 @@
#include "app.h"
static pid_t logger_pid = 0;
static thread_id net_thread;
void *THREAD_FUNC net_main(thread_id id, void *data);
status_t app_will_initialize(char *config_path, char *log_path)
{
@ -50,11 +47,6 @@ status_t app_will_initialize(char *config_path, char *log_path)
status_t app_did_initialize(char *config_path, char *log_path)
{
status_t rv;
rv = thread_create(&net_thread, NULL, net_main, NULL);
if (rv != CORE_OK) return rv;
return CORE_OK;
}
@ -62,8 +54,6 @@ void app_will_terminate(void)
{
if (logger_pid)
core_kill(logger_pid, SIGTERM);
thread_delete(net_thread);
}
void app_did_terminate(void)
@ -73,13 +63,3 @@ void app_did_terminate(void)
core_terminate();
#endif
}
void *THREAD_FUNC net_main(thread_id id, void *data)
{
while (!thread_should_stop())
{
net_fds_read_run(50);
}
return NULL;
}

View File

@ -7,8 +7,11 @@
#include "mme_s6a_handler.h"
static thread_id mme_sm_thread;
void *THREAD_FUNC mme_sm_main(thread_id id, void *data);
static thread_id sm_thread;
static void *THREAD_FUNC sm_main(thread_id id, void *data);
static thread_id net_thread;
static void *THREAD_FUNC net_main(thread_id id, void *data);
status_t mme_initialize()
{
@ -27,7 +30,9 @@ status_t mme_initialize()
ret = mme_s6a_init();
if (ret != 0) return -1;
rv = thread_create(&mme_sm_thread, NULL, mme_sm_main, NULL);
rv = thread_create(&sm_thread, NULL, sm_main, NULL);
if (rv != CORE_OK) return rv;
rv = thread_create(&net_thread, NULL, net_main, NULL);
if (rv != CORE_OK) return rv;
return CORE_OK;
@ -35,7 +40,8 @@ status_t mme_initialize()
void mme_terminate(void)
{
thread_delete(mme_sm_thread);
thread_delete(net_thread);
thread_delete(sm_thread);
mme_s6a_final();
@ -44,7 +50,7 @@ void mme_terminate(void)
gtp_xact_final();
}
void *THREAD_FUNC mme_sm_main(thread_id id, void *data)
static void *THREAD_FUNC sm_main(thread_id id, void *data)
{
event_t event;
fsm_t mme_sm;
@ -99,7 +105,7 @@ void *THREAD_FUNC mme_sm_main(thread_id id, void *data)
return NULL;
}
void *THREAD_FUNC mme_net_main(thread_id id, void *data)
static void *THREAD_FUNC net_main(thread_id id, void *data)
{
while (!thread_should_stop())
{

View File

@ -6,8 +6,11 @@
#include "pgw_context.h"
#include "pgw_event.h"
static thread_id pgw_sm_thread;
void *THREAD_FUNC pgw_sm_main(thread_id id, void *data);
static thread_id sm_thread;
static void *THREAD_FUNC sm_main(thread_id id, void *data);
static thread_id net_thread;
static void *THREAD_FUNC net_main(thread_id id, void *data);
status_t pgw_initialize()
{
@ -25,7 +28,9 @@ status_t pgw_initialize()
rv = pgw_ip_pool_generate();
if (rv != CORE_OK) return rv;
rv = thread_create(&pgw_sm_thread, NULL, pgw_sm_main, NULL);
rv = thread_create(&sm_thread, NULL, sm_main, NULL);
if (rv != CORE_OK) return rv;
rv = thread_create(&net_thread, NULL, net_main, NULL);
if (rv != CORE_OK) return rv;
return CORE_OK;
@ -33,14 +38,15 @@ status_t pgw_initialize()
void pgw_terminate(void)
{
thread_delete(pgw_sm_thread);
thread_delete(net_thread);
thread_delete(sm_thread);
pgw_context_final();
gtp_xact_final();
}
void *THREAD_FUNC pgw_sm_main(thread_id id, void *data)
static void *THREAD_FUNC sm_main(thread_id id, void *data)
{
event_t event;
fsm_t pgw_sm;
@ -94,3 +100,13 @@ void *THREAD_FUNC pgw_sm_main(thread_id id, void *data)
return NULL;
}
static void *THREAD_FUNC net_main(thread_id id, void *data)
{
while (!thread_should_stop())
{
net_fds_read_run(50);
}
return NULL;
}

View File

@ -6,8 +6,11 @@
#include "sgw_context.h"
#include "sgw_event.h"
static thread_id sgw_sm_thread;
void *THREAD_FUNC sgw_sm_main(thread_id id, void *data);
static thread_id sm_thread;
static void *THREAD_FUNC sm_main(thread_id id, void *data);
static thread_id net_thread;
static void *THREAD_FUNC net_main(thread_id id, void *data);
status_t sgw_initialize()
{
@ -22,7 +25,9 @@ status_t sgw_initialize()
rv = sgw_context_setup_trace_module();
if (rv != CORE_OK) return rv;
rv = thread_create(&sgw_sm_thread, NULL, sgw_sm_main, NULL);
rv = thread_create(&sm_thread, NULL, sm_main, NULL);
if (rv != CORE_OK) return rv;
rv = thread_create(&net_thread, NULL, net_main, NULL);
if (rv != CORE_OK) return rv;
return CORE_OK;
@ -30,14 +35,15 @@ status_t sgw_initialize()
void sgw_terminate(void)
{
thread_delete(sgw_sm_thread);
thread_delete(net_thread);
thread_delete(sm_thread);
sgw_context_final();
gtp_xact_final();
}
void *THREAD_FUNC sgw_sm_main(thread_id id, void *data)
static void *THREAD_FUNC sm_main(thread_id id, void *data)
{
event_t event;
fsm_t sgw_sm;
@ -91,3 +97,13 @@ void *THREAD_FUNC sgw_sm_main(thread_id id, void *data)
return NULL;
}
static void *THREAD_FUNC net_main(thread_id id, void *data)
{
while (!thread_should_stop())
{
net_fds_read_run(50);
}
return NULL;
}

View File

@ -622,8 +622,8 @@ static void nas_sm_test3(abts_case *tc, void *data)
char *_initial_context_setup_request =
"00090080c8000006 00000005c0020000 c800080002000200 42000a183e800000"
"603e800000001800 7700003400724540 0920000000000000 00000f800a0123d8"
"000000035b27a23a 27b4020742024906 4000f1102b670032 5201c10509ffffff"
"ff0908696e746572 6e657405012d2d2d 035e060000000004 04270f80000d0408"
"000000015b27ac42 a95d020742024906 4000f1102b670032 5201c10509ffffff"
"ff0908696e746572 6e657405012d2d2d 015e060000000004 04270f80000d0408"
"080808000d040404 0404500bf600f110 0002010000000353 12172c5949640125"
"006b00051e000e00 000049002040964d eb63a0afb5d0d374 c1da505f6252d1f9"
"05ff9c6791b8503a 032c6effa7";
@ -891,8 +891,10 @@ abts_suite *test_nas_sm(abts_suite *suite)
{
suite = ADD_SUITE(suite)
#if 0
abts_run_test(suite, nas_sm_test1, NULL);
abts_run_test(suite, nas_sm_test2, NULL);
#endif
abts_run_test(suite, nas_sm_test3, NULL);
return suite;