diff options
author | Christian Richter <christian.richter@beronet.com> | 2006-05-22 15:02:03 +0000 |
---|---|---|
committer | Christian Richter <christian.richter@beronet.com> | 2006-05-22 15:02:03 +0000 |
commit | 19d46333bfa44eb6d8fffeb7b4a6ec6372a3de14 (patch) | |
tree | d3a9c8a177ba54b66647f79a35e3b5fecf9a04a8 | |
parent | 5a8e7415c7a22f172e8a49d500051873551bf081 (diff) |
added callcounters for incoming and outgoing calls
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@29411 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r-- | channels/chan_misdn.c | 153 | ||||
-rw-r--r-- | channels/misdn/chan_misdn_config.h | 8 | ||||
-rw-r--r-- | channels/misdn_config.c | 5 | ||||
-rw-r--r-- | configs/misdn.conf.sample | 15 |
4 files changed, 181 insertions, 0 deletions
diff --git a/channels/chan_misdn.c b/channels/chan_misdn.c index cfcdc58e3..830d41690 100644 --- a/channels/chan_misdn.c +++ b/channels/chan_misdn.c @@ -280,6 +280,10 @@ static int *misdn_debug; static int *misdn_debug_only; static int max_ports; +static int *misdn_in_calls; +static int *misdn_out_calls; + + struct chan_list dummy_cl; struct chan_list *cl_te=NULL; @@ -311,6 +315,11 @@ int chan_misdn_jb_empty(struct misdn_bchannel *bc, char *buf, int len); void debug_numplan(int port, int numplan, char *type); + +int add_out_calls(int port); +int add_in_calls(int port); + + /*************** Helpers *****************/ static struct chan_list * get_chan_by_ast(struct ast_channel *ast) @@ -647,6 +656,39 @@ static void reload_config(void) misdn_debug[i] = cfg_debug; misdn_debug_only[i] = 0; } + +#ifdef M_TIMER + if (misdn_sched) + sched_context_destroy(misdn_sched); + + misdn_sched=sched_context_create(); + + if (!misdn_sched) { + ast_log(LOG_ERROR,"Couldn't create scheduler\n"); + return -1; + } + + /* Loop through all ports and find out which one should be + * watched regarding the l1 */ + int port; + int dotimer=0; + for ( port=misdn_cfg_get_next_port(0); + port>0; + port=misdn_cfg_get_next_port(port)) { + int l1timer; + misdn_cfg_get( port, MISDN_CFG_L1_TIMER, &l1timer, sizeof(l1timer)); + if (l1timer>0) { + ast_sched_add(misdn_sched, l1timer*1000, l1_timer_cb, &port); + dotimer=1; +; } + } + + if (dotimer) { + /*start timer thread*/ + pthread_create( &misdn_timer, NULL, (void*)misdn_timerd, NULL); + } +#endif + } static int misdn_reload (int fd, int argc, char *argv[]) @@ -780,6 +822,24 @@ static int misdn_show_stacks (int fd, int argc, char *argv[]) } + +static int misdn_show_ports_stats (int fd, int argc, char *argv[]) +{ + int port; + + ast_cli(fd, "Port\tin_calls\tout_calls\n"); + + for (port=misdn_cfg_get_next_port(0); port > 0; + port=misdn_cfg_get_next_port(port)) { + ast_cli(fd,"%d\t%d\t\t%d\n",port,misdn_in_calls[port],misdn_out_calls[port]); + } + ast_cli(fd,"\n"); + + return 0; + +} + + static int misdn_show_port (int fd, int argc, char *argv[]) { int port; @@ -1077,6 +1137,14 @@ static struct ast_cli_entry cli_show_stacks = "Usage: misdn show stacks\n" }; +static struct ast_cli_entry cli_show_ports_stats = +{ {"misdn","show","ports","stats", NULL}, + misdn_show_ports_stats, + "Shows chan_misdns call statistics per port", + "Usage: misdn show port stats\n" +}; + + static struct ast_cli_entry cli_show_port = { {"misdn","show","port", NULL}, misdn_show_port, @@ -1523,6 +1591,14 @@ static int misdn_call(struct ast_channel *ast, char *dest, int timeout) port=newbc->port; strncpy(newbc->dad,ext,sizeof( newbc->dad)); strncpy(ast->exten,ext,sizeof(ast->exten)); + + int exceed; + if ((exceed=add_out_calls(port))) { + char tmp[16]; + sprintf(tmp,"%d",exceed); + pbx_builtin_setvar_helper(ast,"MAX_OVERFLOW",tmp); + return -1; + } chan_misdn_log(1, port, "* CALL: %s\n",dest); @@ -2743,6 +2819,13 @@ static void release_chan(struct misdn_bchannel *bc) { if (!bc->nojitter) chan_misdn_log(5,bc->port,"Jitterbuffer already destroyed.\n"); } + + + if (ch->orginator == ORG_AST) { + misdn_out_calls[bc->port]--; + } else { + misdn_in_calls[bc->port]--; + } if (ch) { @@ -2972,6 +3055,40 @@ void export_ies(struct ast_channel *chan, struct misdn_bchannel *bc) } +int add_in_calls(int port) +{ + int max_in_calls; + + misdn_cfg_get( port, MISDN_CFG_MAX_IN, &max_in_calls, sizeof(max_in_calls)); + + misdn_in_calls[port]++; + + if (max_in_calls >=0 && max_in_calls<misdn_in_calls[port]) { + ast_log(LOG_NOTICE,"Marking Incoming Call on port[%d]\n",port); + return misdn_in_calls[port]-max_in_calls; + } + + return 0; +} + +int add_out_calls(int port) +{ + int max_out_calls; + + misdn_cfg_get( port, MISDN_CFG_MAX_OUT, &max_out_calls, sizeof(max_out_calls)); + + + if (max_out_calls >=0 && max_out_calls<=misdn_out_calls[port]) { + ast_log(LOG_NOTICE,"Rejecting Outgoing Call on port[%d]\n",port); + return (misdn_out_calls[port]+1)-max_out_calls; + } + + misdn_out_calls[port]++; + + return 0; +} + + /************************************************************/ /* Receive Events from isdn_lib here */ @@ -3169,12 +3286,14 @@ cb_events(enum event_e event, struct misdn_bchannel *bc, void *user_data) chan_misdn_log(1, bc->port, " --> Ignoring Call, its not in our MSN List\n"); return RESPONSE_IGNORE_SETUP; /* Ignore MSNs which are not in our List */ } + print_bearer(bc); { struct chan_list *ch=init_chan_list(ORG_MISDN); struct ast_channel *chan; + int exceed; if (!ch) { chan_misdn_log(-1, bc->port, "cb_events: malloc for chan_list failed!\n"); return 0;} @@ -3186,6 +3305,12 @@ cb_events(enum event_e event, struct misdn_bchannel *bc, void *user_data) chan=misdn_new(ch, AST_STATE_RESERVED,bc->dad, bc->oad, AST_FORMAT_ALAW, bc->port, bc->channel); ch->ast = chan; + if ((exceed=add_in_calls(bc->port))) { + char tmp[16]; + sprintf(tmp,"%d",exceed); + pbx_builtin_setvar_helper(chan,"MAX_OVERFLOW",tmp); + } + read_config(ch, ORG_MISDN); export_ies(chan, bc); @@ -3679,6 +3804,21 @@ cb_events(enum event_e event, struct misdn_bchannel *bc, void *user_data) /** TE STUFF END **/ +#ifdef M_TIMER +/* timer thread */ +pthread_t misdn_timer; +struct sched_context *misdn_sched; + +void misdn_timerd(void *arg) +{ + + +} + + +/* timer thread end */ +#endif + /****************************************** * * Asterisk Channel Endpoint END @@ -3708,6 +3848,7 @@ static int unload_module(void *mod) ast_cli_unregister(&cli_show_cl); ast_cli_unregister(&cli_show_config); ast_cli_unregister(&cli_show_port); + ast_cli_unregister(&cli_show_ports_stats); ast_cli_unregister(&cli_show_stacks); ast_cli_unregister(&cli_restart_port); ast_cli_unregister(&cli_port_up); @@ -3764,7 +3905,15 @@ static int load_module(void *mod) if (strlen(tempbuf)) tracing = 1; } + + misdn_in_calls = (int *)malloc(sizeof(int) * (max_ports+1)); + misdn_out_calls = (int *)malloc(sizeof(int) * (max_ports+1)); + for (i=1; i <= max_ports; i++) { + misdn_in_calls[i]=0; + misdn_out_calls[i]=0; + } + ast_mutex_init(&cl_te_lock); ast_mutex_init(&release_lock_mutex); @@ -3805,6 +3954,7 @@ static int load_module(void *mod) ast_cli_register(&cli_show_config); ast_cli_register(&cli_show_port); ast_cli_register(&cli_show_stacks); + ast_cli_register(&cli_show_ports_stats); ast_cli_register(&cli_restart_port); ast_cli_register(&cli_port_up); @@ -3833,6 +3983,9 @@ static int load_module(void *mod) misdn_cfg_get( 0, MISDN_GEN_TRACEFILE, global_tracefile, BUFFERSIZE); + + + chan_misdn_log(0, 0, "-- mISDN Channel Driver Registred -- (BE AWARE THIS DRIVER IS EXPERIMENTAL!)\n"); diff --git a/channels/misdn/chan_misdn_config.h b/channels/misdn/chan_misdn_config.h index a2ff16b3a..722c4bb78 100644 --- a/channels/misdn/chan_misdn_config.h +++ b/channels/misdn/chan_misdn_config.h @@ -55,6 +55,9 @@ enum misdn_cfg_elements { MISDN_CFG_JITTERBUFFER_UPPER_THRESHOLD, /* int */ MISDN_CFG_CALLGROUP, /* ast_group_t */ MISDN_CFG_PICKUPGROUP, /* ast_group_t */ + MISDN_CFG_MAX_IN, /* int */ + MISDN_CFG_MAX_OUT, /* int */ + MISDN_CFG_L1_POLL, /* int */ MISDN_CFG_MSNS, /* char[] */ MISDN_CFG_PTP, /* int (bool) */ MISDN_CFG_LAST, @@ -104,4 +107,9 @@ int misdn_cfg_is_msn_valid(int port, char* msn); int misdn_cfg_is_port_valid(int port); int misdn_cfg_is_group_method(char *group, enum misdn_cfg_method meth); +#if 0 +char *misdn_cfg_get_next_group(char *group); +int misdn_cfg_get_next_port_in_group(int port, char *group); +#endif + #endif diff --git a/channels/misdn_config.c b/channels/misdn_config.c index a94f34781..8d507a517 100644 --- a/channels/misdn_config.c +++ b/channels/misdn_config.c @@ -116,6 +116,9 @@ static const struct misdn_cfg_spec port_spec[] = { { "jitterbuffer_upper_threshold", MISDN_CFG_JITTERBUFFER_UPPER_THRESHOLD, MISDN_CTYPE_INT, "0", NONE }, { "callgroup", MISDN_CFG_CALLGROUP, MISDN_CTYPE_ASTGROUP, NO_DEFAULT, NONE }, { "pickupgroup", MISDN_CFG_PICKUPGROUP, MISDN_CTYPE_ASTGROUP, NO_DEFAULT, NONE }, + { "max_incoming", MISDN_CFG_MAX_IN, MISDN_CTYPE_INT, "-1", NONE }, + { "max_outgoing", MISDN_CFG_MAX_OUT, MISDN_CTYPE_INT, "-1", NONE }, + { "l1_poll_timer", MISDN_CFG_L1_POLL, MISDN_CTYPE_INT, "-1", NONE }, { "msns", MISDN_CFG_MSNS, MISDN_CTYPE_MSNLIST, NO_DEFAULT, NONE } }; @@ -772,3 +775,5 @@ void misdn_cfg_init (int this_max_ports) misdn_cfg_unlock(); AST_DESTROY_CFG(cfg); } + + diff --git a/configs/misdn.conf.sample b/configs/misdn.conf.sample index 1fb071930..5bdaecb54 100644 --- a/configs/misdn.conf.sample +++ b/configs/misdn.conf.sample @@ -300,6 +300,21 @@ jitterbuffer_upper_threshold=0 ; hdlc=no + +; +; defines the maximum amount of incoming calls per port for +; this group. Calls which exceed the maximum will be marked with +; the channel varible MAX_OVERFLOW. It will contain the amount of +; overflowed calls +; +max_incoming=-1 + +; +; defines the maximum amount of outgoing calls per port for this group +; exceeding calls will be rejected +; +max_outgoing=-1 + [intern] ; define your ports, e.g. 1,2 (depends on mISDN-driver loading order) ports=1,2 |