Change in osmo-mgw[master]: mgcp_vty: refactor endpoint number configuration

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 Jul 3 14:10:52 UTC 2020


dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-mgw/+/19121 )


Change subject: mgcp_vty: refactor endpoint number configuration
......................................................................

mgcp_vty: refactor endpoint number configuration

At the moment the number of possible E1 endpoints (depends on the number
of E1 timeslots that should be used) is hardcoded and the configuration
of the number of virtual endpoints has an off-by-one problem.

For the E1 timeslots one might choose not to occupy all E1 timeslots of
once. A one TRX E1 BTS usually requires 3 E1 timeslots. One as D-Channel
timeslot and two to cover the voice channels. The voice channels
timeslots need to be set up in osmo-mgw, while the D-Channel timeslot
must not be touched. The VTY config needs to be able to reflect that.

Change-Id: I73b31e3c236a61ea0a6f76ef5ff98ce589f52c77
Related: OS#2547
---
M include/osmocom/mgcp/mgcp_trunk.h
M src/libosmo-mgcp/mgcp_trunk.c
M src/libosmo-mgcp/mgcp_vty.c
M tests/mgcp/mgcp_test.c
4 files changed, 85 insertions(+), 28 deletions(-)



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

diff --git a/include/osmocom/mgcp/mgcp_trunk.h b/include/osmocom/mgcp/mgcp_trunk.h
index aa6dd29..4caeff9 100644
--- a/include/osmocom/mgcp/mgcp_trunk.h
+++ b/include/osmocom/mgcp/mgcp_trunk.h
@@ -39,11 +39,23 @@
 	int rtp_accept_all;
 
 	unsigned int number_endpoints;
-	unsigned int vty_number_endpoints;
 	struct mgcp_endpoint **endpoints;
 
 	/* global rate counters to measure the trunks overall performance and health */
 	struct mgcp_ratectr_trunk ratectr;
+
+	union {
+		/* Virtual trunk specific */
+		struct {
+			unsigned int vty_number_endpoints;
+		} virtual;
+		/* E1 specific */
+		struct {
+			unsigned int vty_timeslot_first;
+			unsigned int vty_timeslot_num;
+		} e1;
+	};
+
 };
 
 struct mgcp_trunk *mgcp_trunk_alloc(struct mgcp_config *cfg, enum mgcp_trunk_type ttype, int nr);
diff --git a/src/libosmo-mgcp/mgcp_trunk.c b/src/libosmo-mgcp/mgcp_trunk.c
index 43abe45..1aadc2c 100644
--- a/src/libosmo-mgcp/mgcp_trunk.c
+++ b/src/libosmo-mgcp/mgcp_trunk.c
@@ -41,13 +41,16 @@
 		return NULL;
 	}
 
+	/* Set reasonable VTY defaults */
+	trunk->virtual.vty_number_endpoints = 32;
+	trunk->e1.vty_timeslot_first = 1;
+	trunk->e1.vty_timeslot_num = 2;
+
 	trunk->cfg = cfg;
 	trunk->trunk_type = ttype;
 	trunk->trunk_nr = nr;
-
 	trunk->audio_send_ptime = 1;
 	trunk->audio_send_name = 1;
-	trunk->vty_number_endpoints = 33;
 	trunk->omit_rtcp = 0;
 
 	mgcp_trunk_set_keepalive(trunk, MGCP_KEEPALIVE_ONCE);
@@ -67,13 +70,8 @@
 {
 	int i;
 	struct mgcp_endpoint *endp;
-
-	/* Make sure the amount of requested endpoints does not execeed
-	 * sane limits. The VTY already limits the possible amount,
-	 * however miss-initalation of the struct or memory corruption
-	 * could still lead to an excessive allocation of endpoints, so
-	 * better stop early if that is the case. */
-	OSMO_ASSERT(trunk->vty_number_endpoints < 65534);
+	unsigned int number_endpoints;
+	unsigned int offset_endpoints;
 
 	/* This function is called once on startup by the VTY to allocate the
 	 * endpoints. The number of endpoints must not change througout the
@@ -81,15 +79,37 @@
 	OSMO_ASSERT(trunk->number_endpoints == 0);
 	OSMO_ASSERT(trunk->endpoints == NULL);
 
+	switch (trunk->trunk_type) {
+	case MGCP_TRUNK_VIRTUAL:
+		number_endpoints = trunk->virtual.vty_number_endpoints;
+		/* Note: due to historical reasons the endpoints on the virtual
+		 * trunk start counting at 1. */
+		offset_endpoints = 1;
+		break;
+	case MGCP_TRUNK_E1:
+		number_endpoints = trunk->e1.vty_timeslot_num * MGCP_ENDP_E1_SUBSLOTS;
+		offset_endpoints = trunk->e1.vty_timeslot_first * MGCP_ENDP_E1_SUBSLOTS;
+		break;
+	default:
+		OSMO_ASSERT(false);
+	}
+
+	/* Make sure the amount of requested endpoints does not execeed
+	 * sane limits. The VTY already limits the possible amount,
+	 * however miss-initalation of the struct or memory corruption
+	 * could still lead to an excessive allocation of endpoints, so
+	 * better stop early if that is the case. */
+	OSMO_ASSERT(number_endpoints < 65534);
+
 	/* allocate pointer array for the endpoints */
 	trunk->endpoints = _talloc_zero_array(trunk->cfg,
-					     sizeof(struct mgcp_endpoint *), trunk->vty_number_endpoints, "endpoints");
+					      sizeof(struct mgcp_endpoint *), number_endpoints, "endpoints");
 	if (!trunk->endpoints)
 		return -1;
 
 	/* create endpoints */
-	for (i = 0; i < trunk->vty_number_endpoints; ++i) {
-		endp = mgcp_endp_alloc(trunk, i);
+	for (i = 0; i < number_endpoints; i++) {
+		endp = mgcp_endp_alloc(trunk, i + offset_endpoints);
 		if (!endp) {
 			talloc_free(trunk->endpoints);
 			return -1;
@@ -98,7 +118,7 @@
 	}
 
 	/* make the endpoints we just created available to the MGW code */
-	trunk->number_endpoints = trunk->vty_number_endpoints;
+	trunk->number_endpoints = number_endpoints;
 
 	return 0;
 }
diff --git a/src/libosmo-mgcp/mgcp_vty.c b/src/libosmo-mgcp/mgcp_vty.c
index 683d2ed..2310b6a 100644
--- a/src/libosmo-mgcp/mgcp_vty.c
+++ b/src/libosmo-mgcp/mgcp_vty.c
@@ -112,7 +112,7 @@
 		trunk->audio_send_name ? "" : "no ", VTY_NEWLINE);
 	vty_out(vty, " loop %u%s", ! !trunk->audio_loop, VTY_NEWLINE);
 	vty_out(vty, " number endpoints %u%s",
-		trunk->vty_number_endpoints - 1, VTY_NEWLINE);
+		trunk->virtual.vty_number_endpoints, VTY_NEWLINE);
 	vty_out(vty, " %sallow-transcoding%s",
 		trunk->no_audio_transcoding ? "no " : "", VTY_NEWLINE);
 	if (g_cfg->call_agent_addr)
@@ -289,7 +289,7 @@
 
 	vty_out(vty, "%s trunk %d with %d endpoints:%s",
 		trunk->trunk_type == MGCP_TRUNK_VIRTUAL ? "Virtual" : "E1",
-		trunk->trunk_nr, trunk->number_endpoints - 1, VTY_NEWLINE);
+		trunk->trunk_nr, trunk->number_endpoints, VTY_NEWLINE);
 
 	if (!trunk->endpoints) {
 		vty_out(vty, "No endpoints allocated yet.%s", VTY_NEWLINE);
@@ -715,8 +715,7 @@
 {
 	struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
 	OSMO_ASSERT(trunk);
-	/* + 1 as we start counting at one */
-	trunk->vty_number_endpoints = atoi(argv[0]) + 1;
+	trunk->virtual.vty_number_endpoints = atoi(argv[0]);
 	return CMD_SUCCESS;
 }
 
@@ -934,6 +933,10 @@
 				trunk->audio_fmtp_extra, VTY_NEWLINE);
 		vty_out(vty, "  %sallow-transcoding%s",
 			trunk->no_audio_transcoding ? "no " : "", VTY_NEWLINE);
+		vty_out(vty, "  timeslot first %u%s",
+			trunk->e1.vty_timeslot_first, VTY_NEWLINE);
+		vty_out(vty, "  timeslot num %u%s",
+			trunk->e1.vty_timeslot_num, VTY_NEWLINE);
 	}
 
 	return CMD_SUCCESS;
@@ -1160,6 +1163,26 @@
 	return CMD_SUCCESS;
 }
 
+DEFUN(cfg_trunk_e1_timeslot_first,
+      cfg_trunk_e1_timeslot_first_cmd,
+      "timeslot first <0-31>",
+      "timeslot options" "First E1 timeslot to be used\n" "E1 timeslot number\n")
+{
+	struct mgcp_trunk *trunk = vty->index;
+	trunk->e1.vty_timeslot_first = atoi(argv[0]);
+	return CMD_SUCCESS;
+}
+
+DEFUN(cfg_trunk_e1_timeslot_num,
+      cfg_trunk_e1_timeslot_num_cmd,
+      "timeslot num <0-31>",
+      "timeslot options" "Number of E1 timeslots to use\n" "E1 timeslot count\n")
+{
+	struct mgcp_trunk *trunk = vty->index;
+	trunk->e1.vty_timeslot_num = atoi(argv[0]);
+	return CMD_SUCCESS;
+}
+
 DEFUN(loop_conn,
       loop_conn_cmd,
       "loop-endpoint <0-64> NAME (0|1)",
@@ -1550,6 +1573,8 @@
 	install_element(TRUNK_NODE_E1, &cfg_trunk_no_sdp_payload_send_name_cmd);
 	install_element(TRUNK_NODE_E1, &cfg_trunk_allow_transcoding_cmd);
 	install_element(TRUNK_NODE_E1, &cfg_trunk_no_allow_transcoding_cmd);
+	install_element(TRUNK_NODE_E1, &cfg_trunk_e1_timeslot_first_cmd);
+	install_element(TRUNK_NODE_E1, &cfg_trunk_e1_timeslot_num_cmd);
 
 	return 0;
 }
diff --git a/tests/mgcp/mgcp_test.c b/tests/mgcp/mgcp_test.c
index 8c084b4..c0e70d3 100644
--- a/tests/mgcp/mgcp_test.c
+++ b/tests/mgcp/mgcp_test.c
@@ -605,7 +605,7 @@
 
 	trunk = endp->trunk;
 	last_endpoint[0] = '\0';
-	for (i = 0; i < trunk->vty_number_endpoints; i++) {
+	for (i = 0; i < trunk->number_endpoints; i++) {
 		if (strcmp(endp->name, trunk->endpoints[i]->name) == 0)
 			strcpy(last_endpoint, trunk->endpoints[i]->name);
 	}
@@ -655,7 +655,7 @@
 static void mgcp_endpoints_release(struct mgcp_trunk *trunk)
 {
 	int i;
-	for (i = 1; i < trunk->number_endpoints; i++)
+	for (i = 0; i < trunk->number_endpoints; i++)
 		mgcp_endp_release(trunk->endpoints[i]);
 }
 
@@ -770,7 +770,7 @@
 	cfg = mgcp_config_alloc();
 	trunk = mgcp_trunk_by_num(cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
 
-	trunk->vty_number_endpoints = 64;
+	trunk->virtual.vty_number_endpoints = 64;
         mgcp_trunk_alloc_endpts(trunk);
 	cfg->policy_cb = mgcp_test_policy_cb;
 
@@ -912,7 +912,7 @@
 	cfg = mgcp_config_alloc();
 	trunk = mgcp_trunk_by_num(cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
 
-	trunk->vty_number_endpoints = 64;
+	trunk->virtual.vty_number_endpoints = 64;
         mgcp_trunk_alloc_endpts(trunk);
 
 	memset(last_conn_id, 0, sizeof(last_conn_id));
@@ -982,7 +982,7 @@
 	trunk = mgcp_trunk_by_num(cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
 	cfg->rqnt_cb = rqnt_cb;
 
-	trunk->vty_number_endpoints = 64;
+	trunk->virtual.vty_number_endpoints = 64;
         mgcp_trunk_alloc_endpts(trunk);
 
 	trunk2 = mgcp_trunk_alloc(cfg, MGCP_TRUNK_E1, 1);
@@ -1063,7 +1063,7 @@
 
 	endp.cfg = &cfg;
 	endp.type = &ep_typeset.rtp;
-	trunk.vty_number_endpoints = 1;
+	trunk.virtual.vty_number_endpoints = 1;
 	trunk.endpoints = endpoints;
 	trunk.endpoints[0] = &endp;
 	endp.trunk = &trunk;
@@ -1315,7 +1315,7 @@
 	endp.cfg = &cfg;
 	endp.type = &ep_typeset.rtp;
 
-	trunk.vty_number_endpoints = 1;
+	trunk.virtual.vty_number_endpoints = 1;
 	trunk.endpoints = endpoints;
 	trunk.endpoints[0] = &endp;
 	trunk.force_constant_ssrc = patch_ssrc;
@@ -1394,7 +1394,7 @@
 
 	cfg = mgcp_config_alloc();
 	trunk = mgcp_trunk_by_num(cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
-	trunk->vty_number_endpoints = 64;
+	trunk->virtual.vty_number_endpoints = 64;
         mgcp_trunk_alloc_endpts(trunk);
 	cfg->policy_cb = mgcp_test_policy_cb;
 
@@ -1540,7 +1540,7 @@
 
 	cfg = mgcp_config_alloc();
 	trunk = mgcp_trunk_by_num(cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
-	trunk->vty_number_endpoints = 64;
+	trunk->virtual.vty_number_endpoints = 64;
         mgcp_trunk_alloc_endpts(trunk);
 
 	endp = mgcp_endp_by_name(NULL, "rtpbridge/1 at mgw", cfg);
@@ -1590,7 +1590,7 @@
 	cfg = mgcp_config_alloc();
 	trunk = mgcp_trunk_by_num(cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
 
-	trunk->vty_number_endpoints = 64;
+	trunk->virtual.vty_number_endpoints = 64;
 	trunk->audio_send_name = 0;
         mgcp_trunk_alloc_endpts(trunk);
 

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

Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Change-Id: I73b31e3c236a61ea0a6f76ef5ff98ce589f52c77
Gerrit-Change-Number: 19121
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/20200703/2b82e548/attachment.htm>


More information about the gerrit-log mailing list