Freitag, 25. April 2008

Using the Asterisk Voip PBX as SIP Mediaserver

Here I show how the open source Voip PBX Asterisk can be used as a simple mediaserver for Sip applications.

Prerequisites

  • I use the AsteriskNOW software appliance which is prepackaged ready-to-run version of Asterisk. It can be downloaded from http://www.asterisknow.org/downloads . There is a very good documentation avaliable as PDF download from Asterisk Book Download .
  • Asterisk is running on Linux only, so in order to run it on Windows or other OS you need a virtual machine environment e.g. VMware. The download from AsteriskNOW is an ISO image, to run it on VMWare you need VMWare Server which you can get for free from http://www.vmware.com/download/server/ . Alternatively you can use VMware Player and run an Asterisk Virtual Appliance which you can get from the VMware virtual appliance directory at http://www.vmware.com/appliances/ .
  • I prefer to run it from VMware Server. To install it create a new virtual machine, insert a CD made from the ISO image or mount the image directly and follow the instructions of the graphic installer. There is quickstart guide available at http://www.asterisknow.org/support/install .
  • Asterisk provides a Web based administration, but for our usecases it is required to have direct access to the Asterisk console. Use an ssh client (e.g. Putty from http://www.chiark.greenend.org.uk/~sgtatham/putty/ ) to connect to the Asterisk server.

Configuration

  • Connect to Asterisk using the ssh client and login (default user is admin and password is password). Configuration of Asterisk is done by editing various configuration files. When you edit the configuration files you must give yourself the access rights with sudo, e.g sudo vi sip.conf.
  • The sip configuration file is sip.conf in /etc/asterisk. Rename the file from the installation (it is very complicated and contains lots of examples) and create a new sip.conf as follows:

    [general]
    context=default
    allowoverlap=no
    bindport=5060
    bindaddr=0.0.0.0
    srvlookup=yes
    [sailfin]
    type=peer
    context=from-fwd
    host=192.168.0.12
    insecure=port

    The configuration is done by declaring contexts, in our case the sailfin context, type=peer means that this context can only receive calls.The host address has to be replaced with the ip address of the sailfin server (yes the sailfin server since it is the peer, not the Asterisk server). Detailed explanation about contents can be found in the Asterisk book.
  • The next configuration file is extensions.conf, which contains the dialplan. Rename the file and create a new one like for sip.conf. A dialplan tells Asterisk what to do when a call is received. In our example we are using a very simple dialplan which tells Asterisk to play an announcement when a callis received on a certain extension.

    [from-fwd]
    exten => 1234,1,Answer()
    exten => 1234,2,Playback(to-reach-operator)
    exten => 1234,3,Hangup()


    When a call is received for the context from-fwd with the extension 1234 the call is answered, then an announcement is played and the call is finished. Announcement are defined as .wav files with a full path, if no path is specified the default directory /var/lib/asterisk/sounds is used.
  • To activate the context type sip reload from the console (the console can be reached from the Asterisk main menu with ALT-F9). There are many other sip related console commands, they are explained in detail in the Asterisk book in appendix E.
  • The log files for sip can be found in /var/log/asterisk in file full, errors are in file messages.
  • When you now make a sip call to Asterisk (sip:1234@192.168.0.12 in our example) Asterisk answers the call with 200 OK, then receives an ACK, plays the announcement and ends the call with BYE when the announcement is finished.

Next Steps

The usecase described here is an extremely simple one, Asterisk can do much more than that, e.g. it can act as

  • IVR with voice menus reacting on keypresses and event database access.
  • Voice mail server
  • Call recording server

I will try to explore these possibilities and explain in a future post.