+ All Categories
Home > Documents > ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i...

ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i...

Date post: 03-Jan-2016
Category:
Upload: anna-park
View: 219 times
Download: 5 times
Share this document with a friend
42
ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development
Transcript
Page 1: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Application Development On Linux

Moisés Humberto Silva Salmerón

System i Access for Linux Development

Page 2: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications2 Oct 19, 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

Page 3: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications3 Oct 19, 2007

: Agenda : Application Development On Asterisk

What is Asterisk?

Development with Asterisk Extension Language

Asterisk Gateway Interface

Asterisk Manager Interface

Page 4: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications4 Oct 19, 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.

Page 5: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications5 Oct 19, 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.

Page 6: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications6 Oct 19, 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.

Page 7: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications7 Oct 19, 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.

Page 8: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications8 Oct 19, 2007

: Common VoIP solutions :

CISCO Call Manager.

Avaya.

Nortel.

3COM.

Page 9: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications9 Oct 19, 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.

Page 10: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications10 Oct 19, 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.

Page 11: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications11 Oct 19, 2007

: Application Development On Asterisk :

Page 12: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications12 Oct 19, 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 ).

Page 13: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications13 Oct 19, 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 )

Page 14: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications14 Oct 19, 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 )

Page 15: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications15 Oct 19, 2007

: 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.

Page 16: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications16 Oct 19, 2007

: 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.

Page 17: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications17 Oct 19, 2007

: Asterisk Extension Language :

Hello World AEL

context default {

_XXX => {

Answer(); Playback(hello-world); Hangup();

};

};

Page 18: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications18 Oct 19, 2007

: 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}

Page 19: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications19 Oct 19, 2007

: 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();

};

};

Page 20: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications20 Oct 19, 2007

: 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 ...

Page 21: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications21 Oct 19, 2007

: 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();

}; };

Page 22: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications22 Oct 19, 2007

: 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();

};};

Page 23: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications23 Oct 19, 2007

: Asterisk Extension Language :

Commonly used Asterisk applications:

Answer()

Dial()

Playback()

Background()

Playtones()

SetLanguage()

Bridge()

MeetMe()

Festival()

Page 24: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications24 Oct 19, 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.

Page 25: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications25 Oct 19, 2007

: Asterisk Gateway Interface :

Page 26: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications26 Oct 19, 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”;

?>

Page 27: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications27 Oct 19, 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.

Page 28: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications28 Oct 19, 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";?>

Page 29: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications29 Oct 19, 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)

Page 30: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications30 Oct 19, 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);

Page 31: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications31 Oct 19, 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.

Page 32: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications32 Oct 19, 2007

: Asterisk Manager Interface :

Page 33: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications33 Oct 19, 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.

Page 34: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications34 Oct 19, 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>

Page 35: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications35 Oct 19, 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.

Page 36: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications36 Oct 19, 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";

Page 37: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications37 Oct 19, 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.

Page 38: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications38 Oct 19, 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 ).

Page 39: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications39 Oct 19, 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?

Page 40: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications40 Oct 19, 2007

: References :

http://www.voip-info.org/

http://www.asterisk.org/

http://www.asteriskdocs.org/

http://www.freeswitch.org/

Page 41: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications41 Oct 19, 2007

: Questions Session :

Page 42: ENLi 2007 Rapid VoIP Application Development On Linux Moisés Humberto Silva Salmerón System i Access for Linux Development.

ENLi 2007

Rapid VoIP Applications42 Oct 19, 2007

: Contact Information :

Moisés Humberto Silva Salmerón

[email protected]

[email protected]

http://www.moythreads.com/


Recommended