路由类型
opensips路由逻辑使用几种类型的路由。每种路由类型由特定的事件触发并且允许你处理不同的类型的消息(请求或者回复)。
route
请求路由块:包含一系列针对sip请求的操作。
Triggered by:接收的来自网络的外呼请求。
Type:最初是无状态的,可以通过使用TM函数强制改为有状态的。
Default action:如果请求即没有被转发也没有回复,则路由最后将丢弃这个强求。
为每个SIP请求执行由"route {…}’'或者"route[0]{…}标识的 main"route’块。
执行主路由后会丢弃sip请求。为了发送回复或者抓饭请求,必须在路由块内调用明确的的操作。
使用用例
route {
if(is_method("OPTIONS")) {
# send reply for each options request
sl_send_reply("200", "ok");
exit();
}
route(1);
}
route[1] {
# forward according to uri
forward();
}
注意,如果从’branch_route[y]‘调用’route[X]’,那么在’route[X]'中值处理一个单独的分支而不是在main route中出现的所有分支。
branch_route
请求的分支路由块。包含一个sip请求的一个分支操作集合。
Triggered by:preparation a new branch (of a request); the branch is well formed, but not yet sent out.
Processing:the SIP request (with the branch particularities, like RURI, branch flags)
Type:stateful
Default action:如果branch_route没有dropped(通过’drop()'语句),branch_route将自动发送出去。
It is executed only by TM module after it was armed via 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();
}
}
failure_route
事务失败路由块。对于接受到所有否定答复的事务包含一系列操作。