openSIPS路由类型
2014-04-04 09:46
288 查看
openSIPS路由规则使用几种类型的路由。每种路由是被一中特定时间触发,并且允许你处理一种确定类型的消息。(请求或者应答)
1.主路由--route
由route{...}或者route[0]{...}来标识
触发条件:SIP请求
处理:SIP请求
类型:初始的时候无状态,后面可能会由TM模块函数变为有状态。
默认动作:如果请求没有被转发或者回复,会被丢弃。
2.分支路由--branch_route
请求的分支路由块,它包含了对于一个SIP请求每个分支的一系列动作
触发条件:准备一个请求的新分支,这个分支已经完整但并未被发送出去
处理:带有分支特征的SIP请求(比如requset URI,分支标志等)
类型:有状态
默认动作:如果分支中没有使用drop,则默认会将请求发送出去
例子:它是由TM模块中的t_on_branch("branch_route_index")来执行调用的
3.失败路由--failure_route
错误处理路由。里面有当传输中任何分支收到错误应答(>=300)时所应该采取的动作。
触发条件:任何分支中的传输错误
处理:被发出去的初始request
类型:有状态
默认动作:如果里面没有走新的分支路由,或者没有应答被强制结束,将获得的回复转发给UAC
例子:由TM模块中的t_on_failure("fail_route_index")来执行
4.应答路由--onreply_route
应答路由块。对于每个SIP应答所采取的动作
触发条件:接收到网络中应答
处理:reply
类型:有状态(传输相关)或者无状态(全局应答)
默认动作:如果未被丢弃(只有临时应答可能会被),会由传输引擎来处理
有三种类型的应答路由:
(1)global
全局应答路由,捕获所有openSIPS收到的应答,不需要特殊操作。使用:onreply_route{...}或者onreplay_route[0]{...}
(2)per request/transaction
每次请求/传输对应应答路由,捕获某个确定传输过程中的所有应答,由t_on_reply()请求时在请求路由中执行。使用:onreply_route
{...}
(3)per branch
每个分支对应应答路由,捕获某个确定分支中的应单,由t_on_reply()请求时在分支路由中执行。使用:onreply_route
{...}
例子:
5.错误路由--error_route
解析SIP请求中出现语法错误时所应采取的动作。
触发条件:解析错误
处理:失败的请求
类型:无状态(需要)
默认动作:丢弃请求
例子:
6.本地路由--local_route
在一个SIP请求由TM模块产生而非UAC时执行,它用来做消息检查,账户认证和更新消息头。路由和信令函数不能在这里面执行。
触发条件:TM模块生成新请求
处理:新请求
类型:有状态
默认动作:发出请求
例子:
在原始请求上进行封装。
7.起始路由--startup_route
在opensSIPS启动后到监听进程运行中间时,做出必要的初始化动作,不处理SIP信息。
触发条件:openSIPS启动后
处理:初始函数
例子:
startup_route {
avp_db_query("select gwlist where ruleid==1",$avp(i:100));
cache_store("local", "rule1", "$avp(i:100)");
}
8.定时路由--time_route
定期自动执行的路由,不处理SIP信息。
触发条件:定时器
处理:做刷新动作的函数
例子:
9.事件路由--event_route
当事件发生时,openSIPS Event接口来执行脚本。名字是由路由来处理的事件的名字。
触发条件:当一个Event被抛出时由event_route触发
处理:该event
类型:无状态(需要)
默认动作 :event发生时不执行任何脚本
例子:
1.主路由--route
由route{...}或者route[0]{...}来标识
触发条件:SIP请求
处理:SIP请求
类型:初始的时候无状态,后面可能会由TM模块函数变为有状态。
默认动作:如果请求没有被转发或者回复,会被丢弃。
2.分支路由--branch_route
请求的分支路由块,它包含了对于一个SIP请求每个分支的一系列动作
触发条件:准备一个请求的新分支,这个分支已经完整但并未被发送出去
处理:带有分支特征的SIP请求(比如requset URI,分支标志等)
类型:有状态
默认动作:如果分支中没有使用drop,则默认会将请求发送出去
例子:它是由TM模块中的t_on_branch("branch_route_index")来执行调用的
route { lookup("location"); t_on_branch("1"); if(!t_relay()) { sl_send_reply("500", "relaying failed"); } } branch_route[1] { if(uri=~"10\.10\.10].10") { # discard branches that go to 10.10.10.10 drop(); } }
3.失败路由--failure_route
错误处理路由。里面有当传输中任何分支收到错误应答(>=300)时所应该采取的动作。
触发条件:任何分支中的传输错误
处理:被发出去的初始request
类型:有状态
默认动作:如果里面没有走新的分支路由,或者没有应答被强制结束,将获得的回复转发给UAC
例子:由TM模块中的t_on_failure("fail_route_index")来执行
route { lookup("location"); t_on_failure("1"); if(!t_relay()) { sl_send_reply("500", "relaying failed"); } } failure_route[1] { if(is_method("INVITE")) { # call failed - relay to voice mail t_relay("udp:voicemail.server.com:5060"); } }
4.应答路由--onreply_route
应答路由块。对于每个SIP应答所采取的动作
触发条件:接收到网络中应答
处理:reply
类型:有状态(传输相关)或者无状态(全局应答)
默认动作:如果未被丢弃(只有临时应答可能会被),会由传输引擎来处理
有三种类型的应答路由:
(1)global
全局应答路由,捕获所有openSIPS收到的应答,不需要特殊操作。使用:onreply_route{...}或者onreplay_route[0]{...}
(2)per request/transaction
每次请求/传输对应应答路由,捕获某个确定传输过程中的所有应答,由t_on_reply()请求时在请求路由中执行。使用:onreply_route
{...}
(3)per branch
每个分支对应应答路由,捕获某个确定分支中的应单,由t_on_reply()请求时在分支路由中执行。使用:onreply_route
{...}
例子:
route { seturi("sip:bob@opensips.org"); # first branch append_branch("sip:alice@opensips.org"); # second branch t_on_reply("global"); # the "global" reply route # is set the whole transaction t_on_branch("1"); t_relay(); } branch_route[1] { if ($rU=="alice") t_on_reply("alice"); # the "alice" reply route # is set only for second branch } onreply_route { xlog("OpenSIPS received a reply from $si\n"); } onreply_route[alice] { xlog("received reply on the branch from alice\n"); } onreply_route[global] { if (t_check_status("1[0-9][0-9]")) { setflag(1); log("provisional reply received\n"); if (t_check_status("183")) drop; } }
5.错误路由--error_route
解析SIP请求中出现语法错误时所应采取的动作。
触发条件:解析错误
处理:失败的请求
类型:无状态(需要)
默认动作:丢弃请求
例子:
error_route { xlog("--- error route class=$(err.class) level=$(err.level) info=$(err.info) rcode=$(err.rcode) rreason=$(err.rreason) ---\n"); xlog("--- error from [$si:$sp]\n+++++\n$mb\n++++\n"); sl_send_reply("$err.rcode", "$err.rreason"); exit; }
6.本地路由--local_route
在一个SIP请求由TM模块产生而非UAC时执行,它用来做消息检查,账户认证和更新消息头。路由和信令函数不能在这里面执行。
触发条件:TM模块生成新请求
处理:新请求
类型:有状态
默认动作:发出请求
例子:
local_route { if (is_method("INVITE") && $ru=~"@foreign.com") { append_hf("P-hint: foreign request\r\n"); exit; } if (is_method("BYE") ) { acc_log_request("internally generated BYE"); } }
在原始请求上进行封装。
7.起始路由--startup_route
在opensSIPS启动后到监听进程运行中间时,做出必要的初始化动作,不处理SIP信息。
触发条件:openSIPS启动后
处理:初始函数
例子:
startup_route {
avp_db_query("select gwlist where ruleid==1",$avp(i:100));
cache_store("local", "rule1", "$avp(i:100)");
}
8.定时路由--time_route
定期自动执行的路由,不处理SIP信息。
触发条件:定时器
处理:做刷新动作的函数
例子:
timer_route[gw_update, 300] { avp_db_query("select gwlist where ruleid==1",$avp(i:100)); $shv(i:100) =$avp(i:100); }
9.事件路由--event_route
当事件发生时,openSIPS Event接口来执行脚本。名字是由路由来处理的事件的名字。
触发条件:当一个Event被抛出时由event_route触发
处理:该event
类型:无状态(需要)
默认动作 :event发生时不执行任何脚本
例子:
event_route[E_PIKE_BLOCKED] { xlog("The E_PIKE_BLOCKED event was raised\n"); }
相关文章推荐
- openSIPS路由类型
- OSPF区域类型及路由发布(一)
- OpenSIPS实战(三):路由脚本介绍与实战
- angular2系列教程(十)两种启动方法、两个路由服务、引用类型和单例模式的妙用
- RabbitMQ五种消息队列学习(六)--通配符模式(路由类型:Topic)
- OSPF区域类型及路由发布(二)
- OSPF路由协议建立邻居关系、邻接关系和路由汇聚过程中的表类型、包类型及状态类型
- rails路由常用请求类型
- RIP 数据包类型 路由中毒
- 链路的类型,链路的容量,可靠性,信令点编码,路由和路由集
- Asp.net mvc 限制路由参数类型
- AspNetWebApi管线中如果定义两种类型的消息处理程序(全局/路由)
- OSPF系列小实验之6:网络类型对邻居关系及路由学习的影响
- BGP的消息类型、路由选择和配置命令
- MVC自定义路由,实现二级域名类导致的找到多个与名为xxx的控制器匹配的类型的错误
- ASP.NET Web API框架揭秘:路由系统的几个核心类型
- (4)学习tp5之路由类型,定义,动态注册,过滤,闭包,miss(默认),资源路由
- 找到多个与名为“xxx”的控制器匹配的类型。如果为此请求(“{controller}/{action}/{id}”)提供服务的路由没有指定命名空间以搜索与此请求相匹配的控制器,则会发生这种情况。
- MVC API中路由参数类型约定
- 类型:.net;问题:ASP.NET路由;结果:ASP.NET 路由 .NET Framework 4