Change in osmo-mgw[master]: mgcp_vty: fix 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/.

laforge gerrit-no-reply at lists.osmocom.org
Thu Jul 16 11:57:47 UTC 2020


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

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

mgcp_vty: fix 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 src/libosmo-mgcp/mgcp_trunk.c
M src/libosmo-mgcp/mgcp_vty.c
M tests/mgcp/mgcp_test.c
3 files changed, 37 insertions(+), 19 deletions(-)

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



diff --git a/src/libosmo-mgcp/mgcp_trunk.c b/src/libosmo-mgcp/mgcp_trunk.c
index f3785cd..55a8953 100644
--- a/src/libosmo-mgcp/mgcp_trunk.c
+++ b/src/libosmo-mgcp/mgcp_trunk.c
@@ -47,7 +47,7 @@
 
 	trunk->audio_send_ptime = 1;
 	trunk->audio_send_name = 1;
-	trunk->vty_number_endpoints = 33;
+	trunk->vty_number_endpoints = 32;
 	trunk->omit_rtcp = 0;
 
 	mgcp_trunk_set_keepalive(trunk, MGCP_KEEPALIVE_ONCE);
@@ -67,13 +67,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 first_endpoint_nr;
 
 	/* 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 +76,39 @@
 	OSMO_ASSERT(trunk->number_endpoints == 0);
 	OSMO_ASSERT(trunk->endpoints == NULL);
 
+	switch (trunk->trunk_type) {
+	case MGCP_TRUNK_VIRTUAL:
+		/* Due to historical reasons the endpoints on the virtual
+		 * trunk start counting at 1. */
+		first_endpoint_nr = 1;
+		number_endpoints = trunk->vty_number_endpoints;
+		break;
+	case MGCP_TRUNK_E1:
+		/* The first timeslot on an E1 line is reserved for framing
+		 * and alignment and can not be used for audio transport */
+	        first_endpoint_nr = 1 * MGCP_ENDP_E1_SUBSLOTS;
+		number_endpoints = 31 * 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-initialization 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 + first_endpoint_nr);
 		if (!endp) {
 			talloc_free(trunk->endpoints);
 			return -1;
@@ -98,7 +117,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 2f862f1..35b75fb 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->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);
@@ -710,13 +710,12 @@
 
 DEFUN(cfg_mgcp_number_endp,
       cfg_mgcp_number_endp_cmd,
-      "number endpoints <0-65534>",
+      "number endpoints <1-65534>",
       "Number options\n" "Endpoints available\n" "Number endpoints\n")
 {
 	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->vty_number_endpoints = atoi(argv[0]);
 	return CMD_SUCCESS;
 }
 
diff --git a/tests/mgcp/mgcp_test.c b/tests/mgcp/mgcp_test.c
index 9cafcf7..792ae1f 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)
 			osmo_strlcpy(last_endpoint, trunk->endpoints[i]->name,
 				     sizeof(last_endpoint));
@@ -656,7 +656,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]);
 }
 

-- 
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: 7
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann at sysmocom.de>
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/20200716/592de809/attachment.htm>


More information about the gerrit-log mailing list