You are on page 1of 16

Channels:

SIP
IAX – Inter Asterisk Exchange: can do some interesting things between 2 Asterisk PBX’s
DAHDI (Digium Asterisk Hardware Device Interface): analog FXO or FXS channels, TDM channels

Interfaces (how you interact with asterisk):

.conf files
command line interface
Asterisk Gateway Interface
Asterisk Manager Interface

Config File Basics: etc/asterisk/filename.conf

[section-heading]
key=value
; comment

;-- Multiple line comment


commented
commented
commented –;

Download the source code to /usr /local /src


Untar the archive: tar zxvf name.tar.gz

cd to the directory where the Asterisk source code is.

./configure

If there are dependencies that are not installed, navigate to /contrib /scripts and run:

./install_prereq install

Run ./configure again

make menuselect

make

make install

Optionally, run <make samples> to create some sample config files and for a sample basic PBX: make
basic-pbx

to install asterisk program documentation run: make progdocs (requires doxygen to be installed)
asterisk is located inside /usr /sbin
to open CLI for asterisk, run /usr /sbin/asterisk -r (or rasterisk)

run <dialplan show> for the dialplan


if you type <dialplan show> and then press TAB key, you can select the context

• Understand what a dialplan is

- the Asterisk dialplan is much more like a small scripting language


- in a traditional PBX, the dialplan is a simple table that maps extension numbers to phones (physical
ports)
- uses logic to make smarter choices; this is what makes Asterisk flexible
- a dialplan is simply instructions telling Asterisk what to do with a call

• extensions.conf syntax
- Contexts, Extensions, Priorities
- ‘n’ priority
- Priority labels
- ”same” designator

• build some basic extensions

CONTEXTS:
Def: Contexts are containers that separate extensions. Like bucket for extensions

[context-name]

Example:

[context1]
extension
extension
extension

[context2]
extension
extension
extension

The way the contexts work is that by default, they separate extensions

Exemple:

[demo]
3000
500
3001
3002

[default]

6000
500
6001
6002
6005

500@demo is different than 500@default

The full name for an extension is extension@context

If you comment a context, you must comment the extensions associated with that context too, because
otherwise those extensions will become part of the previous context; To avoid this, you can either
comment the extensions under the desired context, or comment the whole thing (group)

Extensions: are a script that it’s gonna execute


An Asterisk extension is the mapping between a dialplan address and a named set of actions
- not an endpoint
- more like a script
- each action is called an “application”

extension@context [context]
extension
• application
• application
• application

The concept of an extension being a phone is a legacy concept. A phone might have multiple extensions
configured
Each extension is a script that is gonna be executed: it could dial a phone, an IVR, a voice mail etc.
Each extension will have a series of actions (applications) that will be executed one at a time

• Syntax:

exten => name,priority,application


Examples: exten => 1000,1,Dial(SIP/digium-phone)
exten => Tom,1,Dial(SIP/digium-phone)
exten => 1234,1,NoOp(Hello World!)

extension@context [context]
extension
1. application
2. application
3. application
4. application
1,2,3,4 are priorities
exten => extension,priority,application
To see all available applications, run <core show applications>
You can also run <asterisk -rx “core show applications”> and return to the bash CLI

TRAINING:

What is Asterisk?

It is an Open Source Telephony Platform. Using Digium Interface Cards, it can communicate directly
with analog phones.

At the core, Asterisk switches telephone calls.

Asterisk Characteristics: It is featureful. It supports: called ID, call recording, conference calling and
voice mail are just a few features that Asterisk provide.

Scalable, Free, Supportable

Asterisk Use Cases:

-as a traditional PBX: in conjunction with Digium DAHDI interface cards, Asterisk can connect to the
public telephone network
- using VoIP, Asterisk can serve as a complete IP PBX, without any need to directly connect to a local
Telecom.
- as a hybrid PBX.
- Call Center

Operating System Requirements: it is supported on RedHat, fedora, Ubuntu, debian and CentOS
Minimum system requirements:
Dimensioning your Asterisk Server:
-how many simultaneous calls do I expect?
-will my system be transcoding audio from one codec to another?
- will my system be using conferences? If so, how many room and with how many users?
- will I be recording any calls?
- what other applications or services do I want to run on my Asterisk system?

Downloading& Installing:

It is best practice to install DAHDI before installing Asterisk, even if you don’t use it. Necessary
dependencies are: libnewt (C library for text screen widgets), kernel-headers(C header files for the
Linux kernel)

LibPRI provides support for ISDN


./configure -h | less
/contrib/scripts/ install_prereq
make menuselect will generate a list of asterisk modules and display the package
requirements

-Download the source code: Asterisk, DAHDI and LibPRI


-DAHDI and LibPRI must be installed prior to installing Asterisk

Run /usr/local/src/asterisk/contrib/scripts/install_prereq install to install all dependencies


cd ../.. and run ./configure
Run make menuselect
Run make
Run make install
make samples
make config

service asterisk start

Editing configuration files:

When Asterisk is installed for the first time, it is recommended that you run the command: make
samples

Configuration files:

Configuration files live in /etc/asterisk by default

asterisk.conf is an important configuration file since it specifies where asterisk should look for it’s
configuration files

[directories](!) --> what is contained in square brackets is the section identifier


astetcdir => /etc/asterisk --> these lines are key=value pairs
astmoddir => /usr/lib/asterisk/modules
astvarlibdir => /var/lib/asterisk
astdbdir => /var/lib/asterisk
astkeydir => /var/lib/asterisk
astdatadir => /var/lib/asterisk
astagidir => /var/lib/asterisk/agi-bin
astspooldir => /var/spool/asterisk
astrundir => /var/run/asterisk
root@asterisk:/etc/asterisk# head -50 asterisk.conf
[directories](!)
astetcdir => /etc/asterisk
astmoddir => /usr/lib/asterisk/modules
astvarlibdir => /var/lib/asterisk
astdbdir => /var/lib/asterisk
astkeydir => /var/lib/asterisk
astdatadir => /var/lib/asterisk
astagidir => /var/lib/asterisk/agi-bin
astspooldir => /var/spool/asterisk
astrundir => /var/run/asterisk
astlogdir => /var/log/asterisk
astsbindir => /usr/sbin

[options] –> another section identifier


;verbose = 3
;debug = 3
;refdebug = yes ; Enable reference count debug logging.
;alwaysfork = yes ; Same as -F at startup.

Key-value pairs are separate either by = sign or by =>

extensions.conf – also just called the dialplan

This is where Asterisk is told how to handle both incoming and outgoing calls
In legacy PBXs, extension might refer to a physical line or an endpoint. In Asterisk, extensions are just
a dial string, used to access services as well as endpoints.
An Asterisk dialplan not unlike a router table in a modern networking switch

In the extensions.conf you will find the General section, followed by the globals sections

Each section starting with [] is called a context within the extensions.conf

sip.conf – the configuration file for sip channel driver

SIP is an industry VoIP protocol

If you deleted a configuration file, you can find a copy in the /usr/local/src/asterisk/configs/ folder

Asterisk does not re-read the configuration files. If you made a change, you need to reload the module
for which the change was done or reload Asterisk. The command reload can be used: Run asterisk -r,
then reload

You can reload specific modules as follows:

sip reload
module reload chan_sip.so

Asterisk.conf , extensions.conf and sip.conf are the three most important configuration files you’ll use

Asterisk Basics: Architectural Overview


Asterisk is modular. A relatively small and simple core manages loading and unloading dynamic
modules that provide most of Asterisk’s functionality

Example of modules: Channel Drivers, Applications, Functions, Resources, Codecs, Formats

Modules are files in the Linux system and end in .so standing for Shared Object

These library files are loaded by default from the /usr/lib/asterisk/modules directory or from wherever
the astmoddir option is set in asterisk.conf

/etc/asterisk/modules.conf lets an administrative decide whether Asterisk should automatically load all
modules found in the modules directory or whether individual modules must be specified to be loaded

Asterisk core also provides System Timing so that audio from different sources can be syncronized
Asterisk is capable of handling many different types of media channels. Traditional analog and digital
telephony channels can be configured using Digium Hardware in the DAHDI driver package
Various VOIP channel types including SIP and IAX can also be used with Asterisk (chan_sip.so and
chan_iax2.so)

For each channel type that Asterisk supports, a channel driver module must be written. These drivers
are custom written Asterisk modules.

Applications are Asterisk modules used for dialplan processing. The actual routing calls in the dialplan
happens in the PBX core modules but the various actions calls take or actions done to calls are
implemented in applications (ex: dial an extension, play an audio file or record a voicemail message)

There are over 100 applications natively available in Asterisk.

Each application module is dynamically loaded by the core when needed and most applications live in
a file with a name similar to app_dial.so or app_playback.so

Functions get or set channel data. They can manage func_callerid.so, func_cdr.so – Call detail records

Resources perform an action on or to the channel statically loaded. May operate simultaneously on
multiple channels. Ex: res_musiconhold.so

Digital media carried by Asterisk must be formatted in a specific predefined way. An audio or video
codec defines a standardized representation format that converts between that format and a needed
internal format.

Codecs convert media on a channel.


Format modules convert media saved on disk file system

CLI: is an absolute requirements for any Asterisk system administrator


Asterisk CLI

you can hang up an ongoing call, update configuration settings or stop asterisk completely

asterisk -c will start asterisk and put you on the asterisk CLI
asterisk -r Start the Asterisk CLI when Asterisk is already running
core stop now will shutdown the Asterisk core
core restart now restart Asterisk
core stop gracefully it rejects new calls but only stops when the currently ongoing calls
terminate
core stop when convenient stops when call volume hits zero
core abort shutdown will cancel the shutdown for the command gracefully and when
convenient
core show version displays which version of Asterisk you’re running
core show settings show several configuration settings for Asterisk core
core show applications shows all applications that are currently available
core show channels outputs a list of currently available channels

reload will reload all modules and their configuration files


module reload chan_sip.so reload specific modules
dialplan reload reread the extensions in the extensions.conf config file

core set verbose 0 turns off verbosity


core set verbose 1 only most important info
core set verbose 2 prints more than 1
core set debug are more directly troubleshooting internal errors; follows the pattern of
verbose

! lets you execute a Linux shell command while you’re on the Asterisk CLI

help list all available commands


help and command will give you information about that specific command

Make a first call:

You must edit sip.conf to create an account

Asterisk Dialplan is the heart of Asterisk. This is where all call routing occur

An asterisk dialplan is unlike traditional dialplans. There’s no direct association between an endpoint
and an extension

Asterisk dial plan routes calls to extensions and each extension performs one or more applications.

To map an extension to a phone, we use the dial application, but instead of dialing a phone, we could
use a voice mail application.

Basic syntax of an extension:


[internal_users]
exten => extension_name,priority,application()

priority – is the first action asterisk will take when this extension is executed
Each new line or priority of an extension must begin with the same extension name

Example:

[internal_users]
exten => 6000,1,Answer()
exten => 6000,2,Playback(hello-world)

Playback with play the file contained as a parameter within (). The audio file reside in the asterisk’s
sounds directory

sip.conf

type=friend ‘friend’ can send and receive calls


‘user’ can only make calls
‘peer’ can only receive calls

host=dynamic means that user doesn’t have a static IP address and must register to let Asterisk
know it’s IP address

Other variants: host=192.168.55.14


host=hostname.example.com

context=internal_users Setting it like this points Asterisk get a context in the dialplan configured
in extensions.conf When the user dials a number on this phone, Asterisk will try to match the dialed
number against extensions in this context.

Contexts are containers of extensions. Much like categories.


An extension is a dialed string used to access services as well as endpoints. It is not necessarily a phone
in the traditional sense

First Call Breakdown

demo: exten => 6002,1,Dial(SIP/phone-2,20)

More than one extension can dial the same phone. For example, you can set up two extensions that will
dial the from at Reception. A user can dial 300, for example, and 400, both will dial the same phone in
the Reception

We can easily have another extension that looks identical except for the extension name and other
extentions, living in another context, can dial the same phone

The first priority must be 1.


We use the Dial application to ring phones, as well as make Outbound calls over a VoIP or traditional
trunk

The format of the argument (SIP/phone-2) takes the form of (Technology/Resource)


The Technology must represent an available Asterisk channel driver such as SIP, IAX2 or DAHDI
A valid Resource must be the name of a phone or trunk identified in the configuration file of the
specified channel driver (In this case it is sip.conf or pjsip.conf)

20 is the timeout; this is the maximum number of seconds the endpoint will ring

Visual breakdown

phone-1 dials 6002

What is a Dialplan?

• The Asterisk dialplan is unlike the dialplan in traditional PBX systems


- in a traditional PBX, the dialplan is a simple table that maps extension numbers to phones
- the Asterisk dialplan is much more like a small scripting language
- This is what makes Asterisk so powerful
• The dialplan is the heart of any Asterisk system
• It defines the behavior of the system
• It consists of a list of instructions

Extension Syntax

exten => name,priority,application


exten => 1000,1,Dial(PJSIP/digium-phone)
exten => Tom,1,Dial(PJSIP/digium-phone)
exten => 1234,1,NoOp(Hello World!)

An Asterisk priority is “a tag that tells each step in an extension when to execute”

Example:

exten => 6000,1,Playback(hello-world)


exten => 6000,2,Playback(goodbye)
exten => 6000,3,Hangup()

A little bit easier:


exten => 6000,1,Playback(hello-world)
same => 2,Playback(goodbye)
same => 3,Hangup()

exten => 6000,1,Playback(hello-world)


same => n,Playback(goodbye)
same => n,Hangup()

Syntax:

exten => name,n(label),application

exten => 6000,1,Playback(hello-world)


same => 2,Playback(goodbye)
same => 3,Goto(2)

exten =>6000,1,Playback(hello-world)
same => n(start-loop),Playback(goodbye)
same => n,Goto(start-loop)

Pjsip was introduced in Asterisk 12. Is the new de facto SIP channel driver

• 3 step process
1. Configure an account on Asterisk
2. Create an extension to dial the account
3. Configure the endpoint to match

The bare minimum the server needs to know:


- Transport (what path can be used to communicate with the phone)
- Location of the phone: IP address
- Credentials of the phone
- How to route calls from the phone: to be configured in extensions.conf
- By using Asterisk’s dialplan...you must tell the server where the phone will begin to look in the
dialplan logic → so this would be the context

When you configure an endpoint, you will define which context that endpoint is allowed to dial into

sip.conf:

[account-name]
type=friend
host=dynamic → this tells Asterisk that IP address might change, so use registration instead of IP addr
context=inside → tells Asterisk which part of the dialplan this phone can use
secret=password
To be reviewed:

type=user → inbound calls


type=peer → outbound calls → very often used for trunks
type=friend → user & peer → very often is used for endpoints

pjsip.conf:

[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0

- transport is defined in it’s own section


- place it anywhere in pjsip.conf file
- transport is referenced in the endpoint section
- if endpoint does not specify, then the first declared transport in the file is considered the default

pjsip.conf example:

[7001] - this is the endpoint section


type=endpoint
context=phones → part of the dialplan this phone has access to when it dials an extension
disallow=all
allow=ulaw
transport=transport-udp
auth=7001 → this points to another section; this endpoint will use the next section for authentication
aors=7001

[7001] → credential section


type=auth
auth_type=userpass
password=MyP@ssw0rd
username=bobby-bee

[7001] → network location


type=aor
max_contacts=1

In the endpoint section we’re defining the characteristics of the devices itself-the endpoint
An endpoint could be a trunk or a phone, anything that uses SIP

disallow=all → this endpoint can use no codecs


allow=ulaw → ok, this endpoint can use ulaw codecs
Like in iptables, deny all and then allow specific

aors=7001 → address of record; basically you can have multiple devices attached to a single account.
So now you can dial that account and all the phones configured with it will ring simultaneously and the
first that answers gets the call.

Useful when you have for example a SIP phone on the desk, but also a softphone installed.

max_contacts=1 OR
contact=7001@192.168.101.75

If you leave just max_contacts=1 you’re expecting a registration and it basically tells Asterisk that only
one devices is allowed to register; if you change it to 2, then 2 devices can simultaneously register

Example:

[inside]
exten => 7001,1,Dial(PJSIP/7001,20)

The above extension means that endpoints with access to the “inside” context can dial that endpoint
you configured in sip.conf at 7001.

SIP Callflow:
First we have Doug who has an endpoint (205) and Jane also has an endpoint (200)
Doug dials 200 and that channel is set up with Asterisk and the phone sends the information to Asterisk
and says “Hey, I’m this endpoint and I need to dial extension 200”
So inside the pjsip.conf, that endpoint will be checked and we see context=inside so Doug has access to
the “inside” context

So now we go to the extensions.conf and within the “inside” context we find that one of the extensions
is 200 and that 200 extension executes the Dial application using the PJSIP channel driver against the
jane endpoint

Dialplan Basics:

an extension is a named set of actions that Asterisk will perform when that extension is dialed
each context is distinct, so extensions in one context are completely separated by extensions in another
context

A dialplan consists of several contexts


Each context has one or more extensions
Each extension is made up of 1 or more priorities, which are the numbered actions for each extension
Each priority calls an Application

Contexts:

Dialplan contexts are extensions.conf version of sections

if you want to include extensions from one context to another, you can use the include syntax:

include => features

dialplan show extension@context

Dialplan Priorities:

exten => 6000,n(label),Playback(freezing)

you can use

exten => 6000,n,Goto(label) to jump to a specific label

Asterisk Applications:

Applications execute synchronously and dynamically loaded by the Asterisk core when they’re called
Resources are statically loaded and can’t operate simultaneously on more than one channel

When an application module is loaded, is making available the Application to be used. For example,
when the app_dial.so is loaded, it makes it possible to use Dial()
Dialplan Application categories:

• Call Control
Dial(SIP/phone-1,20,etc..)
Answer()

Auto fallthrough occurs when there is nothing left for an extensions context to do, and a dial
fails.

OTHER NOTES:

Dialplan search order:

explicit extensions
pattern match extensions
includes
switches

#include filename reads the contents of filename and place them in the current filename
#exec program runs a program and the output of that program will be place here
${EXTEN} is a variable and is going to be replaced with the dialed extension
ex: exten => _NXXNXXXXXX,1,Dial(SIP/provider/${EXTEN})

FreeSwitch - FusionPBX
Asterisk - FreePBX
3cx

You might also like