aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/tests/bsc-nat/bsc_nat_test.c
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2010-04-01 06:48:52 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2010-06-15 20:24:10 +0800
commit76c83548635fd0c30c16d5c1b38e5ed946720684 (patch)
treece3c3e97ba4ebf93d5f6c78fa3318919adea7b4e /openbsc/tests/bsc-nat/bsc_nat_test.c
parentfc9bd2300075258566fc9a287e57734f6f9d83c7 (diff)
nat: Test rewriting of MGCP messages to patch ip and port
Add code to change the ip and port for audio data inside MGCP messages. This is needed because the BSS might be behind the NAT and can not reach the network directly and might be behind a nat so the announced sourceport is not the one as we see it.
Diffstat (limited to 'openbsc/tests/bsc-nat/bsc_nat_test.c')
-rw-r--r--openbsc/tests/bsc-nat/bsc_nat_test.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/openbsc/tests/bsc-nat/bsc_nat_test.c b/openbsc/tests/bsc-nat/bsc_nat_test.c
index 30f1490f1..217c4f415 100644
--- a/openbsc/tests/bsc-nat/bsc_nat_test.c
+++ b/openbsc/tests/bsc-nat/bsc_nat_test.c
@@ -410,6 +410,40 @@ static void test_mgcp_find(void)
talloc_free(nat);
}
+static void test_mgcp_rewrite(void)
+{
+ int i;
+ struct msgb *input, *output;
+ fprintf(stderr, "Test rewriting MGCP messages.\n");
+
+ input = msgb_alloc(4096, "input");
+
+ for (i = 0; i < ARRAY_SIZE(mgcp_messages); ++i) {
+ const char *orig = mgcp_messages[i].orig;
+ const char *patc = mgcp_messages[i].patch;
+ const char *ip = mgcp_messages[i].ip;
+ const int port = mgcp_messages[i].port;
+
+ copy_to_msg(input, (const u_int8_t *) orig, strlen(orig) + 1);
+
+ output = bsc_mgcp_rewrite(input, ip, port);
+ if (msgb_l2len(output) != strlen(patc)) {
+ fprintf(stderr, "Wrong sizes for test: %d %d != %d != %d\n", i, msgb_l2len(output), strlen(patc), strlen(orig));
+ fprintf(stderr, "String '%s' vs '%s'\n", (const char *) output->l2h, patc);
+ abort();
+ }
+
+ if (memcmp(output->l2h, patc, msgb_l2len(output)) != 0) {
+ fprintf(stderr, "Broken on %d msg: '%s'\n", i, (const char *) output->l2h);
+ abort();
+ }
+
+ msgb_free(output);
+ }
+
+ msgb_free(input);
+}
+
int main(int argc, char **argv)
{
struct debug_target *stderr_target;
@@ -423,6 +457,7 @@ int main(int argc, char **argv)
test_paging();
test_mgcp_ass_tracking();
test_mgcp_find();
+ test_mgcp_rewrite();
return 0;
}