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