open5gs/tests/unit/s1ap-message-test.c

205 lines
5.7 KiB
C
Raw Normal View History

2019-04-27 14:54:30 +00:00
#include "core/abts.h"
2017-12-07 05:37:58 +00:00
2019-06-11 13:10:47 +00:00
#include "mme/s1ap-build.h"
2017-02-13 10:14:04 +00:00
static void s1ap_message_test1(abts_case *tc, void *data)
2017-02-03 08:00:22 +00:00
{
/* S1SetupRequest */
const char *payload =
2017-03-05 06:26:28 +00:00
"0011002d000004003b00090000f11040"
"54f64010003c400903004a4c542d3632"
"3100400007000c0e4000f11000894001"
"00";
2017-02-04 16:28:53 +00:00
2019-09-13 12:07:47 +00:00
ogs_s1ap_message_t message;
2019-04-27 14:54:30 +00:00
ogs_pkbuf_t *pkbuf;
int result;
2019-09-13 12:07:47 +00:00
char hexbuf[OGS_MAX_SDU_LEN];
2019-09-13 12:07:47 +00:00
pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN);
2019-04-27 14:54:30 +00:00
ogs_assert(pkbuf);
ogs_pkbuf_put_data(pkbuf,
OGS_HEX(payload, strlen(payload), hexbuf), 49);
2017-02-04 16:28:53 +00:00
2019-09-13 12:07:47 +00:00
result = ogs_s1ap_decode(&message, pkbuf);
ABTS_INT_EQUAL(tc, 0, result);
2019-09-13 12:07:47 +00:00
ogs_s1ap_free(&message);
2017-02-07 04:52:34 +00:00
2019-04-27 14:54:30 +00:00
ogs_pkbuf_free(pkbuf);
}
2017-02-13 10:14:04 +00:00
static void s1ap_message_test2(abts_case *tc, void *data)
{
2017-02-04 05:48:57 +00:00
/* InitialUE(Attach Request) */
const char *payload =
2017-03-05 06:26:28 +00:00
"000c406f000006000800020001001a00"
"3c3b17df675aa8050741020bf600f110"
"000201030003e605f070000010000502"
"15d011d15200f11030395c0a003103e5"
"e0349011035758a65d0100e0c1004300"
"060000f1103039006440080000f1108c"
"3378200086400130004b00070000f110"
"000201";
2017-02-04 16:28:53 +00:00
2019-09-13 12:07:47 +00:00
ogs_s1ap_message_t message;
2019-04-27 14:54:30 +00:00
ogs_pkbuf_t *pkbuf;
int result;
2019-09-13 12:07:47 +00:00
char hexbuf[OGS_MAX_SDU_LEN];
2019-09-13 12:07:47 +00:00
pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN);
2019-04-27 14:54:30 +00:00
ogs_assert(pkbuf);
ogs_pkbuf_put_data(pkbuf,
OGS_HEX(payload, strlen(payload), hexbuf), 115);
2017-02-04 16:28:53 +00:00
2019-09-13 12:07:47 +00:00
result = ogs_s1ap_decode(&message, pkbuf);
ABTS_INT_EQUAL(tc, 0, result);
2019-09-13 12:07:47 +00:00
ogs_s1ap_free(&message);
2019-04-27 14:54:30 +00:00
ogs_pkbuf_free(pkbuf);
2017-02-03 08:00:22 +00:00
}
2017-02-13 10:14:04 +00:00
static void s1ap_message_test3(abts_case *tc, void *data)
2017-02-04 05:48:57 +00:00
{
/* initial context setup response */
const char *payload =
2017-03-05 06:26:28 +00:00
"2009002500000300004005c0020000bf"
"0008400200010033400f000032400a0a"
"1f0a0123c601000908";
2017-02-04 16:28:53 +00:00
2019-09-13 12:07:47 +00:00
ogs_s1ap_message_t message;
2019-04-27 14:54:30 +00:00
ogs_pkbuf_t *pkbuf;
2017-02-04 05:48:57 +00:00
int result;
2019-09-13 12:07:47 +00:00
char hexbuf[OGS_MAX_SDU_LEN];
2017-02-04 05:48:57 +00:00
2019-09-13 12:07:47 +00:00
pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN);
2019-04-27 14:54:30 +00:00
ogs_assert(pkbuf);
ogs_pkbuf_put_data(pkbuf,
OGS_HEX(payload, strlen(payload), hexbuf), 41);
2017-02-04 16:28:53 +00:00
2019-09-13 12:07:47 +00:00
result = ogs_s1ap_decode(&message, pkbuf);
2017-02-04 05:48:57 +00:00
ABTS_INT_EQUAL(tc, 0, result);
2019-09-13 12:07:47 +00:00
ogs_s1ap_free(&message);
2019-04-27 14:54:30 +00:00
ogs_pkbuf_free(pkbuf);
2017-02-04 05:48:57 +00:00
}
2017-02-13 10:14:04 +00:00
static void s1ap_message_test4(abts_case *tc, void *data)
2017-02-06 10:12:10 +00:00
{
2019-09-13 12:07:47 +00:00
ogs_s1ap_message_t message;
2019-04-27 14:54:30 +00:00
int rv;
ogs_pkbuf_t *pkbuf;
2017-02-13 09:11:09 +00:00
int result;
2017-02-06 10:12:10 +00:00
2019-05-19 11:26:33 +00:00
mme_self()->max_num_of_served_gummei = 1;
mme_self()->served_gummei[0].num_of_plmn_id = 1;
mme_self()->served_gummei[0].num_of_mme_gid = 1;
mme_self()->served_gummei[0].num_of_mme_code = 1;
2019-11-30 07:45:09 +00:00
pkbuf = s1ap_build_setup_rsp();
2017-02-06 12:52:20 +00:00
ABTS_PTR_NOTNULL(tc, pkbuf);
2019-04-27 14:54:30 +00:00
ABTS_PTR_NOTNULL(tc, pkbuf->data);
2017-02-13 09:11:09 +00:00
ABTS_INT_EQUAL(tc, 27, pkbuf->len);
2019-09-13 12:07:47 +00:00
result = ogs_s1ap_decode(&message, pkbuf);
2017-02-13 09:11:09 +00:00
ABTS_INT_EQUAL(tc, 0, result);
2017-02-07 04:52:34 +00:00
2019-09-13 12:07:47 +00:00
ogs_s1ap_free(&message);
2019-04-27 14:54:30 +00:00
ogs_pkbuf_free(pkbuf);
2017-02-06 11:54:31 +00:00
}
2017-02-13 10:14:04 +00:00
static void s1ap_message_test5(abts_case *tc, void *data)
2017-02-06 11:54:31 +00:00
{
2020-08-22 03:33:45 +00:00
#if 0
2019-09-13 12:07:47 +00:00
ogs_s1ap_message_t message;
2019-04-27 14:54:30 +00:00
int rv;
ogs_pkbuf_t *pkbuf;
2017-02-13 09:11:09 +00:00
int result;
2017-02-06 11:54:31 +00:00
2020-08-22 03:33:45 +00:00
pkbuf = test_s1ap_build_s1_setup_request(
S1AP_ENB_ID_PR_macroENB_ID, 0x54f64, 12345, 1, 1, 2);
2017-02-06 11:54:31 +00:00
2019-04-27 14:54:30 +00:00
ABTS_INT_EQUAL(tc, OGS_OK, rv);
2017-02-13 07:25:36 +00:00
ABTS_PTR_NOTNULL(tc, pkbuf);
2019-04-27 14:54:30 +00:00
ABTS_PTR_NOTNULL(tc, pkbuf->data);
2017-02-13 09:11:09 +00:00
ABTS_INT_EQUAL(tc, 35, pkbuf->len);
2019-09-13 12:07:47 +00:00
result = ogs_s1ap_decode(&message, pkbuf);
2017-02-13 09:11:09 +00:00
ABTS_INT_EQUAL(tc, 0, result);
2017-02-10 04:26:48 +00:00
2019-09-13 12:07:47 +00:00
ogs_s1ap_free(&message);
2019-04-27 14:54:30 +00:00
ogs_pkbuf_free(pkbuf);
2020-08-22 03:33:45 +00:00
#endif
2017-02-06 10:12:10 +00:00
}
2017-04-13 05:46:27 +00:00
static void s1ap_message_test6(abts_case *tc, void *data)
{
2019-04-27 14:54:30 +00:00
int rv;
ogs_pkbuf_t *s1apbuf = NULL;
ogs_pkbuf_t *emmbuf = NULL;
2018-03-10 03:21:02 +00:00
enb_ue_t enb_ue;
2017-04-13 16:37:16 +00:00
int i;
2017-04-13 05:46:27 +00:00
char buffer[1024];
const char *_result =
2017-04-13 05:46:27 +00:00
"000b4080 8c000003 00000002 00010008 00020001 001a0079 78efefef efefefef"
"efefefef efefefef efefefef efefefef efefefef efefefef efefefef efefefef"
"efefefef efefefef efefefef efefefef efefefef efefefef efefefef efefefef"
"efefefef efefefef efefefef efefefef efefefef efefefef efefefef efefefef"
"efefefef efefefef efefefef efefefef ef";
2018-03-10 03:21:02 +00:00
enb_ue.mme_ue_s1ap_id = 1;
enb_ue.enb_ue_s1ap_id = 1;
2017-04-13 05:46:27 +00:00
2019-04-27 14:54:30 +00:00
emmbuf = ogs_pkbuf_alloc(NULL, 120);
ABTS_PTR_NOTNULL(tc, emmbuf);
ogs_pkbuf_put(emmbuf, 120);
2018-03-10 03:21:02 +00:00
for (i = 0; i < emmbuf->len; i++)
2019-04-27 14:54:30 +00:00
((char *)emmbuf->data)[i] = 0xef;
2017-04-13 05:46:27 +00:00
2019-11-30 07:45:09 +00:00
s1apbuf = s1ap_build_downlink_nas_transport(&enb_ue, emmbuf);
2019-04-27 14:54:30 +00:00
ABTS_TRUE(tc, memcmp(OGS_HEX(_result, strlen(_result), buffer),
s1apbuf->data, s1apbuf->len) == 0);
ogs_pkbuf_free(s1apbuf);
2017-04-13 05:46:27 +00:00
}
2019-03-22 07:59:37 +00:00
static void s1ap_message_test7(abts_case *tc, void *data)
{
/* InitialUE(Service Request) */
const char *payload =
2019-03-22 07:59:37 +00:00
"000c402d000005000800020071001a00 0504c706b410004300060013f1890001"
"006440080013f189400bb75000864001 40006440080013f189400bb750004340"
"060013f18900014300060013f1890001 006440080013f189400db09000864001"
"30000000000000000000000000000000 00000000000000000000000000000000";
2019-09-13 12:07:47 +00:00
ogs_s1ap_message_t message;
2019-04-27 14:54:30 +00:00
ogs_pkbuf_t *pkbuf;
2019-03-22 07:59:37 +00:00
int result;
2019-09-13 12:07:47 +00:00
char hexbuf[OGS_MAX_SDU_LEN];
2019-03-22 07:59:37 +00:00
2019-09-13 12:07:47 +00:00
pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN);
2019-04-27 14:54:30 +00:00
ogs_assert(pkbuf);
ogs_pkbuf_put_data(pkbuf,
OGS_HEX(payload, strlen(payload), hexbuf), 128);
2019-03-22 07:59:37 +00:00
2019-09-13 12:07:47 +00:00
result = ogs_s1ap_decode(&message, pkbuf);
2019-03-22 07:59:37 +00:00
ABTS_INT_EQUAL(tc, 0, result);
2019-09-13 12:07:47 +00:00
ogs_s1ap_free(&message);
2019-03-22 07:59:37 +00:00
2019-04-27 14:54:30 +00:00
ogs_pkbuf_free(pkbuf);
2019-03-22 07:59:37 +00:00
}
2017-02-13 10:14:04 +00:00
abts_suite *test_s1ap_message(abts_suite *suite)
2017-02-03 08:00:22 +00:00
{
suite = ADD_SUITE(suite)
2017-02-13 10:14:04 +00:00
abts_run_test(suite, s1ap_message_test1, NULL);
abts_run_test(suite, s1ap_message_test2, NULL);
abts_run_test(suite, s1ap_message_test3, NULL);
abts_run_test(suite, s1ap_message_test4, NULL);
abts_run_test(suite, s1ap_message_test5, NULL);
2017-04-13 05:46:27 +00:00
abts_run_test(suite, s1ap_message_test6, NULL);
2019-03-22 07:59:37 +00:00
abts_run_test(suite, s1ap_message_test7, NULL);
2017-02-03 08:00:22 +00:00
return suite;
}