Create CSFB test framework

This commit is contained in:
Sukchan Lee 2019-06-15 19:37:34 +09:00
parent 343c72b288
commit cb00bf848e
5 changed files with 551 additions and 2 deletions

View File

@ -214,6 +214,7 @@ AC_CONFIG_FILES([support/Makefile])
AC_CONFIG_FILES([tests/sample.conf])
AC_CONFIG_FILES([tests/sample-simple.conf])
AC_CONFIG_FILES([tests/sample-volte.conf])
AC_CONFIG_FILES([tests/sample-csfb.conf])
AC_CONFIG_FILES([tests/Makefile])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

View File

@ -1,9 +1,9 @@
## Process this file with automake to produce Makefile.in.
bin_PROGRAMS = testunit testsimple testcomplex testvolte
bin_PROGRAMS = testunit testsimple testcomplex testvolte testcsfb
configdir = ${sysconfdir}/nextepc/tests
config_DATA = sample.conf sample-simple.conf sample-volte.conf
config_DATA = sample.conf sample-simple.conf sample-volte.conf sample-csfb.conf
testunit_SOURCES = \
common/test-packet.h common/test-packet.c \
@ -38,6 +38,13 @@ testvolte_SOURCES = \
$(NULL)
testvolte_LDADD = $(top_srcdir)/src/libepc.la
testcsfb_SOURCES = \
common/test-packet.h common/test-packet.c \
csfb/abts-main.c \
csfb/csfb-test.c \
$(NULL)
testcsfb_LDADD = $(top_srcdir)/src/libepc.la
AM_CPPFLAGS = \
@OGSCORE_CFLAGS@ \
@MONGOC_CFLAGS@ \

151
tests/csfb/abts-main.c Normal file
View File

@ -0,0 +1,151 @@
/*
* 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/>.
*/
#include "ogs-core.h"
#include "core/abts.h"
#include "fd/fd-lib.h"
#include "app/application.h"
#include "app/context.h"
#include "app-init.h"
#include "test-packet.h"
abts_suite *test_csfb(abts_suite *suite);
const struct testlist {
abts_suite *(*func)(abts_suite *suite);
} alltests[] = {
{test_csfb},
{NULL},
};
static int connected_count = 0;
static void test_fd_logger_handler(enum fd_hook_type type, struct msg * msg,
struct peer_hdr * peer, void * other, struct fd_hook_permsgdata *pmd,
void * regdata)
{
if (type == HOOK_PEER_CONNECT_SUCCESS) {
connected_count++;
}
}
void test_terminate(void)
{
ogs_msleep(50);
testpacket_final();
epc_terminate();
base_finalize();
ogs_core_finalize();
}
int test_initialize(app_param_t *param, int argc, const char *const argv[])
{
int rv;
fd_logger_register(test_fd_logger_handler);
atexit(test_terminate);
ogs_core_initialize();
base_initialize();
rv = epc_initialize(param);
if (rv != OGS_OK) {
ogs_error("app_initialize() failed");
return OGS_ERROR;
}
rv = testpacket_init();
if (rv != OGS_OK) {
ogs_error("testpacket() failed");
return OGS_ERROR;
}
while(1) {
if (connected_count == 1) break;
ogs_msleep(50);
}
return rv;
}
int main(int argc, const char **argv)
{
int i;
app_param_t param;
const char *debug_mask = NULL;
const char *trace_mask = NULL;
char config_dir[MAX_FILEPATH_LEN/2];
char config_path[MAX_FILEPATH_LEN];
abts_suite *suite = NULL;
abts_init(argc, argv);
memset(&param, 0, sizeof(param));
for (i = 1; i < argc; i++) {
/* abts_init(argc, argv) handles the following options */
if (!strcmp(argv[i], "-v")) continue;
if (!strcmp(argv[i], "-x")) continue;
if (!strcmp(argv[i], "-l")) continue;
if (!strcmp(argv[i], "-q")) continue;
if (!strcmp(argv[i], "-d")) {
param.log_level = OGS_LOG_DEBUG;
param.log_domain = argv[++i];
continue;
}
if (!strcmp(argv[i], "-t")) {
param.log_level = OGS_LOG_TRACE;
param.log_domain = argv[++i];
continue;
}
if (!strcmp(argv[i], "-f")) {
param.config_path = argv[++i];
continue;
}
if (argv[i][0] == '-') {
fprintf(stderr, "Invalid option: `%s'\n", argv[i]);
exit(1);
}
}
if (!param.config_path) {
ogs_path_remove_last_component(config_dir, argv[0]);
if (strstr(config_dir, ".libs"))
ogs_path_remove_last_component(config_dir, config_dir);
ogs_snprintf(config_path, sizeof config_path,
"%s/sample-csfb.conf", config_dir);
param.config_path = config_path;
}
if (param.log_level)
ogs_core()->log.level = OGS_LOG_DEFAULT;
else
ogs_core()->log.level = OGS_LOG_ERROR;
test_initialize(&param, argc, argv);
for (i = 0; alltests[i].func; i++)
{
suite = alltests[i].func(suite);
}
return abts_report(suite);
}

260
tests/csfb/csfb-test.c Normal file
View File

@ -0,0 +1,260 @@
#include <mongoc.h>
#include "core/abts.h"
#include "app/context.h"
#include "mme/mme-context.h"
#include "mme/s1ap-build.h"
#include "asn1c/s1ap-message.h"
#include "test-packet.h"
static void test1_func(abts_case *tc, void *data)
{
int rv;
ogs_socknode_t *s1ap;
ogs_socknode_t *gtpu;
ogs_pkbuf_t *sendbuf;
ogs_pkbuf_t *recvbuf;
s1ap_message_t message;
int i;
int msgindex = 15;
enb_ue_t *enb_ue = NULL;
mme_ue_t *mme_ue = NULL;
uint32_t m_tmsi = 0;
uint8_t tmp[MAX_SDU_LEN];
char *_authentication_request =
"000b403b00000300 000005c001a00102 000800020018001a 002524075200906d"
"231ff57ef278c719 1d170303deb610d0 7c4defa47480001f 2b5350926bdb3a";
char *_security_mode_command =
"000b402400000300 000005c001a00102 000800020018001a 000e0d37c966d549"
"00075d010002e0e0";
char *_esm_information_request =
"000b402000000300 000005c001a00102 000800020018001a 000a0927846a01a8"
"010201d9";
char *_initial_context_setup_request =
"00090080c1000006 00000005c001a001 0200080002001800 42000a183d090000"
"603d090000001800 70000034006b4500 093d0f807f000002 000000015c279a3e"
"783d02074201490c 0313401000320033 0034003500315201 c101090c07737461"
"72656e7403636f6d 05012d2d00025e06 fefee2e20303270f 80000d0408080808"
"000d040808040450 0bf6134010801e64 d90068e259496401 01006b000518000c"
"00000049002046c7 89cba93e9b977583 35c097e6c386c872 e4b82434a48037c3"
"0601590edd8e";
char *_emm_information =
"000b403b00000300 000005c001a00102 000800020018001a 0025242729f8b0bb"
"030761430f10004e 0065007800740045 0050004347914032 80113463490100";
mongoc_collection_t *collection = NULL;
bson_t *doc = NULL;
int64_t count = 0;
bson_error_t error;
const char *json =
"{"
"\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, "
"\"imsi\" : \"310014987654004\", "
"\"pdn\" : ["
"{"
"\"apn\" : \"starent.com\", "
"\"_id\" : { \"$oid\" : \"310014158b8861d7605378c7\" }, "
"\"ambr\" : {"
"\"uplink\" : { \"$numberLong\" : \"1000000\" }, "
"\"downlink\" : { \"$numberLong\" : \"1000000\" } "
"},"
"\"qos\" : { "
"\"qci\" : 9, "
"\"arp\" : { "
"\"priority_level\" : 15,"
"\"pre_emption_vulnerability\" : 0, "
"\"pre_emption_capability\" : 1"
"} "
"}, "
"\"type\" : 2"
"}"
"],"
"\"ambr\" : { "
"\"uplink\" : { \"$numberLong\" : \"1000000\" }, "
"\"downlink\" : { \"$numberLong\" : \"1000000\" } "
"},"
"\"subscribed_rau_tau_timer\" : 12,"
"\"network_access_mode\" : 2, "
"\"subscriber_status\" : 0, "
"\"access_restriction_data\" : 32, "
"\"security\" : { "
"\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", "
"\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", "
"\"amf\" : \"8000\", "
"\"sqn\" : { \"$numberLong\" : \"64\" }, "
"\"rand\" : \"906d231f f57ef278 c7191d17 0303deb6\" "
"}, "
"\"__v\" : 0 "
"}";
/* eNB connects to MME */
s1ap = testenb_s1ap_client("127.0.0.1");
ABTS_PTR_NOTNULL(tc, s1ap);
/* eNB connects to SGW */
gtpu = testenb_gtpu_server("127.0.0.5");
ABTS_PTR_NOTNULL(tc, gtpu);
/* Send S1-Setup Reqeust */
rv = tests1ap_build_setup_req(
&sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x54f64, 51, 310, 14, 3);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
rv = testenb_s1ap_send(s1ap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive S1-Setup Response */
recvbuf = testenb_s1ap_read(s1ap);
ABTS_PTR_NOTNULL(tc, recvbuf);
rv = s1ap_decode_pdu(&message, recvbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
s1ap_free_pdu(&message);
ogs_pkbuf_free(recvbuf);
collection = mongoc_client_get_collection(
context_self()->db.client,
context_self()->db.name, "subscribers");
ABTS_PTR_NOTNULL(tc, collection);
/********** Insert Subscriber in Database */
doc = bson_new_from_json((const uint8_t *)json, -1, &error);;
ABTS_PTR_NOTNULL(tc, doc);
ABTS_TRUE(tc, mongoc_collection_insert(collection,
MONGOC_INSERT_NONE, doc, NULL, &error));
bson_destroy(doc);
doc = BCON_NEW("imsi", BCON_UTF8("310014987654004"));
ABTS_PTR_NOTNULL(tc, doc);
do
{
count = mongoc_collection_count (
collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error);
} while (count == 0);
bson_destroy(doc);
mme_self()->mme_ue_s1ap_id = 27263233;
rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
rv = testenb_s1ap_send(s1ap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive Authentication Request */
recvbuf = testenb_s1ap_read(s1ap);
ABTS_PTR_NOTNULL(tc, recvbuf);
ABTS_TRUE(tc, memcmp(recvbuf->data,
OGS_HEX(_authentication_request, strlen(_authentication_request), tmp),
recvbuf->len) == 0);
ogs_pkbuf_free(recvbuf);
/* Send Authentication Response */
rv = tests1ap_build_authentication_response(&sendbuf, msgindex);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
rv = testenb_s1ap_send(s1ap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive Security mode Command */
recvbuf = testenb_s1ap_read(s1ap);
ABTS_PTR_NOTNULL(tc, recvbuf);
ABTS_TRUE(tc, memcmp(recvbuf->data,
OGS_HEX(_security_mode_command, strlen(_security_mode_command), tmp),
recvbuf->len) == 0);
ogs_pkbuf_free(recvbuf);
/* Send Security mode Complete */
rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
rv = testenb_s1ap_send(s1ap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive ESM Information Request */
recvbuf = testenb_s1ap_read(s1ap);
ABTS_PTR_NOTNULL(tc, recvbuf);
ABTS_TRUE(tc, memcmp(recvbuf->data,
OGS_HEX(_esm_information_request, strlen(_security_mode_command), tmp),
recvbuf->len) == 0);
ogs_pkbuf_free(recvbuf);
/* Send ESM Information Response */
rv = tests1ap_build_esm_information_response(&sendbuf, msgindex);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
rv = testenb_s1ap_send(s1ap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive Initial Context Setup Request +
* Attach Accept +
* Activate Default Bearer Context Request */
recvbuf = testenb_s1ap_read(s1ap);
ABTS_PTR_NOTNULL(tc, recvbuf);
OGS_HEX(_initial_context_setup_request,
strlen(_initial_context_setup_request), tmp);
ABTS_TRUE(tc, memcmp(recvbuf->data, tmp, 62) == 0);
ABTS_TRUE(tc, memcmp(recvbuf->data+66, tmp+66, 78) == 0);
ABTS_TRUE(tc, memcmp(recvbuf->data+148, tmp+148, 50) == 0);
ogs_pkbuf_free(recvbuf);
/* Send UE Capability Info Indication */
rv = tests1ap_build_ue_capability_info_indication(&sendbuf, msgindex);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
rv = testenb_s1ap_send(s1ap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Send Initial Context Setup Response */
rv = tests1ap_build_initial_context_setup_response(&sendbuf,
27263233, 24, 5, 1, "127.0.0.5");
ABTS_INT_EQUAL(tc, OGS_OK, rv);
rv = testenb_s1ap_send(s1ap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Send Attach Complete + Activate default EPS bearer cotext accept */
rv = tests1ap_build_attach_complete(&sendbuf, msgindex);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
rv = testenb_s1ap_send(s1ap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive EMM information */
recvbuf = testenb_s1ap_read(s1ap);
ABTS_PTR_NOTNULL(tc, recvbuf);
OGS_HEX(_emm_information, strlen(_emm_information), tmp);
ABTS_TRUE(tc, memcmp(recvbuf->data, tmp, 28) == 0);
ABTS_TRUE(tc, memcmp(recvbuf->data+32, tmp+32, 20) == 0);
ogs_pkbuf_free(recvbuf);
/* Send GTP-U ICMP Packet */
rv = testgtpu_build_ping(&sendbuf, "45.45.0.2", "45.45.0.1");
ABTS_INT_EQUAL(tc, OGS_OK, rv);
rv = testenb_gtpu_send(gtpu, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive GTP-U ICMP Packet */
recvbuf = testenb_gtpu_read(gtpu);
ABTS_PTR_NOTNULL(tc, recvbuf);
ogs_pkbuf_free(recvbuf);
/********** Remove Subscriber in Database */
doc = BCON_NEW("imsi", BCON_UTF8("310014987654004"));
ABTS_PTR_NOTNULL(tc, doc);
ABTS_TRUE(tc, mongoc_collection_remove(collection,
MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error))
bson_destroy(doc);
mongoc_collection_destroy(collection);
/* eNB disonncect from MME */
testenb_s1ap_close(s1ap);
/* eNB disonncect from SGW */
testenb_gtpu_close(gtpu);
}
abts_suite *test_csfb(abts_suite *suite)
{
suite = ADD_SUITE(suite)
abts_run_test(suite, test1_func, NULL);
return suite;
}

130
tests/sample-csfb.conf.in Normal file
View File

@ -0,0 +1,130 @@
db_uri: mongodb://localhost/nextepc
logger:
parameter:
no_ipv6: true
mme:
freeDiameter:
identity: mme.localdomain
realm: localdomain
no_sctp: true
listen_on: 127.0.0.2
load_extension:
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dbg_msg_dumps/.libs/dbg_msg_dumps.so
conf: 0x8888
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_rfc5777/.libs/dict_rfc5777.so
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_mip6i/.libs/dict_mip6i.so
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_nasreq/.libs/dict_nasreq.so
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_nas_mipv6/.libs/dict_nas_mipv6.so
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_dcca/.libs/dict_dcca.so
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_dcca_3gpp/.libs/dict_dcca_3gpp.so
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_s6a/.libs/dict_s6a.so
connect:
- identity: hss.localdomain
addr: 127.0.0.4
s1ap:
addr: 127.0.0.1
gtpc:
addr: 127.0.0.1
gummei:
plmn_id:
mcc: 310
mnc: 014
mme_gid: 32798
mme_code: 100
tai:
plmn_id:
mcc: 310
mnc: 014
tac: [50, 51, 52, 53]
security:
integrity_order : [ EIA1, EIA2, EIA0 ]
ciphering_order : [ EEA0, EEA1, EEA2 ]
network_name:
full: NextEPC
hss:
freeDiameter:
identity: hss.localdomain
realm: localdomain
no_sctp: true
listen_on: 127.0.0.4
load_extension:
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dbg_msg_dumps/.libs/dbg_msg_dumps.so
conf: 0x8888
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_rfc5777/.libs/dict_rfc5777.so
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_mip6i/.libs/dict_mip6i.so
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_nasreq/.libs/dict_nasreq.so
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_nas_mipv6/.libs/dict_nas_mipv6.so
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_dcca/.libs/dict_dcca.so
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_dcca_3gpp/.libs/dict_dcca_3gpp.so
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_s6a/.libs/dict_s6a.so
connect:
- identity: mme.localdomain
addr: 127.0.0.2
sgw:
gtpc:
addr: 127.0.0.2
gtpu:
addr: 127.0.0.2
pgw:
freeDiameter:
identity: pgw.localdomain
realm: localdomain
no_sctp: true
listen_on: 127.0.0.3
load_extension:
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dbg_msg_dumps/.libs/dbg_msg_dumps.so
conf: 0x8888
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_rfc5777/.libs/dict_rfc5777.so
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_mip6i/.libs/dict_mip6i.so
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_nasreq/.libs/dict_nasreq.so
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_nas_mipv6/.libs/dict_nas_mipv6.so
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_dcca/.libs/dict_dcca.so
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_dcca_3gpp/.libs/dict_dcca_3gpp.so
connect:
- identity: pcrf.localdomain
addr: 127.0.0.5
gtpc:
- addr:
- 127.0.0.3
- ::1
- addr:
- 127.0.0.4
apn: starent.com
gtpu:
- addr: 127.0.0.3
- addr: ::1
ue_pool:
- addr: 45.45.0.1/16
- addr: cafe::1/64
dns:
- 8.8.8.8
- 8.8.4.4
- 2001:4860:4860::8888
- 2001:4860:4860::8844
pcrf:
freeDiameter:
identity: pcrf.localdomain
realm: localdomain
no_sctp: true
listen_on: 127.0.0.5
load_extension:
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dbg_msg_dumps/.libs/dbg_msg_dumps.so
conf: 0x8888
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_rfc5777/.libs/dict_rfc5777.so
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_mip6i/.libs/dict_mip6i.so
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_nasreq/.libs/dict_nasreq.so
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_nas_mipv6/.libs/dict_nas_mipv6.so
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_dcca/.libs/dict_dcca.so
- module: @abs_top_builddir@/lib/@FREEDIAMETER_DIR@/extensions/dict_dcca_3gpp/.libs/dict_dcca_3gpp.so
connect:
- identity: pgw.localdomain
addr: 127.0.0.3