VoIP Study and Implementation Asterisk Installation and Configuration Part 1 Version 1.0 – Author : Marc PYBOURDIN / Julien BERTON Last Update : 15/05/2012
Course objectives Asterisk overview Asterisk components By completing this course, you will see: Asterisk Overview
INTRODUCING ASTERISK Asterisk Installation and Configuration – Part 1
What is Asterisk ? Open Source PBX (Private Branch Exchange) system Distributed under the GNU GPL with commercial licenses available –Codec licensing also available(G729a) Current version is the Overview
What is Asterisk ? Supports analog circuits with DAHDI –such as PSTN with hardware cards Supports several codecs : –G711 –G729 –Speex –LPC-10 –…–… Provides transcoding between codecs Can be used as an IVR platform Overview
What is Asterisk ? Asterisk features includes : –Complete management of the call flow(incoming/outgoing) with the DialPlan) –Traditional phones features(Hold, Transfer,…) –Voic –Conference rooms –MoH, IVR –Parking –Fax detection Overview
DAHDI DAHDI (previously called ZapTel) stands for : Digium Asterisk Hardware Device Interface Communication between Asterisk and hardware cards Also used by Asterisk components like MeetMe Architecture
Any questions?
INSTALLING ASTERISK Asterisk Installation and Configuration – Part 1
Installing Asterisk From package –Dependencies generally automatically handled From sources –Compile Asterisk with the components that fits your needs and your architecture Architecture
Installing Asterisk with packages Install from package with DAHDI with distribution repositories –Debian/Ubuntu apt-get install asterisk asterisk-dahdi –Fedora yum install asterisk asterisk-configs asterisk-voic dahdi-linux dahdi-tools Architecture
Installing DAHDI and Asterisk from sources Install from sources with Debian/Ubuntu –Make sure that the repositories are updated apt-get update && apt-get upgrade –Install the compilation dependencies apt-get install build-essential libxml2-dev libncurses5-dev linux- headers-`uname -r` libsqlite3-dev –Create the source directory and go inside mkdir /usr/src/asterisk && cd /usr/src/asterisk Architecture
Installing DAHDI and Asterisk from sources Install from sources with Debian/Ubuntu –Get the lastest version of DAHDI wget complete/dahdi-linux-complete-current.tar.gz –Extract the sources and go inside the source directory tar –xvzf dahdi-linux-complete-current.tar.gz && cd dahdi-linux- complete / –Compile, install and start DAHDI make all && make install && make config && /etc/init.d/dahdi start Architecture
Installing DAHDI and Asterisk from sources Install from sources with Debian/Ubuntu –Get the lastest version of Asterisk wget current.tar.gz –Extract the sources and go inside the source directory tar –xvzf asterisk-10-current.tar.gz && cd asterisk / –Check the dependencies and launch menuselect./configure && make menuselect Architecture
Installing DAHDI and Asterisk from sources Install from sources with Debian/Ubuntu –Launch the compilation and the installation make && make install –Install samples configuration files make samples && make config –You can then launch Asterisk with the command /etc/init.d/asterisk start Architecture
Any questions?
ASTERISK ADMINISTRATION Asterisk Installation and Configuration – Part 1
Administrating Asterisk Two methods : –Asterisk console –Configuration files Architecture
Asterisk Console Central administration point to : –Do real-time debugging –Show status of Asterisk components –Do actions on the Asterisk server Can be launched using :asterisk -r Architecture
Asterisk Console CommandDescription sip show channelsShow currents active channels sip show registryShow trunk status sip show peersShow peers status set verbose XSet the verbosity of the console where X is a digit or a number core show translationShow transcode latency between codecs Architecture
Asterisk Console Commanddescription reloadForce Asterisk to read again the configuration file without restart it core restart nowForce Asterisk to restart Asterisk as the command is entered core restart gracefullyRestart Asterisk but allow active calls to continue. All new calls are rejected. core restart when convenientRestart Asterisk but allow active calls to continue. All new calls are accepted. Architecture
Configuration files FileDescription sip.confTrunk configuration users.confUsers configuration extensions.confDialPlan configuration iax.confIAX users, peers, friends, and parameters logger.confLog files, log levels, etc. meetme.confMeetMe conference configuration modules.confModules, preloads, globals, and noloads musiconhold.confMusic on hold configuration voic .confVoic mailboxes, general parameters Overview
Any questions?
DIALPLAN Asterisk Installation and Configuration – Part 1
DialPlan Asterisk is centered around the dialplan. –Responsible for directing and routing all calls of the calls through the PBX –Define the user’s environment by using contexts What numbers can be called What is happening when numbers called Extensions.conf
Extensions format exten => Number,Priority,App(arguments) –May be any number of digits –May be string literals –May pattern match (when proceeded with '_') »‘N’ matches digits from 2 to 9 »‘X’ matches digits from 0 to 9 »‘.’ matches one or more characters »‘!’ matches zero or more characters Extensions.conf
Diaplan structure Each step in the Dial Plan is an Application –For example, Playback() application is used to play sounds Each step is assigned a priority sequence –For example, to play a sound and then hangup : exten => s,1,Answer() exten => s,2,Playback(tt-weasels) exten => s,3,Hangup() Extensions.conf
Extension contexts A dialplan is composed with extension contexts –Represented in the file by brackets – [my_context] define a new context Contexts contain extensions –Example, to add two numbers to the context : [my_context] exten => 1,1,Answer() exten => 1,2,Playback(tt-weasels) exten => 1,3,Hangup() exten => 2,1,Answer() exten => 2,2,MusicOnHold() exten => 2,3,Hangup() Extensions.conf
Extension contexts Contexts can be nested with the include statement Example : to include [my_context] into [bigger_context] : [bigger_context] include => my_context Extensions.conf
Extensions variables As a call is created into a channel, variables can be used in extensions such as : –${EXTEN} The current extension that being called –${CONTEXT} The name of the current context –${CALLERID(name)} The current Caller ID name –${CALLERID(num)} The current Caller ID number –${EPOCH} The current UNIX-style epoch(number of seconds since 1 Jan 1970) Extensions.conf
Standard extensions ExtensionDescription 's’ (start)Used as a start point in your extension for calls that enter in the context without specific context information 't' (timeout)Used when calls have been inactive after a prompt was played(during an IVR for example). 'i’ (invalid)When a non-existant extension in the current context has been called. 'o’ (operator)Used for operator exit by pressing zero in voic . 'h’ (hangup)When the call is terminated. Extensions.conf
DialPlan applications Answer() Makes Asterisk pick-up the call Always without argument HangUp() Makes Asterisk hangup the call Always without argument Extensions.conf
DialPlan applications Dial(type/identifier,timeout) Makes Asterisk dial a number Comes always with argument(s) Dial(SIP/6000,20) for calling the user 6000 during 20 seconds Dial(SIP/myTrunk/${EXTEN}) for calling number through SIP trunk Extensions.conf
DialPlan applications Makes Asterisk launch the voic IVR for callers to leave voice message Always used with argument(s) Application used to check voic Always used with argument(s) Extensions.conf
DialPlan applications Goto(context,extension,priority) Used in dialplan to jump into another context, extension, priority Playtones(tone) Plays a tone to the caller Playback(sound-file) Play a sound to the caller Located in /var/lib/asterisk/sounds Extensions.conf
DialPlan applications SayUnixTime(unixtime,timezone,format) Uses some of the sound files stored in /var/lib/asterisk/sounds to construct a phrase saying the specified date and/or time in the specified format. Extensions.conf
Quiz What can be done if you want to achieve to following? –wants to match all users from 6000 to 6999 –call the dialed user within this range –if peer not available, hangup In order to do that, you must only use one extension Extensions.conf
Quiz - Answer [my_context] ; if not existing already Exten => _6XXX,1,Answer() Exten => _6XXX,2,Dial(SIP/${EXTEN}) Exten => _6XXX,3,Hangup() We match the pattern « 6XXX » where X means any number between 0 and 9. Extensions.conf
Demonstration Show how to implement this solution on Asterisk and test it Extensions.conf
Any questions?
USER & VOIC CONFIGURATION Asterisk Installation and Configuration – Part 1
SIP types in Asterisk Asterisk has three SIP types –peer A SIP entity that can handle inbound and outbound calls –Essentially for trunks connected to a SIP provider –user A SIP entity than can handle only inbound calls –Not commonly used nowadays –friend A SIP entity that’ll be instanciated as an user and a peer –Essentially for SIP clients –Can receive and place calls Defined by the type=value in the user/trunk configuration Extensions.conf
Users management Created in users.conf The syntax is the following : [6000] ; username type=friend ; always friend for end devices ; user password host=dynamic ; allow dynamic IP to log in context=my_context mailbox=6000 ; mailbox number qualify=yes ; enable real-time monitoring Users.conf
Users templates In order to create template, do the following : [aperture_clients](!) type=friend host=dynamic context=my_context qualify=yes nat=yes In order to create users with the template, do the following : [6000](aperture_clients) mailbox=6000 Users.conf
Voic mailboxes In the voic .conf file. –Format : =,,,, –Contexts are also available in voic .conf. Voic .conf
Any questions?
INCOMING & OUTGOING CALL ROUTING Asterisk Installation and Configuration – Part 1
Trunk configuration In the sip.conf file. Trunk configuration need two actions: –Define the SIP trunk in the [general] context –Define the SIP trunk dedicated user You can check the trunk status in the Asterisk console with: –show sip registry –show sip peers Sip.conf
Trunk configuration Define the SIP trunk in the [general] context –register => –For example, for an OVH trunk: register => 6789 Sip.conf
Trunk configuration Define the SIP trunk dedicated user [myTrunk] type=peer ;always peer for trunk secret=MySecr3t host=sip.ovh.net fromuser= username= nat=never ;Asterisk server has a public address context=from-trunk insecure=invite,port ;accept calls w/o auth qualify=yes Sip.conf
Outgoing call setup If our trunk to the service provider work, we can now configure Asterisk to use the trunk four outgoing calls. Configuration of the DialPlan still and always on the extensions.conf file. Extensions.conf
Outgoing call setup In your internal context [my_context], add the following : exten => _0XXXXXXXXX,1,Dial(SIP/myTrunk/${EXTEN}) exten => _0XXXXXXXXX,2,Playtones(congestion) exten => _0XXXXXXXXX,3,Congestion() exten => _XXXX,1,Dial(SIP/myTrunk/${EXTEN}) exten => _XXXX,2,Playtones(congestion) exten => _XXXX,3,Congestion() At this point, your users are able to dial French phone numbers(extended or short). Extensions.conf
Quiz Oh! You forgot to set short number for French emergencies numbers such as: –15 –17 –18 Modify your configuration to allow routing and calling of these three numbers in your internal context [my_context]. –Use only one extension to do that Extensions.conf
Quiz - Answer Add the following at the end of your context: exten => _1[578],1,Dial(SIP/myTrunk/${EXTEN}) exten => _1[578],2,Playtones(congestion) exten => _1[578],3,Congestion() Number inside bracket means a possibility for one unique digit. –Here, [578] means 5 or 7 or 8 for the second digit. Extensions.conf
Demonstration Show how to implement this solution on Asterisk and test it Extensions.conf
Incoming call setup In order to accept calls from a public PSTN number, you need to : –Define the trunk context –Define a start action on it Always done in the extensions.conf file. Extensions.conf
Incoming call setup To set incoming calls : [from-trunk] exten => s,1,Dial(SIP/6000,20) exten => exten => s,3,Hangup() In this example, if someone calls us on the PSTN public number : 1.the SIP user 6000 will ring during 20s 2.If no one answer, transfer to Voic of the user 3.then hangup Extensions.conf
Demonstration Show how to implement this solution on Asterisk and test it Extensions.conf
Any questions?