[PATCH 5/9] mgcp/test: Show the number of dummy packets sent

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
Tue Jan 7 11:07:47 UTC 2014


This patch extends the test_messages test to show the number of dummy
packets that has been passed to sendto(). This way, dummy packets are
even being counted when sendto() itself failes (e.g. due to the fd
being -1).

Sponsored-by: On-Waves ehf
---
 openbsc/tests/mgcp/mgcp_test.c |   32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/openbsc/tests/mgcp/mgcp_test.c b/openbsc/tests/mgcp/mgcp_test.c
index 538dc9f..7eeef99 100644
--- a/openbsc/tests/mgcp/mgcp_test.c
+++ b/openbsc/tests/mgcp/mgcp_test.c
@@ -16,6 +16,8 @@
  * 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/>.
  */
+#undef _GNU_SOURCE
+#define _GNU_SOURCE
 
 #include <openbsc/mgcp.h>
 #include <openbsc/mgcp_internal.h>
@@ -24,6 +26,7 @@
 #include <osmocom/core/talloc.h>
 #include <string.h>
 #include <limits.h>
+#include <dlfcn.h>
 
 char *strline_r(char *str, char **saveptr);
 
@@ -293,6 +296,31 @@ static int mgcp_test_policy_cb(struct mgcp_trunk_config *cfg, int endpoint,
 	return MGCP_POLICY_CONT;
 }
 
+#define MGCP_DUMMY_LOAD 0x23
+static int dummy_packets = 0;
+/* override and forward */
+ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,
+		const struct sockaddr *dest_addr, socklen_t addrlen)
+{
+	typedef ssize_t (*sendto_t)(int, const void *, size_t, int,
+			const struct sockaddr *, socklen_t);
+	static sendto_t real_sendto = NULL;
+	uint32_t dest_host = htonl(((struct sockaddr_in *)dest_addr)->sin_addr.s_addr);
+	int      dest_port = htons(((struct sockaddr_in *)dest_addr)->sin_port);
+
+	if (!real_sendto)
+		real_sendto = dlsym(RTLD_NEXT, "sendto");
+
+	if (len == 1 && ((const char *)buf)[0] == MGCP_DUMMY_LOAD ) {
+		fprintf(stderr, "Dummy packet to 0x%08x:%d, msg length %d\n%s\n\n",
+		       dest_host, dest_port,
+		       len, osmo_hexdump(buf, len));
+		dummy_packets += 1;
+	}
+
+	return real_sendto(sockfd, buf, len, flags, dest_addr, addrlen);
+}
+
 static void test_messages(void)
 {
 	struct mgcp_config *cfg;
@@ -326,6 +354,7 @@ static void test_messages(void)
 		printf("Testing %s\n", t->name);
 
 		last_endpoint = -1;
+		dummy_packets = 0;
 
 		inp = create_msg(t->req);
 		msg = mgcp_handle_message(cfg, inp);
@@ -337,6 +366,9 @@ static void test_messages(void)
 			printf("%s failed '%s'\n", t->name, (char *) msg->data);
 		msgb_free(msg);
 
+		if (dummy_packets)
+			printf("Dummy packets: %d\n", dummy_packets);
+
 		if (last_endpoint != -1) {
 			endp = &cfg->trunk.endpoints[last_endpoint];
 
-- 
1.7.9.5





More information about the OpenBSC mailing list