`

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(AMI) 中文文档

    ### Asterisk Manager Interface (AMI) 中文文档概览 #### 一、引言 Asterisk Manager Interface (AMI) 是一款强大的工具,它允许开发者通过TCP/IP协议与Asterisk PBX系统进行交互,实现远程管理和监控功能。本文档...

    Asterisk_manager_API(AMI)文档

    Asterisk Manager API (AMI) 是 Asterisk 通信平台的核心组件之一,它提供了一种机制,使得外部应用程序可以通过网络与 Asterisk PBX 进行交互和控制。AMI 使用基于文本的简单“key: value”协议,允许管理客户端...

    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 API文档

    Asterisk Manager API (AMI) 是一种用于远程管理和监控 Asterisk PBX 系统的接口。它通过TCP/IP协议提供了一种方式,让管理客户端能够连接到Asterisk实例,发送命令并接收事件。这对于实时追踪PBX的状态、电话客户端...

    通过asterisk-java操作asterisk

    首先,理解Asterisk-java的基础是熟悉Asterisk的Manager API。Asterisk Manager Interface(AMI)是Asterisk提供的一种HTTP协议,用于远程管理和监控PBX。Asterisk-java通过实现这个接口,允许开发者使用Java语言...

    asterisk AMI programs

    由于提到主要支持Asterisk 1.4版本,这可能意味着代码或指南可能不适用于较新的Asterisk版本,因为API和功能可能会有所更新。 【标签】:“asterisk ami sock proxy” “ami sock proxy”可能指的是一个AMl代理,...

    Asterisk+manager+Interface(CN).doc

    ### Asterisk Manager Interface (AMI) 详解 #### 一、概览 Asterisk Manager Interface (简称 AMI),是Asterisk系统中的一个重要组件,它为开发者提供了远程管理和监控Asterisk实例的能力。通过AMI,我们可以实现...

    NodeJS-AsteriskManager:NodeJS Asterisk Manager API

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

    Asterisk 客户端.rar

    在这个"Asterisk客户端.rar"压缩包中,我们主要关注的是Asterisk的客户端组件以及Asterisk Manager API(AMI)的相关文档。 1. **Asterisk客户端**:Asterisk客户端是指与Asterisk服务器交互的各种应用程序,包括软...

    j asterisk manager interface-开源

    【描述】:“Jami,全称为Java Asterisk Manager接口,是一款用Java编写的开源库,它允许开发者通过Manager接口与Asterisk PBX(Private Branch eXchange)系统进行交互。Asterisk是一款功能强大的开源IP电话服务器...

    Asterisk CLI 命令列表

    在使用Asterisk Manager Interface (AMI)时,此命令用于查看已配置的AMI用户,AMl是Asterisk的API,允许远程程序控制Asterisk。 8. **cdr show** 显示呼叫详细记录(Call Detail Records),用于追踪和分析通话...

    Asterisk AMI 接口代码

    - `ManagerCommand`:用于向Asterisk发送命令,例如`Originate`命令发起一个呼叫,或者`CoreShowChannels`命令获取所有通道的信息。 - `ActionID`:每个发送的命令都有一个唯一的`ActionID`,通过它可以跟踪命令的...

    Asterisk.NET 1.6.3 控制Asterisk

    在Asterisk.NET 1.6.3 版本中,开发者可以期待一些改进和修复,比如性能优化、API稳定性提升以及对Asterisk最新特性的支持。使用这个版本,你能够更加稳定地构建和维护基于.NET的Asterisk应用,同时享受到版本更新...

    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代码学习笔记

    2. **架构概述**:Asterisk的核心架构包括通道(Channels)、拨号计划(DialPlan)、应用程序(Apps)和管理接口(Manager API)。通道处理实际的通信连接,DialPlan定义了如何处理呼叫,应用程序执行特定的通话操作...

    Asterisk-CLI-命令列表.zip_asterisk_cli

    9. **Asterisk Manager API** 除了CLI,Asterisk还提供了Manager API,这是一个基于HTTP的接口,用于远程控制和监控Asterisk系统,常用于开发自定义应用程序和集成。 10. **学习和资源** 对于深入了解Asterisk ...

    Asterisk 简介 Asterisk 架构 Asterisk程序框图

    3. **应用程序接口**:提供了丰富的API,允许开发者编写自定义的应用程序,如IVR(Interactive Voice Response)系统、录音、会议等。 4. **媒体处理**:包括编解码、静音检测、回声消除等功能,确保语音质量。 5....

    Asterisk Connection Manager-开源

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

Global site tag (gtag.js) - Google Analytics