lrkproxy:some features add to lrkproxy module master
authorMojtaba Esfandiari.S <mespio@gmail.com>
Fri, 3 Dec 2021 21:11:51 +0000 (00:41 +0330)
committerMojtaba Esfandiari.S <mespio@gmail.com>
Fri, 3 Dec 2021 21:11:51 +0000 (00:41 +0330)
add 'gt' option for optimization port resource allocation
add 'custom_sdp_ip_avp' option for handling NAT client

src/modules/lrkproxy/README
src/modules/lrkproxy/doc/lrkproxy_admin.xml
src/modules/lrkproxy/lrkproxy.c
src/modules/lrkproxy/lrkproxy_funcs.c
src/modules/lrkproxy/lrkproxy_funcs.h
src/modules/lrkproxy/lrkproxy_hash.c

index b43dd8b..8de720a 100644 (file)
@@ -31,6 +31,8 @@ Mojtaba Esfandiari.S
                     4.3.5. lrkp_alg (integer)
                     4.3.6. hash_table_tout (integer)
                     4.3.7. hash_table_size (integer)
                     4.3.5. lrkp_alg (integer)
                     4.3.6. hash_table_tout (integer)
                     4.3.7. hash_table_size (integer)
+                    4.3.8. custom_sdp_ip_avp (string)
+                    4.3.9. gt (integer)
 
               4.4. Functions
 
 
               4.4. Functions
 
@@ -46,8 +48,10 @@ Mojtaba Esfandiari.S
    1.5. Set lrkp_alg parameter
    1.6. Set hash_table_tout parameter
    1.7. Set hash_table_size parameter
    1.5. Set lrkp_alg parameter
    1.6. Set hash_table_tout parameter
    1.7. Set hash_table_size parameter
-   1.8. set_lrkproxy_set usage
-   1.9. lrkproxy_manage usage
+   1.8. Set custom_sdp_ip_avp parameter
+   1.9. Set gt parameter
+   1.10. set_lrkproxy_set usage
+   1.11. lrkproxy_manage usage
 
 Chapter 1. Admin Guide
 
 
 Chapter 1. Admin Guide
 
@@ -73,6 +77,8 @@ Chapter 1. Admin Guide
               4.3.5. lrkp_alg (integer)
               4.3.6. hash_table_tout (integer)
               4.3.7. hash_table_size (integer)
               4.3.5. lrkp_alg (integer)
               4.3.6. hash_table_tout (integer)
               4.3.7. hash_table_size (integer)
+              4.3.8. custom_sdp_ip_avp (string)
+              4.3.9. gt (integer)
 
         4.4. Functions
 
 
         4.4. Functions
 
@@ -142,6 +148,8 @@ Chapter 1. Admin Guide
         4.3.5. lrkp_alg (integer)
         4.3.6. hash_table_tout (integer)
         4.3.7. hash_table_size (integer)
         4.3.5. lrkp_alg (integer)
         4.3.6. hash_table_tout (integer)
         4.3.7. hash_table_size (integer)
+        4.3.8. custom_sdp_ip_avp (string)
+        4.3.9. gt (integer)
 
    4.4. Functions
 
 
    4.4. Functions
 
@@ -172,15 +180,19 @@ Chapter 1. Admin Guide
    Default value is “NONE” (disabled).
 
    Example 1.1. Set lrkproxy_sock parameter
    Default value is “NONE” (disabled).
 
    Example 1.1. Set lrkproxy_sock parameter
-...
-# single lrkproxy
-modparam("lrkproxy", "lrkproxy_sock", "udp:192.168.122.108:8080")
+                                                ...
+                                                # single lrkproxy
+                                                modparam("lrkproxy", "lrkproxy_s
+ock", "udp:192.168.122.108:8080")
 
 
-# multiple lrkproxies for LB in diffenrent machine
-modparam("lrkproxy", "lrkproxy_sock", "udp:192.168.122.108:8080")
-modparam("lrkproxy", "lrkproxy_sock", "udp:192.168.122.109:8080")
+                                                # multiple lrkproxies for LB in
+diffenrent machine
+                                                modparam("lrkproxy", "lrkproxy_s
+ock", "udp:192.168.122.108:8080")
+                                                modparam("lrkproxy", "lrkproxy_s
+ock", "udp:192.168.122.109:8080")
 
 
-...
+                                                ...
 
 4.3.2. lrkproxy_disable_tout (integer)
 
 
 4.3.2. lrkproxy_disable_tout (integer)
 
@@ -191,9 +203,10 @@ modparam("lrkproxy", "lrkproxy_sock", "udp:192.168.122.109:8080")
    Default value is “60”.
 
    Example 1.2. Set lrkproxy_disable_tout parameter
    Default value is “60”.
 
    Example 1.2. Set lrkproxy_disable_tout parameter
-...
-modparam("lrkproxy", "lrkproxy_disable_tout", 20)
-...
+                                                ...
+                                                modparam("lrkproxy", "lrkproxy_d
+isable_tout", 20)
+                                                ...
 
 4.3.3. lrkproxy_tout (integer)
 
 
 4.3.3. lrkproxy_tout (integer)
 
@@ -202,9 +215,10 @@ modparam("lrkproxy", "lrkproxy_disable_tout", 20)
    Default value is “1”.
 
    Example 1.3. Set lrkproxy_tout parameter
    Default value is “1”.
 
    Example 1.3. Set lrkproxy_tout parameter
-...
-modparam("lrkproxy", "lrkproxy_tout", 2)
-...
+                                                ...
+                                                modparam("lrkproxy", "lrkproxy_t
+out", 2)
+                                                ...
 
 4.3.4. lrkproxy_retr (integer)
 
 
 4.3.4. lrkproxy_retr (integer)
 
@@ -214,9 +228,10 @@ modparam("lrkproxy", "lrkproxy_tout", 2)
    Default value is “5”.
 
    Example 1.4. Set lrkproxy_retr parameter
    Default value is “5”.
 
    Example 1.4. Set lrkproxy_retr parameter
-...
-modparam("lrkproxy", "lrkproxy_retr", 2)
-...
+                                                ...
+                                                modparam("lrkproxy", "lrkproxy_r
+etr", 2)
+                                                ...
 
 4.3.5. lrkp_alg (integer)
 
 
 4.3.5. lrkp_alg (integer)
 
@@ -226,9 +241,10 @@ modparam("lrkproxy", "lrkproxy_retr", 2)
    Default value is “0”.
 
    Example 1.5. Set lrkp_alg parameter
    Default value is “0”.
 
    Example 1.5. Set lrkp_alg parameter
-...
-modparam("lrkproxy", "lrkp_alg", 1)
-...
+                                                ...
+                                                modparam("lrkproxy", "lrkp_alg",
+ 1)
+                                                ...
 
 4.3.6. hash_table_tout (integer)
 
 
 4.3.6. hash_table_tout (integer)
 
@@ -251,9 +267,10 @@ modparam("lrkproxy", "lrkp_alg", 1)
    Default value is “3600”.
 
    Example 1.6. Set hash_table_tout parameter
    Default value is “3600”.
 
    Example 1.6. Set hash_table_tout parameter
-...
-modparam("lrkproxy", "hash_table_tout", "3600")
-...
+                                                ...
+                                                modparam("lrkproxy", "hash_table
+_tout", "3600")
+                                                ...
 
 4.3.7. hash_table_size (integer)
 
 
 4.3.7. hash_table_size (integer)
 
@@ -262,9 +279,36 @@ modparam("lrkproxy", "hash_table_tout", "3600")
    Default value is “128”.
 
    Example 1.7. Set hash_table_size parameter
    Default value is “128”.
 
    Example 1.7. Set hash_table_size parameter
-...
-modparam("lrkproxy", "hash_table_size", 256)
-...
+                                                ...
+                                                modparam("lrkproxy", "hash_table
+_size", 256)
+                                                ...
+
+4.3.8. custom_sdp_ip_avp (string)
+
+   This option useful for solving STUN and help UDP packets make it across
+   NAT devices safe and sound. In this way, it should be set by clients's
+   ip public manually.
+
+   Default value is “NULL”.
+
+   Example 1.8. Set custom_sdp_ip_avp parameter
+                                                ...
+                                                modparam("lrkproxy", "custom_sdp
+_ip_avp", "$avp(RR_CUSTOM_SDP_IP_AVP)")
+                                                ...
+
+4.3.9. gt (integer)
+
+   This option useful for optimization in allocation port resource in
+   lrkproxy service.
+
+   Default value is “0”.
+
+   Example 1.9. Set gt parameter
+                                                ...
+                                                modparam("lrkproxy", "gt", "1")
+                                                ...
 
 4.4. Functions
 
 
 4.4. Functions
 
@@ -277,11 +321,11 @@ modparam("lrkproxy", "hash_table_size", 256)
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
    BRANCH_ROUTE.
 
    This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
    BRANCH_ROUTE.
 
-   Example 1.8. set_lrkproxy_set usage
-...
-set_lrkproxy_set("0");
-lrkproxy_manage();
-...
+   Example 1.10. set_lrkproxy_set usage
+                                                ...
+                                                set_lrkproxy_set("0");
+                                                lrkproxy_manage();
+                                                ...
 
 4.4.2.  lrkproxy_manage([flags [, ip_address]])
 
 
 4.4.2.  lrkproxy_manage([flags [, ip_address]])
 
@@ -307,12 +351,12 @@ lrkproxy_manage();
 
    This function can be used from ANY_ROUTE.
 
 
    This function can be used from ANY_ROUTE.
 
-   Example 1.9. lrkproxy_manage usage
-...
-lrkproxy_manage();
-//or
-lrkproxy_manage("ie");
-//or
-lrkproxy_manage("ei");
+   Example 1.11. lrkproxy_manage usage
+                                                ...
+                                                lrkproxy_manage();
+                                                //or
+                                                lrkproxy_manage("ie");
+                                                //or
+                                                lrkproxy_manage("ei");
 
 
-...
+                                                ...
index c826047..2a0beb4 100644 (file)
@@ -1,12 +1,12 @@
 <?xml version="1.0" encoding='ISO-8859-1'?>
 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
 <?xml version="1.0" encoding='ISO-8859-1'?>
 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
-"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
+               "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
 
 
-<!-- Include general documentation entities -->
-<!ENTITY % docentities SYSTEM "../../../../doc/docbook/entities.xml">
-%docentities;
+               <!-- Include general documentation entities -->
+               <!ENTITY % docentities SYSTEM "../../../../doc/docbook/entities.xml">
+               %docentities;
 
 
-]>
+               ]>
 
 <!-- Module User's Guide -->
 
 
 <!-- Module User's Guide -->
 
        <title>&adminguide;</title>
 
        <section>
        <title>&adminguide;</title>
 
        <section>
-       <title>Overview</title>
-       <para>
-               This is a module that enables media streams to be relayed via
-               pylrkproxy engine that exist in:
-               https://github.com/mojtabaesfandiari/pylrkproxy
-               It does relaying audio streams between peers in
-               PREROUTING netfilter-hooking section in kernel-space linux.
-               The LRKProxy architecture is composed of two
-               different layers. These layers are independent of each
-               other.
-               For more information about LRKProxy architecture, please visit our paper in ieeexplore:
-               https://ieeexplore.ieee.org/document/9303608
-       </para>
-       </section>
-
-       <section>
-       <title>LRKProxy Architecture</title>
-       <section>
-               <title>LRKP_Controlling Layer (LRKP_CL)</title>
+               <title>Overview</title>
                <para>
                <para>
-                       The first layer is developed as User-Space
-                       application that allows User-Space to directly
-                       access and manipulate cache data
-                       buffer and packet buffer in Kernel-Space. This layer
-                       gets all information about creating new sessions,
-                       active sessions and teardown sessions which is
-                       gotten from SDP body during signaling plan and relay
-                       them to the LRKP-Transport Stateful Layer (LRKP-
-                       TSL).
+                       This is a module that enables media streams to be relayed via
+                       pylrkproxy engine that exist in:
+                       https://github.com/mojtabaesfandiari/pylrkproxy
+                       It does relaying audio streams between peers in
+                       PREROUTING netfilter-hooking section in kernel-space linux.
+                       The LRKProxy architecture is composed of two
+                       different layers. These layers are independent of each
+                       other.
+                       For more information about LRKProxy architecture, please visit our paper in ieeexplore:
+                       https://ieeexplore.ieee.org/document/9303608
                </para>
        </section>
                </para>
        </section>
-       <section>
-               <title>LRKP_Transport Stateful Layer (LRKP_TSL)</title>
-               <para>
-                       The second layer is developed in Kernel-Space as
-                       a main decision point for RTP admission controller
-                       and Quickpath selector to where a received packet
-                       should be forwarded with power of packet mangling
-                       framework in the network stack.
-               </para>
-       </section>
-       <para>
-               The LRKP_CL and LRKP-TSL could be run as
-               independence functions on different machines. We
-               could have one LRKP_CL with multiple LRKP-TSL
-               on different machines. The LRKP_CL could works
-               with all LRKP-TSL with different strategies(lrkp_alg parameter).
-       </para>
-       </section>
-       <section>
-       <title>Multiple LRKProxy usage</title>
-       <para>
-               The LRKP_CL Layer can support multiple LRKP_TSL Layer
-               for balancing/distribution and control/selection purposes.
-       </para>
-       <para>
-               The module allows definition of several sets of LRKP_TSL.
-               Load-balancing will be performed over predefine algorithm by setting lrkp_alg parameter.
 
 
-       </para>
-       <para>
-               IMPORTANT: This module does not support balancing inside a set like as is done RTPProxy module based on
-               the weight of each rtpproxy from the set. The balancing would be run on different machine
-       </para>
-       </section>
-       
        <section>
        <section>
-       <title>Dependencies</title>
-       <section>
-               <title>&kamailio; Modules</title>
-               <para>
-               The following modules must be loaded before this module:
-                       <itemizedlist>
-                       <listitem>
+               <title>LRKProxy Architecture</title>
+               <section>
+                       <title>LRKP_Controlling Layer (LRKP_CL)</title>
                        <para>
                        <para>
-                               <emphasis>tm module</emphasis> - (optional) if you want to
-                               have lrkproxy_manage() fully functional
+                               The first layer is developed as User-Space
+                               application that allows User-Space to directly
+                               access and manipulate cache data
+                               buffer and packet buffer in Kernel-Space. This layer
+                               gets all information about creating new sessions,
+                               active sessions and teardown sessions which is
+                               gotten from SDP body during signaling plan and relay
+                               them to the LRKP-Transport Stateful Layer (LRKP-
+                               TSL).
                        </para>
                        </para>
-                       </listitem>
-                       </itemizedlist>
-               </para>
-       </section>
-       <section>
-               <title>External Libraries or Applications</title>
-               <para>
-               The following libraries or applications must be installed before
-               running &kamailio; with this module loaded:
-                       <itemizedlist>
-                       <listitem>
+               </section>
+               <section>
+                       <title>LRKP_Transport Stateful Layer (LRKP_TSL)</title>
                        <para>
                        <para>
-                               <emphasis>None</emphasis>.
+                               The second layer is developed in Kernel-Space as
+                               a main decision point for RTP admission controller
+                               and Quickpath selector to where a received packet
+                               should be forwarded with power of packet mangling
+                               framework in the network stack.
                        </para>
                        </para>
-                       </listitem>
-                       </itemizedlist>
-               </para>
-       </section>
-       <section>
-       <title>Parameters</title>
-       <section id="lrkproxy.p.lrkproxy_sock">
-       <title><varname>lrkproxy_sock</varname> (string)</title>
-                       <para>
-                       Used to define the list of LRKP_TSL instances to connect to. These can
-                       be UNIX sockets or IPv4/IPv6 UDP sockets. Each modparam entry will
-                       insert sockets into a single set with default value set ID '0'.
-                       To define multiple LRKP_TSL, just add the instances in each modparam.
-                       </para>
-                       <para>
-                       <emphasis>
-                               Default value is <quote>NONE</quote> (disabled).
-                       </emphasis>
-                       </para>
-                       <example>
-                       <title>Set <varname>lrkproxy_sock</varname> parameter</title>
-                       <programlisting format="linespecific">
-...
-# single lrkproxy
-modparam("lrkproxy", "lrkproxy_sock", "udp:192.168.122.108:8080")
-
-# multiple lrkproxies for LB in diffenrent machine
-modparam("lrkproxy", "lrkproxy_sock", "udp:192.168.122.108:8080")
-modparam("lrkproxy", "lrkproxy_sock", "udp:192.168.122.109:8080")
-
-...
-</programlisting>
-               </example>
-       </section>
-       <section id="lrkproxy.p.lrkproxy_disable_tout">
-               <title><varname>lrkproxy_disable_tout</varname> (integer)</title>
-               <para>
-               Once LRKP_TSL was found unreachable and marked as disabled, the
-               LRKP_CL module will not attempt to establish communication to LRKP_TSL
-               for lrkproxy_disable_tout seconds.
-               </para>
-               <para>
-               <emphasis>
-                       Default value is <quote>60</quote>.
-               </emphasis>
-               </para>
-               <example>
-               <title>Set <varname>lrkproxy_disable_tout</varname> parameter</title>
-               <programlisting format="linespecific">
-...
-modparam("lrkproxy", "lrkproxy_disable_tout", 20)
-...
-</programlisting>
-               </example>
-       </section>
-       <section id="lrkproxy.p.lrkproxy_tout">
-               <title><varname>lrkproxy_tout</varname> (integer)</title>
-               <para>
-               Timeout value in waiting for reply from LRKP_TSL.
-               </para>
-               <para>
-               <emphasis>
-                       Default value is <quote>1</quote>.
-               </emphasis>
-               </para>
-               <example>
-               <title>Set <varname>lrkproxy_tout</varname> parameter</title>
-               <programlisting format="linespecific">
-...
-modparam("lrkproxy", "lrkproxy_tout", 2)
-...
-</programlisting>
-               </example>
-       </section>
-       <section id="lrkproxy.p.lrkproxy_retr">
-               <title><varname>lrkproxy_retr</varname> (integer)</title>
-               <para>
-               How many times the LRKP_CL should retry to send and receive after
-               timeout was generated.
-               </para>
+               </section>
                <para>
                <para>
-               <emphasis>
-                       Default value is <quote>5</quote>.
-               </emphasis>
+                       The LRKP_CL and LRKP-TSL could be run as
+                       independence functions on different machines. We
+                       could have one LRKP_CL with multiple LRKP-TSL
+                       on different machines. The LRKP_CL could works
+                       with all LRKP-TSL with different strategies(lrkp_alg parameter).
                </para>
                </para>
-               <example>
-               <title>Set <varname>lrkproxy_retr</varname> parameter</title>
-               <programlisting format="linespecific">
-...
-modparam("lrkproxy", "lrkproxy_retr", 2)
-...
-</programlisting>
-               </example>
        </section>
        </section>
-       <section id="lrkproxy.p.lrkp_alg">
-               <title><varname>lrkp_alg</varname> (integer)</title>
+       <section>
+               <title>Multiple LRKProxy usage</title>
                <para>
                <para>
-               This parameter set the algorithm of LRKP_TSL selection.
-               lrk_LINER=0,
-               lrk_RR=1
+                       The LRKP_CL Layer can support multiple LRKP_TSL Layer
+                       for balancing/distribution and control/selection purposes.
                </para>
                <para>
                </para>
                <para>
-               <emphasis>
-                       Default value is <quote>0</quote>.
-               </emphasis>
-               </para>
-               <example>
-               <title>Set <varname>lrkp_alg</varname> parameter</title>
-               <programlisting format="linespecific">
-...
-modparam("lrkproxy", "lrkp_alg", 1)
-...
-</programlisting>
-               </example>
-       </section>
+                       The module allows definition of several sets of LRKP_TSL.
+                       Load-balancing will be performed over predefine algorithm by setting lrkp_alg parameter.
 
 
-       <section id="lrkproxy.p.hash_table_tout">
-               <title><varname>hash_table_tout</varname> (integer)</title>
-               <para>
-               Number of seconds after an lrkproxy hash table entry is marked for
-               deletion. By default, this parameter is set to 3600 (seconds).
-               </para>
-               <para>
-               To maintain information about a selected rtp machine node, for a given
-               call, entries are added in a hashtable of (callid, viabranch) pairs. When
-               command comes, lookup callid, viabranch pairs. If found, return chosen node. If not
-               found, choose a new node, insert it in the hastable and return the
-               chosen node.
-               </para>
-               <para>
-               NOTE: In the current implementation, the actual deletion happens on the
-               fly, while insert/remove/lookup the hastable, only for the entries in
-               the insert/remove/lookup path.
-               </para>
-               <para>
-               NOTE: When configuring this parameter, one should consider maximum call
-               time VS share memory for unfinished calls.
-               </para>
-               <para>
-               <emphasis>
-                       Default value is <quote>3600</quote>.
-               </emphasis>
-               </para>
-               <example>
-               <title>Set <varname>hash_table_tout</varname> parameter</title>
-               <programlisting format="linespecific">
-...
-modparam("lrkproxy", "hash_table_tout", "3600")
-...
-</programlisting>
-               </example>
-       </section>
-       <section id="lrkproxy.p.hash_table_size">
-               <title><varname>hash_table_size</varname> (integer)</title>
-               <para>
-               Size of the hash table. Default value is 128.
                </para>
                <para>
                </para>
                <para>
-               <emphasis>
-                       Default value is <quote>128</quote>.
-               </emphasis>
+                       IMPORTANT: This module does not support balancing inside a set like as is done RTPProxy module based on
+                       the weight of each rtpproxy from the set. The balancing would be run on different machine
                </para>
                </para>
-               <example>
-               <title>Set <varname>hash_table_size</varname> parameter</title>
-               <programlisting format="linespecific">
-...
-modparam("lrkproxy", "hash_table_size", 256)
-...
-</programlisting>
-               </example>
-       </section>
        </section>
        </section>
+
        <section>
        <section>
-       <title>Functions</title>
-       <section id="lrkproxy.f.set_lrkproxy_set">
-               <title>
-               <function moreinfo="none">set_lrkproxy_set(setid)</function>
-               </title>
-               <para>
-               Sets the Id of the lrkproxy set to be used for the next
-               lrkproxy_manage() command. The parameter can be an integer or a config
-               variable holding an integer.
-               </para>
-               <para>
-               This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
-               BRANCH_ROUTE.
-               </para>
-               <example>
-               <title><function>set_lrkproxy_set</function> usage</title>
-               <programlisting format="linespecific">
-...
-set_lrkproxy_set("0");
-lrkproxy_manage();
-...
-</programlisting>
-               </example>
-       </section>
-        <section id="lrkproxy.f.lrkproxy_manage">
-                <title>
-                <function moreinfo="none">lrkproxy_manage([flags [, ip_address]])</function>
-                </title>
-                <para>
-                Manage the LRKProxy session - it combines the functionality of
-               lrkproxy_offer(), lrkproxy_answer() and unforce_lrkproxy(), detecting
-               internally based on message type and method which one to execute.
-                </para>
-               <para>
-                  IMPORTANT:The LRKProxy just has one function relating rtp packets. 
-                  It does not support combination of functionality of lrkproxy_offer(),
-                  lrkproxy_answer() and unforce_lrkproxy() and other etc.
-                  So you have to just use lrkproxy_manage.
-               </para>
-               <para>Meaning of the parameters is as follows:</para>
-               <itemizedlist>
-               <listitem>
+               <title>Dependencies</title>
+               <section>
+                       <title>&kamailio; Modules</title>
                        <para>
                        <para>
-                       <emphasis>flags</emphasis> - flags to turn on some features.
+                               The following modules must be loaded before this module:
+                               <itemizedlist>
+                                       <listitem>
+                                               <para>
+                                                       <emphasis>tm module</emphasis> - (optional) if you want to
+                                                       have lrkproxy_manage() fully functional
+                                               </para>
+                                       </listitem>
+                               </itemizedlist>
                        </para>
                        </para>
-                       <itemizedlist>
-                               <listitem><para>
-                               <emphasis>internal,external</emphasis> - The shorthand of this flag is "ie".
-                               This can be used to relay media sessions between two different NIC from internal to external path.
-                               </para></listitem>
-                       </itemizedlist>
-                       <itemizedlist>
-                               <listitem><para>
-                               <emphasis>external,internal</emphasis> - The shorthand of this flag is "ei".
-                               This can be used to relay media sessions between two different NIC from external to internal path.
-                               </para></listitem>
-                       </itemizedlist>
-               </listitem>
-               <listitem><para>
-               <emphasis>ip_address</emphasis> - new SDP IP address.This optional parameter is under development.
-               </para></listitem>
-               </itemizedlist>
-               <para>
-               This function can be used from ANY_ROUTE.
-                </para>
-               <example>
-               <title><function>lrkproxy_manage</function> usage</title>
-               <programlisting format="linespecific">
-...
-lrkproxy_manage();
-//or
-lrkproxy_manage("ie");
-//or
-lrkproxy_manage("ei");
+               </section>
+               <section>
+                       <title>External Libraries or Applications</title>
+                       <para>
+                               The following libraries or applications must be installed before
+                               running &kamailio; with this module loaded:
+                               <itemizedlist>
+                                       <listitem>
+                                               <para>
+                                                       <emphasis>None</emphasis>.
+                                               </para>
+                                       </listitem>
+                               </itemizedlist>
+                       </para>
+               </section>
+               <section>
+                       <title>Parameters</title>
+                       <section id="lrkproxy.p.lrkproxy_sock">
+                               <title><varname>lrkproxy_sock</varname> (string)</title>
+                               <para>
+                                       Used to define the list of LRKP_TSL instances to connect to. These can
+                                       be UNIX sockets or IPv4/IPv6 UDP sockets. Each modparam entry will
+                                       insert sockets into a single set with default value set ID '0'.
+                                       To define multiple LRKP_TSL, just add the instances in each modparam.
+                               </para>
+                               <para>
+                                       <emphasis>
+                                               Default value is <quote>NONE</quote> (disabled).
+                                       </emphasis>
+                               </para>
+                               <example>
+                                       <title>Set <varname>lrkproxy_sock</varname> parameter</title>
+                                       <programlisting format="linespecific">
+                                               ...
+                                               # single lrkproxy
+                                               modparam("lrkproxy", "lrkproxy_sock", "udp:192.168.122.108:8080")
 
 
-...
-</programlisting>
-                </example>
-       </section>
+                                               # multiple lrkproxies for LB in diffenrent machine
+                                               modparam("lrkproxy", "lrkproxy_sock", "udp:192.168.122.108:8080")
+                                               modparam("lrkproxy", "lrkproxy_sock", "udp:192.168.122.109:8080")
 
 
+                                               ...
+                                       </programlisting>
+                               </example>
+                       </section>
+                       <section id="lrkproxy.p.lrkproxy_disable_tout">
+                               <title><varname>lrkproxy_disable_tout</varname> (integer)</title>
+                               <para>
+                                       Once LRKP_TSL was found unreachable and marked as disabled, the
+                                       LRKP_CL module will not attempt to establish communication to LRKP_TSL
+                                       for lrkproxy_disable_tout seconds.
+                               </para>
+                               <para>
+                                       <emphasis>
+                                               Default value is <quote>60</quote>.
+                                       </emphasis>
+                               </para>
+                               <example>
+                                       <title>Set <varname>lrkproxy_disable_tout</varname> parameter</title>
+                                       <programlisting format="linespecific">
+                                               ...
+                                               modparam("lrkproxy", "lrkproxy_disable_tout", 20)
+                                               ...
+                                       </programlisting>
+                               </example>
+                       </section>
+                       <section id="lrkproxy.p.lrkproxy_tout">
+                               <title><varname>lrkproxy_tout</varname> (integer)</title>
+                               <para>
+                                       Timeout value in waiting for reply from LRKP_TSL.
+                               </para>
+                               <para>
+                                       <emphasis>
+                                               Default value is <quote>1</quote>.
+                                       </emphasis>
+                               </para>
+                               <example>
+                                       <title>Set <varname>lrkproxy_tout</varname> parameter</title>
+                                       <programlisting format="linespecific">
+                                               ...
+                                               modparam("lrkproxy", "lrkproxy_tout", 2)
+                                               ...
+                                       </programlisting>
+                               </example>
+                       </section>
+                       <section id="lrkproxy.p.lrkproxy_retr">
+                               <title><varname>lrkproxy_retr</varname> (integer)</title>
+                               <para>
+                                       How many times the LRKP_CL should retry to send and receive after
+                                       timeout was generated.
+                               </para>
+                               <para>
+                                       <emphasis>
+                                               Default value is <quote>5</quote>.
+                                       </emphasis>
+                               </para>
+                               <example>
+                                       <title>Set <varname>lrkproxy_retr</varname> parameter</title>
+                                       <programlisting format="linespecific">
+                                               ...
+                                               modparam("lrkproxy", "lrkproxy_retr", 2)
+                                               ...
+                                       </programlisting>
+                               </example>
+                       </section>
+                       <section id="lrkproxy.p.lrkp_alg">
+                               <title><varname>lrkp_alg</varname> (integer)</title>
+                               <para>
+                                       This parameter set the algorithm of LRKP_TSL selection.
+                                       lrk_LINER=0,
+                                       lrk_RR=1
+                               </para>
+                               <para>
+                                       <emphasis>
+                                               Default value is <quote>0</quote>.
+                                       </emphasis>
+                               </para>
+                               <example>
+                                       <title>Set <varname>lrkp_alg</varname> parameter</title>
+                                       <programlisting format="linespecific">
+                                               ...
+                                               modparam("lrkproxy", "lrkp_alg", 1)
+                                               ...
+                                       </programlisting>
+                               </example>
+                       </section>
 
 
+                       <section id="lrkproxy.p.hash_table_tout">
+                               <title><varname>hash_table_tout</varname> (integer)</title>
+                               <para>
+                                       Number of seconds after an lrkproxy hash table entry is marked for
+                                       deletion. By default, this parameter is set to 3600 (seconds).
+                               </para>
+                               <para>
+                                       To maintain information about a selected rtp machine node, for a given
+                                       call, entries are added in a hashtable of (callid, viabranch) pairs. When
+                                       command comes, lookup callid, viabranch pairs. If found, return chosen node. If not
+                                       found, choose a new node, insert it in the hastable and return the
+                                       chosen node.
+                               </para>
+                               <para>
+                                       NOTE: In the current implementation, the actual deletion happens on the
+                                       fly, while insert/remove/lookup the hastable, only for the entries in
+                                       the insert/remove/lookup path.
+                               </para>
+                               <para>
+                                       NOTE: When configuring this parameter, one should consider maximum call
+                                       time VS share memory for unfinished calls.
+                               </para>
+                               <para>
+                                       <emphasis>
+                                               Default value is <quote>3600</quote>.
+                                       </emphasis>
+                               </para>
+                               <example>
+                                       <title>Set <varname>hash_table_tout</varname> parameter</title>
+                                       <programlisting format="linespecific">
+                                               ...
+                                               modparam("lrkproxy", "hash_table_tout", "3600")
+                                               ...
+                                       </programlisting>
+                               </example>
+                       </section>
+
+
+
+                       <section id="lrkproxy.p.hash_table_size">
+                               <title><varname>hash_table_size</varname> (integer)</title>
+                               <para>
+                                       Size of the hash table. Default value is 128.
+                               </para>
+                               <para>
+                                       <emphasis>
+                                               Default value is <quote>128</quote>.
+                                       </emphasis>
+                               </para>
+                               <example>
+                                       <title>Set <varname>hash_table_size</varname> parameter</title>
+                                       <programlisting format="linespecific">
+                                               ...
+                                               modparam("lrkproxy", "hash_table_size", 256)
+                                               ...
+                                       </programlisting>
+                               </example>
+                       </section>
+
+                       <section id="lrkproxy.p.custom_sdp_ip_avp">
+                               <title><varname>custom_sdp_ip_avp</varname> (string)</title>
+                               <para>
+                                       This option useful for solving STUN and help UDP packets make it across NAT devices safe and sound.
+                                       In this way, it should be set by clients's ip public manually.
+                               </para>
+                               <para>
+                                       <emphasis>
+                                               Default value is <quote>NULL</quote>.
+                                       </emphasis>
+                               </para>
+                               <example>
+                                       <title>Set <varname>custom_sdp_ip_avp</varname> parameter</title>
+                                       <programlisting format="linespecific">
+                                               ...
+                                               modparam("lrkproxy", "custom_sdp_ip_avp", "$avp(RR_CUSTOM_SDP_IP_AVP)")
+                                               ...
+                                       </programlisting>
+                               </example>
+                       </section>
+
+                       <section id="lrkproxy.p.gt">
+                               <title><varname>gt</varname> (integer)</title>
+                               <para>
+                                       This option useful for optimization in allocation port resource in lrkproxy service.
+                               </para>
+                               <para>
+                                       <emphasis>
+                                               Default value is <quote>0</quote>.
+                                       </emphasis>
+                               </para>
+                               <example>
+                                       <title>Set <varname>gt</varname> parameter</title>
+                                       <programlisting format="linespecific">
+                                               ...
+                                               modparam("lrkproxy", "gt", "1")
+                                               ...
+                                       </programlisting>
+                               </example>
+                       </section>
+
+
+
+
+
+               </section>
+               <section>
+                       <title>Functions</title>
+                       <section id="lrkproxy.f.set_lrkproxy_set">
+                               <title>
+                                       <function moreinfo="none">set_lrkproxy_set(setid)</function>
+                               </title>
+                               <para>
+                                       Sets the Id of the lrkproxy set to be used for the next
+                                       lrkproxy_manage() command. The parameter can be an integer or a config
+                                       variable holding an integer.
+                               </para>
+                               <para>
+                                       This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
+                                       BRANCH_ROUTE.
+                               </para>
+                               <example>
+                                       <title><function>set_lrkproxy_set</function> usage</title>
+                                       <programlisting format="linespecific">
+                                               ...
+                                               set_lrkproxy_set("0");
+                                               lrkproxy_manage();
+                                               ...
+                                       </programlisting>
+                               </example>
+                       </section>
+                       <section id="lrkproxy.f.lrkproxy_manage">
+                               <title>
+                                       <function moreinfo="none">lrkproxy_manage([flags [, ip_address]])</function>
+                               </title>
+                               <para>
+                                       Manage the LRKProxy session - it combines the functionality of
+                                       lrkproxy_offer(), lrkproxy_answer() and unforce_lrkproxy(), detecting
+                                       internally based on message type and method which one to execute.
+                               </para>
+                               <para>
+                                       IMPORTANT:The LRKProxy just has one function relating rtp packets.
+                                       It does not support combination of functionality of lrkproxy_offer(),
+                                       lrkproxy_answer() and unforce_lrkproxy() and other etc.
+                                       So you have to just use lrkproxy_manage.
+                               </para>
+                               <para>Meaning of the parameters is as follows:</para>
+                               <itemizedlist>
+                                       <listitem>
+                                               <para>
+                                                       <emphasis>flags</emphasis> - flags to turn on some features.
+                                               </para>
+                                               <itemizedlist>
+                                                       <listitem><para>
+                                                               <emphasis>internal,external</emphasis> - The shorthand of this flag is "ie".
+                                                               This can be used to relay media sessions between two different NIC from internal to external path.
+                                                       </para></listitem>
+                                               </itemizedlist>
+                                               <itemizedlist>
+                                                       <listitem><para>
+                                                               <emphasis>external,internal</emphasis> - The shorthand of this flag is "ei".
+                                                               This can be used to relay media sessions between two different NIC from external to internal path.
+                                                       </para></listitem>
+                                               </itemizedlist>
+                                       </listitem>
+                                       <listitem><para>
+                                               <emphasis>ip_address</emphasis> - new SDP IP address.This optional parameter is under development.
+                                       </para></listitem>
+                               </itemizedlist>
+                               <para>
+                                       This function can be used from ANY_ROUTE.
+                               </para>
+                               <example>
+                                       <title><function>lrkproxy_manage</function> usage</title>
+                                       <programlisting format="linespecific">
+                                               ...
+                                               lrkproxy_manage();
+                                               //or
+                                               lrkproxy_manage("ie");
+                                               //or
+                                               lrkproxy_manage("ei");
+
+                                               ...
+                                       </programlisting>
+                               </example>
+                       </section>
+
+
+               </section>
        </section>
        </section>
-       </section>
-</chapter>
+</chapter>
\ No newline at end of file
index a5b93bb..e30f4e9 100644 (file)
@@ -169,6 +169,18 @@ int lrkp_algorithm = LRK_LINER;
 static int hash_table_size = 0;
 static int hash_table_tout = 3600;
 
 static int hash_table_size = 0;
 static int hash_table_tout = 3600;
 
+/*!< The gt is game-theory variable, It could be set 0:disable and 1:enable
+ * default is 0.
+ */
+int gt = 0;
+
+/*
+ * the custom_sdp_ip_spec variable is used for specific SDP information based $si (source address)
+ * */
+static str custom_sdp_ip_spec = {NULL, 0};
+pv_spec_t custom_sdp_ip_avp;
+
+
 
 
 //static char *ice_candidate_priority_avp_param = NULL;
 
 
 //static char *ice_candidate_priority_avp_param = NULL;
@@ -220,6 +232,8 @@ static param_export_t params[] = {
         {"lrkp_alg",         INT_PARAM, &lrkp_algorithm         },
         {"hash_table_tout",       INT_PARAM, &hash_table_tout        },
         {"hash_table_size",       INT_PARAM, &hash_table_size        },
         {"lrkp_alg",         INT_PARAM, &lrkp_algorithm         },
         {"hash_table_tout",       INT_PARAM, &hash_table_tout        },
         {"hash_table_size",       INT_PARAM, &hash_table_size        },
+        {"custom_sdp_ip_avp",     PARAM_STR, &custom_sdp_ip_spec},
+        {"gt",   INT_PARAM  , &gt},
 
         {0, 0, 0}
 };
 
         {0, 0, 0}
 };
@@ -609,6 +623,18 @@ mod_init(void)
         memset(&tmb, 0, sizeof(struct tm_binds));
     }
 
         memset(&tmb, 0, sizeof(struct tm_binds));
     }
 
+    if (custom_sdp_ip_spec.s) {
+        if (pv_parse_spec(&custom_sdp_ip_spec, &custom_sdp_ip_avp) == 0
+            && (custom_sdp_ip_avp.type != PVT_AVP)) {
+                    LM_ERR("malformed or non AVP custom_sdp_ip "
+                                   "AVP definition in '%.*s'\n", custom_sdp_ip_spec.len,custom_sdp_ip_spec.s);
+            return -1;
+        }
+    }
+
+    init_custom_sdp_ip(custom_sdp_ip_spec.s ? &custom_sdp_ip_avp : 0);
+
+
     return 0;
 }
 
     return 0;
 }
 
@@ -1261,7 +1287,10 @@ static int change_media_sdp(sip_msg_t *msg, struct lrkproxy_hash_entry *e, const
         unsigned int snat_port;
 
         str2int(&e->dst_port, &snat_port);
         unsigned int snat_port;
 
         str2int(&e->dst_port, &snat_port);
-        snat_port += 2;
+
+        /*check if gt is enable or not*/
+        if (!gt)
+            snat_port += 2;
 
         current_port.s = int2str(snat_port, &current_port.len);
 
 
         current_port.s = int2str(snat_port, &current_port.len);
 
@@ -1555,6 +1584,7 @@ static int lrkproxy_force(struct sip_msg *msg, const char *flags, enum lrk_opera
 
         //fill src_ipv4 and src_port for entry.
         str src_ipv4;
 
         //fill src_ipv4 and src_port for entry.
         str src_ipv4;
+
         if (get_sdp_ipaddr_media(msg, &src_ipv4) == -1) {
                     LM_ERR("can't get media src_ipv4 from sdp field\n");
             return -1;
         if (get_sdp_ipaddr_media(msg, &src_ipv4) == -1) {
                     LM_ERR("can't get media src_ipv4 from sdp field\n");
             return -1;
@@ -1618,9 +1648,12 @@ static int lrkproxy_force(struct sip_msg *msg, const char *flags, enum lrk_opera
 
         if (node->lrkp_n_c->current_port >= node->lrkp_n_c->end_port)
             node->lrkp_n_c->current_port = node->lrkp_n_c->start_port;
 
         if (node->lrkp_n_c->current_port >= node->lrkp_n_c->end_port)
             node->lrkp_n_c->current_port = node->lrkp_n_c->start_port;
-        else
-            node->lrkp_n_c->current_port += 4;
-
+        else {
+            if (gt)
+                node->lrkp_n_c->current_port += 2;
+            else
+                node->lrkp_n_c->current_port += 4;
+        }
     } else if (op == OP_ANSWER) {
                 LM_INFO ("Here is SIP_REPLY of METHOD_INVITE\n");
 
     } else if (op == OP_ANSWER) {
                 LM_INFO ("Here is SIP_REPLY of METHOD_INVITE\n");
 
index 08a41f2..c3b740f 100644 (file)
@@ -42,6 +42,9 @@
 #include "../../core/parser/parser_f.h"
 #include "../../core/parser/sdp/sdp_helpr_funcs.h"
 
 #include "../../core/parser/parser_f.h"
 #include "../../core/parser/sdp/sdp_helpr_funcs.h"
 
+static pv_spec_t *custom_sdp_ip_avp;           /*!< AVP for custom_sdp_ip setting */
+
+
 #define READ(val) \
        (*(val + 0) + (*(val + 1) << 8) + (*(val + 2) << 16) + (*(val + 3) << 24))
 #define advance(_ptr,_n,_str,_error) \
 #define READ(val) \
        (*(val + 0) + (*(val + 1) << 8) + (*(val + 2) << 16) + (*(val + 3) << 24))
 #define advance(_ptr,_n,_str,_error) \
@@ -407,6 +410,25 @@ int get_sdp_ipaddr_media(struct sip_msg *msg, str *ip_addr) {
         return -1;
     }
 
         return -1;
     }
 
+    char *s = ip_addr2a(&msg->rcv.src_ip);
+            LM_INFO("=========>msg->rcv.src_ip:%s\n", s);
+//            LM_INFO("=========>msg->contact-body:%.*s\n", msg->contact->body.len, msg->contact->body.s);
+//            LM_INFO("=========>msg->contact-name:%.*s\n", msg->contact->name.len, msg->contact->name.s);
+
+    pv_value_t pv_val;
+    if (custom_sdp_ip_avp) {
+        if ((pv_get_spec_value(msg, custom_sdp_ip_avp, &pv_val) == 0)
+            && (pv_val.flags & PV_VAL_STR) && (pv_val.rs.len > 0)) {
+            ip_addr->s = pv_val.rs.s;
+            ip_addr->len = pv_val.rs.len;
+                    LM_INFO("=========>custom_sdp_ip_avp:%.*s\n",   ip_addr->len,   ip_addr->s);
+
+            return 0;
+        }
+        else
+                LM_DBG("invalid AVP value, using default user from RURI\n");
+    }
+
 
     int sdp_session_num = 0;
     sdp_session = get_sdp_session(msg, sdp_session_num);
 
     int sdp_session_num = 0;
     sdp_session = get_sdp_session(msg, sdp_session_num);
@@ -418,9 +440,11 @@ int get_sdp_ipaddr_media(struct sip_msg *msg, str *ip_addr) {
 
     if (sdp_session->ip_addr.s && sdp_session->ip_addr.len > 0) {
                 LM_INFO("sdp_session->ip_addr:%.*s\n", sdp_session->ip_addr.len, sdp_session->ip_addr.s);
 
     if (sdp_session->ip_addr.s && sdp_session->ip_addr.len > 0) {
                 LM_INFO("sdp_session->ip_addr:%.*s\n", sdp_session->ip_addr.len, sdp_session->ip_addr.s);
+
         ip_addr->s = sdp_session->ip_addr.s;
         ip_addr->len = sdp_session->ip_addr.len;
         trim(ip_addr);
         ip_addr->s = sdp_session->ip_addr.s;
         ip_addr->len = sdp_session->ip_addr.len;
         trim(ip_addr);
+
     }
     else {
         int sdp_stream_num = 0;
     }
     else {
         int sdp_stream_num = 0;
@@ -477,3 +501,8 @@ int get_sdp_port_media(struct sip_msg *msg, str *port){
 
 }
 
 
 }
 
+void init_custom_sdp_ip(pv_spec_t *custom_sdp_ip_avp_p)
+{
+    custom_sdp_ip_avp = custom_sdp_ip_avp_p;
+
+}
index d644235..5e64fb9 100644 (file)
@@ -24,6 +24,7 @@
 
 
 #include "../../core/str.h"
 
 
 #include "../../core/str.h"
+#include "../../core/pvar.h"
 #include "../../core/parser/msg_parser.h"
 #include "../../core/parser/contact/contact.h"
 
 #include "../../core/parser/msg_parser.h"
 #include "../../core/parser/contact/contact.h"
 
@@ -36,6 +37,7 @@ int get_contact_uri(struct sip_msg *, struct sip_uri *, contact_t **);
 int get_via_branch(struct sip_msg *, int, str *);
 int get_sdp_ipaddr_media(struct sip_msg *msg, str *ip_addr);
 int get_sdp_port_media(struct sip_msg *msg, str *port);
 int get_via_branch(struct sip_msg *, int, str *);
 int get_sdp_ipaddr_media(struct sip_msg *msg, str *ip_addr);
 int get_sdp_port_media(struct sip_msg *msg, str *port);
+void init_custom_sdp_ip(pv_spec_t *custom_sdp_ip_avp_p);
 
 
 #endif //_LRKPROXY_FUNCS_H
 
 
 #endif //_LRKPROXY_FUNCS_H
index 460db1d..b174bd6 100644 (file)
@@ -365,7 +365,12 @@ int lrkproxy_hash_table_remove(str callid, str viabranch, enum lrk_operation op)
     while (entry) {
         // if callid found, delete entry
         if ((str_equal(entry->callid, callid) && str_equal(entry->viabranch, viabranch)) ||
     while (entry) {
         // if callid found, delete entry
         if ((str_equal(entry->callid, callid) && str_equal(entry->viabranch, viabranch)) ||
-            (str_equal(entry->callid, callid) && viabranch.len == 0 && op == OP_DELETE)) {
+            (str_equal(entry->callid, callid) && viabranch.len == 0 && op == OP_DELETE) ||
+            str_equal(entry->callid, callid)){
+            //if ((str_equal(entry->callid, callid) && str_equal(entry->viabranch, viabranch)) ||
+            //    (str_equal(entry->callid, callid) && viabranch.len == 0 && op == OP_DELETE)) {
+            // set pointers; exclude entry
+
             // set pointers; exclude entry
             last_entry->next = entry->next;
 
             // set pointers; exclude entry
             last_entry->next = entry->next;