aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2011-09-14 01:42:22 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2011-09-18 12:37:22 +0000
commit5712864b4c77c1f38dc3a193f18cb3dc998b1d44 (patch)
tree1a21b6695c0ff92cb8e75905d6ac85122cde0289
parent0fcc075e5eded3ac1580f8099be806ca9bc94caa (diff)
mgcp: Add VTY commands to block endpoints instead of having this hardcoded
Instead of assuming which endpoints are blocked there is now a VTY command to block those. Clean up the init of the trunks, the only difference between Virtual and E1 is in the way to calculate the start port. Reduce the number of endpoints to 32, 31 is the last one that can be used on the E1 trunk, otherwise we move into TS 0 of the following trunk.
-rw-r--r--src/mgcp/mgcp_protocol.c4
-rw-r--r--src/mgcp_ss7.c89
-rw-r--r--src/mgcp_ss7_vty.c45
3 files changed, 89 insertions, 49 deletions
diff --git a/src/mgcp/mgcp_protocol.c b/src/mgcp/mgcp_protocol.c
index df47264..ec69f15 100644
--- a/src/mgcp/mgcp_protocol.c
+++ b/src/mgcp/mgcp_protocol.c
@@ -932,7 +932,7 @@ struct mgcp_trunk_config *mgcp_trunk_alloc(struct mgcp_config *cfg, int nr)
trunk->trunk_type = MGCP_TRUNK_E1;
trunk->trunk_nr = nr;
trunk_init(trunk);
- trunk->number_endpoints = 33;
+ trunk->number_endpoints = 32;
llist_add_tail(&trunk->entry, &cfg->trunks);
return trunk;
}
@@ -986,6 +986,8 @@ int mgcp_endpoints_allocate(struct mgcp_trunk_config *tcfg)
if (!tcfg->endpoints)
return -1;
+ tcfg->endpoints[0].blocked = 1;
+
for (i = 0; i < tcfg->number_endpoints; ++i) {
tcfg->endpoints[i].ci = CI_UNUSED;
tcfg->endpoints[i].cfg = tcfg->cfg;
diff --git a/src/mgcp_ss7.c b/src/mgcp_ss7.c
index b224e0c..aff477c 100644
--- a/src/mgcp_ss7.c
+++ b/src/mgcp_ss7.c
@@ -662,6 +662,41 @@ static int realloc_cb(struct mgcp_trunk_config *tcfg, int endp_no)
return 0;
}
+static int configure_trunk(struct mgcp_trunk_config *tcfg, int *dsp_resource)
+{
+ int i, start;
+
+ start = tcfg->trunk_type == MGCP_TRUNK_VIRTUAL ?
+ tcfg->target_trunk_start : tcfg->trunk_nr;
+
+ for (i = 1; i < tcfg->number_endpoints; ++i) {
+ if (tcfg->endpoints[i].blocked)
+ continue;
+
+ *dsp_resource += 1;
+ tcfg->endpoints[i].hw_snmp_port = *dsp_resource;
+
+ if (tcfg->cfg->configure_trunks) {
+ int multiplex, timeslot, res;
+
+ mgcp_endpoint_to_timeslot(i, &multiplex, &timeslot);
+ res = mgcp_snmp_connect(*dsp_resource,
+ start + multiplex,
+ timeslot);
+
+ if (res != 0) {
+ LOGP(DMGCP, LOGL_ERROR,
+ "Failed to configure trunk Type: %s Trunk: %d\n",
+ tcfg->trunk_type == MGCP_TRUNK_VIRTUAL ?
+ "virtual" : "trunk", start);
+ return -1;
+ }
+ }
+ }
+
+ return 0;
+}
+
static struct mgcp_ss7 *mgcp_ss7_init(struct mgcp_config *cfg)
{
struct mgcp_trunk_config *trunk;
@@ -697,58 +732,16 @@ static struct mgcp_ss7 *mgcp_ss7_init(struct mgcp_config *cfg)
/* Now do the init of the trunks */
dsp_resource = 0;
for (i = 1; i < cfg->trunk.number_endpoints; ++i) {
- int multiplex, timeslot;
- mgcp_endpoint_to_timeslot(i, &multiplex, &timeslot);
- if (timeslot == 0x0 || timeslot == 0x1F) {
- cfg->trunk.endpoints[i].blocked = 1;
- continue;
- }
-
- dsp_resource += 1;
- cfg->trunk.endpoints[i].hw_snmp_port = dsp_resource;
-
- if (cfg->configure_trunks) {
- int res;
-
- res = mgcp_snmp_connect(dsp_resource,
- cfg->trunk.target_trunk_start + multiplex,
- timeslot);
-
- if (res != 0) {
- LOGP(DMGCP, LOGL_ERROR, "Failed to configure virtual trunk.\n");
- talloc_free(conf);
- return NULL;
- }
+ if (configure_trunk(&cfg->trunk, &dsp_resource) != 0) {
+ talloc_free(conf);
+ return NULL;
}
}
llist_for_each_entry(trunk, &cfg->trunks, entry) {
-
- for (i = 1; i < trunk->number_endpoints; ++i) {
- int multiplex, timeslot;
- mgcp_endpoint_to_timeslot(i, &multiplex, &timeslot);
- if (timeslot == 0x0 || timeslot == 0x1) {
- trunk->endpoints[i].blocked = 1;
- continue;
- }
-
- dsp_resource += 1;
- trunk->endpoints[i].hw_snmp_port = dsp_resource;
-
- if (cfg->configure_trunks) {
- int res;
-
- res = mgcp_snmp_connect(dsp_resource,
- trunk->trunk_nr + multiplex,
- timeslot);
-
- if (res != 0) {
- LOGP(DMGCP, LOGL_ERROR,
- "Failed to configure virtual trunk.\n");
- talloc_free(conf);
- return NULL;
- }
- }
+ if (configure_trunk(trunk, &dsp_resource) != 0) {
+ talloc_free(conf);
+ return NULL;
}
}
diff --git a/src/mgcp_ss7_vty.c b/src/mgcp_ss7_vty.c
index d145777..a1fa86e 100644
--- a/src/mgcp_ss7_vty.c
+++ b/src/mgcp_ss7_vty.c
@@ -23,6 +23,7 @@
#include <ss7_vty.h>
#include <mgcp/mgcp.h>
+#include <mgcp/mgcp_internal.h>
#include <stdlib.h>
@@ -172,6 +173,24 @@ DEFUN(cfg_mgcp_target_trunk, cfg_mgcp_target_trunk_cmd,
return CMD_SUCCESS;
}
+#define ENDP_BLOCK_STR "Block the Endpoint/Timeslot for Audio\n"
+
+DEFUN(cfg_mgcp_timeslot_block, cfg_mgcp_timeslot_block_cmd,
+ "block-endpoint <1-65534>",
+ ENDP_BLOCK_STR "Endpoint number\n")
+{
+ int nr = atoi(argv[0]);
+
+ if (g_cfg->trunk.number_endpoints <= nr) {
+ vty_out(vty, "%%Endpoint %d too big. Current size: %d%s",
+ nr, g_cfg->trunk.number_endpoints, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ g_cfg->trunk.endpoints[nr].blocked = 1;
+ return CMD_SUCCESS;
+}
+
DEFUN(cfg_trunk_vad, cfg_trunk_vad_cmd,
"vad (enabled|disabled)",
"Enable the Voice Activity Detection\n"
@@ -315,6 +334,28 @@ DEFUN_DEPRECATED(cfg_trunk_endp_offset, cfg_trunk_endp_offset_cmd,
return CMD_WARNING;
}
+DEFUN(cfg_trunk_timeslot_block, cfg_trunk_timeslot_block_cmd,
+ "block-endpoint <1-31>",
+ ENDP_BLOCK_STR "Endpoint number\n")
+{
+ struct mgcp_trunk_config *trunk = vty->index;
+ trunk->endpoints[atoi(argv[0])].blocked = 1;
+ return CMD_SUCCESS;
+}
+
+static void write_blocked_endpoints(struct vty *vty,
+ struct mgcp_trunk_config *tcfg)
+{
+ int i;
+
+ for (i = 1; i < tcfg->number_endpoints; ++i) {
+ if (!tcfg->endpoints[i].blocked)
+ continue;
+
+ vty_out(vty, "block-endpoint %d%s", i, VTY_NEWLINE);
+ }
+}
+
void mgcp_write_extra(struct vty *vty, struct mgcp_config *cfg)
{
vty_out(vty, " configure-trunks %d%s",
@@ -345,6 +386,7 @@ void mgcp_write_extra(struct vty *vty, struct mgcp_config *cfg)
cfg->trunk.dwnstr_target_lvl, VTY_NEWLINE);
vty_out(vty, " target-trunk-start %d%s",
cfg->trunk.target_trunk_start, VTY_NEWLINE);
+ write_blocked_endpoints(vty, &cfg->trunk);
}
void mgcp_write_trunk_extra(struct vty *vty, struct mgcp_trunk_config *trunk)
@@ -373,6 +415,7 @@ void mgcp_write_trunk_extra(struct vty *vty, struct mgcp_trunk_config *trunk)
trunk->dwnstr_max_gain, VTY_NEWLINE);
vty_out(vty, " downstream-target-level %d%s",
trunk->dwnstr_target_lvl, VTY_NEWLINE);
+ write_blocked_endpoints(vty, trunk);
}
@@ -398,6 +441,7 @@ void mgcp_mgw_vty_init(void)
install_element(MGCP_NODE, &cfg_mgcp_dwnstr_target_cmd);
install_element(MGCP_NODE, &cfg_mgcp_endp_offset_cmd);
install_element(MGCP_NODE, &cfg_mgcp_target_trunk_cmd);
+ install_element(MGCP_NODE, &cfg_mgcp_timeslot_block_cmd);
install_element(TRUNK_NODE, &cfg_trunk_vad_cmd);
install_element(TRUNK_NODE, &cfg_trunk_realloc_cmd);
@@ -412,6 +456,7 @@ void mgcp_mgw_vty_init(void)
install_element(TRUNK_NODE, &cfg_trunk_dwnstr_max_gain_cmd);
install_element(TRUNK_NODE, &cfg_trunk_dwnstr_target_cmd);
install_element(TRUNK_NODE, &cfg_trunk_endp_offset_cmd);
+ install_element(TRUNK_NODE, &cfg_trunk_timeslot_block_cmd);
}