Systems & Technology Group © 2007 IBM Corporation Rapid VoIP Application Development On Linux...
-
Upload
preston-booth -
Category
Documents
-
view
216 -
download
0
Transcript of Systems & Technology Group © 2007 IBM Corporation Rapid VoIP Application Development On Linux...
Systems & Technology Group
© 2007 IBM Corporation
Rapid VoIP Application DevelopmentOn Linux
Moisés Humberto Silva Salmerón
System i Access for Linux Development
QSE 2007
Systems & Technology Group
© 2007 IBM Corporation2 Aug 31, 2007
: Agenda : Demystifying VoIP
What VoIP is not
What is VoIP?
Consequences of VoIP
What is a PBX?
Common VoIP solutions
Next generation VoIP solutions
Systems & Technology Group
© 2007 IBM Corporation3 Aug 31, 2007
: Agenda : VoIP Application Development On Asterisk
What is Asterisk?
Development with Asterisk Extension Language
Asterisk Gateway Interface
Asterisk Manager Interface
Systems & Technology Group
© 2007 IBM Corporation4 Aug 31, 2007
: Demystifying VoIP :
Systems & Technology Group
© 2007 IBM Corporation5 Aug 31, 2007
: 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.
Systems & Technology Group
© 2007 IBM Corporation6 Aug 31, 2007
: 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.
Systems & Technology Group
© 2007 IBM Corporation7 Aug 31, 2007
: 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.
Systems & Technology Group
© 2007 IBM Corporation8 Aug 31, 2007
: 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.
Systems & Technology Group
© 2007 IBM Corporation9 Aug 31, 2007
: Common VoIP solutions :
CISCO Call Manager.
Avaya.
Nortel.
3COM.
Systems & Technology Group
© 2007 IBM Corporation10 Aug 31, 2007
: 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.
Systems & Technology Group
© 2007 IBM Corporation11 Aug 31, 2007
: 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.
Systems & Technology Group
© 2007 IBM Corporation12 Aug 31, 2007
: VoIP Application Development On Asterisk :
Systems & Technology Group
© 2007 IBM Corporation13 Aug 31, 2007
: 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 ).
Systems & Technology Group
© 2007 IBM Corporation14 Aug 31, 2007
: 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 )
Systems & Technology Group
© 2007 IBM Corporation15 Aug 31, 2007
: 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 )
Systems & Technology Group
© 2007 IBM Corporation16 Aug 31, 2007
: Development with 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.
Systems & Technology Group
© 2007 IBM Corporation17 Aug 31, 2007
: Development with 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.
Systems & Technology Group
© 2007 IBM Corporation18 Aug 31, 2007
: Development with Asterisk Extension Language :
Hello World AEL
context default {
_XXX => {
Answer(); Playback(hello-world); Hangup();
};
};
Systems & Technology Group
© 2007 IBM Corporation19 Aug 31, 2007
: Development with Asterisk Extension Language :
Variables are defined and used in a similar way to other scripting languages:
– myvariable=myvalue;
– ${myvariable}
Substring can be obtained using ${var:0:3}
String length: ${LEN(${var})}
String concatenation: ${myvar1}${myvar2}
Systems & Technology Group
© 2007 IBM Corporation20 Aug 31, 2007
: Development with Asterisk Extension Language : Matching different patterns.
context common_users {
_XX => { Answer(); Dial(SIP/${EXTEN}); Hangup(); };
_XXXX => { Answer(); Dial(IAX2/${EXTEN});
Hangup(); };
_0NX => { Answer();
Dial(Zap/g1/${EXTEN}); Hangup();
};
};
Systems & Technology Group
© 2007 IBM Corporation21 Aug 31, 2007
: Development with 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 ...
Systems & Technology Group
© 2007 IBM Corporation22 Aug 31, 2007
: Development with Asterisk Extension Language : Catching Dial() return value.
context dial_catcher { _X. => { Answer(); Dial(IAX2/user:[rsakey]@myvoipserver.host.com/${EXTEN});
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();
}; };
Systems & Technology Group
© 2007 IBM Corporation23 Aug 31, 2007
: Development with 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. => {
Answer();Dial(SIP/test);&handle-dial-response(${DIALSTATUS},test);Hangup();
};};
Systems & Technology Group
© 2007 IBM Corporation24 Aug 31, 2007
: Development with Asterisk Extension Language :
Commonly used Asterisk applications:
Answer()
Dial()
Playback()
Background()
Playtones()
SetLanguage()
Bridge()
MeetMe()
Festival()
Systems & Technology Group
© 2007 IBM Corporation25 Aug 31, 2007
: 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.
Systems & Technology Group
© 2007 IBM Corporation26 Aug 31, 2007
: Asterisk Gateway Interface :
Systems & Technology Group
© 2007 IBM Corporation27 Aug 31, 2007
: Asterisk Gateway Interface :
Hello World AGI in PHP
context default {
_XXX => {
Answer(); AGI(hello-world.php); Hangup();
};
};
<?php$s = “”;
do {
$s = fread(STDIN, 1024);
} while ( FALSE === strpos($s, “agi_accountcode:”) );
print “EXEC Playback hello-world”;
?>
Systems & Technology Group
© 2007 IBM Corporation28 Aug 31, 2007
: 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.
Systems & Technology Group
© 2007 IBM Corporation29 Aug 31, 2007
: Asterisk Gateway Interface :
Reading call information values.
#!/usr/bin/php <?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_env[$parameter_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";?>
Systems & Technology Group
© 2007 IBM Corporation30 Aug 31, 2007
: Asterisk Gateway Interface :
Asterisk sends a command response that programs can read from standard input.
Response format: “200 result=<res> (optional data)”
Common responses:– 200 result=1
– 200 result=1 (some variable value)
– 200 result=0 (timeout)
Systems & Technology Group
© 2007 IBM Corporation31 Aug 31, 2007
: Asterisk Gateway Interface :
Reading response values.
print "GET VARIABLE EXTEN\n";$response = fread(STDIN, 1024);eregi($response_regexp, $response, $matches);$result = $matches[1];$data = isset($matches[2]) ? $matches[2] : ''; file_put_contents('/tmp/agi.log', "result is: {$result}\ndata is: {$data}", FILE_APPEND);
Systems & Technology Group
© 2007 IBM Corporation32 Aug 31, 2007
: 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.
Systems & Technology Group
© 2007 IBM Corporation33 Aug 31, 2007
: Asterisk Manager Interface :
Systems & Technology Group
© 2007 IBM Corporation34 Aug 31, 2007
: 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.
Systems & Technology Group
© 2007 IBM Corporation35 Aug 31, 2007
: Asterisk Manager Interface :
AMI messages have the following format:
<Message type>: <Message value><CRLF>
<Header1>: <Header 1 value><CRLF>
<Header2>: <Header 2 value><CRLF>
<Header N>: <Header N value><CRLF>
<CRLF>
Systems & Technology Group
© 2007 IBM Corporation36 Aug 31, 2007
: 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.
Systems & Technology Group
© 2007 IBM Corporation37 Aug 31, 2007
: 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";
Systems & Technology Group
© 2007 IBM Corporation38 Aug 31, 2007
: 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.
Systems & Technology Group
© 2007 IBM Corporation39 Aug 31, 2007
: 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 ).
Systems & Technology Group
© 2007 IBM Corporation40 Aug 31, 2007
: 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?
Systems & Technology Group
© 2007 IBM Corporation41 Aug 31, 2007
: References :
http://www.voip-info.org/
http://www.asterisk.org/
http://www.asteriskdocs.org/
http://www.freeswitch.org/
Systems & Technology Group
© 2007 IBM Corporation42 Aug 31, 2007
: Questions Session :
Systems & Technology Group
© 2007 IBM Corporation43 Aug 31, 2007
: Contact Information :
Moisés Humberto Silva Salmerón
http://www.moythreads.com/