Advertisement
Guest User

Untitled

a guest
Sep 1st, 2017
844
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.19 KB | None | 0 0
  1. #!KAMAILIO
  2. #
  3. # sample config file for dispatcher module
  4. # - load balancing of VoIP calls with round robin
  5. # - no TPC listening
  6. # - don't dispatch REGISTER and presence requests
  7. #
  8. # Kamailio (OpenSER) SIP Server v3.2
  9. # - web: http://www.kamailio.org
  10. # - git: http://sip-router.org
  11. #
  12. # Direct your questions about this file to: sr-users@lists.sip-router.org
  13. #
  14. # Refer to the Core CookBook at http://www.kamailio.org/dokuwiki/doku.php
  15. # for an explanation of possible statements, functions and parameters.
  16. #
  17. # Several features can be enabled using '#!define WITH_FEATURE' directives:
  18. #
  19. # *** To run in debug mode:
  20. # - define WITH_DEBUG
  21. #
  22.  
  23. ####### Global Parameters #########
  24.  
  25. #!define WITH_DEBUG
  26.  
  27. #!ifdef WITH_DEBUG
  28. debug=2 #4
  29. log_stderror=yes
  30. #!else
  31. debug=2
  32. log_stderror=no
  33. #!endif
  34.  
  35. #!define WITH_NAT
  36.  
  37. memdbg=5
  38. memlog=5
  39.  
  40. log_facility=LOG_LOCAL0
  41.  
  42. fork=yes
  43. children=4
  44.  
  45. /* comment the next line to enable TCP */
  46. disable_tcp=yes
  47.  
  48. /* uncomment the next line to disable the auto discovery of local aliases
  49. based on revers DNS on IPs (default on) */
  50. #auto_aliases=no
  51.  
  52. /* add local domain aliases */
  53. # alias="mysipserver.com"
  54.  
  55. #advertised_address="165.227.66.108"
  56. #advertised_port=5060
  57.  
  58. #alias=138.197.49.44 # Floating IP
  59. #alias=10.132.115.211 # Private network
  60. #alias=165.227.66.108 # Public IP
  61.  
  62. #port=5060
  63.  
  64. /* uncomment and configure the following line if you want Kamailio to
  65. bind on a specific interface/port/proto (default bind on all available) */
  66. # listen=udp:138.197.49.44:5060
  67. #listen=udp:165.227.66.108:5060
  68. advertised_address="138.197.49.44"
  69. advertised_port=5060
  70.  
  71. sip_warning=no
  72.  
  73. ####### Modules Section ########
  74.  
  75. #set module path
  76. #mpath="/usr/local/lib64/kamailio/modules/"
  77. mpath="/usr/lib/x86_64-linux-gnu/kamailio/modules/"
  78.  
  79. # loadmodule "db_mysql.so"
  80. #loadmodule "mi_fifo.so"
  81. loadmodule "kex.so"
  82. loadmodule "tm.so"
  83. loadmodule "tmx.so"
  84. loadmodule "sl.so"
  85. loadmodule "rr.so"
  86. loadmodule "pv.so"
  87. loadmodule "maxfwd.so"
  88. loadmodule "textops.so"
  89. loadmodule "siputils.so"
  90. loadmodule "xlog.so"
  91. loadmodule "sanity.so"
  92. loadmodule "ctl.so"
  93. loadmodule "mi_rpc.so"
  94. loadmodule "mi_fifo.so"
  95. loadmodule "acc.so"
  96. loadmodule "dispatcher.so"
  97. #loadmodule "rtpproxy"
  98.  
  99. # ----------------- setting module-specific parameters ---------------
  100.  
  101.  
  102. # ----- mi_fifo params -----
  103. modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
  104.  
  105.  
  106. # ----- rr params -----
  107. # add value to ;lr param to cope with most of the UAs
  108. modparam("rr", "enable_full_lr", 1)
  109. # do not append from tag to the RR (no need for this script)
  110. modparam("rr", "append_fromtag", 0)
  111.  
  112.  
  113. # ----- acc params -----
  114. modparam("acc", "log_flag", 1)
  115. modparam("acc", "failed_transaction_flag", 3)
  116. modparam("acc", "log_extra",
  117. "src_user=$fU;src_domain=$fd;dst_ouser=$tU;dst_user=$rU;dst_domain=$rd;src_ip=$si")
  118.  
  119. # ----- tm params -----
  120. modparam("tm", "fr_timer", 2000)
  121. modparam("tm", "fr_inv_timer", 40000)
  122.  
  123. # ----- dispatcher params -----
  124. # modparam("dispatcher", "db_url",
  125. # "mysql://openser:openserro@localhost/openser")
  126. modparam("dispatcher", "table_name", "dispatcher")
  127. modparam("dispatcher", "flags", 2)
  128. modparam("dispatcher", "dst_avp", "$avp(AVP_DST)")
  129. modparam("dispatcher", "grp_avp", "$avp(AVP_GRP)")
  130. modparam("dispatcher", "cnt_avp", "$avp(AVP_CNT)")
  131. modparam("dispatcher", "list_file", "/etc/kamailio/dispatcher.list")
  132.  
  133. # ------ rtp proxy params -------
  134. #modparam("rtpproxy", "rtpproxy_sock", "udp:127.0.0.1:7722")
  135.  
  136. ####### Routing Logic ########
  137.  
  138.  
  139. # main request routing logic
  140.  
  141. route {
  142.  
  143. # per request initial checks
  144. route(REQINIT);
  145.  
  146. # handle requests within SIP dialogs
  147. route(WITHINDLG);
  148.  
  149. ### only initial requests (no To tag)
  150.  
  151. # CANCEL processing
  152. if (is_method("CANCEL"))
  153. {
  154. if (t_check_trans())
  155. t_relay();
  156. exit;
  157. }
  158.  
  159. t_check_trans();
  160.  
  161. # record routing for dialog forming requests (in case they are routed)
  162. # - remove preloaded route headers
  163. remove_hf("Route");
  164. if (is_method("INVITE|SUBSCRIBE"))
  165. record_route();
  166. #if (is_method("INVITE"))
  167. #{
  168. # ds_select_domain("1","4");
  169. # #sl_send_reply("300","Redirect");
  170. # #t_relay();
  171. # exit;
  172. #}
  173.  
  174. # account only INVITEs
  175. if (is_method("INVITE"))
  176. {
  177. setflag(1); # do accounting
  178. }
  179.  
  180. # handle presence related requests
  181. route(PRESENCE);
  182.  
  183. # handle registrations
  184. route(REGISTRAR);
  185.  
  186. if ($rU==$null)
  187. {
  188. # request with no Username in RURI
  189. sl_send_reply("484","Address Incomplete");
  190. exit;
  191. }
  192.  
  193. # dispatch destinations
  194. route(DISPATCH);
  195.  
  196. route(RELAY);
  197. }
  198.  
  199.  
  200. route[RELAY] {
  201. if (!t_relay()) {
  202. sl_reply_error();
  203. }
  204. exit;
  205. }
  206.  
  207. # Per SIP request initial checks
  208. route[REQINIT] {
  209. if (!mf_process_maxfwd_header("10")) {
  210. sl_send_reply("483","Too Many Hops");
  211. exit;
  212. }
  213.  
  214. if(!sanity_check("1511", "7"))
  215. {
  216. xlog("Malformed SIP message from $si:$sp\n");
  217. exit;
  218. }
  219. }
  220.  
  221. # Handle requests within SIP dialogs
  222. route[WITHINDLG] {
  223. if (has_totag()) {
  224. # sequential request withing a dialog should
  225. # take the path determined by record-routing
  226. if (loose_route()) {
  227. if (is_method("BYE")) {
  228. setflag(1); # do accounting ...
  229. setflag(3); # ... even if the transaction fails
  230. }
  231. route(RELAY);
  232. } else {
  233. if (is_method("SUBSCRIBE") && uri == myself) {
  234. # in-dialog subscribe requests
  235. route(PRESENCE);
  236. exit;
  237. }
  238. if ( is_method("ACK") ) {
  239. if ( t_check_trans() ) {
  240. # non loose-route, but stateful ACK;
  241. # must be ACK after a 487 or e.g. 404 from upstream server
  242. t_relay();
  243. exit;
  244. } else {
  245. # ACK without matching transaction ... ignore and discard.
  246. exit;
  247. }
  248. }
  249. sl_send_reply("404","Not here");
  250. }
  251. exit;
  252. }
  253. }
  254.  
  255. # Handle SIP registrations
  256. route[REGISTRAR] {
  257. if(!is_method("REGISTER"))
  258. return;
  259. #sl_send_reply("404", "No registrar");
  260. #t_relay();
  261. if(!ds_select_dst("1", "4"))
  262. {
  263. sl_send_reply("404", "No registrar");
  264. exit;
  265. }
  266. forward();
  267.  
  268. exit;
  269. }
  270.  
  271. # Presence server route
  272. route[PRESENCE] {
  273. if(!is_method("PUBLISH|SUBSCRIBE"))
  274. return;
  275.  
  276. sl_send_reply("404", "Not here");
  277. exit;
  278. }
  279.  
  280. # Dispatch requests
  281. route[DISPATCH] {
  282. # round robin dispatching on gateways group '1'
  283. if(!ds_select_dst("1", "4"))
  284. {
  285. send_reply("404", "No destination");
  286. exit;
  287. }
  288. xlog("L_DBG", "--- SCRIPT: going to <$ru> via <$du>\n");
  289. t_on_failure("RTF_DISPATCH");
  290. return;
  291. }
  292.  
  293. # Sample failure route
  294. failure_route[RTF_DISPATCH] {
  295. if (t_is_canceled()) {
  296. exit;
  297. }
  298. # next DST - only for 500 or local timeout
  299. if (t_check_status("500")
  300. or (t_branch_timeout() and !t_branch_replied()))
  301. {
  302. if(ds_next_dst())
  303. {
  304. t_on_failure("RTF_DISPATCH");
  305. route(RELAY);
  306. exit;
  307. }
  308. }
  309. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement