[SR-Users] Workings of the kamailio dispatcher module
Alex Balashov
abalashov at evaristesys.com
Tue Aug 6 15:39:37 CEST 2013
On 08/06/2013 09:00 AM, Grant Bagdasarian wrote:
> Hello,
>
> Consider the following Kamailio script:
>
> route {
>
> ….
>
> route(DISPATCH);
>
> route(RELAY);
>
> }
>
> route[DISPATCH] {
>
> ds_select_domain("1", "8");
>
> return;
>
> }
>
> Dispatcher Table
>
> SetID
>
>
>
> Destination
>
> 1
>
>
>
> 192.168.1.10
>
> 1
>
>
>
> 192.168.1.11
>
> Algorithm 8 uses the first destination, but if it’s not available, it
> uses the next one.
>
> Does the ds_select_domain function send the SIP request to the first
> destination or is it the responsibility of the RELAY route to do this? I
> believe it’s the latter, according to the documentation.
All the ds_select_domain() function does is change the domain part of
the Request URI ($rd). It's still up to you to take that modified SIP
request, perform any additional processing, and relay/forward it as
desired. When you do this, t_relay() will consume the domain part of
the request URI, in the absence of an overriding destination set ($du,
as would be the case if you used ds_select_dst()).
> When Kamailio can’t reach the first destination, how does it internally
> handle the failover? Because once the SIP request has been relayed to
> the host, the script doesn’t have any instructions anymore.
You must arm a failure_route before t_relay(), and call
ds_select_domain() again to advance through the gateways in the
dispatcher set.
Example:
route[DISPATCHER_INITIAL] {
xlog("L_INFO", "[R-DISPATCHER-INITIAL:$ci] Entering dispatcher
selection route\n");
if(!ds_select_domain("1", "4")) {
# This should only happen if the route set is empty.
sl_send_reply("503", "Out of Gateways");
xlog("L_ERR", "[R-DISPATCHER-INITIAL:$ci] !> "
"No gateways available!\n");
exit;
}
xlog("L_INFO", "[R-DISPATCHER-INITIAL:$ci] -> "
"Selected gateway: $rd:$rp\n");
t_on_failure("DISPATCHER_ROLLOVER");
t_relay() etc blah blah;
}
failure_route[DISPATCHER_ROLLOVER] {
xlog("L_INFO", "[R-DISPATCHER-ROLLOVER:$ci] "
"Relay to dispatcher-selected gateway failed\n");
if(t_is_expired()) {
xlog("L_INFO", "[R-DISPATCHER-ROLLOVER:$ci] !> "
"Transaction expired - aborting\n");
exit;
}
if(t_is_canceled()) {
xlog("L_INFO", "[R-DISPATCHER-ROLLOVER:$ci] !> "
"Transaction cancelled - aborting\n");
exit;
}
if(!ds_next_domain()) {
# This should happen when we are out of gateways/have tried
# the last one in the route set.
xlog("L_ERR", "[R-DISPATCHER-ROLLOVER:$ci] !> "
"No more gateways in route set\n");
t_reply("503", "Out of gateways");
exit;
}
xlog("L_INFO", "[R-DISPATCHER-ROLLOVER:$ci] -> "
"Attempting relay to new gateway: $rd:$rp\n");
t_on_failure("DISPATCHER_ROLLOVER");
t_relay();
}
-- Alex
--
Alex Balashov - Principal
Evariste Systems LLC
235 E Ponce de Leon Ave
Suite 106
Decatur, GA 30030
United States
Tel: +1-678-954-0670
Web: http://www.evaristesys.com/, http://www.alexbalashov.com/
More information about the sr-users
mailing list