New st-client deployment. Allow to load same stack id (accumulative services), ignori...
[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
13 #############
14 # FUNCTIONS #
15 #############
16 _exit () {
17   echo
18   echo $1
19   echo
20   exit 1
21 }
22
23 # ceil of division $1/$2
24 ceil() {
25   echo "$1 $2" | awk '{print int( ($1/$2) + 1 )}'
26 }
27
28 # Calculates the number of ADML instances and their client connections
29 calculate_deployment_layout() {
30   echo "Input the maximum client connections accepted by the server to be tested [5000]:"
31   read max_server_accepted_connections
32   [ "$max_server_accepted_connections" = "" ] && max_server_accepted_connections=5000
33
34   echo "Input the maximum test case rate per second:"
35   read desired_rate
36   while [ -z "$desired_rate" ]; do read desired_rate; done
37
38   max_connections=$((desired_rate/MAXIMUM_ADML_ASYNC_RATE))
39   if [ $max_connections -eq 0 ]
40   then
41     G_ADML_CONNECTIONS=1
42     G_ADML_INSTANCES=1
43     return
44   fi
45   max_adml_instances=$((max_server_accepted_connections/MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE))
46   if [ $max_connections -gt $max_server_accepted_connections ]
47   then
48     echo
49     echo "Maximum rate reached for $max_server_accepted_connections server connections:"
50     G_ADML_CONNECTIONS=$MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE
51     G_ADML_INSTANCES=$max_adml_instances
52     return
53   fi
54
55   echo
56   echo "==========================================================================================================="
57   echo "Orientative table"
58   echo "-----------------------------------------------------------------------------------------------------------"
59   echo -e "Connects per instance:\t1\t2\t3\t4\t5\t6\t7\t8\t9\t10"
60   echo -n "Number of instances:  "
61   for conn in `seq 1 $MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE`
62   do
63     instances=$(ceil $max_connections $conn)
64     echo -n -e "\t$instances"
65   done
66   echo
67   echo "==========================================================================================================="
68   echo
69   echo "Input selection (connections per instance 1..$MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE) [1]:"
70   read G_ADML_CONNECTIONS
71   [ -z "$G_ADML_CONNECTIONS" ] && G_ADML_CONNECTIONS=1
72   [ $G_ADML_CONNECTIONS -lt 1 ] && G_ADML_CONNECTIONS=1
73   [ $G_ADML_CONNECTIONS -gt $MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE ] && G_ADML_CONNECTIONS=$MAXIMUM_SUGGESTED_CLIENT_CONNECTION_PER_ADML_INSTANCE
74   
75   G_ADML_INSTANCES=$((max_connections/G_ADML_CONNECTIONS))
76 }
77
78 #############
79 # EXECUTION #
80 #############
81
82 cd `dirname $0`
83
84 echo
85 echo "====================================="
86 echo "ADML SYSTEM TEST CONFIGURATION WIZARD"
87 echo "====================================="
88 echo
89
90 calculate_deployment_layout
91
92 # Dump persintently:
93 echo $G_ADML_INSTANCES > $ADML_INSTANCES__ST_CONF_FILE
94 echo $G_ADML_CONNECTIONS > $ADML_CONNECTIONS__ST_CONF_FILE
95
96 echo
97 echo "Suggested layout:"
98 echo " - $G_ADML_INSTANCES ADML instances"
99 echo " - $G_ADML_CONNECTIONS client connections per ADML instance"
100 maximum_rate=$((G_ADML_INSTANCES*G_ADML_CONNECTIONS*MAXIMUM_ADML_ASYNC_RATE))
101 echo " - Maximum rate: $maximum_rate test cases per second"
102 echo
103 echo "Usually, you will program a test case per subscriber. Input the number of test cases to program:"
104 read N_TESTCASES
105 while [ -z "$N_TESTCASES" ]; do read N_TESTCASES; done
106 echo $N_TESTCASES > $N_TESTCASES__ST_CONF_FILE
107 echo
108 time_covered_1=$(ceil $N_TESTCASES $maximum_rate)
109 time_covered=$(ceil $N_TESTCASES $((maximum_rate*G_ADML_INSTANCES)))
110 echo "That amount covers $time_covered_1 seconds for one running ADML instance."
111 if [ $G_ADML_INSTANCES -gt 1 ]
112 then
113   echo "But you will have $G_ADML_INSTANCES instances running in parallel, then the total covered time is: $time_covered seconds"
114   testcase_per_adml_instance=$(ceil $N_TESTCASES $G_ADML_INSTANCES)
115   echo "(aproximately, $testcase_per_adml_instance test cases will be programmed on each ADML instance)"
116 fi
117
118 echo
119 if [ $time_covered -lt 300 ]
120 then
121   echo "$time_covered seconds is under 5 minutes, you should add more test cases to the pool except if you are sure"
122   echo " they will take less time that cycle completion. You could ensure that with a first timeout step."
123   echo "Configuring such timeout slightly under $((1000*time_covered)) milliseconds, you could repeat the cycle safely to"
124   echo " obtain a greater total time of testing."
125 fi
126 echo
127 echo "How many total time do you want to cover (in minutes):"
128 read minutes
129 while [ -z "$minutes" ]; do read minutes; done
130 seconds=$((minutes*60))
131 repeats=$(ceil $seconds $time_covered)
132 echo $repeats > $CYCLE_REPEATS__ST_CONF_FILE
133 [ $repeats -gt 0 ] && echo "Configured $repeats cycle repeats ($repeats x $time_covered seconds = $seconds seconds (desired $minutes minutes)"
134 echo
135 echo "System test configuration completed."
136 echo
137 echo "Ready to clone/start the ADML instances: press ENTER to continue, CTRL+C to abort ..."
138 read dummy
139 [ ! -d realms ] && _exit "Missing realms configuration (expecting '$PWD/realms' directory). Try with 'realms.example' and see README inside it !"
140
141 # Update services.xml regarding the number of client connections:
142 cp realms/services.msk realms/services.xml
143 sed -i 's/__CLIENT_CONNECTIONS__/'$G_ADML_CONNECTIONS'/g' realms/services.xml
144
145 rm -rf ADMLS
146 for instance in `seq 1 $G_ADML_INSTANCES`
147 do
148   mkdir -p ADMLS/$instance
149   cd ADMLS/$instance
150   # Create resources:
151   ln -s ../../ADML-launcher
152   ln -s ../../operation.sh
153   ln -s ../../realms/services.xml
154   for cer in `ls ../../realms/cer*xml`; do ln -s $cer; done
155   cd - >/dev/null
156 done
157