b818a789437e7f9ac1d9d07532cb0ec3bb4583d1
[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   for conn in `seq 1 $MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE | tac`
61   do
62     instances=$(ceil $max_connections $conn)
63     echo -n -e "\t$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   instances__dflt=$(ceil $max_connections $MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE)
71   echo "Input the desired number of ADML instances [$instances__dflt]:"
72   echo " (more than $instances instances, implies 1 single connection/instance)"
73   read G_ADML_INSTANCES
74   [ -z "$G_ADML_INSTANCES" ] && G_ADML_INSTANCES=$instances__dflt
75   [ $G_ADML_INSTANCES -lt 1 ] && G_ADML_INSTANCES=1
76   G_ADML_CONNECTIONS=$(ceil $max_connections $G_ADML_INSTANCES)
77   if [ $G_ADML_CONNECTIONS -gt $MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE ]
78   then
79     echo "Warning: the number of connections per ADML instance ($G_ADML_CONNECTIONS) is greater"
80     echo "         than the maximum suggested: $MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE"
81     echo
82     echo "Press ENTER to continue, CTRL-C to abort ..."
83     read dummy
84   fi
85   client_connections=$((G_ADML_INSTANCES*G_ADML_CONNECTIONS))
86   if [ $client_connections -gt $max_server_accepted_connections ]
87   then
88     echo
89     echo "Insufficient server connections available ($max_server_accepted_connections) to accept"
90     echo " launcher client connections: $G_ADML_INSTANCES x $G_ADML_CONNECTIONS = $client_connections."
91     _exit "Configuration error"
92   fi
93 }
94
95 #############
96 # EXECUTION #
97 #############
98
99 cd `dirname $0`
100
101 echo
102 echo "====================================="
103 echo "ADML SYSTEM TEST CONFIGURATION WIZARD"
104 echo "====================================="
105 echo
106 if [ -d ADMLS ]
107 then
108   echo
109   echo "Detected configured layout (*):"
110   echo
111   ADML_INSTANCES=`cat $ADML_INSTANCES__ST_CONF_FILE 2>/dev/null`
112   ADML_CONNECTIONS=`cat $ADML_CONNECTIONS__ST_CONF_FILE 2>/dev/null`
113   RATE_PER_INSTANCE=`cat $ADML_RATE_PER_INSTANCE__ST_CONF_FILE 2>/dev/null`
114   DESIRED_RATE=`cat $ADML_DESIRED_RATE__ST_CONF_FILE 2>/dev/null`
115   REPEATS=`cat $CYCLE_REPEATS__ST_CONF_FILE 2>/dev/null`
116   N_TESTCASES=`cat $N_TESTCASES__ST_CONF_FILE 2>/dev/null`
117
118   [ -n "$ADML_INSTANCES" ] && echo "  $ADML_INSTANCES ADML instances."
119   [ -n "$ADML_CONNECTIONS" ] && echo "  $ADML_CONNECTIONS connections per ADML instance."
120   [ -n "$RATE_PER_INSTANCE" ] && echo "  Rate of $RATE_PER_INSTANCE TCs/second and instance."
121   [ -n "$DESIRED_RATE" ] && echo "  Desired rate was: $DESIRED_RATE TCs/second and instance."
122   [ -n "$REPEATS" ] && echo "  Number of cycles: $((REPEATS + 1))."
123   [ -n "$N_TESTCASES" ] && echo "  $N_TESTCASES test cases programmed."
124   echo
125   operation_result=$(echo "scale=3 ; (1 + $REPEATS) * $N_TESTCASES / $ADML_INSTANCES / $RATE_PER_INSTANCE" | bc)
126   echo "  Time covered: $((REPEATS + 1)) cycles x ($N_TESTCASES/(${ADML_INSTANCES}x${RATE_PER_INSTANCE})) = $operation_result seconds"
127   echo
128
129   echo "  (*) As ADMLS directory still exists you should move/remove it to continue."
130   echo "      You may have to 'pkill ADML' before (resources busy)."
131   _exit
132 fi
133
134 [ ! -d services ] && _exit "Missing services configuration (expecting '$PWD/services' directory) !"
135
136 calculate_deployment_layout
137
138 # Dump persintently:
139 echo $G_ADML_INSTANCES > $ADML_INSTANCES__ST_CONF_FILE
140 echo $G_ADML_CONNECTIONS > $ADML_CONNECTIONS__ST_CONF_FILE
141
142 # Rate per instance:
143 #rate_per_instance=$(ceil $desired_rate $G_ADML_INSTANCES)
144 rate_per_instance=$((desired_rate/$G_ADML_INSTANCES))
145 [ $rate_per_instance -lt 1 ] && rate_per_instance=1
146 echo $rate_per_instance > $ADML_RATE_PER_INSTANCE__ST_CONF_FILE
147 echo $desired_rate > $ADML_DESIRED_RATE__ST_CONF_FILE
148
149 echo
150 echo "Layout:"
151 echo
152 echo " - $G_ADML_INSTANCES ADML instances"
153 echo " - $G_ADML_CONNECTIONS client connections per ADML instance"
154 #maximum_rate_1c=$((G_ADML_INSTANCES*MAXIMUM_ADML_ASYNC_RATE))
155 maximum_rate=$((G_ADML_INSTANCES*G_ADML_CONNECTIONS*MAXIMUM_ADML_ASYNC_RATE))
156 overcommit_rate_per_instance=$((G_ADML_CONNECTIONS*MAXIMUM_ADML_ASYNC_RATE))
157 echo
158 echo " - Desired rate: $desired_rate test cases per second:"
159 echo "   Remember the command to send the needed rate per instance ($rate_per_instance TCs/sec):"
160 echo "       ./operation.sh \"test|ttps|$rate_per_instance\""
161 echo
162 if [ $maximum_rate -ne $desired_rate ]
163 then
164   echo " - Maximum bunch rate ($G_ADML_CONNECTIONS connections per instance): $maximum_rate testcases/second"
165   echo "   For this, configure instances rate to $overcommit_rate_per_instance test cases per second:"
166   echo "       ./operation.sh \"test|ttps|$overcommit_rate_per_instance\""
167   echo
168 fi
169 echo "Usually, you will program a test case per subscriber."
170 echo "Input the number of test cases to program:"
171 read N_TESTCASES
172 while [ -z "$N_TESTCASES" ]; do read N_TESTCASES; done
173 echo $N_TESTCASES > $N_TESTCASES__ST_CONF_FILE
174 testcase_per_adml_instance=$N_TESTCASES
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_1=$(ceil $N_TESTCASES $desired_rate)
181 time_covered=$(ceil $N_TESTCASES $((desired_rate*G_ADML_INSTANCES)))
182 echo "That amount covers $time_covered_1 seconds for one running ADML instance."
183 if [ $G_ADML_INSTANCES -gt 1 ]
184 then
185   echo "But you will have $G_ADML_INSTANCES instances running in parallel, then the total covered time is: $time_covered seconds"
186   testcase_per_adml_instance=$((N_TESTCASES/G_ADML_INSTANCES))
187   echo "(aproximately, $testcase_per_adml_instance test cases will be programmed on each ADML instance)"
188 fi
189
190 0>$N_TESTCASES_PROGRAM_LAYOUT__ST_CONF_FILE
191 for instance in `seq 1 $G_ADML_INSTANCES`
192 do
193   offset=$((testcase_per_adml_instance * (instance-1)))
194   ini=$((offset + first_value))
195   fin=$((offset + first_value + testcase_per_adml_instance - 1))
196   echo "$instance $ini $fin" >> $N_TESTCASES_PROGRAM_LAYOUT__ST_CONF_FILE
197 done
198
199 echo
200 if [ $time_covered -lt 300 ]
201 then
202   echo "$time_covered seconds is under 5 minutes, you should add more test cases to the pool except if you are sure"
203   echo " they will take less time that cycle completion. You could ensure that with a first timeout step."
204   echo "Configuring such timeout slightly under $((1000*time_covered)) milliseconds, you could repeat the cycle safely to"
205   echo " obtain a greater total time of testing."
206 fi
207 echo
208 echo "How many total time you need to cover (in minutes):"
209 read minutes
210 while [ -z "$minutes" ]; do read minutes; done
211 seconds=$((minutes*60))
212 repeats=$(ceil $seconds $time_covered)
213 if [ $repeats -gt 0 ]
214 then
215   echo "You will need $repeats cycles to cover $minutes minutes."
216   echo "Input the number of cyles [$repeats]: "
217   echo " (providing 0, you will cover $time_covered seconds)"
218   echo
219   read wanted_repeats
220   [ -z "$wanted_repeats" ] && wanted_repeats=$repeats
221   echo $wanted_repeats > $CYCLE_REPEATS__ST_CONF_FILE
222   [ $wanted_repeats -gt 0 ] && echo "Configured $wanted_repeats cycle repeats ($((wanted_repeats+1)) x $time_covered seconds ~ $(((wanted_repeats+1)*time_covered)) seconds of testing)."
223 fi
224 echo
225 echo "System test configuration completed."
226 echo
227 echo "Ready to clone/start the ADML instances: press ENTER to continue, CTRL+C to abort ..."
228 read dummy
229
230 # Update services.xml regarding the number of client connections:
231 cd services 
232 cp services.msk services.xml
233 sed -i 's/__CLIENT_CONNECTIONS__/'$G_ADML_CONNECTIONS'/g' services.xml
234 cd - >/dev/null
235
236
237 for instance in `seq 1 $G_ADML_INSTANCES`
238 do
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-launcher 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
258 echo "Done!"
259