mirror of
https://gitea.osmocom.org/cellular-infrastructure/osmo-mgw.git
synced 2025-10-23 08:12:01 +00:00
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
This commit is contained in:
@@ -137,6 +137,8 @@ uint32_t mgcp_client_remote_addr_n(struct mgcp_client *mgcp);
|
||||
|
||||
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. */
|
||||
|
@@ -902,6 +902,58 @@ const char *mgcp_client_rtpbridge_wildcard(const struct mgcp_client *mgcp)
|
||||
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,
|
||||
|
@@ -547,6 +547,57 @@ static void test_map_codec_to_pt_and_map_pt_to_codec(void)
|
||||
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 @@ int main(int argc, char **argv)
|
||||
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");
|
||||
|
@@ -72,4 +72,9 @@ DLMGCP ptmap contains illegal mapping: codec=113 maps to pt=2
|
||||
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@mgw), rate(128)/offset(0) combination is invalid!
|
||||
DLMGCP Cannot compose MGCP e1-endpoint name (ds/e1-15/s-1/su8-16@mgw), rate(8)/offset(16) combination is invalid!
|
||||
DLMGCP Cannot compose MGCP e1-endpoint name (ds/e1-15/s-0/su8-2@mgw), E1-timeslot number (0) is invalid!
|
||||
DLMGCP Cannot compose MGCP e1-endpoint name (ds/e1-15/s-64/su8-2@mgw), E1-timeslot number (64) is invalid!
|
||||
Done
|
||||
|
@@ -178,4 +178,19 @@ test_sdp_section_start() test [9]:
|
||||
2 <= 2
|
||||
100 <= 100
|
||||
|
||||
ds/e1-1/s-15/su64-0@mgw
|
||||
ds/e1-2/s-14/su32-0@mgw
|
||||
ds/e1-3/s-13/su32-4@mgw
|
||||
ds/e1-4/s-12/su16-0@mgw
|
||||
ds/e1-5/s-11/su16-2@mgw
|
||||
ds/e1-6/s-10/su16-4@mgw
|
||||
ds/e1-7/s-9/su16-6@mgw
|
||||
ds/e1-8/s-8/su8-0@mgw
|
||||
ds/e1-9/s-7/su8-1@mgw
|
||||
ds/e1-10/s-6/su8-2@mgw
|
||||
ds/e1-11/s-5/su8-3@mgw
|
||||
ds/e1-12/s-4/su8-4@mgw
|
||||
ds/e1-13/s-3/su8-5@mgw
|
||||
ds/e1-14/s-2/su8-6@mgw
|
||||
ds/e1-15/s-1/su8-7@mgw
|
||||
Done
|
||||
|
Reference in New Issue
Block a user