[PATCH 3/8] mgcp: Add tests for payload types in MGCP messages

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Jacob Erlbeck jerlbeck at sysmocom.de
Fri Nov 29 12:43:45 UTC 2013


These tests mainly check whether the SDP parsing works properly by
looking at the payload type detected.

Sponsored-by: On-Waves ehf
---
 openbsc/tests/bsc-nat/bsc_data.c     |    5 +++
 openbsc/tests/bsc-nat/bsc_nat_test.c |   16 ++++++-
 openbsc/tests/mgcp/mgcp_test.c       |   82 +++++++++++++++++++++++++++++++---
 openbsc/tests/mgcp/mgcp_test.ok      |    1 +
 4 files changed, 98 insertions(+), 6 deletions(-)

diff --git a/openbsc/tests/bsc-nat/bsc_data.c b/openbsc/tests/bsc-nat/bsc_data.c
index 5a76689..d1f8ebc 100644
--- a/openbsc/tests/bsc-nat/bsc_data.c
+++ b/openbsc/tests/bsc-nat/bsc_data.c
@@ -177,6 +177,7 @@ struct mgcp_patch_test {
 	const char *patch;
 	const char *ip;
 	const int port;
+	const int payload_type;
 };
 
 static const struct mgcp_patch_test mgcp_messages[] = {
@@ -191,24 +192,28 @@ static const struct mgcp_patch_test mgcp_messages[] = {
 		.patch = crcx_resp_patched,
 		.ip = "10.0.0.1",
 		.port = 999,
+		.payload_type = 98,
 	},
 	{
 		.orig = mdcx,
 		.patch = mdcx_patched,
 		.ip = "10.0.0.23",
 		.port = 6666,
+		.payload_type = 126,
 	},
 	{
 		.orig = mdcx_resp,
 		.patch = mdcx_resp_patched,
 		.ip = "10.0.0.23",
 		.port = 5555,
+		.payload_type = 98,
 	},
 	{
 		.orig = mdcx_resp2,
 		.patch = mdcx_resp_patched2,
 		.ip = "10.0.0.23",
 		.port = 5555,
+		.payload_type = 98,
 	},
 };
 
diff --git a/openbsc/tests/bsc-nat/bsc_nat_test.c b/openbsc/tests/bsc-nat/bsc_nat_test.c
index 5158f46..3320e06 100644
--- a/openbsc/tests/bsc-nat/bsc_nat_test.c
+++ b/openbsc/tests/bsc-nat/bsc_nat_test.c
@@ -624,10 +624,24 @@ static void test_mgcp_rewrite(void)
 		const char *patc = mgcp_messages[i].patch;
 		const char *ip = mgcp_messages[i].ip;
 		const int port = mgcp_messages[i].port;
+		const int expected_payload_type = mgcp_messages[i].payload_type;
+		int payload_type = -1;
 
 		char *input = strdup(orig);
 
-		output = bsc_mgcp_rewrite(input, strlen(input), 0x1e, ip, port);
+		output = bsc_mgcp_rewrite(input, strlen(input), 0x1e,
+					  ip, port);
+
+		if (payload_type != -1) {
+			fprintf(stderr, "Found media payload type %d in SDP data\n",
+				payload_type);
+			if (payload_type != expected_payload_type) {
+				printf("Wrong payload type %d (expected %d)\n",
+				       payload_type, expected_payload_type);
+				abort();
+			}
+		}
+
 		if (msgb_l2len(output) != strlen(patc)) {
 			printf("Wrong sizes for test: %d  %d != %d != %d\n", i, msgb_l2len(output), strlen(patc), strlen(orig));
 			printf("String '%s' vs '%s'\n", (const char *) output->l2h, patc);
diff --git a/openbsc/tests/mgcp/mgcp_test.c b/openbsc/tests/mgcp/mgcp_test.c
index 362f029..0aebb4c 100644
--- a/openbsc/tests/mgcp/mgcp_test.c
+++ b/openbsc/tests/mgcp/mgcp_test.c
@@ -82,6 +82,26 @@ static void test_strline(void)
 		 "t=0 0\r\n"			\
 		 "m=audio 0 RTP/AVP 126\r\n"	\
 		 "a=rtpmap:126 AMR/8000\r\n"
+#define MDCX4 "MDCX 18983216 1 at mgw MGCP 1.0\r\n" \
+		 "C: 2\r\n"          \
+		 "I: 1\r\n"                    \
+		 "L: p:20, a:AMR, nt:IN\r\n"    \
+		 "\n"				\
+		 "v=0\r\n"			\
+		 "o=- 1 23 IN IP4 0.0.0.0\r\n"	\
+		 "c=IN IP4 0.0.0.0\r\n"		\
+		 "t=0 0\r\n"			\
+		 "m=audio 4441 RTP/AVP 99\r\n"	\
+		 "a=rtpmap:99 AMR/8000\r\n"
+#define MDCX4_RET "200 18983216 OK\r\n"		\
+		 "I: 1\n"			\
+		 "\n"				\
+		 "v=0\r\n"			\
+		 "o=- 1 23 IN IP4 0.0.0.0\r\n"	\
+		 "c=IN IP4 0.0.0.0\r\n"		\
+		 "t=0 0\r\n"			\
+		 "m=audio 0 RTP/AVP 126\r\n"	\
+		 "a=rtpmap:126 AMR/8000\r\n"
 
 #define SHORT2	"CRCX 1"
 #define SHORT2_RET "510 000000 FAIL\r\n"
@@ -145,10 +165,16 @@ static void test_strline(void)
 #define RQNT1_RET "200 186908780 OK\r\n"
 #define RQNT2_RET "200 186908781 OK\r\n"
 
+#define PTYPE_IGNORE 0 /* == default initializer */
+#define PTYPE_NONE 128
+#define PTYPE_NYI  PTYPE_NONE
+
 struct mgcp_test {
 	const char *name;
 	const char *req;
 	const char *exp_resp;
+	int exp_net_ptype;
+	int exp_bts_ptype;
 };
 
 static const struct mgcp_test tests[] = {
@@ -156,10 +182,11 @@ static const struct mgcp_test tests[] = {
 	{ "AUEP2", AUEP2, AUEP2_RET },
 	{ "MDCX1", MDCX_WRONG_EP, MDCX_ERR_RET },
 	{ "MDCX2", MDCX_UNALLOCATED, MDCX_RET },
-	{ "CRCX", CRCX, CRCX_RET },
-	{ "MDCX3", MDCX3, MDCX3_RET },
-	{ "DLCX", DLCX, DLCX_RET },
-	{ "CRCX_ZYN", CRCX_ZYN, CRCX_ZYN_RET },
+	{ "CRCX", CRCX, CRCX_RET, PTYPE_NYI, 126 },
+	{ "MDCX3", MDCX3, MDCX3_RET, PTYPE_NONE, 126 },
+	{ "MDCX4", MDCX4, MDCX4_RET, 99, 126 },
+	{ "DLCX", DLCX, DLCX_RET, -1, -1 },
+	{ "CRCX_ZYN", CRCX_ZYN, CRCX_ZYN_RET, PTYPE_NYI, 126 },
 	{ "EMPTY", EMPTY, EMPTY_RET },
 	{ "SHORT1", SHORT, SHORT_RET },
 	{ "SHORT2", SHORT2, SHORT2_RET },
@@ -167,7 +194,7 @@ static const struct mgcp_test tests[] = {
 	{ "SHORT4", SHORT4, SHORT2_RET },
 	{ "RQNT1", RQNT, RQNT1_RET },
 	{ "RQNT2", RQNT2, RQNT2_RET },
-	{ "DLCX", DLCX, DLCX_RET },
+	{ "DLCX", DLCX, DLCX_RET, -1, -1 },
 };
 
 static const struct mgcp_test retransmit[] = {
@@ -188,9 +215,21 @@ static struct msgb *create_msg(const char *str)
 	return msg;
 }
 
+static int last_endpoint = -1;
+
+static int mgcp_test_policy_cb(struct mgcp_trunk_config *cfg, int endpoint,
+			       int state, const char *transactio_id)
+{
+	fprintf(stderr, "Policy CB got state %d on endpoint %d\n",
+		state, endpoint);
+	last_endpoint = endpoint;
+	return MGCP_POLICY_CONT;
+}
+
 static void test_messages(void)
 {
 	struct mgcp_config *cfg;
+	struct mgcp_endpoint *endp;
 	int i;
 
 	cfg = mgcp_config_alloc();
@@ -198,8 +237,16 @@ static void test_messages(void)
 	cfg->trunk.number_endpoints = 64;
 	mgcp_endpoints_allocate(&cfg->trunk);
 
+	cfg->policy_cb = mgcp_test_policy_cb;
+
 	mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1));
 
+	/* reset endpoints */
+	for (i = 0; i < cfg->trunk.number_endpoints; i++) {
+		endp = &cfg->trunk.endpoints[i];
+		endp->net_end.payload_type = PTYPE_NONE;
+	}
+
 	for (i = 0; i < ARRAY_SIZE(tests); i++) {
 		const struct mgcp_test *t = &tests[i];
 		struct msgb *inp;
@@ -207,6 +254,8 @@ static void test_messages(void)
 
 		printf("Testing %s\n", t->name);
 
+		last_endpoint = -1;
+
 		inp = create_msg(t->req);
 		msg = mgcp_handle_message(cfg, inp);
 		msgb_free(inp);
@@ -216,6 +265,29 @@ static void test_messages(void)
 		} else if (strcmp((char *) msg->data, t->exp_resp) != 0)
 			printf("%s failed '%s'\n", t->name, (char *) msg->data);
 		msgb_free(msg);
+
+		/* Check detected payload type */
+		if (t->exp_net_ptype != PTYPE_IGNORE ||
+		    t->exp_bts_ptype != PTYPE_IGNORE) {
+			OSMO_ASSERT(last_endpoint != -1);
+			endp = &cfg->trunk.endpoints[last_endpoint];
+
+			fprintf(stderr, "endpoint %d: "
+				"payload type BTS %d (exp %d), NET %d (exp %d)\n",
+				last_endpoint,
+				endp->bts_end.payload_type, t->exp_bts_ptype,
+				endp->net_end.payload_type, t->exp_net_ptype);
+
+			if (t->exp_bts_ptype != PTYPE_IGNORE)
+				OSMO_ASSERT(endp->bts_end.payload_type ==
+					    t->exp_bts_ptype);
+			if (t->exp_net_ptype != PTYPE_IGNORE)
+				OSMO_ASSERT(endp->net_end.payload_type ==
+					    t->exp_net_ptype);
+
+			/* Reset them again for next test */
+			endp->net_end.payload_type = PTYPE_NONE;
+		}
 	}
 
 	talloc_free(cfg);
diff --git a/openbsc/tests/mgcp/mgcp_test.ok b/openbsc/tests/mgcp/mgcp_test.ok
index 429e0df..3bfd78b 100644
--- a/openbsc/tests/mgcp/mgcp_test.ok
+++ b/openbsc/tests/mgcp/mgcp_test.ok
@@ -17,6 +17,7 @@ Testing MDCX1
 Testing MDCX2
 Testing CRCX
 Testing MDCX3
+Testing MDCX4
 Testing DLCX
 Testing CRCX_ZYN
 Testing EMPTY
-- 
1.7.9.5





More information about the OpenBSC mailing list