Commit 2a648282 authored by Olav Kvittem's avatar Olav Kvittem

sipp scripts


git-svn-id: file:///home/svn/sipshaman/trunk@1 9383e1fa-a92b-456e-b4ec-45f0d4f7abeb
parents
#!/usr/bin/perl
#
# process sip log files from sipp-responder and sipp-test and report to Xymon
# the task.log file gives meta-info
use XML::Simple;
use Data::Dumper;
use Socket;
use IO::Select;
require "newgetopt.pl";
@opts=( 'f', 'die=s', 'timeout=s', 'bb=s', 'remote', 'debug', 'dump', 'v', 'h', 'help' );
my $usage="Usage $0 [-debug] [-die mins] [-remote] [-f]
-bb <hostname> - XYMON/BB host to receive reports
-remote - this is remote sipp (not used)
-f - wait for results like tail -f
-die <minutes> - end after <minutes>
";
my $rc=&NGetOpt(@opts);
die $usage if not $rc or $opt_h or $opt_help;
my $bb_host = $opt_bb || `hostname -f`;
$mos_limit=[0,3.2,3.9]; # mos values
$bb_color=["red", "yellow", "green"];
$call_limit=[0,70,90]; # call succes in percent
# check results from sipp-initated calls with tcpdumps in sipp-test
$tmp="/tmp/qstream-sipp-$$.xml";
my $endooflife=0;
if ($opt_die){
$endoflife=time+$opt_die*60;
}
my $timeout= $opt_timeout || 1; # wait n seconds for file too be updated
foreach $tasklog(@ARGV){
open TASKLOG, "<$tasklog" || die "Could not open $tasklog : $!";
while( 1 ){ # read task.log
# while(eof(TASKLOG)){ # wait for next line to file
# exit(1) if $opt_die && (time > $endoflife);
# last if !$opt_f;
# sleep $timeout;
# next; # wait for more data
# }
exit(1) if $opt_die && (time > $endoflife);
if (! ($line=<TASKLOG>)){ # could not read the line
exit(1) if $opt_die && (time > $endoflife);
last if !$opt_f;
sleep $timeout;
next;
}
next if $line !~ /[\d-]+ [\d:]+ \d+ \d+/; # invalid line/empty ..Format : date time port port
my ($date, $time, $pid, $sip_port, $rtp_port, $id, $function, $machine, $rtt)=split(/\s+/, $line);
# sleep 300; # minutes to be sure that the forked processes are dead
# active=1 test $active -gt 0
until (system("ps -p $pid > /dev/null")){ # wait until process finished
sleep $timeout;
}
$src=$id; $src=~ s/.*@//;
$machine=$src if !$machine ne '';
$machine=~s/:\d+$//;
if ($machine=~ /^\d+\.\d+/){ # lookup hostname
my $iaddr=inet_aton($machine);
$machine= gethostbyaddr($iaddr, AF_INET);
}
$machine=~s/\./,/g;
my $mossum=0, $n=0;
my @f=`ls rtp_*${pid}_*.pcap* 2>/dev/null`;
my $qstream_rep='';
if($#f >=0){ # yess some files
chomp(@f);
my $rtp_files= join(' ', @f);
$cmd="/local/net-status/bin/qstream.pl -v -rtp -rtt '$rtt' -id $src -xml $tmp $rtp_files";
$qstream_rep='date +%T $pid $port $mport $service@$server $function $machine ping' . $_;
open QSTREAM, "$cmd|";
while(<QSTREAM>){ $qstream_rep.=$_}
close QSTREAM;
# system($cmd); # || die "command failed : $cmd : $!";
$xml = XMLin($tmp) || die "Could not analyze XML $tmp : $!";
print Dumper($xml) if $opt_dump;
my @flow=();
if (ref($xml->{flow}) eq "ARRAY"){
@flow= @{$xml->{flow}};
} else { # just one
@flow=($xml->{flow});
}
$min_mos=10;
foreach $flow (@flow){
my $mos= $flow->{network_stats}->{MOS};
$mossum += $mos;
$n++;
$min_mos=$mos if ($mos < $min_mos) ;
}
}
if ($n >0){
my $mean_mos=$mossum/$n;
&bb_report("M-$function", $machine, &bb_color($mos_limit,$bb_color,$min_mos),
sprintf "$date $time - %.1f \n%s\n",$min_mos,$qstream_rep);
} else {
&bb_report("M-$function", $machine, &bb_color($mos_limit,$bb_color,0), "No RTP files");
}
my $log='';
# checking call success
if ($opt_remote){
if ($n > 0){
$status=100;
$message="Call received successfully";
} else {
$status=0;
$message="No calls received\n";
}
&bb_report("C-$function", $machine, &bb_color($call_limit,$bb_color,$status), $message);
} else {
open (CSV, "/local/net-status/sipp/bin/sipp-print -f 'OutgoingCall(C)|SuccessfulCall(C)|FailedCall(C)|Retransmissions(C)|ResponseTime1(C)|ResponseTime1StDev(C)|CallLength(C)|CallLengthStDev(C)' *${pid}_.csv|");
while(<CSV>){
$log.=$_;
if (/^\s+\d+\s+\d+\s+/){
my ($callsout, $success, $failed, $rest)=split;
if ($success>0){
$calls=$success+$failed;
$status=100*$success/$calls; # success rate in %
$message=sprintf "$date $time - %d percent success (%d/%d)\n%s",$status,$success,$calls,$log;
} else {
$status=0;
$message="No successfull calls :\n $log";
}
&bb_report("C-$function", $machine, &bb_color($call_limit,$bb_color,$status), $message);
}
}
close CSV;
}
}
close TASKLOG;
}
# /local/net-status/sipp/bin/sipp-print -id $src -q -f 'OutgoingCall(C)|SuccessfulCall(C)|FailedCall(C)|Retransmissions(C)|ResponseTime1(C)|ResponseTime1StDev(C)|CallLength(C)|CallLengthStDev(C)' *${pid}_.csv
unlink ($tmp);
exit(0);
sub bb_color {
my ($limit, $color, $value)=@_;
for ($i=$#$limit;$i>=$[;$i--){
if ( $value >= @$limit[$i]){
return @$color[$i];
}
}
}
sub bb_report {
my ($bbtest, $machine, $color, $msg)=@_;
# my $cmd="/usr/lib/hobbit/client/bin/bb $bb_host 'status $machine.$bbtest $color $msg\n'>>$ENV{HOME}/cmd.log 2>&1";
my $cmd="/usr/lib/hobbit/client/bin/bb $bb_host 'status $machine.$bbtest $color $msg\n'";
# system($cmd)|| warn "Command failed : $cmd : $!";
my @cmd=("/usr/lib/hobbit/client/bin/bb", "$bb_host", "status $machine.$bbtest $color $msg\n");
system(@cmd); # || warn "Command failed : $cmd : $!";
print $cmd, "\n" if $opt_v;
}
#!/bin/bash
# make qstream statistics from sipp-test logs
# - listen to updates on the task.log file
. /etc/sipshaman/sipshaman.cf
y=`date +%Y`
m=`date +%m`
d=`date +%d`
h=`date +%H`
ydir=$DATA/$y
mdir=$ydir/$m
ddir=$mdir/$d
hdir=$ddir/$h
cd $hdir
$BIN/qstream-sipp-check $* -bb $BB_HOST -f -die 59 task.log
#!/usr/bin/perl
# parse and print variable from sipp .csv report-files
require "newgetopt.pl";
$usage="$0 -f field1|file2|... file.csv...
-q quiet - less info
-all - list all lines";
@opts=('f=s', 'q', 'all', 'id=s');
&NGetOpt(@opts) || die $usage;
if ($opt_f){
$fields=$opt_f;
} else {
$fields = 'OutgoingCall(C)|FailedCall(C)|Retransmissions(C)|ResponseTime1(C)|ResponseTime1StDev(C)|CallLength(C)|CallLengthStDev(C)';
}
$fields =~ s/\(/\\(/g;
$fields =~ s/\)/\\)/g;
foreach $file (@ARGV){
open CSV, "<$file" || die "Could not open $file";
if (! defined($head) ) { # first heading
$head=<>; # top line with headerfields
@h=split(/;/, $head);
foreach $fno (0 .. $#h){ # find matching headings
if ($h[$fno] =~ $fields){
push(@fno, $fno);
printf "%20s ", $h[$fno] if ! $opt_q;
}
}
print " File name\n\n" if ! $opt_q;
} else {
$head=<>;
}
while(<CSV>){ # read data lines
next if /$h[0]/; # heading
@f= split(/;/);
$line="";
foreach $fno (@fno){
$line.=sprintf "%20s ", $f[$fno];
}
# next if $line =~ /^[\s0;:]+$/; # zero stats
printf "$line %s\n", $opt_id || $file if $opt_all or eof(CSV);
}
#xs printf "$line %s\n", $opt_id || $file; # last line is final status
}
#!/bin/sh
# register sipp user
#
. /etc/sipshaman/sipshaman.cf
registrar=`/sbin/ifconfig eth0| perl -ne 'print $1 if /inet addr:(\d+\.\d+\.\d+\.\d+)/'`
interf=$registrar
if test .$1 = .-h; then
echo Usage__: $0 "[registrar [announed-interface]]"
echo Default: $0 $registrar $interf
exit 1
fi
if test $# -gt 0; then
registrar=$1
shift
fi
if test $# -gt 0; then
interf=$1
shift
fi
y=`date +%Y`
m=`date +%m`
d=`date +%d`
h=`date +%H`
t1=`date +%s`
ydir=$DATA/$y
test -d $ydir || mkdir $ydir
mdir=$ydir/$m
test -d $mdir || mkdir $mdir
ddir=$mdir/$d
test -d $ddir || mkdir $ddir
hdir=$ddir/$h
test -d $hdir || mkdir $hdir
cd $hdir
$BIN/sipp $registrar -s sipp -i $interf -p $REGISTER_PORT -l 1 -m 1 -sf $CONF/register.xml -trace_err -trace_msg -inf $CONF/register-name.txt -bg
#!/bin/bash
# start a sipp responder that waits for a test call
# sipp exits for each and logs data in a directory per hour
# and exits withinafter an hour
. /etc/sipshaman/sipshaman.cf
registrar=`/sbin/ifconfig eth0| perl -ne 'print $1 if /inet addr:(\d+\.\d+\.\d+\.\d+)/'`
interf=$registrar
if test .$1 = .-h; then
echo Usage__: $0 "[registrar [announed-interface]]"
echo Default: $0 $registrar $interf
exit 1
fi
if test $# -gt 0; then
registrar=$1
shift
fi
if test $# -gt 0; then
interf=$1
shift
fi
while test 1=1 ; do
ps axw | grep -q "$BIN/[s]ipp $registrar" -
if test $? = 1 ; then # not found
y=`date +%Y`
m=`date +%m`
d=`date +%d`
h=`date +%H`
t1=`date +%s`
ydir=$DATA/$y
test -d $ydir || mkdir $ydir
mdir=$ydir/$m
test -d $mdir || mkdir $mdir
ddir=$mdir/$d
test -d $ddir || mkdir $ddir
hdir=$ddir/$h
test -d $hdir || mkdir $hdir
cd $hdir
port=$SIP_PORT
mport=16388
$BIN/sipp $registrar:5062 -s sipp -i $interf -p $port -mp $mport -l 1 -m 1 -sf $CONF/sipp-responder.xml -trace_stat -trace_logs -trace_err -trace_msg -rp 600000 -r 1 -bg -nofork 2>> sipp.err >> sipp.log &
pid=$!
echo $y-$m-$d `date +%T` $pid $port $mport sipp@$interf iPBX `hostname --fqdn` 0 >> task.log
t2=`date +%s`
dt=$(($t2-$t1))
if test $dt -lt 5; then #
echo #### too short interval $dt | mail -s sipp-responder oak@uninett.no
exit 1
fi
fi
sleep 3
done
#!/bin/sh
# start responder if not running
. /etc/sipshaman/sipshaman.cf
ps axw | grep -q "sh .*/local/net-status/sipp/bin/sipp-responde[r]" -
if test $? -eq 1; then # not found and ok to run
$BIN/sipp-responder&
fi
\ No newline at end of file
#!/bin/bash
# run a series of sipp-tests and store the logs
. /etc/sipshaman/sipshaman.cf
y=`date +%Y`
m=`date +%m`
d=`date +%d`
h=`date +%H`
ydir=$DATA/$y
test -d $ydir || mkdir $ydir
mdir=$ydir/$m
test -d $mdir || mkdir $mdir
ddir=$mdir/$d
test -d $ddir || mkdir $ddir
hdir=$ddir/$h
test -d $hdir || mkdir $hdir
cd $hdir
port=$SIP_PORT # sip service port start
mport=$MEDIA_PORT # rtp service port start
export IFS=";"
addr=`/sbin/ifconfig eth0 | perl -ne 'print $1 if /inet addr:(\d+\.\d+\.\d+\.\d+)/'`
while read server service rest; do
echo $server | egrep -q '^\s*#'
if test $? = 1 ; then # no comment
$BIN/sipp $server -s $service -i $addr -sf $CONF/sipp-client.xml -p $port -mp $mport -m 10 -rp 200000 -l 1 -trace_stat -fd 99999 -trace_logs -trace_msg -trace_err -bg >/dev/null 2>&1 &
pid=$!
adr=$service@$server
echo $y-$m-$d `date +%T` $pid $port $mport $service@$server `ping -c 10 -i 0.5 -q $server | awk -F / '/^rtt /{print $5}'`>> task.log
time=$y-$m-$d-$h
port=$(($port+2))
mport=$(($mport+4))
fi
done
#!/bin/bash
vent=$1
shift
echo /usr/sbin/tcpdump $* >> tcpdump.log
/usr/sbin/tcpdump $* 2>&1 >> tcpdump.log &
sleep $vent
kill %1
exit 0
head 1.1;
access;
symbols;
locks
oak:1.1; strict;
comment @# @;
1.1
date 2009.03.03.14.27.50; author oak; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial revision
@
text
@#SEQUENTIAL
# targets for sipp performance monitoring
# server service
# phoenix.uninett.no;plain_echo
bo-sip.hit.no;plain_echo
sip.hia.no;plain_echo
sip.hiof.no;plain_echo
sip.uninett.no;plain_echo
# sip.uit.no;plain_echo
# sip.uio.no;plain_echo@
head 1.1;
access;
symbols;
locks
up:1.1; strict;
comment @# @;
1.1
date 2011.08.12.13.02.22; author up; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial revision
@
text
@<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE scenario SYSTEM "sipp.dtd">
<!-- This program is free software; you can redistribute it and/or -->
<!-- modify it under the terms of the GNU General Public License as -->
<!-- published by the Free Software Foundation; either version 2 of the -->
<!-- License, or (at your option) any later version. -->
<!-- -->
<!-- This program is distributed in the hope that it will be useful, -->
<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -->
<!-- GNU General Public License for more details. -->
<!-- -->
<!-- You should have received a copy of the GNU General Public License -->
<!-- along with this program; if not, write to the -->
<!-- Free Software Foundation, Inc., -->
<!-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -->
<!-- -->
<!-- Sipp 'uac' scenario with pcap (rtp) play -->
<!-- -->
<scenario name="UAC with media and tcpdump">
<!-- In client mode (sipp placing calls), the Call-ID MUST be -->
<!-- generated by sipp. To do so, use [call_id] keyword. -->
<nop> <action>
<!-- outgoing proxy -->
<assignstr assign_to="proxy_ip" value="[local_ip]"/>
<assignstr assign_to="proxy_port" value="5062"/>
<!-- automedia_port to be called once -->
<assignstr assign_to="my_media_port" value="[auto_media_port]"/>
<log message="my_media_port [$my_media_port]" />
</action> </nop>
<send retrans="500">
<![CDATA[
INVITE sip:[service]@@[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
Max-Forwards: 70
Contact: sip:sipp@@[local_ip]:[local_port]
To: SIPP test <sip:[service]@@[remote_ip]:[remote_port]>
From: sipp <sip:sipp@@[$proxy_ip]:[$proxy_port]>;tag=[pid]SIPpTag09[call_number]
Call-ID: [call_id]
CSeq: 1 INVITE
Subject: Performance Test
Content-Type: application/sdp
User-Agent: sipp@@sip-services
Content-Length: [len]
v=0
o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
s=-
c=IN IP[local_ip_type] [local_ip]
t=0 0
/local/net-status/sipp/bin/sipp-start-responderm=audio [$my_media_port] RTP/AVP 8 101
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-11,16
]]>
</send>
<recv response="100" optional="true">
</recv>
<recv response="180" optional="true">
</recv>
<!-- By adding rrs="true" (Record Route Sets), the route sets -->
<!-- are saved and used for following messages sent. Useful to test -->
<!-- against stateful SIP proxies/B2BUAs. -->
<recv response="200" rtd="true" crlf="true" rrs="true">
</recv>
<!-- nop>
<action>
<log message="next_url [next_url]" />
</action>
</nop -->
<!-- Set the response address to the received OK rather than the proxy in the INVITE -->
<nop>
<action>
<log message="next_url [next_url]" />
<assignstr assign_to="url" value="[next_url]" />
<ereg regexp="sip:(.*@@|)([0-9A-Za-z\.]+):([0-9]+);transport=([A-Z]+)" search_in="var" check_it="true" assign_to="dummy,dummy,client_ip,client_port,transport" variable="url" />
<setdest host="[$client_ip]" port="[$client_port]" protocol="[$transport]" />
<log message="remote_ip=[$client_ip], remote_port=[$client_port]" />
</action>
</nop>
<Reference variables="dummy" />
<!-- Packet lost can be simulated in any send/recv message by -->
<!-- by adding the 'lost = "10"'. Value can be [1-100] percent. -->
<!-- From: sipp <sip:sipp@@[local_ip]:[local_port]>;tag=[pid]SIPpTag09[call_number] -->
<nop>
<action>
<setdest host="[$proxy_ip]" port="[$proxy_port]" protocol="[transport]" />
</action>
</nop>
<send>
<![CDATA[
ACK [next_url] SIP/2.0
[last_Via:]
Max-Forwards: 70
[routes]
Contact: sip:sipp@@[local_ip]:[local_port]
To: <sip:[service]@@[remote_ip]:[remote_port]>[peer_tag_param]
From: sipp <sip:sipp@@[$proxy_ip]:[$proxy_port]>;tag=[pid]SIPpTag09[call_number]
Call-ID: [call_id]
CSeq: 1 ACK
User-Agent: sipp@@sip-services
Content-Length: 0
]]>
</send>
<!-- Play a pre-recorded PCAP file (RTP stream) -->
<nop>
<action>
<exec command="/local/net-status/sipp/bin/tcpdump-vent 10 -i eth0 -q -s 0 -w rtp_[local_ip]_[pid]_[call_number].pcap src host [local_ip] and dst port [$my_media_port]"/>
<exec play_pcap_audio="/local/net-status/sipp/pcap/g711a.pcap"/>
</action>
</nop>
<!-- Pause 8 seconds, which is approximately the duration of the -->
<!-- PCAP file
-->
<pause milliseconds="8000"/>
<!-- The 'crlf' option inserts a blank line in the statistics report. -->
<send retrans="500">
<![CDATA[
BYE [next_url] SIP/2.0
[last_Via:]
Max-Forwards: 70
[routes]
Contact: sip:sipp@@[local_ip]:[local_port]
To: SIPP test <sip:[service]@@[remote_ip]:[remote_port]>[peer_tag_param]
From: sipp <sip:sipp@@[$proxy_ip]:[$proxy_port]>;tag=[pid]SIPpTag09[call_number]
Call-ID: [call_id]
CSeq: 2 BYE
User-Agent: sipp@@sip-services
Content-Length: 0
]]>
</send>
<recv response="200" crlf="true">
</recv>
<!-- definition of the response time repartition table (unit is ms) -->
<ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/>
<!-- definition of the call length repartition table (unit is ms) -->
<CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/>
<pause milliseconds="2000"/>
</scenario>
@
head 1.1;
access;
symbols;
locks
up:1.1; strict;
comment @# @;
1.1
date 2011.04.19.09.38.20; author up; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial revision
@
text
@<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE scenario SYSTEM "sipp.dtd">
<!-- This program is free software; you can redistribute it and/or -->
<!-- modify it under the terms of the GNU General Public License as -->
<!-- published by the Free Software Foundation; either version 2 of the -->
<!-- License, or (at your option) any later version. -->
<!-- -->
<!-- This program is distributed in the hope that it will be useful, -->
<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -->
<!-- GNU General Public License for more details. -->
<!-- -->
<!-- You should have received a copy of the GNU General Public License -->
<!-- along with this program; if not, write to the -->
<!-- Free Software Foundation, Inc., -->
<!-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -->
<!-- -->
<!-- Sipp 'uac' scenario with pcap (rtp) play -->
<!-- -->
<scenario name="UAC with media and tcpdump">
<!-- In client mode (sipp placing calls), the Call-ID MUST be -->
<!-- generated by sipp. To do so, use [call_id] keyword. -->
<send retrans="500">
<![CDATA[
INVITE sip:[service]@@[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: sipp <sip:sippa@@[local_ip]:[local_port]>;tag=[pid]SIPpTag09[call_number]
To: sut <sip:[service]@@[remote_ip]:[remote_port]>
Call-ID: [call_id]
CSeq: 1 INVITE
Contact: sip:sippa@@[local_ip]:[local_port]
Max-Forwards: 70
Subject: Performance Test Miguel
Content-Type: application/sdp
Content-Length: [len]
v=0
o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
s=-
c=IN IP[local_ip_type] [local_ip]
t=0 0
m=audio [media_port] RTP/AVP 8 101
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-11,16
]]>
</send>