freeswitch的3XX重定向

 

概述

sip协议标准RFC3261中,对3XX重定向有明确的定义。

freeswitch中如何使用3XX redirect的特性,如何落地,应用场景有哪些?

环境

centos:CentOS  release 7.0 (Final)或以上版本

freeswitch:v1.8.7

GCC:4.8.5

3XX重定向

RFC3261中对3XX的响应定义是这样的。

3xx responses give information about the user's new location, or about alternative services that might be able to satisfy the call.

3XX响应提供有关用户新位置的信息,或者可能能够满足呼叫请求的替代服务。

各种具体的响应消息定义如下。

300 Multiple Choices: Indicates that the address resolved to more than one location.

300 多重选择:响应中带有多个可选地址。

301 Moved permanently: Indicates user is no longer available at this location, an alternate location should be included in the header.

301 永久转移:当前地址永久性不可用,响应中附带可选的新地址。

302 Moved Temporarily: Indicates that the user in temporarily unavailable, an alternate location should be included in the header.

302 临时转移:当前地址临时性不可用,响应中附带可选的新地址。

305 Use Proxy: This response indicates that the caller must use a proxy to contact the called party.

305 使用代理:该响应表示用户必须使用代理来建立呼叫。

380 Call is not successful but alternate services are available.

380 呼叫失败但是有可用的替代服务。

freeswitch中的重定向

freeswitch的官方文档中,只找到了300和302响应的app接口“mod_dptools: redirect”。

应用很简单,dialplan拨号计划中直接配置使用。

拨号计划实例:

<action application="redirect" data="sip:foo@bar.com"/>

<action application="redirect" data="sip:foo@bar.com,sip:foo@end.com"/>

查看fs源代码,发现的可用的数据格式。

<action application="redirect" data="<sip:1002@10.55.55.137:5082>;q=0.128,<sip:1002@10.55.55.137:5084>;q=0.129,<sip:1002@10.55.55.137:5086>;q=0.15"/>

其中的“q值”可以用来作为redirect的排序依据。

配置测试

构造一个简单场景,测试一下redirect的流程。

1001->fs138->fs137->fs138->1002

其中,fs137开放多个端口5080、5082、5084、5086。

fs137的5080端口收到invite之后,使用redirect返回300重定向消息,重定向位置为fs137的多个端口5082、5084、5086。

修改dialplan拨号计划如下。

<context name="public">

    <extension name="test" continue="false">

        <condition field="destination_number" expression="^(\d+)$">

        <action application="redirect" data="sip:$1@10.55.55.137:5082,sip:$1@10.55.55.137:5084,sip:$1@10.55.55.137:5086" />

        </condition>

    </extension>

</context>

重启fs之后,发起呼叫测试,sngrep的信令流程如下。

redirect 300的消息流程截图。

重定向之后的呼叫流程截图。

总结

可以在redirect之前,增加一致性HASH的接口来计算重定向目标,以达到负载均衡的目的。

3XX重定向服务可以用在故障转移场景?

3XX重定向服务在分布式大集群中应用的场景,集群容量上限该如何计算?

302重定向只能在呼叫未接通之前使用。

空空如常

求真得真


版权声明:本文为qiuzhendezhen原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。