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
This commit is contained in:
Philipp Maier 2020-07-03 16:04:16 +02:00 committed by laforge
parent 37a808c5a5
commit 869b21c869
3 changed files with 37 additions and 19 deletions

View File

@ -47,7 +47,7 @@ struct mgcp_trunk *mgcp_trunk_alloc(struct mgcp_config *cfg, enum mgcp_trunk_typ
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 mgcp_trunk_alloc_endpts(struct mgcp_trunk *trunk)
{
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 @@ int mgcp_trunk_alloc_endpts(struct mgcp_trunk *trunk)
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 @@ int mgcp_trunk_alloc_endpts(struct mgcp_trunk *trunk)
}
/* 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;
}

View File

@ -112,7 +112,7 @@ static int config_write_mgcp(struct vty *vty)
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 @@ static void dump_trunk(struct vty *vty, struct mgcp_trunk *trunk, int show_stats
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_rtp_accept_all,
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;
}

View File

@ -605,7 +605,7 @@ static int mgcp_test_policy_cb(struct mgcp_endpoint *endp,
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 @@ int clock_gettime(clockid_t clk_id, struct timespec *tp)
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]);
}