| 1 |
matrix Module |
| 2 |
|
| 3 |
Hardy Kahl |
| 4 |
|
| 5 |
1&1 Internet AG |
| 6 |
|
| 7 |
Edited by |
| 8 |
|
| 9 |
Henning Westerholt |
| 10 |
|
| 11 |
1&1 Internet AG |
| 12 |
<[email protected]> |
| 13 |
|
| 14 |
Copyright © 2008 1&1 Internet AG |
| 15 |
__________________________________________________________________ |
| 16 |
|
| 17 |
Table of Contents |
| 18 |
|
| 19 |
1. Admin Guide |
| 20 |
|
| 21 |
1. Overview |
| 22 |
2. Dependencies |
| 23 |
|
| 24 |
2.1. Kamailio Modules |
| 25 |
2.2. External Libraries or Applications |
| 26 |
|
| 27 |
3. Parameters |
| 28 |
|
| 29 |
3.1. db_url (string) |
| 30 |
3.2. matrix_table (string) |
| 31 |
3.3. matrix_first_col (string) |
| 32 |
3.4. matrix_second_col (string) |
| 33 |
3.5. matrix_res_col (string) |
| 34 |
|
| 35 |
4. Functions |
| 36 |
|
| 37 |
4.1. matrix (string first, string second, string dstavp) |
| 38 |
|
| 39 |
5. RPC Commands |
| 40 |
|
| 41 |
5.1. matrix.reload |
| 42 |
|
| 43 |
6. Installation and Running |
| 44 |
|
| 45 |
6.1. Database setup |
| 46 |
|
| 47 |
2. Module parameter for database access. |
| 48 |
|
| 49 |
1. db_url (String) |
| 50 |
2. matrix_table (String) |
| 51 |
3. matrix_first_col (string) |
| 52 |
4. matrix_second_col (string) |
| 53 |
5. matrix_res_col (string) |
| 54 |
|
| 55 |
List of Examples |
| 56 |
|
| 57 |
1.1. Set db_url parameter |
| 58 |
1.2. Set matrix_table parameter |
| 59 |
1.3. Set matrix_first_col parameter |
| 60 |
1.4. Set matrix_second_col parameter |
| 61 |
1.5. Set matrix_res_col parameter |
| 62 |
1.6. matrix usage |
| 63 |
1.7. matrix.reload usage |
| 64 |
1.8. Example database content - matrix table |
| 65 |
2.1. Set db_url parameter |
| 66 |
2.2. Set matrix_table parameter |
| 67 |
2.3. Set matrix_first_col parameter |
| 68 |
2.4. Set matrix_second_col parameter |
| 69 |
2.5. Set matrix_res_col parameter |
| 70 |
|
| 71 |
Chapter 1. Admin Guide |
| 72 |
|
| 73 |
Table of Contents |
| 74 |
|
| 75 |
1. Overview |
| 76 |
2. Dependencies |
| 77 |
|
| 78 |
2.1. Kamailio Modules |
| 79 |
2.2. External Libraries or Applications |
| 80 |
|
| 81 |
3. Parameters |
| 82 |
|
| 83 |
3.1. db_url (string) |
| 84 |
3.2. matrix_table (string) |
| 85 |
3.3. matrix_first_col (string) |
| 86 |
3.4. matrix_second_col (string) |
| 87 |
3.5. matrix_res_col (string) |
| 88 |
|
| 89 |
4. Functions |
| 90 |
|
| 91 |
4.1. matrix (string first, string second, string dstavp) |
| 92 |
|
| 93 |
5. RPC Commands |
| 94 |
|
| 95 |
5.1. matrix.reload |
| 96 |
|
| 97 |
6. Installation and Running |
| 98 |
|
| 99 |
6.1. Database setup |
| 100 |
|
| 101 |
1. Overview |
| 102 |
|
| 103 |
The matrix module can be used to arbitrary lookup operations over an |
| 104 |
array. One possible use-case is to define which routing tree should be |
| 105 |
used depending on the preferred carrier of the source number and the |
| 106 |
carrier id of the destination number. The matrix cells are read from a |
| 107 |
database and can be reloaded using a FIFO command. You do not have to |
| 108 |
define all matrix cells. The matrix can be sparse. Currently, the |
| 109 |
implementation is designed for a small number of columns (they are |
| 110 |
stored in a linked list). This does not scale well and has to be |
| 111 |
replaced by more an efficient data data structure when needed. |
| 112 |
|
| 113 |
2. Dependencies |
| 114 |
|
| 115 |
2.1. Kamailio Modules |
| 116 |
2.2. External Libraries or Applications |
| 117 |
|
| 118 |
2.1. Kamailio Modules |
| 119 |
|
| 120 |
The module depends on the following modules (in other words the listed |
| 121 |
modules must be loaded before this module): |
| 122 |
* none |
| 123 |
|
| 124 |
2.2. External Libraries or Applications |
| 125 |
|
| 126 |
The following libraries or applications must be installed before |
| 127 |
running Kamailio with this module loaded: |
| 128 |
* none |
| 129 |
|
| 130 |
3. Parameters |
| 131 |
|
| 132 |
3.1. db_url (string) |
| 133 |
3.2. matrix_table (string) |
| 134 |
3.3. matrix_first_col (string) |
| 135 |
3.4. matrix_second_col (string) |
| 136 |
3.5. matrix_res_col (string) |
| 137 |
|
| 138 |
3.1. db_url (string) |
| 139 |
|
| 140 |
The URL for the database connection. |
| 141 |
|
| 142 |
Default value is “mysql://kamailioro:kamailioro@localhost/kamailio”. |
| 143 |
|
| 144 |
Example 1.1. Set db_url parameter |
| 145 |
... |
| 146 |
modparam("matrix", "db_url", "mysql://kamailioro:kamailioro@localhost/kamailio") |
| 147 |
... |
| 148 |
|
| 149 |
3.2. matrix_table (string) |
| 150 |
|
| 151 |
The name of the table containing the matrix data. |
| 152 |
|
| 153 |
Default value is “matrix”. |
| 154 |
|
| 155 |
Example 1.2. Set matrix_table parameter |
| 156 |
... |
| 157 |
modparam("matrix", "matrix_table", "matrix") |
| 158 |
... |
| 159 |
|
| 160 |
3.3. matrix_first_col (string) |
| 161 |
|
| 162 |
The name of the column containing the first row in the matrix. |
| 163 |
|
| 164 |
Default value is “first”. |
| 165 |
|
| 166 |
Example 1.3. Set matrix_first_col parameter |
| 167 |
... |
| 168 |
modparam("matrix", "matrix_first_col", "first") |
| 169 |
... |
| 170 |
|
| 171 |
3.4. matrix_second_col (string) |
| 172 |
|
| 173 |
The name of the column containing the second row in the matrix. |
| 174 |
|
| 175 |
Default value is “second”. |
| 176 |
|
| 177 |
Example 1.4. Set matrix_second_col parameter |
| 178 |
... |
| 179 |
modparam("matrix", "matrix_second_col", "second") |
| 180 |
... |
| 181 |
|
| 182 |
3.5. matrix_res_col (string) |
| 183 |
|
| 184 |
The name of the column containing the result ID to be used. |
| 185 |
|
| 186 |
Default value is “res”. |
| 187 |
|
| 188 |
Example 1.5. Set matrix_res_col parameter |
| 189 |
... |
| 190 |
modparam("matrix", "matrix_res_col", "res") |
| 191 |
... |
| 192 |
|
| 193 |
4. Functions |
| 194 |
|
| 195 |
4.1. matrix (string first, string second, string dstavp) |
| 196 |
|
| 197 |
4.1. matrix (string first, string second, string dstavp) |
| 198 |
|
| 199 |
Looks up the desired result ID in the matrix for the given column and |
| 200 |
value and saves the result in dstavp. Returns false if the cell is not |
| 201 |
defined or when an error occurred. Pseudo-variables or AVPs can be used |
| 202 |
for first and second. |
| 203 |
|
| 204 |
Example 1.6. matrix usage |
| 205 |
... |
| 206 |
if (!matrix("$avp(first)", "$avp(second)", "$avp(route_tree)")) |
| 207 |
$avp(route_tree) = $avp(frst); # default routing as defined for source number |
| 208 |
} |
| 209 |
cr_route("$avp(route_tree)", "$rd", "$rU", "$rU", "call_id"); |
| 210 |
... |
| 211 |
|
| 212 |
5. RPC Commands |
| 213 |
|
| 214 |
5.1. matrix.reload |
| 215 |
|
| 216 |
5.1. matrix.reload |
| 217 |
|
| 218 |
Reloads the internal matrix representation from the database. This is |
| 219 |
necessary after entries in the database have been changed. |
| 220 |
|
| 221 |
Example 1.7. matrix.reload usage |
| 222 |
... |
| 223 |
kamctl rpc matrix.reload |
| 224 |
... |
| 225 |
|
| 226 |
6. Installation and Running |
| 227 |
|
| 228 |
6.1. Database setup |
| 229 |
|
| 230 |
6.1. Database setup |
| 231 |
|
| 232 |
Before running Kamailio with matrix, you have to set up the database |
| 233 |
table where the module will read the matrix data. For that, if the |
| 234 |
table was not created by the installation script or you choose to |
| 235 |
install everything by yourself you can use the matrix-create.sql SQL |
| 236 |
script in the database directories in the kamailio/scripts folder as |
| 237 |
template. Database, table, and column names can be set with module |
| 238 |
parameters so they can be changed. You can also find the complete |
| 239 |
database documentation on the project webpage, |
| 240 |
https://www.kamailio.org/docs/db-tables/kamailio-db-devel.html. |
| 241 |
|
| 242 |
Example 1.8. Example database content - matrix table |
| 243 |
... |
| 244 |
+---------+--------------+---------+ |
| 245 |
| first | second | res | |
| 246 |
+---------+--------------+---------+ |
| 247 |
| 1 | 9 | 2 | |
| 248 |
| 2 | 69 | 1 | |
| 249 |
| 2 | 13 | 3 | |
| 250 |
+---------+--------------+---------+ |
| 251 |
... |
| 252 |
|
| 253 |
Chapter 2. Module parameter for database access. |
| 254 |
|
| 255 |
Table of Contents |
| 256 |
|
| 257 |
1. db_url (String) |
| 258 |
2. matrix_table (String) |
| 259 |
3. matrix_first_col (string) |
| 260 |
4. matrix_second_col (string) |
| 261 |
5. matrix_res_col (string) |
| 262 |
|
| 263 |
1. db_url (String) |
| 264 |
|
| 265 |
URL to the database containing the data. |
| 266 |
|
| 267 |
Default value is “mysql://kamailioro:kamailioro@localhost/kamailio”. |
| 268 |
|
| 269 |
Example 2.1. Set db_url parameter |
| 270 |
... |
| 271 |
modparam("matrix", "db_url", "dbdriver://username:password@dbhost/dbname") |
| 272 |
... |
| 273 |
|
| 274 |
2. matrix_table (String) |
| 275 |
|
| 276 |
Name of the matrix table for the matrix module. |
| 277 |
|
| 278 |
Default value is “matrix”. |
| 279 |
|
| 280 |
Example 2.2. Set matrix_table parameter |
| 281 |
... |
| 282 |
modparam("matrix", "matrix_table", "matrix") |
| 283 |
... |
| 284 |
|
| 285 |
3. matrix_first_col (string) |
| 286 |
|
| 287 |
The row index in the matrix |
| 288 |
|
| 289 |
Example 2.3. Set matrix_first_col parameter |
| 290 |
... |
| 291 |
modparam("matrix", "matrix_first_col", "first") |
| 292 |
... |
| 293 |
|
| 294 |
4. matrix_second_col (string) |
| 295 |
|
| 296 |
The column index in the matrix |
| 297 |
|
| 298 |
Example 2.4. Set matrix_second_col parameter |
| 299 |
... |
| 300 |
modparam("matrix", "matrix_second_col", "second") |
| 301 |
... |
| 302 |
|
| 303 |
5. matrix_res_col (string) |
| 304 |
|
| 305 |
The resource contained in the matrix |
| 306 |
|
| 307 |
Example 2.5. Set matrix_res_col parameter |
| 308 |
... |
| 309 |
modparam("matrix", "matrix_res_col", "res") |
| 310 |
... |