Change in osmo-mgw[master]: mgcp_client: add function to generate e1-endpoint names

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
Tue Jun 30 18:33:07 UTC 2020


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


Change subject: mgcp_client: add function to generate e1-endpoint names
......................................................................

mgcp_client: add function to generate e1-endpoint names

mgcp_client.h offers functions to generate endpoint names for wildcarded
request. This is used in osmo-bsc, lets now also add a function that can
generate e1-endpoint names.

Related: OS#2547
Change-Id: Iec35b5bae8a7b07ddb3559f7114a24dcd10e8f14
---
M include/osmocom/mgcp_client/mgcp_client.h
M src/libosmo-mgcp-client/mgcp_client.c
2 files changed, 62 insertions(+), 0 deletions(-)



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

diff --git a/include/osmocom/mgcp_client/mgcp_client.h b/include/osmocom/mgcp_client/mgcp_client.h
index 32bd87b..8a43ccc 100644
--- a/include/osmocom/mgcp_client/mgcp_client.h
+++ b/include/osmocom/mgcp_client/mgcp_client.h
@@ -137,6 +137,8 @@
 
 const char *mgcp_client_endpoint_domain(const struct mgcp_client *mgcp);
 const char *mgcp_client_rtpbridge_wildcard(const struct mgcp_client *mgcp);
+const char *mgcp_client_e1_epname(const struct mgcp_client *mgcp, uint8_t trunk_id, uint8_t ts, uint8_t rate,
+				  uint8_t offset);
 
 /* Invoked when an MGCP response is received or sending failed.  When the
  * response is passed as NULL, this indicates failure during transmission. */
diff --git a/src/libosmo-mgcp-client/mgcp_client.c b/src/libosmo-mgcp-client/mgcp_client.c
index 819461d..17983fa 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -900,6 +900,66 @@
 	return _mgcp_client_name_append_domain(mgcp, "rtpbridge/*");
 }
 
+/*! Compose endpoint name for an E1 endpoint.
+ *  \param[in] mgcp MGCP client descriptor.
+ *  \param[in] trunk_id id number of the E1 trunk (1-64).
+ *  \param[in] ts timeslot on the E1 trunk (1-31).
+ *  \param[in] rate bitrate used on the E1 trunk (e.g 16 for 16kbit).
+ *  \param[in] offset bit offset of the E1 subslot (e.g. 4 for the third 16k subslot).
+ *  \returns string containing the endpoint name (e.g. ds/e1-0/s-1/su16-4). */
+const char *mgcp_client_e1_epname(const struct mgcp_client *mgcp, uint8_t trunk_id, uint8_t ts, uint8_t rate,
+				  uint8_t offset)
+{
+	/* See also comment in libosmo-mgcp, mgcp_client.c, gen_e1_epname() */
+	static const uint8_t valid_rates[] = { 64, 32, 32, 16, 16, 16, 16, 8, 8, 8, 8, 8, 8, 8, 8 };
+	static const uint8_t valid_offsets[] = { 0, 0, 4, 0, 2, 4, 6, 0, 1, 2, 3, 4, 5, 6, 7 };
+
+	static char endpoint[MGCP_ENDPOINT_MAXLEN];
+	uint8_t i;
+	int rc;
+	bool rate_offs_valid = false;
+
+	/* Check if the supplied rate/offset pair resembles a valid combination */
+	for (i = 0; i < sizeof(valid_rates); i++) {
+		if (valid_rates[i] == rate && valid_offsets[i] == offset)
+			rate_offs_valid = true;
+	}
+	if (!rate_offs_valid) {
+		LOGP(DLMGCP, LOGL_ERROR,
+		     "Cannot compose MGCP e1-endpoint name, rate(%u)/offset(%u) combination is invalid!\n", rate,
+		     offset);
+		return NULL;
+	}
+
+	/* osmo-mgw only allows a maximum of 64 trunks. The trunk id 0 is
+	 * reserved due to historical reasons. */
+	if (trunk_id == 0 || trunk_id > 64) {
+		LOGP(DLMGCP, LOGL_ERROR, "Cannot compose MGCP e1-endpoint name, trunk number (%u) is invalid!\n",
+		     trunk_id);
+		return NULL;
+	}
+	/* An E1 line has a maximum of 32 timeslots, while the first (ts=0) is
+	 * reserverd for signalling, so we can not use it here. */
+	if (ts == 0 || ts > 31) {
+		LOGP(DLMGCP, LOGL_ERROR, "Cannot compose MGCP e1-endpoint name, E1-timeslot number (%u) is invalid!\n",
+		     ts);
+		return NULL;
+	}
+
+	rc = snprintf(endpoint, sizeof(endpoint), "ds/e1-%u/s-%u/su%u-%u", trunk_id, ts, rate, offset);
+	if (rc > sizeof(endpoint) - 1) {
+		LOGP(DLMGCP, LOGL_ERROR, "MGCP endpoint exceeds maximum length of %zu: 'ds/e1-%u/s-%u/su%u-%u'\n",
+		     sizeof(endpoint) - 1, trunk_id, ts, rate, offset);
+		return NULL;
+	}
+	if (rc < 1) {
+		LOGP(DLMGCP, LOGL_ERROR, "Cannot compose MGCP endpoint name\n");
+		return NULL;
+	}
+
+	return _mgcp_client_name_append_domain(mgcp, endpoint);
+}
+
 struct mgcp_response_pending * mgcp_client_pending_add(
 					struct mgcp_client *mgcp,
 					mgcp_trans_id_t trans_id,

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

Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Change-Id: Iec35b5bae8a7b07ddb3559f7114a24dcd10e8f14
Gerrit-Change-Number: 19075
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/20200630/1a4ca301/attachment.htm>


More information about the gerrit-log mailing list