aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2011-02-28 14:37:03 +0100
committerHolger Hans Peter Freyther <zecke@selfish.org>2011-02-28 19:40:53 +0100
commit1f0c5b47426b4236ae0c91c71bc0d14a157f222f (patch)
treeef10bc6a84e9618220d90738410267db8e4b39be
parent74e61110e5f8231dd11a921252157dd924aefce6 (diff)
mgcp: Allocate the endpoints for the E1 trunks as well.
-rw-r--r--openbsc/include/openbsc/mgcp.h2
-rw-r--r--openbsc/src/mgcp/mgcp_protocol.c9
-rw-r--r--openbsc/src/mgcp/mgcp_vty.c83
-rw-r--r--openbsc/tests/mgcp/mgcp_test.c5
4 files changed, 61 insertions, 38 deletions
diff --git a/openbsc/include/openbsc/mgcp.h b/openbsc/include/openbsc/mgcp.h
index 54a3a6ee2..88e523026 100644
--- a/openbsc/include/openbsc/mgcp.h
+++ b/openbsc/include/openbsc/mgcp.h
@@ -159,7 +159,7 @@ struct mgcp_config {
struct mgcp_config *mgcp_config_alloc(void);
int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg);
int mgcp_vty_init(void);
-int mgcp_endpoints_allocate(struct mgcp_config *cfg);
+int mgcp_endpoints_allocate(struct mgcp_trunk_config *cfg);
void mgcp_free_endp(struct mgcp_endpoint *endp);
int mgcp_reset_transcoder(struct mgcp_config *cfg);
diff --git a/openbsc/src/mgcp/mgcp_protocol.c b/openbsc/src/mgcp/mgcp_protocol.c
index 46214a559..b95cc81a8 100644
--- a/openbsc/src/mgcp/mgcp_protocol.c
+++ b/openbsc/src/mgcp/mgcp_protocol.c
@@ -942,15 +942,12 @@ static void mgcp_rtp_end_init(struct mgcp_rtp_end *end)
end->rtcp.fd = -1;
}
-int mgcp_endpoints_allocate(struct mgcp_config *cfg)
+int mgcp_endpoints_allocate(struct mgcp_trunk_config *tcfg)
{
- struct mgcp_trunk_config *tcfg;
int i;
- tcfg = &cfg->trunk;
-
/* Initialize all endpoints */
- tcfg->endpoints = _talloc_zero_array(cfg,
+ tcfg->endpoints = _talloc_zero_array(tcfg->cfg,
sizeof(struct mgcp_endpoint),
tcfg->number_endpoints, "endpoints");
if (!tcfg->endpoints)
@@ -958,7 +955,7 @@ int mgcp_endpoints_allocate(struct mgcp_config *cfg)
for (i = 0; i < tcfg->number_endpoints; ++i) {
tcfg->endpoints[i].ci = CI_UNUSED;
- tcfg->endpoints[i].cfg = cfg;
+ tcfg->endpoints[i].cfg = tcfg->cfg;
tcfg->endpoints[i].tcfg = tcfg;
mgcp_rtp_end_init(&tcfg->endpoints[i].net_end);
mgcp_rtp_end_init(&tcfg->endpoints[i].bts_end);
diff --git a/openbsc/src/mgcp/mgcp_vty.c b/openbsc/src/mgcp/mgcp_vty.c
index 81cc68b26..f9554980c 100644
--- a/openbsc/src/mgcp/mgcp_vty.c
+++ b/openbsc/src/mgcp/mgcp_vty.c
@@ -636,40 +636,26 @@ int mgcp_vty_init(void)
return 0;
}
-int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg)
+static int allocate_trunk(struct mgcp_trunk_config *trunk)
{
- int i, rc;
-
- g_cfg = cfg;
- rc = vty_read_config_file(config_file, NULL);
- if (rc < 0) {
- fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
- return rc;
- }
-
-
- if (!g_cfg->bts_ip)
- fprintf(stderr, "No BTS ip address specified. This will allow everyone to connect.\n");
-
- if (!g_cfg->source_addr) {
- fprintf(stderr, "You need to specify a bind address.\n");
- return -1;
- }
+ int i;
+ struct mgcp_config *cfg = trunk->cfg;
- if (mgcp_endpoints_allocate(g_cfg) != 0) {
- fprintf(stderr, "Failed to allocate endpoints: %d. Quitting.\n",
- g_cfg->trunk.number_endpoints);
+ if (mgcp_endpoints_allocate(trunk) != 0) {
+ LOGP(DMGCP, LOGL_ERROR,
+ "Failed to allocate %d endpoints on trunk %d.\n",
+ trunk->number_endpoints, trunk->trunk_nr);
return -1;
}
/* early bind */
- for (i = 1; i < g_cfg->trunk.number_endpoints; ++i) {
- struct mgcp_endpoint *endp = &g_cfg->trunk.endpoints[i];
+ for (i = 1; i < trunk->number_endpoints; ++i) {
+ struct mgcp_endpoint *endp = &trunk->endpoints[i];
int rtp_port;
- if (g_cfg->bts_ports.mode == PORT_ALLOC_STATIC) {
+ if (cfg->bts_ports.mode == PORT_ALLOC_STATIC) {
rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp),
- g_cfg->bts_ports.base_port);
+ cfg->bts_ports.base_port);
if (mgcp_bind_bts_rtp_port(endp, rtp_port) != 0) {
LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port);
return -1;
@@ -677,9 +663,9 @@ int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg)
endp->bts_end.local_alloc = PORT_ALLOC_STATIC;
}
- if (g_cfg->net_ports.mode == PORT_ALLOC_STATIC) {
+ if (cfg->net_ports.mode == PORT_ALLOC_STATIC) {
rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp),
- g_cfg->net_ports.base_port);
+ cfg->net_ports.base_port);
if (mgcp_bind_net_rtp_port(endp, rtp_port) != 0) {
LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port);
return -1;
@@ -687,10 +673,10 @@ int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg)
endp->net_end.local_alloc = PORT_ALLOC_STATIC;
}
- if (g_cfg->transcoder_ip && g_cfg->transcoder_ports.mode == PORT_ALLOC_STATIC) {
+ if (cfg->transcoder_ip && cfg->transcoder_ports.mode == PORT_ALLOC_STATIC) {
/* network side */
rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp),
- g_cfg->transcoder_ports.base_port);
+ cfg->transcoder_ports.base_port);
if (mgcp_bind_trans_net_rtp_port(endp, rtp_port) != 0) {
LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port);
return -1;
@@ -699,7 +685,7 @@ int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg)
/* bts side */
rtp_port = rtp_calculate_port(endp_back_channel(ENDPOINT_NUMBER(endp)),
- g_cfg->transcoder_ports.base_port);
+ cfg->transcoder_ports.base_port);
if (mgcp_bind_trans_bts_rtp_port(endp, rtp_port) != 0) {
LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port);
return -1;
@@ -711,3 +697,40 @@ int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg)
return 0;
}
+int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg)
+{
+ int rc;
+ struct mgcp_trunk_config *trunk;
+
+ g_cfg = cfg;
+ rc = vty_read_config_file(config_file, NULL);
+ if (rc < 0) {
+ fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
+ return rc;
+ }
+
+
+ if (!g_cfg->bts_ip)
+ fprintf(stderr, "No BTS ip address specified. This will allow everyone to connect.\n");
+
+ if (!g_cfg->source_addr) {
+ fprintf(stderr, "You need to specify a bind address.\n");
+ return -1;
+ }
+
+ if (allocate_trunk(&g_cfg->trunk) != 0) {
+ LOGP(DMGCP, LOGL_ERROR, "Failed to initialize the virtual trunk.\n");
+ return -1;
+ }
+
+ llist_for_each_entry(trunk, &g_cfg->trunks, entry) {
+ if (allocate_trunk(trunk) != 0) {
+ LOGP(DMGCP, LOGL_ERROR,
+ "Failed to initialize E1 trunk %d.\n", trunk->trunk_nr);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
diff --git a/openbsc/tests/mgcp/mgcp_test.c b/openbsc/tests/mgcp/mgcp_test.c
index c63a7860f..4052377ec 100644
--- a/openbsc/tests/mgcp/mgcp_test.c
+++ b/openbsc/tests/mgcp/mgcp_test.c
@@ -18,6 +18,7 @@
*/
#include <openbsc/mgcp.h>
+#include <openbsc/mgcp_internal.h>
#include <osmocore/talloc.h>
#include <string.h>
@@ -48,7 +49,9 @@ static void test_auep(void)
struct msgb *msg;
struct mgcp_config *cfg = mgcp_config_alloc();
cfg->trunk.number_endpoints = 64;
- mgcp_endpoints_allocate(cfg);
+ mgcp_endpoints_allocate(&cfg->trunk);
+
+ mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1));
inp = create_auep1();
msg = mgcp_handle_message(cfg, inp);