open5gs/test/nas_sm_test.c

115 lines
3.4 KiB
C

#include "core_debug.h"
#include "core_pkbuf.h"
#include "core_lib.h"
#include "mme/context.h"
#include "s1ap_message.h"
#include "testutil.h"
#include "tests1ap.h"
static void nas_sm_test1(abts_case *tc, void *data)
{
status_t rv;
net_sock_t *sock;
pkbuf_t *sendbuf;
pkbuf_t *recvbuf;
s1ap_message_t message;
int rc;
int i;
c_uint8_t tmp[MESSAGE_SDU_SIZE];
char *_authentication_request =
"000b403b00000300 000005c00100009d 000800020001001a 0025240752002008"
"0c3818183b522614 162c07601d0d10f1 1b89a2a8de8000ad 0ccf7f55e8b20d";
char *_security_mode_command =
"000b402700000300 000005c00100009d 000800020001001a 00111037f933b5d5"
"00075d010005e060 c04070";
/* eNB connects to MME */
sock = tests1ap_enb_connect();
ABTS_PTR_NOTNULL(tc, sock);
d_log_set_level(D_MSG_TO_STDOUT, D_LOG_LEVEL_WARN);
/* Send S1-Setup Reqeust */
rv = tests1ap_build_setup_req(&sendbuf, 0x54f64);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
rv = tests1ap_enb_send(sock, sendbuf);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
pkbuf_free(sendbuf);
/* Receive S1-Setup Response */
recvbuf = pkbuf_alloc(0, MESSAGE_SDU_SIZE);
rc = tests1ap_enb_read(sock, recvbuf);
ABTS_INT_NEQUAL(tc, 0, rc);
rv = s1ap_decode_pdu(&message, recvbuf);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
s1ap_free_pdu(&message);
pkbuf_free(recvbuf);
/* Send Initial-UE Message */
mme_self()->mme_ue_s1ap_id = 16777373;
rv = tests1ap_build_initial_ue_msg(&sendbuf);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
rv = tests1ap_enb_send(sock, sendbuf);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
pkbuf_free(sendbuf);
/* Receive Authentication-Request */
recvbuf = pkbuf_alloc(0, MESSAGE_SDU_SIZE);
rc = tests1ap_enb_read(sock, recvbuf);
ABTS_INT_NEQUAL(tc, 0, rc);
recvbuf->len = 63;
ABTS_TRUE(tc, memcmp(recvbuf->payload,
core_ascii_to_hex(_authentication_request,
strlen(_authentication_request), tmp, sizeof(tmp)),
recvbuf->len) == 0);
pkbuf_free(recvbuf);
/* Send Authentication-Response */
rv = tests1ap_build_authentication_response(&sendbuf);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
rv = tests1ap_enb_send(sock, sendbuf);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
pkbuf_free(sendbuf);
/* Receive Security-mode-Command */
recvbuf = pkbuf_alloc(0, MESSAGE_SDU_SIZE);
rc = tests1ap_enb_read(sock, recvbuf);
recvbuf->len = 43;
ABTS_TRUE(tc, memcmp(recvbuf->payload,
core_ascii_to_hex(_security_mode_command,
strlen(_security_mode_command), tmp, sizeof(tmp)),
recvbuf->len) == 0);
ABTS_INT_NEQUAL(tc, 0, rc);
pkbuf_free(recvbuf);
/* Send Security-mode-Complete */
rv = tests1ap_build_security_mode_complete(&sendbuf);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
rv = tests1ap_enb_send(sock, sendbuf);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
pkbuf_free(sendbuf);
d_log_set_level(D_MSG_TO_STDOUT, D_LOG_LEVEL_ERROR);
/* eNB disonncect from MME */
rv = tests1ap_enb_close(sock);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
core_sleep(time_from_msec(300));
d_log_set_level(D_MSG_TO_STDOUT, D_LOG_LEVEL_FULL);
}
abts_suite *test_nas_sm(abts_suite *suite)
{
suite = ADD_SUITE(suite)
#if 0
d_log_set_level(D_MSG_TO_STDOUT, D_LOG_LEVEL_FULL);
#endif
abts_run_test(suite, nas_sm_test1, NULL);
return suite;
}