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.orglaforge has submitted this change. ( 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. Change-Id: Iec35b5bae8a7b07ddb3559f7114a24dcd10e8f14 Related: OS#2547 --- M include/osmocom/mgcp_client/mgcp_client.h M src/libosmo-mgcp-client/mgcp_client.c M tests/mgcp_client/mgcp_client_test.c M tests/mgcp_client/mgcp_client_test.err M tests/mgcp_client/mgcp_client_test.ok 5 files changed, 126 insertions(+), 0 deletions(-) Approvals: laforge: Looks good to me, but someone else must approve daniel: Looks good to me, approved Jenkins Builder: Verified diff --git a/include/osmocom/mgcp_client/mgcp_client.h b/include/osmocom/mgcp_client/mgcp_client.h index 32bd87b..d4dd2d9 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(void *ctx, 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 bbf805b..1ca7483 100644 --- a/src/libosmo-mgcp-client/mgcp_client.c +++ b/src/libosmo-mgcp-client/mgcp_client.c @@ -902,6 +902,58 @@ return _mgcp_client_name_append_domain(mgcp, "rtpbridge/*"); } +/*! Compose endpoint name for an E1 endpoint. + * \param[in] ctx talloc context. + * \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-1/s-1/su16-4). */ +const char *mgcp_client_e1_epname(void *ctx, 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() */ + const uint8_t valid_rates[] = { 64, 32, 32, 16, 16, 16, 16, 8, 8, 8, 8, 8, 8, 8, 8 }; + const uint8_t valid_offsets[] = { 0, 0, 4, 0, 2, 4, 6, 0, 1, 2, 3, 4, 5, 6, 7 }; + + uint8_t i; + bool rate_offs_valid = false; + char *epname; + + epname = + talloc_asprintf(ctx, "ds/e1-%u/s-%u/su%u-%u@%s", trunk_id, ts, rate, offset, + mgcp_client_endpoint_domain(mgcp)); + if (!epname) { + LOGP(DLMGCP, LOGL_ERROR, "Cannot compose MGCP e1-endpoint name!\n"); + return NULL; + } + + /* 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 (%s), rate(%u)/offset(%u) combination is invalid!\n", epname, + rate, offset); + talloc_free(epname); + return NULL; + } + + /* An E1 line has a maximum of 32 timeslots, while the first (ts=0) is + * reserverd for framing and alignment, so we can not use it here. */ + if (ts == 0 || ts > 31) { + LOGP(DLMGCP, LOGL_ERROR, + "Cannot compose MGCP e1-endpoint name (%s), E1-timeslot number (%u) is invalid!\n", epname, ts); + talloc_free(epname); + return NULL; + } + + return epname; +} + struct mgcp_response_pending * mgcp_client_pending_add( struct mgcp_client *mgcp, mgcp_trans_id_t trans_id, diff --git a/tests/mgcp_client/mgcp_client_test.c b/tests/mgcp_client/mgcp_client_test.c index d2e34a6..db9f4f8 100644 --- a/tests/mgcp_client/mgcp_client_test.c +++ b/tests/mgcp_client/mgcp_client_test.c @@ -547,6 +547,57 @@ printf("\n"); } +void test_mgcp_client_e1_epname(void) +{ + char *epname; + + if (mgcp) + talloc_free(mgcp); + mgcp = mgcp_client_init(ctx, &conf); + + /* Valid endpoint names */ + epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 1, 15, 64, 0); + printf("%s\n", epname); + epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 2, 14, 32, 0); + printf("%s\n", epname); + epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 3, 13, 32, 4); + printf("%s\n", epname); + epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 4, 12, 16, 0); + printf("%s\n", epname); + epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 5, 11, 16, 2); + printf("%s\n", epname); + epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 6, 10, 16, 4); + printf("%s\n", epname); + epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 7, 9, 16, 6); + printf("%s\n", epname); + epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 8, 8, 8, 0); + printf("%s\n", epname); + epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 9, 7, 8, 1); + printf("%s\n", epname); + epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 10, 6, 8, 2); + printf("%s\n", epname); + epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 11, 5, 8, 3); + printf("%s\n", epname); + epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 12, 4, 8, 4); + printf("%s\n", epname); + epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 13, 3, 8, 5); + printf("%s\n", epname); + epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 14, 2, 8, 6); + printf("%s\n", epname); + epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 15, 1, 8, 7); + printf("%s\n", epname); + + /* A few invalid enpoint names */ + epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 15, 1, 128, 0); + OSMO_ASSERT(epname == NULL); + epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 15, 1, 8, 16); + OSMO_ASSERT(epname == NULL); + epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 15, 0, 8, 2); + OSMO_ASSERT(epname == NULL); + epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 15, 64, 8, 2); + OSMO_ASSERT(epname == NULL); +} + static const struct log_info_cat log_categories[] = { }; @@ -575,6 +626,7 @@ test_sdp_section_start(); test_map_codec_to_pt_and_map_pt_to_codec(); test_map_pt_to_codec(); + test_mgcp_client_e1_epname(); printf("Done\n"); fprintf(stderr, "Done\n"); diff --git a/tests/mgcp_client/mgcp_client_test.err b/tests/mgcp_client/mgcp_client_test.err index fbcf8f6..e114f79 100644 --- a/tests/mgcp_client/mgcp_client_test.err +++ b/tests/mgcp_client/mgcp_client_test.err @@ -72,4 +72,9 @@ DLMGCP ptmap contains illegal mapping: codec=0 maps to pt=100 DLMGCP ptmap contains illegal mapping: codec=113 maps to pt=2 DLMGCP ptmap contains illegal mapping: codec=0 maps to pt=100 +DLMGCP MGCP client: using endpoint domain '@mgw' +DLMGCP Cannot compose MGCP e1-endpoint name (ds/e1-15/s-1/su128-0 at mgw), rate(128)/offset(0) combination is invalid! +DLMGCP Cannot compose MGCP e1-endpoint name (ds/e1-15/s-1/su8-16 at mgw), rate(8)/offset(16) combination is invalid! +DLMGCP Cannot compose MGCP e1-endpoint name (ds/e1-15/s-0/su8-2 at mgw), E1-timeslot number (0) is invalid! +DLMGCP Cannot compose MGCP e1-endpoint name (ds/e1-15/s-64/su8-2 at mgw), E1-timeslot number (64) is invalid! Done diff --git a/tests/mgcp_client/mgcp_client_test.ok b/tests/mgcp_client/mgcp_client_test.ok index 8b3e15b..2b03ba1 100644 --- a/tests/mgcp_client/mgcp_client_test.ok +++ b/tests/mgcp_client/mgcp_client_test.ok @@ -178,4 +178,19 @@ 2 <= 2 100 <= 100 +ds/e1-1/s-15/su64-0 at mgw +ds/e1-2/s-14/su32-0 at mgw +ds/e1-3/s-13/su32-4 at mgw +ds/e1-4/s-12/su16-0 at mgw +ds/e1-5/s-11/su16-2 at mgw +ds/e1-6/s-10/su16-4 at mgw +ds/e1-7/s-9/su16-6 at mgw +ds/e1-8/s-8/su8-0 at mgw +ds/e1-9/s-7/su8-1 at mgw +ds/e1-10/s-6/su8-2 at mgw +ds/e1-11/s-5/su8-3 at mgw +ds/e1-12/s-4/su8-4 at mgw +ds/e1-13/s-3/su8-5 at mgw +ds/e1-14/s-2/su8-6 at mgw +ds/e1-15/s-1/su8-7 at mgw Done -- 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: 9 Gerrit-Owner: dexter <pmaier at sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel <dwillmann 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/ee71a752/attachment.htm>