PHP, Linux and the like…

September 4, 2007

Basic Asterisk Configuration

Filed under: Asterisk, Fedora Core, Telephony — Paul Skinner @ 1:29 am

I really like the stats package included with WordPress, it provides an excellent source of ideas for what I should write about next. Many of you reach me through a post titled Asterisk and Fedora Core 7 looking for more specifics on how to configure Asterisk. If you need to install Asterisk on FC7, read the Asterisk and Fedora Core 7 post first.

Alright, so you’ve got Asterisk installed but its not configured or has the default Asterisk sample configuration files.

The Asterisk configuration files are found in /etc/asterisk. If you are using Asterisk without telephony hardware, you really need to be concerned with 2 or 3 files. Of importance are the following files

  1. sip.conf: this file contains everything to do with the SIP protocol, settings and authentication for Asterisk.
  2. extensions.conf: At the most basic level, this file contains the call-plan; what happens on in-bound calls and how outgoing calls are to be treated.

You’re also going to need something to test Asterisk with. Either a soft-phone such as X-Lite or a handset device such as a Polycom 430, or a ATA device, such as the LinkSys PAP-2.

For the sake of this sample, we’re going to configure Asterisk to handle the SIP registration of 3 IP devices.

  1. X-Lite Softphone [extension 203]
  2. a Polycom 301 [extension 200]
  3. a Linksys PAP-2 (Vonage un-locked) [extensions 201 and 202]

sip.conf is easy enough to get going; some advanced features found on some handsets may require additional settings but to keep things simple lets start with the softphone alone.

Backup your existing /etc/asterisk/sip.conf and go with something like this

[general]
port=5060
bindaddr=0.0.0.0
context=home
tos=0x18
nat=yes
externip=YOUR PUBLIC IP
disallow=all
allow=g729
allow=gsm
allow=ulaw

[203]
type=friend
host=dynamic
context=home
secret=agoodsippasswordgoeshere
callerid=CIA FBI ATF <1-555-555-5555>
dtmfmode=rfc2833
nat=yes
mailbox=200@home
disallow=all
allow=ulaw

Feel free to have some fun with the “callerid” parameter, you can have some great fun with your friends and family.

Make a backup of /etc/asterisk/extensions.conf and replace it with this

[general]

static=yes
writeprotect=no

[home]
exten => 55,1,Playback(demo-echotest) ; Let them know what's going on
exten => 55,2,Echo ; Do the echo test
exten => 55,3,Playback(demo-echodone) ; Let them know it's over

This bare bones configuration sets up extension 55 in the “home” context to be an echo server.

Get Asterisk to re-read the sip.conf and extensions.conf files (if already running, to start Asterisk, just run “asterisk” as root).

[root@athlon asterisk]# asterisk -r
Asterisk 1.2.20, Copyright (C) 1999 - 2007 Digium, Inc. and others.
Created by Mark Spencer <markster@digium.com>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'show license' for details.
=========================================================================
Connected to Asterisk 1.2.20 currently running on athlon (pid = 3193)
Verbosity is at least 42
athlon*CLI> sip reload
 Reloading SIP
  == Parsing '/etc/asterisk/sip.conf': Found
  == Parsing '/etc/asterisk/sip_notify.conf': Found
athlon*CLI> extensions reload
  == Parsing '/etc/asterisk/extensions.conf': Found
    -- Registered extension context 'home'
    -- Added extension '55' priority 1 to home
    -- Added extension '55' priority 2 to home
    -- Added extension '55' priority 3 to home
athlon*CLI>

Configure the X-Lite phone by adding a SIP account with the following details:

X-Lite Account Details

Save the settings and X-Lite should register with Asterisk. If watching the Asterisk CLI, you should see the following

Connected to Asterisk 1.2.20 currently running on athlon (pid = 3193)
Verbosity is at least 42
    -- Remote UNIX connection
    -- Registered SIP '203' at 10.10.50.198 port 14126 expires 3600
    -- Saved useragent "X-Lite release 1011s stamp 41150" for peer 203
athlon*CLI>

X-Lite SIP account 203 registered

At this point you should be able to dial the echo server. Go ahead and dial “55″ and hit the green send button. You’ll connect with the “Echo Test”, basically just echoes whatever you say to it. It’s simple but a great way to get the basics right without having to deal with the large “sample” configuration files.

If your call to the echo server worked, the rest of the setup is basically the same as before, editing both the sip.conf and extensions.conf files.

Moving on, lets add the other extensions to the mix. We’ll have our own little PBX by the end of this!

Add the rest of the SIP devices to the sip.conf file

[general]
port=5060
bindaddr=0.0.0.0
context=home
tos=0x18
nat=yes
externip=YOUR PUBLIC IP
disallow=all
allow=g729
allow=gsm
allow=ulaw

[200]
type=peer
host=dynamic
context=home
secret=agoodsippasswordgoeshere
callerid= CITY MORGUE
dtmfmode=rfc2833
nat=yes
mailbox=200@home
disallow=all
allow=ulaw

[201]
type=friend
host=dynamic
context=home
secret=agoodsippasswordgoeshere
callerid= CITY MORGUE
dtmfmode=rfc2833
nat=yes
mailbox=200@home
disallow=all
allow=ulaw

[202]
type=friend
host=dynamic
context=home
secret=agoodsippasswordgoeshere
callerid= CITY MORGUE
dtmfmode=rfc2833
nat=yes
mailbox=200@home
disallow=all
allow=ulaw

[203]
type=friend
host=dynamic
context=home
secret=agoodsippasswordgoeshere
callerid=CIA FBI ATF
dtmfmode=rfc2833
nat=yes
mailbox=200@home
disallow=all
allow=ulaw

Now lets add the sip registrations to the extensions.conf file so that calls can be placed amongst the devices.

[general]

static=yes
writeprotect=no

[home]
exten => 55,1,Playback(demo-echotest) ; Let them know what's going on
exten => 55,2,Echo ; Do the echo test
exten => 55,3,Playback(demo-echodone) ; Let them know it's over
exten => 200,1,Dial(SIP/200,20)
exten => 201,1,Dial(SIP/201,60)
exten => 202,1,Dial(SIP/202,60)
exten => 203,1,Dial(SIP/203,60)

Reload sip.conf and extensions.conf and you should now be able to place calls between the registered devices and each device should be able to dial the echo server.

This is a very basic Asterisk configuration that should allow you to further explore other Asterisk options. In the next parts of this post, we’ll explore adding “trunking” with a VoIP provider, ZapTel hardware and voice mail with email notification (In no particular order).

July 30, 2007

Asterisk and Fedora Core 7

Filed under: Asterisk, Fedora Core, Linux, Telephony — Paul Skinner @ 4:12 am

Looking over my blog stats, most of you reach me via a Google search for FC7 and Asterisk. With that, this post will detail installing Asterisk on FC6-7 or any modern Linux distribution for that matter as nothing here is Fedora specific anyways.

Getting Asterisk compiled and installed is quite trivial, so I thought it would be wise to spend a few moments examining the hardware you intend to use with Asterisk. If you are using a PSTN interface card through ZapTel such as Digium TDM or something else, you need to be aware that these cards generate a tremendous number of interrupts during their operation and the target system must be able to handle these interrupts quickly.

I’ve deployed Asterisk at the office where it provides call queues, automatic attendant, voice-mail and telephony services for 30+ people. This particular setup runs on a Dell 2850 with 1GB of RAM at 3.0ghz with a Digium TDM2400 card to analog PSTN lines. This setup’s load average rarely peeks over 0.01 during the day and the only complaint is occasional echo on the PSTN lines. We will soon be ditching the PSTN lines in favour of SIP channels from Primus providing both a huge cost savings and improved call quality.

At home, I’ve run Asterisk on a PIII-800 with 256MB of RAM using SIP only (no PSTN hardware) and have never had a problem with load related glitching or call drops.

The point in all this is to ensure that you select hardware appropriate for the application; don’t expect that old surplus P-III550 to serve as a corporate PBX for very long; but for home purposes that’ll only ever have 1 or 2 concurrent calls, it’ll probably be fine.

If you go with PSTN hardware, make sure to run the “zaptest” (or other for non-Zaptel hardware) program to test the interrupt timings.

Getting on with the installation, you should probably start by making sure any distribution specific Asterisk packages or Asterisk look-a-like clones are removed before you start. On FC7, OpenPBX is an available package, but in my opinion isn’t worth wasting the download. Go and get Asterisk from Digium directly and build your own.

This assumes you have a working build environment; generally the development packages for your particular distribution should have installed the basics like “make” and “gcc”… You’re really on your own here.

We’re going to be compiling Asterisk 1.2 at this time. Although 1.4 is out and in reasonable shape, I only have 1.2 experience and I’m quite happy with it so far.

Download the following source packages:

Asterisk 1.2.23 The Asterisk Code

Add-Ons 1.2.7 Asterisk Add-ons

Asterisk Sounds Pre-Recorded PBX sounds.

If you are going to be using ZapTel hardware, you’re going to have to build a kernel module. Download ZapTel as well.

To make things really easy, I’m going to include the commands to get this done. Lets start with Asterisk. Get, untar and build.

[skin@borg ~]$ mkdir asterisk
[skin@borg ~]$ cd asterisk/
[skin@borg asterisk]$ ls
[skin@borg asterisk]$ wget http://ftp.digium.com/pub/asterisk/releases/asterisk-1.2.23.tar.gz
--21:22:42--  http://ftp.digium.com/pub/asterisk/releases/asterisk-1.2.23.tar.gz
Resolving ftp.digium.com... 216.27.40.102
Connecting to ftp.digium.com|216.27.40.102|:80... connected.
...downloading...
[skin@borg asterisk]$ tar -xzvf asterisk-1.2.23.tar.gz
... lots of files...
[skin@borg asterisk]$ cd  asterisk-1.2.23
[skin@borg asterisk-1.2.23]$ make
...compiling...
 +--------- Asterisk Build Complete ---------+
 + Asterisk has successfully been built, but +
 + cannot be run before being installed by   +
 + running:                                  +
 +                                           +
 +               make install                +
 +-------------------------------------------+
[skin@borg asterisk-1.2.23]$ su root -c "make install"
[skin@borg asterisk-1.2.23]$ su root -c "make samples"

If everything worked out, you are the proud owner of a new Asterisk installation. There are a couple more things that need to be done though.

Lets do the sounds next.

[skin@borg asterisk-1.2.23]$ cd ..
[skin@borg asterisk]$ wget http://ftp.digium.com/pub/asterisk/releases/asterisk-sounds-1.2.1.tar.gz
[skin@borg asterisk]$ tar -xzvf asterisk-sounds-1.2.1.tar.gz
[skin@borg asterisk]$ cd asterisk-sounds-1.2.1
[skin@borg asterisk-sounds-1.2.1]$ su root -c "make install"

Lets do the add-ons now. If you want to use MySQL for CDR support, you need to make sure the MySQL-devel packages are installed for your distro before you run this. It going to look for mysql.h, errmsg.h and mysql_version.h.

[skin@borg asterisk]$ cd ..
[skin@borg asterisk]$ wget http://ftp.digium.com/pub/asterisk/releases/asterisk-addons-1.2.7.tar.gz
[skin@borg asterisk]$ tar -xzvf asterisk-addons-1.2.7.tar.gz
[skin@borg asterisk]$ cd asterisk-addons-1.2.7
[skin@borg asterisk-addons-1.2.7]$  make
[skin@borg asterisk-addons-1.2.7]$  su root -c "make install"

At this point, you should have a fully installed, ready for configuration Asterisk PBX. The installation gets a little more complicated if you need ZapTel for some PSTN hardware. If you’re planning to use the Conference Room feature, you’re going to need a ZapTel timer even if you don’t have hardware. It probably a good idea to build ZapTel anyways.

Like above, Get, untar, and build ZapTel.

[skin@borg asterisk-addons-1.2.7]$ cd ..
[skin@borg asterisk]$ wget http://ftp.digium.com/pub/zaptel/releases/zaptel-1.2.19.tar.gz
[skin@borg asterisk]$ tar -xzvf zaptel-1.2.19.tar.gz
[skin@borg asterisk]$ cd zaptel-1.2.19
[skin@borg asterisk]$ make
[skin@borg asterisk]$ su root -c "make install"
Building /etc/modprobe.d/zaptel...
***
*** WARNING:
*** If you had custom settings in /etc/modprobe.d/zaptel,
*** they have been moved to /etc/modprobe.d/zaptel.bak.
***
*** In the future, do not edit /etc/modprobe.d/zaptel, but
*** instead put your changes in another file
*** in the same directory so that they will not
*** be overwritten by future Zaptel updates.
***

Now we can try the ZapTel basics. Become root and try:

[root@borg ~]# modprobe zaptel
[root@borg ~]# lsmod
Module                  Size  Used by
wctdm                  37056  0
zaptel                183972  1 wctdm
crc_ccitt               6337  1 zaptel
.
.
.

The lsmod should show ZapTel loaded. This doesn’t imply that your hardware is configured, just that the ZapTel basics are in place. You’ll have to reference the specific module and configuration for your hardware, but the basics should be in place to get you going.

July 9, 2007

Fedora Core 7: OpenPBX

Filed under: Asterisk, Fedora Core, Linux, Reviews, Telephony — Paul Skinner @ 7:08 am

Following the theme of my previous post on Fedora Core 7, I really wanted to touch on my experience with OpenPBX.

Just for a bit of background, we’ve opted out of traditional telephone in favour of a SIP based VoIP, provided by a Montreal area re-seller named BabyTel. I had figured out and configured BabyTel to run under Asterisk 1.2 on my HP NetServ machine where it was happily doing its job answering the phone and taking messages etc… However, with all this swapping and upgrading, the HP NetServ is being retired.

So, looking through the FC7 package manager I see a listing for OpenPBX; I dig a bit deeper. OpenPBX is built on Asterisk and is somewhat different. Here’s what the authors claim make it different.

  • OpenPBX.org has built-in STUN support for SIP NAT traversal
  • OpenPBX.org uses SpanDSP which means better codecs and full T.38 fax over IP support
  • OpenPBX.org uses Sqlite instead of Berkeley DB as its internal database
  • OpenPBX.org has a universal jitterbuffer for use with any channel type
  • OpenPBX.org uses POSIX timers which means there are no Zaptel timing dependencies
  • OpenPBX.org has much faster and more efficient dialplan execution because it uses hashing
  • OpenPBX.org evaluates correctness and integrity of configuration data (work in progress)
  • OpenPBX.org runs well under a virtual machine such as Xen or VMware

Looking at this list, one assumes that the basics work and the folks at OpenPBX are diligently working on icing and candy. Sounds pretty good right? Prepackaged solution, easy to install, standard Asterisk config? What could go wrong?

So I embarked on the journey; OpenPBX installed via the FC7 Package Manager and then configuration began…

Having working extension.conf, sip.conf and voicemail.conf files, the theory is you should be able to drop these files in and basically start OpenPBX and life should go on. So, I grabbed the files off the old Asterisk server and copied them to /etc/openpbx.org/ on the new rig.

The copy was immediately followed by a service openpbx start.

Lo and behold, OpenPBX did start and did register the SIP channel with BabyTel. So I proceeded with a test call to the local talking clock (613-745-1576); great success! The call was answered and I was told the time.

Next and finally I moved onto voicemail. My callplan has the * key linked with VoiceMailMain; so to access any voicemail that was left, one would simply dial * and follow the prompts.

As soon as I tried the * key from a desktop phone; “click” the call was dropped. Looking through the logs the problem seems obvious; OpenPBX doesn’t ship with sound files.

Right around here is where OpenPBX begins to resemble a jet engine, in that it concurrently sucks and blows. I begin to search of a tarball of sound files for OpenPBX. OpenPBX seems to be a product without a real identity; searching for OpenPBX yields a sparse wiki and something much worse called CallWeaver. It would seem that OpenPBX is now something called CallWeaver. Take your pick, documentation for both packages is just plain terrible.

After searching and following countless 404’s the sound files were eventually fished out of svn://svn.openpbx.org/openpbx-sounds/trunk/sounds/ using svn. These files included a Make that ran each WAV through SOX for formatting presumably. Once complete the files were copied to the sound path specified in OpenPBX’s config files.

So, I try again. Dial voicemail using “*”. Click… hangup.

In the log again, this time its bemoaning the fact that it cannot find a codec to handle the translation of ulaw to g729. Which I suppose is fine as there is no g729 codec installed under OpenPBX. I deal with this by removing all references to g729 from SIP.conf to see if that helps.

Reloaded OpenPBX and tried again… A similar error this time; Unable to find a codec translation path.

mmmmkay. So now its bitching about codec paths that aren’t even configured. I figured a “reload” was enough, so I stopped and started OpenPBX. During the subsequent start-up it complained about the g729 codec. Loader.c: /usr/lib/openpbx.org/modules/codec_g729.so: undefined symbol: ast_log.

Assuming that an Asterisk compatible module would work in OpenPBX was a mistake. Based on the error one can only assume that in the process of “making” OpenPBX the authors did a wholesale “Find and Replace” on certain “asterisk” like words that resulted in breaking binary compatibility all over the place.

With a sour mouthful of OpenPBX tainting my palette, enoughs enough. YUM was called in to remove OpenPBX with extreme prejudice. I visited the Asterisk home page, downloaded the latest version of Asterisk and the supporting files and rolled-my-own build of Asterisk. I copied my configuration and g729 codec over and rigged up an init.d script based on the stock proftpd script.

First try, the talking clock worked.

Second try, the voicemail worked.

Given the 5 minutes of effort it took to download, compile, install and configure it took to get Asterisk going, I feel I’m way ahead of the 2 hours I’ve been tooling around with OpenPBX.

Why I can’t recommend OpenPBX to anyone:

  1. Its a package looking for an identity. Not very clear what it is… or who is in charge of it.
  2. The name change from OpenPBX to Callweaver further skews this identity.
  3. Documentation is piss-poor. You might as well look up Asterisk how-to docs or use voip.info.org .
  4. Binary compatibility with Asterisk is broken
  5. Doesn’t seem to persist SIP registration between shutdowns. All the devices need to re-register. There may be a setting for this… but Asterisk does this out-of-the-box
  6. Uses SQLite… but it doesn’t work nor is there any documentation to help.
  7. Installation does not work out-of-the-box. There are a number of obscure downloads and builds required.

What does it have going for it?

  1. Its a FC7 package. Maybe the worst one, but its easy to install but easy stops there!

Recommendation? Stay away. Get the real-deal from Asterisk. It works and has a future.

Blog at WordPress.com.