2019-10-27 08:41:14 +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-09-13 12:07:47 +00:00
|
|
|
#include "ogs-sctp.h"
|
2019-10-27 08:41:14 +00:00
|
|
|
|
|
|
|
#include "test-epc.h"
|
|
|
|
#include "test-config-private.h"
|
|
|
|
|
|
|
|
#define MAX_CHILD_PROCESS 8
|
|
|
|
#define OGS_ARG_MAX 256
|
2017-07-11 09:44:59 +00:00
|
|
|
|
2019-08-25 11:15:20 +00:00
|
|
|
static ogs_thread_t *pcrf_thread = NULL;
|
|
|
|
static ogs_thread_t *pgw_thread = NULL;
|
|
|
|
static ogs_thread_t *sgw_thread = NULL;
|
|
|
|
static ogs_thread_t *hss_thread = NULL;
|
2017-08-17 05:15:08 +00:00
|
|
|
|
2019-08-25 11:15:20 +00:00
|
|
|
static ogs_proc_t process[MAX_CHILD_PROCESS];
|
|
|
|
static int process_num = 0;
|
2017-07-11 09:44:59 +00:00
|
|
|
|
2019-08-25 11:15:20 +00:00
|
|
|
static void child_main(void *data)
|
|
|
|
{
|
2019-10-27 08:41:14 +00:00
|
|
|
const char **commandLine = data;
|
2019-08-25 11:15:20 +00:00
|
|
|
ogs_proc_t *current = NULL;
|
|
|
|
FILE *out = NULL;
|
|
|
|
char buf[OGS_HUGE_LEN];
|
|
|
|
int ret = 0, out_return_code = 0;;
|
|
|
|
|
|
|
|
current = &process[process_num++];
|
2019-10-27 08:41:14 +00:00
|
|
|
ret = ogs_proc_create(commandLine,
|
2019-08-25 11:15:20 +00:00
|
|
|
ogs_proc_option_combined_stdout_stderr|
|
|
|
|
ogs_proc_option_inherit_environment,
|
|
|
|
current);
|
|
|
|
ogs_assert(ret == 0);
|
|
|
|
out = ogs_proc_stdout(current);
|
|
|
|
ogs_assert(out);
|
|
|
|
|
|
|
|
while(fgets(buf, OGS_HUGE_LEN, out)) {
|
|
|
|
printf("%s", buf);
|
|
|
|
}
|
2017-08-02 12:11:22 +00:00
|
|
|
|
2019-08-25 11:15:20 +00:00
|
|
|
ret = ogs_proc_join(current, &out_return_code);
|
|
|
|
ogs_assert(ret == 0);
|
|
|
|
ogs_assert(out_return_code == 0);
|
2017-07-11 09:44:59 +00:00
|
|
|
|
2019-08-25 11:15:20 +00:00
|
|
|
ret = ogs_proc_destroy(current);
|
|
|
|
ogs_assert(ret == 0);
|
2019-04-27 14:54:30 +00:00
|
|
|
}
|
2017-07-11 09:44:59 +00:00
|
|
|
|
2019-10-27 08:41:14 +00:00
|
|
|
ogs_thread_t *test_child_create(const char *name, const char *const argv[])
|
2019-04-27 14:54:30 +00:00
|
|
|
{
|
2019-08-25 11:15:20 +00:00
|
|
|
ogs_thread_t *child = NULL;
|
2019-10-27 08:41:14 +00:00
|
|
|
const char *commandLine[OGS_ARG_MAX];
|
2019-08-25 11:15:20 +00:00
|
|
|
int i = 0;
|
2019-09-13 12:07:47 +00:00
|
|
|
char command[OGS_MAX_FILEPATH_LEN];
|
2019-08-25 11:15:20 +00:00
|
|
|
|
|
|
|
while(argv[i] && i < 32) {
|
|
|
|
commandLine[i] = argv[i];
|
|
|
|
i++;
|
2017-08-17 05:15:08 +00:00
|
|
|
}
|
2019-08-25 11:15:20 +00:00
|
|
|
commandLine[i] = NULL;
|
2017-08-17 05:15:08 +00:00
|
|
|
|
2019-10-27 08:41:14 +00:00
|
|
|
/* buildroot/src/mme/open5gs-mmed */
|
|
|
|
ogs_snprintf(command, sizeof command, "%s%s%s%sd",
|
|
|
|
MESON_BUILD_ROOT OGS_DIR_SEPARATOR_S "src" OGS_DIR_SEPARATOR_S,
|
|
|
|
name, OGS_DIR_SEPARATOR_S "open5gs-", name);
|
2019-08-25 11:15:20 +00:00
|
|
|
commandLine[0] = command;
|
2017-08-17 05:15:08 +00:00
|
|
|
|
2019-10-27 08:41:14 +00:00
|
|
|
child = ogs_thread_create(child_main, commandLine);
|
2019-08-25 11:15:20 +00:00
|
|
|
ogs_msleep(50);
|
2017-08-04 12:29:49 +00:00
|
|
|
|
2019-08-25 11:15:20 +00:00
|
|
|
return child;
|
|
|
|
}
|
2017-08-04 12:29:49 +00:00
|
|
|
|
2019-10-27 08:41:14 +00:00
|
|
|
void test_child_terminate(void)
|
2019-08-25 11:15:20 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
ogs_proc_t *current = NULL;
|
|
|
|
for (i = 0; i < process_num; i++) {
|
|
|
|
current = &process[i];
|
|
|
|
ogs_proc_terminate(current);
|
2017-08-03 10:50:20 +00:00
|
|
|
}
|
2019-08-25 11:15:20 +00:00
|
|
|
}
|
2017-07-11 09:44:59 +00:00
|
|
|
|
2019-10-27 08:41:14 +00:00
|
|
|
int app_initialize(const char *const argv[])
|
2019-08-25 11:15:20 +00:00
|
|
|
{
|
|
|
|
int rv;
|
2017-08-04 12:29:49 +00:00
|
|
|
|
2019-10-27 08:41:14 +00:00
|
|
|
const char *argv_out[OGS_ARG_MAX];
|
|
|
|
bool user_config = false;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
for (i = 0; argv[i]; i++) {
|
|
|
|
if (strcmp("-c", argv[i]) == 0) {
|
|
|
|
user_config = true;
|
|
|
|
}
|
|
|
|
argv_out[i] = argv[i];
|
|
|
|
}
|
|
|
|
argv_out[i] = NULL;
|
|
|
|
|
|
|
|
if (!user_config) {
|
|
|
|
argv_out[i++] = "-c";
|
|
|
|
argv_out[i++] = DEFAULT_CONFIG_FILENAME;
|
|
|
|
argv_out[i] = NULL;
|
|
|
|
}
|
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
if (ogs_config()->parameter.no_pcrf == 0)
|
2019-10-27 08:41:14 +00:00
|
|
|
pcrf_thread = test_child_create("pcrf", argv_out);
|
2019-09-13 12:07:47 +00:00
|
|
|
if (ogs_config()->parameter.no_pgw == 0)
|
2019-10-27 08:41:14 +00:00
|
|
|
pgw_thread = test_child_create("pgw", argv_out);
|
2019-09-13 12:07:47 +00:00
|
|
|
if (ogs_config()->parameter.no_sgw == 0)
|
2019-10-27 08:41:14 +00:00
|
|
|
sgw_thread = test_child_create("sgw", argv_out);
|
2019-09-13 12:07:47 +00:00
|
|
|
if (ogs_config()->parameter.no_hss == 0)
|
2019-10-27 08:41:14 +00:00
|
|
|
hss_thread = test_child_create("hss", argv_out);
|
2017-08-02 12:11:22 +00:00
|
|
|
|
2019-09-13 12:07:47 +00:00
|
|
|
ogs_sctp_init(ogs_config()->usrsctp.udp_port);
|
|
|
|
|
2017-08-04 12:29:49 +00:00
|
|
|
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-04-27 14:54:30 +00:00
|
|
|
return OGS_OK;;
|
2017-08-02 12:11:22 +00:00
|
|
|
}
|
|
|
|
|
2019-08-25 11:15:20 +00:00
|
|
|
void app_terminate(void)
|
2017-08-02 12:11:22 +00:00
|
|
|
{
|
2017-08-04 12:29:49 +00:00
|
|
|
mme_terminate();
|
2019-09-13 12:07:47 +00:00
|
|
|
|
2019-06-18 08:38:25 +00:00
|
|
|
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-08-25 11:15:20 +00:00
|
|
|
if (hss_thread) ogs_thread_destroy(hss_thread);
|
|
|
|
if (sgw_thread) ogs_thread_destroy(sgw_thread);
|
|
|
|
if (pgw_thread) ogs_thread_destroy(pgw_thread);
|
|
|
|
if (pcrf_thread) ogs_thread_destroy(pcrf_thread);
|
2017-07-11 09:44:59 +00:00
|
|
|
}
|