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