Support for Multiple Peer deployments. Support for coexisting several ADMLS instances...
[anna.git] / example / diameter / launcher / deployments / st-client / configure.sh
1 #!/bin/bash
2
3 #############
4 # VARIABLES #
5 #############
6 CWD=$(dirname $0)
7 MAXIMUM_ADML_ASYNC_RATE=50
8 MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE=10
9 ADML_INSTANCES__ST_CONF_FILE=.st_conf_adml_instances
10 ADML_CONNECTIONS__ST_CONF_FILE=.st_conf_adml_connections
11 CYCLE_REPEATS__ST_CONF_FILE=.st_conf_cycle_repeats
12 N_TESTCASES__ST_CONF_FILE=.st_conf_n_testcases
13 ADML_RATE_PER_INSTANCE__ST_CONF_FILE=.st_conf_rate_per_instance
14 ADML_DESIRED_RATE__ST_CONF_FILE=.st_conf_desired_rate
15 N_TESTCASES_PROGRAM_LAYOUT__ST_CONF_FILE=.st_conf_n_testcases_program_layout
16
17 #############
18 # FUNCTIONS #
19 #############
20 _exit () {
21   echo -e "\n$1\n"
22
23   # Cleanup:
24   cd $CWD
25   rm -rf ADMLS.tmp
26   cd services
27   rm -f cer*.xml services.xml *.msk2
28  
29   rc=1
30   [ -n "$2" ] && rc=$2 
31   exit $rc
32 }
33
34 sig_handler () {
35   _exit "Script interrupted. Cleanup & exit ..."
36 }
37
38 # ceil of division $1/$2
39 ceil() {
40   #echo "$1 $2" | awk '{print int( ($1/$2) + 1 )}'
41   awk -vnumber="$1" -vdiv="$2" '
42   function ceiling(x){return x%1 ? int(x)+1 : x}
43   BEGIN{ print ceiling(number/div) }'
44 }
45
46 # Calculates the number of ADML instances and their client connections
47 calculate_deployment_layout() {
48   echo "Input the maximum client connections accepted by the server to be tested [5000]:"
49   read max_server_accepted_connections
50   [ "$max_server_accepted_connections" = "" ] && max_server_accepted_connections=5000
51
52   echo "Input the maximum desired test case rate per second:"
53   read desired_rate
54   while [ -z "$desired_rate" ]; do read desired_rate; done
55
56   max_connections=$((desired_rate/MAXIMUM_ADML_ASYNC_RATE))
57   if [ $max_connections -eq 0 ]
58   then
59     G_ADML_CONNECTIONS=1
60     G_ADML_INSTANCES=1
61     return
62   elif [ $max_connections -gt $max_server_accepted_connections ]
63   then
64     _exit "Not enough server connections to fit the desired rate (requires $max_connections connections)."
65   fi
66
67   echo
68   echo "==========================================================================================================="
69   echo "Orientative table"
70   echo "-----------------------------------------------------------------------------------------------------------"
71   echo -n "Number of instances:  "
72   instances__dflt=$(ceil $max_connections $MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE)
73   for conn in `seq 1 $MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE | tac`
74   do
75     instances=$(ceil $max_connections $conn)
76     echo -n -e "\t$instances"
77     [ $conn -eq 1 ] && instances__dflt=$instances
78   done
79   echo
80   echo -e "Connects per instance:\t10\t9\t8\t7\t6\t5\t4\t3\t2\t1"
81   echo "==========================================================================================================="
82   echo
83   #echo "Input selection (connections per instance 1..$MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE) [1]:"
84   echo "Input the desired number of ADML instances [$instances__dflt]:"
85   echo " (more than $instances instances, implies 1 single connection/instance)"
86   read G_ADML_INSTANCES
87   [ -z "$G_ADML_INSTANCES" ] && G_ADML_INSTANCES=$instances__dflt
88   [ $G_ADML_INSTANCES -lt 1 ] && G_ADML_INSTANCES=1
89   G_ADML_CONNECTIONS=$(ceil $max_connections $G_ADML_INSTANCES)
90   if [ $G_ADML_CONNECTIONS -gt $MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE ]
91   then
92     echo "Warning: the number of connections per ADML instance ($G_ADML_CONNECTIONS) is greater"
93     echo "         than the maximum recommended: $MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE"
94     echo
95     echo "Press ENTER to continue, CTRL-C to abort ..."
96     read dummy
97   fi
98   client_connections=$((G_ADML_INSTANCES*G_ADML_CONNECTIONS))
99   if [ $client_connections -gt $max_server_accepted_connections ]
100   then
101     echo
102     echo "Insufficient server connections available ($max_server_accepted_connections) to accept"
103     echo " launcher client connections: $G_ADML_INSTANCES x $G_ADML_CONNECTIONS = $client_connections."
104     _exit "Configuration error"
105   fi
106 }
107
108 #############
109 # EXECUTION #
110 #############
111
112 trap sig_handler INT QUIT TERM
113
114 cd $CWD
115
116 echo
117 echo "====================================="
118 echo "ADML SYSTEM TEST CONFIGURATION WIZARD"
119 echo "====================================="
120 echo
121
122 [ ! -d services ] && _exit "Missing services configuration (expecting '$PWD/services' directory).\nTake a look to 'services_example' and './dynlibs' scenaries stuff to complete your services.\n\nFor example:\n   ln -s services_example services\n   cp dynlibs/gx/00001/services/* services\n   Edit CER files and 'services.msk' there, to fit your needs."
123
124 calculate_deployment_layout
125
126 # Format for instance number (for example: 1 -> 001, .., 45 -> 045, 300 -> 300)
127 INSTANCE_FORMAT=$(echo $G_ADML_INSTANCES | wc -c)
128 INSTANCE_FORMAT=$((INSTANCE_FORMAT-1))
129
130 # Dump persintently:
131 echo $G_ADML_INSTANCES > $ADML_INSTANCES__ST_CONF_FILE
132 echo $G_ADML_CONNECTIONS > $ADML_CONNECTIONS__ST_CONF_FILE
133
134 # Rate per instance:
135 rate_per_instance=$((desired_rate/$G_ADML_INSTANCES))
136 [ $rate_per_instance -lt 1 ] && rate_per_instance=1
137 echo $rate_per_instance > $ADML_RATE_PER_INSTANCE__ST_CONF_FILE
138 echo $desired_rate > $ADML_DESIRED_RATE__ST_CONF_FILE
139
140 echo
141 echo "Layout:"
142 echo
143 echo " - $G_ADML_INSTANCES ADML instances"
144 echo " - $G_ADML_CONNECTIONS client connections per ADML instance"
145 maximum_rate=$((G_ADML_INSTANCES*G_ADML_CONNECTIONS*MAXIMUM_ADML_ASYNC_RATE))
146 overcommit_rate_per_instance=$((G_ADML_CONNECTIONS*MAXIMUM_ADML_ASYNC_RATE))
147 echo
148 echo " - Desired rate: $desired_rate test cases per second:"
149 echo "   Remember the command to send the needed rate per instance ($rate_per_instance TCs/sec):"
150 echo "       ./operation.sh \"test|ttps|$rate_per_instance\""
151 echo
152 if [ $maximum_rate -ne $desired_rate ]
153 then
154   echo " - Maximum bunch rate ($G_ADML_CONNECTIONS connections per instance): $maximum_rate testcases/second"
155   echo "   For this, configure instances rate to $overcommit_rate_per_instance test cases per second:"
156   echo "       ./operation.sh \"test|ttps|$overcommit_rate_per_instance\""
157   echo
158 fi
159 echo "Usually, you will program a test case per subscriber."
160 echo "Input the number of test cases to program:"
161 read N_TESTCASES
162 while [ -z "$N_TESTCASES" ]; do read N_TESTCASES; done
163 echo $N_TESTCASES > $N_TESTCASES__ST_CONF_FILE
164 echo "Input the first test id to program [1]:"
165 read first_value
166 [ "$first_value" = "" ] && first_value=1
167 [ $first_value -lt 1 ] && first_value=1
168 echo
169 time_covered=$(echo "$N_TESTCASES/$desired_rate" | bc)
170 testcase_per_adml_instance=$((N_TESTCASES/G_ADML_INSTANCES))
171 echo "Aproximately, $testcase_per_adml_instance test cases will be programmed on each ADML instance (we have $G_ADML_INSTANCES instances)."
172 echo "As we shall program $N_TESTCASES test cases, the total time covered for the desired system rate of $desired_rate cps, is $time_covered seconds."
173
174 echo
175 if [ $time_covered -lt 10 ]
176 then
177   echo "$time_covered seconds is under 10 seconds, you should add more test cases to the pool except if you are sure"
178   echo " they will take less time that cycle completion. You could ensure that with a first timeout step."
179   echo "Configuring such timeout slightly under $((1000*time_covered)) milliseconds, you could repeat the cycle safely to"
180   echo " obtain a greater total time of testing."
181 fi
182 echo
183 echo "How many total time you need to cover (in minutes):"
184 read minutes
185 while [ -z "$minutes" ]; do read minutes; done
186 seconds=$((minutes*60))
187 repeats=0
188 [ $seconds -gt $time_covered -a $time_covered -gt 0 ] && { repeats=$(ceil $seconds $time_covered) ; repeats=$((repeats-1)) ; }
189 if [ $repeats -gt 0 ]
190 then
191   cycles=$((repeats+1))
192   echo "You will need $cycles cycles to cover $minutes minutes."
193   echo "Input the desired number of cycles [$cycles]: "
194   echo " (providing 1, you will cover $time_covered seconds)"
195   echo
196   read wanted_cycles
197   [ -z "$wanted_cycles" ] && wanted_cycles=$cycles
198   wanted_repeats=$((wanted_cycles-1))
199   echo $wanted_cycles > $CYCLE_REPEATS__ST_CONF_FILE
200   [ $wanted_repeats -gt 0 ] && echo "Configured $wanted_repeats cycle repeats ($wanted_cycles cycles x $time_covered seconds ~ $((wanted_cycles*time_covered)) seconds of testing)."
201 else
202   echo 0 > $CYCLE_REPEATS__ST_CONF_FILE
203 fi
204
205 # Single vs multiple peer:
206 echo
207 echo "Select [s]ingle peer or (m)ultiple peer [s]:"
208 read opt
209 peer_seq=
210 [ -z "$opt" ] && opt=s
211 [ "$opt" = "m" ] && { peer_seq=1 ; echo "Origin-Host will be sequenced for each ADML instance." ; }
212
213 echo
214 echo "System test configuration completed."
215 echo
216 echo "Ready to clone/start the ADML instances: press ENTER to continue, CTRL+C to abort ..."
217 read dummy
218
219 # Update services.xml regarding the number of client connections:
220 cd services 
221 cp services.msk services.msk2
222 for cer in $(ls cer*.msk 2>/dev/null); do cp $cer ${cer}2; done
223 cd ..
224
225 sed -i 's/__CLIENT_CONNECTIONS__/'$G_ADML_CONNECTIONS'/g' services/services.msk2
226
227 # Create instances and layout:
228 0>$N_TESTCASES_PROGRAM_LAYOUT__ST_CONF_FILE
229 for i in `seq 1 $G_ADML_INSTANCES`
230 do
231   instance=$(printf "%0${INSTANCE_FORMAT}d" $i)
232   offset=$((testcase_per_adml_instance * (i-1)))
233   ini=$((offset + first_value))
234   fin=$((offset + first_value + testcase_per_adml_instance - 1))
235   echo "$instance $ini $fin" >> $N_TESTCASES_PROGRAM_LAYOUT__ST_CONF_FILE
236
237   # Case of multiple peer:
238   sed 's/__PEER_SEQ__/'$peer_seq'/g' services/services.msk2 > services/services.xml
239   for cer in $(ls services/cer*.msk2 2>/dev/null)
240   do
241     cer_xml="${cer%.*}.xml"
242     sed 's/__PEER_SEQ__/'$peer_seq'/g' $cer > $cer_xml
243   done
244   [ -n "$peer_seq" ] && peer_seq=$((peer_seq+1))
245
246   echo "Creating ADML instance $instance ..."
247   mkdir -p ADMLS.tmp/ADML-$instance
248   cd ADMLS.tmp/ADML-$instance
249   mkdir counters
250   mkdir test-reports
251   ln -s ../../dynlibs
252   # Create resources:
253   ln -s ../../.operation-one.sh operation.sh
254   ln -s ../../pre-start.sh
255   cp ../../.run-one.sh run.sh
256   sed -i 's/^EXE=.*/EXE=ADML-'$instance'/' run.sh
257   ln -s ../../ADML ADML-$instance
258   for xml in `ls ../../services/*xml`; do cp $xml .; done
259   cd - >/dev/null
260 done
261
262 cd $CWD
263
264 # Default ADMLS name:
265 echo
266 echo "Configured layout:"
267 echo
268 ADML_INSTANCES=`cat $ADML_INSTANCES__ST_CONF_FILE 2>/dev/null`
269 ADML_CONNECTIONS=`cat $ADML_CONNECTIONS__ST_CONF_FILE 2>/dev/null`
270 RATE_PER_INSTANCE=`cat $ADML_RATE_PER_INSTANCE__ST_CONF_FILE 2>/dev/null`
271 DESIRED_RATE=`cat $ADML_DESIRED_RATE__ST_CONF_FILE 2>/dev/null`
272 REPEATS=`cat $CYCLE_REPEATS__ST_CONF_FILE 2>/dev/null`
273 N_TESTCASES=`cat $N_TESTCASES__ST_CONF_FILE 2>/dev/null`
274
275 [ -n "$ADML_INSTANCES" ] && echo "  $ADML_INSTANCES ADML instances."
276 [ -n "$ADML_CONNECTIONS" ] && echo "  $ADML_CONNECTIONS connections per ADML instance."
277 [ -n "$RATE_PER_INSTANCE" ] && echo "  Rate of $RATE_PER_INSTANCE TCs/second and instance."
278 [ -n "$DESIRED_RATE" ] && echo "  Desired rate was: $DESIRED_RATE TCs/second and instance."
279 [ -n "$REPEATS" ] && echo "  Number of cycles: $((REPEATS + 1))."
280 [ -n "$N_TESTCASES" ] && echo "  $N_TESTCASES test cases programmed."
281 echo
282 operation_result=$(echo "scale=3 ; (1 + $REPEATS) * $N_TESTCASES / $ADML_INSTANCES / $RATE_PER_INSTANCE" | bc)
283 echo "  Time covered: $((REPEATS + 1)) cycles x ($N_TESTCASES/(${ADML_INSTANCES}x${RATE_PER_INSTANCE})) = $operation_result seconds"
284 echo
285 ADMLS__dflt="ADMLS#${ADML_INSTANCES}instances.${ADML_CONNECTIONS}connectionsPerInstance"
286 if [ -n "$peer_seq" ]
287 then
288   ADMLS__dflt="${ADMLS__dflt}.MultiplePeer"
289 else
290   ADMLS__dflt="${ADMLS__dflt}.SinglePeer"
291 fi
292
293 echo
294 echo "Input a name for the ADMLS instances directory [$ADMLS__dflt]:"
295 read ADMLS_NAME
296 [ "$ADMLS_NAME" = "" ] && ADMLS_NAME=$ADMLS__dflt
297 while [ -e "$ADMLS_NAME" ]
298 do
299   ADMLS_NAME=
300   echo "Some file/directory already exists with that name ! Please, input another one:"
301   while [ -z "$ADMLS_NAME" ]; do read ADMLS_NAME; done
302 done
303
304 mv ADMLS.tmp $ADMLS_NAME
305 rm -rf ADMLS
306 ln -s $ADMLS_NAME ADMLS
307
308 echo
309 echo "Now you can run all the instances deployed: ./run.sh"
310 echo "You could provide optional target: 'run.sh <another ADMLS directory>'."
311 echo
312 echo "To configure another layout you should execute this script again."
313 echo
314 _exit "Done!" 0
315