gbproxy/test: Add assertions, improve test coverage

This patch add explicit tests for
  - gbproxy_peer_by_bvci
  - gbproxy_peer_by_nsei
  - gbproxy_cleanup_peers
  - gbproxy_peer_by_rai
  - gbproxy_peer_by_lai
  - gbproxy_peer_by_lac
and for messages with an unknown TLLI sent by the SGSN.

Sponsored-by: On-Waves ehf
This commit is contained in:
Jacob Erlbeck 2014-09-04 11:08:50 +02:00
parent 31591142e9
commit 7fb26c2943
3 changed files with 86 additions and 0 deletions

View File

@ -249,6 +249,8 @@ struct gbproxy_peer *gbproxy_peer_by_rai(
struct gbproxy_config *cfg, const uint8_t *ra);
struct gbproxy_peer *gbproxy_peer_by_lai(
struct gbproxy_config *cfg, const uint8_t *la);
struct gbproxy_peer *gbproxy_peer_by_lac(
struct gbproxy_config *cfg, const uint8_t *la);
struct gbproxy_peer *gbproxy_peer_by_bssgp_tlv(
struct gbproxy_config *cfg, struct tlv_parsed *tp);
struct gbproxy_peer *gbproxy_peer_alloc(struct gbproxy_config *cfg, uint16_t bvci);

View File

@ -166,6 +166,13 @@ static int dump_peers(FILE *stream, int indent, time_t now,
return 0;
}
const uint8_t *convert_ra(struct gprs_ra_id *raid)
{
static uint8_t buf[6];
gsm48_construct_ra(buf, raid);
return buf;
}
/* DTAP - Attach Request */
static const unsigned char dtap_attach_req[] = {
0x08, 0x01, 0x02, 0xf5, 0xe0, 0x21, 0x08, 0x02,
@ -1149,6 +1156,24 @@ static void test_gbproxy()
send_ns_unitdata(nsi, NULL, &sgsn_peer, 0x10ff, (uint8_t *)"", 0);
/* Find peer */
OSMO_ASSERT(gbproxy_peer_by_bvci(&gbcfg, 0xeeee) == NULL);
OSMO_ASSERT(gbproxy_peer_by_bvci(&gbcfg, 0x1000) == NULL);
OSMO_ASSERT(gbproxy_peer_by_bvci(&gbcfg, 0x1012) != NULL);
OSMO_ASSERT(gbproxy_peer_by_nsei(&gbcfg, 0xeeee) == NULL);
OSMO_ASSERT(gbproxy_peer_by_nsei(&gbcfg, 0x1012) == NULL);
OSMO_ASSERT(gbproxy_peer_by_nsei(&gbcfg, 0x1000) != NULL);
/* Cleanup */
OSMO_ASSERT(gbproxy_cleanup_peers(&gbcfg, 0, 0) == 0);
OSMO_ASSERT(gbproxy_cleanup_peers(&gbcfg, 0x1000, 0xeeee) == 0);
OSMO_ASSERT(gbproxy_cleanup_peers(&gbcfg, 0, 0x1002) == 0);
OSMO_ASSERT(gbproxy_cleanup_peers(&gbcfg, 0x1000, 0x1012) == 1);
OSMO_ASSERT(gbproxy_cleanup_peers(&gbcfg, 0x1000, 0x1012) == 0);
dump_peers(stdout, 0, 0, &gbcfg);
dump_global(stdout, 0);
gbprox_reset(&gbcfg);
@ -1376,6 +1401,18 @@ static void test_gbproxy_ra_patching()
GPRS_SAPI_GMM, 1,
dtap_attach_acc, sizeof(dtap_attach_acc));
OSMO_ASSERT(gbproxy_peer_by_rai(&gbcfg, convert_ra(&rai_bss)) != NULL);
OSMO_ASSERT(gbproxy_peer_by_rai(&gbcfg, convert_ra(&rai_sgsn)) == NULL);
OSMO_ASSERT(gbproxy_peer_by_rai(&gbcfg, convert_ra(&rai_unknown)) == NULL);
OSMO_ASSERT(gbproxy_peer_by_lai(&gbcfg, convert_ra(&rai_bss)) != NULL);
OSMO_ASSERT(gbproxy_peer_by_lai(&gbcfg, convert_ra(&rai_sgsn)) == NULL);
OSMO_ASSERT(gbproxy_peer_by_lai(&gbcfg, convert_ra(&rai_unknown)) == NULL);
OSMO_ASSERT(gbproxy_peer_by_lac(&gbcfg, convert_ra(&rai_bss)) != NULL);
OSMO_ASSERT(gbproxy_peer_by_lac(&gbcfg, convert_ra(&rai_sgsn)) != NULL);
OSMO_ASSERT(gbproxy_peer_by_lac(&gbcfg, convert_ra(&rai_unknown)) == NULL);
tlli_info = gbproxy_find_tlli_by_sgsn_tlli(peer, local_tlli);
OSMO_ASSERT(tlli_info);
OSMO_ASSERT(tlli_info->tlli.assigned == local_tlli);
@ -1532,6 +1569,7 @@ static void test_gbproxy_ptmsi_patching()
const uint32_t local_sgsn_tlli2 = 0xe0987654;
const uint32_t local_sgsn_tlli3 = 0xe0543210;
const uint32_t random_sgsn_tlli = 0x7c69fb81;
const uint32_t unknown_sgsn_tlli = 0xeebadbad;
const uint32_t bss_ptmsi = 0xc00f7304;
const uint32_t bss_ptmsi2 = 0xe656aa1f;
@ -1541,6 +1579,7 @@ static void test_gbproxy_ptmsi_patching()
const uint32_t local_bss_tlli3 = 0xead4775a;
const uint32_t foreign_bss_tlli = 0x8000dead;
const uint8_t imsi[] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18};
struct gbproxy_tlli_info *tlli_info;
struct gbproxy_peer *peer;
@ -1801,6 +1840,18 @@ static void test_gbproxy_ptmsi_patching()
dump_global(stdout, 0);
/* Bad case: Invalid TLLI from SGSN (IMSI unknown) */
send_llc_dl_ui(nsi, "GMM INFO", &sgsn_peer, 0x1002,
unknown_sgsn_tlli, 1, NULL, 0,
GPRS_SAPI_GMM, 2,
dtap_gmm_information, sizeof(dtap_gmm_information));
/* Bad case: Invalid TLLI from SGSN (IMSI known) */
send_llc_dl_ui(nsi, "GMM INFO", &sgsn_peer, 0x1002,
unknown_sgsn_tlli, 1, imsi, sizeof(imsi),
GPRS_SAPI_GMM, 3,
dtap_gmm_information, sizeof(dtap_gmm_information));
/* Detach */
send_llc_ul_ui(nsi, "DETACH REQ", &bss_peer[0], 0x1002,
local_bss_tlli3, &rai_bss, cell_id,

View File

@ -799,6 +799,13 @@ MESSAGE to SGSN at 0x05060708:32000, msg length 14
result (UNITDATA) = 14
Peers:
NSEI 8192, BVCI 8194, not blocked, RAI 112-332-16464-96
NSEI mismatch : 1
TLLI-Cache: 0
NSEI 8192, BVCI 4098, not blocked, RAI 112-332-16464-96
NSEI mismatch : 1
TLLI-Cache: 0
Gbproxy global:
Invalid BVC Identifier : 1
=== test_gbproxy_ident_changes ===
@ -2443,6 +2450,30 @@ result (BVC_SUSPEND_ACK) = 22
Gbproxy global:
Invalid Routing Area Identifier : 1
Patch error: no peer : 1
PROCESSING GMM INFO from 0x05060708:32000
00 00 10 02 00 ee ba db ad 00 50 20 16 82 02 58 13 99 18 b3 43 2b 25 96 62 00 60 80 9a c2 c6 62 00 60 80 ba c8 c6 62 00 60 80 00 0a 82 08 02 00 83 00 00 00 0e 88 41 c0 09 08 21 04 ba 3d
CALLBACK, event 0, msg length 58, bvci 0x1002
00 00 10 02 00 ee ba db ad 00 50 20 16 82 02 58 13 99 18 b3 43 2b 25 96 62 00 60 80 9a c2 c6 62 00 60 80 ba c8 c6 62 00 60 80 00 0a 82 08 02 00 83 00 00 00 0e 88 41 c0 09 08 21 04 ba 3d
NS UNITDATA MESSAGE to BSS, BVCI 0x1002, msg length 58 (gprs_ns_sendmsg)
MESSAGE to BSS at 0x01020304:1111, msg length 62
00 00 10 02 00 ee ba db ad 00 50 20 16 82 02 58 13 99 18 b3 43 2b 25 96 62 00 60 80 9a c2 c6 62 00 60 80 ba c8 c6 62 00 60 80 00 0a 82 08 02 00 83 00 00 00 0e 88 41 c0 09 08 21 04 ba 3d
result (GMM INFO) = 62
PROCESSING GMM INFO from 0x05060708:32000
00 00 10 02 00 ee ba db ad 00 50 20 16 82 02 58 13 99 18 b3 43 2b 25 96 62 00 60 80 9a c2 c6 62 00 60 80 ba c8 c6 62 00 60 80 00 0a 82 08 02 0d 88 11 12 13 14 15 16 17 18 00 81 00 0e 88 41 c0 0d 08 21 68 71 6b
CALLBACK, event 0, msg length 66, bvci 0x1002
00 00 10 02 00 ee ba db ad 00 50 20 16 82 02 58 13 99 18 b3 43 2b 25 96 62 00 60 80 9a c2 c6 62 00 60 80 ba c8 c6 62 00 60 80 00 0a 82 08 02 0d 88 11 12 13 14 15 16 17 18 00 81 00 0e 88 41 c0 0d 08 21 68 71 6b
NS UNITDATA MESSAGE to BSS, BVCI 0x1002, msg length 66 (gprs_ns_sendmsg)
MESSAGE to BSS at 0x01020304:1111, msg length 70
00 00 10 02 00 ee ba db ad 00 50 20 16 82 02 58 13 99 18 b3 43 2b 25 96 62 00 60 80 9a c2 c6 62 00 60 80 ba c8 c6 62 00 60 80 00 0a 82 08 02 0d 88 11 12 13 14 15 16 17 18 00 81 00 0e 88 41 c0 0d 08 21 68 71 6b
result (GMM INFO) = 70
PROCESSING DETACH REQ from 0x01020304:1111
00 00 10 02 01 ea d4 77 5a 00 00 04 08 88 11 22 33 40 50 60 12 34 00 80 0e 00 15 01 c0 1d 08 05 01 18 05 f4 ef e2 b7 00 19 03 b9 97 cb aa cc a3
@ -2465,6 +2496,7 @@ Peers:
P-TMSI patched (BSS ): 1
P-TMSI patched (SGSN): 3
Attach Request count : 1
TLLI from SGSN unknown : 2
TLLI cache size : 1
TLLI-Cache: 1
TLLI ead4775a -> e0543210, IMSI 12131415161718, AGE 0, IMSI matches
@ -2490,6 +2522,7 @@ Peers:
P-TMSI patched (BSS ): 1
P-TMSI patched (SGSN): 3
Attach Request count : 1
TLLI from SGSN unknown : 2
TLLI-Cache: 0
Gbproxy global:
Invalid Routing Area Identifier : 1