launch 4.44 KB
Newer Older
1 2
#!/bin/bash

3
### CONFIGURATION ###
4

5 6 7 8
# You can set these in a launch.config.perso file that you put into
# the root directory. See launch.config.perso.sample for an example.

# location of the executables of interest
9 10
FLEXISIP=${FLEXISIP:=/opt/belledonne-communications/bin/flexisip}
SIPP=${SIPP:=sipp}
11 12

# Number of users to simulate
13
NB_USERS=${NB_USERS:=1000}
14 15 16 17 18

# invite rate, number of invites to send every second
INV_RATE=${INV_RATE:=50}

# duration of the call
19
CALL_LENGTH=${CALL_LENGTH:=60}
20 21

# expire
22
EXPIRE=${EXPIRE:=3600}
23 24 25 26


### More advanced configuration ###

27 28 29 30 31 32 33
IP=${IP:=127.0.0.1}
DOMAIN=${DOMAIN:=localhost}
FLEXISIP_PORT=${FLEXISIP_PORT:=50060}
PROXY=${PROXY:=localhost}
REGISTER_PORT=${REGISTER_PORT:=5070}
USERS_PORT=${USERS_PORT:=5063}
INVITER_PORT=${INVITER_PORT:=5064}
34
SKIP_REGISTERS=${SKIP_REGISTERS:=0}
35
SKIP_UAS=${SKIP_UAS:=0}
36

37
UA="Linphone/Linphone-3.3.x_(sipp/unknown)"
38 39 40 41
SDOMAIN="-set domain $DOMAIN"
SEXPIRE="-set expire $EXPIRE"
SUA="-set ua $UA"
PWD="`pwd`"
42

43
# Import configuration
44
FOLDER=$1
45 46

# Use auth or not?
47 48
if [ -n "$2" ]
then
49 50
 echo -e "Using authentication"
 AUTH_PREFIX="-auth"
51
else
52
 echo -e "NOT using authentication"
53
fi
54 55 56 57 58 59 60 61 62 63 64
AUTHENTICATION_VALUE="true"
[ -z "$2" ] && AUTHENTICATION_VALUE="false"

# If using auth, check which files we should use: if a test contains a "passwords" file, then use it, otherwise use the default.
# Same thing for the CSV file. This allows for test-specific authentication
PASSWORD_FILE="$PWD/passwords"
[ -f "$FOLDER/passwords" ] && PASSWORD_FILE="$FOLDER/passwords"

USERS_CSV="$PWD/users.csv"
[ -f "$FOLDER/users.csv" ] && USERS_CSV="$FOLDER/users.csv"

65 66
UAS_FILE="$PWD/uas.xml"
[ -f "$FOLDER/uas.xml" ] && UAS_FILE="$FOLDER/uas.xml"
67

68

69 70 71 72 73 74
if [ -z $FOLDER ] 
then
 echo "Usage ./launch folder, where folder is "
 ls */launch.config | sed 's/\/.*$//'
 exit
fi
75 76

# load test-specific configuration values
77
[ ! -f $FOLDER/launch.config ] && echo "config file not found : "$FOLDER/launch.config"" && exit
78 79 80
. $FOLDER/launch.config


81 82
FLEX_OPTIONS="$FLEX_OPTIONS -p flexisip_pid -c $FOLDER/flexisip.conf -t sip:*:$FLEXISIP_PORT --hosts localhost=127.0.0.1 --set module::Authentication/datasource=\"$PASSWORD_FILE\""
FLEX_OPTIONS="$FLEX_OPTIONS --set module::Authentication/enabled=$AUTHENTICATION_VALUE"
83

84
SIPP_COMMONS="127.0.0.1:$FLEXISIP_PORT $SIPP_COMMONS -i $IP -trace_err -trace_msg"
85
REG_OPTIONS="$REG_OPTIONS -p $REGISTER_PORT -m `echo "1+$NB_USERS"|bc` $SIPP_COMMONS -inf $USERS_CSV $SDOMAIN $SEXPIRE"
86
REG_INVITER_OPTIONS="$REG_INVITER_OPTIONS -p $INVITER_PORT -m 1 $SIPP_COMMONS -nd $SDOMAIN $SEXPIRE $SUA"
87
INV_OPTIONS="$INV_OPTIONS -m $NB_USERS -p $INVITER_PORT $SIPP_COMMONS $SDOMAIN $SUA "
88
UAS_OPTIONS="$UAS_OPTIONS -bg -p $USERS_PORT $SIPP_COMMONS -mi $IP -mp 15000 -rtp_echo -trace_msg"
89

90 91
echo "NB_USERS=$NB_USERS"
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
92

93 94
# Accept core dumps
ulimit -c unlimited
95

96 97 98
# Open many file descriptors
ulimit -n 65000

99
if [[ "$SKIP_UAS" -eq "0" ]]; then
100

101 102 103 104 105
	CMD_UAS="$SIPP -sf $UAS_FILE $UAS_OPTIONS"
	echo -e "\nStart users listening:"
	echo $CMD_UAS
	$CMD_UAS 2>&1 > uas.log
	sleep 2
106

107
fi
108
	
109
CMD_FLEXISIP="$FLEXISIP $FLEX_OPTIONS"
110
echo -e "Start flexisip:"
111
echo $CMD_FLEXISIP
112
$CMD_FLEXISIP &> flexisip.log &
113
sleep 2
114 115 116 117 118 119 120
ps aux | grep flexisip | grep -v grep
if [ $? -ne 0 ]; then
  echo "Error launching flexisip"
  cat flexisip.log
  exit -1
fi

121

122 123 124 125 126
if [[ "$SKIP_REGISTERS" -eq "0" ]]; then
	CMD_REG_USERS="$SIPP $PROXY -sf register_users.xml $REG_OPTIONS -set ua noauth"
	echo -e "Register users:"
	echo $CMD_REG_USERS
	$CMD_REG_USERS
127

128 129 130 131 132 133 134
	CMD_REG_INVITER="$SIPP $PROXY -sf register_inviter$AUTH_PREFIX.xml $REG_INVITER_OPTIONS"
	echo -e "Register inviter"
	echo $CMD_REG_INVITER
	$CMD_REG_INVITER
else
	echo "Skipping registration because tests asks for it"
fi
135 136


137 138 139 140 141 142

function take_mem_shot() {
	if [ "$(uname)" == "Darwin" ]; then
		top -l 1 -pid `cat flexisip_pid` > memory.log
	elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
		top -n 1 -p `cat flexisip_pid` > memory.log
143 144
		echo "##### Proc #####" >> memory.log
		cat /proc/`cat flexisip_pid`/status >> memory.log
145 146 147
	fi
}

148 149
# Allow killing
function onexit() {
150
	echo -e "Killing everyone"
151
	kill -9 `cat flexisip_pid` 2>/dev/null
152
	killall sipp 2>/dev/null
153
	rm -f flexisip_pid
154

155 156 157 158
	LOGS=logs/"$FOLDER"_`date '+%s'`
	LOGS_TO_SAVE=$FOLDER"/*.log *.log core"
	mkdir -p $LOGS
	mv $LOGS_TO_SAVE $LOGS
159

160
	exit
161 162 163
}
set -o errtrace 
trap onexit 1 2 3 15 ERR
164

165 166
CMD_INVITE_USERS="$SIPP $PROXY -sf $FOLDER/invite$AUTH_PREFIX.xml $INV_OPTIONS"
echo -e "Start inviting users :"
167
echo $CMD_INVITE_USERS
168
$CMD_INVITE_USERS
169
RETVAL=$?
170

171 172
take_mem_shot

173
onexit