nat: Add another test case for TP-SRR clearing and number rewrite

This commit is contained in:
Holger Hans Peter Freyther 2012-03-26 16:21:42 +02:00
parent 2f2be578cb
commit 09db1a44bc
2 changed files with 42 additions and 3 deletions

View File

@ -137,6 +137,16 @@ static const uint8_t smsc_rewrite_num_patched[] = {
0xbf, 0xeb, 0x20 0xbf, 0xeb, 0x20
}; };
static const uint8_t smsc_rewrite_num_patched_tp_srr[] = {
0x00, 0x2f, 0xfd, 0x06, 0x01, 0x13, 0x1e, 0x00,
0x01, 0x28, 0x01, 0x03, 0x25, 0x09, 0x01, 0x22,
0x00, 0x0c, 0x00, 0x07, 0x91, 0x36, 0x19, 0x08,
0x00, 0x10, 0x50, 0x16, 0x01, 0x0c, 0x0d, 0x91,
0x23, 0x51, 0x87, 0x86, 0x78, 0x46, 0xf5,
0x00, 0x00, 0x09, 0xcc, 0xb7, 0xbd, 0x0c, 0xca,
0xbf, 0xeb, 0x20
};
/* /*
* MGCP messages * MGCP messages
*/ */

View File

@ -1078,15 +1078,15 @@ static void test_sms_smsc_rewrite()
static void test_sms_number_rewrite(void) static void test_sms_number_rewrite(void)
{ {
struct msgb *msg = msgb_alloc(4096, "SMSC rewrite"), *out; struct msgb *msg, *out;
struct bsc_nat_parsed *parsed; struct bsc_nat_parsed *parsed;
const char *imsi = "515039900406700"; const char *imsi = "515039900406700";
struct bsc_nat *nat = bsc_nat_alloc(); struct bsc_nat *nat = bsc_nat_alloc();
/* a fake list */ /* a fake list */
struct osmo_config_list num_entries; struct osmo_config_list num_entries, clear_entries;
struct osmo_config_entry num_entry; struct osmo_config_entry num_entry, clear_entry;
INIT_LLIST_HEAD(&num_entries.entry); INIT_LLIST_HEAD(&num_entries.entry);
num_entry.mcc = "^515039"; num_entry.mcc = "^515039";
@ -1101,6 +1101,7 @@ static void test_sms_number_rewrite(void)
/* /*
* Check if the SMSC address is changed * Check if the SMSC address is changed
*/ */
msg = msgb_alloc(4096, "SMSC rewrite");
copy_to_msg(msg, smsc_rewrite, ARRAY_SIZE(smsc_rewrite)); copy_to_msg(msg, smsc_rewrite, ARRAY_SIZE(smsc_rewrite));
parsed = bsc_nat_parse(msg); parsed = bsc_nat_parse(msg);
if (!parsed) { if (!parsed) {
@ -1117,6 +1118,34 @@ static void test_sms_number_rewrite(void)
verify_msg(out, smsc_rewrite_num_patched, verify_msg(out, smsc_rewrite_num_patched,
ARRAY_SIZE(smsc_rewrite_num_patched)); ARRAY_SIZE(smsc_rewrite_num_patched));
msgb_free(out); msgb_free(out);
/*
* Now with TP-SRR rewriting enabled
*/
INIT_LLIST_HEAD(&clear_entries.entry);
clear_entry.mcc = "^515039";
clear_entry.option = "";
clear_entry.text = "";
llist_add_tail(&clear_entry.list, &clear_entries.entry);
bsc_nat_num_rewr_entry_adapt(nat, &nat->sms_clear_tp_srr, &clear_entries);
msg = msgb_alloc(4096, "SMSC rewrite");
copy_to_msg(msg, smsc_rewrite, ARRAY_SIZE(smsc_rewrite));
parsed = bsc_nat_parse(msg);
if (!parsed) {
printf("FAIL: Could not parse SMS\n");
abort();
}
out = bsc_nat_rewrite_msg(nat, msg, parsed, imsi);
if (out == msg) {
printf("FAIL: This should have changed.\n");
abort();
}
verify_msg(out, smsc_rewrite_num_patched_tp_srr,
ARRAY_SIZE(smsc_rewrite_num_patched_tp_srr));
msgb_free(out);
} }
int main(int argc, char **argv) int main(int argc, char **argv)