提交 29436b8c authored 作者: David Yat Sin's avatar David Yat Sin

Support for huntgroups


git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@944 a93c3328-9c30-0410-af19-c9cd2b2d52af
上级 b4331759
......@@ -1033,7 +1033,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
const char *dest = NULL;
char *data = NULL;
int span_id = -1, chan_id = 0;
int span_id = -1, group_id = -1,chan_id = 0;
zap_channel_t *zchan = NULL;
switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
char name[128];
......@@ -1097,11 +1097,18 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
}
if (span_id == -1) {
//Look for a group
zap_group_t *group;
zap_status_t zstatus = zap_group_find_by_name(span_name, &group);
if (zstatus == ZAP_SUCCESS && group) {
group_id = group->group_id;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing span\n");
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
}
}
if (chan_id < 0) {
if (group_id < 0 && chan_id < 0) {
direction = ZAP_BOTTOM_UP;
chan_id = 0;
}
......@@ -1144,10 +1151,12 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
zap_set_string(caller_data.cid_name, outbound_profile->caller_id_name);
zap_set_string(caller_data.cid_num.digits, outbound_profile->caller_id_number);
if (chan_id) {
if (group_id >= 0) {
status = zap_channel_open_by_group(group_id, direction, &caller_data, &zchan);
} else if (chan_id) {
status = zap_channel_open(span_id, chan_id, &zchan);
} else {
status = zap_channel_open_any(span_id, direction, &caller_data, &zchan);
status = zap_channel_open_by_span(span_id, direction, &caller_data, &zchan);
}
if (status != ZAP_SUCCESS) {
......@@ -1766,8 +1775,6 @@ static ZIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal)
sigmsg->channel->span_id, sigmsg->channel->chan_id, (uuid) ? uuid : "N/A");
}
}
break;
default:
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unhandled msg type %d for channel %d:%d\n",
......
......@@ -195,6 +195,9 @@ extern "C" {
#define ZAP_MAX_CHANNELS_SPAN ZAP_MAX_CHANNELS_PHYSICAL_SPAN * ZAP_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN
#define ZAP_MAX_SPANS_INTERFACE 128
#define ZAP_MAX_CHANNELS_GROUP 1024
#define ZAP_MAX_GROUPS_INTERFACE ZAP_MAX_SPANS_INTERFACE
#define GOTO_STATUS(label,st) status = st; goto label ;
#define zap_copy_string(x,y,z) strncpy(x, y, z - 1)
......@@ -578,6 +581,16 @@ struct zap_span {
struct zap_span *next;
};
struct zap_group {
char *name;
uint32_t group_id;
uint32_t chan_count;
zap_channel_t *channels[ZAP_MAX_CHANNELS_GROUP];
uint32_t last_used_index;
zap_mutex_t *mutex;
struct zap_group *next;
};
OZ_DECLARE_DATA extern zap_logger_t zap_log;
typedef enum {
......@@ -706,11 +719,19 @@ OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **s
OZ_DECLARE(zap_status_t) zap_span_close_all(void);
OZ_DECLARE(zap_status_t) zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_chan_type_t type, zap_channel_t **chan);
OZ_DECLARE(zap_status_t) zap_span_set_event_callback(zap_span_t *span, zio_event_cb_t event_callback);
OZ_DECLARE(zap_status_t) zap_channel_add_to_group(const char* name, zap_channel_t* zchan);
OZ_DECLARE(zap_status_t) zap_group_add_channels(const char* name, zap_span_t* span, const char* val);
OZ_DECLARE(zap_status_t) zap_channel_remove_from_group(zap_group_t* group, zap_channel_t* zchan);
OZ_DECLARE(zap_status_t) zap_group_find(uint32_t id, zap_group_t **group);
OZ_DECLARE(zap_status_t) zap_group_find_by_name(const char *name, zap_group_t **group);
OZ_DECLARE(zap_status_t) zap_group_create(zap_group_t **group, const char *name);
OZ_DECLARE(zap_status_t) zap_channel_set_event_callback(zap_channel_t *zchan, zio_event_cb_t event_callback);
OZ_DECLARE(zap_status_t) zap_channel_open(uint32_t span_id, uint32_t chan_id, zap_channel_t **zchan);
OZ_DECLARE(zap_status_t) zap_channel_open_chan(zap_channel_t *zchan);
OZ_DECLARE(zap_status_t) zap_span_channel_use_count(zap_span_t *span, uint32_t *count);
OZ_DECLARE(zap_status_t) zap_channel_open_any(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan);
OZ_DECLARE(zap_status_t) zap_group_channel_use_count(zap_group_t *group, uint32_t *count);
OZ_DECLARE(zap_status_t) zap_channel_open_by_span(uint32_t span_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan);
OZ_DECLARE(zap_status_t) zap_channel_open_by_group(uint32_t group_id, zap_direction_t direction, zap_caller_data_t *caller_data, zap_channel_t **zchan);
OZ_DECLARE(zap_status_t) zap_channel_close(zap_channel_t **zchan);
OZ_DECLARE(zap_status_t) zap_channel_done(zap_channel_t *zchan);
OZ_DECLARE(zap_status_t) zap_channel_use(zap_channel_t *zchan);
......
......@@ -458,6 +458,7 @@ typedef struct zap_channel zap_channel_t;
typedef struct zap_event zap_event_t;
typedef struct zap_sigmsg zap_sigmsg_t;
typedef struct zap_span zap_span_t;
typedef struct zap_group zap_group_t;
typedef struct zap_caller_data zap_caller_data_t;
typedef struct zap_io_interface zap_io_interface_t;
......
......@@ -55,8 +55,11 @@ zap_mutex_t *g_boost_modules_mutex = NULL;
zap_hash_t *g_boost_modules_hash = NULL;
#define MAX_TRUNK_GROUPS 64
//DAVIDY need to merge congestion_timeouts with zap_sangoma_boost_trunkgroups
static time_t congestion_timeouts[MAX_TRUNK_GROUPS];
static zap_sangoma_boost_trunkgroup_t *g_trunkgroups[MAX_TRUNK_GROUPS];
#define BOOST_QUEUE_SIZE 500
/* get openzap span and chan depending on the span mode */
......@@ -303,6 +306,25 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request)
zap_set_string(ani, caller_data->ani.digits);
r = next_request_id();
if (r == 0) {
zap_log(ZAP_LOG_CRIT, "All tanks ids are busy.\n");
*zchan = NULL;
return ZAP_FAIL;
}
sangomabc_call_init(&event, caller_data->cid_num.digits, ani, r);
if (sangoma_boost_data->sigmod) {
*zchan = span->channels[chan_id];
event.span = (uint8_t) (*zchan)->physical_span_id;
event.chan = (uint8_t) (*zchan)->physical_chan_id;
zap_set_flag((*zchan), ZAP_CHANNEL_OUTBOUND);
zap_set_flag_locked((*zchan), ZAP_CHANNEL_INUSE);
OUTBOUND_REQUESTS[r].zchan = *zchan;
} else {
if ((gr = strchr(ani, '@'))) {
*gr++ = '\0';
}
......@@ -329,19 +351,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request)
return ZAP_FAIL;
}
r = next_request_id();
if (r == 0) {
zap_log(ZAP_LOG_CRIT, "All tanks ids are busy.\n");
*zchan = NULL;
return ZAP_FAIL;
}
sangomabc_call_init(&event, caller_data->cid_num.digits, ani, r);
//sangoma_bc_call_init will clear the trunk_group val so we need to set it again
event.trunk_group=tg;
if (gr && *(gr+1)) {
switch(*gr) {
case 'g':
event.hunt_group = SIGBOOST_HUNTGRP_SEQ_ASC;
......@@ -360,6 +370,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request)
event.hunt_group = SIGBOOST_HUNTGRP_SEQ_ASC;
}
}
}
zap_set_string(event.calling_name, caller_data->cid_name);
zap_set_string(event.isup_in_rdnis, caller_data->rdnis.digits);
......@@ -369,10 +380,6 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request)
event.calling_number_screening_ind = caller_data->screen;
event.calling_number_presentation = caller_data->pres;
if (sangoma_boost_data->sigmod) {
/* boost sigmods only know about physical spans, give them that and let them hunt there */
event.span = (uint8_t)span->channels[1]->physical_span_id;
}
OUTBOUND_REQUESTS[r].status = BST_WAITING;
OUTBOUND_REQUESTS[r].span = span;
......@@ -380,7 +387,9 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request)
if (sangomabc_connection_write(&sangoma_boost_data->mcon, &event) <= 0) {
zap_log(ZAP_LOG_CRIT, "Failed to tx boost event [%s]\n", strerror(errno));
status = ZAP_FAIL;
if (!sangoma_boost_data->sigmod) {
*zchan = NULL;
}
goto done;
}
......@@ -388,8 +397,11 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request)
zap_sleep(1);
if (--boost_request_timeout <= 0) {
status = ZAP_FAIL;
if (!sangoma_boost_data->sigmod) {
*zchan = NULL;
}
zap_log(ZAP_LOG_CRIT, "Timed out waiting for boost channel request response, current status: BST_WAITING\n");
zap_log(ZAP_LOG_CRIT, "DYDBG s%dc%d: Csid:%d Timed out waiting for boost channel request response, current status: BST_WAITING\n", (*zchan)->physical_span_id, (*zchan)->physical_chan_id, r);
goto done;
}
}
......@@ -406,7 +418,9 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request)
zap_sleep(1);
if (--boost_request_timeout <= 0) {
status = ZAP_FAIL;
if (!sangoma_boost_data->sigmod) {
*zchan = NULL;
}
zap_log(ZAP_LOG_CRIT, "Timed out waiting for boost channel request response, current status: BST_ACK\n");
goto done;
}
......@@ -420,8 +434,10 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request)
zap_log(ZAP_LOG_DEBUG, "Channel state changed to PROGRESS_MEDIA [Csid:%d]\n", r);
} else {
status = ZAP_FAIL;
if (!sangoma_boost_data->sigmod) {
*zchan = NULL;
}
}
done:
......@@ -433,6 +449,14 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request)
} else if (st != BST_READY) {
assert(r <= MAX_REQ_ID);
nack_map[r] = 1;
if (sangoma_boost_data->sigmod) {
sangomabc_exec_command(&sangoma_boost_data->mcon,
(*zchan)->physical_span_id,
(*zchan)->physical_chan_id,
r,
SIGBOOST_EVENT_CALL_START_NACK,
0);
} else {
sangomabc_exec_command(&sangoma_boost_data->mcon,
0,
0,
......@@ -440,6 +464,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request)
SIGBOOST_EVENT_CALL_START_NACK,
0);
}
}
return status;
}
......@@ -526,9 +551,11 @@ static void handle_call_progress(sangomabc_connection_t *mcon, sangomabc_short_e
*/
static void handle_call_start_ack(sangomabc_connection_t *mcon, sangomabc_short_event_t *event)
{
zap_channel_t *zchan;
uint32_t event_span = event->span+1;
uint32_t event_chan = event->chan+1;
if (nack_map[event->call_setup_id]) {
return;
}
......@@ -541,12 +568,19 @@ static void handle_call_start_ack(sangomabc_connection_t *mcon, sangomabc_short_
OUTBOUND_REQUESTS[event->call_setup_id].event = *event;
SETUP_GRID[event->span][event->chan] = event->call_setup_id;
if ((zchan = find_zchan(OUTBOUND_REQUESTS[event->call_setup_id].span, event, 0))) {
if (mcon->sigmod) {
zchan = OUTBOUND_REQUESTS[event->call_setup_id].zchan;
zap_set_flag(zchan, ZAP_CHANNEL_OUTBOUND);
zap_set_flag_locked(zchan, ZAP_CHANNEL_INUSE);
} else {
zchan = find_zchan(OUTBOUND_REQUESTS[event->call_setup_id].span, event, 0);
}
if (zchan) {
if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) {
zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error);
} else {
zap_set_flag(zchan, ZAP_CHANNEL_OUTBOUND);
zap_set_flag_locked(zchan, ZAP_CHANNEL_INUSE);
zchan->extra_id = event->call_setup_id;
zap_log(ZAP_LOG_DEBUG, "Assign chan %d:%d (%d:%d) CSid=%d\n", zchan->span_id, zchan->chan_id, event_span, event_chan, event->call_setup_id);
zchan->sflags = 0;
......@@ -620,6 +654,7 @@ static void handle_call_done(zap_span_t *span, sangomabc_connection_t *mcon, san
static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event)
{
zap_channel_t *zchan;
zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data;
if (event->release_cause == SIGBOOST_CALL_SETUP_NACK_ALL_CKTS_BUSY) {
uint32_t count = 0;
......@@ -648,8 +683,10 @@ static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mco
event->release_cause = 17;
}
if (event->call_setup_id) {
zap_log(ZAP_LOG_CRIT, "DYDBG setting event->call_setup_id:%d to BST_FAIL\n", event->call_setup_id);
OUTBOUND_REQUESTS[event->call_setup_id].event = *event;
OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL;
if (!sangoma_boost_data->sigmod) {
sangomabc_exec_command(mcon,
0,
0,
......@@ -657,8 +694,6 @@ static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mco
SIGBOOST_EVENT_CALL_START_NACK_ACK,
0);
OUTBOUND_REQUESTS[event->call_setup_id].event = *event;
OUTBOUND_REQUESTS[event->call_setup_id].status = BST_FAIL;
return;
} else {
if ((zchan = find_zchan(span, event, 1))) {
......@@ -677,6 +712,7 @@ static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mco
}
}
#if 0
if (zchan) {
zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG);
}
......@@ -688,6 +724,7 @@ static void handle_call_start_nack(zap_span_t *span, sangomabc_connection_t *mco
0,
SIGBOOST_EVENT_CALL_START_NACK_ACK,
0);
#endif
}
/**
......@@ -1528,6 +1565,7 @@ end:
*/
static ZIO_SIG_LOAD_FUNCTION(zap_sangoma_boost_init)
{
int i;
g_boost_modules_hash = create_hashtable(10, zap_hash_hashfromstring, zap_hash_equalkeys);
if (!g_boost_modules_hash) {
return ZAP_FAIL;
......@@ -1535,6 +1573,10 @@ static ZIO_SIG_LOAD_FUNCTION(zap_sangoma_boost_init)
zap_mutex_create(&request_mutex);
zap_mutex_create(&signal_mutex);
zap_mutex_create(&g_boost_modules_mutex);
for(i=0;i< MAX_TRUNK_GROUPS;i++) {
g_trunkgroups[i]=NULL;
}
return ZAP_SUCCESS;
}
......@@ -1806,7 +1848,6 @@ static ZIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(zap_sangoma_boost_configure_span)
}
}
if (!sigmod) {
if (!local_ip && local_port && remote_ip && remote_port && sig_cb) {
zap_set_string(span->last_error, "missing Sangoma boost IP parameters");
......
......@@ -36,6 +36,8 @@
#include "sangoma_boost_client.h"
#include "openzap.h"
#define MAX_CHANS_PER_TRUNKGROUP 1024
typedef enum {
ZAP_SANGOMA_BOOST_RUNNING = (1 << 0),
ZAP_SANGOMA_BOOST_RESTARTING = (1 << 1)
......@@ -53,6 +55,13 @@ typedef struct zap_sangoma_boost_data {
zap_queue_t *boost_queue;
} zap_sangoma_boost_data_t;
typedef struct zap_sangoma_boost_trunkgroup {
zap_mutex_t *mutex;
zap_size_t size; /* Number of b-channels in group */
unsigned int last_used_index; /* index of last b-channel used */
zap_channel_t* zchans[MAX_CHANS_PER_TRUNKGROUP];
//DAVIDY need to merge congestion timeouts to this struct
} zap_sangoma_boost_trunkgroup_t;
#endif
/* For Emacs:
......
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论