From 5635a8ccf699a947abf8b889f5a228c34730a321 Mon Sep 17 00:00:00 2001 From: Frederic-Philippe Metz Date: Mon, 30 Mar 2015 11:24:15 +0200 Subject: [PATCH 1/5] Replaced rtpengine-ctl shell script with perl script. --- utils/rtpengine-ctl | 128 +++++++++++++++++++++++--------------------- 1 file changed, 67 insertions(+), 61 deletions(-) diff --git a/utils/rtpengine-ctl b/utils/rtpengine-ctl index e69deb12c..464fcf0d4 100755 --- a/utils/rtpengine-ctl +++ b/utils/rtpengine-ctl @@ -1,70 +1,76 @@ -#!/bin/bash -# +#!/usr/bin/perl -host=127.0.0.1 -port=9900 -error_rc=255 +use IO::Socket::INET; -prgname=${0##*/} -prgdir=${0%$prgname} +$num_args = $#ARGV + 1; +if ($num_args == 0) { + showusage(); + exit; +} + +# auto-flush on socket +$| = 1; + +my $argumentstring = ""; +my $ip = "127.0.0.1"; +my $port = "9900"; -showusage() { - echo "" - echo " $0 [ -ip -port ] " - echo "" - echo " Supported commands are:" - echo "" - echo " list [ numsessions | sessions | session ]" - echo " numsessions : prints the number of sessions" - echo " sessions : print one-liner session information" - echo " session : print detail about one session" - echo " totals : print total statistics (does not include current sessions)" - echo "" - echo " terminate [ all | ]" - echo " all : terminates all current sessions" - echo " : session is immediately terminated" - echo "" - echo "" - echo " Return Value:" - echo " 0 on success with ouput from server side, other values for failure." - echo "" - exit 0 +for (my $argnum=0; $argnum <= $#ARGV; $argnum++) { + if ($ARGV[$argnum] eq "-ip") { + die "No argument after -ip\n" unless $argnum+1<=$#ARGV; + $argnum = $argnum+1; + $ip = $ARGV[$argnum]; + } elsif ($ARGV[$argnum] eq "-port") { + die "No argument after -port\n" unless $argnum+1<=$#ARGV; + $argnum = $argnum+1; + $port = $ARGV[$argnum]; + } else { + $argumentstring .= "$ARGV[$argnum] "; + } } -if [ $# -eq 0 ]; then showusage; fi +# create a connecting socket +my $socket = new IO::Socket::INET ( + PeerHost => $ip, + PeerPort => $port, + Proto => 'tcp', +); +die "Cannot connect to the rtpengine $!\n" unless $socket; + +$argumentstring = trim($argumentstring); +my $size = $socket->send($argumentstring); + +# notify server that request has been sent +shutdown($socket, 1); + +# receive a response of up to 10MB +my $response = ""; +$socket->recv($response, 1024*1024*10); +print $response; -command -v nc 2>&1 >/dev/null -if [ $? -ne 0 ]; then - echo "Error: $0 requires netcat to be installed." - exit 0 -fi +$socket->close(); -while [ $# -gt 0 ]; do - case $1 in - "-?"|"-help"|"-h") - showusage - ;; - "-ip") - shift - if [ $# -gt 0 ]; then - host=$1 - else - echo "Missing parameter for option '-ip'" >&2 - fi - ;; - "-port") - shift - if [ $# -gt 0 ]; then - port=$1 - else - echo "Missing parameter for option '-port'" >&2 - fi - ;; - *) - varargs="$varargs $1" - esac - shift -done +sub showusage { + print "\n"; + print " rtpengine-ctl [ -ip -port ] \n"; + print "\n"; + print " Supported commands are:\n"; + print "\n"; + print " list [ numsessions | sessions | session | totals ]\n"; + print " numsessions : prints the number of sessions\n"; + print " sessions : print one-liner session information\n"; + print " session : print detail about one session\n"; + print " totals : print total statistics\n"; + print "\n"; + print " terminate [ all | ]\n"; + print " all : terminates all current sessions\n"; + print " : session is immediately terminated\n"; + print "\n"; + print "\n"; + print " Return Value:\n"; + print " 0 on success with ouput from server side, other values for failure.\n"; + print "\n"; +} -echo -n ${varargs} | nc ${host} ${port} +sub trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s }; From 6255d1fe2f2824e27e7699b23cbc5c9f92dfbee2 Mon Sep 17 00:00:00 2001 From: pkuzak Date: Fri, 24 Apr 2015 09:48:41 +0200 Subject: [PATCH 2/5] Disable delay measurement by default --- kernel-module/rtpengine_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel-module/rtpengine_config.h b/kernel-module/rtpengine_config.h index 13188e85c..955fe7bc1 100644 --- a/kernel-module/rtpengine_config.h +++ b/kernel-module/rtpengine_config.h @@ -10,6 +10,6 @@ #ifndef RTPENGINE_CONFIG_H_ #define RTPENGINE_CONFIG_H_ -#define RE_HAS_MEASUREDELAY 1 +#define RE_HAS_MEASUREDELAY 0 #endif /* RTPENGINE_CONFIG_H_ */ From c444c05a5f14ca211e6a9aac93be9b19b242fafd Mon Sep 17 00:00:00 2001 From: Frederic-Philippe Metz Date: Mon, 4 May 2015 14:26:05 +0200 Subject: [PATCH 3/5] Implemented MAX_SESSIONS limit or calls. related to RTPENGINE-20 --- daemon/call.h | 1 + daemon/call_interfaces.c | 12 ++++++++++++ daemon/main.c | 3 +++ debian/ngcp-rtpengine-daemon.default | 1 + debian/ngcp-rtpengine-daemon.init | 2 ++ el/rtpengine.init | 5 +++++ 6 files changed, 24 insertions(+) diff --git a/daemon/call.h b/daemon/call.h index ab9ab85bd..40c0ca699 100644 --- a/daemon/call.h +++ b/daemon/call.h @@ -426,6 +426,7 @@ struct callmaster_config { GQueue *interfaces; /* struct interface_address */ int port_min; int port_max; + int max_sessions; unsigned int timeout; unsigned int silent_timeout; unsigned int delete_delay; diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index f9f495803..242a82134 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -691,6 +691,18 @@ out: const char *call_offer_ng(bencode_item_t *input, struct callmaster *m, bencode_item_t *output, const char* addr, const struct sockaddr_in6 *sin) { + static char *errstr[64]; memset(errstr,0,64); + + if (m->conf.max_sessions>0) { + rwlock_lock_r(&m->hashlock); + if (g_hash_table_size(m->callhash) >= m->conf.max_sessions) { + rwlock_unlock_r(&m->hashlock); + ilog(LOG_ERROR, "Parallel session limit reached (%i)",m->conf.max_sessions); + snprintf(errstr, 64, "Parallel session limit reached (%i)",m->conf.max_sessions); + return errstr; + } + rwlock_unlock_r(&m->hashlock); + } return call_offer_answer_ng(input, m, output, OP_OFFER, addr, sin); } diff --git a/daemon/main.c b/daemon/main.c index 660080128..a0b7cf58a 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -101,6 +101,7 @@ static int timeout; static int silent_timeout; static int port_min = 30000; static int port_max = 40000; +static int max_sessions = 0; static u_int32_t redis_ip; static u_int16_t redis_port; static int redis_db = -1; @@ -297,6 +298,7 @@ static void options(int *argc, char ***argv) { { "delete-delay", 'd', 0, G_OPTION_ARG_INT, &delete_delay, "Delay for deleting a session from memory.", "INT" }, { "sip-source", 0, 0, G_OPTION_ARG_NONE, &sip_source, "Use SIP source address by default", NULL }, { "dtls-passive", 0, 0, G_OPTION_ARG_NONE, &dtls_passive_def,"Always prefer DTLS passive role", NULL }, + { "max-sessions", 0, 0, G_OPTION_ARG_INT, &max_sessions, "Limit of maximum number of sessions", NULL }, { NULL, } }; @@ -572,6 +574,7 @@ no_kernel: mc.interfaces = &interfaces; mc.port_min = port_min; mc.port_max = port_max; + mc.max_sessions = max_sessions; mc.timeout = timeout; mc.silent_timeout = silent_timeout; mc.delete_delay = delete_delay; diff --git a/debian/ngcp-rtpengine-daemon.default b/debian/ngcp-rtpengine-daemon.default index d06a56e74..afa883027 100644 --- a/debian/ngcp-rtpengine-daemon.default +++ b/debian/ngcp-rtpengine-daemon.default @@ -27,3 +27,4 @@ TABLE=0 # GRAPHITE=9006 # GRAPHITE_INTERVAL=60 # GRAPHITE_PREFIX=myownprefix +# MAX_SESSIONS=5000 diff --git a/debian/ngcp-rtpengine-daemon.init b/debian/ngcp-rtpengine-daemon.init index f3001db7f..7be49ea14 100755 --- a/debian/ngcp-rtpengine-daemon.init +++ b/debian/ngcp-rtpengine-daemon.init @@ -76,6 +76,8 @@ OPTIONS="$OPTIONS --table=$TABLE" [ -z "$GRAPHITE" ] || OPTIONS="$OPTIONS --graphite=$GRAPHITE" [ -z "$GRAPHITE_INTERVAL" ] || OPTIONS="$OPTIONS --graphite-interval=$GRAPHITE_INTERVAL" [ -z "$GRAPHITE_PREFIX" ] || OPTIONS="$OPTIONS --graphite-prefix=$GRAPHITE_PREFIX" +[ -z "$MAX_SESSIONS" ] || OPTIONS="$OPTIONS --max-sessions=$MAX_SESSIONS" + if test "$FORK" = "no" ; then OPTIONS="$OPTIONS --foreground" fi diff --git a/el/rtpengine.init b/el/rtpengine.init index 3cf2930ad..cf3ff51c1 100644 --- a/el/rtpengine.init +++ b/el/rtpengine.init @@ -167,6 +167,11 @@ build_opts() { then OPTS+=" --log-facility-rtcp=$LOG_FACILITY_RTCP" fi + + if [[ -n "$MAX_SESSIONS" ]] + then + OPTS+=" --max-sessions=$MAX_SESSIONS" + fi } start() { From ef842591b7c48a79b25aa8353b266a010549a68a Mon Sep 17 00:00:00 2001 From: Pawel Kuzak Date: Tue, 12 May 2015 14:12:47 +0200 Subject: [PATCH 4/5] Added MAX_SESSIONS to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d03e7ff6f..5d8613749 100644 --- a/README.md +++ b/README.md @@ -187,6 +187,7 @@ option and which are reproduced below: -g, --graphite=[IP46:]PORT TCP address of graphite statistics server -w, --graphite-interval=INT Graphite data statistics send interval --graphite-prefix=STRING Graphite prefix for every line + --max-sessions=INT Limit the number of maximum concurrent sessions Most of these options are indeed optional, with two exceptions. It's mandatory to specify at least one local IP address through `--interface`, and at least one of the `--listen-...` options must be given. From 369316adb037a7313281711f35b8cc1b020d059d Mon Sep 17 00:00:00 2001 From: Pawel Kuzak Date: Tue, 12 May 2015 17:32:27 +0200 Subject: [PATCH 5/5] Added rejected sessions statistics to total stats and graphite --- daemon/call.h | 1 + daemon/call_interfaces.c | 2 ++ daemon/cli.c | 2 ++ daemon/graphite.c | 3 +++ 4 files changed, 8 insertions(+) diff --git a/daemon/call.h b/daemon/call.h index 40c0ca699..309a7d1f7 100644 --- a/daemon/call.h +++ b/daemon/call.h @@ -223,6 +223,7 @@ struct stats { struct totalstats { time_t started; atomic64 total_timeout_sess; + atomic64 total_rejected_sess; atomic64 total_silent_timeout_sess; atomic64 total_regular_term_sess; atomic64 total_forced_term_sess; diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 242a82134..73ddec05c 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -697,6 +697,8 @@ const char *call_offer_ng(bencode_item_t *input, struct callmaster *m, bencode_i rwlock_lock_r(&m->hashlock); if (g_hash_table_size(m->callhash) >= m->conf.max_sessions) { rwlock_unlock_r(&m->hashlock); + atomic64_inc(&m->totalstats.total_rejected_sess); + atomic64_inc(&m->totalstats_interval.total_rejected_sess); ilog(LOG_ERROR, "Parallel session limit reached (%i)",m->conf.max_sessions); snprintf(errstr, 64, "Parallel session limit reached (%i)",m->conf.max_sessions); return errstr; diff --git a/daemon/cli.c b/daemon/cli.c index e41397c08..50ee6c7d6 100644 --- a/daemon/cli.c +++ b/daemon/cli.c @@ -42,6 +42,8 @@ static void cli_incoming_list_totals(char* buffer, int len, struct callmaster* m ADJUSTLEN(printlen,outbufend,replybuffer); printlen = snprintf(replybuffer,(outbufend-replybuffer), " Total managed sessions :"UINT64F"\n", num_sessions); ADJUSTLEN(printlen,outbufend,replybuffer); + printlen = snprintf(replybuffer,(outbufend-replybuffer), " Total rejected sessions :"UINT64F"\n", atomic64_get(&m->totalstats.total_rejected_sess)); + ADJUSTLEN(printlen,outbufend,replybuffer); printlen = snprintf(replybuffer,(outbufend-replybuffer), " Total timed-out sessions via TIMEOUT :"UINT64F"\n",atomic64_get(&m->totalstats.total_timeout_sess)); 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)); diff --git a/daemon/graphite.c b/daemon/graphite.c index 14fcd1bb1..e072597de 100644 --- a/daemon/graphite.c +++ b/daemon/graphite.c @@ -135,6 +135,7 @@ int send_graphite_data() { /* atomically copy values to stack and reset to zero */ 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_regular_term_sess); atomic64_local_copy_zero_struct(&ts, &cm->totalstats_interval, total_forced_term_sess); @@ -172,6 +173,8 @@ int send_graphite_data() { rc = sprintf(ptr,"%s.totals.silent_timeout_sess "UINT64F" %llu\n",hostname, 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,"%s.totals.timeout_sess "UINT64F" %llu\n",hostname, 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,"%s.totals.reject_sess "UINT64F" %llu\n",hostname, atomic64_get_na(&ts.total_rejected_sess),(unsigned long long)g_now.tv_sec); ptr += rc; rc = write(graphite_sock, data_to_send, ptr - data_to_send); if (rc<0) {