diff options
Diffstat (limited to 'tests/sgsn/sgsn_test.c')
-rw-r--r-- | tests/sgsn/sgsn_test.c | 93 |
1 files changed, 45 insertions, 48 deletions
diff --git a/tests/sgsn/sgsn_test.c b/tests/sgsn/sgsn_test.c index 057462062..a149b8e2c 100644 --- a/tests/sgsn/sgsn_test.c +++ b/tests/sgsn/sgsn_test.c @@ -19,43 +19,38 @@ * */ +#include <osmocom/core/application.h> +#include <osmocom/core/msgb.h> +#include <osmocom/core/rate_ctr.h> +#include <osmocom/core/utils.h> +#include <osmocom/gsm/apn.h> +#include <osmocom/gsm/gsm_utils.h> +#include <osmocom/gsm/gsup.h> +#include <osmocom/gprs/gprs_bssgp.h> +#include <osmocom/vty/vty.h> + +#include <osmocom/gsupclient/gsup_client.h> + #include <osmocom/sgsn/gprs_llc.h> #include <osmocom/sgsn/sgsn.h> #include <osmocom/sgsn/gprs_gmm.h> #include <osmocom/sgsn/debug.h> #include <osmocom/sgsn/gprs_subscriber.h> -#include <osmocom/gsm/gsup.h> -#include <osmocom/gsupclient/gsup_client.h> #include <osmocom/sgsn/gprs_utils.h> -#include <osmocom/sgsn/gprs_gb_parse.h> #include <osmocom/sgsn/gprs_gmm_fsm.h> - -#include <osmocom/gprs/gprs_bssgp.h> - -#include <osmocom/gsm/gsm_utils.h> - -#include <osmocom/core/application.h> -#include <osmocom/core/msgb.h> -#include <osmocom/core/rate_ctr.h> -#include <osmocom/core/utils.h> -#include <osmocom/vty/vty.h> +#include <osmocom/sgsn/gtp_ggsn.h> #include <stdio.h> +#include "gprs_gb_parse.h" + void *tall_sgsn_ctx; -static struct sgsn_instance sgsn_inst = { - .config_file = "osmo_sgsn.cfg", - .cfg = { - .gtp_statedir = "./", - .auth_policy = SGSN_AUTH_POLICY_CLOSED, - }, -}; -struct sgsn_instance *sgsn = &sgsn_inst; +struct sgsn_instance *sgsn; unsigned sgsn_tx_counter = 0; struct msgb *last_msg = NULL; struct gprs_gb_parse_context last_dl_parse_ctx; -static void reset_last_msg() +static void reset_last_msg(void) { if (last_msg) msgb_free(last_msg); @@ -64,9 +59,10 @@ static void reset_last_msg() memset(&last_dl_parse_ctx, 0, sizeof(last_dl_parse_ctx)); } -static void cleanup_test() +static void cleanup_test(void) { reset_last_msg(); + TALLOC_FREE(sgsn); } static uint32_t get_new_ptmsi(const struct gprs_gb_parse_context *parse_ctx) @@ -281,7 +277,7 @@ static void show_subscrs(FILE *out) } } -static void assert_no_subscrs() +static void assert_no_subscrs(void) { show_subscrs(stdout); fflush(stdout); @@ -383,6 +379,7 @@ static void test_auth_triplets(void) uint32_t local_tlli = 0xffeeddcc; printf("Testing authentication triplet handling\n"); + sgsn = sgsn_instance_alloc(tall_sgsn_ctx); /* Check for emptiness */ OSMO_ASSERT(gprs_subscr_get_by_imsi(imsi1) == NULL); @@ -571,6 +568,7 @@ static void test_subscriber_gsup(void) printf("Testing subscriber GSUP handling\n"); update_subscriber_data_cb = my_dummy_sgsn_update_subscriber_data; + sgsn = sgsn_instance_alloc(tall_sgsn_ctx); /* Check for emptiness */ OSMO_ASSERT(gprs_subscr_get_by_imsi(imsi1) == NULL); @@ -747,6 +745,7 @@ static void test_gmm_detach(void) uint32_t local_tlli; printf("Testing GMM detach\n"); + sgsn = sgsn_instance_alloc(tall_sgsn_ctx); /* DTAP - Detach Request (MO) */ /* normal detach, power_off = 0 */ @@ -788,6 +787,7 @@ static void test_gmm_detach_power_off(void) uint32_t local_tlli; printf("Testing GMM detach (power off)\n"); + sgsn = sgsn_instance_alloc(tall_sgsn_ctx); /* DTAP - Detach Request (MO) */ /* normal detach, power_off = 1 */ @@ -828,6 +828,7 @@ static void test_gmm_detach_no_mmctx(void) uint32_t local_tlli; printf("Testing GMM detach (no MMCTX)\n"); + sgsn = sgsn_instance_alloc(tall_sgsn_ctx); /* DTAP - Detach Request (MO) */ /* normal detach, power_off = 0 */ @@ -864,6 +865,7 @@ static void test_gmm_detach_accept_unexpected(void) uint32_t local_tlli; printf("Testing GMM detach accept (unexpected)\n"); + sgsn = sgsn_instance_alloc(tall_sgsn_ctx); /* DTAP - Detach Accept (MT) */ /* normal detach */ @@ -900,6 +902,7 @@ static void test_gmm_status_no_mmctx(void) uint32_t local_tlli; printf("Testing GMM Status (no MMCTX)\n"); + sgsn = sgsn_instance_alloc(tall_sgsn_ctx); /* DTAP - GMM Status, protocol error */ static const unsigned char gmm_status[] = { @@ -1194,6 +1197,7 @@ static void test_gmm_reject(void) }; printf("Testing GMM reject\n"); + sgsn = sgsn_instance_alloc(tall_sgsn_ctx); /* reset the PRNG used by sgsn_alloc_ptmsi */ srand(1); @@ -1240,6 +1244,9 @@ static void test_gmm_cancel(void) uint32_t foreign_tlli; uint32_t local_tlli = 0; struct gprs_llc_lle *lle; + + sgsn = sgsn_instance_alloc(tall_sgsn_ctx); + sgsn->cfg.gea_encryption_mask = 0x1; const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy; /* DTAP - Attach Request */ @@ -1270,8 +1277,7 @@ static void test_gmm_cancel(void) }; printf("Testing cancellation\n"); - - sgsn_inst.cfg.auth_policy = SGSN_AUTH_POLICY_OPEN; + sgsn->cfg.auth_policy = SGSN_AUTH_POLICY_OPEN; foreign_tlli = gprs_tmsi2tlli(0xc0000023, TLLI_FOREIGN); @@ -1343,6 +1349,7 @@ static void test_apn_matching(void) struct apn_ctx *actx, *actxs[9]; printf("Testing APN matching\n"); + sgsn = sgsn_instance_alloc(tall_sgsn_ctx); actxs[0] = sgsn_apn_ctx_find_alloc("*.test", ""); actxs[1] = sgsn_apn_ctx_find_alloc("*.def.test", ""); @@ -1432,9 +1439,6 @@ static void test_apn_matching(void) cleanup_test(); } -struct sgsn_subscriber_pdp_data* sgsn_subscriber_pdp_data_alloc( - struct sgsn_subscriber_data *sdata); - static void test_ggsn_selection(void) { struct apn_ctx *actxs[4]; @@ -1453,6 +1457,7 @@ static void test_ggsn_selection(void) printf("Testing GGSN selection\n"); osmo_gsup_client_send_cb = my_gsup_client_send_dummy; + sgsn = sgsn_instance_alloc(tall_sgsn_ctx); /* Check for emptiness */ OSMO_ASSERT(gprs_subscr_get_by_imsi(imsi1) == NULL); @@ -1471,9 +1476,9 @@ static void test_ggsn_selection(void) /* TODO: Add PDP info entries to s1 */ - ggcs[0] = sgsn_ggsn_ctx_find_alloc(0); - ggcs[1] = sgsn_ggsn_ctx_find_alloc(1); - ggcs[2] = sgsn_ggsn_ctx_find_alloc(2); + ggcs[0] = sgsn_ggsn_ctx_find_alloc(sgsn, 0); + ggcs[1] = sgsn_ggsn_ctx_find_alloc(sgsn, 1); + ggcs[2] = sgsn_ggsn_ctx_find_alloc(sgsn, 2); actxs[0] = sgsn_apn_ctx_find_alloc("test.apn", "123456"); actxs[0]->ggsn = ggcs[0]; @@ -1484,13 +1489,14 @@ static void test_ggsn_selection(void) pdp_data = sgsn_subscriber_pdp_data_alloc(s1->sgsn_data); pdp_data->context_id = 1; - pdp_data->pdp_type = 0x0121; + pdp_data->pdp_type_org = PDP_TYPE_ORG_IETF; + pdp_data->pdp_type_nr = PDP_TYPE_N_IETF_IPv4; osmo_strlcpy(pdp_data->apn_str, "*", sizeof(pdp_data->apn_str)); /* Resolve GGSNs */ tp.lv[GSM48_IE_GSM_APN].len = - gprs_str_to_apn(apn_enc, sizeof(apn_enc), "Test.Apn"); + osmo_apn_from_str(apn_enc, sizeof(apn_enc), "Test.Apn"); ggc = sgsn_mm_ctx_find_ggsn_ctx(ctx, &tp, &gsm_cause, apn_str); OSMO_ASSERT(ggc != NULL); @@ -1498,7 +1504,7 @@ static void test_ggsn_selection(void) OSMO_ASSERT(strcmp(apn_str, "Test.Apn") == 0); tp.lv[GSM48_IE_GSM_APN].len = - gprs_str_to_apn(apn_enc, sizeof(apn_enc), "Other.Apn"); + osmo_apn_from_str(apn_enc, sizeof(apn_enc), "Other.Apn"); ggc = sgsn_mm_ctx_find_ggsn_ctx(ctx, &tp, &gsm_cause, apn_str); OSMO_ASSERT(ggc != NULL); @@ -1524,7 +1530,7 @@ static void test_ggsn_selection(void) tp.lv[GSM48_IE_GSM_APN].val = apn_enc; tp.lv[GSM48_IE_GSM_APN].len = - gprs_str_to_apn(apn_enc, sizeof(apn_enc), "Foo.Bar"); + osmo_apn_from_str(apn_enc, sizeof(apn_enc), "Foo.Bar"); ggc = sgsn_mm_ctx_find_ggsn_ctx(ctx, &tp, &gsm_cause, apn_str); OSMO_ASSERT(ggc == NULL); @@ -1541,7 +1547,7 @@ static void test_ggsn_selection(void) osmo_strlcpy(pdp_data->apn_str, "Test.Apn", sizeof(pdp_data->apn_str)); tp.lv[GSM48_IE_GSM_APN].len = - gprs_str_to_apn(apn_enc, sizeof(apn_enc), "Test.Apn"); + osmo_apn_from_str(apn_enc, sizeof(apn_enc), "Test.Apn"); ggc = sgsn_mm_ctx_find_ggsn_ctx(ctx, &tp, &gsm_cause, apn_str); OSMO_ASSERT(ggc != NULL); @@ -1549,7 +1555,7 @@ static void test_ggsn_selection(void) OSMO_ASSERT(strcmp(apn_str, "Test.Apn") == 0); tp.lv[GSM48_IE_GSM_APN].len = - gprs_str_to_apn(apn_enc, sizeof(apn_enc), "Other.Apn"); + osmo_apn_from_str(apn_enc, sizeof(apn_enc), "Other.Apn"); ggc = sgsn_mm_ctx_find_ggsn_ctx(ctx, &tp, &gsm_cause, apn_str); OSMO_ASSERT(ggc == NULL); @@ -1620,11 +1626,6 @@ static struct log_info_cat gprs_categories[] = { .description = "GPRS Packet Service", .enabled = 1, .loglevel = LOGL_DEBUG, }, - [DNS] = { - .name = "DNS", - .description = "GPRS Network Service (NS)", - .enabled = 1, .loglevel = LOGL_INFO, - }, [DLLC] = { .name = "DLLC", .description = "GPRS Logical Link Control Protocol (LLC)", @@ -1656,11 +1657,7 @@ int main(int argc, char **argv) tall_sgsn_ctx = talloc_named_const(osmo_sgsn_ctx, 0, "sgsn"); msgb_ctx = msgb_talloc_ctx_init(osmo_sgsn_ctx, 0); - sgsn_rate_ctr_init(); - sgsn_auth_init(sgsn); - gprs_subscr_init(sgsn); vty_init(&vty_info); - sgsn_vty_init(&sgsn->cfg); test_llme(); test_subscriber(); @@ -1680,7 +1677,7 @@ int main(int argc, char **argv) talloc_report_full(osmo_sgsn_ctx, stderr); OSMO_ASSERT(talloc_total_blocks(msgb_ctx) == 1); - OSMO_ASSERT(talloc_total_blocks(tall_sgsn_ctx) == 2); + OSMO_ASSERT(talloc_total_blocks(tall_sgsn_ctx) == 1); return 0; } |