nat: Change number of multiplexes to the max-endpoints
This commit is contained in:
parent
a9e9331285
commit
9ec030d32d
|
@ -80,6 +80,7 @@ struct bsc_connection {
|
||||||
/* mgcp related code */
|
/* mgcp related code */
|
||||||
char *_endpoint_status;
|
char *_endpoint_status;
|
||||||
int number_multiplexes;
|
int number_multiplexes;
|
||||||
|
int max_endpoints;
|
||||||
int last_endpoint;
|
int last_endpoint;
|
||||||
|
|
||||||
/* a back pointer */
|
/* a back pointer */
|
||||||
|
@ -126,7 +127,7 @@ struct bsc_config {
|
||||||
int forbid_paging;
|
int forbid_paging;
|
||||||
|
|
||||||
/* audio handling */
|
/* audio handling */
|
||||||
int number_multiplexes;
|
int max_endpoints;
|
||||||
|
|
||||||
/* backpointer */
|
/* backpointer */
|
||||||
struct bsc_nat *nat;
|
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
|
* 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_write_mgcp(struct bsc_connection *bsc, const uint8_t *data, unsigned int length);
|
||||||
int bsc_mgcp_assign_patch(struct sccp_connections *, struct msgb *msg);
|
int bsc_mgcp_assign_patch(struct sccp_connections *, struct msgb *msg);
|
||||||
void bsc_mgcp_init(struct sccp_connections *);
|
void bsc_mgcp_init(struct sccp_connections *);
|
||||||
|
|
|
@ -38,8 +38,20 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.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)
|
static int bsc_init_endps_if_needed(struct bsc_connection *con)
|
||||||
{
|
{
|
||||||
|
int multiplexes;
|
||||||
|
|
||||||
/* we have done that */
|
/* we have done that */
|
||||||
if (con->_endpoint_status)
|
if (con->_endpoint_status)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -48,9 +60,10 @@ static int bsc_init_endps_if_needed(struct bsc_connection *con)
|
||||||
if (!con->cfg)
|
if (!con->cfg)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
con->number_multiplexes = con->cfg->number_multiplexes;
|
multiplexes = bsc_mgcp_nr_multiplexes(con->cfg->max_endpoints);
|
||||||
con->_endpoint_status = talloc_zero_array(con, char,
|
con->number_multiplexes = multiplexes;
|
||||||
(32 * con->cfg->number_multiplexes) + 1);
|
con->max_endpoints = con->cfg->max_endpoints;
|
||||||
|
con->_endpoint_status = talloc_zero_array(con, char, 32 * multiplexes + 1);
|
||||||
return con->_endpoint_status == NULL;
|
return con->_endpoint_status == NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +71,7 @@ static int bsc_assign_endpoint(struct bsc_connection *bsc, struct sccp_connectio
|
||||||
{
|
{
|
||||||
int multiplex;
|
int multiplex;
|
||||||
int timeslot;
|
int timeslot;
|
||||||
const int number_endpoints = 32 * bsc->number_multiplexes;
|
const int number_endpoints = bsc->max_endpoints;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
mgcp_endpoint_to_timeslot(bsc->last_endpoint, &multiplex, ×lot);
|
mgcp_endpoint_to_timeslot(bsc->last_endpoint, &multiplex, ×lot);
|
||||||
|
@ -82,6 +95,14 @@ static int bsc_assign_endpoint(struct bsc_connection *bsc, struct sccp_connectio
|
||||||
|
|
||||||
endpoint = mgcp_timeslot_to_endpoint(multiplex, timeslot);
|
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) {
|
if (bsc->_endpoint_status[endpoint] == 0) {
|
||||||
bsc->_endpoint_status[endpoint] = 1;
|
bsc->_endpoint_status[endpoint] = 1;
|
||||||
con->bsc_endp = endpoint;
|
con->bsc_endp = endpoint;
|
||||||
|
|
|
@ -126,7 +126,7 @@ struct bsc_config *bsc_config_alloc(struct bsc_nat *nat, const char *token)
|
||||||
conf->token = talloc_strdup(conf, token);
|
conf->token = talloc_strdup(conf, token);
|
||||||
conf->nr = nat->num_bsc;
|
conf->nr = nat->num_bsc;
|
||||||
conf->nat = nat;
|
conf->nat = nat;
|
||||||
conf->number_multiplexes = 1;
|
conf->max_endpoints = 32;
|
||||||
|
|
||||||
INIT_LLIST_HEAD(&conf->lac_list);
|
INIT_LLIST_HEAD(&conf->lac_list);
|
||||||
|
|
||||||
|
|
|
@ -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);
|
vty_out(vty, " description %s%s", bsc->description, VTY_NEWLINE);
|
||||||
if (bsc->acc_lst_name)
|
if (bsc->acc_lst_name)
|
||||||
vty_out(vty, " access-list-name %s%s", bsc->acc_lst_name, VTY_NEWLINE);
|
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)
|
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;
|
int i, j, endp;
|
||||||
|
|
||||||
llist_for_each_entry(con, &_nat->bsc_connections, list_entry) {
|
llist_for_each_entry(con, &_nat->bsc_connections, list_entry) {
|
||||||
|
int max;
|
||||||
if (!con->cfg)
|
if (!con->cfg)
|
||||||
continue;
|
continue;
|
||||||
if (con->cfg->nr != nr)
|
if (con->cfg->nr != nr)
|
||||||
|
@ -183,7 +184,8 @@ DEFUN(show_bsc_mgcp, show_bsc_mgcp_cmd, "show bsc mgcp NR",
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
vty_out(vty, "MGCP Status for %d%s", con->cfg->nr, VTY_NEWLINE);
|
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) {
|
for (j = 0; j < 32; ++j) {
|
||||||
endp = mgcp_timeslot_to_endpoint(i, j);
|
endp = mgcp_timeslot_to_endpoint(i, j);
|
||||||
vty_out(vty, " Endpoint 0x%x %s%s", endp,
|
vty_out(vty, " Endpoint 0x%x %s%s", endp,
|
||||||
|
@ -634,13 +636,13 @@ DEFUN(cfg_bsc_acc_lst_name,
|
||||||
return CMD_SUCCESS;
|
return CMD_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFUN(cfg_bsc_nr_multip, cfg_bsc_nr_multip_cmd,
|
DEFUN(cfg_bsc_max_endps, cfg_bsc_max_endps_cmd,
|
||||||
"number-multiplexes <1-64>",
|
"max-endpoints <1-1024>",
|
||||||
"Number of multiplexes on a BSC\n" "Number of ports\n")
|
"Highest endpoint to use (exclusively)\n" "Number of ports\n")
|
||||||
{
|
{
|
||||||
struct bsc_config *conf = vty->index;
|
struct bsc_config *conf = vty->index;
|
||||||
|
|
||||||
conf->number_multiplexes = atoi(argv[0]);
|
conf->max_endpoints = atoi(argv[0]);
|
||||||
return CMD_SUCCESS;
|
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_paging_cmd);
|
||||||
install_element(NAT_BSC_NODE, &cfg_bsc_desc_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_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();
|
mgcp_vty_init();
|
||||||
|
|
||||||
|
|
|
@ -435,7 +435,7 @@ static void test_mgcp_allocations(void)
|
||||||
struct bsc_connection *bsc;
|
struct bsc_connection *bsc;
|
||||||
struct bsc_nat *nat;
|
struct bsc_nat *nat;
|
||||||
struct sccp_connections con;
|
struct sccp_connections con;
|
||||||
int i, j;
|
int i, j, multiplex;
|
||||||
|
|
||||||
fprintf(stderr, "Testing MGCP.\n");
|
fprintf(stderr, "Testing MGCP.\n");
|
||||||
memset(&con, 0, sizeof(con));
|
memset(&con, 0, sizeof(con));
|
||||||
|
@ -449,7 +449,7 @@ static void test_mgcp_allocations(void)
|
||||||
|
|
||||||
bsc = bsc_connection_alloc(nat);
|
bsc = bsc_connection_alloc(nat);
|
||||||
bsc->cfg = bsc_config_alloc(nat, "foo");
|
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_config_add_lac(bsc->cfg, 2323);
|
||||||
bsc->last_endpoint = 0x22;
|
bsc->last_endpoint = 0x22;
|
||||||
con.bsc = bsc;
|
con.bsc = bsc;
|
||||||
|
@ -465,7 +465,8 @@ static void test_mgcp_allocations(void)
|
||||||
++i;
|
++i;
|
||||||
} while(1);
|
} 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)
|
for (j = 0; j < 32; ++j)
|
||||||
printf("%d", bsc->_endpoint_status[i*32 + j]);
|
printf("%d", bsc->_endpoint_status[i*32 + j]);
|
||||||
printf(": %d of %d\n", i*32 + 32, 32 * 8);
|
printf(": %d of %d\n", i*32 + 32, 32 * 8);
|
||||||
|
|
Loading…
Reference in New Issue