/* * Copyright (C) 2019 by Sukchan Lee * * 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 . */ #include "test-app.h" #include "test-fd-path.h" int parse_config(void); abts_suite *test_epdg(abts_suite *suite); const struct testlist { abts_suite *(*func)(abts_suite *suite); } alltests[] = { {test_epdg}, {NULL}, }; static void terminate(void) { ogs_msleep(50); test_child_terminate(); app_terminate(); test_fd_final(); test_epc_final(); ogs_gtp_node_remove_all(&test_self()->gtpc_list); ogs_gtp_context_final(); ogs_gtp_xact_final(); ogs_app_terminate(); } static void initialize(const char *const argv[]) { int rv; rv = ogs_app_initialize(NULL, NULL, argv); ogs_assert(rv == OGS_OK); ogs_gtp_context_init(OGS_MAX_NUM_OF_GTPU_RESOURCE); rv = ogs_gtp_xact_init(); ogs_assert(rv == OGS_OK); test_epc_init(); rv = test_fd_init(); ogs_assert(rv == OGS_OK); rv = app_initialize(argv); ogs_assert(rv == OGS_OK); } int main(int argc, const char *const argv[]) { int i; int rc; abts_suite *suite = NULL; atexit(terminate); test_app_run(argc, argv, "non3gpp.yaml", initialize); parse_config(); for (i = 0; alltests[i].func; i++) suite = alltests[i].func(suite); return abts_report(suite); } static int prepare(void) { test_self()->gtpc_port = OGS_GTPV2_C_UDP_PORT; return OGS_OK; } static int validation(void) { return OGS_OK; } int parse_config(void) { int rv; yaml_document_t *document = NULL; ogs_yaml_iter_t root_iter; document = ogs_app()->document; ogs_assert(document); rv = prepare(); if (rv != OGS_OK) return rv; ogs_yaml_iter_init(&root_iter, document); while (ogs_yaml_iter_next(&root_iter)) { const char *root_key = ogs_yaml_iter_key(&root_iter); ogs_assert(root_key); if (!strcmp(root_key, "smf")) { ogs_yaml_iter_t smf_iter; ogs_yaml_iter_recurse(&root_iter, &smf_iter); while (ogs_yaml_iter_next(&smf_iter)) { const char *smf_key = ogs_yaml_iter_key(&smf_iter); ogs_assert(smf_key); if (!strcmp(smf_key, "gtpc")) { ogs_yaml_iter_t gtpc_iter; ogs_yaml_iter_recurse(&smf_iter, >pc_iter); while (ogs_yaml_iter_next(>pc_iter)) { const char *gtpc_key = ogs_yaml_iter_key(>pc_iter); ogs_assert(gtpc_key); if (!strcmp(gtpc_key, "server")) { ogs_yaml_iter_t server_array, server_iter; ogs_yaml_iter_recurse(>pc_iter, &server_array); do { int family = AF_UNSPEC; int i, num = 0; const char *hostname[OGS_MAX_NUM_OF_HOSTNAME]; uint16_t port = test_self()->gtpc_port; ogs_sockaddr_t *addr = NULL; if (ogs_yaml_iter_type(&server_array) == YAML_MAPPING_NODE) { memcpy(&server_iter, &server_array, sizeof(ogs_yaml_iter_t)); } else if (ogs_yaml_iter_type(&server_array) == YAML_SEQUENCE_NODE) { if (!ogs_yaml_iter_next(&server_array)) break; ogs_yaml_iter_recurse( &server_array, &server_iter); } else if (ogs_yaml_iter_type(&server_array) == YAML_SCALAR_NODE) { break; } else ogs_assert_if_reached(); while (ogs_yaml_iter_next(&server_iter)) { const char *server_key = ogs_yaml_iter_key(&server_iter); ogs_assert(server_key); if (!strcmp(server_key, "family")) { const char *v = ogs_yaml_iter_value(&server_iter); if (v) family = atoi(v); if (family != AF_UNSPEC && family != AF_INET && family != AF_INET6) { ogs_warn("Ignore family(%d) : " "AF_UNSPEC(%d), " "AF_INET(%d), AF_INET6(%d) ", family, AF_UNSPEC, AF_INET, AF_INET6); family = AF_UNSPEC; } } else if (!strcmp(server_key, "address")) { ogs_yaml_iter_t hostname_iter; ogs_yaml_iter_recurse(&server_iter, &hostname_iter); ogs_assert(ogs_yaml_iter_type( &hostname_iter) != YAML_MAPPING_NODE); do { if (ogs_yaml_iter_type( &hostname_iter) == YAML_SEQUENCE_NODE) { if (!ogs_yaml_iter_next( &hostname_iter)) break; } ogs_assert(num < OGS_MAX_NUM_OF_HOSTNAME); hostname[num++] = ogs_yaml_iter_value( &hostname_iter); } while (ogs_yaml_iter_type( &hostname_iter) == YAML_SEQUENCE_NODE); } else if (!strcmp(server_key, "port")) { const char *v = ogs_yaml_iter_value(&server_iter); if (v) port = atoi(v); } else ogs_warn("unknown key `%s`", server_key); } addr = NULL; for (i = 0; i < num; i++) { rv = ogs_addaddrinfo(&addr, family, hostname[i], port, 0); ogs_assert(rv == OGS_OK); } ogs_filter_ip_version(&addr, ogs_global_conf()->parameter. no_ipv4, #if 0 /* Only IPv4 is supporeted in Test-GTPv2C */ ogs_global_conf()->parameter. no_ipv6, #else 1, #endif ogs_global_conf()->parameter. prefer_ipv4); if (addr == NULL) continue; ogs_gtp_node_add_by_addr( &test_self()->gtpc_list, addr); ogs_freeaddrinfo(addr); } while (ogs_yaml_iter_type(&server_array) == YAML_SEQUENCE_NODE); } } } } } } rv = validation(); if (rv != OGS_OK) return rv; return OGS_OK; }