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/.

dexter gerrit-no-reply at lists.osmocom.org
Fri May 29 17:12:30 UTC 2020


dexter has uploaded this change for review. ( 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_endp.c
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
8 files changed, 158 insertions(+), 122 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/90/18590/1

diff --git a/include/osmocom/mgcp/mgcp.h b/include/osmocom/mgcp/mgcp.h
index 4c122e7..47c741f 100644
--- a/include/osmocom/mgcp/mgcp.h
+++ b/include/osmocom/mgcp/mgcp.h
@@ -211,11 +211,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 51e9fb5..60fb840 100644
--- a/include/osmocom/mgcp/mgcp_trunk.h
+++ b/include/osmocom/mgcp/mgcp_trunk.h
@@ -38,7 +38,12 @@
 	struct mgcp_endpoint **endpoints;
 };
 
-struct mgcp_trunk *mgcp_trunk_alloc(struct mgcp_config *cfg, enum mgcp_trunk_type ttype, int nr);
+int mgcp_trunk_alloc(struct mgcp_config *cfg, enum mgcp_trunk_type ttype, int nr);
 int mgcp_trunk_alloc_endpts(struct mgcp_trunk *tcfg);
 struct mgcp_trunk *mgcp_trunk_by_num(struct mgcp_config *cfg, int index);
 struct mgcp_trunk *mgcp_trunk_by_name(const char *epname, struct mgcp_config *cfg);
+
+/* 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_endp.c b/src/libosmo-mgcp/mgcp_endp.c
index 5e42bcb..69e44e5 100644
--- a/src/libosmo-mgcp/mgcp_endp.c
+++ b/src/libosmo-mgcp/mgcp_endp.c
@@ -97,16 +97,12 @@
 	switch (trunk->trunk_type) {
 	case MGCP_TRUNK_VIRTUAL:
 		prefix_len = sizeof(MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK) - 1;
-		if (strlen(epname) <= prefix_len)
-			return epname;
 		if (strncmp
 		    (epname, MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK,
 		     prefix_len) == 0)
 			return epname + prefix_len;
 	case MGCP_TRUNK_E1:
 		prefix_len = sizeof(MGCP_ENDPOINT_PREFIX_E1_TRUNK) - 1;
-		if (strlen(epname) <= prefix_len)
-			return epname;
 		if (strncmp
 		    (epname, MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK,
 		     prefix_len) == 0)
diff --git a/src/libosmo-mgcp/mgcp_osmux.c b/src/libosmo-mgcp/mgcp_osmux.c
index ca8b5f0..ba8e10f 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, 0);
 	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 f62b581..13cf3b1 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -1501,16 +1501,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) != 0) {
 		talloc_free(cfg);
 		return NULL;
 	}
 
-	/* Initalize list head for user configurable trunks */
-	INIT_LLIST_HEAD(&cfg->trunks);
-
 	mgcp_ratectr_alloc(cfg, &cfg->ratectr);
 
 	return cfg;
diff --git a/src/libosmo-mgcp/mgcp_trunk.c b/src/libosmo-mgcp/mgcp_trunk.c
index 4424874..04789b8 100644
--- a/src/libosmo-mgcp/mgcp_trunk.c
+++ b/src/libosmo-mgcp/mgcp_trunk.c
@@ -30,15 +30,15 @@
  *  \param[in] cfg mgcp configuration
  *  \param[in] nr trunk number
  *  \param[in] ttype trunk type
- *  \returns pointer to allocated trunk, NULL on failure */
-struct mgcp_trunk *mgcp_trunk_alloc(struct mgcp_config *cfg, enum mgcp_trunk_type ttype, int nr)
+ *  \returns -EINVAL on failure, 0 on success. */
+int mgcp_trunk_alloc(struct mgcp_config *cfg, enum mgcp_trunk_type ttype, int nr)
 {
 	struct mgcp_trunk *trunk;
 
 	trunk = talloc_zero(cfg, struct mgcp_trunk);
 	if (!trunk) {
-		LOGP(DLMGCP, LOGL_ERROR, "Failed to allocate.\n");
-		return NULL;
+		LOGP(DLMGCP, LOGL_ERROR, "Failed to allocate trunk.\n");
+		return -EINVAL;
 	}
 
 	trunk->cfg = cfg;
@@ -52,13 +52,8 @@
 
 	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);
-
-	return trunk;
+	llist_add_tail(&trunk->entry, &cfg->trunks);
+	return 0;
 }
 
 /*! allocate endpoints and set default values.
@@ -140,7 +135,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, 0);
 	}
 
 	/* E1 trunks are not implemented yet, so we deny any request for an
@@ -163,7 +158,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, 0);
 	}
 
 	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 d0bb602..71e5ead 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,7 @@
 
 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);
 
 	vty_out(vty, "mgcp%s", VTY_NEWLINE);
 	vty_out(vty, "  domain %s%s", g_cfg->domain, VTY_NEWLINE);
@@ -317,8 +305,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);
 
@@ -377,7 +363,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;
@@ -567,11 +553,13 @@
       "Add extra fmtp for the SDP file\n" "Audio\n" "Fmtp-extra\n"
       "Extra Information\n")
 {
+	/* FIXME: This works only for the virtual trunk, what about other trunks? */
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
 	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;
 }
@@ -580,7 +568,9 @@
       cfg_mgcp_allow_transcoding_cmd,
       "allow-transcoding", "Allow transcoding\n")
 {
-	g_cfg->virt_trunk->no_audio_transcoding = 0;
+	/* FIXME: This works only for the virtual trunk, what about other trunks? */
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	trunk->no_audio_transcoding = 0;
 	return CMD_SUCCESS;
 }
 
@@ -588,7 +578,9 @@
       cfg_mgcp_no_allow_transcoding_cmd,
       "no allow-transcoding", NO_STR "Allow transcoding\n")
 {
-	g_cfg->virt_trunk->no_audio_transcoding = 1;
+	/* FIXME: This works only for the virtual trunk, what about other trunks? */
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	trunk->no_audio_transcoding = 1;
 	return CMD_SUCCESS;
 }
 
@@ -624,7 +616,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;
+	/* FIXME: This works only for the virtual trunk, what about other trunks? */
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	trunk->audio_send_ptime = 1;
 	return CMD_SUCCESS;
 }
 
@@ -633,7 +627,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;
+	/* FIXME: This works only for the virtual trunk, what about other trunks? */
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	trunk->audio_send_ptime = 0;
 	return CMD_SUCCESS;
 }
 
@@ -642,7 +638,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;
+	/* FIXME: This works only for the virtual trunk, what about other trunks? */
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	trunk->audio_send_name = 1;
 	return CMD_SUCCESS;
 }
 
@@ -651,7 +649,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;
+	/* FIXME: This works only for the virtual trunk, what about other trunks? */
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	trunk->audio_send_name = 0;
 	return CMD_SUCCESS;
 }
 
@@ -660,11 +660,13 @@
       "loop (0|1)",
       "Loop audio for all endpoints on main trunk\n" "Don't Loop\n" "Loop\n")
 {
+	/* FIXME: This works only for the virtual trunk, what about other trunks? */
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
 	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;
 }
 
@@ -674,7 +676,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]);
+	/* FIXME: This works only for the virtual trunk, what about other trunks? */
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	trunk->force_realloc = atoi(argv[0]);
 	return CMD_SUCCESS;
 }
 
@@ -684,7 +688,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]);
+	/* FIXME: This works only for the virtual trunk, what about other trunks? */
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	trunk->rtp_accept_all = atoi(argv[0]);
 	return CMD_SUCCESS;
 }
 
@@ -693,21 +699,27 @@
       "number endpoints <0-65534>",
       "Number options\n" "Endpoints available\n" "Number endpoints\n")
 {
+	/* FIXME: This works only for the virtual trunk, what about other trunks? */
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
 	/* + 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;
+	/* FIXME: This works only for the virtual trunk, what about other trunks? */
+	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;
+	/* FIXME: This works only for the virtual trunk, what about other trunks? */
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	trunk->omit_rtcp = 0;
 	return CMD_SUCCESS;
 }
 
@@ -715,7 +727,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;
+	/* FIXME: This works only for the virtual trunk, what about other trunks? */
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	trunk->force_constant_ssrc = 1;
 	return CMD_SUCCESS;
 }
 
@@ -723,7 +737,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;
+	/* FIXME: This works only for the virtual trunk, what about other trunks? */
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	trunk->force_constant_ssrc = 0;
 	return CMD_SUCCESS;
 }
 
@@ -731,7 +747,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;
+	/* FIXME: This works only for the virtual trunk, what about other trunks? */
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	trunk->force_aligned_timing = 1;
 	return CMD_SUCCESS;
 }
 
@@ -739,7 +757,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;
+	/* FIXME: This works only for the virtual trunk, what about other trunks? */
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	trunk->force_aligned_timing = 0;
 	return CMD_SUCCESS;
 }
 
@@ -747,7 +767,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;
+	/* FIXME: This works only for the virtual trunk, what about other trunks? */
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	trunk->rfc5993_hr_convert = true;
 	return CMD_SUCCESS;
 }
 
@@ -755,16 +777,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;
+	/* FIXME: This works only for the virtual trunk, what about other trunks? */
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	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;
+	/* FIXME: This works only for the virtual trunk, what about other trunks? */
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	trunk->force_constant_ssrc = 0;
+	trunk->force_aligned_timing = 0;
+	trunk->rfc5993_hr_convert = false;
 	return CMD_SUCCESS;
 }
 
@@ -773,7 +799,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]));
+	/* FIXME: This works only for the virtual trunk, what about other trunks? */
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	mgcp_trunk_set_keepalive(trunk, atoi(argv[0]));
 	return CMD_SUCCESS;
 }
 
@@ -782,7 +810,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);
+	/* FIXME: This works only for the virtual trunk, what about other trunks? */
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	mgcp_trunk_set_keepalive(trunk, MGCP_KEEPALIVE_ONCE);
 	return CMD_SUCCESS;
 }
 
@@ -790,7 +820,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);
+	/* FIXME: This works only for the virtual trunk, what about other trunks? */
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+	mgcp_trunk_set_keepalive(trunk, MGCP_KEEPALIVE_NEVER);
 	return CMD_SUCCESS;
 }
 
@@ -817,7 +849,7 @@
 
 	trunk = mgcp_trunk_by_num(g_cfg, index);
 	if (!trunk) {
-		trunk = mgcp_trunk_alloc(g_cfg, MGCP_TRUNK_E1, index);
+		if(mgcp_trunk_alloc(g_cfg, MGCP_TRUNK_E1, index) != 0);
 		if (!trunk)
 			return CMD_WARNING;
 	}
@@ -861,7 +893,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);
@@ -1115,7 +1147,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);
@@ -1174,7 +1206,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);
@@ -1227,7 +1259,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);
@@ -1260,7 +1292,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);
@@ -1309,6 +1341,9 @@
       "osmux (on|off|only)",
       OSMUX_STR "Enable OSMUX\n" "Disable OSMUX\n" "Only use OSMUX\n")
 {
+	/* FIXME: This works only for the virtual trunk, what about other trunks? */
+	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_VIRT_TRUNK_ID);
+
 	if (strcmp(argv[0], "off") == 0) {
 		g_cfg->osmux = OSMUX_USAGE_OFF;
 		return CMD_SUCCESS;
@@ -1317,7 +1352,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;
 	}
@@ -1518,13 +1553,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..eff84bf 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,14 +768,16 @@
 	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));
 
-	trunk2 = mgcp_trunk_alloc(cfg, MGCP_TRUNK_E1, 1);
+	mgcp_trunk_alloc(cfg, MGCP_TRUNK_E1, 1);
+	trunk2 = mgcp_trunk_by_num(cfg, 1);
         mgcp_trunk_alloc_endpts(trunk2);
 
 	for (i = 0; i < ARRAY_SIZE(tests); i++) {
@@ -788,7 +791,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 +824,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 +880,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,26 +897,29 @@
 	}
 
 	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));
 
-	trunk2 = mgcp_trunk_alloc(cfg, MGCP_TRUNK_E1, 1);
+	mgcp_trunk_alloc(cfg, MGCP_TRUNK_E1, 1);
+	trunk2 = mgcp_trunk_by_num(cfg, 1);
         mgcp_trunk_alloc_endpts(trunk2);
 
 	for (i = 0; i < ARRAY_SIZE(retransmit); i++) {
@@ -955,7 +961,7 @@
 	}
 
 	mgcp_endpoints_release(trunk2);
-	mgcp_endpoints_release(cfg->virt_trunk);
+	mgcp_endpoints_release(trunk);
 	talloc_free(cfg);
 }
 
@@ -969,17 +975,20 @@
 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(cfg, MGCP_TRUNK_E1, 1);
+	trunk2 = mgcp_trunk_by_num(cfg, 1);
         mgcp_trunk_alloc_endpts(trunk2);
 
 	inp = create_msg(CRCX, NULL);
@@ -1010,7 +1019,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 +1385,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,11 +1396,13 @@
 	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);
+	mgcp_trunk_alloc(cfg, MGCP_TRUNK_E1, 1);
+	trunk2 = mgcp_trunk_by_num(cfg, 1);
         mgcp_trunk_alloc_endpts(trunk2);
 
 	/* Allocate endpoint 1 at mgw with two codecs */
@@ -1403,7 +1415,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 +1430,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 +1450,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 +1465,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 +1473,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 +1481,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 +1492,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 +1514,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 +1522,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 +1538,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,26 +1579,29 @@
 	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;
 
-	trunk2 = mgcp_trunk_alloc(cfg, MGCP_TRUNK_E1, 1);
+	mgcp_trunk_alloc(cfg, MGCP_TRUNK_E1, 1);
+	trunk2 = mgcp_trunk_by_num(cfg, 1);
         mgcp_trunk_alloc_endpts(trunk2);
 
 	inp = create_msg(CRCX, NULL);
@@ -1599,7 +1616,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: 1
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200529/439f2af5/attachment.htm>


More information about the gerrit-log mailing list