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