Change in osmo-mgw[master]: trunk: get rid of virt_trunk pointer

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/gerrit-log@lists.osmocom.org/.

laforge gerrit-no-reply at lists.osmocom.org
Thu Jun 18 11:21:14 UTC 2020


laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-mgw/+/18590 )

Change subject: trunk: get rid of virt_trunk pointer
......................................................................

trunk: get rid of virt_trunk pointer

The virtual trunk is a pre-configured trunk that always exists. It is
kept separate from the trunk list using a separate pointer. This makes
thinks unecessarly complicated. Lets organize the trunk in the trunk
list like any other trunk, except that we automatically create it on
startup and assign it always the trunk id number 0.

Change-Id: I81934fbd211b225ab7920e78510729c8e22607b3
Related: OS#2659
---
M include/osmocom/mgcp/mgcp.h
M include/osmocom/mgcp/mgcp_trunk.h
M src/libosmo-mgcp/mgcp_osmux.c
M src/libosmo-mgcp/mgcp_protocol.c
M src/libosmo-mgcp/mgcp_trunk.c
M src/libosmo-mgcp/mgcp_vty.c
M tests/mgcp/mgcp_test.c
7 files changed, 155 insertions(+), 105 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved
  neels: Looks good to me, but someone else must approve



diff --git a/include/osmocom/mgcp/mgcp.h b/include/osmocom/mgcp/mgcp.h
index 989d138..33bfe71 100644
--- a/include/osmocom/mgcp/mgcp.h
+++ b/include/osmocom/mgcp/mgcp.h
@@ -152,11 +152,7 @@
 
 	uint32_t last_call_id;
 
-	/* trunk handling */
-
-	/* virtual trunk for RTP - RTP endpoints */
-	struct mgcp_trunk *virt_trunk;
-	/* physical trunks with underlying E1 endpoints */
+	/* list holding the trunks */
 	struct llist_head trunks;
 
 	enum mgcp_role role;
diff --git a/include/osmocom/mgcp/mgcp_trunk.h b/include/osmocom/mgcp/mgcp_trunk.h
index c230e9f..78d65e4 100644
--- a/include/osmocom/mgcp/mgcp_trunk.h
+++ b/include/osmocom/mgcp/mgcp_trunk.h
@@ -45,3 +45,8 @@
 int mgcp_trunk_alloc_endpts(struct mgcp_trunk *tcfg);
 struct mgcp_trunk *mgcp_trunk_by_num(const struct mgcp_config *cfg, int index);
 struct mgcp_trunk *mgcp_trunk_by_name(const struct mgcp_config *cfg, const char *epname);
+
+/* The virtual trunk is always created on trunk id 0 for historical reasons,
+ * use this define constant as ID when allocating a virtual trunk. Other
+ * trunks may be assigned with arbritrary id numbers */
+#define MGCP_VIRT_TRUNK_ID 0
diff --git a/src/libosmo-mgcp/mgcp_osmux.c b/src/libosmo-mgcp/mgcp_osmux.c
index ca8b5f0..9715e70 100644
--- a/src/libosmo-mgcp/mgcp_osmux.c
+++ b/src/libosmo-mgcp/mgcp_osmux.c
@@ -198,14 +198,15 @@
 osmux_conn_lookup(struct mgcp_config *cfg, uint8_t cid,
 		struct in_addr *from_addr)
 {
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(cfg, MGCP_VIRT_TRUNK_ID);
 	struct mgcp_endpoint *endp;
 	struct mgcp_conn *conn = NULL;
 	struct mgcp_conn_rtp * conn_rtp;
 	int i;
 
-	for (i=0; i<cfg->virt_trunk->number_endpoints; i++) {
+	for (i = 0; i < trunk->number_endpoints; i++) {
 
-		endp = cfg->virt_trunk->endpoints[i];
+		endp = trunk->endpoints[i];
 
 		llist_for_each_entry(conn, &endp->conns, entry) {
 			if (conn->type != MGCP_CONN_TYPE_RTP)
diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c
index 1d25c45..1e393e2 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -1498,16 +1498,14 @@
 
 	cfg->get_net_downlink_format_cb = &mgcp_get_net_downlink_format_default;
 
+	INIT_LLIST_HEAD(&cfg->trunks);
+
 	/* Allocate virtual trunk */
-	cfg->virt_trunk = mgcp_trunk_alloc(cfg, MGCP_TRUNK_VIRTUAL, 0);
-	if (!cfg->virt_trunk) {
+	if (!mgcp_trunk_alloc(cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID)) {
 		talloc_free(cfg);
 		return NULL;
 	}
 
-	/* Initalize list head for user configurable trunks */
-	INIT_LLIST_HEAD(&cfg->trunks);
-
         mgcp_ratectr_global_alloc(cfg, &cfg->ratectr);
 
 	return cfg;
diff --git a/src/libosmo-mgcp/mgcp_trunk.c b/src/libosmo-mgcp/mgcp_trunk.c
index 024db03..208604a 100644
--- a/src/libosmo-mgcp/mgcp_trunk.c
+++ b/src/libosmo-mgcp/mgcp_trunk.c
@@ -52,11 +52,7 @@
 
 	mgcp_trunk_set_keepalive(trunk, MGCP_KEEPALIVE_ONCE);
 
-	/* Note: Trunk Nr.0 is reserved as "virtual trunk",
-	 * it is not stored using a separate pointer and
-	 * not in the trunk list. */
-	if (nr > 0)
-		llist_add_tail(&trunk->entry, &cfg->trunks);
+	llist_add_tail(&trunk->entry, &cfg->trunks);
 
         mgcp_ratectr_trunk_alloc(cfg, &trunk->ratectr);
 
@@ -152,7 +148,7 @@
 
 	prefix_len = sizeof(MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK) - 1;
 	if (strncmp(epname, MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK, prefix_len) == 0) {
-		return cfg->virt_trunk;
+		return  mgcp_trunk_by_num(cfg, MGCP_VIRT_TRUNK_ID);
 	}
 
 	/* E1 trunks are not implemented yet, so we deny any request for an
@@ -175,7 +171,7 @@
 	if ((epname[0] >= '0' && epname[0] <= '9') || (epname[0] >= 'a' && epname[0] <= 'f')) {
 		LOGP(DLMGCP, LOGL_ERROR, "missing trunk prefix in endpoint name \"%s\", assuming trunk \"%s\"!\n", epname,
 		     MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK);
-		return cfg->virt_trunk;
+		return  mgcp_trunk_by_num(cfg, MGCP_VIRT_TRUNK_ID);
 	}
 
 	LOGP(DLMGCP, LOGL_ERROR, "unable to find trunk for endpoint name \"%s\"!\n", epname);
diff --git a/src/libosmo-mgcp/mgcp_vty.c b/src/libosmo-mgcp/mgcp_vty.c
index 4cfe3b5..938eef5 100644
--- a/src/libosmo-mgcp/mgcp_vty.c
+++ b/src/libosmo-mgcp/mgcp_vty.c
@@ -43,18 +43,6 @@
 
 static struct mgcp_config *g_cfg = NULL;
 
-static struct mgcp_trunk *find_trunk(struct mgcp_config *cfg, int nr)
-{
-	struct mgcp_trunk *trunk;
-
-	if (nr == 0)
-		trunk = cfg->virt_trunk;
-	else
-		trunk = mgcp_trunk_by_num(cfg, nr);
-
-	return trunk;
-}
-
 struct cmd_node mgcp_node = {
 	MGCP_NODE,
 	"%s(config-mgcp)# ",
@@ -69,7 +57,8 @@
 
 static int config_write_mgcp(struct vty *vty)
 {
-	struct mgcp_trunk *trunk = g_cfg->virt_trunk;
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	OSMO_ASSERT(trunk);
 
 	vty_out(vty, "mgcp%s", VTY_NEWLINE);
 	vty_out(vty, " domain %s%s", g_cfg->domain, VTY_NEWLINE);
@@ -328,8 +317,6 @@
 	struct mgcp_trunk *trunk;
 	int show_stats = argc >= 1;
 
-	dump_trunk(vty, g_cfg->virt_trunk, show_stats);
-
 	llist_for_each_entry(trunk, &g_cfg->trunks, entry)
 		dump_trunk(vty, trunk, show_stats);
 
@@ -388,7 +375,7 @@
 	struct mgcp_trunk *trunk;
 	int trunkidx = atoi(argv[0]);
 
-	trunk = find_trunk(g_cfg, trunkidx);
+	trunk = mgcp_trunk_by_num(g_cfg, trunkidx);
 	if (!trunk) {
 		vty_out(vty, "trunk %d not found%s", trunkidx, VTY_NEWLINE);
 		return CMD_WARNING;
@@ -578,11 +565,13 @@
       "Add extra fmtp for the SDP file\n" "Audio\n" "Fmtp-extra\n"
       "Extra Information\n")
 {
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	OSMO_ASSERT(trunk);
 	char *txt = argv_concat(argv, argc, 0);
 	if (!txt)
 		return CMD_WARNING;
 
-	osmo_talloc_replace_string(g_cfg, &g_cfg->virt_trunk->audio_fmtp_extra, txt);
+	osmo_talloc_replace_string(g_cfg, &trunk->audio_fmtp_extra, txt);
 	talloc_free(txt);
 	return CMD_SUCCESS;
 }
@@ -591,7 +580,9 @@
       cfg_mgcp_allow_transcoding_cmd,
       "allow-transcoding", "Allow transcoding\n")
 {
-	g_cfg->virt_trunk->no_audio_transcoding = 0;
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	OSMO_ASSERT(trunk);
+	trunk->no_audio_transcoding = 0;
 	return CMD_SUCCESS;
 }
 
@@ -599,7 +590,9 @@
       cfg_mgcp_no_allow_transcoding_cmd,
       "no allow-transcoding", NO_STR "Allow transcoding\n")
 {
-	g_cfg->virt_trunk->no_audio_transcoding = 1;
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	OSMO_ASSERT(trunk);
+	trunk->no_audio_transcoding = 1;
 	return CMD_SUCCESS;
 }
 
@@ -635,7 +628,9 @@
       "sdp audio-payload send-ptime",
       SDP_STR AUDIO_STR "Send SDP ptime (packet duration) attribute\n")
 {
-	g_cfg->virt_trunk->audio_send_ptime = 1;
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	OSMO_ASSERT(trunk);
+	trunk->audio_send_ptime = 1;
 	return CMD_SUCCESS;
 }
 
@@ -644,7 +639,9 @@
       "no sdp audio-payload send-ptime",
       NO_STR SDP_STR AUDIO_STR "Send SDP ptime (packet duration) attribute\n")
 {
-	g_cfg->virt_trunk->audio_send_ptime = 0;
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	OSMO_ASSERT(trunk);
+	trunk->audio_send_ptime = 0;
 	return CMD_SUCCESS;
 }
 
@@ -653,7 +650,9 @@
       "sdp audio-payload send-name",
       SDP_STR AUDIO_STR "Send SDP rtpmap with the audio name\n")
 {
-	g_cfg->virt_trunk->audio_send_name = 1;
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	OSMO_ASSERT(trunk);
+	trunk->audio_send_name = 1;
 	return CMD_SUCCESS;
 }
 
@@ -662,7 +661,9 @@
       "no sdp audio-payload send-name",
       NO_STR SDP_STR AUDIO_STR "Send SDP rtpmap with the audio name\n")
 {
-	g_cfg->virt_trunk->audio_send_name = 0;
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	OSMO_ASSERT(trunk);
+	trunk->audio_send_name = 0;
 	return CMD_SUCCESS;
 }
 
@@ -671,11 +672,13 @@
       "loop (0|1)",
       "Loop audio for all endpoints on main trunk\n" "Don't Loop\n" "Loop\n")
 {
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	OSMO_ASSERT(trunk);
 	if (g_cfg->osmux) {
 		vty_out(vty, "Cannot use `loop' with `osmux'.%s", VTY_NEWLINE);
 		return CMD_WARNING;
 	}
-	g_cfg->virt_trunk->audio_loop = atoi(argv[0]);
+	trunk->audio_loop = atoi(argv[0]);
 	return CMD_SUCCESS;
 }
 
@@ -685,7 +688,9 @@
       "Force endpoint reallocation when the endpoint is still seized\n"
       "Don't force reallocation\n" "force reallocation\n")
 {
-	g_cfg->virt_trunk->force_realloc = atoi(argv[0]);
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	OSMO_ASSERT(trunk);
+	trunk->force_realloc = atoi(argv[0]);
 	return CMD_SUCCESS;
 }
 
@@ -695,7 +700,9 @@
       "Accept all RTP packets, even when the originating IP/Port does not match\n"
       "enable filter\n" "disable filter\n")
 {
-	g_cfg->virt_trunk->rtp_accept_all = atoi(argv[0]);
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	OSMO_ASSERT(trunk);
+	trunk->rtp_accept_all = atoi(argv[0]);
 	return CMD_SUCCESS;
 }
 
@@ -704,21 +711,26 @@
       "number endpoints <0-65534>",
       "Number options\n" "Endpoints available\n" "Number endpoints\n")
 {
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	OSMO_ASSERT(trunk);
 	/* + 1 as we start counting at one */
-	g_cfg->virt_trunk->vty_number_endpoints = atoi(argv[0]) + 1;
+	trunk->vty_number_endpoints = atoi(argv[0]) + 1;
 	return CMD_SUCCESS;
 }
 
 DEFUN(cfg_mgcp_omit_rtcp, cfg_mgcp_omit_rtcp_cmd, "rtcp-omit", RTCP_OMIT_STR)
 {
-	g_cfg->virt_trunk->omit_rtcp = 1;
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, 0);
+	trunk->omit_rtcp = 1;
 	return CMD_SUCCESS;
 }
 
 DEFUN(cfg_mgcp_no_omit_rtcp,
       cfg_mgcp_no_omit_rtcp_cmd, "no rtcp-omit", NO_STR RTCP_OMIT_STR)
 {
-	g_cfg->virt_trunk->omit_rtcp = 0;
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	OSMO_ASSERT(trunk);
+	trunk->omit_rtcp = 0;
 	return CMD_SUCCESS;
 }
 
@@ -726,7 +738,9 @@
       cfg_mgcp_patch_rtp_ssrc_cmd,
       "rtp-patch ssrc", RTP_PATCH_STR "Force a fixed SSRC\n")
 {
-	g_cfg->virt_trunk->force_constant_ssrc = 1;
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	OSMO_ASSERT(trunk);
+	trunk->force_constant_ssrc = 1;
 	return CMD_SUCCESS;
 }
 
@@ -734,7 +748,9 @@
       cfg_mgcp_no_patch_rtp_ssrc_cmd,
       "no rtp-patch ssrc", NO_STR RTP_PATCH_STR "Force a fixed SSRC\n")
 {
-	g_cfg->virt_trunk->force_constant_ssrc = 0;
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	OSMO_ASSERT(trunk);
+	trunk->force_constant_ssrc = 0;
 	return CMD_SUCCESS;
 }
 
@@ -742,7 +758,9 @@
       cfg_mgcp_patch_rtp_ts_cmd,
       "rtp-patch timestamp", RTP_PATCH_STR "Adjust RTP timestamp\n")
 {
-	g_cfg->virt_trunk->force_aligned_timing = 1;
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	OSMO_ASSERT(trunk);
+	trunk->force_aligned_timing = 1;
 	return CMD_SUCCESS;
 }
 
@@ -750,7 +768,9 @@
       cfg_mgcp_no_patch_rtp_ts_cmd,
       "no rtp-patch timestamp", NO_STR RTP_PATCH_STR "Adjust RTP timestamp\n")
 {
-	g_cfg->virt_trunk->force_aligned_timing = 0;
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	OSMO_ASSERT(trunk);
+	trunk->force_aligned_timing = 0;
 	return CMD_SUCCESS;
 }
 
@@ -758,7 +778,9 @@
       cfg_mgcp_patch_rtp_rfc5993hr_cmd,
       "rtp-patch rfc5993hr", RTP_PATCH_STR RTP_TS101318_RFC5993_CONV_STR)
 {
-	g_cfg->virt_trunk->rfc5993_hr_convert = true;
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	OSMO_ASSERT(trunk);
+	trunk->rfc5993_hr_convert = true;
 	return CMD_SUCCESS;
 }
 
@@ -766,16 +788,20 @@
       cfg_mgcp_no_patch_rtp_rfc5993hr_cmd,
       "no rtp-patch rfc5993hr", NO_STR RTP_PATCH_STR RTP_TS101318_RFC5993_CONV_STR)
 {
-	g_cfg->virt_trunk->rfc5993_hr_convert = false;
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	OSMO_ASSERT(trunk);
+	trunk->rfc5993_hr_convert = false;
 	return CMD_SUCCESS;
 }
 
 DEFUN(cfg_mgcp_no_patch_rtp,
       cfg_mgcp_no_patch_rtp_cmd, "no rtp-patch", NO_STR RTP_PATCH_STR)
 {
-	g_cfg->virt_trunk->force_constant_ssrc = 0;
-	g_cfg->virt_trunk->force_aligned_timing = 0;
-	g_cfg->virt_trunk->rfc5993_hr_convert = false;
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	OSMO_ASSERT(trunk);
+	trunk->force_constant_ssrc = 0;
+	trunk->force_aligned_timing = 0;
+	trunk->rfc5993_hr_convert = false;
 	return CMD_SUCCESS;
 }
 
@@ -784,7 +810,9 @@
       "rtp keep-alive <1-120>",
       RTP_STR RTP_KEEPALIVE_STR "Keep alive interval in secs\n")
 {
-	mgcp_trunk_set_keepalive(g_cfg->virt_trunk, atoi(argv[0]));
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	OSMO_ASSERT(trunk);
+	mgcp_trunk_set_keepalive(trunk, atoi(argv[0]));
 	return CMD_SUCCESS;
 }
 
@@ -793,7 +821,9 @@
       "rtp keep-alive once",
       RTP_STR RTP_KEEPALIVE_STR "Send dummy packet only once after CRCX/MDCX\n")
 {
-	mgcp_trunk_set_keepalive(g_cfg->virt_trunk, MGCP_KEEPALIVE_ONCE);
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	OSMO_ASSERT(trunk);
+	mgcp_trunk_set_keepalive(trunk, MGCP_KEEPALIVE_ONCE);
 	return CMD_SUCCESS;
 }
 
@@ -801,7 +831,9 @@
       cfg_mgcp_no_rtp_keepalive_cmd,
       "no rtp keep-alive", NO_STR RTP_STR RTP_KEEPALIVE_STR)
 {
-	mgcp_trunk_set_keepalive(g_cfg->virt_trunk, MGCP_KEEPALIVE_NEVER);
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	OSMO_ASSERT(trunk);
+	mgcp_trunk_set_keepalive(trunk, MGCP_KEEPALIVE_NEVER);
 	return CMD_SUCCESS;
 }
 
@@ -826,6 +858,11 @@
 	struct mgcp_trunk *trunk;
 	int index = atoi(argv[0]);
 
+	/* Due to historical reasons, the trunk id number 0 is reserved for the
+	 * virtual trunk. This trunk is configured with separate VTY
+	 * parameters, so we restrict the access to trunks with id numbers
+	 * greater than 0. */
+
 	trunk = mgcp_trunk_by_num(g_cfg, index);
 	if (!trunk) {
 		trunk = mgcp_trunk_alloc(g_cfg, MGCP_TRUNK_E1, index);
@@ -846,6 +883,15 @@
 	struct mgcp_trunk *trunk;
 
 	llist_for_each_entry(trunk, &g_cfg->trunks, entry) {
+
+		/* Due to historical reasons, the virtual trunk is configured
+		   using separate VTY parameters, so we omit writing the trunk
+		   config of trunk 0 here. The configuration for the virtual
+		   trunk is written by config_write_mgcp(). */
+
+		if (trunk->trunk_nr == MGCP_VIRT_TRUNK_ID)
+			continue;
+
 		vty_out(vty, " trunk %d%s", trunk->trunk_nr, VTY_NEWLINE);
 		vty_out(vty, "  %ssdp audio-payload send-ptime%s",
 			trunk->audio_send_ptime ? "" : "no ", VTY_NEWLINE);
@@ -869,7 +915,7 @@
 		else
 			vty_out(vty, "  no rtcp-omit%s", VTY_NEWLINE);
 		if (trunk->force_constant_ssrc || trunk->force_aligned_timing
-		    || g_cfg->virt_trunk->rfc5993_hr_convert) {
+		    || trunk->rfc5993_hr_convert) {
 			vty_out(vty, "  %srtp-patch ssrc%s",
 				trunk->force_constant_ssrc ? "" : "no ",
 				VTY_NEWLINE);
@@ -1123,7 +1169,7 @@
 	struct mgcp_endpoint *endp;
 	struct mgcp_conn *conn;
 
-	trunk = find_trunk(g_cfg, atoi(argv[0]));
+	trunk = mgcp_trunk_by_num(g_cfg, atoi(argv[0]));
 	if (!trunk) {
 		vty_out(vty, "%%Trunk %d not found in the config.%s",
 			atoi(argv[0]), VTY_NEWLINE);
@@ -1182,7 +1228,7 @@
 	struct mgcp_conn_rtp *conn;
         const char *conn_id = NULL;
 
-	trunk = find_trunk(g_cfg, atoi(argv[0]));
+	trunk = mgcp_trunk_by_num(g_cfg, atoi(argv[0]));
 	if (!trunk) {
 		vty_out(vty, "%%Trunk %d not found in the config.%s",
 			atoi(argv[0]), VTY_NEWLINE);
@@ -1235,7 +1281,7 @@
 	struct mgcp_trunk *trunk;
 	struct mgcp_endpoint *endp;
 
-	trunk = find_trunk(g_cfg, atoi(argv[0]));
+	trunk = mgcp_trunk_by_num(g_cfg, atoi(argv[0]));
 	if (!trunk) {
 		vty_out(vty, "%%Trunk %d not found in the config.%s",
 			atoi(argv[0]), VTY_NEWLINE);
@@ -1268,7 +1314,7 @@
 	struct mgcp_endpoint *endp;
 	int endp_no, rc;
 
-	trunk = find_trunk(g_cfg, atoi(argv[0]));
+	trunk = mgcp_trunk_by_num(g_cfg, atoi(argv[0]));
 	if (!trunk) {
 		vty_out(vty, "%%Trunk %d not found in the config.%s",
 			atoi(argv[0]), VTY_NEWLINE);
@@ -1317,6 +1363,9 @@
       "osmux (on|off|only)",
       OSMUX_STR "Enable OSMUX\n" "Disable OSMUX\n" "Only use OSMUX\n")
 {
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	OSMO_ASSERT(trunk);
+
 	if (strcmp(argv[0], "off") == 0) {
 		g_cfg->osmux = OSMUX_USAGE_OFF;
 		return CMD_SUCCESS;
@@ -1325,7 +1374,7 @@
 	else if (strcmp(argv[0], "only") == 0)
 		g_cfg->osmux = OSMUX_USAGE_ONLY;
 
-	if (g_cfg->virt_trunk->audio_loop) {
+	if (trunk->audio_loop) {
 		vty_out(vty, "Cannot use `loop' with `osmux'.%s", VTY_NEWLINE);
 		return CMD_WARNING;
 	}
@@ -1526,13 +1575,6 @@
 		return -1;
 	}
 
-	if (mgcp_trunk_alloc_endpts(g_cfg->virt_trunk) != 0) {
-		LOGP(DLMGCP, LOGL_ERROR,
-		     "Failed to initialize the virtual trunk (%d endpoints)\n",
-		     g_cfg->virt_trunk->number_endpoints);
-		return -1;
-	}
-
 	llist_for_each_entry(trunk, &g_cfg->trunks, entry) {
 		if (mgcp_trunk_alloc_endpts(trunk) != 0) {
 			LOGP(DLMGCP, LOGL_ERROR,
diff --git a/tests/mgcp/mgcp_test.c b/tests/mgcp/mgcp_test.c
index d0da18b..56a17b1 100644
--- a/tests/mgcp/mgcp_test.c
+++ b/tests/mgcp/mgcp_test.c
@@ -760,6 +760,7 @@
 {
 	struct mgcp_config *cfg;
 	struct mgcp_endpoint *endp;
+	struct mgcp_trunk *trunk;
 	struct mgcp_trunk *trunk2;
 	int i;
 	struct mgcp_conn_rtp *conn = NULL;
@@ -767,9 +768,10 @@
 	int rc;
 
 	cfg = mgcp_config_alloc();
+	trunk = mgcp_trunk_by_num(cfg, MGCP_VIRT_TRUNK_ID);
 
-	cfg->virt_trunk->vty_number_endpoints = 64;
-        mgcp_trunk_alloc_endpts(cfg->virt_trunk);
+	trunk->vty_number_endpoints = 64;
+        mgcp_trunk_alloc_endpts(trunk);
 	cfg->policy_cb = mgcp_test_policy_cb;
 
 	memset(last_conn_id, 0, sizeof(last_conn_id));
@@ -788,7 +790,7 @@
 		last_endpoint = -1;
 		dummy_packets = 0;
 
-		osmo_talloc_replace_string(cfg, &cfg->virt_trunk->audio_fmtp_extra,
+		osmo_talloc_replace_string(cfg, &trunk->audio_fmtp_extra,
 					   t->extra_fmtp);
 
 		inp = create_msg(t->req, last_conn_id);
@@ -821,7 +823,7 @@
 			printf("Dummy packets: %d\n", dummy_packets);
 
 		if (last_endpoint != -1) {
-			endp = cfg->virt_trunk->endpoints[last_endpoint];
+			endp = trunk->endpoints[last_endpoint];
 
 			conn = mgcp_conn_get_rtp(endp, "1");
 			if (conn) {
@@ -877,7 +879,7 @@
 		/* Check detected payload type */
 		if (conn && t->ptype != PTYPE_IGNORE) {
 			OSMO_ASSERT(last_endpoint != -1);
-			endp = cfg->virt_trunk->endpoints[last_endpoint];
+			endp = trunk->endpoints[last_endpoint];
 
 			fprintf(stderr, "endpoint 0x%x: "
 				"payload type %d (expected %d)\n",
@@ -894,22 +896,24 @@
 	}
 
 	mgcp_endpoints_release(trunk2);
-	mgcp_endpoints_release(cfg->virt_trunk);
+	mgcp_endpoints_release(trunk);
 	talloc_free(cfg);
 }
 
 static void test_retransmission(void)
 {
 	struct mgcp_config *cfg;
+	struct mgcp_trunk *trunk;
 	struct mgcp_trunk *trunk2;
 	int i;
 	char last_conn_id[256];
 	int rc;
 
 	cfg = mgcp_config_alloc();
+	trunk = mgcp_trunk_by_num(cfg, MGCP_VIRT_TRUNK_ID);
 
-	cfg->virt_trunk->vty_number_endpoints = 64;
-        mgcp_trunk_alloc_endpts(cfg->virt_trunk);
+	trunk->vty_number_endpoints = 64;
+        mgcp_trunk_alloc_endpts(trunk);
 
 	memset(last_conn_id, 0, sizeof(last_conn_id));
 
@@ -955,7 +959,7 @@
 	}
 
 	mgcp_endpoints_release(trunk2);
-	mgcp_endpoints_release(cfg->virt_trunk);
+	mgcp_endpoints_release(trunk);
 	talloc_free(cfg);
 }
 
@@ -969,15 +973,17 @@
 static void test_rqnt_cb(void)
 {
 	struct mgcp_config *cfg;
+	struct mgcp_trunk *trunk;
 	struct mgcp_trunk *trunk2;
 	struct msgb *inp, *msg;
 	char conn_id[256];
 
 	cfg = mgcp_config_alloc();
+	trunk = mgcp_trunk_by_num(cfg, MGCP_VIRT_TRUNK_ID);
 	cfg->rqnt_cb = rqnt_cb;
 
-	cfg->virt_trunk->vty_number_endpoints = 64;
-        mgcp_trunk_alloc_endpts(cfg->virt_trunk);
+	trunk->vty_number_endpoints = 64;
+        mgcp_trunk_alloc_endpts(trunk);
 
 	trunk2 = mgcp_trunk_alloc(cfg, MGCP_TRUNK_E1, 1);
         mgcp_trunk_alloc_endpts(trunk2);
@@ -1010,7 +1016,7 @@
 	msgb_free(mgcp_handle_message(cfg, inp));
 	msgb_free(inp);
 	mgcp_endpoints_release(trunk2);
-	mgcp_endpoints_release(cfg->virt_trunk);
+	mgcp_endpoints_release(trunk);
 	talloc_free(cfg);
 }
 
@@ -1376,6 +1382,7 @@
 static void test_multilple_codec(void)
 {
 	struct mgcp_config *cfg;
+	struct mgcp_trunk *trunk;
 	struct mgcp_trunk *trunk2;
 	struct mgcp_endpoint *endp;
 	struct msgb *inp, *resp;
@@ -1386,8 +1393,9 @@
 	printf("Testing multiple payload types\n");
 
 	cfg = mgcp_config_alloc();
-	cfg->virt_trunk->vty_number_endpoints = 64;
-        mgcp_trunk_alloc_endpts(cfg->virt_trunk);
+	trunk = mgcp_trunk_by_num(cfg, MGCP_VIRT_TRUNK_ID);
+	trunk->vty_number_endpoints = 64;
+        mgcp_trunk_alloc_endpts(trunk);
 	cfg->policy_cb = mgcp_test_policy_cb;
 
 	trunk2 = mgcp_trunk_alloc(cfg, MGCP_TRUNK_E1, 1);
@@ -1403,7 +1411,7 @@
 	msgb_free(resp);
 
 	OSMO_ASSERT(last_endpoint == 1);
-	endp = cfg->virt_trunk->endpoints[last_endpoint];
+	endp = trunk->endpoints[last_endpoint];
 	conn = mgcp_conn_get_rtp(endp, conn_id);
 	OSMO_ASSERT(conn);
 	OSMO_ASSERT(conn->end.codec->payload_type == 18);
@@ -1418,7 +1426,7 @@
 	msgb_free(resp);
 
 	OSMO_ASSERT(last_endpoint == 2);
-	endp = cfg->virt_trunk->endpoints[last_endpoint];
+	endp = trunk->endpoints[last_endpoint];
 	conn = mgcp_conn_get_rtp(endp, conn_id);
 	OSMO_ASSERT(conn);
 	OSMO_ASSERT(conn->end.codec->payload_type == 18);
@@ -1438,7 +1446,7 @@
 	msgb_free(resp);
 
 	OSMO_ASSERT(last_endpoint == 3);
-	endp = cfg->virt_trunk->endpoints[last_endpoint];
+	endp = trunk->endpoints[last_endpoint];
 	conn = mgcp_conn_get_rtp(endp, conn_id);
 	OSMO_ASSERT(conn);
 	OSMO_ASSERT(conn->end.codec->payload_type == 0);
@@ -1453,7 +1461,7 @@
 	msgb_free(resp);
 
 	OSMO_ASSERT(last_endpoint == 4);
-	endp = cfg->virt_trunk->endpoints[last_endpoint];
+	endp = trunk->endpoints[last_endpoint];
 	conn = mgcp_conn_get_rtp(endp, conn_id);
 	OSMO_ASSERT(conn);
 	OSMO_ASSERT(conn->end.codec->payload_type == 18);
@@ -1461,7 +1469,7 @@
 	/* Allocate 5 at mgw and let osmo-mgw pick a codec from the list */
 	last_endpoint = -1;
 	inp = create_msg(CRCX_MULT_GSM_EXACT, NULL);
-	cfg->virt_trunk->no_audio_transcoding = 1;
+	trunk->no_audio_transcoding = 1;
 	resp = mgcp_handle_message(cfg, inp);
 	OSMO_ASSERT(get_conn_id_from_response(resp->data, conn_id,
 					      sizeof(conn_id)) == 0);
@@ -1469,7 +1477,7 @@
 	msgb_free(resp);
 
 	OSMO_ASSERT(last_endpoint == 5);
-	endp = cfg->virt_trunk->endpoints[last_endpoint];
+	endp = trunk->endpoints[last_endpoint];
 	conn = mgcp_conn_get_rtp(endp, conn_id);
 	OSMO_ASSERT(conn);
 	OSMO_ASSERT(conn->end.codec->payload_type == 0);
@@ -1480,7 +1488,7 @@
 	msgb_free(inp);
 	msgb_free(resp);
 	OSMO_ASSERT(last_endpoint == 5);
-	endp = cfg->virt_trunk->endpoints[last_endpoint];
+	endp = trunk->endpoints[last_endpoint];
 	conn = mgcp_conn_get_rtp(endp, conn_id);
 	OSMO_ASSERT(conn);
 	OSMO_ASSERT(conn->end.codec->payload_type == 3);
@@ -1502,7 +1510,7 @@
 
 	last_endpoint = -1;
 	inp = create_msg(CRCX_MULT_GSM_EXACT, NULL);
-	cfg->virt_trunk->no_audio_transcoding = 0;
+	trunk->no_audio_transcoding = 0;
 	resp = mgcp_handle_message(cfg, inp);
 	OSMO_ASSERT(get_conn_id_from_response(resp->data, conn_id,
 					      sizeof(conn_id)) == 0);
@@ -1510,13 +1518,13 @@
 	msgb_free(resp);
 
 	OSMO_ASSERT(last_endpoint == 5);
-	endp = cfg->virt_trunk->endpoints[last_endpoint];
+	endp = trunk->endpoints[last_endpoint];
 	conn = mgcp_conn_get_rtp(endp, conn_id);
 	OSMO_ASSERT(conn);
 	OSMO_ASSERT(conn->end.codec->payload_type == 0);
 
 	mgcp_endpoints_release(trunk2);
-	mgcp_endpoints_release(cfg->virt_trunk);
+	mgcp_endpoints_release(trunk);
 	talloc_free(cfg);
 }
 
@@ -1526,14 +1534,16 @@
 	struct mgcp_endpoint *endp;
 	struct mgcp_conn_rtp *conn = NULL;
 	struct mgcp_conn *_conn = NULL;
+	struct mgcp_trunk *trunk;
 
 	printf("Testing no sequence flow on initial packet\n");
 
 	cfg = mgcp_config_alloc();
-	cfg->virt_trunk->vty_number_endpoints = 64;
-        mgcp_trunk_alloc_endpts(cfg->virt_trunk);
+	trunk = mgcp_trunk_by_num(cfg, MGCP_VIRT_TRUNK_ID);
+	trunk->vty_number_endpoints = 64;
+        mgcp_trunk_alloc_endpts(trunk);
 
-	endp = cfg->virt_trunk->endpoints[1];
+	endp = trunk->endpoints[1];
 
 	_conn = mgcp_conn_alloc(NULL, endp, MGCP_CONN_TYPE_RTP,
 				"test-connection");
@@ -1565,22 +1575,24 @@
 	OSMO_ASSERT(conn->state.stats.cycles == UINT16_MAX + 1);
 	OSMO_ASSERT(conn->state.stats.max_seq == 0);
 
-	mgcp_endpoints_release(cfg->virt_trunk);
+	mgcp_endpoints_release(trunk);
 	talloc_free(cfg);
 }
 
 static void test_no_name(void)
 {
+	struct mgcp_trunk *trunk;
 	struct mgcp_trunk *trunk2;
 	struct mgcp_config *cfg;
 	struct msgb *inp, *msg;
 
 	printf("Testing no rtpmap name\n");
 	cfg = mgcp_config_alloc();
+	trunk = mgcp_trunk_by_num(cfg, MGCP_VIRT_TRUNK_ID);
 
-	cfg->virt_trunk->vty_number_endpoints = 64;
-	cfg->virt_trunk->audio_send_name = 0;
-        mgcp_trunk_alloc_endpts(cfg->virt_trunk);
+	trunk->vty_number_endpoints = 64;
+	trunk->audio_send_name = 0;
+        mgcp_trunk_alloc_endpts(trunk);
 
 	cfg->policy_cb = mgcp_test_policy_cb;
 
@@ -1599,7 +1611,7 @@
 	msgb_free(msg);
 
 	mgcp_endpoints_release(trunk2);
-	mgcp_endpoints_release(cfg->virt_trunk);
+	mgcp_endpoints_release(trunk);
 	talloc_free(cfg);
 }
 

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-mgw/+/18590
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Change-Id: I81934fbd211b225ab7920e78510729c8e22607b3
Gerrit-Change-Number: 18590
Gerrit-PatchSet: 13
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: neels <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200618/c75637ec/attachment.htm>


More information about the gerrit-log mailing list