User Tools

Site Tools


cookbooks:5.2.x:core

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
cookbooks:5.2.x:core [2019/01/02 09:13]
mslehto [onreply_route] clarify core reply_route vs. TM onreply_route
cookbooks:5.2.x:core [2019/10/30 00:30]
joelsdc
Line 47: Line 47:
 </code> </code>
  
 +Usually setting a parameter is ended by end of line, but it can be also ended with **;** (semicolon). This should be used when the grammar of a parameter allows values on multiple lines (like **listen** or **alias**) and the next line creates a conflict by being swallowed as part of value for previous parameter.
 +
 +<code c>
 +alias="sip.mydomain.com";
 +</code>
 +
 +If you want to use a reserved config keyword as part of a parameter, you need to enclose it in quotes. See the example below for the keyword "dns".
 +
 +<code c>
 +listen=tcp:127.0.0.1:5060 advertise "sip.dns.example.com":5060
 +</code>
 ==== Modules Settings Section ==== ==== Modules Settings Section ====
  
Line 725: Line 736:
 ==== auto_bind_ipv6 ==== ==== auto_bind_ipv6 ====
  
-When turned on, Kamailio will automatically bind to all IPv6 addresses (much like the default behaviour for IPv4).+When turned on, Kamailio will automatically bind to all IPv6 addresses (much like the default behaviour for IPv4). Default value is off.
  
 Example: Example:
Line 855: Line 866:
 ==== flags ==== ==== flags ====
  
-**Alias name: bool**+SIP message (transaction) flags can have string names.  
 +The //name// for flags cannot be used for **branch** or **script flags**(*) 
 + 
 + 
 +<code c> 
 +... 
 +flags 
 +  FLAG_ONE   : 1, 
 +  FLAG_TWO   : 2; 
 +... 
 +</code> 
 + 
 +(*) The named flags feature was propagated from the source code merge back in 2008 and is not extensively tested. The recommended way of defining flags is using [[cookbooks:5.2.x:core#define|#!define]] (which is also valid for branch/script flags): 
 +<code c> 
 +#!define FLAG_NAME FLAG_BIT 
 +</code> 
  
 ==== force_rport ==== ==== force_rport ====
Line 971: Line 998:
 ==== latency_limit_db ==== ==== latency_limit_db ====
  
-Limit of latency in ms for db operations. If a db operation executed via DB API v1 takes longer that its value, a message is printed in the logs, showing the first 50 characters of the db query.+Limit of latency in us (micro-seconds) for db operations. If a db operation executed via DB API v1 takes longer that its value, a message is printed in the logs, showing the first 50 characters of the db query.
  
  
Line 1386: Line 1413:
 ==== pv_buffer_size ==== ==== pv_buffer_size ====
  
-The size in bytes of internal buffer to print dynamic strings with pseudo-variables inside. The default value is 8192 (8kB).+The size in bytes of internal buffer to print dynamic strings with pseudo-variables inside. The default value is 8192 (8kB). Please keep in mind that for xlog messages, there is a dedicated module parameter to set the internal buffer size.
  
 Example of usage: Example of usage:
Line 1425: Line 1452:
  
     reply_to_via=0     reply_to_via=0
 +    
 +==== route_locks_size ====
 +
 +Set the number of mutex locks to be used for synchronizing the execution of messages sharing the same Call-Id. In other words, enables Kamailio to execute sequentially the requests and replies received within the same dialog -- a new message received within the same dialog waits until the previous one is routed out.
 +
 +For smaller impact on parallel processing, its value it should be at least twice the number of kamailio processes (children
 +
 +Example:
 +
 +<code c>
 +route_locks_size = 256
 +</code>
 ==== server_id ==== ==== server_id ====
  
Line 3106: Line 3145:
   * groupid - should be the name of the module that triggers the event   * groupid - should be the name of the module that triggers the event
   * eventid - some meaningful short text describing the event   * eventid - some meaningful short text describing the event
 +
  
 Implementations: Implementations:
  
   * **event_route[core:worker-one-init]** - executed by core after the first udp sip worker process executed the child_init() for all modules, before starting to process sip traffic   * **event_route[core:worker-one-init]** - executed by core after the first udp sip worker process executed the child_init() for all modules, before starting to process sip traffic
-    * note that due to forking, other sip workers can get faster to listening for sip traffic 
- 
-<code c> 
-event_route[core:worker-one-init] { 
-        xlog("L_INFO","Hello world\n"); 
-} 
-</code> 
- 
-  * **event_route[htable:mod-init]** - executed by **htable** module after all modules have been initialised. Good for initialising values in hash tables. 
-<code c> 
-modparam("htable", "htable", "a=>size=4;") 
- 
-event_route[htable:mod-init] { 
-  $sht(a=>calls-to::10.10.10.10) = 0; 
-  $sht(a=>max-calls-to::10.10.10.10) = 100; 
-} 
- 
-request_route { 
-  if(is_method("INVITE") && !has_totag()) 
-  { 
-    switch($rd) { 
-      case "10.10.10.10": 
-        lock("calls-to::10.10.10.10"); 
-        $sht(a=>calls-to::10.10.10.10) = 
-            $sht(a=>calls-to::10.10.10.10) + 1; 
-        unlock("calls-to::10.10.10.10"); 
-        if($sht(a=>calls-to::10.10.10.10)>$sht(a=>max-calls-to::10.10.10.10)) 
-        { 
-           sl_send_reply("500", "To many calls to .10"); 
-           exit; 
-        } 
-      break; 
-      ... 
-    } 
-  } 
-} 
-</code> 
-  * **event_route [tm:local-request]** - executed on locally generated requests. 
-<code c> 
-event_route [tm:local-request] { # Handle locally generated requests 
-  xlog("L_INFO", "Routing locally generated $rm to <$ru>\n"); 
-  t_set_fr(10000, 10000); 
-} 
-</code> 
- 
-  * **event_route [tm:branch-failure]** - executed on all failure responses. 
-<code c> 
-event_route [tm:failure-branch] { # Handle failure response 
-  xlog("L_INFO", "Handling $T_reply_code response to $rm to <$ru>\n"); 
-  if (t_check_status("430")) { # Outbound flow failed 
-    unregister("location", "$tu", "$T_reply_ruid"); 
-    if (t_next_contact_flow()) { 
-      t_relay(); 
-    } 
-  } 
-} 
-</code> 
- 
-===== Script Statements ===== 
- 
-==== if ==== 
-IF-ELSE statement 
- 
-Prototype: 
- 
-<code> 
-    if(expr) { 
-       actions; 
-    } else { 
-       actions; 
-    } 
-</code> 
- 
-The 'expr' should be a valid logical expression. 
- 
-The logical operators that can be used in 'expr': 
- 
-<code> 
-  ==      equal 
-  !=      not equal 
-  =~      regular expression matching: Note: Posix regular expressions will be used, e.g. use [[:digit:]]{3} instead of \d\d\d 
-  !~      regular expression not-matching (NOT PORTED from Kamailio 1.x, use '!(x =~ y)') 
-  >       greater 
-  >=      greater or equal 
-  <       less 
-  <=      less or equal 
-  &&      logical AND 
-  ||      logical OR 
-  !       logical NOT 
-  [ ... ] test operator - inside can be any arithmetic expression 
-</code> 
- 
-Example of usage: 
- 
-    if(is_method("INVITE")) 
-    { 
-        log("this sip message is an invite\n"); 
-    } else { 
-        log("this sip message is not an invite\n"); 
-    } 
- 
- 
-==== switch ==== 
- 
-SWITCH statement - it can be used to test the value of a pseudo-variable.  
- 
-IMPORTANT NOTE: 'break' can be used only to mark the end of a 'case' branch (as it is in shell scripts). If you are trying to use 'break' outside a 'case' block the script will return error -- you must use 'return' there. 
- 
- 
-Example of usage: 
-<code> 
-    route { 
-        route(1); 
-        switch($retcode) 
-        { 
-            case -1: 
-                log("process INVITE requests here\n"); 
-            break; 
-            case 1: 
-                log("process REGISTER requests here\n"); 
-            break; 
-            case 2: 
-            case 3: 
-                log("process SUBSCRIBE and NOTIFY requests here\n"); 
-            break; 
-            default: 
-                log("process other requests here\n"); 
-       } 
- 
-        # switch of R-URI username 
-        switch($rU) 
-        { 
-            case "101": 
-                log("destination number is 101\n"); 
-            break; 
-            case "102": 
-                log("destination number is 102\n"); 
-            break; 
-            case "103": 
-            case "104": 
-                log("destination number is 103 or 104\n"); 
-            break; 
-            default: 
-                log("unknown destination number\n"); 
-       } 
-    } 
- 
-    route[1]{ 
-        if(is_method("INVITE")) 
-        { 
-            return(-1); 
-        }; 
-        if(is_method("REGISTER")) 
-            return(1); 
-        } 
-        if(is_method("SUBSCRIBE")) 
-            return(2); 
-        } 
-        if(is_method("NOTIFY")) 
-            return(3); 
-        } 
-        return(-2); 
-    } 
-</code> 
- 
-NOTE: take care while using 'return' - 'return(0)' stops the execution of the script. 
- 
- 
-==== while ==== 
- 
-while statement 
- 
-Example of usage: 
-     
-    $var(i) = 0; 
-    while($var(i) < 10) 
-    { 
-        xlog("counter: $var(i)\n"); 
-        $var(i) = $var(i) + 1; 
-    } 
- 
-===== Script Operations ===== 
- 
-Assignments together with string and arithmetic operations can be done directly in configuration file. 
-==== Assignment ==== 
- 
-Assignments can be done like in C, via '=' (equal). The following pseudo-variables can be used in left side of an assignment: 
-  * Unordered List Item AVPs - to set the value of an AVP 
-  * script variables ($var(...)) -  to set the value of a script variable 
-  * shared variables ($shv(...)) 
-  * $ru - to set R-URI 
-  * $rd - to set domain part of R-URI 
-  * $rU - to set user part of R-URI 
-  * $rp - to set the port of R-URI 
-  * $du - to set dst URI 
-  * $fs - to set send socket 
-  * $br - to set branch 
-  * $mf - to set message flags value 
-  * $sf - to set script flags value 
-  * $bf - to set branch flags value 
- 
-<code> 
-$var(a) = 123; 
-</code> 
- 
-For avp's there a way to remove all values and assign a single value in one statement (in other words, delete existing AVPs with same name, add a new one with the right side value). This replaces the := assignment operator from kamailio < 3.0. 
-<code> 
-$(avp(i:3)[*]) = 123; 
-$(avp(i:3)[*]) = $null; 
-</code> 
- 
-==== String Operations ==== 
-For strings, '+' is available to concatenate. 
- 
-<code> 
-$var(a) = "test"; 
-$var(b) = "sip:" + $var(a) + "@" + $fd; 
-</code> 
-==== Arithmetic Operations ==== 
- 
-For numbers, one can use: 
-  * + : plus 
-  * - : minus 
-  * / : divide 
-  * * : multiply 
-  * % : modulo (Kamailio uses 'mod' instead of '%') 
-  * | : bitwise OR 
-  * & : bitwise AND 
-  * ^ : bitwise XOR 
-  * ~ : bitwise NOT 
-  * <nowiki><<</nowiki> : bitwise left shift 
-  * <nowiki>>></nowiki> : bitwise right shift 
- 
-Example: 
- 
-<code> 
-$var(a) = 4 + ( 7 & ( ~2 ) ); 
-</code> 
- 
-NOTE: to ensure the priority of operands in expression evaluations do use __parenthesis__. 
- 
-Arithmetic expressions can be used in condition expressions. 
- 
-<code> 
-if( $var(a) & 4 ) 
-    log("var a has third bit set\n"); 
-</code> 
- 
-===== Operators ===== 
- 
-  - type casts operators: (int), (str). 
-  - string comparison: eq, ne 
-  - integer comparison: ieq, ine  
- 
-Note: The names are not yet final (use them at your own risk). Future version might use ==/!= only for ints (ieq/ine) and eq/ne for strings (under debate). They are almost equivalent to == or !=, but they force the conversion of their operands (eq to string and ieq to int), allowing among other things better type checking on startup and more optimizations. 
- 
-Non equiv. examples: 
- 
-0 == "" (true) is not equivalent to 0 eq "" (false: it evaluates to "0" eq ""). 
- 
-"a" ieq "b" (true: (int)"a" is 0 and (int)"b" is 0) is not equivalent to "a" == "b" (false). 
- 
-Note: internally == and != are converted on startup to eq/ne/ieq/ine  whenever possible (both operand types can be safely determined at start time and they are the same).  
- 
-  - Kamailio tries to guess what the user wanted when operators that support multiple types are used on different typed operands. In general convert the right operand to the type of the left operand and then perform the operation. Exception: the left operand is undef. This applies to the following operators: +, == and !=. 
-     Special case: undef as left operand: 
-     For +: undef + expr -> undef is converted to string => "" + expr. 
-     For == and !=:   undef == expr -> undef is converted to type_of expr. 
-     If expr is undef, then undef == undef is true (internally is converted 
-     to string). 
- 
-  - expression evaluation changes: Kamailio will auto-convert to integer or string in function of the operators:  
-       int(undef)==0,  int("")==0, int("123")==123, int("abc")==0 
-       str(undef)=="", str(123)=="123". 
  
-  - script operators for dealing with empty/undefined variables 
-      defined expr - returns true if expr is defined, and false if not. 
-                     Note: only a standalone avp or pvar can be 
-                     undefined, everything else is defined. 
-      strlen(expr) - returns the lenght of expr evaluated as string. 
-      strempty(expr) - returns true if expr evaluates to the empty 
-                       string (equivalent to expr==""). 
-      Example: if (defined $v && !strempty($v)) $len=strlen($v); 
cookbooks/5.2.x/core.txt · Last modified: 2020/04/03 09:34 by henningw