Bulk Call Generation Using Asterisk

Business PBX Solutions
Provider Solution Details
3CX Software PBX for Windows
  • Windows Software Solution
  • Easy to Install and Manage
  • Auto Configures Phones & Trunks
  • Android, iOS, Windows & Mac clients
Details
Bicom VoIP Become an ITSP Now!
  • Become a serious competitor in VoIP Immediately
  • FULL Consultancy, Installation, Training & Support
  • Sell Hosted IP PBXs, Biz Lines, Call Centre
  • Turnkey Provisioning at your data center
Details
Contact Center 4PSA's VoipNow Cloud Communications Platform
  • Enjoy your custom licensing plan - Pay-As-You-Grow!
  • Your fastest go-to-market solution - from deployment to billing.
  • Professional support, training and knowledge base to help you grow your business
  • On your infrastructure or cloud-based, it's up to you.
Details
One of the ways in which Asterisk can be useful, other than by functioning as a PBX, is to provide automated testing and call generation of other VoIP systems. In a lab environment, it can be difficult to generate large numbers of calls, or calls with specific functional patterns, without spending a large sum of money on specialized equipment. Asterisk can fill this role in most (but not all) cases.

Shared here is a script that gives Asterisk the ability to function as a bulk call generator in two different forms. First, as a rapid call generator that can be setup to generate a fixed number of calls per second. Second, as a slow paced call generator which places single calls with a fixed delay between them. The script is very basic in it's form but can be easily expanded upon to include a number of additional call control options. Because it leverages the Asterisk auto-dial out feature, any options available to that feature can be used here.

One important note on performance. Just because you tell the script to generate 1,000 calls per second for the next eight hours doesn't mean it will happen. You're ultimately bound by the performance of your Asterisk installation so running this on a Pentium 3 550Mhz with 256mb of RAM will not yield stellar results. You also need to take into account the time it will take your system to generate the .call files if you're making more than a few hundred calls. I've noted in the script that you need to add about 10 seconds of startDelay for every 1,000 calls you want to make to allow time for your system to run the script.

This script is intended to be a starting point for any number of uses. You can run multiple Asterisk servers and use this script on an external system to control them all. You can tweak the script to allow you to instruct Asterisk to place calls to multiple destinations, or from multiple origins.

All the usual advice about using bash scripts applies here. Once you've created the file make sure you make it executable (chmod 755), make sure you read the internal documentation about how to configure Asterisk (nothing special but it doesn't work out of the box) and for Christ's sake make sure you're only using this script on your own systems in a test environment.


#!/bin/bash

#***************************************************************#
#                     generateCalls.sh                          #
#                  written by: Sam Rausch                       #
#                    samrausch@gmail.com                        #
#                       version 0.1                             #
#                  written October 21, 2011                     #
#***************************************************************#
#                                                               #
# assumes presence of Asterisk already configured               #
# + with a spool path at /var/spool/asterisk/outgoing           #
# + with an 'autodialer' context configured as follows          #
#                                                               #
# [autodialer]                                                  #
# exten => 100,1,Playback(some-foo-goes-here)                   #
# exten => 100,2,Wait(1)                                        #
# exten => 100,3,Playback(goodbye)                              #
# exten => 100,4,Hangup                                         #
#                                                               #
# this script has two functions                                 #
# + fast() will generate calls at a fixed $callsPerSecond rate  #
# + slow() will generate calls with a fixed $intercallDelay     #
#                                                               #
# if you find this script useful, consider dropping             #
# me a note to say thanks.  i don't want beer money             #
# and i don't have an Amazon wishlist ;-)                       #
# if you're inclined to compensate me monetarily,               #
# please make a donation to:                                    #
#                                                               #
# -= http://www.donors1.org/contribute =-                       #
#                                                               #
# this script is free to redistribute as long as                #
# everything above remains intact                               #
#                                                               #
# if you remove my name and take credit for the script          #
# rabid space cats will come to your house and                  #
# speedhump your legs until you beg for mercy...                #
# ...please don't make me send my space cats                    #
#                                                               #
#***************************************************************#

asteriskSpoolPath=/var/spool/asterisk/outgoing

#-----------------------------------------------------------------------------#
# fast ()                                                                     #
# generates .call files for use by Asterisk                                   #
# Parameters: numcalls, callingParty, calledParty, callsPerSecond, startDelay #
#-----------------------------------------------------------------------------#
fast ()
{
# prompt for values if not given on the CLI
if [ -z "$2" ]
then
  echo
  echo "<---------------------------------------------------------------------------->"
  echo "Oops, I don't know enough to place your calls."
  echo "Please tell me more about what you'd like to do"
  echo "using the following format:"
  echo
  echo "generateCalls <numCalls> <callingParty> <calledParty> <callsPerSecond> <startDelay>"
  echo
  echo "<numCalls> = total number of calls to generate"
  echo "<callingParty> = phone number originating the calls expressed as xxxxxxxxxx"
  echo "<calledParty> = phone number terminating the calls expressed as xxxxxxxxxx"
  echo "<callsPerSecond> = number of calls placed per second, if the same as
  echo "                   <numCalls> then all calls will be placed simultaneously"
  echo "<startDelay> = delay after executing script for calls to start expressed in seconds
  echo
  echo "I'll be creating your .call files in $(pwd)"
  echo "then moving them to the default Asterisk spool path"
  echo "/var/spool/asterisk/outgoing/"
  echo
  echo "If you'ld like them to go somewhere else, you'll need to"
  echo "edit this script"
  echo "<---------------------------------------------------------------------------->"
  echo 
  exit 0
else
 let numCalls=$1
 let callingParty=$2
 let calledParty=$3
 let callsPerSecond=$4
 let startDelay=$5
fi

# Output the values for visual confirmation
echo  "You want to make $numCalls calls"
echo  "You want to call from $callingParty"
echo  "You want to call to $calledParty"
echo  "You want to place $callsPerSecond calls per second"
echo  "You want to wait $startDelay seconds before the first call"
echo
echo  "Confirm Y/N?"
read confirm
if [[ "$confirm" = 'N' || "$confirm" = 'n' ]]
then
  echo
  echo "Fine :-(  Try again when you know what you want"
  exit 0
fi 

# Generate the .call files
let callsPerSecondReference=$callsPerSecond
let second=$startDelay
while [ "$numCalls" -gt 0 ]
do
  let callsPerSecond=$callsPerSecondReference
  while [ "$callsPerSecond" -gt 0 ]
  do
    echo "Channel: SIP/acmepcscf/$calledParty" > testcall$numCalls.call
    echo "CallerID: \"Autodialer\"<$callingParty>" >> testcall$numCalls.call
    echo "Context: autodialer" >> testcall$numCalls.call
    echo "Extension: 100" >> testcall$numCalls.call
    echo "Priority: 2" >> testcall$numCalls.call
    touch -r testcall$numCalls.call -d "+$second sec" testcall$numCalls.call
#    touch -t "$month$day$hour$minute.$second" testcall$numCalls.call
    let "numCalls -= 1"
    let "callsPerSecond -= 1"
  done
  let "second += 1"
done

# Move the .call files to the default Asterisk outgoing path
echo "Calls are ready, do you want to start? (Y/N)"
read bigRedButton
if [[ "$bigRedButton" = 'N' || "$bigRedButton" = 'n' ]]
then
  echo
  echo "Fine!  You never follow through with anything!"
  rm -f *.call
  exit 0
fi 
echo "Your calls will start in $startDelay seconds"
mv *.call /var/spool/asterisk/outgoing/

# Remind the user to answer their phone
echo Answer your phone!!!

# Now go away...
exit 0
}

#-----------------------------------------------------------------------------#
# slow ()                                                                     #
# generates .call files for use by Asterisk                                   #
# Parameters: numcalls, callingParty, calledParty, intercallDelay, startDelay #
#-----------------------------------------------------------------------------#
slow ()
{
# prompt for values if not given on the CLI
if [ -z "$2" ]
then
  echo
  echo "<---------------------------------------------------------------------------->"
  echo "Oops, I don't know enough to place your calls."
  echo "Please tell me more about what you'd like to do"
  echo "using the following format:"
  echo
  echo "generateCalls <numCalls> <callingParty> <calledParty> <intercallDelay> <startDelay>"
  echo
  echo "<numCalls> = total number of calls to generate"
  echo "<callingParty> = phone number originating the calls expressed as xxxxxxxxxx"
  echo "<calledParty> = phone number terminating the calls expressed as xxxxxxxxxx"
  echo "<intercallDelay> = number of seconds between calls"
  echo "<startDelay> = delay after executing script for calls to start expressed in seconds"
  echo "               You'll want to add 10 sec for every 1,000 files you want to generate"
  echo "I'll be creating your .call files in $(pwd)"
  echo "then moving them to the default Asterisk spool path"
  echo "/var/spool/asterisk/outgoing/"
  echo
  echo "If you'ld like them to go somewhere else, you'll need to"
  echo "edit this script"
  echo "<---------------------------------------------------------------------------->"
  echo 
  exit 0
else
 let numCalls=$1
 let callingParty=$2
 let calledParty=$3
 let intercallDelay=$4
 let startDelay=$5
fi

# Output the values for visual confirmation
echo  "You want to make $numCalls calls"
echo  "You want to call from $callingParty"
echo  "You want to call to $calledParty"
echo  "You want to wait $intercallDelay seconds between calls"
echo  "You want to wait $startDelay seconds before the first call"
echo
echo  "Confirm Y/N?"
read confirm
if [[ "$confirm" = 'N' || "$confirm" = 'n' ]]
then
  echo
  echo "Fine :-(  Try again when you know what you want"
  exit 0
fi 

# Generate the .call files
let second=$startDelay
while [ "$numCalls" -gt 0 ]
do
  echo "Channel: SIP/acmepcscf/$calledParty" > testcall$numCalls.call
  echo "CallerID: \"Autodialer\"<$callingParty>" >> testcall$numCalls.call
  echo "Context: autodialer" >> testcall$numCalls.call
  echo "Extension: 100" >> testcall$numCalls.call
  echo "Priority: 2" >> testcall$numCalls.call
  touch -r testcall$numCalls.call -d "+$second sec" testcall$numCalls.call
  let "numCalls -= 1"
  let second=$second+$intercallDelay
done

# Move the .call files to the default Asterisk outgoing path
echo "Calls are	ready, do you want to start? (Y/N)"
read bigRedButton
if [[ "$bigRedButton" =	'N' || "$bigRedButton" = 'n' ]]
then
  echo
  echo "Fine!  You never follow through with anything!"
  rm -f *.call
  exit 0
fi
echo "Your calls will start in $startDelay seconds"
mv *.call /var/spool/asterisk/outgoing/

# Remind the user to answer their phone
echo Answer your phone!!!

# Now go away...
exit 0
}

help ()
{
echo
echo
echo "****************************************************************"
echo
echo " this script has two functions                                  "
echo " + fast() will generate calls at a fixed callsPerSecond rate    "
echo " + slow() will generate calls with a fixed intercallDelay       "
echo                                                                
echo " if you find this script useful, consider dropping              "
echo " me a note to say thanks.  i don't want beer money              "
echo " and i don't have an Amazon wishlist ;-)                        "
echo " if you're inclined to compensate me monetarily,                "
echo " please make a donation to:                                     "
echo "                                                                "     
echo " -= http://www.donors1.org/contribute =-                        "   
echo "                                                                "  
echo " this script is free to redistribute as long as                 " 
echo " everything above remains intact                                "
echo "                                                                "
echo " if you remove my name and take credit for the script           "
echo " rabid space cats will come to your house and                   "
echo " speedhump your legs until you beg for mercy...                 "
echo " ...please don't make me send my space cats                     "
echo
echo "****************************************************************"
echo 
echo "generateCalls fast <numCalls> <callingParty> <calledParty> <callsPerSecond> <startDelay>"
echo "     numCalls       = total number of calls to generate"
echo "     callingParty   = phone number originating the calls expressed as xxxxxxxxxx"
echo "     calledParty    = phone number terminating the calls expressed as xxxxxxxxxx"
echo "     callsPerSecond = number of calls placed per second, if the same as"
echo "                      numCalls then all calls will be placed simultaneously"
echo "     startDelay     = delay after executing script for calls to start expressed in seconds"
echo
echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
echo
echo "generateCalls slow <numCalls> <callingParty> <calledParty> <intercallDelay> <startDelay>"
echo "     numCalls       = total number of calls to generate"
echo "     callingParty   = phone number originating the calls expressed as xxxxxxxxxx"
echo "     calledParty    = phone number terminating the calls expressed as xxxxxxxxxx"
echo "     intercallDelay = number of seconds between calls"
echo "     startDelay     = delay after executing script for calls to start expressed in seconds"
echo "                      You'll want to add 10 sec for every 1,000 files you want to generate"
echo
echo
exit 0
}

# need this line to call the function passed from the CLI
# because bash is too stupid to let me define functions
# locally to override what's in .bashrc
$1 $2 $3 $4 $5 $6

exit 0

Created by: SCR, Last modification: Sat 22 of Oct, 2011 (17:20 UTC)


Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+

Page Changes | Comments

 

Featured -

Search: