-
Notifications
You must be signed in to change notification settings - Fork 12
/
stress-test.sh
501 lines (469 loc) · 25.5 KB
/
stress-test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
#!/bin/bash
set -e
# Authors: Rodrigo Cuadra
# with Collaboration of Jose Miguel Rivera
# Date: 30-May-2023
# Support: [email protected]
#
echo -e "\n"
echo -e "\e[39m"
echo -e "************************************************************"
echo -e "* Welcome to the VitalPBX 3-4 stress test *"
echo -e "* All options are mandatory *"
echo -e "************************************************************"
filename="config.txt"
if [ -f $filename ]; then
echo -e "config file"
n=1
while read line; do
case $n in
1)
ip_local=$line
;;
2)
ip_remote=$line
;;
3)
ssh_remote_port=$line
;;
4)
interface_name=$line
;;
5)
protocol=$line
;;
6)
codec=$line
;;
7)
recording=$line
;;
8)
maxcpuload=$line
;;
9)
call_step=$line
;;
10)
call_step_seconds=$line
;;
esac
n=$((n+1))
done < $filename
echo -e "IP Local....................................... > $ip_local"
echo -e "IP Remote...................................... > $ip_remote"
echo -e "SSH Remote Port (Default is 22)................ > $ssh_remote_port"
echo -e "Network Interface name (ej: eth0).............. > $interface_name"
echo -e "Protocol (1.-SIP, 2.-IAX, 3.-PJSIP)............ > $protocol"
echo -e "Codec (1.-None, 2.-G79, 3.- GSM)............... > $codec"
echo -e "Recording Calls (yes,no)....................... > $recording"
echo -e "Max CPU Load (Recommended 75%)................. > $maxcpuload"
echo -e "Calls Step (Recommended 5-100)................. > $call_step"
echo -e "Seconds between each step (Recommended 5-30)... > $call_step_seconds"
fi
while [[ $ip_local == '' ]]
do
read -p "IP Local....................................... > " ip_local
done
while [[ $ip_remote == '' ]]
do
read -p "IP Remote...................................... > " ip_remote
done
while [[ $ssh_remote_port == '' ]]
do
read -p "SSH Remote Port (Default is 22)................ > " ssh_remote_port
done
while [[ $interface_name == '' ]]
do
read -p "Network Interface name (ej: eth0).............. > " interface_name
done
while [[ $protocol == '' ]]
do
read -p "Protocol (1.-SIP, 2.-IAX, 3.-PJSIP)............ > " protocol
done
while [[ $codec == '' ]]
do
read -p "Codec (1.-None, 2.-G79, 3.- GSM)............... > " codec
done
while [[ $recording == '' ]]
do
read -p "Recording Calls (yes,no)....................... > " recording
done
while [[ $maxcpuload == '' ]]
do
read -p "Max CPU Load (Recommended 75%)................. > " maxcpuload
done
while [[ $call_step == '' ]]
do
read -p "Calls Step (Recommended 5-100)................. > " call_step
done
while [[ $call_step_seconds == '' ]]
do
read -p "Seconds between each step (Recommended 5-30)... > " call_step_seconds
done
echo -e "************************************************************"
echo -e "* Check Information *"
echo -e "* Make sure that both server have communication *"
echo -e "************************************************************"
while [[ $veryfy_info != yes && $veryfy_info != no ]]
do
read -p "Are you sure to continue with this settings? (yes,no) > " veryfy_info
done
if [ "$veryfy_info" = yes ] ;then
echo -e "************************************************************"
echo -e "* Starting to run the scripts *"
echo -e "************************************************************"
else
while [[ $ip_local == '' ]]
do
read -p "IP Local....................................... > " ip_local
done
while [[ $ip_remote == '' ]]
do
read -p "IP Remote...................................... > " ip_remote
done
while [[ $ssh_remote_port == '' ]]
do
read -p "SSH Remote Port (Default is 22)................. > " ssh_remote_port
done
while [[ $interface_name == '' ]]
do
read -p "Network Interface name (ej: eth0).............. > " interface_name
done
while [[ $protocol == '' ]]
do
read -p "Protocol (1.-SIP, 2.-IAX, 3.-PJSIP............. > " protocol
done
while [[ $codec == '' ]]
do
read -p "Codec (1.-None, 2.-G79, 3.- GSM................ > " codec
done
while [[ $recording == '' ]]
do
read -p "Recording Calls (yes,no)....................... > " recording
done
while [[ $maxcpuload == '' ]]
do
read -p "Max CPU Load (Recommended 75%).................. > " maxcpuload
done
while [[ $call_step == '' ]]
do
read -p "Calls Step (Recommended 5-100)................. > " call_step
done
while [[ $call_step_seconds == '' ]]
do
read -p "Seconds between each step (Recommended 5-30)... > " call_step_seconds
done
fi
echo -e "$ip_local" > config.txt
echo -e "$ip_remote" >> config.txt
echo -e "$ssh_remote_port" >> config.txt
echo -e "$interface_name" >> config.txt
echo -e "$protocol" >> config.txt
echo -e "$codec" >> config.txt
echo -e "$recording" >> config.txt
echo -e "$maxcpuload" >> config.txt
echo -e "$call_step" >> config.txt
echo -e "$call_step_seconds" >> config.txt
echo -e "************************************************************"
echo -e "* Copy Authorization key to remote server *"
echo -e "************************************************************"
sshKeyFile=/root/.ssh/id_rsa
if [ ! -f $sshKeyFile ]; then
ssh-keygen -f /root/.ssh/id_rsa -t rsa -N '' >/dev/null
fi
ssh-copy-id -p $ssh_remote_port root@$ip_remote
echo -e "*** Done ***"
echo -e "************************************************************"
echo -e "* Creating Asterisk config files *"
echo -e "************************************************************"
echo -e "[call-test-ext]" > /etc/asterisk/vitalpbx/extensions__60-call-test.conf
echo -e "exten => _200,1,NoOp(Outgoing Call)" >> /etc/asterisk/vitalpbx/extensions__60-call-test.conf
if [ "$cdrs" != yes ] ;then
echo -e " same => n,NoCDR()" >> /etc/asterisk/vitalpbx/extensions__60-call-test.conf
fi
if [ "$recording" = yes ] ;then
echo -e " same => n,MixMonitor(/tmp/$"{UNIQUEID}".wav,ab)" >> /etc/asterisk/vitalpbx/extensions__60-call-test.conf
fi
if [ "$protocol" = 1 ] ;then
echo -e " same => n,Dial(SIP/call-test-trk/100,30,rtT)" >> /etc/asterisk/vitalpbx/extensions__60-call-test.conf
fi
if [ "$protocol" = 2 ] ;then
echo -e " same => n,Dial(IAX2/call-test-trk/100,30,rtT)" >> /etc/asterisk/vitalpbx/extensions__60-call-test.conf
fi
if [ "$protocol" = 3 ] ;then
echo -e " same => n,Dial(PJSIP/100@call-test-trk)" >> /etc/asterisk/vitalpbx/extensions__60-call-test.conf
fi
echo -e " same => n,Hangup()" >> /etc/asterisk/vitalpbx/extensions__60-call-test.conf
if [ "$protocol" = 1 ] ;then
protocol_name=SIP
rm -rf /etc/asterisk/vitalpbx/iax__60-call-test.conf
rm -rf /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
echo -e "[call-test-trk]" > /etc/asterisk/vitalpbx/sip__60-call-test.conf
echo -e "context=call-test-ext" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
echo -e "description=Call_Test" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
echo -e "host=$ip_remote" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
echo -e "port=5062" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
echo -e "type=friend" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
echo -e "transport=udp" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
echo -e "qualify=yes" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
echo -e "outbound_registration=yes" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
echo -e "auth_rejection_permanent=yes" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
echo -e "max_retries=10" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
echo -e "expiration=3600" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
echo -e "retry_interval=60" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
echo -e "forbidden_retry_interval=10" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
codec_name=NONE
if [ "$codec" = 2 ] ;then
codec_name=g729
echo -e "allow=!all,g729" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
fi
if [ "$codec" = 3 ] ;then
codec_name=gsm
echo -e "allow=!all,gsm" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
fi
fi
if [ "$protocol" = 2 ] ;then
protocol_name=IAX
rm -rf /etc/asterisk/vitalpbx/sip__60-call-test.conf
rm -rf /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
echo -e "[call-test-trk]" > /etc/asterisk/vitalpbx/iax__60-call-test.conf
echo -e "context=call-test-ext" >> /etc/asterisk/vitalpbx/iax__60-call-test.conf
echo -e "description=Call_Test" >> /etc/asterisk/vitalpbx/iax__60-call-test.conf
echo -e "host=$ip_remote" >> /etc/asterisk/vitalpbx/iax__60-call-test.conf
echo -e "type=friend" >> /etc/asterisk/vitalpbx/iax__60-call-test.conf
echo -e "transport=udp" >> /etc/asterisk/vitalpbx/iax__60-call-test.conf
echo -e "qualify=yes" >> /etc/asterisk/vitalpbx/iax__60-call-test.conf
echo -e "outbound_registration=yes" >> /etc/asterisk/vitalpbx/iax__60-call-test.conf
echo -e "auth_rejection_permanent=yes" >> /etc/asterisk/vitalpbx/iax__60-call-test.conf
echo -e "max_retries=10" >> /etc/asterisk/vitalpbx/iax__60-call-test.conf
echo -e "expiration=3600" >> /etc/asterisk/vitalpbx/iax__60-call-test.conf
echo -e "retry_interval=60" >> /etc/asterisk/vitalpbx/iax__60-call-test.conf
echo -e "forbidden_retry_interval=10" >> /etc/asterisk/vitalpbx/iax__60-call-test.conf
codec_name=NONE
if [ "$codec" = 2 ] ;then
codec_name=g729
echo -e "allow=!all,g729" >> /etc/asterisk/vitalpbx/iax__60-call-test.conf
fi
if [ "$codec" = 3 ] ;then
codec_name=gsm
echo -e "allow=!all,gsm" >> /etc/asterisk/vitalpbx/iax__60-call-test.conf
fi
fi
if [ "$protocol" = 3 ] ;then
protocol_name=PJSIP
rm -rf /etc/asterisk/vitalpbx/sip__60-call-test.conf
rm -rf /etc/asterisk/vitalpbx/iax__60-call-test.conf
echo -e "[call-test-trk](p1)" > /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
echo -e "type=endpoint" >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
echo -e "dtmf_mode=rfc4733" >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
echo -e "context=call-test-ext" >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
if [ "$codec" = 1 ] ;then
codec_name=NONE
echo -e "allow=!all,ulaw,alaw" >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
fi
if [ "$codec" = 2 ] ;then
codec_name=g729
echo -e "allow=!all,g729" >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
fi
if [ "$codec" = 3 ] ;then
codec_name=gsm
echo -e "allow=!all,gsm" >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
fi
echo -e "language=en" >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
echo -e "aors=call-test-trk" >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
echo -e "trust_id_inbound=no" >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
echo -e "trust_id_outbound=no" >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
echo -e "" >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
echo -e "[call-test-trk](p1-aor)" >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
echo -e "type=aor" >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
echo -e "max_contacts=2" >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
echo -e "contact=sip:call-test-trk@$ip_remote:5060" >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
echo -e "qualify_frequency=30" >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
echo -e "qualify_timeout=3" >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
echo -e "" >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
echo -e "[call-test-trk]" >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
echo -e "type=identify" >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
echo -e "endpoint=call-test-trk" >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
echo -e "match=@$ip_remote" >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf
fi
ssh -p $ssh_remote_port root@$ip_remote "echo -e '[call-test-ext]' > /etc/asterisk/vitalpbx/extensions__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote "echo -e 'exten => _100,1,Answer()' >> /etc/asterisk/vitalpbx/extensions__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote "echo -e ' same => n,NoCDR()' >> /etc/asterisk/vitalpbx/extensions__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote "echo -e ' same => n(begin),Wait(1)' >> /etc/asterisk/vitalpbx/extensions__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote "echo -e ' same => n,Playback(demo-instruct&silence/10)' >> /etc/asterisk/vitalpbx/extensions__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote "echo -e ' same => n,Goto(begin)' >> /etc/asterisk/vitalpbx/extensions__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote "echo -e ' same => n,Hangup()' >> /etc/asterisk/vitalpbx/extensions__60-call-test.conf"
if [ "$protocol" = 1 ] ;then
ssh -p $ssh_remote_port root@$ip_remote "rm -rf /etc/asterisk/vitalpbx/iax__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote "rm -rf /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e '[call-test-trk]' > /etc/asterisk/vitalpbx/sip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'context=call-test-ext' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'description=Call_Test' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'host=$ip_local' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'port=5062' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'type=friend' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'transport=udp' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'qualify=yes' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'outbound_registration=yes' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'auth_rejection_permanent=yes' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'max_retries=10' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'expiration=3600' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'retry_interval=60' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'forbidden_retry_interval=10' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
if [ "$codec" = 2 ] ;then
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'allow=!all,g729' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
fi
if [ "$codec" = 3 ] ;then
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'allow=!all,gsm' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
fi
fi
if [ "$protocol" = 2 ] ;then
ssh -p $ssh_remote_port root@$ip_remote "rm -rf /etc/asterisk/vitalpbx/sip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote "rm -rf /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e '[call-test-trk]' > /etc/asterisk/vitalpbx/iax__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'context=call-test-ext' >> /etc/asterisk/vitalpbx/iax__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'description=Call_Test' >> /etc/asterisk/vitalpbx/iax__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'host=$ip_local' >> /etc/asterisk/vitalpbx/iax__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'type=friend' >> /etc/asterisk/vitalpbx/iax__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'transport=udp' >> /etc/asterisk/vitalpbx/iax__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'qualify=yes' >> /etc/asterisk/vitalpbx/iax__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'outbound_registration=yes' >> /etc/asterisk/vitalpbx/iax__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'auth_rejection_permanent=yes' >> /etc/asterisk/vitalpbx/iax__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'max_retries=10' >> /etc/asterisk/vitalpbx/iax__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'expiration=3600' >> /etc/asterisk/vitalpbx/iax__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'retry_interval=60' >> /etc/asterisk/vitalpbx/iax__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'forbidden_retry_interval=10' >> /etc/asterisk/vitalpbx/iax__60-call-test.conf"
if [ "$codec" = 2 ] ;then
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'allow=!all,g729' >> /etc/asterisk/vitalpbx/iax__60-call-test.conf"
fi
if [ "$codec" = 3 ] ;then
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'allow=!all,gsm' >> /etc/asterisk/vitalpbx/iax__60-call-test.conf"
fi
fi
if [ "$protocol" = 3 ] ;then
ssh -p $ssh_remote_port root@$ip_remote "rm -rf /etc/asterisk/vitalpbx/sip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote "rm -rf /etc/asterisk/vitalpbx/iax__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e '[call-test-trk](p1)' > /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'type=endpoint' >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'dtmf_mode=rfc4733' >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'context=call-test-ext' >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
if [ "$codec" = 1 ] ;then
codec_name=NONE
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'allow=!all,ulaw,alaw' >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
fi
if [ "$codec" = 2 ] ;then
codec_name=g729
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'allow=!all,g729' >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
fi
if [ "$codec" = 3 ] ;then
codec_name=gsm
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'allow=!all,gsm' >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
fi
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'language=en' >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'aors=call-test-trk' >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'trust_id_inbound=no' >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'trust_id_outbound=no' >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e '' >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e '[call-test-trk](p1-aor)' >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'type=aor' >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'max_contacts=2' >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'contact=sip:call-test-trk@$ip_local:5060' >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'qualify_frequency=30' >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'qualify_timeout=3' >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e '' >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e '[call-test-trk]' >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'type=identify' >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'endpoint=call-test-trk' >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
ssh -p $ssh_remote_port root@$ip_remote " echo -e 'match=$ip_local' >> /etc/asterisk/vitalpbx/pjsip__60-call-test.conf"
fi
systemctl restart asterisk
ssh -p $ssh_remote_port root@$ip_remote "systemctl restart asterisk"
echo -e "*** Done ***"
echo -e " **************************************************************************************"
echo -e " * Restarting Asterisk in both Server *"
echo -e " **************************************************************************************"
sleep 10
numcores=`nproc --all`
exitcalls=false
i=0
step=0
clear
echo -e " ************************************************************************************************"
echo -e " Actual Test State (Step: "$call_step_seconds"s, Core: "$numcores", Protocol: "$protocol_name", Codec: "$codec_name", Recording: "$recording") "
echo -e " ************************************************************************************************"
echo -e " ------------------------------------------------------------------------------------------------"
printf "%2s %7s %10s %16s %10s %10s %10s %12s %12s\n" "|" " Step |" "Calls |" "Asterisk Calls |" "CPU Load |" "Load |" "Memory |" "BW TX kb/s |" "BW RX kb/s |"
R1=`cat /sys/class/net/"$interface_name"/statistics/rx_bytes`
T1=`cat /sys/class/net/"$interface_name"/statistics/tx_bytes`
date1=$(date +"%s")
slepcall=$(printf %.2f "$((1000000000 * call_step_seconds / call_step))e-9")
sleep 1
echo -e "calls, active calls, cpu load (%), memory (%), bwtx (kb/s), bwrx(kb/s), interval(seg)" > data.csv
while [ $exitcalls = 'false' ]
do
R2=`cat /sys/class/net/"$interface_name"/statistics/rx_bytes`
T2=`cat /sys/class/net/"$interface_name"/statistics/tx_bytes`
date2=$(date +"%s")
diff=$(($date2-$date1))
seconds="$(($diff % 60))"
T2=`expr $T2 + 128`
R2=`expr $R2 + 128`
TBPS=`expr $T2 - $T1`
RBPS=`expr $R2 - $R1`
TKBPS=`expr $TBPS / 128`
RKBPS=`expr $RBPS / 128`
bwtx="$((TKBPS/seconds))"
bwrx="$((RKBPS/seconds))"
activecalls=`asterisk -rx "core show calls" | grep "active" | cut -d' ' -f1`
load=`cat /proc/loadavg | awk '{print $0}' | cut -d " " -f 1`
cpu=`top -n 1 | awk 'FNR > 7 {s+=$10} END {print s}'`
cpuint=${cpu%.*}
cpu="$((cpuint/numcores))"
memory=`free | awk '/Mem/{printf("%.2f%"), $3/$2*100} /buffers\/cache/{printf(", buffers: %.2f%"), $4/($3+$4)*100}'`
if [ "$cpu" -le 34 ] ;then
echo -e "\e[92m ------------------------------------------------------------------------------------------------"
fi
if [ "$cpu" -ge 35 ] && [ "$cpu" -lt 65 ] ;then
echo -e "\e[93m ------------------------------------------------------------------------------------------------"
fi
if [ "$cpu" -ge 65 ] ;then
echo -e "\e[91m ------------------------------------------------------------------------------------------------"
fi
printf "%2s %7s %10s %16s %10s %10s %10s %12s %12s\n" "|" " "$step" |" ""$i" |" ""$activecalls" |" ""$cpu"% |" ""$load" |" ""$memory" |" ""$bwtx" |" ""$bwrx" |"
echo -e "$i, $activecalls, $cpu, $load, $memory, $bwtx, $bwrx, $seconds" >> data.csv
exitstep=false
x=1
while [ $exitstep = 'false' ]
do
let x=x+1
if [ "$call_step" -lt $x ] ;then
exitstep=true
fi
asterisk -rx"channel originate Local/200@call-test-ext application Playback demo-instruct&demo-instruct&demo-instruct&demo-instruct&demo-instruct&demo-instruct&demo-instruct&demo-instruct&demo-instruct&demo-instruct&demo-instruct&demo-instruct&demo-instruct&demo-instruct&demo-instruct&demo-instruct&demo-instruct&demo-instruct&demo-instruct&demo-instruct"
sleep "$slepcall"
done
let step=step+1
let i=i+"$call_step"
if [ "$cpu" -gt "$maxcpuload" ] ;then
exitcalls=true
fi
R1=`cat /sys/class/net/"$interface_name"/statistics/rx_bytes`
T1=`cat /sys/class/net/"$interface_name"/statistics/tx_bytes`
date1=$(date +"%s")
# sleep "$call_step_seconds"
sleep 1
done
echo -e "\e[39m ------------------------------------------------------------------------------------------------"
echo -e " ************************************************************************************************"
echo -e " * Restarting Asterisk *"
echo -e " ************************************************************************************************"
rm -rf /etc/asterisk/vitalpbx/asterisk__60-max-load.conf
systemctl restart asterisk
ssh -p $ssh_remote_port root@$ip_remote "systemctl restart asterisk"
rm -rf /tmp/*.wav
echo -e " ************************************************************************************************"
echo -e " * Test Complete *"
echo -e " * Result in data.csv file *"
echo -e " ************************************************************************************************"
echo -e "\e[39m"