OpenSIPS: dispatcher
Referensi http://www.opensips.org/html/docs/modules/1.6.x/dispatcher.html
1.4.1. ds_select_dst(set, alg)
The method selects a destination from addresses set.
Meaning of the parameters is as follows:
- set - the id of the set from where to pick up destination address. It is the first column in destination list file.
- alg - the algorithm used to select the destination address.
“0” - hash over callid “1” - hash over from uri. “2” - hash over to uri. “3” - hash over request-uri. “4” - round-robin (next destination). "5” - hash over authorization-username (Proxy-Authorization or "normal" authorization). If no username is found, round robin is used. “6” - random (using rand()). “7” - hash over the content of PVs string. Note: This works only when the parameter hash_pvar is set. “8” - the first entry in set is chosen. “X” - if the algorithm is not implemented, the first entry in set is chosen.
If the bit 2 in 'flags' is set, the rest of the addresses from the destination set is stored in AVP list. You can use 'ds_next_dst()' to use next address to achieve serial forking to all possible destinations.
This function can be used from REQUEST_ROUTE and FAILURE_ROUTE.
Example 1.26. ds_select_dst usage
... ds_select_dst("1", "0"); ...
1.6.1. Destination List File
Each destination point must be on one line. First token is the set id, followed by destination address. Optionally, the third field can be flags value (1 - destination inactive, 2 - destination in probing mod -- you can do bitwise OR to set both flags). The set id must be an integer value. Destination address must be a valid SIP URI. Empty lines or lines starting with “#” are ignored.
Example 1.28. dispatcher list file
... # $Id: dispatcher.list 5901 2009-07-21 07:45:05Z bogdan_iancu $ # dispatcher destination sets # # line format # setit(integer) destination(sip uri) flags (integer, optional) # proxies 2 sip:127.0.0.1:5080 2 sip:127.0.0.1:5082 # gateways 1 sip:127.0.0.1:7070 1 sip:127.0.0.1:7072 1 sip:127.0.0.1:7074 ...
1.6.2. OpenSIPS config file
Next picture displays a sample usage of dispatcher.
Example 1.29. OpenSIPS config script - sample dispatcher usage
...
# # $Id: dispatcher.cfg 5901 2009-07-21 07:45:05Z bogdan_iancu $ # sample config file for dispatcher module # debug=9 # debug level (cmd line: -dddddddddd) fork=no log_stderror=yes # (cmd line: -E) children=2 check_via=no # (cmd. line: -v) dns=off # (cmd. line: -r) rev_dns=off # (cmd. line: -R) port=5060 # for more info: sip_router -h # ------------------ module loading ---------------------------------- mpath="/usr/local/lib/opensips/modules/" loadmodule "maxfwd.so" loadmodule "sl.so" loadmodule "dispatcher.so" # loadmodule "modules/tm/tm.so" # ----------------- setting module-specific parameters --------------- # -- dispatcher params -- modparam("dispatcher", "list_file", "../etc/dispatcher.list") # modparam("dispatcher", "force_dst", 1) route{ if ( !mf_process_maxfwd_header("10") ) { sl_send_reply("483","To Many Hops"); drop(); }; ds_select_dst("2", "0"); forward(); # t_relay(); }
loadmodule "dispatcher.so" . modparam("dispatcher","list_file","/usr/local/etc/opensips/dispatcher.cfg") .
changed route to use dispatcher
route[3]{ if (uri =~ "sip:001[0-9]@*"){ log(1, "Forwarding to Asterisk \n"); ds_select_dst("2","4"); forward(); route(1); exit; }
My dispatcher Config Looks like below
dispatcher.cfg
2 sip:a2b-asterisk-ip:5062 2 sip:a2b-asterisk-ip2:5062