Vince-0

opensips.cfg cgrates osips tut

Feb 8th, 2022
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.49 KB | None | 0 0
  1. #
  2. # OpenSIPS residential configuration script
  3. # by OpenSIPS Solutions <[email protected]>
  4. #
  5. # This script was generated via "make menuconfig", from
  6. # the "Residential" scenario.
  7. # You can enable / disable more features / functionalities by
  8. # re-generating the scenario with different options.#
  9. #
  10. # Please refer to the Core CookBook at:
  11. # http://www.opensips.org/Resources/DocsCookbooks
  12. # for a explanation of possible statements, functions and parameters.
  13. #
  14.  
  15.  
  16. ####### Global Parameters #########
  17.  
  18. log_level=3
  19. log_stderror=no
  20. log_facility=LOG_LOCAL0
  21.  
  22. udp_workers=4
  23.  
  24. auto_aliases=no
  25.  
  26. #socket=udp:enp0s8:5060
  27. socket=udp:ens18:5060
  28.  
  29. ####### Modules Section ########
  30.  
  31. #set module path
  32. mpath="/usr/lib/x86_64-linux-gnu/opensips/modules/"
  33.  
  34. #### SIGNALING module
  35. loadmodule "signaling.so"
  36.  
  37. #### StateLess module
  38. loadmodule "sl.so"
  39.  
  40. #### Transaction Module
  41. loadmodule "tm.so"
  42. modparam("tm", "fr_timeout", 5)
  43. modparam("tm", "fr_inv_timeout", 30)
  44. modparam("tm", "restart_fr_on_each_reply", 0)
  45. modparam("tm", "onreply_avp_mode", 1)
  46.  
  47. #### Record Route Module
  48. loadmodule "rr.so"
  49. /* do not append from tag to the RR (no need for this script) */
  50. modparam("rr", "append_fromtag", 0)
  51.  
  52. #### MAX ForWarD module
  53. loadmodule "maxfwd.so"
  54.  
  55. #### SIP MSG OPerationS module
  56. loadmodule "sipmsgops.so"
  57.  
  58. #### FIFO Management Interface
  59. loadmodule "mi_fifo.so"
  60. modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
  61. modparam("mi_fifo", "fifo_mode", 0666)
  62.  
  63. #### USeR LOCation module
  64. loadmodule "usrloc.so"
  65. modparam("usrloc", "nat_bflag", "NAT")
  66. modparam("usrloc", "db_mode", 0)
  67.  
  68. #### REGISTRAR module
  69. loadmodule "registrar.so"
  70. modparam("registrar", "tcp_persistent_flag", "TCP_PERSISTENT")
  71.  
  72. #### ACCounting module
  73. loadmodule "acc.so"
  74. modparam("acc", "early_media", 0)
  75. modparam("acc", "report_cancels", 0)
  76. modparam("acc", "detect_direction", 0)
  77.  
  78. loadmodule "proto_udp.so"
  79.  
  80.  
  81. #### CGRateS module
  82. loadmodule "dialog.so"
  83. loadmodule "cgrates.so"
  84. modparam("cgrates", "cgrates_engine", "127.0.0.1:2014")
  85.  
  86. #### MySQL module
  87. loadmodule "db_mysql.so"
  88.  
  89. #### Drouting module
  90. loadmodule "drouting.so"
  91. modparam("drouting", "db_url",
  92. "mysql://opensips:opensipsrw@localhost/opensips")
  93.  
  94.  
  95. ####### Routing Logic ########
  96.  
  97. # main request routing logic
  98.  
  99. route{
  100.  
  101. if (!mf_process_maxfwd_header(10)) {
  102. send_reply(483,"Too Many Hops");
  103. exit;
  104. }
  105.  
  106. if (has_totag()) {
  107.  
  108. # handle hop-by-hop ACK (no routing required)
  109. if ( is_method("ACK") && t_check_trans() ) {
  110. t_relay();
  111. exit;
  112. }
  113.  
  114. # sequential request within a dialog should
  115. # take the path determined by record-routing
  116. if ( !loose_route() ) {
  117. # we do record-routing for all our traffic, so we should not
  118. # receive any sequential requests without Route hdr.
  119. send_reply(404, "Not here");
  120. exit;
  121. }
  122.  
  123. if (is_method("BYE")) {
  124. # do accounting even if the transaction fails
  125. do_accounting("log","failed");
  126. }
  127.  
  128. # route it out to whatever destination was set by loose_route()
  129. # in $du (destination URI).
  130. route(relay);
  131. exit;
  132. }
  133.  
  134. # CANCEL processing
  135. if (is_method("CANCEL")) {
  136. if (t_check_trans())
  137. t_relay();
  138. exit;
  139. }
  140.  
  141. # absorb retransmissions, but do not create transaction
  142. t_check_trans();
  143.  
  144. if ( !(is_method("REGISTER") ) ) {
  145.  
  146. if (is_myself("$fd")) {
  147.  
  148. } else {
  149. # if caller is not local, then called number must be local
  150.  
  151. if (!is_myself("$rd")) {
  152. send_reply(403,"Relay Forbidden");
  153. exit;
  154. }
  155. }
  156.  
  157. }
  158.  
  159. # preloaded route checking
  160. if (loose_route()) {
  161. xlog("L_ERR",
  162. "Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci]");
  163. if (!is_method("ACK"))
  164. send_reply(403, "Preload Route denied");
  165. exit;
  166. }
  167.  
  168. # record routing
  169. if (!is_method("REGISTER|MESSAGE"))
  170. record_route();
  171.  
  172. if (!is_myself("$rd")) {
  173. append_hf("P-hint: outbound\r\n");
  174.  
  175. route(relay);
  176. }
  177.  
  178. # requests for my domain
  179.  
  180. if (is_method("PUBLISH|SUBSCRIBE")) {
  181. send_reply(503, "Service Unavailable");
  182. exit;
  183. }
  184.  
  185. if (is_method("REGISTER")) {
  186.  
  187. if (!save("location"))
  188. sl_reply_error();
  189.  
  190. exit;
  191. }
  192.  
  193. if ($rU==NULL) {
  194. # request with no Username in RURI
  195. send_reply(484,"Address Incomplete");
  196. exit;
  197. }
  198.  
  199. # do lookup with method filtering
  200. if (!lookup("location","m")) {
  201. t_reply(404, "Not Found");
  202. exit;
  203. }
  204.  
  205. # check auth with CGRateS
  206. $cgr_opt(GetMaxUsage) = 1; # also retrieve the max usage
  207. $cgr_opt(GetAttributes) = 1;
  208. $cgr_opt(GetRoutes) = 1;
  209. $cgr_opt(AuthorizeResources) = 1;
  210. $cgr_opt(AllocateResources) = 1;
  211. $cgr_opt(ReleaseResources) = 1;
  212. $cgr_opt(ProcessThresholds) = 1;
  213. $cgr_opt(ProcessStatQueues) = 1;
  214. $cgr(RequestType) = "*prepaid";
  215. $cgr(OriginHost) = "127.0.0.1";
  216. $cgr(Source) = "OpenSIPS";
  217.  
  218. if (!async(cgrates_auth("$fU", "$rU"), resume_cgr_auth)) {
  219. sl_send_reply(503, "Service Unavailable");
  220. exit;
  221. }
  222. }
  223.  
  224. route [resume_cgr_auth] {
  225. $var(rc) = $rc;
  226. # with GetMaxUsage == false, cgrates_auth() returns -2 on success
  227. if ($var(rc) < 0 && ($cgr_ret(MaxUsage) != 0 || $var(rc) != -2)) {
  228. xlog("L_NOTICE", "[$ci] CGRateS auth failed: rc=$var(rc), code=$cgr_ret\n");
  229. send_reply(403, "Forbidden");
  230. exit;
  231. }
  232.  
  233. # Set the returned attributes from CGRateS as script pseudovariables
  234. $var(idx) = 0;
  235. while ($(cgr_ret(AttributesDigest){s.select,$var(idx),,}) != NULL) {
  236. $avp($(cgr_ret(AttributesDigest){s.select,$var(idx),,}{s.select,0,:}))
  237. = $(cgr_ret(AttributesDigest){s.select,$var(idx),,}{s.select,1,:});
  238. $var(idx) = $var(idx) + 1;
  239. }
  240.  
  241. # Enable CDRs being sent to CGRateS
  242. cgrates_acc("cdr|missed", "$fU", "$rU");
  243.  
  244. if ( $cgr_ret(RoutesDigest)==NULL ) { # no routing requested
  245. route(relay);
  246. }
  247.  
  248. xlog("L_INFO", "[$ci] CGRateS auth OK, with routes: <$cgr_ret(RoutesDigest)>\n");
  249. $avp(carriers) := $cgr_ret(RoutesDigest);
  250. $avp(carriers_idx) := 0;
  251.  
  252. route( to_carriers );
  253. }
  254.  
  255.  
  256. route[to_carriers] {
  257.  
  258. xlog("L_INFO", "[$ci] routing to carrier IDX $avp(carriers_idx)\n");
  259.  
  260. $var(carrier) = $(avp(carriers){s.select,$avp(carriers_idx),,});
  261. if ( $var(carrier) == NULL) {
  262. send_reply( 404 , "No route available to route");
  263. exit;
  264. }
  265. $cgr(RouteID) = $var(carrier);
  266.  
  267. xlog("L_INFO", "[$ci] routing to carrier <$var(carrier)>\n");
  268. $avp(carriers_idx) := $avp(carriers_idx) + 1;
  269.  
  270. if ( !route_to_carrier("$var(carrier)") ) {
  271. xlog("L_INFO", "[$ci] failed to route to carrier, skipping>\n");
  272. route( to_carriers );
  273. exit;
  274. }
  275.  
  276. t_on_failure("gw_failure");
  277. t_relay();
  278.  
  279. #end;
  280.  
  281. }
  282.  
  283. failure_route[gw_failure] {
  284. xlog("L_INFO", "[$ci] GW call failed to established with $T_reply_code code\n");
  285.  
  286. if (t_was_cancelled()) {
  287. exit;
  288. }
  289.  
  290. # failure indication about GWs?
  291. if ( t_check_status("(408)|([56][0-9][0-9])") ) {
  292. xlog("L_INFO", "[$ci] GW $rd failed with $T_reply_code -> retry\n");
  293. if ( use_next_gw() ) {
  294. xlog("L_INFO", "[$ci] using new GW <$rd>\n");
  295. t_on_failure("gw_failure");
  296. t_relay();
  297. #end
  298. }
  299.  
  300. # no more GWs for the carrier, try the next carrier
  301. route( to_carriers );
  302. }
  303.  
  304. }
  305.  
  306.  
  307.  
  308.  
  309. route[relay] {
  310. # for INVITEs enable some additional helper routes
  311. if (is_method("INVITE")) {
  312. t_on_branch("per_branch_ops");
  313. t_on_reply("handle_reply");
  314. t_on_failure("handle_failure");
  315. }
  316.  
  317. if (!t_relay()) {
  318. send_reply(500,"Internal Error");
  319. }
  320. exit;
  321. }
  322.  
  323.  
  324.  
  325.  
  326. branch_route[per_branch_ops] {
  327. xlog("new branch at $ru\n");
  328. }
  329.  
  330.  
  331. onreply_route[handle_reply] {
  332. xlog("incoming reply\n");
  333. }
  334.  
  335.  
  336. failure_route[handle_failure] {
  337. if (t_was_cancelled()) {
  338. exit;
  339. }
  340. }
  341.  
Advertisement
Add Comment
Please, Sign In to add comment