Kamailio AVPs - Attribute-Value Pairs

From open-voip.org

Jump to: navigation, search

Contents

AVP - overview

  • used for manipulating the user preferences.
  • pairs of value (string, integer) and identifier
  • AVP tied to transaction. allocated when transaction start and unallocated when finished.
  • can be used from the kamailio script or from MySQL
  • all AVPs being loaded from a database come from the usr_preference table
  • you can associate an AVP to a uuid, username or username+domain in multi-domain setup.

usage:

$avp(id[N])

where ID is:

  • si:name - AVP identifier name. s - string. i - integer
  • name - name of alias AVP

Examples:

$avp(i:700)
$avp(s:blacklist)

AVPOPS Module

in order to use AVP, we need to define the following:

mpath="/usr/local/lib/kamailio/modules"
loadmodule "avpops.so"
modparam("avpops", "avp_url","mysql://openser:asterisk@localhost/openser")
modparam("avpops", "avp_table", "usr_preferences")

usr_preferences table

  • uuid - unique user identifier
  • username
  • domain
  • attribute - the AVP name
  • type
    • 0 - AVP with string name and string value
    • 1 - AVP with string name and integer value
    • 2 - AVP with integer name and string value
    • 3 - AVP with integer name and integer value
  • value - AVP value
  • last modified


AVP functions

  • avp_db_load - loads from DB to memory
  • avp_db_store - store AVP to DB
  • avp_db_delete - Delete AVP from DB
  • avp_db_query - Make DB query and store in AVP
  • avp_delete - Delete AVP from memory
  • avp_pushto - push AVP value to SIP message
  • avp_check - check value of AVP using < > =
  • avp_copy - copy AVP to another
  • avp_printf - format a string to an AVP
  • avp_subst - find and replace values into an AVP
  • avp_op - math operations on AVPs
  • is_avp_set - check if this AVP is set
  • avp_print - print all AVP from memory (debug_

use example

Syntax:

avp_db_load(source,name)
source = (sip_uri|avp_alias|str_value) ['/'('username'|'domain'|'uri'|'uuid')]
          sip_uri = '$from' | '$to' | '$ruri' 
name = (|'s:'|'i:'|avp_name|avp_alias)['/'db_spec]
          db_spec = table_name | '$'db_scheme_name 

example:

 if (avp_db_load("$ruri/username", "s:callfwd")) { 
   avp_pushto("$ruri", "s:callfwd");
   route(6);
   break;
 };
  • avp_db_load will load the callfwd AVP from the DB by the ruri of the current message. search will be done by "username" column.
  • avp_pushto will replcae the ruri in the current message with the one we got from the DB ("callfwd").

The value at the DB of the callfwd should be as follow: File:kamailio_AVP_table.JPG

Personal tools