Table of Contents
List of Examples
db_url
parametermatrix_table
parametermatrix_first_col
parametermatrix_second_col
parametermatrix_res_col
parametermatrix
usagereload_matrix
usagedb_url
parametermatrix_table
parametermatrix_first_col
parametermatrix_second_col
parametermatrix_res_col
parameterTable of Contents
The matrix module can be used to arbitrary lookup operations over an array. One possible usecase is to define which routing tree should be used depending on the preferred carrier of the source number and the carrier id of the destination number. The matrix cells are read from a database and can be reloaded using a FIFO command. You do not have to define all matrix cells. The matrix can be sparse. Currently, the implementation is designed for a small number of columns (they are stored in a linked list). This does not scale well and has to be replaced by more an efficient data data structure when needed.
The module depends on the following modules (in the other words the listed modules must be loaded before this module):
none
The URL for the database connection.
Default value is “mysql://kamailioro:kamailioro@localhost/kamailio”.
Example 1.1. Set db_url
parameter
... modparam("matrix", "db_url", "mysql://kamailioro:kamailioro@localhost/kamailio") ...
The name of the table containing the matrix data.
Default value is “matrix”.
The name of the column containing the first row in the matrix.
Default value is “first”.
Looks up the desired result ID in the matrix for the given column and value and saves the result in dstavp. Returns false if the cell is not defined or when an error occured. Pseudo-variables or AVPs can be used for first and second.
Example 1.6. matrix
usage
... if (!matrix("$avp(first)", "$avp(second)", "$avp(route_tree)")) $avp(route_tree) = $avp(frst); # default routing as defined for source number } cr_route("$avp(route_tree)", "$rd", "$rU", "$rU", "call_id"); ...
Before running Kamailio with matrix, you have to setup the database table where the module will read the matrix data. For that, if the table was not created by the installation script or you choose to install everything by yourself you can use the matrix-create.sql SQL script in the database directories in the kamailio/scripts folder as template. Database, table, and column names can be set with module parameters so they can be changed. You can also find the complete database documentation on the project webpage, http://www.kamailio.org/docs/db-tables/kamailio-db-devel.html.
Example 1.8. Example database content - matrix table
... +---------+--------------+---------+ | first | second | res | +---------+--------------+---------+ | 1 | 9 | 2 | | 2 | 69 | 1 | | 2 | 13 | 3 | +---------+--------------+---------+ ...
Table of Contents
URL to the database containing the data.
Default value is “mysql://kamailioro:kamailioro@localhost/kamailio”.
Example 2.1. Set db_url
parameter
... modparam("matrix", "db_url", "dbdriver://username:password@dbhost/dbname") ...
Name of the matrix table for the matrix module.
Default value is “matrix”.
The row index in the matrix