b05b6e076f8ae9e0aefe8fb119281cc8b4e877e8
[anna.git] / example / diameter / launcher / deployments / advanced / burst.sh
1 #!/bin/bash
2 > curl_log.txt
3 TRACE="--trace-ascii curl_log.txt"
4 SERVER=`cat .httpServer`
5 burstMargin__dflt=1
6
7 salir () {
8    echo
9    echo $1
10    echo
11    exit
12 }
13
14 calc () { echo "$1" | bc -l ; }
15
16 entero () {
17    limpio=$(calc "scale=0;${1}/1")
18    [[ $limpio != $1 ]] && salir "Invalid value '$1'. Must be integer"
19 }
20
21 uso () {
22
23    echo "Load tests configuration script"
24    echo
25    echo "Use: $0 <action: clear | load | start | push | pop | stop | resume | repeat | send | goto | look> [action parameters]"
26    echo
27    echo "     clear:"
28    echo "        Clears all loaded burst messages."
29    echo
30    echo "     load <amount> <traffic type: mms | sms | voice | data | content>:"
31    echo "        Loads 'amount' messages for the provided traffic type. For example:"
32    echo "           $0 load 2000 sms"
33    echo
34    echo "     start [initial launch: default $burstMargin__dflt]:"
35    echo "        Starts the message sending from the begining of the burst list loaded,"
36    echo "        with a certain initial load. For example:"
37    echo "           $0 start 200"
38    echo
39    echo "     push [amount: default $burstMargin__dflt]:"
40    echo "        Launch 'amount' messages as initial load does (non-asynchronous mode)."
41    echo "        It works even if burst launch is stopped. Useful to achieve congestion"
42    echo "        conditions. For example:"
43    echo "           $0 push 300"
44    echo
45    echo "     pop [amount: default $burstMargin__dflt]:"
46    echo "        Skip send burst messages in order to reduce over-the-air requests."
47    echo
48    echo "     stop:"
49    echo "        Stops the burst cycle at the current position. It could affect sessions"
50    echo "        on the air (i.e. data contexts). Totally safe for IEC scenaries as SMS."
51    echo
52    echo "     resume:"
53    echo "        Resume an stopped burst launch from the same point (start will reset"
54    echo "        the work pointer to the first burst list position). This is equivalent" 
55    echo "        to one-message-push operation."
56    echo
57    echo "     repeat [[yes] | no]:"
58    echo "        Restarts the burst launch cycle when finished."
59    echo
60    echo "     send [amount: default 1]:"
61    echo "        send messages from burst list. The main difference with start/push operations"
62    echo "        is that burst won't be awaken. Externally we could control sending time (no"
63    echo "        request will be sent for answers). When reach the last position, starts again."
64    echo
65    echo "     sendXS <requests per second> [amount: default -1 (no limit)]:"
66    echo "        send messages from burst list with the TPS provided. User could hot change"
67    echo "        speed by mean 'echo <TPS> > .tps' at another shell. You can stop the load"
68    echo "        removing that hidden file or using CTRL+C from the shell where you launched"
69    echo "        the burst command. Real tps is dumped on '.real_tps' file during testing."
70    echo "        You could limit the amount of messages sent by mean the second parameter."
71    echo "        No limit is established by default (-1 or negative value)."
72    echo
73    echo "     goto <order>:"
74    echo "        Updates current burst pointer position."
75    echo
76    echo "     look <order>:"
77    echo "        Show programmed burst message for order provided."
78    echo
79    echo
80    salir 
81 }
82
83 _curl () {
84    curl -m 5 --data "$1" $TRACE ${SERVER}
85 }
86
87 echo
88 echo
89 [[ "$1" = "" ]] && uso
90 case $1 in
91    clear) _curl "burst|clear"
92    ;;
93    load) [[ "$3" = "" ]] && uso
94          [[ ! -f "${3}.sh" ]] && salir "Burst generation file '${3}.sh' not found!"
95          entero $2
96          if test "$3" = "data"
97          then
98             count=$2
99             RESTO=$((count%4))
100             [[ "$RESTO" != "0" ]] && salir "Data context should load a multiple of 4 (messages generated by data.sh)" 
101          fi
102          count=1
103          while test "$count" -le "$2"
104          do
105             ${3}.sh $count > .${3}.xml
106             echo -n "Loading message ${count}; "
107             _curl "burst|load|.${3}.xml"
108             count=$((count+1))
109          done
110    ;;
111    start) load=$burstMargin__dflt
112           [[ "$2" != "" ]] && load=$2
113           entero $load
114           _curl "burst|start|$load"
115    ;;
116    pop) release=$burstMargin__dflt
117           [[ "$2" != "" ]] && release=$2
118           entero $release
119           _curl "burst|pop|$release"
120    ;;
121    push) [[ "$2" = "" ]] && uso
122          entero $2
123          _curl "burst|push|$2"
124    ;;
125    stop) _curl "burst|stop"
126    ;;
127    resume) _curl "burst|push|1"
128    ;;
129    repeat) repeat=yes
130           [[ "$2" != "" ]] && repeat=$2
131           _curl "burst|repeat|$repeat"
132    ;;
133    send) amount=1
134          [[ "$2" != "" ]] && amount=$2
135          entero $amount
136          _curl "burst|send|$amount"
137    ;;
138    sendXS) [[ "$2" = "" ]] && uso
139          limit=$3
140          [[ "$limit" = "" ]] && limit=-1
141          entero $2
142          entero $limit
143          TPS=0
144          count=0
145          amount=1
146          echo $2 > .tps
147          while test -f .tps
148          do
149             [[ "$count" = "$limit" ]] && break
150             BEFORE_ns=`date +%s%N`
151             READ_TPS=`cat .tps`
152             # Hot change could make .tps still unavailable:
153             [[ "$READ_TPS" = "" ]] && READ_TPS=$TPS
154             # Volvemos a calcular medias (REAL_TPS) cada 10 segundos o cuando cambia el TPS en caliente:
155             [[ "$READ_TPS" != "$TPS" ]] && { BEGIN_ns=$BEFORE_ns ; count=0 ; }
156             [[ $count = $((10*TPS)) ]] && { BEGIN_ns=$BEFORE_ns ; count=0 ; }
157             TPS=$READ_TPS
158             [[ "$TPS" = "0" ]] && salir "Test stopped due to 0-tps value read"
159             # Background:
160             _curl "burst|send|$amount" &
161             count=$((count+amount))
162             AFTER_ns=`date +%s%N`
163             # Real tps:
164             REAL_TPS=$(calc "1000000000 * $count / ($AFTER_ns - $BEGIN_ns)")
165             echo $REAL_TPS > .real_tps
166             
167             COEF=1
168             [[ $(calc "$TPS > $REAL_TPS") = "1" ]] && COEF=$(calc "$REAL_TPS / $TPS")
169             K=$(calc "$COEF ^ 10")
170             amount=$(calc "scale=0;1/$K")
171             usleep $(calc "$K * 1000000/$TPS")
172          done
173    ;;
174    goto) [[ "$2" = "" ]] && uso
175          entero $2
176          _curl "burst|goto|$2"
177    ;;
178    look) [[ "$2" = "" ]] && uso
179          entero $2
180          _curl "burst|look|$2"
181    ;;
182    *) uso
183 esac
184