matrix_admin.xml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. <chapter>
  9. <title>&adminguide;</title>
  10. <section>
  11. <title>Overview</title>
  12. <para>
  13. The matrix module can be used to arbitrary lookup operations over an array.
  14. One possible usecase is to define which routing tree should
  15. be used depending on the preferred carrier of the source number and
  16. the carrier id of the destination number.
  17. The matrix cells are read from a database and can be reloaded using
  18. a FIFO command.
  19. You do not have to define all matrix cells. The matrix can be sparse.
  20. Currently, the implementation is designed for a small number of
  21. columns (they are stored in a linked list). This does
  22. not scale well and has to be replaced by more an efficient data
  23. data structure when needed.
  24. </para>
  25. </section>
  26. <section>
  27. <title>Dependencies</title>
  28. <section>
  29. <title>&kamailio; Modules</title>
  30. <para>
  31. The module depends on the following modules (in the other words
  32. the listed modules must be loaded before this module):
  33. </para>
  34. <itemizedlist>
  35. <listitem>
  36. <para><emphasis>none</emphasis></para>
  37. </listitem>
  38. </itemizedlist>
  39. </section>
  40. <section>
  41. <title>External Libraries or Applications</title>
  42. <para>
  43. The following libraries or applications must be installed
  44. before running &kamailio; with this module loaded:
  45. </para>
  46. <itemizedlist>
  47. <listitem>
  48. <para><emphasis>none</emphasis></para>
  49. </listitem>
  50. </itemizedlist>
  51. </section>
  52. </section>
  53. <section>
  54. <title>Parameters</title>
  55. <section>
  56. <title><varname>db_url</varname> (string)</title>
  57. <para>
  58. The URL for the database connection.
  59. </para>
  60. <para>
  61. <emphasis>
  62. Default value is <quote>&defaultrodb;</quote>.
  63. </emphasis>
  64. </para>
  65. <example>
  66. <title>Set <varname>db_url</varname> parameter</title>
  67. <programlisting format="linespecific">
  68. ...
  69. modparam("matrix", "db_url", "&defaultrodb;")
  70. ...
  71. </programlisting>
  72. </example>
  73. </section>
  74. <section>
  75. <title><varname>matrix_table</varname> (string)</title>
  76. <para>
  77. The name of the table containing the matrix data.
  78. </para>
  79. <para>
  80. <emphasis>
  81. Default value is <quote>matrix</quote>.
  82. </emphasis>
  83. </para>
  84. <example>
  85. <title>Set <varname>matrix_table</varname> parameter</title>
  86. <programlisting format="linespecific">
  87. ...
  88. modparam("matrix", "matrix_table", "matrix")
  89. ...
  90. </programlisting>
  91. </example>
  92. </section>
  93. <section>
  94. <title><varname>matrix_first_col</varname> (string)</title>
  95. <para>
  96. The name of the column containing the first row in the matrix.
  97. </para>
  98. <para>
  99. <emphasis>
  100. Default value is <quote>first</quote>.
  101. </emphasis>
  102. </para>
  103. <example>
  104. <title>Set <varname>matrix_first_col</varname> parameter</title>
  105. <programlisting format="linespecific">
  106. ...
  107. modparam("matrix", "matrix_first_col", "first")
  108. ...
  109. </programlisting>
  110. </example>
  111. </section>
  112. <section>
  113. <title><varname>matrix_second_col</varname> (string)</title>
  114. <para>
  115. The name of the column containing the second row in the matrix.
  116. </para>
  117. <para>
  118. <emphasis>
  119. Default value is <quote>second</quote>.
  120. </emphasis>
  121. </para>
  122. <example>
  123. <title>Set <varname>matrix_second_col</varname> parameter</title>
  124. <programlisting format="linespecific">
  125. ...
  126. modparam("matrix", "matrix_second_col", "second")
  127. ...
  128. </programlisting>
  129. </example>
  130. </section>
  131. <section>
  132. <title><varname>matrix_res_col</varname> (string)</title>
  133. <para>
  134. The name of the column containing the result ID to be used.
  135. </para>
  136. <para>
  137. <emphasis>
  138. Default value is <quote>res</quote>.
  139. </emphasis>
  140. </para>
  141. <example>
  142. <title>Set <varname>matrix_res_col</varname> parameter</title>
  143. <programlisting format="linespecific">
  144. ...
  145. modparam("matrix", "matrix_res_col", "res")
  146. ...
  147. </programlisting>
  148. </example>
  149. </section>
  150. </section>
  151. <section>
  152. <title>Functions</title>
  153. <section>
  154. <title>
  155. <function moreinfo="none">matrix (string first, string second, string dstavp)</function>
  156. </title>
  157. <para>
  158. Looks up the desired result ID in the matrix for the given column
  159. and value and saves the result in dstavp. Returns false if the cell
  160. is not defined or when an error occured.
  161. Pseudo-variables or AVPs can be used for first and second.
  162. </para>
  163. <example>
  164. <title><function>matrix</function> usage</title>
  165. <programlisting format="linespecific">
  166. ...
  167. if (!matrix("$avp(first)", "$avp(second)", "$avp(route_tree)"))
  168. $avp(route_tree) = $avp(frst); # default routing as defined for source number
  169. }
  170. cr_route("$avp(route_tree)", "$rd", "$rU", "$rU", "call_id");
  171. ...
  172. </programlisting>
  173. </example>
  174. </section>
  175. </section>
  176. <section>
  177. <title><acronym>MI</acronym> Commands</title>
  178. <section>
  179. <title>
  180. <function moreinfo="none">reload_matrix</function>
  181. </title>
  182. <para>
  183. Reloads the internal matrix representation from the database.
  184. This is necessary after entries in the database have been changed.
  185. </para>
  186. <example>
  187. <title><function>reload_matrix</function> usage</title>
  188. <programlisting format="linespecific">
  189. ...
  190. kamctl fifo reload_matrix
  191. ...
  192. </programlisting>
  193. </example>
  194. </section>
  195. </section>
  196. <section>
  197. <title>Installation and Running</title>
  198. <section>
  199. <title>Database setup</title>
  200. <para>
  201. Before running &kamailio; with matrix, you have to setup the database
  202. table where the module will read the matrix data. For that, if
  203. the table was not created by the installation script or you choose
  204. to install everything by yourself you can use the matrix-create.sql
  205. <acronym>SQL</acronym> script in the database directories in the
  206. kamailio/scripts folder as template.
  207. Database, table, and column names can be set with module parameters so they
  208. can be changed.
  209. You can also find the complete database documentation on the
  210. project webpage, &kamailiodbdocs;.
  211. </para>
  212. <example>
  213. <title>Example database content - matrix table</title>
  214. <programlisting format="linespecific">
  215. ...
  216. +---------+--------------+---------+
  217. | first | second | res |
  218. +---------+--------------+---------+
  219. | 1 | 9 | 2 |
  220. | 2 | 69 | 1 |
  221. | 2 | 13 | 3 |
  222. +---------+--------------+---------+
  223. ...
  224. </programlisting>
  225. </example>
  226. </section>
  227. </section>
  228. </chapter>