diff --git a/README.md b/README.md index 55d3d7866..47c33e202 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,7 @@ option and which are reproduced below: -T, --tos=INT TOS value to set on streams -o, --timeout=SECS RTP timeout -s, --silent-timeout=SECS RTP timeout for muted + -a, --final-timeout=SECS Call timeout -p, --pidfile=FILE Write PID to file -f, --foreground Don't fork to background -m, --port-min=INT Lowest port to use for RTP @@ -292,6 +293,11 @@ The options are described in more detail below. Ditto as the `--timeout` option, but applies to muted or inactive media streams. Defaults to 3600 (one hour). +* -a, --final-timeout + + The number of seconds after the call is deleted. Useful for limiting the lifetime of a call. + By default this timeout is disabled. + * -p, --pidfile Specifies a path and file name to write the daemon's PID number to. diff --git a/daemon/call.c b/daemon/call.c index 252b2c633..c4e7c4f58 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -108,6 +108,7 @@ static const char * const __term_reason_texts[] = { [REGULAR] = "REGULAR", [FORCED] = "FORCED", [SILENT_TIMEOUT] = "SILENT_TIMEOUT", + [FINAL_TIMEOUT] = "FINAL_TIMEOUT", }; static const char * const __tag_type_texts[] = { [FROM_TAG] = "FROM_TAG", @@ -183,7 +184,7 @@ static void call_timer_iterator(void *key, void *val, void *ptr) { int good = 0; struct packet_stream *ps; struct stream_fd *sfd; - int tmp_t_reason=0; + int tmp_t_reason = UNKNOWN; struct call_monologue *ml; enum call_stream_state css; atomic64 *timestamp; @@ -193,6 +194,18 @@ static void call_timer_iterator(void *key, void *val, void *ptr) { cm = c->callmaster; + if (cm->conf.final_timeout && poller_now >= (c->created + cm->conf.final_timeout)) { + ilog(LOG_INFO, "Closing call due to final timeout"); + tmp_t_reason = FINAL_TIMEOUT; + for (it = c->monologues.head; it; it = it->next) { + ml = it->data; + gettimeofday(&(ml->terminated),NULL); + ml->term_reason = tmp_t_reason; + } + + goto delete; + } + if (c->deleted && poller_now >= c->deleted && c->last_signal <= c->deleted) goto delete; @@ -232,10 +245,10 @@ no_sfd: goto next; check = cm->conf.timeout; - tmp_t_reason = 1; + tmp_t_reason = TIMEOUT; if (!MEDIA_ISSET(ps->media, RECV) || !sfd || !PS_ISSET(ps, FILLED)) { check = cm->conf.silent_timeout; - tmp_t_reason = 2; + tmp_t_reason = SILENT_TIMEOUT; } if (poller_now - atomic64_get(timestamp) < check) @@ -254,13 +267,7 @@ next: for (it = c->monologues.head; it; it = it->next) { ml = it->data; gettimeofday(&(ml->terminated),NULL); - if (tmp_t_reason==1) { - ml->term_reason = TIMEOUT; - } else if (tmp_t_reason==2) { - ml->term_reason = SILENT_TIMEOUT; - } else { - ml->term_reason = UNKNOWN; - } + ml->term_reason = tmp_t_reason; } ilog(LOG_INFO, "Closing call due to timeout"); @@ -2123,6 +2130,11 @@ void call_destroy(struct call *c) { timeval_totalstats_average_add(&m->totalstats_interval, &tim_result_duration); timeval_totalstats_interval_call_duration_add(&m->totalstats_interval, &ml->started, &g_now, &m->latest_graphite_interval_start); + + if (ml->term_reason==FINAL_TIMEOUT) { + atomic64_inc(&m->totalstats.total_final_timeout_sess); + atomic64_inc(&m->totalstats_interval.total_final_timeout_sess); + } } diff --git a/daemon/call.h b/daemon/call.h index 28f5c26e0..e11106d7c 100644 --- a/daemon/call.h +++ b/daemon/call.h @@ -35,7 +35,8 @@ enum termination_reason { REGULAR=1, FORCED=2, TIMEOUT=3, - SILENT_TIMEOUT=4 + SILENT_TIMEOUT=4, + FINAL_TIMEOUT=5 }; enum tag_type { @@ -236,6 +237,7 @@ struct totalstats { atomic64 total_timeout_sess; atomic64 total_rejected_sess; atomic64 total_silent_timeout_sess; + atomic64 total_final_timeout_sess; atomic64 total_regular_term_sess; atomic64 total_forced_term_sess; atomic64 total_relayed_packets; @@ -422,6 +424,7 @@ struct callmaster_config { int max_sessions; unsigned int timeout; unsigned int silent_timeout; + unsigned int final_timeout; unsigned int delete_delay; struct redis *redis; struct redis *redis_write; diff --git a/daemon/cli.c b/daemon/cli.c index ad831ffe8..31cf1cff3 100644 --- a/daemon/cli.c +++ b/daemon/cli.c @@ -39,6 +39,8 @@ static void cli_incoming_list_totals(char* buffer, int len, struct callmaster* m ADJUSTLEN(printlen,outbufend,replybuffer); printlen = snprintf(replybuffer,(outbufend-replybuffer), " Total timed-out sessions via SILENT_TIMEOUT :"UINT64F"\n",atomic64_get(&m->totalstats.total_silent_timeout_sess)); ADJUSTLEN(printlen,outbufend,replybuffer); + printlen = snprintf(replybuffer,(outbufend-replybuffer), " Total timed-out sessions via FINAL_TIMEOUT :"UINT64F"\n",atomic64_get(&m->totalstats.total_final_timeout_sess)); + ADJUSTLEN(printlen,outbufend,replybuffer); printlen = snprintf(replybuffer,(outbufend-replybuffer), " Total regular terminated sessions :"UINT64F"\n",atomic64_get(&m->totalstats.total_regular_term_sess)); ADJUSTLEN(printlen,outbufend,replybuffer); printlen = snprintf(replybuffer,(outbufend-replybuffer), " Total forced terminated sessions :"UINT64F"\n",atomic64_get(&m->totalstats.total_forced_term_sess)); diff --git a/daemon/graphite.c b/daemon/graphite.c index 66bf28add..d3d1fcff7 100644 --- a/daemon/graphite.c +++ b/daemon/graphite.c @@ -87,6 +87,7 @@ int send_graphite_data(struct callmaster *cm, struct totalstats *sent_data) { atomic64_local_copy_zero_struct(ts, &cm->totalstats_interval, total_timeout_sess); atomic64_local_copy_zero_struct(ts, &cm->totalstats_interval, total_rejected_sess); atomic64_local_copy_zero_struct(ts, &cm->totalstats_interval, total_silent_timeout_sess); + atomic64_local_copy_zero_struct(ts, &cm->totalstats_interval, total_final_timeout_sess); atomic64_local_copy_zero_struct(ts, &cm->totalstats_interval, total_regular_term_sess); atomic64_local_copy_zero_struct(ts, &cm->totalstats_interval, total_forced_term_sess); atomic64_local_copy_zero_struct(ts, &cm->totalstats_interval, total_relayed_packets); @@ -143,6 +144,8 @@ int send_graphite_data(struct callmaster *cm, struct totalstats *sent_data) { if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } rc = sprintf(ptr,"silent_timeout_sess "UINT64F" %llu\n", atomic64_get_na(&ts->total_silent_timeout_sess),(unsigned long long)g_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } + rc = sprintf(ptr,"final_timeout_sess "UINT64F" %llu\n", atomic64_get_na(&ts->total_final_timeout_sess),(unsigned long long)g_now.tv_sec); ptr += rc; + if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } rc = sprintf(ptr,"timeout_sess "UINT64F" %llu\n", atomic64_get_na(&ts->total_timeout_sess),(unsigned long long)g_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } rc = sprintf(ptr,"reject_sess "UINT64F" %llu\n", atomic64_get_na(&ts->total_rejected_sess),(unsigned long long)g_now.tv_sec); ptr += rc; diff --git a/daemon/main.c b/daemon/main.c index e16b6a0dc..236f48e95 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -66,6 +66,7 @@ static int table = -1; static int no_fallback; static int timeout; static int silent_timeout; +static int final_timeout; static int port_min = 30000; static int port_max = 40000; static int max_sessions = -1; @@ -285,6 +286,7 @@ static void options(int *argc, char ***argv) { { "tos", 'T', 0, G_OPTION_ARG_INT, &tos, "Default TOS value to set on streams", "INT" }, { "timeout", 'o', 0, G_OPTION_ARG_INT, &timeout, "RTP timeout", "SECS" }, { "silent-timeout",'s',0,G_OPTION_ARG_INT, &silent_timeout,"RTP timeout for muted", "SECS" }, + { "final-timeout",'a',0,G_OPTION_ARG_INT, &final_timeout, "Call timeout", "SECS" }, { "pidfile", 'p', 0, G_OPTION_ARG_FILENAME, &pidfile, "Write PID to file", "FILE" }, { "foreground", 'f', 0, G_OPTION_ARG_NONE, &foreground, "Don't fork to background", NULL }, { "port-min", 'm', 0, G_OPTION_ARG_INT, &port_min, "Lowest port to use for RTP", "INT" }, @@ -360,9 +362,13 @@ static void options(int *argc, char ***argv) { if (timeout <= 0) timeout = 60; + if (silent_timeout <= 0) silent_timeout = 3600; + if (final_timeout <= 0) + final_timeout = 0; + if (redisps) if (redis_ep_parse(&redis_ep, &redis_db, &redis_auth, "RTPENGINE_REDIS_AUTH_PW", redisps)) die("Invalid Redis endpoint [IP:PORT/INT] (--redis)"); @@ -536,6 +542,7 @@ no_kernel: mc.max_sessions = max_sessions; mc.timeout = timeout; mc.silent_timeout = silent_timeout; + mc.final_timeout = final_timeout; mc.delete_delay = delete_delay; mc.default_tos = tos; mc.b2b_url = b2b_url; diff --git a/debian/ngcp-rtpengine-daemon.default b/debian/ngcp-rtpengine-daemon.default index 161088ed8..a296a9c88 100644 --- a/debian/ngcp-rtpengine-daemon.default +++ b/debian/ngcp-rtpengine-daemon.default @@ -8,6 +8,7 @@ LISTEN_CLI=9900 # INTERFACES="12.23.34.45!23.34.45.56" TIMEOUT=60 SILENT_TIMEOUT=3600 +# FINAL_TIMEOUT=10800 PIDFILE=/var/run/ngcp-rtpengine-daemon.pid FORK=yes # TOS=184 diff --git a/debian/ngcp-rtpengine-daemon.init b/debian/ngcp-rtpengine-daemon.init index 5bf1e891f..f9a193d2d 100755 --- a/debian/ngcp-rtpengine-daemon.init +++ b/debian/ngcp-rtpengine-daemon.init @@ -58,6 +58,7 @@ fi [ -z "$LISTEN_CLI" ] || OPTIONS="$OPTIONS --listen-cli=$LISTEN_CLI" [ -z "$TIMEOUT" ] || OPTIONS="$OPTIONS --timeout=$TIMEOUT" [ -z "$SILENT_TIMEOUT" ] || OPTIONS="$OPTIONS --silent-timeout=$SILENT_TIMEOUT" +[ -z "$FINAL_TIMEOUT" ] || OPTIONS="$OPTIONS --final-timeout=$FINAL_TIMEOUT" [ -z "$PIDFILE" ] || OPTIONS="$OPTIONS --pidfile=$PIDFILE" [ -z "$TOS" ] || OPTIONS="$OPTIONS --tos=$TOS" [ -z "$PORT_MIN" ] || OPTIONS="$OPTIONS --port-min=$PORT_MIN"