aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2011-02-27 11:04:27 +0100
committerHolger Hans Peter Freyther <zecke@selfish.org>2011-02-27 11:05:18 +0100
commit9ec030d32da5426e184179c4867b01b910885dec (patch)
tree8590afb1a90b87274fd0224606f6a6ac1d3353e9 /openbsc
parenta9e9331285bccb97e3e9b8aeb5659b1fe119597b (diff)
nat: Change number of multiplexes to the max-endpoints
Diffstat (limited to 'openbsc')
-rw-r--r--openbsc/include/openbsc/bsc_nat.h4
-rw-r--r--openbsc/src/nat/bsc_mgcp_utils.c29
-rw-r--r--openbsc/src/nat/bsc_nat_utils.c2
-rw-r--r--openbsc/src/nat/bsc_nat_vty.c16
-rw-r--r--openbsc/tests/bsc-nat/bsc_nat_test.c7
5 files changed, 42 insertions, 16 deletions
diff --git a/openbsc/include/openbsc/bsc_nat.h b/openbsc/include/openbsc/bsc_nat.h
index 2fc8e40cf..ad46aaa06 100644
--- a/openbsc/include/openbsc/bsc_nat.h
+++ b/openbsc/include/openbsc/bsc_nat.h
@@ -80,6 +80,7 @@ struct bsc_connection {
/* mgcp related code */
char *_endpoint_status;
int number_multiplexes;
+ int max_endpoints;
int last_endpoint;
/* a back pointer */
@@ -126,7 +127,7 @@ struct bsc_config {
int forbid_paging;
/* audio handling */
- int number_multiplexes;
+ int max_endpoints;
/* backpointer */
struct bsc_nat *nat;
@@ -306,6 +307,7 @@ struct sccp_connections *bsc_nat_find_con_by_bsc(struct bsc_nat *, struct sccp_s
/**
* MGCP/Audio handling
*/
+int bsc_mgcp_nr_multiplexes(int max_endpoints);
int bsc_write_mgcp(struct bsc_connection *bsc, const uint8_t *data, unsigned int length);
int bsc_mgcp_assign_patch(struct sccp_connections *, struct msgb *msg);
void bsc_mgcp_init(struct sccp_connections *);
diff --git a/openbsc/src/nat/bsc_mgcp_utils.c b/openbsc/src/nat/bsc_mgcp_utils.c
index 4df5621ed..363734932 100644
--- a/openbsc/src/nat/bsc_mgcp_utils.c
+++ b/openbsc/src/nat/bsc_mgcp_utils.c
@@ -38,8 +38,20 @@
#include <errno.h>
#include <unistd.h>
+int bsc_mgcp_nr_multiplexes(int max_endpoints)
+{
+ int div = max_endpoints / 32;
+
+ if ((max_endpoints % 32) != 0)
+ div += 1;
+
+ return div;
+}
+
static int bsc_init_endps_if_needed(struct bsc_connection *con)
{
+ int multiplexes;
+
/* we have done that */
if (con->_endpoint_status)
return 0;
@@ -48,9 +60,10 @@ static int bsc_init_endps_if_needed(struct bsc_connection *con)
if (!con->cfg)
return -1;
- con->number_multiplexes = con->cfg->number_multiplexes;
- con->_endpoint_status = talloc_zero_array(con, char,
- (32 * con->cfg->number_multiplexes) + 1);
+ multiplexes = bsc_mgcp_nr_multiplexes(con->cfg->max_endpoints);
+ con->number_multiplexes = multiplexes;
+ con->max_endpoints = con->cfg->max_endpoints;
+ con->_endpoint_status = talloc_zero_array(con, char, 32 * multiplexes + 1);
return con->_endpoint_status == NULL;
}
@@ -58,7 +71,7 @@ static int bsc_assign_endpoint(struct bsc_connection *bsc, struct sccp_connectio
{
int multiplex;
int timeslot;
- const int number_endpoints = 32 * bsc->number_multiplexes;
+ const int number_endpoints = bsc->max_endpoints;
int i;
mgcp_endpoint_to_timeslot(bsc->last_endpoint, &multiplex, &timeslot);
@@ -82,6 +95,14 @@ static int bsc_assign_endpoint(struct bsc_connection *bsc, struct sccp_connectio
endpoint = mgcp_timeslot_to_endpoint(multiplex, timeslot);
+ /* Now check if we are allowed to assign this one */
+ if (endpoint >= bsc->max_endpoints) {
+ multiplex = 0;
+ timeslot = 1;
+ endpoint = mgcp_timeslot_to_endpoint(multiplex, timeslot);
+ }
+
+
if (bsc->_endpoint_status[endpoint] == 0) {
bsc->_endpoint_status[endpoint] = 1;
con->bsc_endp = endpoint;
diff --git a/openbsc/src/nat/bsc_nat_utils.c b/openbsc/src/nat/bsc_nat_utils.c
index 047038785..6a3b27466 100644
--- a/openbsc/src/nat/bsc_nat_utils.c
+++ b/openbsc/src/nat/bsc_nat_utils.c
@@ -126,7 +126,7 @@ struct bsc_config *bsc_config_alloc(struct bsc_nat *nat, const char *token)
conf->token = talloc_strdup(conf, token);
conf->nr = nat->num_bsc;
conf->nat = nat;
- conf->number_multiplexes = 1;
+ conf->max_endpoints = 32;
INIT_LLIST_HEAD(&conf->lac_list);
diff --git a/openbsc/src/nat/bsc_nat_vty.c b/openbsc/src/nat/bsc_nat_vty.c
index 5366dd384..761c29947 100644
--- a/openbsc/src/nat/bsc_nat_vty.c
+++ b/openbsc/src/nat/bsc_nat_vty.c
@@ -113,7 +113,7 @@ static void config_write_bsc_single(struct vty *vty, struct bsc_config *bsc)
vty_out(vty, " description %s%s", bsc->description, VTY_NEWLINE);
if (bsc->acc_lst_name)
vty_out(vty, " access-list-name %s%s", bsc->acc_lst_name, VTY_NEWLINE);
- vty_out(vty, " number-multiplexes %d%s", bsc->number_multiplexes, VTY_NEWLINE);
+ vty_out(vty, " max-endpoints %d%s", bsc->max_endpoints, VTY_NEWLINE);
}
static int config_write_bsc(struct vty *vty)
@@ -173,6 +173,7 @@ DEFUN(show_bsc_mgcp, show_bsc_mgcp_cmd, "show bsc mgcp NR",
int i, j, endp;
llist_for_each_entry(con, &_nat->bsc_connections, list_entry) {
+ int max;
if (!con->cfg)
continue;
if (con->cfg->nr != nr)
@@ -183,7 +184,8 @@ DEFUN(show_bsc_mgcp, show_bsc_mgcp_cmd, "show bsc mgcp NR",
continue;
vty_out(vty, "MGCP Status for %d%s", con->cfg->nr, VTY_NEWLINE);
- for (i = 0; i < con->number_multiplexes; ++i) {
+ max = bsc_mgcp_nr_multiplexes(con->max_endpoints);
+ for (i = 0; i < max; ++i) {
for (j = 0; j < 32; ++j) {
endp = mgcp_timeslot_to_endpoint(i, j);
vty_out(vty, " Endpoint 0x%x %s%s", endp,
@@ -634,13 +636,13 @@ DEFUN(cfg_bsc_acc_lst_name,
return CMD_SUCCESS;
}
-DEFUN(cfg_bsc_nr_multip, cfg_bsc_nr_multip_cmd,
- "number-multiplexes <1-64>",
- "Number of multiplexes on a BSC\n" "Number of ports\n")
+DEFUN(cfg_bsc_max_endps, cfg_bsc_max_endps_cmd,
+ "max-endpoints <1-1024>",
+ "Highest endpoint to use (exclusively)\n" "Number of ports\n")
{
struct bsc_config *conf = vty->index;
- conf->number_multiplexes = atoi(argv[0]);
+ conf->max_endpoints = atoi(argv[0]);
return CMD_SUCCESS;
}
@@ -744,7 +746,7 @@ int bsc_nat_vty_init(struct bsc_nat *nat)
install_element(NAT_BSC_NODE, &cfg_bsc_paging_cmd);
install_element(NAT_BSC_NODE, &cfg_bsc_desc_cmd);
install_element(NAT_BSC_NODE, &cfg_bsc_acc_lst_name_cmd);
- install_element(NAT_BSC_NODE, &cfg_bsc_nr_multip_cmd);
+ install_element(NAT_BSC_NODE, &cfg_bsc_max_endps_cmd);
mgcp_vty_init();
diff --git a/openbsc/tests/bsc-nat/bsc_nat_test.c b/openbsc/tests/bsc-nat/bsc_nat_test.c
index ad7ce61af..1d9052d6f 100644
--- a/openbsc/tests/bsc-nat/bsc_nat_test.c
+++ b/openbsc/tests/bsc-nat/bsc_nat_test.c
@@ -435,7 +435,7 @@ static void test_mgcp_allocations(void)
struct bsc_connection *bsc;
struct bsc_nat *nat;
struct sccp_connections con;
- int i, j;
+ int i, j, multiplex;
fprintf(stderr, "Testing MGCP.\n");
memset(&con, 0, sizeof(con));
@@ -449,7 +449,7 @@ static void test_mgcp_allocations(void)
bsc = bsc_connection_alloc(nat);
bsc->cfg = bsc_config_alloc(nat, "foo");
- bsc->cfg->number_multiplexes = 2;
+ bsc->cfg->max_endpoints = 60;
bsc_config_add_lac(bsc->cfg, 2323);
bsc->last_endpoint = 0x22;
con.bsc = bsc;
@@ -465,7 +465,8 @@ static void test_mgcp_allocations(void)
++i;
} while(1);
- for (i = 0; i < bsc->cfg->number_multiplexes; ++i) {
+ multiplex = bsc_mgcp_nr_multiplexes(bsc->cfg->max_endpoints);
+ for (i = 0; i < multiplex; ++i) {
for (j = 0; j < 32; ++j)
printf("%d", bsc->_endpoint_status[i*32 + j]);
printf(": %d of %d\n", i*32 + 32, 32 * 8);