[asterisk-commits] trunk r29411 - in /trunk: channels/
channels/misdn/ configs/
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Mon May 22 08:02:04 MST 2006
Author: crichter
Date: Mon May 22 10:02:03 2006
New Revision: 29411
URL: http://svn.digium.com/view/asterisk?rev=29411&view=rev
Log:
added callcounters for incoming and outgoing calls
Modified:
trunk/channels/chan_misdn.c
trunk/channels/misdn/chan_misdn_config.h
trunk/channels/misdn_config.c
trunk/configs/misdn.conf.sample
Modified: trunk/channels/chan_misdn.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_misdn.c?rev=29411&r1=29410&r2=29411&view=diff
==============================================================================
--- trunk/channels/chan_misdn.c (original)
+++ trunk/channels/chan_misdn.c Mon May 22 10:02:03 2006
@@ -280,6 +280,10 @@
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;
@@ -310,6 +314,11 @@
void debug_numplan(int port, int numplan, char *type);
+
+
+int add_out_calls(int port);
+int add_in_calls(int port);
+
/*************** Helpers *****************/
@@ -647,6 +656,39 @@
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_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 @@
"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 @@
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);
@@ -2742,6 +2818,13 @@
} else {
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 @@
}
+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 @@
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;}
@@ -3185,6 +3304,12 @@
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);
@@ -3679,6 +3804,21 @@
/** 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 @@
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 @@
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 @@
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 @@
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");
Modified: trunk/channels/misdn/chan_misdn_config.h
URL: http://svn.digium.com/view/asterisk/trunk/channels/misdn/chan_misdn_config.h?rev=29411&r1=29410&r2=29411&view=diff
==============================================================================
--- trunk/channels/misdn/chan_misdn_config.h (original)
+++ trunk/channels/misdn/chan_misdn_config.h Mon May 22 10:02:03 2006
@@ -55,6 +55,9 @@
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_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
Modified: trunk/channels/misdn_config.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/misdn_config.c?rev=29411&r1=29410&r2=29411&view=diff
==============================================================================
--- trunk/channels/misdn_config.c (original)
+++ trunk/channels/misdn_config.c Mon May 22 10:02:03 2006
@@ -116,6 +116,9 @@
{ "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 @@
misdn_cfg_unlock();
AST_DESTROY_CFG(cfg);
}
+
+
Modified: trunk/configs/misdn.conf.sample
URL: http://svn.digium.com/view/asterisk/trunk/configs/misdn.conf.sample?rev=29411&r1=29410&r2=29411&view=diff
==============================================================================
--- trunk/configs/misdn.conf.sample (original)
+++ trunk/configs/misdn.conf.sample Mon May 22 10:02:03 2006
@@ -299,6 +299,21 @@
; another channel type or to an application.
;
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)
More information about the asterisk-commits
mailing list