2
0

lcr_admin.xml 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137
  1. <?xml version="1.0" encoding='ISO-8859-1'?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
  4. <!-- Include general documentation entities -->
  5. <!ENTITY % docentities SYSTEM "../../../docbook/entities.xml">
  6. %docentities;
  7. ]>
  8. <!-- Module User's Guide -->
  9. <chapter>
  10. <title>&adminguide;</title>
  11. <section>
  12. <title>Overview</title>
  13. <para>
  14. The Least Cost Routing (LCR) module implements capability to
  15. serially forward a request to one or more gateways so that the
  16. order in which the gateways is tried is based on admin defined
  17. "least cost" rules.
  18. </para>
  19. <para>
  20. The LCR module supports many independent LCR instances (gateways and
  21. least cost rules). Each such instance has its own <emphasis>LCR
  22. identifier.</emphasis>
  23. </para>
  24. <para>
  25. For the purpose of facilitating least cost routing of requests,
  26. each gateway of an LCR instance belongs to a gateway group and
  27. each gateway group is associated with one or more
  28. &lt;prefix, from pattern, priority&gt;
  29. tuples. A gateway matches a request if the user part of the Request URI
  30. matches a "prefix" and the caller's URI matches a "from" pattern in a
  31. tuple that belongs to the group of the gateway.
  32. </para>
  33. <para>
  34. When the function <emphasis>load_gws()</emphasis> is called, matching gateways (that are
  35. not currently designated as defunct) are ordered
  36. for forwarding purposes in the following order:
  37. <itemizedlist>
  38. <listitem>
  39. <para>(1) according to longest user part match
  40. </para>
  41. </listitem>
  42. <listitem>
  43. <para>(2) according to tuple's priority
  44. </para>
  45. </listitem>
  46. <listitem>
  47. <para>(3) gateway's randomized weight within its group
  48. </para>
  49. </listitem>
  50. </itemizedlist>
  51. Prefix is a string of characters or NULL. From
  52. pattern is a regular expression (see 'man
  53. pcresyntax' for syntax), an empty string, or NULL. An empty or
  54. NULL from pattern or prefix matches anything.
  55. Smaller priority value means higher priority (highest priority
  56. value being 0). Weight is an integer value from 1 to 254.
  57. </para>
  58. <para>
  59. The function <emphasis>next_gw()</emphasis> can then be used to select one gateway at a
  60. time for forwarding. Upon each call, the user part of the original request URI is first
  61. stripped by the number of characters as specified by the gateway's strip count and then prefixed by
  62. the gateway's tag. Upon first call, if a gateway's hostname is NULL, the request URI will be
  63. rewritten based on gateway's URI scheme, IP address, port, and transport protocol. If hostname is not NULL,
  64. the request-URI is rewritten based on the gateway's URI scheme and hostname, and destination URI is set
  65. based on gateway's URI scheme, IP address, port, and transport protocol. Upon
  66. subsequent calls, the same is done, but instead of rewriting the Request URI, a new branch is added.
  67. </para>
  68. <para>
  69. Valid URI scheme values are NULL = sip, 1 = sip and 2
  70. = sips. Currently valid transport protocol values are NULL =
  71. none, 1 = udp, 2 = tcp, 3 = tls, and 4 = sctp.
  72. </para>
  73. <para>
  74. As a side effect of the gateway selection, the gateway's flags (that may
  75. contain information about capabilities of the gateway)
  76. are stored into an AVP.
  77. </para>
  78. </section>
  79. <section>
  80. <title>Dependencies</title>
  81. <section>
  82. <title>&siprouter; modules</title>
  83. <para>
  84. The following modules must be loaded before this module:
  85. <itemizedlist>
  86. <listitem>
  87. <para>
  88. <emphasis>TM module</emphasis>
  89. </para>
  90. </listitem>
  91. <listitem>
  92. <para>
  93. <emphasis>A database module like mysql, postgres or
  94. dbtext</emphasis>.
  95. </para>
  96. </listitem>
  97. </itemizedlist>
  98. </para>
  99. </section>
  100. <section>
  101. <title>External libraries or applications</title>
  102. <para>
  103. The following libraries or applications must be installed before
  104. running &siprouter; with this module:
  105. <itemizedlist>
  106. <listitem>
  107. <para>
  108. <emphasis>none</emphasis>.
  109. </para>
  110. </listitem>
  111. </itemizedlist>
  112. </para>
  113. </section>
  114. </section>
  115. <section>
  116. <title>Exported Parameters</title>
  117. <section>
  118. <title><varname>db_url</varname> (string)</title>
  119. <para>
  120. &url; of the database table to be used.
  121. </para>
  122. <para>
  123. <emphasis>
  124. Default value is
  125. <quote>&defaultrodb;</quote>.
  126. </emphasis>
  127. </para>
  128. <example>
  129. <title>Setting <varname>db_url</varname> module parameter</title>
  130. <programlisting format="linespecific">
  131. ...
  132. modparam("lcr","db_url","&exampledb;")
  133. ...
  134. </programlisting>
  135. </example>
  136. </section>
  137. <section>
  138. <title><varname>gw_table</varname> (string)</title>
  139. <para>
  140. Name of the table holding gateways definitions.
  141. </para>
  142. <para>
  143. <emphasis>
  144. Default value is <quote>gw</quote>.
  145. </emphasis>
  146. </para>
  147. <example>
  148. <title>Setting <varname>gw_table</varname> module parameter</title>
  149. <programlisting format="linespecific">
  150. ...
  151. modparam("lcr","gw_table","gw")
  152. ...
  153. </programlisting>
  154. </example>
  155. </section>
  156. <section>
  157. <title><varname>lcr_id_column</varname> (string)</title>
  158. <para>
  159. Name of the column holding the identifier of an LCR instance. Common to both gw and lcr tables.
  160. </para>
  161. <para>
  162. <emphasis>
  163. Default value is <quote>lcr_id</quote>.
  164. </emphasis>
  165. </para>
  166. <example>
  167. <title>Setting <varname>lcr_id_column</varname> module parameter</title>
  168. <programlisting format="linespecific">
  169. ...
  170. modparam("lcr", "lcr_id_column", "lcr_identifier")
  171. ...
  172. </programlisting>
  173. </example>
  174. </section>
  175. <section>
  176. <title><varname>gw_name_column</varname> (string)</title>
  177. <para>
  178. Name of the column holding the gateway name.
  179. </para>
  180. <para>
  181. <emphasis>
  182. Default value is <quote>gw_name</quote>.
  183. </emphasis>
  184. </para>
  185. <example>
  186. <title>Setting <varname>gw_name_column</varname> module parameter</title>
  187. <programlisting format="linespecific">
  188. ...
  189. modparam("lcr","gw_name_column","gw_name")
  190. ...
  191. </programlisting>
  192. </example>
  193. </section>
  194. <section>
  195. <title><varname>grp_id_column</varname> (string)</title>
  196. <para>
  197. Name of the column holding the group ID of gateway both
  198. in gw and lcr tables.
  199. </para>
  200. <para>
  201. <emphasis>
  202. Default value is <quote>grp_id</quote>.
  203. </emphasis>
  204. </para>
  205. <example>
  206. <title>Setting <varname>grp_id_column</varname> module parameter</title>
  207. <programlisting format="linespecific">
  208. ...
  209. modparam("lcr","grp_id_column","grp_id")
  210. ...
  211. </programlisting>
  212. </example>
  213. </section>
  214. <section>
  215. <title><varname>ip_addr_column</varname> (string)</title>
  216. <para>
  217. Name of the column holding the IP address of the gateway.
  218. </para>
  219. <para>
  220. <emphasis>
  221. Default value is <quote>ip_addr</quote>.
  222. </emphasis>
  223. </para>
  224. <example>
  225. <title>Setting <varname>ip_addr_column</varname> module parameter</title>
  226. <programlisting format="linespecific">
  227. ...
  228. modparam("lcr","ip_addr_column","ip_addr")
  229. ...
  230. </programlisting>
  231. </example>
  232. </section>
  233. <section>
  234. <title><varname>hostname_column</varname> (string)</title>
  235. <para>
  236. Name of the column holding gateway's hostname that is
  237. used in Request-URI, when request is sent to the
  238. gateway. Note that request is not forwarded based on
  239. hostname, but based on gateway's IP address in
  240. destination URI.
  241. </para>
  242. <para>
  243. <emphasis>
  244. Default value is <quote>hostname</quote>.
  245. </emphasis>
  246. </para>
  247. <example>
  248. <title>Setting <varname>hostname_column</varname> module parameter</title>
  249. <programlisting format="linespecific">
  250. ...
  251. modparam("lcr", "hostname_column","hostname")
  252. ...
  253. </programlisting>
  254. </example>
  255. </section>
  256. <section>
  257. <title><varname>port_column</varname> (string)</title>
  258. <para>
  259. Name of the column holding the port number of the gateway.
  260. </para>
  261. <para>
  262. <emphasis>
  263. Default value is <quote>port</quote>.
  264. </emphasis>
  265. </para>
  266. <example>
  267. <title>Setting <varname>port_column</varname> module parameter</title>
  268. <programlisting format="linespecific">
  269. ...
  270. modparam("lcr","port_column","port")
  271. ...
  272. </programlisting>
  273. </example>
  274. </section>
  275. <section>
  276. <title><varname>uri_scheme_column</varname> (string)</title>
  277. <para>
  278. Name of the column holding the uri scheme of the gateway.
  279. </para>
  280. <para>
  281. <emphasis>
  282. Default value is <quote>uri_scheme</quote>.
  283. </emphasis>
  284. </para>
  285. <example>
  286. <title>Setting <varname>uri_scheme_column</varname> module
  287. parameter</title>
  288. <programlisting format="linespecific">
  289. ...
  290. modparam("lcr","uri_scheme_column","uri_scheme")
  291. ...
  292. </programlisting>
  293. </example>
  294. </section>
  295. <section>
  296. <title><varname>transport_column</varname> (string)</title>
  297. <para>
  298. Name of the column holding the transport type to be used for
  299. the gateway.
  300. </para>
  301. <para>
  302. <emphasis>
  303. Default value is <quote>transport</quote>.
  304. </emphasis>
  305. </para>
  306. <example>
  307. <title>Setting <varname>transport_column</varname> module
  308. parameter</title>
  309. <programlisting format="linespecific">
  310. ...
  311. modparam("lcr","transport_column","transport")
  312. ...
  313. </programlisting>
  314. </example>
  315. </section>
  316. <section>
  317. <title><varname>strip_column</varname> (string)</title>
  318. <para>
  319. Name of the column holding the number of characters
  320. to be stripped from the front of Request URI user part
  321. before inserting tag.
  322. </para>
  323. <para>
  324. <emphasis>
  325. Default value is <quote>strip</quote>.
  326. </emphasis>
  327. </para>
  328. <example>
  329. <title>Setting <varname>strip_column</varname> module
  330. parameter</title>
  331. <programlisting format="linespecific">
  332. ...
  333. modparam("lcr","strip_column","strip_count")
  334. ...
  335. </programlisting>
  336. </example>
  337. </section>
  338. <section>
  339. <title><varname>tag_column</varname> (string)</title>
  340. <para>
  341. Name of the column holding gateway specific tag string.
  342. </para>
  343. <para>
  344. <emphasis>
  345. Default value is <quote>tag</quote>.
  346. </emphasis>
  347. </para>
  348. <example>
  349. <title>Setting <varname>tag_column</varname> module parameter</title>
  350. <programlisting format="linespecific">
  351. ...
  352. modparam("lcr","tag_column","gw_tag")
  353. ...
  354. </programlisting>
  355. </example>
  356. </section>
  357. <section>
  358. <title><varname>weight_column</varname> (string)</title>
  359. <para>
  360. Name of the column holding gateway's weight within its group.
  361. </para>
  362. <para>
  363. <emphasis>
  364. Default value is <quote>weight</quote>.
  365. </emphasis>
  366. </para>
  367. <example>
  368. <title>Setting <varname>weight_column</varname> module parameter</title>
  369. <programlisting format="linespecific">
  370. ...
  371. modparam("lcr","weight_column","gw_weight")
  372. ...
  373. </programlisting>
  374. </example>
  375. </section>
  376. <section>
  377. <title><varname>flags_column</varname> (string)</title>
  378. <para>
  379. Name of the column holding gateway specific flag values.
  380. </para>
  381. <para>
  382. <emphasis>
  383. Default value is <quote>flags</quote>.
  384. </emphasis>
  385. </para>
  386. <example>
  387. <title>Setting <varname>flags_column</varname> module parameter</title>
  388. <programlisting format="linespecific">
  389. ...
  390. modparam("lcr","flags_column","gw_flags")
  391. ...
  392. </programlisting>
  393. </example>
  394. </section>
  395. <section>
  396. <title><varname>defunct_column</varname> (string)</title>
  397. <para>
  398. Name of the column holding UNIX timestamp telling the
  399. time until which the gw is considered as defunct.
  400. </para>
  401. <para>
  402. <emphasis>
  403. Default value is <quote>defunct</quote>.
  404. </emphasis>
  405. </para>
  406. <example>
  407. <title>Setting <varname>defunct_column</varname> module parameter</title>
  408. <programlisting format="linespecific">
  409. ...
  410. modparam("lcr","defunct_column","defunct_until")
  411. ...
  412. </programlisting>
  413. </example>
  414. </section>
  415. <section>
  416. <title><varname>lcr_table</varname> (string)</title>
  417. <para>
  418. Name of the table holding the LCR rules.
  419. </para>
  420. <para>
  421. <emphasis>
  422. Default value is <quote>lcr</quote>.
  423. </emphasis>
  424. </para>
  425. <example>
  426. <title>Setting <varname>lcr_table</varname> module parameter</title>
  427. <programlisting format="linespecific">
  428. ...
  429. modparam("lcr","lcr_table","lcr")
  430. ...
  431. </programlisting>
  432. </example>
  433. </section>
  434. <section>
  435. <title><varname>prefix_column</varname> (string)</title>
  436. <para>
  437. Name of the column holding prefix of Request URI user
  438. part.
  439. </para>
  440. <para>
  441. <emphasis>
  442. Default value is <quote>prefix</quote>.
  443. </emphasis>
  444. </para>
  445. <example>
  446. <title>Setting <varname>prefix_column</varname> module parameter</title>
  447. <programlisting format="linespecific">
  448. ...
  449. modparam("lcr","prefix_column","prefix")
  450. ...
  451. </programlisting>
  452. </example>
  453. </section>
  454. <section>
  455. <title><varname>from_uri_column</varname> (string)</title>
  456. <para>
  457. Name of the column holding the FROM (source) URI.
  458. </para>
  459. <para>
  460. <emphasis>
  461. Default value is <quote>from_uri</quote>.
  462. </emphasis>
  463. </para>
  464. <example>
  465. <title>Setting <varname>from_uri_column</varname> module parameter</title>
  466. <programlisting format="linespecific">
  467. ...
  468. modparam("lcr","from_uri_column","from_uri")
  469. ...
  470. </programlisting>
  471. </example>
  472. </section>
  473. <section>
  474. <title><varname>priority_column</varname> (string)</title>
  475. <para>
  476. Name of the column holding the priority of the rule.
  477. </para>
  478. <para>
  479. <emphasis>
  480. Default value is <quote>priority</quote>.
  481. </emphasis>
  482. </para>
  483. <example>
  484. <title>Setting <varname>priority_column</varname> module parameter
  485. </title>
  486. <programlisting format="linespecific">
  487. ...
  488. modparam("lcr","priority_column","priority")
  489. ...
  490. </programlisting>
  491. </example>
  492. </section>
  493. <section>
  494. <title><varname>lcr_count</varname> (integer)</title>
  495. <para>
  496. Number of LCR instances.
  497. </para>
  498. <para>
  499. <emphasis>
  500. Default value is 1.
  501. </emphasis>
  502. </para>
  503. <example>
  504. <title>
  505. Setting <varname>lcr_count</varname> module
  506. parameter
  507. </title>
  508. <programlisting format="linespecific">
  509. ...
  510. modparam("lcr", "lcr_count", 10)
  511. ...
  512. </programlisting>
  513. </example>
  514. </section>
  515. <section>
  516. <title><varname>gw_uri_avp</varname> (AVP string)</title>
  517. <para>
  518. Internal AVP that load_gws() function uses to store
  519. information of matching gateways.
  520. </para>
  521. <para>
  522. <emphasis>
  523. There is NO default value, thus this variable must
  524. be defined in &siprouterconfig;.
  525. </emphasis>
  526. </para>
  527. <example>
  528. <title>Setting <varname>gw_uri_avp</varname> module parameter</title>
  529. <programlisting format="linespecific">
  530. ...
  531. modparam("lcr", "gw_uri_avp", "$avp(i:709)")
  532. ...
  533. </programlisting>
  534. </example>
  535. </section>
  536. <section>
  537. <title><varname>ruri_user_avp</varname> (AVP string)</title>
  538. <para>
  539. Internal AVP that next_gw function uses to store Request-URI user for
  540. subsequent next_gw calls.
  541. </para>
  542. <para>
  543. <emphasis>
  544. There is NO default value, thus this variable must
  545. be defined in &siprouterconfig;.
  546. </emphasis>
  547. </para>
  548. <example>
  549. <title>Setting <varname>ruri_user_avp</varname> module parameter</title>
  550. <programlisting format="linespecific">
  551. ...
  552. modparam("lcr", "ruri_user_avp", "$avp(i:500)")
  553. ...
  554. </programlisting>
  555. </example>
  556. </section>
  557. <section>
  558. <title><varname>flags_avp</varname> (AVP string)</title>
  559. <para>
  560. An AVP where successful next_gw and from_gw functions
  561. store gateway's flags.
  562. </para>
  563. <para>
  564. <emphasis>
  565. There is NO default value, thus this variable must
  566. be defined in &siprouterconfig;.
  567. </emphasis>
  568. </para>
  569. <example>
  570. <title>Setting <varname>flags_avp</varname> module parameter</title>
  571. <programlisting format="linespecific">
  572. ...
  573. modparam("lcr", "flags_avp", "$avp(i:712)")
  574. ...
  575. </programlisting>
  576. </example>
  577. </section>
  578. <section>
  579. <title><varname>defunct_capability</varname> (integer)</title>
  580. <para>
  581. Tells if defunct capability of (non-responsive) gateways is
  582. supported. Non-zero value turns on defunct capability.
  583. </para>
  584. <para>
  585. <emphasis>
  586. Default value is 0.
  587. </emphasis>
  588. </para>
  589. <example>
  590. <title>
  591. Setting <varname>defunct_capability</varname> module
  592. parameter
  593. </title>
  594. <programlisting format="linespecific">
  595. ...
  596. modparam("lcr", "defunct_capability", 1)
  597. ...
  598. </programlisting>
  599. </example>
  600. </section>
  601. <section>
  602. <title><varname>lcr_id_avp</varname> (AVP string)</title>
  603. <para>
  604. Internal AVP that load_gws() function uses to store
  605. LCR instance identifier of loaded gateways. Only needed if
  606. gateway defunct capability has been activated.
  607. </para>
  608. <para>
  609. <emphasis>
  610. There is NO default value.
  611. </emphasis>
  612. </para>
  613. <example>
  614. <title>Setting <varname>lcr_id_avp</varname> module parameter</title>
  615. <programlisting format="linespecific">
  616. ...
  617. modparam("lcr", "lcr_id_avp", "$avp(s:lcr_id_avp)")
  618. ...
  619. </programlisting>
  620. </example>
  621. </section>
  622. <section>
  623. <title><varname>defunct_gw_avp</varname> (AVP string)</title>
  624. <para>
  625. Internal AVP that next_gw() function uses to store IP address of the
  626. selected gateway for later use by defunct_gw() function. Only needed if
  627. gateway defunct capability has been activated.
  628. </para>
  629. <para>
  630. <emphasis>
  631. There is NO default value.
  632. </emphasis>
  633. </para>
  634. <example>
  635. <title>Setting <varname>defunct_gw_avp</varname> module parameter</title>
  636. <programlisting format="linespecific">
  637. ...
  638. modparam("lcr", "defunct_gw_avp", "$avp(s:defunct_gw_avp)")
  639. ...
  640. </programlisting>
  641. </example>
  642. </section>
  643. <section>
  644. <title><varname>lcr_hash_size</varname> (integer)</title>
  645. <para>
  646. Defines the size of hash table used to store &lt;prefix,
  647. from_pattern, priority&gt; tuples. Hashing is done based
  648. on prefix. Larger value means less collisions with
  649. other prefixes. Hash size value should be a power of
  650. 2.
  651. </para>
  652. <para>
  653. <emphasis>
  654. Default value is 128.
  655. </emphasis>
  656. </para>
  657. <example>
  658. <title>
  659. Setting <varname>lcr_hash_size</varname> module
  660. parameter
  661. </title>
  662. <programlisting format="linespecific">
  663. ...
  664. modparam("lcr", "lcr_hash_size", 1024)
  665. ...
  666. </programlisting>
  667. </example>
  668. </section>
  669. <section>
  670. <title><varname>fetch_rows</varname> (integer)</title>
  671. <para>
  672. The number of the rows to be fetched at once from database
  673. when loading data from the lcr table. This value can be used to tune
  674. the load time at startup. For 1MB of private memory (default)
  675. it should be below 3750. In order for this parameter to
  676. have effect, the database driver must support fetch_result()
  677. capability.
  678. </para>
  679. <para>
  680. <emphasis>
  681. Default value is <quote>2000</quote>.
  682. </emphasis>
  683. </para>
  684. <example>
  685. <title>Set <varname>fetch_rows</varname> parameter</title>
  686. <programlisting format="linespecific">
  687. ...
  688. modparam("lcr", "fetch_rows", 3000)
  689. ...
  690. </programlisting>
  691. </example>
  692. </section>
  693. </section>
  694. <section>
  695. <title>Exported Functions</title>
  696. <section>
  697. <title>
  698. <function moreinfo="none">load_gws(lcr_id, caller_uri)</function>
  699. </title>
  700. <para>
  701. Loads URI schemes, IP addresses, hostnames, ports, and
  702. transports of matching gateways to gw_uri_avp
  703. (see Overview section). Argument lcr_id specifies the used
  704. LCR instance. It can be an integer or a pseudo
  705. variable containing an integer value.
  706. Caller's URI is given by caller_uri argument, which
  707. must be a pseudo variable.
  708. </para>
  709. <para>
  710. Returns 1 on success and -1 on error.
  711. </para>
  712. <para>
  713. Execution time of load_gws() function is O(N) * O(M),
  714. where N is number of different prefix lengths and M
  715. is number of collisions for matching prefix(es) in lcr
  716. hash table of the LCR instance.
  717. </para>
  718. <para>
  719. This function can be used from REQUEST_ROUTE.
  720. </para>
  721. <example>
  722. <title><function>load_gws</function> usage</title>
  723. <programlisting format="linespecific">
  724. ...
  725. if (!load_gws("1", "$var(caller_uri)")) {
  726. sl_send_reply("500", "Server Internal Error - Cannot load gateways");
  727. exit;
  728. };
  729. ...
  730. </programlisting>
  731. </example>
  732. </section>
  733. <section>
  734. <title>
  735. <function moreinfo="none">next_gw()</function>
  736. </title>
  737. <para>
  738. Upon first call, replaces URI scheme, host,
  739. port, and transport of Request-URI by the values stored
  740. in first gw_uri_avp and destroys that AVP (see
  741. Overview section). Saves user part of Request-URI into
  742. ruri_user_avp for use in subsequent next_gw() calls.
  743. </para>
  744. <para>
  745. Upon subsequent calls, appends a new branch URI to
  746. the request, where URI scheme, host, port, and transport of
  747. are taken from values stored in the first gw_uri_avp
  748. and destroys that AVP. URI user is taken from
  749. ruri_user_avp.
  750. </para>
  751. <para>
  752. As a side effect, stores gateway's flags to flags_avp.
  753. </para>
  754. <para>
  755. Returns 1 on success and -1 if there were no gateways
  756. left or if an error occurred (see syslog).
  757. </para>
  758. <para>
  759. Must be preceded by successful load_gws() call.
  760. </para>
  761. <para>
  762. This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
  763. </para>
  764. <example>
  765. <title><function>next_gw</function> usage from a route block</title>
  766. <programlisting format="linespecific">
  767. ...
  768. if (!next_gw()) {
  769. sl_send_reply("503", "Service not available - No gateways");
  770. exit;
  771. };
  772. ...
  773. </programlisting>
  774. </example>
  775. <example>
  776. <title><function>next_gw</function> usage from a failure route block
  777. </title>
  778. <programlisting format="linespecific">
  779. ...
  780. if (!next_gw()) {
  781. t_reply("503", "Service not available - No more gateways");
  782. exit;
  783. };
  784. ...
  785. </programlisting>
  786. </example>
  787. </section>
  788. <section>
  789. <title>
  790. <function moreinfo="none">defunct_gw(period)</function>
  791. </title>
  792. <para>
  793. Defuncts gateway selected by preceding next_gw() call
  794. for a period of seconds given as argument. Argument
  795. must be a positive integer constant or a pseudo variable
  796. with positive integer value. Value of defunct column in
  797. database is not updated.
  798. </para>
  799. <para>
  800. Returns 1 on success and -1 in case of error (see syslog).
  801. </para>
  802. <para>
  803. Must be preceded by successful next_gw() call.
  804. </para>
  805. <para>
  806. This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
  807. </para>
  808. <example>
  809. <title><function>defunct_gw</function> usage</title>
  810. <programlisting format="linespecific">
  811. ...
  812. defunct_gw("60");
  813. ...
  814. </programlisting>
  815. </example>
  816. </section>
  817. <section>
  818. <title>
  819. <function moreinfo="none">from_gw(lcr_id [, ip_addr])</function>
  820. </title>
  821. <para>
  822. Checks if request comes from IP address of a
  823. gateway in LCR instance specified by lcr_id argument,
  824. which can be an integer constant or a pseudo variable
  825. with integer value.
  826. IP address to be checked is either
  827. taken from source IP address of the request or
  828. (if present) from ip_addr pseudo variable argument.
  829. </para>
  830. <para>
  831. If request comes from a gateway, gateway's flags are
  832. stored into flags_avp as side effect.
  833. </para>
  834. <para>
  835. Returns 1 on success and -1 on failure or on error.
  836. </para>
  837. <para>
  838. Execution time of from_gw() function is O(log N),
  839. where N is number of gateways in the LCR instance.
  840. </para>
  841. <para>
  842. This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
  843. ONREPLY_ROUTE.
  844. </para>
  845. <example>
  846. <title><function>from_gw</function> usage</title>
  847. <programlisting format="linespecific">
  848. ...
  849. if (from_gw("1", "$avp(s:real_source_addr)") {
  850. ...
  851. };
  852. ...
  853. </programlisting>
  854. </example>
  855. </section>
  856. <section>
  857. <title>
  858. <function moreinfo="none">from_any_gw([ip_addr])</function>
  859. </title>
  860. <para>
  861. Checks if request comes from IP address of
  862. any gateway. IP address to be checked is either
  863. taken from source IP address of the request or
  864. (if present) from ip_addr pseudo variable argument.
  865. </para>
  866. <para>
  867. If any gateway has the IP address, function returns LCR
  868. identifier
  869. of the gateway. Returns -1 on error or if the request does
  870. not come from a gateway.
  871. </para>
  872. <para>
  873. If request comes from a gateway, the gateway's flags are stored into flags_avp
  874. as side effect.
  875. </para>
  876. <para>
  877. Execution time of from_gw() function is M * O(log N),
  878. where M is number of LCR instances and N is average number of
  879. gateways in LCR instances.
  880. </para>
  881. <para>
  882. This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
  883. ONREPLY_ROUTE.
  884. </para>
  885. <example>
  886. <title><function>from_gw</function> usage</title>
  887. <programlisting format="linespecific">
  888. ...
  889. $var(lcr_id) = from_any_gw();
  890. ...
  891. </programlisting>
  892. </example>
  893. </section>
  894. <section>
  895. <title>
  896. <function moreinfo="none">to_gw(lcr_id [, ip_addr])</function>
  897. </title>
  898. <para>
  899. Checks if in-dialog request goes to a gateway in LCR
  900. instance specified by lcr_id argument. IP address to be
  901. checked is either taken from Request-URI hostpart or (if
  902. present) from ip_addr pseudo variable argument.
  903. </para>
  904. <para>
  905. Returns 1 on success and -1 on failure and error.
  906. </para>
  907. <para>
  908. Execution time of to_gw() function is O(log N),
  909. where N is number of gateways in the LCR instance.
  910. </para>
  911. <para>
  912. This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
  913. </para>
  914. <example>
  915. <title><function>to_gw</function> usage</title>
  916. <programlisting format = "linespecific">
  917. ...
  918. if (to_gw("1")) {
  919. ...
  920. exit;
  921. };
  922. ...
  923. </programlisting>
  924. </example>
  925. </section>
  926. <section>
  927. <title>
  928. <function moreinfo="none">to_any_gw([ip_addr])</function>
  929. </title>
  930. <para>
  931. Checks if in-dialog request goes to any gateway. IP
  932. address to be checked is either taken from Request-URI
  933. hostpart or (if present) from ip_addr pseudo variable
  934. argument.
  935. </para>
  936. <para>
  937. Execution time of to_any_gw() function is M * O(log N),
  938. where M is number of LCR instances and N is average
  939. number of gateways in LCR instances.
  940. </para>
  941. <para>
  942. If any gateway has the IP address, returns LCR identifier
  943. of the gateway. Returns -1 if request does
  944. not go to a gateway and on error.
  945. </para>
  946. <para>
  947. This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
  948. </para>
  949. <example>
  950. <title><function>to_gw</function> usage</title>
  951. <programlisting format = "linespecific">
  952. ...
  953. if (to_any_gw()) {
  954. ...
  955. exit;
  956. };
  957. ...
  958. </programlisting>
  959. </example>
  960. </section>
  961. </section>
  962. <section>
  963. <title>Exported MI Commands</title>
  964. <section>
  965. <title><function>lcr_reload</function></title>
  966. <para>
  967. Causes lcr module to re-read the contents of
  968. gw and lcr tables into memory.
  969. </para>
  970. <para>
  971. Reload fails if number of
  972. gateways is larger than value of constant
  973. MAX_NO_OF_GWS in file lcr_mod.h, which
  974. defaults to 128. If you have more than 128
  975. gateways, you need
  976. to increase the value of this constant and recompile
  977. lcr module.
  978. </para>
  979. <para>
  980. Name: <emphasis>lcr_reload</emphasis>
  981. </para>
  982. <para>Parameters: <emphasis>none</emphasis></para>
  983. <para>
  984. MI FIFO Command Format:
  985. </para>
  986. <programlisting format="linespecific">
  987. :lcr_reload:_reply_fifo_file_
  988. _empty_line_
  989. </programlisting>
  990. </section>
  991. <section>
  992. <title><function>lcr_gw_dump</function></title>
  993. <para>
  994. Causes lcr module to dump the contents of its
  995. in-memory gw table.
  996. </para>
  997. <para>
  998. Name: <emphasis>lcr_gw_dump</emphasis>
  999. </para>
  1000. <para>Parameters: <emphasis>none</emphasis></para>
  1001. <para>
  1002. MI FIFO Command Format:
  1003. </para>
  1004. <programlisting format="linespecific">
  1005. :lcr_gw_dump:_reply_fifo_file_
  1006. _empty_line_
  1007. </programlisting>
  1008. </section>
  1009. <section>
  1010. <title><function>lcr_lcr_dump</function></title>
  1011. <para>
  1012. Causes lcr module to dump the contents of its
  1013. in-memory lcr table.
  1014. </para>
  1015. <para>
  1016. Name: <emphasis>lcr_lcr_dump</emphasis>
  1017. </para>
  1018. <para>Parameters: <emphasis>none</emphasis></para>
  1019. <para>
  1020. MI FIFO Command Format:
  1021. </para>
  1022. <programlisting format="linespecific">
  1023. :lcr_gw_dump:_reply_fifo_file_
  1024. _empty_line_
  1025. </programlisting>
  1026. </section>
  1027. </section>
  1028. <section>
  1029. <title>Exported RPC Commands</title>
  1030. <section>
  1031. <title><function>lcr.reload</function></title>
  1032. <para>
  1033. Causes lcr module to re-read the contents of
  1034. gw and lcr tables into memory.
  1035. </para>
  1036. <para>
  1037. Name: <emphasis>lcr.reload</emphasis>
  1038. </para>
  1039. <para>Parameters: <emphasis>none</emphasis></para>
  1040. <example>
  1041. <title><function>lcr.reload</function> RPC example</title>
  1042. <programlisting format="linespecific">
  1043. $ sercmd lcr.reload
  1044. </programlisting>
  1045. </example>
  1046. </section>
  1047. <section>
  1048. <title><function>lcr.dump_gws</function></title>
  1049. <para>
  1050. Causes lcr module to dump the contents of its
  1051. in-memory gw table.
  1052. </para>
  1053. <para>Parameters: <emphasis>none</emphasis></para>
  1054. <example>
  1055. <title><function>lcr.dump_gws</function> RPC example</title>
  1056. <programlisting format="linespecific">
  1057. $ sercmd lcr.dump_gws
  1058. </programlisting>
  1059. </example>
  1060. </section>
  1061. <section>
  1062. <title><function>lcr.dump_lcrs</function></title>
  1063. <para>
  1064. Causes lcr module to dump the contents of its
  1065. in-memory lcr table.
  1066. </para>
  1067. <para>Parameters: <emphasis>none</emphasis></para>
  1068. <example>
  1069. <title><function>lcr.dump_lcr</function> RPC example</title>
  1070. <programlisting format="linespecific">
  1071. $ sercmd lcr.dump_lcrs
  1072. </programlisting>
  1073. </example>
  1074. </section>
  1075. </section>
  1076. <section>
  1077. <title>Known Limitations</title>
  1078. <para>
  1079. In-memory gateway and in-memory lcr table are switched
  1080. by two consecutive machine instructions. If lcr reload
  1081. process is interrupted after the first one, in-memory
  1082. gateway table does not match in-memory lcr table until
  1083. execution of lcr reload process is resumed.
  1084. </para>
  1085. </section>
  1086. </chapter>