aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2011-09-15 19:30:20 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2011-09-15 19:30:20 +0200
commitb1dfc462dfa308d62b939847dbee2218c3a25fc1 (patch)
tree45e37d40b8cb870873a66586217e04ca7d0e84fa /tests
parent588754c7d391482de6b903e3a80a0df103d314d8 (diff)
cellmgr: Patch the MGCP messages and replace the domain name
Replace the domain name with a new name domain that can be configured via the VTY interface.
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/mgcp/Makefile.am6
-rw-r--r--tests/mgcp/mgcp_patch_test.c103
3 files changed, 110 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6ffa86d..d7cebd8 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1 +1 @@
-SUBDIRS = mtp patching isup
+SUBDIRS = mtp patching isup mgcp
diff --git a/tests/mgcp/Makefile.am b/tests/mgcp/Makefile.am
new file mode 100644
index 0000000..2e8db48
--- /dev/null
+++ b/tests/mgcp/Makefile.am
@@ -0,0 +1,6 @@
+INCLUDES = $(all_includes) -I$(top_srcdir)/include
+AM_CFLAGS=-Wall $(LIBOSMOCORE_CFLAGS)
+noinst_PROGRAMS = mgcp_patch_test
+
+mgcp_patch_test_SOURCES = mgcp_patch_test.c $(top_srcdir)/src/mgcp_patch.c
+mgcp_patch_test_LDADD = $(LIBOSMOCORE_LIBS)
diff --git a/tests/mgcp/mgcp_patch_test.c b/tests/mgcp/mgcp_patch_test.c
new file mode 100644
index 0000000..335cfcf
--- /dev/null
+++ b/tests/mgcp/mgcp_patch_test.c
@@ -0,0 +1,103 @@
+/*
+ * (C) 2011 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * (C) 2011 by On-Waves
+ * All Rights Reserved
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <mgcp_patch.h>
+#include <ss7_application.h>
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static const char mgcp_in[] =
+ "MDCX 23213 14@mgw MGCP 1.0\r\n"
+ "C: 4a84ad5d25f\r\n"
+ "I: %d\r\n"
+ "L: p:20, a:GSM-EFR, nt:IN\r\n"
+ "M: recvonly\r\n\r\n"
+ "v=0\r\n"
+ "o=- 258696477 0 IN IP4 172.16.1.107\r\n"
+ "s=-\r\n"
+ "c=IN IP4 172.16.1.107\r\n"
+ "t=0 0\r\n"
+ "m=audio 6666 RTP/AVP 127\r\n"
+ "a=rtpmap:127 GSM-EFR/8000/1\r\n"
+ "a=ptime:20\r\n"
+ "a=recvonly\r\n"
+ "m=image 4402 udptl t38\r\n"
+ "a=T38FaxVersion:0\r\n"
+ "a=T38MaxBitRate:14400\r\n";
+
+static const char mgcp_out[] =
+ "MDCX 23213 14@foo2 MGCP 1.0\r\n"
+ "C: 4a84ad5d25f\r\n"
+ "I: %d\r\n"
+ "L: p:20, a:GSM-EFR, nt:IN\r\n"
+ "M: recvonly\r\n\r\n"
+ "v=0\r\n"
+ "o=- 258696477 0 IN IP4 172.16.1.107\r\n"
+ "s=-\r\n"
+ "c=IN IP4 172.16.1.107\r\n"
+ "t=0 0\r\n"
+ "m=audio 6666 RTP/AVP 127\r\n"
+ "a=rtpmap:127 GSM-EFR/8000/1\r\n"
+ "a=ptime:20\r\n"
+ "a=recvonly\r\n"
+ "m=image 4402 udptl t38\r\n"
+ "a=T38FaxVersion:0\r\n"
+ "a=T38MaxBitRate:14400\r\n";
+
+#define ASSERT(a, cmp, b, text) \
+ if (!((a) cmp (b))) { \
+ fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, text); \
+ abort(); \
+ }
+
+static void test_endp_name_rewriting()
+{
+ struct ss7_application app;
+ memset(&app, 0, sizeof(app));
+
+ app.mgcp_domain_name = "foo2";
+
+ /* prepare */
+ struct msgb *msg = msgb_alloc_headroom(4096, 128, "test");
+ msg->l2h = msgb_put(msg, strlen(mgcp_in));
+ memcpy(msg->l2h, mgcp_in, msgb_l2len(msg));
+
+ /* patch it now */
+ struct msgb *msg_out = mgcp_patch(&app, msg);
+ msg_out->l2h[msgb_l2len(msg_out)] = '\0';
+#ifdef DEBUG
+ printf("Want : '%s'\n", mgcp_out);
+ printf("Outpu: '%s'\n", (const char *) msg_out->l2h);
+ printf("%s\n", osmo_hexdump(mgcp_out, strlen(mgcp_out)));
+ printf("%s\n", osmo_hexdump(msg_out->l2h, msgb_l2len(msg_out)));
+#endif
+ ASSERT(msg_out, !=, msg, "msg should not be the same");
+
+ ASSERT(msgb_l2len(msg_out), ==, strlen(mgcp_out), "Output size wrong");
+ ASSERT(strcmp((const char *)msg_out->l2h, mgcp_out), ==, 0, "Text don't match");
+}
+
+int main(int argc, char **argv)
+{
+ test_endp_name_rewriting();
+
+ return 0;
+}