Free sample of the first three chapters

The entire eBook can be bought at www.asteriskguide.com

 

 

 

 

 

 

 

 

astconfguideen2

 

How to build and configure a PBX with Open Source Software

Featuring release 1.4

Flavio E. Gonçalves

Third Generation

2nd Edition/April/2007

rev. 8.7

 

 

 

 

 

 

 

By Flavio E. Goncalves


Asterisk PBX Configuration Guide

Flavio E. Gonçalves

Revision: Luis F. Gonçalves

 

Copyright © 2006 V.Office Networks Ltda., All rights reserved

 

Printing History

 

First Edition: November 2006,

File Date: Friday, January 25, 2008

ISBN: 978-85-906904-2-9

 

Some manufacturers claim trademarks for several designations that distinguish their products. Wherever those designations appear in this book and we are aware of them, the designation is printed in CAPS or the initials are capitalized.

 

Although a great degree of care was used in writing this book, the author assumes no responsibility for errors and omissions, or damages resulting from the use of the information contained in this book.

 

Asterisk, Digium, IAX and DUNDI trademarks are property of Digium Inc.


Preface

 

This book is for anyone who wants to learn how to install and configure a PBX (Private Branch eXchange) based on Asterisk PBX. Asterisk is an open source telephony platform capable to use VoIP and TDM channels.

 

This is the third generation of the book Asterisk Configuration Guide. The book is also available in Spanish and Portuguese. The material that I present in this book helped to prepare for the dCAP certification from Digium last May 2006 and to pass it in the first try. Originally, this e-Book was written for version 1.0. The second generation was updated to version 1.2 and this one is based on version 1.4. However, you may still find examples that were based in the older version. Wherever possible, those examples have been suppressed or changed.

 

The Asterisk Open Source PBX is revolutionary. Telephony will never be the same after this program. For many years, telephony has been dominated by huge companies with proprietary systems. Finally, users can recover their buying power by having access to an open telephony platform. Thus, things that were not possible before because they were not economically viable are likely to start happening. Examples include resources like CTI (computer telephony integration, IVR (interactive voice response), ACD (automatic call distribution), and voicemail, that are now available to everybody. 

 

This book was not designed to teach every single detail of Asterisk. In fact, you will probably not become a guru simply by reading this e-Book. However, you will be able to build and configure a PBX with advanced features like voicemail, IVR an ACD by the end of reading. I hope you enjoy as much learning about Asterisk as I have enjoyed writing about it.

 

Flavio E. Gonçalves

CEO

V.Office Networks

flavio@asteriskguide.com


Audience

 

This book is intended for those who are new to Asterisk. We assume your are familiar with Linux, Linux shell commands and Linux text editors. You could test Asterisk using a Linux system with a graphical interface which may be easier for Linux newbies. Some users will try to execute Asterisk using VMWare and this is really not a problem, except for poorer voice quality. For production systems we do not encourage VMware or Linux with a graphical user interface.

 

It is also desirable that the reader has some knowledge of IP networks, voice over IP (VoIP) and telephony concepts.

 

Acknowledgments

 

I have to thank my family for the patience to see me work at late hours and during the weekends for several months. A special thanks to Ana Cristina Gama, Luis F. Goncalves, Karla Braga and Anna Leticia Loch for their help in the revision and publishing tasks.

Mistakes and errors in the e-Book

 

We always try to find and eliminate errors and mistakes. Please, if you find something wrong, give us feedback and we will act on it immediately.

 

E-mail address for feedback: oops@voffice.com.br

Use as a training material

 

We use this book for Asterisk training. If you are interested to use it in your training center, please send an e-mail to flavio@asteriskguide.com. We have additional materials such as presentations and lab guides.


Table of Contents

Asterisk Introduction. 11

1.1 Objectives. 11

1.2 What is Asterisk? 11

1.3 Why Asterisk? 13

1.4 Asterisk Architecture. 16

1.5 Overview.. 20

1.6 Differences between the old and the new world. 21

1.7 Building a test system. 23

1.8 Asterisk scenarios. 24

1.9 Finding information and help. 29

1.10 Summary. 30

1.11 Questions. 30

Downloading and installing Asterisk. 33

2.1 Objectives. 33

2.2 Introduction. 33

2.3 Minimum Hardware. 33

2.4 Choosing an operating system. 35

2.5 Installing Linux prepared for Asterisk. 36

2.6 Preparing the Debian system for Asterisk. 49

2.7 Obtaining and compiling Asterisk. 52

2.8 Starting and stopping Asterisk. 54

2.9 Installation Directories. 55

2.10 Log files and log rotation. 56

2.11 Starting Asterisk with a non-root user. 58

2.12 Asterisk installation notes. 58

2.13 Summary. 59

2.14 Questions. 59

First Steps. 61

3.1 Objectives. 61

3.2 Understanding the configuration files. 61

3.3 Grammars. 62

3.4 Configuring a PSTN interface. 63

3.5 SIP IP phones configuration. 65

3.6 Dial plan introduction. 67

3.7 Creating a basic dial plan. 72

3.8 Labs. 76

3.9 Summary. 77

3.10 Questions. 77

Analog and digital channels. 81

4.1 Objectives. 81

4.2 Telephony basics. 81

4.3 PSTN interfaces. 83

4.4 Analog FXS, FXO and E&M interfaces. 84

4.5 E1/T1 digital lines. 86

4.6. Asterisk telephony channels setup. 89

4.7 Zapata.conf configuration options. 101

4.8 MFC/R2 configuration. 106

4.9 ZAP channel format. 119

4.10 Unicall channel format. 119

4.11 Questions. 119

Voice over IP with Asterisk. 123

5.1 Objectives. 123

5.2 Introduction. 123

5.3 VoIP benefits. 124

5.4 Asterisk VoIP architecture. 124

5.5 VoIP protocols and the OSI (ISO Open Systems Interconnect) model. 126

5.6 How to choose a protocol. 127

5.7 Peers, Users and Friends. 129

5.8 Codecs and codec translation. 130

5.9 How to choose a Codec. 131

5.10 Overhead caused by protocol headers. 132

5.11 Traffic Engineering. 133

5.12 Reducing the bandwidth required for VoIP. 136

5.13 Summary. 140

5.14 Questions. 140

The IAX Protocol. 143

6.1 Objectives. 143

6.2 Introduction. 143

6.3 How it works? 144

6.4 Bandwidth usage. 145

6.5 Channel naming. 147

6.6 Using IAX. 148

6.7 IAX authentication. 157

6.8 The iax.conf file configuration. 162

6.9 IAX2 debug commands. 164

6.10 Summary. 167

6.11 Questions. 167

The SIP Protocol. 169

7.1 Objectives. 169

7.2 Overview.. 169

7.3 SIP advanced scenarios. 176

7.4 Advanced configurations. 182

7.5 SIP NAT Traversal. 186

7.6 SIP limitations. 191

7.7 SIP dial strings. 191

7.8 SIP CLI commands. 192

7.9 Questions. 192

Introduction to the dial plan. 195

8.1 Objectives. 195

8.2 Extensions.conf file structure. 196

8.3 Contexts. 198

8.4 Extensions. 199

8.5 Variables. 202

8.6 Expressions. 206

8.7 Functions. 208

8.8 Applications. 209

8.9 Building a Dialplan. 216

8.10 Building a simple Dial Plan. 218

8.11 Adding some logic to your dial plan. 220

8.12 Summary. 221

8.13 Questions. 221

Dial Plan advanced features. 223

9.1 Objectives. 223

9.2 Receiving calls using an IVR menu. 223

9.3 Context inclusion. 233

9.4 Using the switch statement. 234

9.5 Dial plan processing order. 235

9.6 The #INCLUDE statement. 236

9.7 Macros. 236

9.8 Implementing Call Forward, Black Lists and DND. 237

9.9 Using a blacklist. 240

9.10 Time based contexts. 241

9.11 To get a new dial tone use DISA. 242

9.12 Limit simultaneous calls. 243

9.13 LAB - Putting it all together. 244

9.14 Summary. 248

9.15 Questions. 248

Using PBX features. 251

10.1 Objectives. 251

10.2 PBX features support. 251

10.3 Call Transfer. 255

10.4 Call parking. 256

10.5 Call pickup. 257

10.6 Call Conference (Meetme) 258

10.7 Call Recording. 263

10.8 Music on hold. 265

10.9 Application Maps. 268

10.10 Questions. 269

ACD Automatic Call Distribution. 271

11.1 Objectives. 271

11.2 Introduction. 271

11.3 ACD architecture. 273

11.4 Queues. 273

11.5 Agents. 275

11.6 ACD related applications. 276

11.7 Configuration tasks. 280

11.8 Queue operation. 283

11.9 Advanced resources. 284

11.10 Questions. 285

Voicemail. 287

12.1 Objectives. 287

12.2 Introduction. 287

12.3 Configuration task list. 288

12.4 Sending voicemail to e-mail. 292

12.5 Voicemail Web interface. 293

12.6 Voicemail notification. 294

12.7 Using the directory application. 295

12.8 Summary. 296

12.9 Questions. 297

Asterisk Call Detail Records. 299

13.1 Introduction. 299

13.2 Objectives. 299

13.3 Asterisk CDR Format. 299

13.4 Account codes and automated message accounting. 300

13.5 Changing the CDR format. 300

13.6 CDR Storage. 301

13.7 Applications and functions. 303

13.8 User authentication. 304

13.9 Using passwords from voicemail. 305

13.10 Summary. 305

13.11 Questions. 306

Extending Asterisk with AMI and AGI 309

14.1 Introduction. 309

14.2 Objectives. 309

14.3 Major ways to extend Asterisk. 309

14.4 Extending Asterisk with console CLI 310

14.5 Extending Asterisk using the System() application. 310

14.6 What is AMI? 311

14.7 Configuring users and permissions. 312

14.8 Asterisk Manager Proxy. 316

14.9 Asterisk Gateway Interface. 318

14.10 Changing the source code. 323

14.11 Summary. 323

14.12 Questions. 324

Asterisk Real-Time. 327

15.1 Introduction. 327

15.2 Objectives. 327

15.3 How  does  Asterisk Real Time work? 328

15.4 LAB 1 Installing Asterisk Real/Time. 329

15.5 Configuring Asterisk Real Time. 329

15.6 Database configuration. 332

15.7 Lab 2 – Installing and creating the database tables. 333

15.8 Lab 3 – Configuring and testing ARA. 336

15.9 Summary. 338

15.10 Questions. 338

Question’s Responses. 341

Chapter 1. 341

Chapter 2. 343

Chapter 3. 345

Chapter 4. 347

Chapter 5. 349

Chapter 6. 351

Chapter 7. 352

Chapter 8. 354

Chapter 9. 356

Chapter 10. 358

Chapter 11. 360

Chapter 12. 362

Chapter 13. 364

Chapter 14. 366

Chapter 15. 367

 


 

 

Asterisk Introduction

 

In the current chapter, we will learn what Asterisk is, its architecture, and how it can be used.

1.1 Objectives

fig1-11

                   Figure 1.1 Objectives

1.2 What is Asterisk?

Chapter 1

 
Asterisk is an “Open Source PBX software” that once installed in a PC hardware along with the correct interfaces, can be used as a full featured PBX for home users, enterprises, VoIP service providers and telecoms. Asterisk is also both an Open Source Community and a commercial product from Digium. You are free to use and modify Asterisk to suit your needs.

 

Asterisk allows real time connectivity between PSTN and VoIP networks. Since Asterisk is much more than a PBX, you have not only an exceptional upgrade to your existing PBX, but you can do new things in telephony, such as:

 

·        Connect employees working from home to an Office PBX over broadband Internet.

·        Connect several offices in different places over an IP network, private network, or even through the Internet itself.

·        Give your employees web and e-mail integrated voicemail.

·        Build applications like IVRs that allow connections to your ordering system or other applications.

·        Give traveling users access to the company PBX from anywhere with a simple broadband or VPN connection

·        And much more....

 

Asterisk includes several advanced resources, only found before in high-end systems, for example:

 

 

1.2.1 Digium’s role in Asterisk

Digium, a company located in Huntsville, Alabama, is the creator and primary developer of Asterisk. Besides being the primary sponsor of Asterisk development, Digium also produces telephony interface cards and other hardware for the Asterisk’s PBX.

 

Digium offers Asterisk under three different types of license agreement:

 

·        General Public License (GPL) Asterisk. This is the most used version. It includes all features and is free to be used and modified according to the terms of the GPL license.

·        Asterisk Business Edition is a recent version of Asterisk. The business edition is used by some companies that don’t want or can’t use the GPL license, mostly because they don’t want to release their source code together with Asterisk. The GPL license requires that any further code development to a GPL licensed code must be released to the source code.

·        Asterisk OEM. Mostly used by PBX manufacturers who do not want to reveal to the public that their software is based on Asterisk.


1.2.2 The Zapata project and its relationship with Asterisk

The Zapata project was developed by Jim Dixon, who was also responsible for the development of a revolutionary hardware that is used with Asterisk. Note that the hardware is Open Source too and, therefore, it can be used by any company. Digium, Sangoma and Varion are some of the main telephony card manufacturers of the Asterisk PBX. The Zapata project can be seen at:

 

http://www.asteriskdocs.org/modules/tinycontent/index.php?id=10)

 

The main feature of the Asterisk hardware is the use of the PC CPU to process media streaming, echo cancellation and transcoding. In contrast, most of the existing cards use DSP (Digital Signal Processors) to perform these tasks. The decision to use the PC CPU reduced the board’s price dramatically. Thus, Digium boards are several times cheaper then previously available boards from, for example, Dialogic, Aculab and others, since they don’t require expensive DSPs. The drawback is that these boards need a lot of CPU and a misuse of the PC CPU can have a major impact in voice quality.

1.3 Why Asterisk?

I remember my first contact with Asterisk. The first reaction to something new, moreover one that competes with something you already know, is to reject it!

 

It happened in 2003. Asterisk was competing with a solution that I was selling to a customer (4 E1 VoIP Gateway) and it was ten times, less expensive than, the price I was charging for the solution I already knew.  Due to the disproportionate price, I started studying Asterisk in order to identify potential pitfalls or drawbacks. I found, for example, that the PC CPU at that time would not support 120 g.729 simultaneous sections and, at the end of the day, I won the proposal with my gateway solution. However, this exercise led me to the discovery that Asterisk could solve a variety of very expensive problems for my customer base. We were in trouble with expensive quotes for IVR, unified messaging, call recording, and dialers. I found that with appropriate dimensioning, the CPU problems could be worked around and, indeed, Asterisk became the flagship product of my company in just three years (I actually decided to open another company just for the Asterisk business).  In my opinion, Asterisk is a revolution in telecommunication and it represents to IP telephony what Apache represents to web services.


1.3.1 Extreme cost reduction

If you compare a traditional PBX with Asterisk with digital interfaces and phones, Asterisk is a little cheaper than those PBXs. However, Asterisk really pays off when you add advanced features like voicemail, ACD, IVR and CTI. With these advanced features, Asterisk is several times less expensive than traditional PBXs. Indeed, comparing Asterisk PBXs with low-end analog PBXs is unfair because it has a lot of features that are not available in low-end analog systems.

1.3.2 Telephony system control and independence

One of the most often quoted benefits from the customer’s point of view is the independence that Asterisk provides. Some of today manufacturers do not even give the customer the system’s password or the configuration documentation. With Asterisk’s “do it yourself” approach, the user achieves total freedom and, as a bonus, has access to a standard interface.

1.3.3 Easy and rapid development environment

Asterisk can be extended using scripting languages like PHP and Perl with AMI and AGI interfaces. Asterisk is Open Source and its source code can be modified by the user. The source code is written mostly in ANSI C programming language.

1.3.4 Feature rich

Asterisk has several features that are either not found or optional in traditional PBXs (e.g. voicemail, CTI, ACD, IVR, built in music on hold, and recording). The costs of these features in some platforms supersede the price of the platform itself.

1.3.5 Dynamic content on the phone

Asterisk is programmed using C language and other languages common in today’s development environment. The possibility to provide dynamic content is almost limitless.

1.3.6 Flexible and powerful dial plan

One more Asterisk breakthrough. If you look at traditional PBXs, even simple things like LCR (Least Cost Routing) are either not feasible or optional. With Asterisk, choosing the best route is easy and clean.

1.3.7 Open source running on top of Linux

One of the greatest features of Asterisk is it’s community. When I access Wiki (www.voip-info.org), e-mail distribution lists, and forums, I see that the adoption of Asterisk has been fast with patches quickly provided to any bugs eventually found. Asterisk is probably the most tested PBX software in the world. From versions 1.0 to 1.2, more than 3000 changes and bugs in the source code were corrected. This process ensures a code that is both stable and almost error free.

 

1.3.8 Asterisk architecture limitations

Some limitations in Asterisk come from the use of the Zapata telephony design. In this design, Asterisk uses the PC CPU to process voice channels instead of dedicated DSPs (Digital Signal Processors) which are common in other platforms.  Although this allows for a huge cost reduction in hardware interface, the system becomes dependent on the PC CPU. My recommendation is to run Asterisk in a dedicated machine and to be conservative about hardware dimensioning. It is also interesting to use Asterisk in a separate VLAN to avoid excessive broadcasts that consume the CPU (broadcast storms caused by loops or viruses). Some newer interface cards from several vendors are now including DSPs to process echo cancellation, codecs and other features. This will make Asterisk even better.


1.4 Asterisk Architecture

fig1-12

                    Figure 1.1  - Asterisk Architecture.

 

The figure above shows the basic Asterisk architecture. Next, we will explain concepts related to the architecture like channels, codecs and applications.

 

1.4.1 Channels

A channel is the equivalent of a telephone line, but in digital format. It usually consists of an analogic or digital (TDM) signaling system or a combination of codec and signaling protocol (e.g. SIP-GSM, IAX-uLaw). In the beginning, all telephony connections were analog and susceptible to echo and noise. Later, most systems were converted to digital systems, with the analogic sound converted into digital format by PCM (Pulse Code Modulation) in most cases. This format allows voice transmission in 64 kilobits/second without compression.

 

TDM hardware supported:

 

Zaptel Cards (usually Digium produced)

 

·        Wildcard T410P –Four E1/T1 interfaces (PCI 3.3 volts only)

·        Wildcard T405P – Four E1/T1 interfaces (PCI 5.0 volts only)

·        TE110P – One port E1/T1 interface

·        TDM400P – Four analog interfaces FXO or FXS

·        TDM2400 – Twenty-four ports FXS or FXO

 

These boards use chan_zap channel drivers

 

·        Linux Cards

·        Quicknet Phonejack and linejack can be used

·        ISDN Cards and drivers

·        ISDN4Linux – Old driver, don’t even try to use it. I have tried with a ISDN BRI Eicon Diva Card. The result is bad voice quality and instability. It was removed from compilation in version 1.2 and deleted in version 1.4. These boards use chan_modem channel drivers

·        ISDN CAPI – It is a third party Linux ISDN driver. It is used with junghanns boards (www.junghanns.net) and integrates with hylafax. These boards use chan_capi channel drivers

·        There are other channel drivers for BRI stuff like chan_misdn, which are considered experimental. These drivers were created by Beronet, Europe. vISDN can be also used with HFC ISDN chips.

·        Voicetronix (www.voicetronix.com.au): Produces high density analog boards, 4, 8 and 16 ports. Now they produce E1/T1 cards too. These boards use chan_vbp channel drivers

·        Other manufacturers include Dialogic and Aculab. Most of them do not release the source code.

 

Asterisk channels supported:

 

  1. chan_console: supports a sound card (OSS or ALSA) - dial string: console/dsp)

 

  1. chan_sip: supports voice over IP using SIP protocol. – dial string: sip/channel

 

  1. chan_iax: supports voice over IP using IAX2 protocol, - dial string: iax2/channel

 

  1. chan_h323: H.323 is one of the oldest and most implemented voice over IP protocols. It’s useful when one attempts to connect to existing H.323 networks. There are different flavors of H.323 in Asterisk: chan_h323 and chan_oh323. A third implementation is being developed by Digium: the first version in asterisk-add-ons subversion.  Chan_h323 can be used in Asterisk as a gateway. Asterisk can point to a gatekeeper, but can’t work as one. Dial string h323/hostname if using a gatekeeper, h323/extension@hostname if going directly to the gateway.

 

  1. chan_mgcp: supports the voice over IP protocol using MGCP. Currently Asterisk supports MGCP phones, but it cannot connect to a VoIP provider using MGCP. Dial string: MGCP/aaln/1@hostname

 

  1. chan_sccp: Supports Cisco voice over IP skinny protocol. There are two versions: chan_skinny and chan_sccp2 (http://chan-sccp.berlios.de). Supports most Cisco phones. More information can be found in http://www.voip-info.org/wiki/view/SCCP-HOWTO2. Dial String: SCCP/channel.

 

  1. chan_unicall: Implements MFC/R2 as a signaling protocol for E1s used in China, Latin America and several other countries. It is supported by a third party channel driver called Unicall. In chapter 4, we will detail how to implement it.  It uses the chan_unicall channel driver.  Dial string: Unicall/channel

·         

  1. chan_agent: Used for ACD (Automatic Call Distribution). It is not related to a specific hardware or protocol. It can also be used for mobility, allowing any person to use any phone just by logging in to the agent.

 

  1. chan_local: Is a pseudo channel, it simply loops back into the dialplan in a different context. Useful for recursive routing. Dial string: Local/extension@context

1.4.2 Codecs and codec translation

We usually try to put as many voice connections as possible in a data network. Codecs enable new features in digital voice. Compression is one of the most important ones, since it allows compression rates larger than 8 to 1. Other features include voice activity detection, packet loss concealment and comfort noise generation. There are several codecs available for Asterisk and these codecs can be transparently translated from one to another. Internally, Asterisk uses slinear as the stream format when it needs to convert from one codec to another. Some codecs in Asterisk are supported only in pass-through mode, and these codecs can’t be translated. 

 

The following codecs are supported:

 

·        G.711 ulaw (USA) – (64 Kbps).

·        G.711 alaw (Europe) – (64 Kbps).

·        G.723.1 – Only pass-through mode

·        G.726 – (16/24/32/40kbps)

·        G.729 – Needs licensing (8Kbps)

·        GSM – (12-13 Kbps)

·        iLBC – (15 Kbps)

·        LPC10 - (2.5 Kbps)

·        Speex - (2.15-44.2 Kbps)

1.4.3 Protocols

Sending data from one phone to another should be easy provided that the data find a path to the other phone by themselves. Unfortunately, it doesn’t happen this way, and a signaling protocol is necessary in order to establish connections between phones, discover end devices and implement telephony signaling. Recently, it has become very common to use of SIP as a signaling protocol. H.323 is largely implemented in voice over IP networks and most legacy implementations use this protocol. IAX is another option that is becoming popular because it works well with NAT traversal and some bandwidth can be saved as well.

 

Asterisk supports:

 

·         SIP

·         H323

·         IAXv1 e v2

·         MGCP

·         SCCP (Cisco Skinny)

·         Nortel unistim

1.4.4 Applications

To bridge calls from one phone to another an application named Dial() is used. Most Asterisk features like voicemail and conferencing are implemented as applications. You can see available Asterisk applications by using the “core show applications” console command. You can add applications from asterisk-addons, from third-party providers or even develop some applications yourself.

1.5 Overview

fig1-1

                   Figure 1.2-Asterisk overview

 

Asterisk is an open source PBX that acts like a hybrid PBX, integrating technologies such as TDM[1] and IP telephony. Asterisk is ready for IVR (Interactive Voice Response) functionality and ACD (Automatic call distribution) and, as mentioned in previous sections of this book, is open to the development of new applications.  In the above figure, you can see that Asterisk connects to telcos and existing PBXs using analog and digital interfaces and also supports analog and IP phones. It can act as a softswitch, media gateway, voicemail, audio conference, and has built in music on hold.

 


1.6 Differences between the old and the new world.

1.6.1 Telephony using the old PBX/Softswitch model

figc-1

                   Figure 1.4- Conventional softswitch or legacy PBX model

 

In the old softswitch model, all components were sold separately. Therefore, you had to purchase each component and then integrate to the PBX or softwitch environment. The costs and risks were high and most of the equipment were proprietary.


1.6.2 Telephony using Asterisk

fig1-3

                   Figure 1.5 –Telephony in the Asterisk way.

 

All functions are integrated in the Asterisk platform in the same or in different boxes according to dimensioning, and are licensed according to the GPL agreement.


1.7 Building a test system

 

fig1-4

                   Figure 1.6 – The 1x1 PBX

 

 

When implementing an Asterisk solution, our first step is generally to build a test machine. The easiest test machine is the 1x1 PBX with at least one phone and one line. There are several ways to do it. Let’s examine some of them.

1.7.1 One FXO, one FXS

The first and simplest way to build a test machine is to purchase a Digium TDM400 board with one FXO and one FXS interface. Connect the FXO port to an existing line and one FXS to an analog phone. There you have: a 1x1 PBX.

1.7.2 VoIP Service Provider, ATA

This is the VoIP option. In this case you would sign up with a voice service provider to have the SIP trunks and will have to purchase a SIP analog telephony adapter. You will probably spend less than US$100.00 if you already have the PC.

1.7.3 Inexpensive FXO board, ATA

This is the way I started. There are some V.90 fax/modems that work with Asterisk as an FXO board. Some of the first Digium boards were created using those (X100P and X101P). These boards are old V.90 fax/modems based on Motorola and Intel chipsets (Motorola 68202-51, Intel 537PU, Intel 537PG, Intel Ambient MD3200 are known to work). They are not easy to find since they are not produced anymore; however, some are sold as X100P clones. I found ten of these boards in a PC recycling company. For the FXS you can use an Analog Telephony Adapter. Once again you could spend less than US$100.00 to start if you already have the PC.

1.8 Asterisk scenarios

There are several different scenarios where Asterisk can be used. We will list some of them and explain the advantages and possible limitations of each.

1.8.1 IP PBX

The most common scenario is the installation of a new  or the replacement of an existing PBX. If you compare Asterisk with some other alternatives, you will find it to be cheaper and richer in features then most available PBXs in the market. Several companies are now changing their specifications to Asterisk instead of other brand named PBXs.

 

fig1-5

                   Figure 1.7 IP PBX

 

1.8.2 IP enabling legacy PBXs

The image below illustrates one of the most commonly used setups. Large companies usually don’t want to take a high risk when investing in new technologies and, at the same time, wish to preserve their investments in legacy equipment. IP enabling a legacy PBX can be very expensive and, thus, connecting an Asterisk PBX using T1/E1 lines can be a good alternative to cost conscious customers. Another benefit is to the possibility of connecting to a VoIP service provider with better telephony rates. 

 

fig1-6

                   Figure 1.8 Integration with legacy PBX

 

1.8.3 Toll-Bypass

A very useful application for VoIP is connecting branch offices over the Internet or a WAN. Using an existing data connection allows you to bypass toll charges incurred in telecommunication connections between headquarters and branch offices.

fig1-7

                   Figure 1.9 Toll Bypass

1.8.4 Application Server (IVR, Conference, Voice Mail)

Asterisk can also be used as an application server for the existing PBX or it can be directly connected to PSTN. Asterisk can do services like voicemail, fax reception, call recording, IVR connected to a database, and audio conferencing server. If you integrate voicemail and fax to existing e-mail you will end up having a unified messaging system, which is usuallyan expensive solution. Using Asterisk as an application server provides extreme cost reduction compared to most other solutions.

 

fig1-8

                   Figure 1.10 Asterisk as an application server

 

1.8.5 Media Gateway

Most voice over IP service providers use a SIP proxy to host all registering, location and authentication of SIP users. Anyway, they have to send the call to the PSTN directly or route it through a wholesale call termination provider using SIP or H.323 voice over IP connection. Asterisk can act as a B2BUA (back to back user agent) or Media Gateway, substituting very expensive soft switches or media gateways. Compare the price of a four E1/T1 gateway from the main market manufacturers with Asterisk. The Asterisk solution can cost several times less than other solutions and is capable to translate signaling protocols (H.323, SIP, IAX…) and codecs (G.711, G.729…).

 

fig1-9

                   Figure 1.11 Asterisk as a media gateway

 

1.8.6 Contact Center Platform

A contact center is a very complex solution. It combines several technologies like ACD (automatic call distribution), IVR (interactive voice response), call supervision, and others. Basically, there are three types of contact centers: inbound, outbound, and blended. Inbound contact centers are very sophisticated. Usually they need ACD, IVR, CTI, recording, supervision, and reports. Asterisk has a built in ACD to queue the calls.  IVR can be done using AGI (Asterisk Gateway Interface) or internal mechanisms like the application background. CTI (Computer telephony integration) is done using AMI (Asterisk Manager Interface); recording and reporting are built into Asterisk. For an outbound contact center, a predictive or power dialer is one of the main components. Although several dialers are available from the Asterisk open source, it is not hard to build your own for the platform if you so desire. A blended contact center permits simultaneous inbound and outbound operation, saving money by better usage of the agent’s time. It’s possible to use Asterisk and it’s ACD mechanism to implement a blended solution.

 

fig1-10

                   Figure 1-12 Asterisk as a Contact Center Platform

1.9 Finding information and help

Some of the best places to find information about Asterisk are:

1.9.1 The official page

http://www.asterisk.org

http://www.asterisk.org/support/get-started

http://forums.digium.com/

 

1.9.2 Asterisk wikipedia

http://www.voip-info.org

        www.voip-info.org/wiki-Asterisk

 

1.9.3 Asterisk mailing lists

http://www.asterisk.org/support/mailing-lists

 


1.9.4 Interesing sites

 

www.asteriskguru.com (Several tutorials)

www.sineapps.com (News about Asterisk)

 

1.10 Summary

Asterisk is an Open Source software licensed according to the GPL that enables an ordinary PC to act as a powerful IP PBX platform. It was created by Mark Spencer from Digium, who sells the interface cards for Asterisk. Hardware is open source too and originated in the Zapata project developed by Jim Dixon.  The Asterisk architecture has the following main components:

 

 

 

 

 

Asterisk can be used in several scenarios: from a small IP PBX to a sophisticated contact center.

1.11 Questions

1. Mark the correct answers. Asterisk has four basic architectural components.

 

a)   Channels

b)   Protocols

c)   Agents 

d)   Phones

e)   Codecs

f)    Applications

 

2. If necessary, you can create an Asterisk PBX with four trunks and eight phones using three TDM400 cards. The first one with four FXO channels and the other two with four FXS channels each. This affirmative is:

 

a)   False

b)   True

 

3. A FXS channel generates a dialing tone, while a FXO channel receives a dialing tone from the PSTN or another PBX. The affirmative is:

 

a)   False

b)   True

 

4. Mark the correct answers. Asterisk allows the use of the following features:

 

 

a)   IVR (Interactive Voice Response)

b)   ACD (Automatic Call Distribution)

c)   IP Phones

d)   Analog phones

e)   Digital phones from any vendor

 

5. To play music on hold, Asterisk needs an external player like a MP3 or CD player. The affirmative is:

 

a)   False

b)   True

 

6. This technology is responsible for automatic answering of customers. Usually plays a “prompt” and wait an option dialed by the user. In some cases can be integrated with a database to provide information by the telephone using text-to-speech technology. It is named _____.

 

a)   CTI

b)   IVR

c)   DAC

d)   Unified Messaging

 

7 – An E1 trunk supports ___ voice channels while a T1 trunk supports ___ voice channels.

 

a)   12, 24

b)   30, 24

c)   12, 12

d)   30, 23

 

8 – In traditional PBXs, usually ACD, IVR and voicemail are included in the PBX together with their respective licensing. This affirmative is:

 

a)   False

b)   True

 

9 – It is possible to connect several branches using voice over IP, thereby reducing long distance toll rates imposed by telephony companies. Asterisk can act at a branch as:

 

a)   The PBX for all users

b)   The media gateway connection to an existing PBX

c)   The only thing possible is to use IP phones or ATAs connected to a centralized Asterisk.

d)   Resilience and robustness are not important when you connect IP phones.

 

10 – Asterisk can be used as a contact center platform. What are the three main types of contact centers?

 

a)   External

b)   Internal

c)   Inbound

d)   Outbound

e)   Blended

 

 


 

 

Chapter 2

 
Downloading and installing Asterisk

 

In this Chapter, we will cover downloading, installation and configuration of Asterisk.

2.1 Objectives

figc-2

                   Figure 2.1 Objectives

2.2 Introduction

Now you will learn how to prepare your system for an Asterisk installation. Asterisk runs in multiple operating systems, but we chose to keep things simple and start with a single operating system: Linux. We chose the Debian distribution because the dependencies are easy to install, this distribution is stable, and has a low footprint. Other distributions can be used as well.

2.3 Minimum Hardware

Asterisk is CPU intensive because it uses the PC processor to process voice instead of dedicated DSPs. The most important parameter for CPU dimensioning is the number of simultaneous calls. If you are building a complex system with high load, it is important to keep these concepts in mind. To build a simple system, a Pentium class processor with more than 300 Mhz and 256 Mbytes of RAM memory is fine. Asterisk does not require too much space on disk (around 100 Mbytes of code, including compiled and source). This should allow enough space for voice-mail and custom prompts.

 

If you are using VoIP, no other hardware is necessary. You can use free softphones from counterpath or SJLABS to connect to VoIP providers. A good list of providers can be found in http://www.voipcharges.com.

 

Note: Some Asterisk applications, like meet-me and music on hold, require a clock source. Usually, the clock source of Asterisk is the TDM interface card. If your system does not use a TDM interface card, you will have to load ztdummy to provide a clock.

2.3.1 Hardware Assembling

The asterisk hardware does not need to be sophisticated. You don’t need an expensive video board or too many peripherals. USB, serial and parallel ports should be disabled to avoid consuming unnecessary interrupts. A good network interface card is important. Take special care if you are using TDM interface cards. Some cards use a 3.3 volts PCI bus and it is not easy to find mother boards for them.

2.3.2 IRQ sharing

Telephony interface cards like X100P can generate large quantities of interruptions. Serving these interruptions takes processor time. The drivers can’t do this processing if you have another device using the same interruption. In a single CPU system, you should avoid IRQ sharing between devices. We recommend the use of a dedicated hardware for running Asterisk. Don’t forget to disable any foreign or unnecessary hardware. Some hardware can be disabled in the motherboard bios setup.

 

Once you have started your computer, see your assigned interrupts in /proc/interrupts.

 

#

cat /proc/interrupts

CPU0

0: 41353058 XT-PIC timer

1: 1988 XT-PIC keyboard

2: 0 XT-PIC cascade

3: 413437739 XT-PIC wctdm <-- TDM400

4: 5721494 XT-PIC eth0

7: 413453581 XT-PIC wcfxo <-- X100P

8: 1 XT-PIC rtc

9: 413445182 XT-PIC wcfxo <-- X100P

12: 0 XT-PIC PS/2 Mouse

14: 179578 XT-PIC ide0

15: 3 XT-PIC ide1

NMI: 0

ERR: 0

 

Above, you can see three Digium boards, each in their own IRQ. If this is your case, go ahead and install the hardware drivers. If this is not your case, go back and try something else to avoid IRQ sharing.

2.4 Choosing an operating system

Asterisk was initially developed to run on Linux. However, it can also run on BSD Unix or Mac OS X. If you are new to Asterisk, try using Linux first since it is much easier. If you were to try BSD Linux or Mac OS X, I forewarn you that you this operating system presents many challenges to run Digium hardware.

2.4.1 Linux distribution

Several Linux distributions were successfully tested with Asterisk (e.g. Fedora, Redhat, SuSe, Debian, Gentoo, and others). Choose yours. We have chosen Debian Sarge 3.1 and this distribution can be downloaded from http://www.us.debian.org/CD/netinst/#netinst-stable.

2.4.2 Necessary packages

Required by Asterisk:

 

 

Required by zaptel

 

 

Caution: The zaptel packages are necessary to compile some Asterisk applications like meetme(). If you compiled Asterisk before zaptel, you will have to recompile Asterisk to compile meetme() and other dependent applications.

2.5 Installing Linux prepared for Asterisk

We used Debian with Kernel 2.6 to install Asterisk. We have chosen this distribution because it’s popular, easy to work with, and it is supported by Digium. The installation steps are described below. You can download Debian Sarge version 3.1 from www.debian.org.

 

Caution: This installation will format your PC. All your disk data will be erased. Please make sure to backup all your data before you start.

 

Step 1: Put the CD in the CD-ROM drive and boot your PC. Use the option linux26 to boot with linux kernel version 2.6.

 

TelaDebianInstalação26

 


Step 2: Select the language

 

02_resize

 

Step 3: Select the country

 

03_resize

 


Step 4: Choose the keyboard layout.

 

04_resize

 

Step 5: Type the host name (e.g. asterisk)

 

05_resize

 


Step 6: Type the domain for this equipment (e.g. astersikguide.com).

 

06_resize

 

Step 7: Now you will partition the disks. Please confirm that you erased the entire disk.

 

Caution!

All your data will be erased.  Backup your data before proceeding.

 

07_resize

 


Step 8: Choose “all files in one partition”

 

08_resize

 

Step 9: Choose “finish partitioning and write changes to disk”

 

09_resize

 


Step 10: Confirm again.

 

10_resize

 

Step 11: Accept GRUB boot loader installation

 

11_resize

 


Step 12: Finish the installation

 

12_resize

 

Step 13: Remove the CD, reboot the PC and click OK when the screen depicted below appears.

 

13_resize

 


Step 14:  Select “No” just in case the hardware clock is not set to GMT.

 

14_resize

 

Step 15: Select the appropriate Time zone

 

tela1

 


Step 16: Type “asterisk” as the root password.

 

18_resize

 

Step 17: Re-enter for confirmation

 

19_resize

 


Step 18: Create a user named “asterisk”.

 

20_resize

 

Step 19: Enter the username “asterisk” again

 

21_resize

 


Step 20:  Type “asterisk” as the password for user “asterisk”

 

22_resize

 

Step 21: Re-enter password for verification

 

23_resize

 


Step 22: Answer “no” for the question “scan another CD?”

 

24_resize

 

Step 23: We will use this server just for Asterisk. Leave all options blank.

 

25_resize

 


Step 24: Choose internet site; mail is sent and received using SMTP. This is necessary for integration of voice-mail and e-mail.

 

tela2

 

Step 25: Use the asterisk account for the mail server

 

27_resize

 


Step 26: End

 

28_resize

 

2.6 Preparing the Debian system for Asterisk

The Debian installation is now complete. Let’s now install the packages necessary for the subsequent compilation of Asterisk and Zaptel drivers. We will first indicate to Debian where the packages are going to be downloaded from. This is done by using the apt-setup utility.

 

Step 1: Log in as root

 

Step 2: Add a source to download the packages (/etc/apt/sources.list)

 

#apt-setup

 

Step 3: Select FTP.

 

33 apt-setup 1_resize

 

Step 4: Select the appropriate country

 

tela3

 


Step 5: Choose the appropriate mirror

 

tela4

 

Step 6: Select <no> to another apt source.

 

36 apt-setup 4_resize

 

Step 7:  To install the kernel headers for zaptel compilation, type:

apt-get install kernel-headers-`uname –r`

ln -s /usr/src/kernel-headers-`uname -r` /usr/src/linux

 

For Debian Etch 4.x and Ubuntu 7.x, use:

apt-get install linux-headers-`uname –r`

ln -s /usr/src/linux-headers-`uname -r` /usr/src/linux

 


Step 8: To install the necessary packages, type:

 

apt-get install bison openssl libssl-dev libasound2-dev libc6-dev libnewt-dev libncurses5-dev zlib1g-dev gcc g++ make

2.7 Obtaining and compiling Asterisk

Linux is now installed. The next step is the Asterisk installation.

2.7.1 Obtaining Asterisk sources

To obtain Asterisk sources and zaptel drivers you should download them from Digium.com. We will use the wget utility to download them. Create a directory /usr/src to receive the files. You should consult www.asterisk.org to verify which the latest versions are.

 

Where ´x´ is the latest software revision, type:

 

cd /usr/src

wget http://ftp.digium.com/pub/zaptel/zaptel-1.4.7.1.tar.gz

wget http://ftp.digium.com/pub/libpri/libpri-1.4.x.tar.gz

wget http://ftp.digium.com/pub/asterisk/asterisk-addons-1.4.x.tar.gz

wget http://ftp.digium.com/pub/asterisk/asterisk-1.4.15.tar.gz

 

Uncompress the files using:

 

# tar –xzvf asterisk-1.4.x.tar.gz

# tar –xzvf libpri-1.4.x.tar.gz

# tar –xzvf asterisk-addons-1.4.x.tar.gz

# tar –xzvf zaptel-1.4.x.tar.gz

2.7.2 Compiling Zaptel drivers

You will need to compile the Zaptel modules. The commands ‘./configure’ and ‘make menuselect’ were added on version 1.4. The last one allows you to select which utilities and modules to build.

 

The following commands will do it:

 

cd /usr/src/zaptel-1.4.x/

make clean

./configure

make menuselect

make install

make install-udev              ;Use to create zaptel devices using udev daemon

make config                     ;Use to start zaptel at boot time

update-rc.d zaptel defaults 99       ;Use to start zaptel at boot time

Use “make menuselect” to install only the necessary modules.

 

This is the “make menuselect” screenshot.

 

 

2.7.3 Compiling Asterisk

If you have compiled software before, compiling Asterisk will be an easy task. Run the following commands to compile and install Asterisk. Once again you can choose which applications and modules to build using ‘make menuselect’.

 

cd /usr/src/libpri-1.4.x

make clean

make

make install

 

cd /usr/src/asterisk-1.4.x

make clean

./configure

make menuselect

make

make install

make samples                  ;use to create sample configuration files

make config                     ;to start asterisk at boot time

 

Use “make menuselect” to install only the necessary modules.


 

‘make menuselect’ screenshot:

 

2.8 Starting and stopping Asterisk

With this minimal configuration, it’s possible to start Asterisk successfully.

 

/usr/sbin/asterisk –vvvgc

 

Use the CLI command stop now to shutdown Asterisk.

 

CLI>stop now

2.8.1 Asterisk runtime options

The Asterisk starting process is very simple. If Asterisk is run without any parameters, it is launched as a daemon.

 

/sbin/asterisk

 

You can access Asterisk console by executing the command below. Please note that more than one console process can be run at the same time.

 

/sbin/asterisk -r

2.8.2 Available runtime options for Asterisk

You can show the available runtime options using ‘asterisk –h’

 

debian:/usr/src/asterisk-1.4.1# asterisk -h

Asterisk 1.4.1, Copyright (C) 1999 - 2006, Digium, Inc. and others.

Usage: asterisk [OPTIONS]

Valid Options:

   -V                               Display version number and exit

   -C <configfile>     Use an alternate configuration file

   -G <group>         Run as a group other than the caller

   -U <user>           Run as a user other than the caller

   -c                                Provide console CLI

   -d                               Enable extra debugging

   -f                                Do not fork

   -F                                Always fork

   -g                                Dump core in case of a crash

   -h                                This help screen

   -i                                 Initialize crypto keys at startup

   -I                                Enable internal timing if Zaptel timer is available

   -L <load>            Limit the maximum load average before rejecting new calls

   -M <value>         Limit the maximum number of calls to the specified value

   -m                     Mute the console from debugging and verbose output

   -n                                Disable console colorization

   -p                                Run as pseudo-realtime thread

   -q                               Quiet mode (suppress output)

   -r                                Connect to Asterisk on this machine

   -R                               Connect to Asterisk, and attempt to reconnect if disconnected

   -t                                Record soundfiles in /var/tmp and move them where they belong after they are done.

   -T                               Display the time in [Mmm dd hh:mm:ss] format for each line of output to the CLI.

   -v                               Increase verbosity (multiple v's = more verbose)

   -x <cmd>           Execute command <cmd> (only valid with -r)

2.9 Installation Directories

 

Asterisk is installed on several directories. These directories can be modified in the asterisk.conf file.

 

asterisk.conf

[directories]

astetcdir => /etc/asterisk

astmoddir => /usr/lib/asterisk/modules

astvarlibdir => /var/lib/asterisk

astdatadir => /var/lib/asterisk

astagidir => /var/lib/asterisk/agi-bin

astspooldir => /var/spool/asterisk

astrundir => /var/run

astlogdir => /var/log/asterisk

 

; Changing the following lines may compromise your security.

;[files]

;astctlpermissions = 0660

;astctlowner = root

;astctlgroup = apache

;astctl = asterisk.ctl

;[options]

;internal_timing = yes

 

2.10 Log files and log rotation

Asterisk PBX logs their messages on the /var/log/asterisk directory. The file that controls the logs is the logger.conf.

 

; Logging Configuration

;

; In this file, you configure logging to files or to

; the syslog system.

;

; "logger reload" at the CLI will reload configuration

; of the logging system.

 

[general]

; Customize the display of debug message time stamps

; this example is the ISO 8601 date format (yyyy-mm-dd HH:MM:SS)

; see strftime(3) Linux manual for format specifiers

;dateformat=%F %T

;

; This appends the hostname to the name of the log files.

;appendhostname = yes

;

; This determines whether or not we log queue events to a file

; (defaults to yes).

;queue_log = no

;

; This determines whether or not we log generic events to a file

; (defaults to yes).

;event_log = no

;

;

; For each file, specify what to log.

;

; For console logging, you set options at start of

; Asterisk with -v for verbose and -d for debug

; See 'asterisk -h' for more information.

;

; Directory for log files is configures in asterisk.conf

; option astlogdir

;

[logfiles]

;

; Format is "filename" and then "levels" of debugging to be included:

;    debug

;    notice

;    warning

;    error

;    verbose

;    dtmf

;

; Special filename "console" represents the system console

;

; We highly recommend that you DO NOT turn on debug mode if you are simply

; running a production system.  Debug mode turns on a LOT of extra messages,

; most of which you are unlikely to understand without an understanding of

; the underlying code.  Do NOT report debug messages as code issues, unless

; you have a specific issue that you are attempting to debug.  They are

; messages for just that -- debugging -- and do not rise to the level of

; something that merit your attention as an Asterisk administrator.  Debug

; messages are also very verbose and can and do fill up logfiles quickly;

; this is another reason not to have debug mode on a production system unless

; you are in the process of debugging a specific issue.

;

;debug => debug

console => notice,warning,error

;console => notice,warning,error,debug

messages => notice,warning,error

;full => notice,warning,error,debug,verbose

 

;syslog keyword : This special keyword logs to syslog facility

;

;syslog.local0 => notice,warning,error

;

 

There are some console commands associated to the logger process.

 

CLI> logger list channels

Channel                             Type     Status    Configuration

-------                             ----     ------    -------------

/var/log/asterisk/messages          File     Enabled    - Warning Notice Error

                                    Console  Enabled    - Warning Notice Error

 

CLI> logger rotate

  == Parsing '/etc/asterisk/logger.conf': Found

Asterisk Event Logger restarted

Asterisk Queue Logger restarted

 

You can control the log rotation using the logrotate daemon. Edit the file /etc/logrotate.d and include the content below to start rotating the log files.

 

/etc/logrotate.d/asterisk.

/var/log/asterisk/messages /var/log/asterisk/*log {
   missingok
   rotate 5
   weekly
   create 0640 asterisk asterisk
   postrotate
       /usr/sbin/asterisk -rx 'logger reload'
   endscript
}

 

More information about logrotate can be obtained using:

 

#man logrotate

2.11 Starting Asterisk with a non-root user

It is safer to execute Asterisk with a non-root user. In case of a security failure or a buffer overflow attack, running Asterisk within an environment with fewer privileges to the user limits the possible actions from an intruder.

 

To change Asterisk running user:

 

1)   Edit the file: vi /etc/init.d/asterisk

 

2)   Uncomment the following lines:

 

AST_USER="asterisk"

AST_GROUP="asterisk"

 

3)   To change user rights in Asterisk folders type:

 

cd /

chown --recursive asterisk:asterisk /etc/asterisk

chmod --recursive u=rwX,g=rX,o= /etc/asterisk

chown --recursive asterisk:asterisk /var/lib/asterisk

chown --recursive asterisk:asterisk /var/log/asterisk

chown --recursive asterisk:asterisk /var/run/asterisk

chown --recursive asterisk:asterisk /var/spool/asterisk

chown --recursive asterisk:asterisk /dev/zap

chmod --recursive u=rwX,g=rX,o= /var/lib/asterisk

chmod --recursive u=rwX,g=rX,o= /var/log/asterisk

chmod --recursive u=rwX,g=rX,o= /var/run/asterisk

chmod --recursive u=rwX,g=rX,o= /var/spool/asterisk

chmod --recursive u=rwX,g=rX,o= /dev/zap

 

4)   Test changes with /etc/init.d/asterisk

2.12 Asterisk installation notes

2.12.1 Production Systems

If Asterisk is installed in a production environment, you should pay attention to the system design. A server has to be optimized in such a way that telephony systems have priority over other system processes. Asterisk should not run together with processor intensive software like X-Windows for example. If you need to run CPU intensive processes like, for example, a huge database, use a separate server. Generally speaking, Asterisk is sensible to hardware performance variations. Thus, try using Asterisk in a hardware environment that does not require more than 40% of CPU utilization.

2.12.2 Network tips

If you plan to use IP phones, it is important that you pay attention to your network. Voice protocols are very good and resistant to latency and even jitter. However, if you use a poorly configured local area network, the voice quality will suffer. It is only possible to guarantee a good voice quality using QoS (Quality of Service) in switches and routers. If you use voice over the Internet (Without QoS), voice quality can be defined as best effort. Voice in a local area network tends to be good, but even in a LAN environment, if you have 10 Mbps hubs with too many collisions, you will end up having distorted or crappy voice. Follow these recommendations to ensure the best possible voice quality:

 

2.13 Summary

In this chapter you learned the minimum hardware requirements, how to download, how to install, and how to compile Asterisk. Asterisk should be executed with a non-root user for security reasons. You should check your network environment before starting a production environment.

2.14 Questions

1. What’s the minimal Asterisk hardware configuration?

 

 

 

2. Telephony interface cards for Asterisk usually have some DSPs (Digital Signal Processors) built in and do not need a lot of CPU resources from the PC.

 

a)   True

b)   False

 

3. If you want perfect voice quality, you need to implement end-to-end QoS (Quality of Service).

 

a)   True

b)   False

 

4. it’s possible to have good voice quality with 100 Mbps switches in a non congested local area network.

 

a)   True

b)   False

 

5. List the necessary packages for Asterisk and the Zaptel compilation.

 

 

 

6. If you don’t have a TDM interface card, you will end up needing a clock source for synchronization. The ztdummy driver is responsible for this role by using USB as a clock source (Kernel 2.4). This is necessary because some applications like _______ and ________ require a time reference.

 

7. When you install Asterisk, it’s better to leave GUIs uninstalled because Asterisk is sensible to performance variations. GUIs stole a lot of CPU cycles.

 

a)   True

b)   False

 

8. Asterisk configuration files are located in the ____________________ directory. 

 

9.  To install Asterisk sample files you need to type the following command:

 

 

 

10. Why is it important to start Asterisk with a non-root user?

 

 

 


 

 

Chapter 3

 
First Steps

 

In this chapter you will learn how to perform a basic Asterisk configuration.  The main objective here is for you to see the PBX running, to be able to dial between extensions, to dial to a message being played, and to dial to a single analog or SIP trunk. The idea behind this chapter is to make sure that your Asterisk is up and running as soon as possible. After working in this chapter, you will have enough background to prepare for the subsequent chapters, where we will get into configuration details.

3.1 Objectives

fig1-18

                   Figure 3.1 Objectives

3.2 Understanding the configuration files

Asterisk is controlled by text configuration files located in /etc/asterisk. The file format is similar to the Windows “.ini” files.  A semicolon is used as a remark character, the signs “=” and “=>” are equivalent and the spaces are ignored.

 

;

; The first line without a comment should be the session title.

;

[Session]

Key = value; Variable designation

[Session 2]

Key => value; Object declaration

 

Asterisk interprets “=” and “=>” in the same way. Differences in syntax are used to distinguish between objects and variables. Prefer “=” when you want to declare a variable and “=>” to designate an object.  The syntax is the same between all files but there are three types of grammar, as discussed below.

3.3 Grammars

Grammar

Object is created:

Conf. File

Example

Simple Group

All in the same line

 

 

 

 

extensions.conf

exten=>4000,1,Dial(SIP/4000)

Option Inheritance

Options are defined first, object inherit the options

zapata.conf

[channels]

context=default

signalling=fxs_ks

group=1

channel => 1

Complex Entity

Each entity receives a context

sip.conf,

iax.conf

[cisco]

type=friend

secret=mysecret

host=10.1.30.50

context=trusted

[xlite]

type=friend

secret=xlite

host=dynamic

3.3.1 Simple Group

The simple group format used in extensions.conf, meetme.conf and voicemail.conf is the most basic grammar. Each object is declared with options in the same line.

 

Example:

 

[Session]

Object 1 => op1,op2,op3

Object 2=> op1b,op2b,op3b

 

In this example, object 1 is created with options op1, op2, op3 while object 2 is created with options op1, op2 and op3.

3.3.2 Object options inheritance grammar

This format is used by zapata.conf and agents.conf where a lot of options are available and most interfaces and objects share the same options.  Typically there are one or more sections with objects and channels declarations. Options to the object are declared above the object and can be changed to another object. Although this concept is hard to understand, it is very easy to use.

 

Example:

 

[Session]

op1 = bas

op2 = adv

object=>1

op1 = int

object => 2

 

The first two lines configure the value of option op1 and op2 to “bas” and “adv” respectively. When the object 1 is instanced, it is created using option 1 as “bas” and option 2 as “adv”. After defining object 1 we have changed the option 1 to “int”. Then we create object 2 with option 1 as “int” and option 2 as “adv”.

3.3.3 Complex entity object

This format is used by iax.conf, sip.conf as well as other configuration files where there are numerous entities with many options. Typically, this format does not share a large volume of common configurations. Each entity receives a context. Sometimes there are reserved contexts like [general] for global configurations. Options are declared in the context declarations.

 

Example:

 

[entity1]

op1=value1

op2=value2

[entity2]

op1=value3

op2=value4

 

The entity [entity1] has values “value1” and “value2” for options op1 and op2, respectively. The entity [entity2] has values “value3” and “value4” for options op1 and op2.

3.4 Configuring a PSTN interface

To connect to the PSTN you will need an interface FXO (Foreign Exchange Office) and a telephone line.  You can use an existing PBX extension too. You can obtain a telephony interface card with a FXO interface from several manufacturers. In this example we will show you how to install a zaptel board.

 

fig1-14 

                   Figure 3.1 FXO end FXS Interfaces

 

Tip: There are other FXO interfaces available. A X100P clone can be found in the market for a very small price. These boards are old 56K fax/modems based on Motorola and Intel chipsets. The chipsets known to work are Motorola 68202-51, Intel 537PU, Intel 537 PG, Intel Ambient MD3200

 

There are no guaranties that this board will work. Use at your own risk. Some present eco problems and low sound volume. If you don’t want to take risks, Digium boards are a very good choice.

3.4.1 Installing a X100P

Before installing a X100P in your computer, disable all unnecessary or unused hardware from your motherboard. This will help to avoid problems with shared interrupts. In order to properly install the X100P, you will have to plug the card into a PCI slot and edit two configuration files:

 

·        “zaptel.conf“ in the /etc directory - the board configuration.

·          “zapata.conf” in the /etc/asterisk directory - this configures the Zapata channel driver.

 

Don’t be concerned at this point to understand all the details of the configuration files. We will have an entire chapter about Zapata channels. At this moment we will show an excerpt of the file. Save a copy of the file /etc/zaptel.conf to /etc/zaptel.conf.old before you begin editing.

 

zaptel.conf

 

fxsks=1

loadzone = br

defaultzone=br

channels=1

 

zapata.conf

 

[channels]

context=default

signalling=fxs_ks

group=1

channel => 1

 

After finishing editing the files, load the zaptel drivers as shown below.

 

modprobe zaptel

modprobe wcfxo

ztcfg –vvvvvv

asterisk -vvvvvgc

3.5 SIP IP phones configuration

Let’s now configure the SIP phones. The idea is to configure a simple PBX. In subsequent chapters you will have an entire SIP session with all the details. SIP is configured in the /etc/asterisk/sip.conf directory and has all the parameters related to SIP phones and VoIP providers. SIP clients have to be configured before you can make and receive calls.

3.5.1 General section

The SIP file is read from top down. The first section contains the global parameters [general]. The main options are:

 

·        allow/disallow: Defines which codecs can be used.

·        bindaddr: Address to be bond to Asterisk SIP listener. If you set it up as 0.0.0.0 (default) it will bind to all interfaces.

·        context: Sets the default context for all clients unless changed in the client section.

·        bindport: SIP UDP port to listen.

·        maxexpirey: Maximum time to register (seconds)

·        defaultexpirey: Default time to register (seconds)

·        register: Registers Asterisk to another Host.

 

Example:

 

[general]

bindport = 5060

bindaddr = 10.1.30.45

context = default

disallow = all

allow = ulaw

maxexpirey = 120

defaultexpirey = 80

3.5.2 Clients section

After finishing the general sections, it is time to set up the SIP clients. I would like to remind the reader, again, that we will have an entire SIP chapter later in the book. For now, let’s concentrate on the basics and leave the details for later.

 

·        [name]: When a SIP device connects to Asterisk, it uses the username part of the SIP URI to find the peer/user. 

·        type: Configures the connection class. Options are peer, user, and friend.

·        peer: Asterisk sends calls to a peer.

·        user: Asterisk receives calls from a user.

·        friend: Both at same time.

·        host: IP address or host name. The most common option is “dynamic”, used when the host registers to Asterisk.

·        secret:  Password to authenticate peers and users.

 

Example:

 

[cisco]

type=friend

secret=mysecret

host=10.1.30.50

context=trusted

 

[xlite]

type=friend

secret=xlite

host=dynamic

defaultip=10.1.30.17

3.6 Dial plan introduction

Dial plan is Asterisk’s heart. It defines how Asterisk handles each and every call to the PBX. It consists of extensions that make an instruction list for Asterisk to follow. Instructions are fired by digits received from the channel or application. In order to configure Asterisk successfully, it is crucial to understand the dial plan.

 

Most of the dial plan is contained in the extensions.conf file at the /etc/asterisk directory. This file uses the simple group grammar and has four major concepts:

 

·        Extensions

·        Priorities

·        Applications

·        Contexts

 

Let’s now create a basic dial plan. In subsequent sections of this book I will devote two full chapters exclusively to dial plan. If you installed the sample files (make samples), the extensions.conf already exists.  Save it with another name and start with a blank file.


3.6.1 Extensions

The dial plan is a set of defined extensions. An extension is a string that will trigger an event when a call is made.  Extensions can be either literal or pattern.

 

fig1-15

                   Figure 3.2 Extensions format

 

Example:

 

exten=>8580,1,Dial(SIP/8580,20)

exten=>8580,2,hangup()

 

The instruction “exten” describes the next step for the call. 8580 is the set of digits received (called number). The numbers “1” and “2” are priorities that define the execution order.  Dialing “8580” will ring the SIP IP phone registered as “8580”. If the call is unanswered in 20 seconds it will hang-up.

 

Extension Syntax:

 

exten=> number (name), {priority|label{+|-}offset}[(alias)],application

The extension command “exten=” is followed by an extension number or name, a comma, a priority, another comma and, finally, the application.  Extension is the matching address of the call (the phone number). Priorities are used to execute the steps in order of priority. Application is the action to be taken (dial, playback, hangup). Each action has a different application.

3.6.2 Priorities

Priorities are numbered steps for execution in each dialed extension. Each priority calls a specific application. Usually, the numbers start with “1” and increment by 1 to each line in the extension definition. In version 1.2, it is common to use the “n” priority as next, instead of manually assigning the numbers. If numbers are not sequential, execution is aborted. After version 1.2 it became possible to use labels and aliases. We will see more about this under the topic ‘Advanced examples’ in Chapter 8.

3.6.3 Applications

Applications play an important role in Asterisk. They handle voice channels, playing tones, the acceptance of digits called to the PBX, as well as call hang-up. Applications can be called with options that affect their behavior. You can use ‘core show applications’ in the Asterisk’s command line interface to show available applications. When you build your first dial plan you will start to understand what applications are appropriate.

 

CLI>core show applications

3.6.4 Contexts

figc-3 

                   Figure 3.3 Asterisk call flow

 

Contexts play an important role in Asterisk’s dial plan configuration and security.  Contexts define a scope, which allows separation of the dial plan into different parts.  It is important to understand that contexts are intimately bond to channels. When a Asterisk receives a phone call, the call is processed within its incoming context section.  The incoming context is always defined by the channel configuration file (iax.conf, sip.conf, zap.conf…).

 

Let’s suppose, for example, that you have two classes of users: “managers” and “guests”. Suppose now that want to play different messages for “guests” and “managers” when they dial “9000”. You can accomplish this by defining the incoming context in the channel files (sip.conf, iax.conf, zap.conf).

 

Example:

 

In the example below, when Mary dials 9000, she receives the message “youareaguest”. When John dials the same number, he receives a different message: “youareamanager”.

 

sip.conf

[john]

context=managers

host=dynamic

[mary]

context=guests

host=dynamic

 

extensions.conf

[managers]

exten=>9000,1,Playback(youareamanager)

[guests]

exten=>9000,1,Playback(youareaguest)

 

By understanding this concept you can create several features in Asterisk. Different contexts can be used to serve different companies and different classes of users within the same Asterisk configuration. Contexts may determine, for example, who can call long distance and who cannot.

 

Contexts receive a name inside brackets ([]). All instructions after the definition are part of the context. To start a new context, simply insert the new context. A context ends when another starts.

 

There are two special contexts in the extensions.conf file. The context [globals] is used to define variables whereas the context [general] is used to define some general options. We will look into these special contexts in chapter 8.

3.6.5 Creating a testing environment

fig1-17 

                   Figur3.4 VoIP Lab

 

For this lab we recommend that you use a FXO interface card. To create a lab like the one above, you may use a Pentium class PC with 256MB RAM for Asterisk and two other computers for the soft phone. You may use virtual machines (VMWare, VirtualPC) if you wish to use a single computer. Although voice quality will be poor, this is acceptable for testing purposes. We also recommend using the X-Lite softphone from counterpath (www.counterpath.com), although other free soft phones (e.g. SJPhone - www.sjlabs.com) may be used as well. It’s possible that the X-Lite softphone does not exist anymore by the time you read this material; you will certainly be able to find others by searching the Internet. You may also use a SIP Analog Telephony Adapter or even an SIP IP Phone. Really, it all depends on your budget.

 

Step 1: Edit the sip.conf file and add the extension 2000 configuration.

 

[general]

bindport=5060

bindaddr=10.1.30.45 ; put here the IP address of your server

context=default

allow=all

 

[2000]

type=friend

secret=2000

host=dynamic

canreinvite=no

 

Step 2: Repeat step 1 for extension 2001.

 

Step 3: Configure the softphone for extension 2000.

 

a)   Run the installation program.

b)   Press “next” in the first screen.

c)   Accept the licensing agreement.

d)   Accept the next screens. In other words NEXT->NEXT->FINISH.

e)   Get into the X-LITE menu by pressing the icon illustrated below.

 

xlite

 

f)    In the next screen, select “system settings”.

 

g)   Choose “sip proxy”.

 

h)   Choose Default.

 

i)     Complete the following fields.

 

Display Name: 2000

Username: 2000

Authorization User: 2000

Password: 2000

Domain/Realm: Asterisk IP Address

SIP Proxy: Asterisk IP Address

 

j)    Close X-LITE and open again.

 

k)   Confirm that the phone was registered to Asterisk with the sip show peers command.

 

Step 4: Repeat the configuration for extension 2001 in the other softphone.

3.7 Creating a basic dial plan

Now we are ready to start creating our first dial plan. We will use examples to explain the dial plan. Let’s move on step-by-step.

 

3.7.1 Basic example

In this example, Asterisk will receive a call, play a sound and hang-up.

 

Edit the extensions.conf file to include these entries:

 

[incoming]

exten=>s,1,answer()

exten=>s,2,playback(goodbye)

exten=>s,3,hangup()

 

Priority 1 calls the answer() application. Asterisk handles the line and sets up the call. After answering the line, it goes to the next priority.

 

Priority 2 calls the playback application() to play a sound from goodbye.gsm file. 

 

Finally, priority 3 hangs up the call.

 

Example explanation:

 

A call received by a FXO interface is sent to the incoming context, defined in the channel configuration file (zapata.conf). When an incoming call arrives it is processed in the “s” extension of the incoming context. We have three priorities, each priority calling an application.

 

The special extension “s” is used to start processing the incoming call when the number that dialed to Asterisk is not known (e.g. incoming call by an analog line).

 

If we are to answer a call, it is better to know the application that will do it. The answer() application is used to answer a channel in the ringing state. Some applications require the answer() application before processing the call.

 

The playback() application is used to play a message from a sound file previously recorded. When the application playback() is being executed, any digits pressed are ignored. The syntax is playback(filename). It plays the file with .gsm or .wav extension from the default sounds directory (/var/lib/asterisk/sounds).

 

The hangup() application does exactly what the name says. It disconnects the active channel. You should use it at the end of the call.

 

3.7.2 A more thorough example

Let’s improve upon our first example by introducing two new applications: background() and goto(). The key for interactive systems based on Asterisk is the background() application. It allows you to play a sound file while waiting for digits to be pressed. When this occurs, the sound that is playing stops and the execution goes to the digits pressed. We will look at the background application in depth in subsequent chapters.

 

Syntax for Background() application:

 

exten=>extension, priority, background(filename)

 

Other useful application is goto(). As the name implies, it jumps from the current context, extension and priority to a specific context, extension and priority.

 

Syntax for Goto() application:

 

exten=>extension, priority,goto(context,extension, priority)

 

Valid syntaxes for goto() are:

 

Goto(context,extension,priority)

Goto(extension,priority)

Goto(priority)

 

This is an example of a small company with three departments: tech support, sales, and training.  Let’s create an interactive system that allows the user to select the department called.  Firstly, we will play a greeting like, “press 1 for tech support, 2 for training, and 3 for sales”. In this simple example we won’t treat invalid digits.  After you select a department, the system will play a message like “you were directed to … department” and transfer the execution to the related context.

 

[incoming]

exten=>s,1,Answer()

exten=>s,2,Background(greeting)

exten=>s,3,hangup()

exten=>1,1,playback(support)

exten=>1,2,goto(support,s,1)

exten=>2,1,playback(training)

exten=>2,2,goto(training,s,1)

exten=>3,1,playback(sales)

exten=>3,2,goto(sales,s,1)

 

Step by step explanation:

 

When someone calls the telephone line connected to Asterisk via the FXO interface card (configured to [incoming] context in zapata.conf), the extension “s” in the [incoming] context is triggered. The extension “s” answers the call using the background application and plays a greeting message, waiting for digits to be pressed. If the user presses “1”, the system goes to extension “1” and plays a message “You were directed to tech support”. Next, extension “2” sends the execution to [support] context for further processing.

3.7.3 Bridging channels using Dial() application

We can improve our example by adding the dial() command. Instead of sending the execution to another context, we will transfer the call to an extension, directly using the dial() application

 

[incoming]

exten=>s,1,Answer()

exten=>s,2,Background(greeting)

exten=>s,3,hangup()

exten=>1,1,playback(support)

exten=>1,2,Dial(SIP/8000)

exten=>2,1,playback(training)

exten=>2,2,Dial(ZAP/1)

exten=>3,1,playback(sales)

exten=>3,2,Dial(IAX2/8002)

 

By comparing with the first example, we’ve just created a shortcut. Instead of sending the call to another context, we are now sending the call to the final channel destination. For “support”, we will direct the call to a SIP phone identified by the “8000” number. For “training” we will send the call directly to TDM (analog or digital) to the channel identified as “1”. Finally, for sales we will send the call to an IAX2 phone identified by the number “8002”.

 

At this point you should have a clear understanding of the use of several applications like answer(), background(), goto(), hangup() and playback().  If this is not clear, please read again until you feel comfortable with the content. You will need this background from now on.

 

Once you understand the basics of extensions, priorities and applications, it will be easy to create a simple dial plan. These concepts will be explored in greater depth later in the book, and you will see that the dial plan will become more powerful.


3.8 Labs

These labs will create a small PBX capable to dial between extensions, to the PSTN, or to a VoIP provider. We will configure call reception using auto attendant.

 

Lab instructions:

 

·        Extensions will range from 2000 to 2100

·        To dial the PSTN you will need to dial 9 first

·        To dial external call via VoIP provider you will need to dial 1 first

·        8000 should be used to record the message for the auto-attendant.

3.8.1 Calling between phones

Step 1: Edit the extensions.conf file inside the [default] section with the following commands.

 

[default]

exten=>2000,1,Dial(SIP/2000)

exten=>2001,1,Dial(SIP/2001)

 

Step 2: Reload the asterisk extensions

 

CLI>dialplan reload

 

Step 3: Test dialing between 2000 and 2001 softphones.

3.8.2 Calling PSTN using the zaptel interface card (FXO)

Step 1: Edit extensions.conf

 

[default]

exten=>0,1,Dial(ZAP/1,20,r)

 

Step 2: Reload Asterisk extensions

 

CLI>dialplan reload

 

Step 3: Test dialing 0. You will receive an external dial tone, then dial the destination number.


3.8.3 Auto-attendant

Step 1: Edit the extensions.conf to include an interface to record the message for the auto-attendant.

 

[default]

exten=>8000,1,Wait(2)

exten=>8000,2,Record(menu:gsm)

exten=>8000,3,Wait(2)

exten=>8000,4,Playback(menu)

exten=>8000,5,Hangup()

 

Step 2: Reload the extensions and dial 8000. Record a message like “Welcome to the XYZ company, dial the extension number”. Press “#” at the end to finish recording. You will hear the recorded message when playback is executed.

 

Step 3: Edit the extensions.conf to include the receiving menu.

 

[default]

exten=>s,1,Background(menu)

exten=>s,2,Dial(SIP/2000)

exten=>2000,1,Dial(SIP/2000)

exten=>2001,1,Dial(SIP/2001)

 

Step 4: Dial from your cell phone (or another external phone) to the line connected to Asterisk. You will hear an auto-attendant message. Dial 2000 to be transferred to the 2000 extension.

3.9 Summary

In this chapter you learned that configuration files are stored in the /etc/asterisk directory. To use Asterisk, it is necessary, in the first place, to configure the channels (e.g. sip, zapata, iax). There are three different grammars for configuration files, simple group, object inheritance, and complex entity. The dial plan is created in the extensions.conf file and is a set of contexts and extensions. In the dial plan each extension triggers an application and you learned to use playback, background, dial, goto, hangup and answer applications.

3.10 Questions

1. These are channel configuration files

 

a)   zaptel.conf

b)   zapata.conf

c)   sip.conf

d)   iax.conf

 

2. It is important to define a context in the channel configuration file, because this will define the incoming context for a call. In the extensions configuration file (extensions.conf) a call from this channel will be processed in the matching incoming context.

 

a)   True

b)   False

 

3. The main differences between the playback() and background() applications are (choose two):

 

a)   Playback simply plays a prompt, but does not wait for digits.

b)   Background simply plays a prompt, but does not wait for digits.

c)   Background plays a message and waits for digits to be pressed

d)   Playback plays message and waits for digits to be pressed

 

4. When a call gets into Asterisk using a telephony interface card (FXO) this call is handled in the special extension:

 

a)   ‘0’

b)   ‘9’

c)   ‘s’

d)   ‘i’

 

5. Valid formats for the goto() application are (choose three):

 

a)   Goto(context,extension, priority)

b)   Goto(priority, context, extension)

c)   Goto(extension,priority)

d)   Goto(priority)

 

6. An extension cannot be defined as (choose all correct answers):

 

a)   An alphanumeric literal

b)   A numeric literal

c)   A pattern beginning with a “_” (dot) character

d)   A pattern starting with a “_” (underscore) character

 

7. A pattern _7[1-5]XX matches (choose all correct answers):

 

a)   7100

b)   7600

c)   7630

d)   7230

 

8. An incoming context for a zaptel compatible telephony interface is defined in the _________ configuration file:

 

a)   zaptel.conf

b)   zapata.conf

c)   asterisk.conf

d)   modules.conf

 

9. In the Options Inheritance grammar used by zapata.conf you:

 

a)   Define the object in a single line

b)   Define options first and declare the objects below the defined options

c)   Define a context for each object

 

10. Priorities must be consecutive!

 

a)   False

b)   True

 



[1] TDM – Time division multiplexing. Today most of digital telephony is based on this concept. With TDM you can use 24 to 30 voice circuits in a single T1 or E1 connection respectively. T1 is mostly used in the USA while E1 is common in Europe.