`

Asterisk Manager api Originate的妙用

阅读更多

Originate Using Asterisk Local Channels

Whenever you want to place a call between two extensions in the dialplan you have to use Local channels.
The OriginateAction that you use when placing calls through the Manager API requires a channel name for the first leg. Usually your application has no knowledge of the dialplan details, i.e. it does not know which channel is triggered by an extension (maybe it's a SIP hardphone, an IAX device or a link to another Asterisk server). What you want to do is "place a call between number a and number b" and leave the rest to Asterisk.

Local channels act as a proxy to the real channels mapped to an extension. So to place a call from 1310 to 1299 your Originate looks like:

1.Channel: Local/1310@from-local
2.Context: from-local
3.Exten: 1310
4.Priority: 1

1.Channel: SIP/1310

2.Context: from-local
3.Exten: 1299
4.Priority: 1

There is an article about Local Channels at voip-info.org that covers the basics.

So that's all very nice and looks straight forward. It becomes more interesting if you have a look at what happens under the hood:

A Local channel actually consists of two channels in Asterisk: Local/XXX,1 and Local/XXX,2. The Local/XXX,2 channel traverses the dialplan starting at the context and extension you provided. In our example this is the extension 1310 in from-local. If you watch the CLI or the events triggered you will see:

1.Set(_ALERT_INFO=<Bellcore-dr1>)
2.Macro(localexten|1310|SIP/1310)
3.Dial(SIP/1310|30|t)

This corresponds to the defintion of 1310 in my dialplan:

01.[from-local]

02.exten => 1310,1,Set(_ALERT_INFO=<Bellcore-dr1>)
03.exten => 1310,n,Macro(localexten,${EXTEN},SIP/${EXTEN})
04.  
05.[macro-localexten]
06.exten => s,1,Dial(${ARG2},30,t)
07.exten => s,n,Goto(s-${DIALSTATUS},1)
08.exten => s-NOANSWER,1,Voicemail(u${ARG1})
09.exten => s-NOANSWER,n,Hangup
10.exten => s-BUSY,1,Busy
11.exten => _s-.,1,Goto(s-NOANSWER,1)

The Dial command triggers an additional channel (SIP/1310). This is the actual channel that is proxied by the Local channel.

The other side of the Local channel, Local/XXX,1, is used for the desination. In our example this is the extension 1299 in from-local. You see similar events for this channel. The actual channel that is triggered for 1299 is an IAX channel to another Asterisk server: IAX2/iax_reucon_net-3.

Now we reach the point where we have four channels set up: The two sides of the Local channel and the two "real" channels SIP/1310 and IAX2/iax_reucon_net. Two channels are now longer needed and will vanish. Before this happens all data of the proxied channel is copied (masqueraded) to Local/XXX,1 so that Local/XXX,1 is renamed to SIP/1310. The "old" SIP/1310 channel is renamed to SIP/1310-0820f718<MASQ> and finally to Local/1310@from-local-1e71,1<ZOMBIE> before it is hung up. Local/XXX,2 is hung up without any renaming.
So in the end you have exactly what you would have expected: Two channels, SIP/1310 and IAX2/iax_reucon_net up and connected.

I have prepared a nice diagram that shows all these steps in detail and helps you understand what happens:

分享到:
评论
3 楼 sunflowers 2010-09-20  
renwolang521 写道
我用软电话没有试成功,当执行如上 AMI 命令时,首先分机1310振铃 接起来之后又会再振铃再接起 它把 “Local/xxx,1” 和 “Local/xxx,2”这两个通道连接起来了,软电话用的是X-lite3.0免费版。CLI输出完整如下:

看你输出的日志记录,你使用的应该是asterisk1.6的内核,这个问题也是我最近发现的,
请看我的博文,希望能帮助到你,http://sunflowers.iteye.com/blog/759614
2 楼 sunflowers 2010-09-20  
请看我的博文,可能是这个问题,http://sunflowers.iteye.com/blog/759614
1 楼 renwolang521 2010-09-19  
不知楼主试过这个否?我没试成功,若楼主有空,帮忙看下。
[quote=AMI]
Action: Originate
Channel: Local/1310@from-local
Context: from-local
Exten: 1310
Priority: 1

我用软电话没有试成功,当执行如上 AMI 命令时,首先分机1310振铃 接起来之后又会再振铃再接起 它把 “Local/xxx,1” 和 “Local/xxx,2”这两个通道连接起来了,软电话用的是X-lite3.0免费版。CLI输出完整如下:
[quote=CLI]

    -- Executing [1310@from-local:1] Set("Local/1310@from-local-003c;2", "_ALERT_INFO=<Bellcore-dr1>") in new stack
    -- Executing [1310@from-local:2] Macro("Local/1310@from-local-003c;2", "localexten,1310,SIP/1310") in new stack
    -- Executing [s@macro-localexten:1] Dial("Local/1310@from-local-003c;2", "SIP/1310,30,t") in new stack
  == Using SIP RTP CoS mark 5
    -- Called 1310
    -- SIP/1310-00000002 is ringing
    -- SIP/1310-00000002 is ringing
    -- SIP/1310-00000002 answered Local/1310@from-local-003c;2
    -- Executing [1310@from-local:1] Set("Local/1310@from-local-003c;1", "_ALERT_INFO=<Bellcore-dr1>") in new stack
    -- Executing [1310@from-local:2] Macro("Local/1310@from-local-003c;1", "localexten,1310,SIP/1310") in new stack
    -- Executing [s@macro-localexten:1] Dial("Local/1310@from-local-003c;1", "SIP/1310,30,t") in new stack
  == Using SIP RTP CoS mark 5
    -- Called 1310
    -- Local/1310@from-local-003c;1 requested special control 20, passing it to SIP/1310-00000003
  == Spawn extension (macro-localexten, s, 1) exited non-zero on 'Local/1310@from-local-003c;2' in macro 'localexten'
  == Spawn extension (from-local, 1310, 2) exited non-zero on 'Local/1310@from-local-003c;2'
    -- SIP/1310-00000003 is ringing
    -- SIP/1310-00000003 is ringing
    -- SIP/1310-00000002 requested special control 16, passing it to SIP/1310-00000003
    -- Music class default requested but no musiconhold loaded.
    -- SIP/1310-00000002 requested special control 20, passing it to SIP/1310-00000003
    -- SIP/1310-00000003 answered SIP/1310-00000002
  == Spawn extension (macro-localexten, s, 1) exited non-zero on 'SIP/1310-00000002' in macro 'localexten'
  == Spawn extension (from-local, 1310, 2) exited non-zero on 'SIP/1310-00000002'

相关推荐

    Asterisk manager API(中文文档)

    Asterisk manager API

    Asterisk_manager_API(AMI)文档

    Asterisk_manager_API(AMI)文档

    Asterisk Manager API的C语言开发包

    The Asterisk Manager Interface (AMI) allows a client program to connect to an Asterisk instance and issue commands or read events over a TCP/IP stream. Integrators will find this particularly useful ...

    Asterisk Manager API(AMI) 中文文档

    Asterisk控制接口(AMI)允管理客端程序接到一个asterisk实例并且可以通过TCP/IP流发送命令或读取事件。 如果你需要进行Asterisk开发,这个文档会非常有用,并且是中文的。 如果英文好,可以直接在www.voip-info.org...

    Asterisk API文档

    Asterisk manager API(AMI)文档

    NodeJS-AsteriskManager:NodeJS Asterisk Manager API

    对于我的项目,我需要Asterisk Manager API的低级接口。 我环顾四周,发现 。 虽然这是一个很好的起点,但对于我来说,它有太多的抽象。 这就是为什么我将其版本基于它,然后从根本上对其进行重构的原因。 最后,...

    asterisk AMI programs

    通过socket 连接asterisk 并分析asterisk 的Event事件。主要支持asterisk 1.4 版本

    Asterisk+manager+Interface(CN).doc

    Asterisk+manager+Interface(CN).doc

    Asterisk 客户端.rar

    Asterisk客户端和Asterisk manager API(AMI)文档。

    j asterisk manager interface-开源

    Jami,Java Asterisk Mananger接口是Java客户端通过mananger接口连接到星号PBX的库。

    libamievent:Asterisk Manager Interface客户端C库

    libamievent是用C编写的Asterisk Manager Interface的异步事件驱动的客户端库。它使用作为事件循环后端。 使用libamievent,您可以发送AMI命令,还可以订阅对该命令的响应。 到达时,libamievent会调用在预订时指定...

    Asterisk CookBook.pdf

    This is a book for anyone who uses Asterisk, but particularly those who already ...external application through the Asterisk Gateway Interface or Asterisk Manager Interface isn’t also possible.

    Asterisk Connection Manager-开源

    Asterisk.NET替代产品的开始。 该项目的目标是创建一个管理器连接库,以简化与多个Asterisk服务器的接口。 Asterisk Connection Manager当前是一个非常新的,不完整的文档。

    ruby-asterisk:Ruby中的Asterisk Manager界面

    这个gem为Asterisk Manager Interface的Ruby或RubyOnRails项目添加了支持 有一个同名的项目,但似乎已停产,所以我决定开始一个新项目 安装 轨道3 添加到您的Gemfile并运行bundle命令进行安装。 gem "ruby-...

    asterisk学习资料

    Asterisk+manager+API(中文文档).doc Asterisk_manager_API.doc Asterisk_系统及其应用分析.pdf asterisk入门连载.doc asterisk架构.doc Asterisk核心框架.docx Asterisk核心框架.pdf asterisk目录结构.txt 基于...

    dami:适用于Deno的Asterisk Manager Interface(AMI)客户端

    DAMI支持发送每个动作,并能够处理[AMI API]( https://www.voip-info.org/asterisk-manager-api/中概述的每个事件)。 DAMI将返回给您的数据与Asterisk完全相同,但是对象由数组中的键/值对组成。 例如,采取“ ...

    asterisk-java.CHM

    asterisk-java AGI 通过asterisk ami接口,连接asterisk. api,开发自己的呼叫中心

    Asterisk 简介 Asterisk 架构 Asterisk程序框图

    Asterisk 简介 Asterisk 架构 Asterisk程序框图

    Asterisk-java-2.0.3

    The Asterisk-Java package consists of a set of Java classes that allow you to... Asterisk-Java supports both interfaces that Asterisk provides for this scenario: The FastAGI protocol and the Manager API.

    Asterisk权威指南中文

    Asterisk权威指南中文(第3版) Asterisk权威指南(第3版)第15章自动话务员 Asterisk权威指南(第3版)第02章Asterisk体系结构 Asterisk权威指南(第3版)第05章用户设备配置 Asterisk权威指南(第3版)第06章Dialplan基础 ...

Global site tag (gtag.js) - Google Analytics