Click here to load reader

Asterisk Presentation

Embed Size (px)

DESCRIPTION

Asterisk Based Implementation and development platform

Citation preview

Asterisk Based Implementation and development platform

Need to communicate?? Asterisk is your answer.

Prepared by: Aziz ZoaibAsterisk CONSULTANT

Asterisk Based Implementation and development platformAgendaAsteriskWhat is Asterisk? What Does Asterisk Do?Asterisk BenefitsAsterisk ArchitectureAsterisk as an Application based PlatformBlock Diagram and Execution Flow Communication b/w AGI and ExternalAPIProtocol & Message formatAsterisk Call ProcessingAsterisk Gateway InterfaceHow to execute an AGI program from the Asterisk dial plan?Communicating with the Asterisk AGI interfacePassing arguments to your AGI programAsterisk Manager InterfaceAMI protocol behaviorAMI Information available for each of these event/action typesAMI CommunicationWhat is Asterisk?

World's most popular open source communications project

Simply to create and deploy a wide range of telephony applications and services, including IP PBXsVoIP gateways Call center ACDs IVR systemsMobile based applications

Released as open source under the GNU General Public License (GPL) What Does Asterisk Do?

Development platform where you can create communications applications.

Includes all the building blocks needed to create PBX systemIVR systemCommunications solution

The "blocks" in the kit include:Drivers for various VoIP protocols and for PSTN interface cards.Routing and call handling (incoming and Outbound calls).Media management functions (record, play, generate tone, etc.).Call detail recording for accounting and billing.Transcoding (conversion from one media format to another).Protocol conversion (conversion from one protocol to another).Database integration. Web services integration.

4What Does Asterisk Do? (Cont)

LDAP integration for accessing corporate directory systems.Single and multi-party call bridging.Call recording and monitoring.Integrated "Dialplan" scripting language for call processing.External API in any programming language via Asterisk Gateway Interface (AGI).Event notification via Asterisk Manager Interface (AMI).Speech synthesis "text-to-speech" in various languages.Speech recognition in various languages using third party recognition engines.

Open nature of Asterisk means that there is no fixed limit on what it can be made to do. Asterisk integrators have built everything from very small IP PBX systems to massive carrier media servers.Asterisk BenefitsSource code availability, your guarantee for business continuity

Use of generic hardware means no proprietary lock-in

Freely and easily extensible

Reduce cost, improve productivity and improve customer service

Easy to integrate into External API modules

Extremely cost effective

Supports a large variety of VoIP and signaling protocols

Asterisk Architecture Asterisk Architecture CLIApplicationManager InterfaceResourcesDialplanDigital card driversAudio/Video CodecsSys Config DriversAGIDAHDISIPIAX2H323 Asterisk CoreAsterisk Architecture (Cont)Asterisk Core:Heart of any Asterisk system. Essential components:Directly intact with signaling protocols Takes care of bridging callsTakes care reading the configuration files and loading the other modulesModules are typically files with a .so file extensionOn starts up, it loads these files and adds their functionality to the system

Dialplan:Core also contains the dialplan, logic of any Asterisk system Dialplan contains a list of instructions that Asterisk should follow to know how to handle incoming and outgoing calls on the system

Asterisk Dialplan Heart of any Asterisk system.List of rules, instructions and steps guiding the flow of inbound and outbound calls in AsteriskDialplan consists of a exten followed by a Dialplan application.Devices that dial in match a pattern and follow series of dial plan applications.Configure in extensions.conf fileDivided into [Contexts]Extensions, Priorities, Applications()exten => 123, 1, Answer()exten => 123, n, Background(menu_prompt)exten => 123, n, WaitExten()...The dialplan is a procedural languageIt is complete with subroutines (macros), Goto commands, conditional branchingIt even provides support for advanced AGI

Asterisk Architecture (Cont)Asterisk Gateway Interface:Use to implement external logics utilizing Asterisk.Perform advanced logicCommunicate with databasesPerform complex tasks that would be hard to do with Dialplan

DialplanSound FileAsterisk CoreChannelsExternal ResourceAGIExternal ResourceExternal ResourceAGI is an application level API application developed using AGI are not bound by the Asterisk License and are not required to be re-distributed with the source

Allows an external, user-written program on any programming language.

launched from the dial plan via pipes to control telephony operations on its associated control and voice channels.Asterisk Architecture (Cont)AGI Features:Provides a standard interface by which external programs may control the Asterisk dialplan.Supports languages like Java, C#, PHP etc- Can be located on different or on same sever running Asterisk. Full command over core functionalities of Asterisk.Uses a TCP socket for communication to the external host which provides the function of an AGI service, in a manner of the clientserver model. Using Management API user can even manage Asterisk core from AGI. User can play prompts from AGI, record files etc etc...Asterisk as an Application based PlatformBlock Diagram of Asterisk based Application platform:

14User5Services RequestServices ResponseQuery to ExternalAPIAsterisk CoreDialplanAGI ScriptExternalAPIProgrammed API2Response from ExternalAPIDBHOST33Asterisk AGI Execution Flow DiagramAsterisk DialplanStep 2 (Dialplan Executed)Step 3 (AGI Executed)AGI ScriptExternalAPIStep 4 (Query to ExternalAPI)Step 5 (Query Response) Step 6 Step 7Step 8 (AGI Termination)Step 9 (Released)

Step 10 (Released)Step 1 (Call triggered)Steps that occur when an AGI script is executed from within the Asterisk dialplanAsterisk AGI Execution FlowStep#1,2User trigger the call, asterisk core detects the incoming call and initiate dialplan.Step#3AGI script is being executed from the Asterisk dialplan.Asterisk will pass a preset number of AGI variables, along with general AGI execution information to our AGI script, which requires initial processing.Step#4,5Once an AGI script has been invoked, all the queries will be sended and received from AGI to ExternalAPI.Step#6,7A preset information flow is performed between the AGI script and Asterisk.Step#8,9,10Once an AGI script has terminated its execution, it will return the control back to Asterisk for the continued execution of the Asterisk dialplan.ExternalAPIExternalAPI is a programmable application is used to allow external systems to communicate directly with Asterisk AGI. ExternalAPI can do variety of stuff from consuming web service to sending/receiving TCP/IP data to operator's modules or fetching a data from database etc..'.

DB & Provisioning ServerWeb Server3rd party systemExternalAPIExternal APICommunication b/w AGI and ExternalAPI:Asterisk AGI ExternalAPIRequest Response Request being processProcess completedAsterisk AGI and ExternalAPI are communicate over TCP/IP socket connections. What is AGI?18Protocol & Message formatMessage exchanged between Asterisk AGI and ExternalAPI is over TCP socket. Function call and response messages from Asterisk AGI to ExternalAPI must be packed in XML format.Sample request message:

provisionService01333093313 IVR

Sample response message:

1000

Parameter NameData TypeDescriptionresultInt1 - Result Accept, 2 Result RejectedresultCodeString000 Success101 msisdn already registered102 invalid msisdn402 Unknown subscriber604 Timeout, System Busy605 Error, System Busy606 db errorAsterisk Call Processing; Span 1: TE4/0/1 "T4XXP (PCI) Card 0 Span 1" (MASTER) HDB3/CCS/CRC4 ClockSource group=0,11context=cs_depositswitchtype = euroisdnsignalling = ss7channel => 2-31group = 63

; Span 2: TE4/0/2 "T4XXP (PCI) Card 0 Span 2" HDB3/CCS/CRC4 group=0,12context=cs_callbackswitchtype = euroisdnsignalling = ss7channel => 32,62group = 63dahdi_channels.conf[cs_deposit]exten => _x.,1,Answer() exten => _x.,n,agi(agi://localhost/cs_deposit.agi) exten => _x.,n,Hangup

[cs_callback]exten => _x.,1,Answer() exten => _x.,n,agi(agi://localhost/cs_callback.agi) exten => _x.,n,Hangup

extensions.confAGI can run a Java application (on the same machine that runs Asterisk or on a separate machine).Combined with Java's multithreading support can build pretty fast AGI scripts using this protocol.E1 Line ConfigurationdialplanAsterisk Gateway InterfaceAsterisk Gateway Interface (AGI)Means how application programmers can implement external logics utilizing Asterisk.- To perform advanced logic- To communicate with databases- Perform complex tasks that would be hard to do with DialplanApplication level API, which means that application developed using AGI are not bound by the Asterisk License and are not required to be re-distributed with the source.Very much similar to a CGI interface used by web server, where communications between Asterisk and your AGI program is performed via an STDIN/STDOUT interface.Invoked from Dialplan (AGI() application)exten => 123, 1, Answer()exten => 123, 2, AGI(test.agi)...It allows the use of high level languages like Java, Perl, PHP and Python to extend Asterisks functionality.

How to execute an AGI program from the Asterisk dial plan?Each item in an extension is of the form:exten => extension-number,priority,application,argumentsTo launch an AGI script the application is agi and the argument is the filename of your script. The script:- must be executable- must be located in /var/lib/asterisk/agi-bin- must be specified complete with an extensionFor example to run a Python script named test.agi then a suitable extension item would be:exten => 123, 1, Answer()exten => 123, 2, AGI(test.agi)...Communicating with the Asterisk AGI interface

Format for passing parameters to an AGI script is as follows:AGI(script.agi, arg1, arg2, ...)AGI script communicates with Asterisk by sending AGI commands on standard output and receiving responses on standard input. The result typically takes this form: result= [data]

where code is an HTTP-like response code (200 for success, 5xx for error) result is the result of the command (common values are -1 for error, and 0 for success); some commands return additional name=value pairs in data, while some return a string value in parentheses (especially "timeout" for a timed command.)Code Example result text 200 result=0 510 Invalid or unknown command 511 Command Not Permitted on a dead channel 520 End of proper usagePassing arguments to your AGI programIn order to pass arguments to your AGI program, you need to define them in the extension.

In example, to launch an AGI program with a parameter would look like so:exten => 1,2,agi,test.php|${CALLERID}

In the above example, Asterisk will pass the environment variable ${CALLERID} to the AGI program test.php

AGI script is also passed a number of environment variables which point to file-system directories which contain Asterisk filesAsterisk Manager InterfaceAsterisk Manager Interface (AMI)AMI enables a client program to connect to an Asterisk instance and issue commands or read events over a TCP connection.

Systems integrators will find these resources useful to track channel states.

AMI is built in a simple concept of a line protocol using key:value pairs over TCP.

Allows external programs to control and monitor Asterisk

If you have lots of connections to AMI consider using Asterisk Manager Proxy. AMI protocol behaviorBefore sending any commands to Asterisk, you need to establish an AMI session- The first line of a packet will have the key Action when sent from a client- The first line of a packet will have a key Response or Event when coming from Asterisk- Packages can be transmitted in any direction after the authentication

The type of the packet is determined by the existence of the following keys:- Action: A packet sent from a client connected to AMI asking for a specific action. The loaded modules determine these actions. A packet contains the action name and its parameters.- Response: The response sent from Asterisk to the last action sent from the client.- Event: Data belonging to an event generated in the Asterisk core or by a module. When a client sends packets of the Action type, a parameter named ActionID is included. Since the order in which the responses sent from Asterisk cannot be predicted, ActionID is used to correlate actions and responses.AMI Information available for each of these event/action typesThe following is a short explanation of the information available for each of these event/action types:

system: Actions and events related to Asterisk's core elements, such as SIP peers and the Asterisk Database call: Actions and events related directly to Asterisk's extension statuses, and call progress and call control log: The source documentation doesn't provide detailed information about the nature of information provided by events of this type. verbose: The source documentation doesn't provide detailed information about the nature of information provided by events of this type. command: This directive enables our connected user to send commands to the Asterisk CLI interface Agent: Actions and events related to Asterisk's queue applications User: User events can be generated from the dialplan, using the UserEvent application. Using user events are a valuable tool when developing applications that incorporate dialplan, AGI, and AMI at the same time.AMI Communication:AsteriskAMI TCP Socket ServicePHP, JAVA, C ApplicationAction: OriginateResponse: SuccessEvent: DialEvent: PeerStatusEvent: DTMFEvent: RegistryAMI Action packets

When you send an action packet to Asterisk, you can provide some extra keys (e.g. called number).

You do this by passing key:value pairs after the Action.

It is also possible too pass channel and global variables to the dial plan.

Action: : : Variable: = Variable: = ... What language to use for AMI?

Selecting a programming language can be hard these days.

There are simply too many options like Java, PHP, Perl, C, C#, Python, and several others.

Its possible to use AMI with any language that supports a socket or telnet interface. Thank You