[#231] Create simulator

This commit is contained in:
Sukchan Lee 2019-07-21 15:14:31 +09:00
parent 5e78b78166
commit 235121c82d
6 changed files with 345 additions and 29 deletions

View File

@ -718,14 +718,20 @@ void emm_state_security_mode(ogs_fsm_t *s, mme_event_t *e)
break;
}
/* Update Kenb */
if (SECURITY_CONTEXT_IS_VALID(mme_ue)) {
mme_kdf_enb(mme_ue->kasme, mme_ue->ul_count.i32,
mme_ue->kenb);
mme_kdf_nh(mme_ue->kasme, mme_ue->kenb, mme_ue->nh);
mme_ue->nhcc = 1;
if (!SECURITY_CONTEXT_IS_VALID(mme_ue)) {
ogs_warn("No Security Context : IMSI[%s]", mme_ue->imsi_bcd);
nas_send_attach_reject(mme_ue,
EMM_CAUSE_SECURITY_MODE_REJECTED_UNSPECIFIED,
ESM_CAUSE_PROTOCOL_ERROR_UNSPECIFIED);
OGS_FSM_TRAN(s, &emm_state_exception);
break;
}
mme_kdf_enb(mme_ue->kasme, mme_ue->ul_count.i32,
mme_ue->kenb);
mme_kdf_nh(mme_ue->kasme, mme_ue->kenb, mme_ue->nh);
mme_ue->nhcc = 1;
mme_s6a_send_ulr(mme_ue);
if (mme_ue->nas_eps.type == MME_EPS_TYPE_ATTACH_REQUEST) {
OGS_FSM_TRAN(s, &emm_state_initial_context_setup);
@ -752,7 +758,7 @@ void emm_state_security_mode(ogs_fsm_t *s, mme_event_t *e)
if (rv != OGS_OK) {
ogs_error("emm_handle_attach_request() failed");
OGS_FSM_TRAN(s, emm_state_exception);
return;
break;
}
mme_s6a_send_air(mme_ue, NULL);
@ -779,7 +785,7 @@ void emm_state_security_mode(ogs_fsm_t *s, mme_event_t *e)
if (rv != OGS_OK) {
ogs_error("emm_handle_attach_request() failed");
OGS_FSM_TRAN(s, emm_state_exception);
return;
break;
}
rv = mme_send_delete_session_or_detach(mme_ue);

View File

@ -46,6 +46,7 @@ testcsfb_SOURCES = \
csfb/mo-idle-test.c csfb/mt-idle-test.c \
csfb/mo-active-test.c csfb/mt-active-test.c \
csfb/mo-sms-test.c csfb/mt-sms-test.c \
csfb/crash-test.c \
$(NULL)
testcsfb_LDADD = $(top_srcdir)/src/libepc.la

View File

@ -428,7 +428,12 @@ int tests1ap_build_initial_ue_msg(ogs_pkbuf_t **pkbuf, int i)
"0600000000830600 000000000d000010 005209f10700075c 08033103e5e07e90"
"1103571882200a60 140462918100127e 00400800021f0004 0240045d0100e0c1"
"004300060009f107 0007006440080009 f1070019b0100086 400130",
"",
"000c4080b1000005 000800048003e993 001a008086808417 6e2da9da06074102"
"0bf627f412000201 f700571805f070c0 4011002d026ed031 d127268080211001"
"0000108106000000 0083060000000000 0d00000300000a00 0005000010000011"
"005227f41230395c 0a003103e5e03e13 27f412c958110357 58a6200c601404ef"
"65233b8878d2f280 4008040260040002 1f025d0103e0c110 0203800043000600"
"27f4123039006440 080027f412000640 200086400130",
"",
/* 21 */
@ -468,7 +473,7 @@ int tests1ap_build_initial_ue_msg(ogs_pkbuf_t **pkbuf, int i)
0,
155,
0,
182,
0,
/* 21 */
@ -522,7 +527,9 @@ int tests1ap_build_identity_response(ogs_pkbuf_t **pkbuf, int i)
/* 18 */
"000d403b00000500 0000020001000800 020001001a001211 177b973f4c0a0756"
"0829262400001118 93006440080009f1 070019b010004340 060009f1070007",
"",
"000d403d00000500 00000200f8000800 048003e993001a00 121117c651b5f907"
"0756087942120000 0000300064400800 27f4120006402000 4340060027f41230"
"39",
"",
/* 21 */
@ -559,7 +566,7 @@ int tests1ap_build_identity_response(ogs_pkbuf_t **pkbuf, int i)
0,
63,
0,
65,
0,
/* 21 */
@ -627,7 +634,9 @@ int tests1ap_build_authentication_response(ogs_pkbuf_t **pkbuf, int i)
/* 18 */
"000d403b00000500 0000020001000800 020001001a001211 17fda45fe50b0753"
"086f7ff4fc4be85f d1006440080009f1 070019b010004340 060009f1070007",
"",
"000d403d00000500 00000200f8000800 048003e993001a00 121117e6e4dd6508"
"0753086f7ff4fc4b e85fd10064400800 27f4120006402000 4340060027f41230"
"39",
"",
/* 21 */
@ -664,7 +673,7 @@ int tests1ap_build_authentication_response(ogs_pkbuf_t **pkbuf, int i)
0,
63,
0,
65,
0,
/* 21 */
@ -784,7 +793,8 @@ int tests1ap_build_security_mode_complete(ogs_pkbuf_t **pkbuf, int i)
/* 18 */
"000d403200000500 0000020001000800 020001001a000908 470ba943dd00075e"
"006440080009f107 0019b01000434006 0009f1070007",
"",
"000d403400000500 00000200f8000800 048003e993001a00 090847592cf09600"
"075e006440080027 f412000640200043 40060027f4123039",
"",
/* 21 */
@ -820,7 +830,7 @@ int tests1ap_build_security_mode_complete(ogs_pkbuf_t **pkbuf, int i)
0,
54,
0,
56,
0,
/* 21 */
@ -900,7 +910,9 @@ int tests1ap_build_esm_information_response(ogs_pkbuf_t **pkbuf, int i)
"000d405a00000500 0000020001000800 020001001a003130 27ebeeb5d4010234"
"da280908696e7465 726e6574271a8080 2110010100108106 0000000083060000"
"0000000d00001000 006440080009f107 0019b01000434006 0009f1070007",
"",
"000d404000000500 00000200f8000800 048003e993001a00 151427f9e0e95c01"
"026eda280908696e 7465726e65740064 40080027f4120006 4020004340060027"
"f4123039",
"",
};
uint16_t len[TESTS1AP_MAX_MESSAGE] = {
@ -916,6 +928,7 @@ int tests1ap_build_esm_information_response(ogs_pkbuf_t **pkbuf, int i)
0,
0,
/* 9 */
69,
69,
0,
@ -928,8 +941,9 @@ int tests1ap_build_esm_information_response(ogs_pkbuf_t **pkbuf, int i)
0,
0,
/* 18 */
94,
0,
68,
0,
};
char hexbuf[MAX_SDU_LEN];

View File

@ -35,6 +35,7 @@ abts_suite *test_mo_active(abts_suite *suite);
abts_suite *test_mt_active(abts_suite *suite);
abts_suite *test_mo_sms(abts_suite *suite);
abts_suite *test_mt_sms(abts_suite *suite);
abts_suite *test_crash(abts_suite *suite);
const struct testlist {
abts_suite *(*func)(abts_suite *suite);
@ -45,6 +46,7 @@ const struct testlist {
{test_mt_active},
{test_mo_sms},
{test_mt_sms},
{test_crash},
{NULL},
};

288
tests/csfb/crash-test.c Normal file
View File

@ -0,0 +1,288 @@
#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"
extern ogs_socknode_t *sgsap;
static void test1_func(abts_case *tc, void *data)
{
int rv;
ogs_socknode_t *s1ap;
ogs_pkbuf_t *sendbuf;
ogs_pkbuf_t *recvbuf;
s1ap_message_t message;
int i;
int msgindex = 19;
enb_ue_t *enb_ue = NULL;
mme_ue_t *mme_ue = NULL;
uint32_t m_tmsi = 0;
mongoc_collection_t *collection = NULL;
bson_t *doc = NULL;
int64_t count = 0;
bson_error_t error;
const char *json =
"{"
"\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, "
"\"imsi\" : \"724210000000003\", "
"\"pdn\" : ["
"{"
"\"apn\" : \"internet\", "
"\"_id\" : { \"$oid\" : \"310014158b8861d7605378c7\" }, "
"\"ambr\" : {"
"\"uplink\" : { \"$numberLong\" : \"1000000\" }, "
"\"downlink\" : { \"$numberLong\" : \"1000000\" } "
"},"
"\"qos\" : { "
"\"qci\" : 9, "
"\"arp\" : { "
"\"priority_level\" : 8,"
"\"pre_emption_vulnerability\" : 0, "
"\"pre_emption_capability\" : 0"
"} "
"}, "
"\"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\" : \"70D49A71DD1A2B806A25ABE0EF749F1E\", "
"\"opc\" : \"6F1BF53D624B3A43AF6592854E2444C7\", "
"\"amf\" : \"8000\", "
"\"sqn\" : { \"$numberLong\" : \"2374\" }, "
"\"rand\" : \"aa266700bc2887354e9f87368d5d0ae7\" "
"}, "
"\"__v\" : 0 "
"}";
/* eNB connects to MME */
s1ap = testenb_s1ap_client("127.0.0.1");
ABTS_PTR_NOTNULL(tc, s1ap);
/* Send S1-Setup Reqeust */
rv = tests1ap_build_setup_req(
&sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x0019b0, 7, 901, 70, 2);
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("724210000000003"));
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);
/* Send Attach Request */
mme_self()->mme_ue_s1ap_id = 247;
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 Identity-Request */
recvbuf = testenb_s1ap_read(s1ap);
ABTS_PTR_NOTNULL(tc, recvbuf);
ogs_pkbuf_free(recvbuf);
/* Send Identity Response */
rv = tests1ap_build_identity_response(&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);
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);
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);
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);
#if 0
/* Receive SGsAP-Location-Update-Request */
recvbuf = testvlr_sgsap_read(sgsap);
ABTS_PTR_NOTNULL(tc, recvbuf);
ogs_pkbuf_free(recvbuf);
/* Send SGsAP-Location-Update-Accept */
rv = testsgsap_location_update_accept(&sendbuf, 0);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
rv = testvlr_sgsap_send(sgsap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
#endif
/* Receive Initial Context Setup Request +
* Attach Accept +
* Activate Default Bearer Context Request */
recvbuf = testenb_s1ap_read(s1ap);
ABTS_PTR_NOTNULL(tc, recvbuf);
ogs_pkbuf_free(recvbuf);
#if 0
/* Send Initial Context Setup Response */
rv = tests1ap_build_initial_context_setup_response(&sendbuf,
1, 1, 5, 0x00460003, "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_pkbuf_free(recvbuf);
/* Receive SGsAP TMSI-REALLOCATION-COMPLETE */
recvbuf = testvlr_sgsap_read(sgsap);
ABTS_PTR_NOTNULL(tc, recvbuf);
ogs_pkbuf_free(recvbuf);
/* Retreive M-TMSI */
enb_ue = enb_ue_find_by_mme_ue_s1ap_id(1);
ogs_assert(enb_ue);
mme_ue = enb_ue->mme_ue;
ogs_assert(mme_ue);
m_tmsi = mme_ue->guti.m_tmsi;
/* Send SGsAP-Paging-Request */
rv = testsgsap_paging_request(&sendbuf, 0);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
rv = testvlr_sgsap_send(sgsap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive S1AP Paging */
recvbuf = testenb_s1ap_read(s1ap);
ABTS_PTR_NOTNULL(tc, recvbuf);
ogs_pkbuf_free(recvbuf);
/* Send Extended Service Request */
rv = tests1ap_build_extended_service_request(&sendbuf, msgindex+1,
1, m_tmsi, 4, mme_ue->knas_int);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
rv = testenb_s1ap_send(s1ap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive Service Request */
recvbuf = testvlr_sgsap_read(sgsap);
ABTS_PTR_NOTNULL(tc, recvbuf);
ogs_pkbuf_free(recvbuf);
/* Receive UE Context Modification Request */
recvbuf = testenb_s1ap_read(s1ap);
ABTS_PTR_NOTNULL(tc, recvbuf);
ogs_pkbuf_free(recvbuf);
/* Send UE Context Modification Response */
rv = tests1ap_build_ue_context_modification_response(&sendbuf, 1, 1);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
rv = testenb_s1ap_send(s1ap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Send UE Context Release Request */
rv = tests1ap_build_ue_context_release_request(&sendbuf, msgindex);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
rv = testenb_s1ap_send(s1ap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Receive UE Context Release Command */
recvbuf = testenb_s1ap_read(s1ap);
ABTS_PTR_NOTNULL(tc, recvbuf);
ogs_pkbuf_free(recvbuf);
/* Send UE Context Release Complete */
rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
rv = testenb_s1ap_send(s1ap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
#endif
ogs_msleep(300);
/********** Remove Subscriber in Database */
doc = BCON_NEW("imsi", BCON_UTF8("724210000000003"));
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);
}
abts_suite *test_crash(abts_suite *suite)
{
suite = ADD_SUITE(suite)
abts_run_test(suite, test1_func, NULL);
return suite;
}

View File

@ -30,17 +30,17 @@ mme:
gtpc:
addr: 127.0.0.1
sgsap:
addr: 127.0.0.2
tai:
plmn_id:
mcc: 901
mnc: 70
tac: 7
lai:
plmn_id:
mcc: 901
mnc: 70
lac: 2342
- addr: 127.0.0.2
tai:
plmn_id:
mcc: 901
mnc: 70
tac: 7
lai:
plmn_id:
mcc: 901
mnc: 70
lac: 2342
gummei:
plmn_id:
mcc: 901
@ -52,6 +52,11 @@ mme:
mcc: 901
mnc: 70
tac: 7
tai:
plmn_id:
mcc: 724
mnc: 21
tac: 12345
security:
integrity_order : [ EIA1, EIA2, EIA0 ]
ciphering_order : [ EEA0, EEA1, EEA2 ]