Skip to content

Kamailio Dispatcher Algorithms: Full List for 2027

Every Kamailio dispatcher algorithm for ds_select_dst, from 0 to 16 and 64, by version, with what each needs and what an unknown number does.

By · Updated · Published

Too many cables
Photo by KIUI staff · CC BY 2.0 · via Flickr

What are the Kamailio dispatcher algorithms?

The algorithms are the numbered selection methods passed as the second argument of ds_select_dst(set, alg). The number tells Kamailio how to pick one destination from the set: by hash, in turn, at random, by priority, by weight, by active calls or by latency.

ds_select_dst returns true if a new destination is set. It sets the destination URI, which is the outbound proxy, and leaves the SIP message unchanged. ds_select_domain rewrites the host and port of the Request-URI instead. The optional limit argument sets the maximum number of items stored in the XAVP list for later failovers. See the official dispatcher module documentation.

Which algorithm number does what, and in which version?

We compiled every value of alg from the official dispatcher documentation on November 15, 2026. The compiled list uses the stable, 5.8.x, 6.0.x, 6.1.x and development pages. It is a reading of published documentation, not a benchmark. Software documentation applies in every country.

"All four" in the table below means the 5.8.x, 6.0.x, 6.1.x and development pages.

NumberWhat it doesWhat it needsListed in
0Hash over Call-IDNothing extraAll four
1Hash over From URINothing extraAll four
2Hash over To URINothing extraAll four
3Hash over Request-URI userNothing extraAll four
4Round-robinNothing extraAll four
5Hash over authorization username; round-robin if none is foundCredentials in the requestAll four
6Random destinationNothing extraAll four
7Hash over the content of pseudo-variableshash_pvar module parameterAll four
8Serial order by priority attributepriority attributeAll four
9Weight-based distributionweight attribute, 1 to 100 (percent of calls)All four
10Call load: fewest active calls, INVITE onlyduid attribute per address; ds_hash_size above 0All four
11Relative weight distributionrweight attribute, 1 to 100; optional cc=1All four
12Parallel forking to every destinationNothing extraAll four
13Latency-optimized round-robin that favors higher-priority gatewaysds_ping_latency_stats set to 1All four
14Round-robin if all destinations share one priority above 0, otherwise serial as in 8priority attribute6.1.x and development
15SRV-style: lowest priority value first, calls split by weight within that levelpriority and weight attributesDevelopment only
16Pressure-based: lowest pressure wins, round-robin on tiespressure attribute, changed through RPCDevelopment only
64Round-robin that skips destinations by overload control rateocrate and ocmin attributes6.0.x, 6.1.x and development
Any other valueFirst entry in the setNoneAll

Algorithms 0 to 13 appear in all four pages. Algorithm 64 starts in 6.0.x, and algorithm 14 starts in 6.1.x. The 5.8.x page lists algorithms 0 to 13 only. Algorithms 15 and 16 appear only in the development branch, as of November 15, 2026. Neither is in the 6.1.x documentation.

Which Kamailio load balancing algorithms spread calls evenly?

Round-robin (algorithm 4) sends each request to the next destination in the set. Random (algorithm 6) picks a destination using rand(). Neither needs extra attributes, so they are the simplest to start with.

Call load distribution (algorithm 10) picks the destination with the fewest active calls. It needs a duid attribute on every address and ds_hash_size greater than 0. The documentation says it works only for INVITE requests. The advanced examples at the end show it in a configuration.

How do weight (9) and relative weight (11) differ?

Algorithm 9 is weight-based distribution. Each address takes a weight attribute from 1 to 100, which is the percentage of calls it receives. The weights should add up to 100. Destinations that push the sum over 100 are ignored. If the sum is less than 100, the last destination fills the missing percentage. An invalid weight is set to 0.

Algorithm 11 is relative weight distribution. It uses an rweight attribute from 1 to 100. An active host's share is its rweight divided by the sum of the rweights of all active hosts in the group. Weights of 1, 2 and 1 split 100 calls as 25%, 50% and 25%. If the third destination becomes inactive, the first and second take 33% and 67%, and the third gets 0%. Algorithm 11 can also enable congestion control with cc=1 on a destination.

Which algorithms keep a caller on the same destination?

Photo of telephone, mobile, call
Photo by niekverlaan · Pixabay Content License · via Pixabay

The hashing algorithms do this. Algorithm 0 hashes over the Call-ID, 1 over the From URI, 2 over the To URI, 3 over the Request-URI user, 5 over the authorization username and 7 over the pseudo-variables named in hash_pvar. Algorithm 5 falls back to round-robin when no username is found.

The Call-ID contains a globally unique identifier for the call, so hashing over it keeps the messages of one call on one destination. The documentation calls the dispatcher stateless, but hashing algorithms still send later requests of the same dialog to the same destination. The documentation warns that hashing does not guarantee a fair distribution. Bit 1 of the flags parameter makes URI hashes use only the username part.

How do you set the ds_select_dst algorithm in kamailio.cfg?

Load the dispatcher module, point list_file at the destination list, and call ds_select_dst with a set id and an algorithm number. The default list path is /etc/kamailio/dispatcher.list or /usr/local/etc/kamailio/dispatcher.list, so the path below is an example.

In kamailio.cfg, the module is loaded and pointed at the list:

Kamailio config
loadmodule "dispatcher.so"
modparam("dispatcher", "list_file", "/run/kamailio/dispatcher.list")

Each line of the list has a set id, a destination, flags, a priority and attributes. The addresses below are documentation examples. Set 1 has two gateways whose weights add up to 100.

In dispatcher.list, the two gateways of set 1 are:

Output
1 sip:192.0.2.21 0 0 weight=50
1 sip:192.0.2.22 0 0 weight=50

In the route block of kamailio.cfg, the call is dispatched to set 1 with algorithm 9:

Kamailio config
route[DISPATCH] {
    if (!ds_select_dst("1", "9")) {
        send_reply("404", "No destination");
        exit;
    }
    route(RELAY);
}

route[RELAY] {
    t_relay();
    exit;
}

If ds_select_dst returns false, no destination was set, so the script replies 404. Otherwise the request goes to the destination URI that ds_select_dst set, and the RELAY route passes it on. t_relay() is a function of the tm module.

To check the loaded groups, use kamcmd from a shell:

Shell
kamcmd dispatcher.list
kamcmd dispatcher.reload

dispatcher.list lists the routing groups with their destination addresses and attributes. dispatcher.reload reloads the groups and destinations, but the documentation disables it for call load based dispatching (algorithm 10).

How do I fail over to the next destination when the selected one does not answer?

Flow chart: ds_select_dst("1", "4") picks a destination by round-robin or the script replies 404. t_on_failure and route(RELAY) send the request. The failure route exits if canceled, and only for a 500 reply or a local timeout calls ds_next_dst() and relays again.
How the dispatcher fails over to the next destination

Failover needs bit 2 of the flags module parameter. With it set, the remaining addresses of the set are stored in XAVPs, and ds_next_dst() moves to the next one. The documentation's sample sets flags to 2 and names the XAVPs with xavp_dst and xavp_ctx.

In kamailio.cfg, the documentation's failover setup looks like this. The dispatch uses round-robin (algorithm 4) on set 1:

Kamailio config
modparam("dispatcher", "flags", 2)
modparam("dispatcher", "xavp_dst", "_dsdst_")
modparam("dispatcher", "xavp_ctx", "_dsctx_")

route[DISPATCH] {
    if (!ds_select_dst("1", "4")) {
        send_reply("404", "No destination");
        exit;
    }
    t_on_failure("RTF_DISPATCH");
    route(RELAY);
}

failure_route[RTF_DISPATCH] {
    if (t_is_canceled()) {
        exit;
    }
    # next DST - only for 500 or local timeout
    if (t_check_status("500") or (t_branch_timeout() and !t_branch_replied())) {
        ds_next_dst();
        t_on_failure("RTF_DISPATCH");
        route(RELAY);
    }
}

The failure route exits when the call was canceled. It moves to the next destination only for a 500 reply or a local timeout. ds_next_dst() takes the next address from the XAVPs and sets it as the outbound proxy address, and the route then relays the request again. The RELAY route is the one defined in the previous section.

Two details matter here. Algorithm 12 does not set the XAVPs, so one failed branch cannot mark a single destination inactive. ds_mark_dst("ip") marks the last used address as inactive and probing.

What does a dispatched call look like message by message in sngrep?

Call flow: the caller sends INVITE to Kamailio, which replies 100 Trying and sends INVITE to the gateway. 180 Ringing and 200 OK come back through Kamailio, the caller sends ACK, then BYE goes from the caller via Kamailio to the gateway and 200 OK returns.
A dispatched call through Kamailio, as sngrep shows it

This walk-through follows one call as sngrep would show it, with the caller, Kamailio, and the gateway that ds_select_dst chose in the route block above. Each item is one SIP message, in the order it is sent.

  1. The caller sends INVITE to Kamailio.
  2. Kamailio sends 100 Trying back to the caller.
  3. Kamailio sends INVITE to the gateway.
  4. The gateway sends 180 Ringing to Kamailio.
  5. Kamailio sends 180 Ringing to the caller.
  6. The gateway sends 200 OK to Kamailio.
  7. Kamailio sends 200 OK to the caller.
  8. The caller sends ACK to Kamailio.

The call then ends:

  1. The caller sends BYE to Kamailio.
  2. Kamailio sends BYE to the gateway.
  3. The gateway sends 200 OK to Kamailio.
  4. Kamailio sends 200 OK to the caller.

Either side can end a call with a BYE, which is confirmed with a 200 OK. This example shows the caller ending it.

Advanced examples: how do failover and priorities combine?

The two examples below combine documented pieces. The first uses priority ordering with algorithm 8 and the failover route from the section above. The second uses call load distribution with duid and maxload attributes.

For the first example, set 3 holds two gateways with priority values. In dispatcher.list:

Output
3 sip:192.0.2.41 0 1
3 sip:192.0.2.42 0 5

The priority sets the initial ordering inside the set, and algorithm 8 selects destinations sorted by that priority value. In kamailio.cfg, the documentation's sample parameters and a priority route look like this:

Kamailio config
modparam("dispatcher", "flags", 2)
modparam("dispatcher", "xavp_dst", "_dsdst_")
modparam("dispatcher", "xavp_ctx", "_dsctx_")
modparam("dispatcher", "ds_ping_from", "sip:proxy@kamailio.org")
modparam("dispatcher", "ds_ping_interval", 60)
modparam("dispatcher", "ds_probing_mode", 1)
modparam("dispatcher", "ds_timer_mode", 1)

route[PRIORITY_DISPATCH] {
    if (!ds_select_dst("3", "8")) {
        send_reply("404", "No destination");
        exit;
    }
    t_on_failure("RTF_DISPATCH");
    route(RELAY);
}

ds_probing_mode controls which gateways are tested to see if they are reachable. The sample sets it to 1, along with ds_timer_mode. Use the failure_route[RTF_DISPATCH] from the failover section with this route. When a branch returns 500 or times out, ds_next_dst() moves to the next address in the set.

For the second example, the gateways of set 2 carry a duid and a maxload. In dispatcher.list:

Output
2 sip:192.0.2.31 0 0 duid=gw31;maxload=20
2 sip:192.0.2.32 0 0 duid=gw32;maxload=20

Every address needs a duid. maxload sets the upper limit of active calls per destination, and 0 means no limit. In kamailio.cfg, the call load route uses algorithm 10:

Kamailio config
modparam("dispatcher", "ds_hash_size", 1)

route[CALL_LOAD] {
    if (!ds_select_dst("2", "10")) {
        send_reply("404", "No destination");
        exit;
    }
    route(RELAY);
}

The documentation requires ds_hash_size to be greater than 0. The value 1 here is an example. Algorithm 10 works only for INVITE requests. It keeps its own call tracker keyed by Call-ID. The documentation's example calls ds_load_update() on BYE and CANCEL and on 2xx replies to INVITE, and ds_load_unset() on 3xx to 6xx replies, so the counts stay current.

More guides in Open-Source PBX and SIP Servers.

Frequently asked questions

Which algorithm number is call load distribution: 9 or 10?
Call load distribution is algorithm 10, which picks the destination with the fewest active calls. Algorithm 9 is weight-based distribution, so the two numbers do different jobs.
What happens if I pass an algorithm number that does not exist?
Kamailio chooses the first entry in the set. Check each number against the table above before you deploy the script.

Sources

  1. ds_select_dst(set, alg[, limit]) selects a destination from an address set and returns tru (www.kamailio.org)
  2. The Kamailio 5.8.x dispatcher documentation lists algorithms 0 to 13 only. (kamailio.org)
  3. The development-branch documentation, checked on November 15, 2026, adds algorithm 15 (SRV (kamailio.org)
  4. Algorithm 14 is round-robin when all destinations in the group have the same priority (gre (kamailio.org)
  5. In SIP, INVITE is the method used to establish a session. A proxy that receives an INVITE (www.rfc-editor.org)