概述
freeswitch是一款简单好用的VOIP开源软交换平台。
在之前的文章,我们介绍过distributor模块实现多线路分发的配置方法,但是当线路发生故障时,distributor并不会自动跳过故障线路实现故障转移。
本节中,我们利用gateway的option检测配置,实现中继线路的故障转移。
环境
centos:CentOS release 7.0 (Final)或以上版本
freeswitch:v1.10.7
GCC:4.8.5
APP接口
distributor的接口格式中,可以追加排除列表“<exception1> <exceptionN>”,distributor在选线的时候会跳过排除列表中的线路。
distributor <list name>[ <exception1> <exceptionN>]
sofia接口检测external下所有的gateway状态,并返回“DOWN”状态的gateway列表。
sofia profile external gwlist down
配置&测试
配置conf/sip_profile/external/gw-138-5080.xml,设置网关参数,gw-138-5090.xml和gw-138-15090.xml设置方法一样。
<include>
<gateway name="gw-138-5080">
<param name="username" value="not-used"/>
<param name="realm" value="10.55.55.138:5080"/>
<param name="password" value="not-used"/>
<param name="register" value="false"/>
<!--send an options ping every x seconds, failure will unregister and/or mark it down-->
<param name="ping" value="20"/>
<param name="ping-min" value="3"/>
<param name="ping-max" value="6"/>
<param name="ping-user-agent" value="proxy"/>
</gateway>
</include>
配置文件conf/autoload_configs/distributor.conf.xml,设置distributor列表。
<configuration name="distributor.conf" description="Distributor Configuration">
<lists>
<list name="test-gw" total-weight="3">
<node name="gw-138-5080" weight="1"/>
<node name="gw-138-5090" weight="1"/>
<node name="gw-138-15090" weight="1"/>
</list>
</lists>
</configuration>
修改配置文件conf/dialplan/test.xml,设置拨号计划,仅仅使用distributor接口。
<extension name="test" continue="false">
<condition field="destination_number" expression="^(\d+)$">
<action application="bridge" data="{sip_invite_call_id=${sip_call_id}}sofia/gateway/${distributor(test-gw)}/$1"/>
</condition>
</extension>
刷新distributor配置数据。
reloadxml
distributor_ctl reload
发起呼叫10011->1002,三次的测试日志如下,可以看到"gw-138-15090"网关有故障但是仍然会被选到。
2022-12-14 11:15:36.478543 [INFO] mod_dialplan_xml.c:637 Processing 10011 <10011>->1002 in context public
...
Dialplan: sofia/external/[email protected] Action bridge({sip_invite_call_id=${sip_call_id}}sofia/gateway/${distributor(test-gw)}/1002)
...
EXECUTE sofia/external/[email protected] bridge({sip_invite_call_id=6b70dbfd-f600-123b-7d99-000c29a63969}sofia/gateway/gw-138-5080/1002)
...
EXECUTE sofia/external/[email protected] bridge({sip_invite_call_id=42ddfe80-f602-123b-7d99-000c29a63969}sofia/gateway/gw-138-5090/1002)
...
EXECUTE sofia/external/[email protected] bridge({sip_invite_call_id=498bf45b-f602-123b-7d99-000c29a63969}sofia/gateway/gw-138-15090/1002)
2022-12-14 11:28:58.618511 [ERR] mod_sofia.c:4511 Gateway 'gw-138-15090' is down!
distributor和gateway联合使用实现出中继线路的负载均衡+故障转移。
修改配置文件conf/dialplan/test.xml,使用distributor和sofia接口。
<extension name="test" continue="false">
<condition field="destination_number" expression="^(\d+)$">
<action application="bridge" data="{sip_invite_call_id=${sip_call_id}}sofia/gateway/${distributor(test-gw ${sofia(profile external gwlist down)})}/$1"/>
</condition>
</extension>
刷新dialplan拨号计划。
reloadxml
发起呼叫10011->1002,三次的测试日志如下,"gw-138-15090"网关不再会被选中。
2022-12-14 13:54:08.495843 [INFO] mod_dialplan_xml.c:637 Processing 10011 <10011>->1002 in context public
...
2022-12-14 13:54:16.435860 [WARNING] sofia.c:6098 Ping failed gw-138-15090 with code 503 - count 3/0/6, state DOWN
...
Dialplan: sofia/external/[email protected] Action bridge({sip_invite_call_id=${sip_call_id}}sofia/gateway/${distributor(test-gw ${sofia(profile external gwlist down)})}/1002)
...
EXECUTE sofia/external/[email protected] bridge({sip_invite_call_id=910ce208-f616-123b-7d99-000c29a63969}sofia/gateway/gw-138-5080/1002)
...
EXECUTE sofia/external/[email protected] bridge({sip_invite_call_id=96142b51-f616-123b-7d99-000c29a63969}sofia/gateway/gw-138-5090/1002)
...
EXECUTE sofia/external/[email protected] bridge({sip_invite_call_id=9a7872ed-f616-123b-7d99-000c29a63969}sofia/gateway/gw-138-5080/1002)
...
总结
freeswitch有非常多好用的功能,每个功能设计简单,能力单一,但是我们可以把不同的功能组合在一起,实现各种复杂的需求。
最好的设计就是功能模块的高内聚,低耦合,职责单一,同时又可以灵活组合。
空空如常
求真得真
标签:gw,中继,sofia,1002,distributor,138,gateway From: https://www.cnblogs.com/qiuzhendezhen/p/17028433.html