Title: Rapid VoIP Application Development On Linux
1Rapid VoIP Application Development On Linux
- Moisés Humberto Silva Salmerón
- System i Access for Linux Development
2 Agenda Demystifying VoIP
- What VoIP is not
- What is VoIP?
- Consequences of VoIP
- What is a PBX?
- Common VoIP solutions
- Next generation VoIP solutions
3 Agenda Application Development On Asterisk
- What is Asterisk?
- Development with Asterisk Extension Language
- Asterisk Gateway Interface
- Asterisk Manager Interface
4 What VoIP is not
- Not yet a full replacement for POTS (Plain Old
Telephony Service). - Not a cheap way to make long distance calls.
- Not making calls over the Internet.
5 What is VoIP?
- Transmission of voice frames using IP network
facilities. - UDP is preferred over TCP because of the real
time nature of telephony calls. - Integration of telephony services in IP networks.
6 Consequences of VoIP
- Cheap calls. Side effect due to the way Internet
Service Providers usually charge for Internet
access. - Flexible communication.
- Easy service integration and convergence.
Telephony is now just another service in the IP
network. - Number portability. You can be reached wherever
you are.
7 What is a PBX?
- Private Branch Exchange.
- Communication system to connect company private
telephony network with the PSTN ( Public Switched
Telephony Network ) . - Provide services like IVR ( Interactive Voice
Response ) menus, voice mail, conferences.
8 Common VoIP solutions
- CISCO Call Manager.
- Avaya.
- Nortel.
- 3COM.
9 Next generation VoIP solutions
better off with software ...
- IBM System i with 3com software on Linux LPAR.
- IBM System i with Nortel software on Linux LPAR.
10 Next generation VoIP solutions
even better with free software.Open
source solutions exist, and can be used on any
Linux computer, including high performance
systems like the IBM System i.
- IBM System i with Asterisk on Linux LPAR.
- IBM System i with FreeSWITCH on Linux LPAR.
11 Application Development On Asterisk
12 What is Asterisk?
- Software PBX project started by Mark Spencer.
- Current development is led by Digium, a company
founded because of the great Asterisk business
potential. - Hundreds of programmers all over the world
contribute. Code is under GNU General Public
License, however, another business-friendly
license is available for a fee. - FreeSWITCH, a similar project, is coming quickly
with a more business-friendly license ( Mozilla
Public License ).
13 What is Asterisk?
- Supported IP technologies include
- SIP ( Session Initiation Protocol )
- H.323
- RTP ( Real Time Protocol )
- IAX2 ( Inter Asterisk Exchange )
- SCCP ( Skinny Client Control Protocol )
- MGCP ( Media Gateway Control Protocol )
- Jingle ( Designed by Google XMMP standards
foundation )
14 What is Asterisk?
- Non-IP supported technologies include
- E1 / T1 ( CAS, CCS, HDB3 etc )
- ISDN / PRI
- MFC / R2
- FXO / FXS
- SS7
- TDMoE ( Time Division Multiplexing over Ethernet )
15 Asterisk Extension Language
- AEL is a pseudo-scripting language to control
incoming and outgoing calls in the Asterisk PBX. - Common development path is
- Specify in configuration file which function to
execute when new incoming call arrives from
specific device. - Match the dialed number against valid patterns
list. - Start executing applications based on the dialed
number and identity of the caller.
16 Asterisk Extension Language
- Number matching is done using the following
patterns - X
- X means any digit from 0 to 9.
- N
- N means any digit from 2 to 9.
- 123
- Brackets are used to group random digits. In this
case it means any number 1, 2 or 3. - 1-7
- Brackets with 2 numbers separated by a dash
represents a range of numbers. In this case any
number from 1 to 7. - s
- The 's' is a special pattern used in devices that
do not send a number to the PBX, like FXS devices.
17 Asterisk Extension Language
context default _XXX gt
Answer() Playback(hello-world)
Hangup()
18 Asterisk Extension Language
- Variables are defined and used in a similar way
to other scripting languages - myvariablemyvalue
- myvariable
- Substring can be obtained using var03
- String length LEN(var)
- String concatenation myvar1myvar2
19 Asterisk Extension Language
- Matching different patterns.
context common_users _XX gt
Answer() Dial(SIP/EXTEN)
Hangup() _XXXX
gt Answer()
Dial(IAX2/EXTEN) Hangup()
_0NX gt Answer()
Dial(Zap/g1/EXTEN) Hangup()
20 Asterisk Extension Language
- Some applications, like Dial(), return status
through setting special variables, like
DIALSTATUS. - Other functionality is offered through the use of
special variables, some of the most used are - EXTEN current dialed number
- LANGUAGE two-letter language code
- CHANNEL current channel name
- EPOCH Unix time
- More ...
21 Asterisk Extension Language
- Catching Dial() return value.
context dial_catcher _X. gt
Answer()
Dial(IAX2/userrsakey_at_myvoipserver.host.com/EX
TEN) switch (DIALSTATUS) case
BUSY NoOp(Peer is busy!) break case
CHANUNAVAIL NoOp(Failure, channel is
unavailable) break case
NOANSWER NoOp(Nobody answered on the other
side!) break default NoOp(Dial
status is DIALSTATUS) Hangup()
22 Asterisk Extension Language
- Creating and using macros.
macro handle-dial-response( response, peer )
switch(response) case
NOANSWER NoOp(No response from
peer) break default Playback(invalid
) NoOp(Yikes! Don't know what to
do!) context default _X. gt
Answer() Dial(SIP/test) handle-dial-res
ponse(DIALSTATUS,test) Hangup()
23 Asterisk Extension Language Commonly used
Asterisk applications
- Answer()
- Dial()
- Playback()
- Background()
- Playtones()
- SetLanguage()
- Bridge()
- MeetMe()
- Festival()
24 Asterisk Gateway Interface
- AGI() is a special Asterisk application to
control call flow through any programming
language using stdin and stdout. - AGI launches a whole new process that is
connected to Asterisk thread only through file
descriptors 1 and 2. - Anything your program writes to STDOUT will be
interpreted by Asterisk as a command. - Anything your program reads from STDIN is a
command response sent by Asterisk. - Enabling agi debug will help to detect errors.
25 Asterisk Gateway Interface
26 Asterisk Gateway Interface
lt?php s do s fread(STDIN,
1024) while ( FALSE strpos(s,
agi_accountcode) ) print EXEC Playback
hello-world ?gt
context default _XXX gt
Answer() AGI(hello-world.php)
Hangup()
27 Asterisk Gateway Interface
- Asterisk send call information to the AGI
program, each line in format agi_parameter
value\n - Most relevant values are
- agi_request Name of the called program.
- agi_channel Name of the created channel.
- agi_language Language defined for the channel.
- agi_type Type of channel technology ( SIP, IAX2
etc). - agi_uniqueid Unique id generated for this call.
- agi_callerid Numeric caller ID.
- agi_dnid Requested number.
28 Asterisk Gateway Interface
- Reading call information values.
!/usr/bin/php lt?php call_env array() do
read_string fread(STDIN, 1024)
read_lines explode("\n", read_string)
foreach ( read_lines as read_line )
if ( FALSE ! strpos(read_line, "") )
list(parameter_name,
parameter_value) explode("", read_line, 2)
parameter_value
trim(parameter_value)
call_envparameter_name parameter_value
while (
!array_key_exists('agi_accountcode', call_env)
) print "EXEC SayDigits call_env'agi_dnid'\
n" print "EXEC DIAL SIP/call_env'agi_dnid'\n
" ?gt
29 Asterisk Gateway Interface
- Asterisk sends a command response that programs
can read from standard input. - Response format 200 resultltresgt (optional
data) - Common responses
- 200 result1
- 200 result1 (some variable value)
- 200 result0 (timeout)
30 Asterisk Gateway Interface
print "GET VARIABLE EXTEN\n" response
fread(STDIN, 1024) eregi(response_regexp,
response, matches) result
matches1 data isset(matches2) ?
matches2 '' file_put_contents('/tmp/agi.lo
g', "result is result\ndata is data",
FILE_APPEND)
31 Asterisk Manager Interface
- AMI is a TCP/IP service exposed by Asterisk.
- Clients can send commands to Asterisk and read
the command results from the TCP socket. - In contrast with AGI, AMI is an interface to the
whole PBX, not to just 1 channel in the PBX. - Clients can listen for telephony events like
- New incoming / outgoing call.
- DTMF digits received / sent.
- Call progress ( Ringing, Answered, Cancelled etc.
). - Device registration.
32 Asterisk Manager Interface
33 Asterisk Manager Interface
- 3 different AMI messages can be sent/received.
- Action
- Response
- Event
- Actions are sent by clients, with an optional
ActionID. - Response to the action is sent by Asterisk, if an
ActionID was provided it is included in the
response message. - Event messages are sent by Asterisk at any time.
34 Asterisk Manager Interface
- AMI messages have the following format
ltMessage typegt ltMessage valuegtltCRLFgt ltHeader1gt
ltHeader 1 valuegtltCRLFgt ltHeader2gt ltHeader 2
valuegtltCRLFgt ltHeader Ngt ltHeader N
valuegtltCRLFgt ltCRLFgt
35 Asterisk Manager Interface
- Commonly used AMI commands.
- Login. Authenticate to start a manager session.
- Originate. Starts a new call to the specified end
point. - PlayDTMF. Send DTMF on the specified channel.
- Redirect. Transfer 1 or 2 legs of the call.
- Monitor. Start to record audio on the specified
channel. - StopMonitor. Stop audio recording on the
specified channel. - Hangup. Hangup the specified channel.
- Logoff. End manager session.
36 Asterisk Manager Interface
- Login into the Asterisk Manager Interface.
/ open the manager socket / manager_socket
fsockopen('localhost', 5038, errno, errstr) /
read the Asterisk welcome message / welcome
fread(manager_socket, 1024) print welcome
. "\n" / Write Login Action data in several
steps for clarity / fwrite(manager_socket,
"Action Login\r\n") fwrite(manager_socket,
"Username test\r\n") fwrite(manager_socket,
"Secret test\r\n") fwrite(manager_socket,
"\r\n") / read login response / response
fread(manager_socket, 1024) print response
. "\n"
37 Asterisk Manager Interface
- After login, we can originate a call to any end
point.
/ send Originate Action /
fwrite(manager_socket, "Action
Originate\r\n")
fwrite(manager_socket, "Channel SIP/33\r\n")
fwrite(manager_socket, "Context
hello-world\r\n")
fwrite(manager_socket, "Exten s\r\n")
fwrite(manager_socket, "Priority
1\r\n") fwrite(manager_socket,
"\r\n") response
fread(manager_socket, 1024)
print response
- Call will be originated to end point SIP/33 and
connected to hello-world context in the PBX to
start application execution.
38 Asterisk Manager Interface
- Originate is useful for applications like
- Click to dial ( web pages or stand alone
applications ). - Predictive dialer.
- Event notification system.
- SPIT ( Spam Over Internet Telephony ).
39 Conclusion
- PBX in software, either open source or
proprietary, is far more flexible than
hardware/firmware only based systems. - Flexibility makes telephony systems far more
flexible, but probably far more crackable as
well. - VoIP industry will require innovative
applications to serve users and secure networks,
it is an emerging industry about to make a boom.
IBM will be part of it, will you?
40 References http//www.voip-info.org/http//
www.asterisk.org/http//www.asteriskdocs.org/htt
p//www.freeswitch.org/
41 Questions Session
42 Contact Information Moisés Humberto Silva
Salmerónmoyhu_at_mx1.ibm.commoises.silva_at_gmail.com
http//www.moythreads.com/