From 44016fee14a494f3fa13b9f094dc205985db2e5e Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 28 Feb 2011 14:46:01 +0100 Subject: mgcp: Fix the static allocation of E1 trunks for the BTS/NET side --- openbsc/include/openbsc/mgcp.h | 4 ++++ openbsc/src/mgcp/mgcp_vty.c | 23 ++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) (limited to 'openbsc') diff --git a/openbsc/include/openbsc/mgcp.h b/openbsc/include/openbsc/mgcp.h index 88e523026..516b76edf 100644 --- a/openbsc/include/openbsc/mgcp.h +++ b/openbsc/include/openbsc/mgcp.h @@ -153,6 +153,10 @@ struct mgcp_config { /* trunk handling */ struct mgcp_trunk_config trunk; struct llist_head trunks; + + /* only used for start with a static configuration */ + int last_net_port; + int last_bts_port; }; /* config management */ diff --git a/openbsc/src/mgcp/mgcp_vty.c b/openbsc/src/mgcp/mgcp_vty.c index f9554980c..f71c17be4 100644 --- a/openbsc/src/mgcp/mgcp_vty.c +++ b/openbsc/src/mgcp/mgcp_vty.c @@ -651,29 +651,30 @@ static int allocate_trunk(struct mgcp_trunk_config *trunk) /* early bind */ for (i = 1; i < trunk->number_endpoints; ++i) { struct mgcp_endpoint *endp = &trunk->endpoints[i]; - int rtp_port; if (cfg->bts_ports.mode == PORT_ALLOC_STATIC) { - rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp), - 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); + cfg->last_bts_port += 2; + if (mgcp_bind_bts_rtp_port(endp, cfg->last_bts_port) != 0) { + LOGP(DMGCP, LOGL_FATAL, + "Failed to bind: %d\n", cfg->last_bts_port); return -1; } endp->bts_end.local_alloc = PORT_ALLOC_STATIC; } if (cfg->net_ports.mode == PORT_ALLOC_STATIC) { - rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp), - 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); + cfg->last_net_port += 2; + if (mgcp_bind_net_rtp_port(endp, cfg->last_net_port) != 0) { + LOGP(DMGCP, LOGL_FATAL, + "Failed to bind: %d\n", cfg->last_net_port); return -1; } endp->net_end.local_alloc = PORT_ALLOC_STATIC; } if (cfg->transcoder_ip && cfg->transcoder_ports.mode == PORT_ALLOC_STATIC) { + int rtp_port; + /* network side */ rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp), cfg->transcoder_ports.base_port); @@ -718,6 +719,10 @@ int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg) return -1; } + /* initialize the last ports */ + g_cfg->last_bts_port = rtp_calculate_port(0, g_cfg->bts_ports.base_port); + g_cfg->last_net_port = rtp_calculate_port(0, g_cfg->net_ports.base_port); + if (allocate_trunk(&g_cfg->trunk) != 0) { LOGP(DMGCP, LOGL_ERROR, "Failed to initialize the virtual trunk.\n"); return -1; -- cgit v1.2.3