[sr-dev] git:master: rtpproxy: Add parameter to set an AVP to store the chosen RTPProxy instance IP address

Daniel-Constantin Mierla miconda at gmail.com
Wed Dec 4 20:59:23 CET 2013


Hello Hugh,

I am wondering if doesn't make it more flexible to allow the parameter 
to be any writable variable (which can be avp as well, but then will 
work with xavp, $var(), etc). Modules such as mtree or dialplan should 
have example how to do it -- it is rather trivial, the setf() function 
from pv spec is used for setting the value.

Cheers,
Daniel

On 12/4/13 7:48 PM, Hugh Waite wrote:
> Module: sip-router
> Branch: master
> Commit: 146e2b093ba57a9c48f2059863d214fcdfc1bd1a
> URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=146e2b093ba57a9c48f2059863d214fcdfc1bd1a
>
> Author: Hugh Waite <hugh.waite at crocodile-rcs.com>
> Committer: Hugh Waite <hugh.waite at crocodile-rcs.com>
> Date:   Wed Dec  4 18:30:37 2013 +0000
>
> rtpproxy: Add parameter to set an AVP to store the chosen RTPProxy instance IP address
>
> ---
>
>   modules/rtpproxy/README                 |   57 ++++++++++++++++++++-----------
>   modules/rtpproxy/doc/rtpproxy_admin.xml |   18 ++++++++++
>   modules/rtpproxy/rtpproxy.c             |   38 ++++++++++++++++++++
>   3 files changed, 93 insertions(+), 20 deletions(-)
>
> diff --git a/modules/rtpproxy/README b/modules/rtpproxy/README
> index 43b57df..8979560 100644
> --- a/modules/rtpproxy/README
> +++ b/modules/rtpproxy/README
> @@ -63,6 +63,7 @@ Carsten Bock
>                 4.8. extra_id_pv (string)
>                 4.9. db_url (string)
>                 4.10. table_name (string)
> +              4.11. rtp_inst_avp (string)
>   
>           5. Functions
>   
> @@ -101,16 +102,17 @@ Carsten Bock
>      1.8. Set extra_id_pv parameter
>      1.9. Set db_url parameter
>      1.10. Set table_name parameter
> -   1.11. set_rtp_proxy_set usage
> -   1.12. rtpproxy_offer usage
> -   1.13. rtpproxy_answer usage
> -   1.14. rtpproxy_destroy usage
> -   1.15. rtpproxy_manage usage
> -   1.16. rtpproxy_stream2xxx usage
> -   1.17. start_recording usage
> -   1.18. $rtpstat-Usage
> -   1.19. nh_enable_rtpp usage
> -   1.20. nh_show_rtpp usage
> +   1.11. Set rtp_inst_avp parameter
> +   1.12. set_rtp_proxy_set usage
> +   1.13. rtpproxy_offer usage
> +   1.14. rtpproxy_answer usage
> +   1.15. rtpproxy_destroy usage
> +   1.16. rtpproxy_manage usage
> +   1.17. rtpproxy_stream2xxx usage
> +   1.18. start_recording usage
> +   1.19. $rtpstat-Usage
> +   1.20. nh_enable_rtpp usage
> +   1.21. nh_show_rtpp usage
>   
>   Chapter 1. Admin Guide
>   
> @@ -135,6 +137,7 @@ Chapter 1. Admin Guide
>           4.8. extra_id_pv (string)
>           4.9. db_url (string)
>           4.10. table_name (string)
> +        4.11. rtp_inst_avp (string)
>   
>      5. Functions
>   
> @@ -222,6 +225,7 @@ Chapter 1. Admin Guide
>      4.8. extra_id_pv (string)
>      4.9. db_url (string)
>      4.10. table_name (string)
> +   4.11. rtp_inst_avp (string)
>   
>   4.1. rtpproxy_sock (string)
>   
> @@ -377,6 +381,19 @@ modparam("rtpproxy", "db_url", "mysql://user:passwb@localhost/database")
>   modparam("rtpproxy", "table_name", "my_rtpp_sets")
>   ...
>   
> +4.11. rtp_inst_avp (string)
> +
> +   An  avp  to store the chosen RTPProxy IP address. If this parameter is
> +   set,   the   IP   address  and  port  of  the  instance  chosen  in  a
> +   rtpproxy_manage() call will be stored in the given AVP.
> +
> +   By default, this parameter is not set.
> +
> +   Example 1.11. Set rtp_inst_avp parameter
> +...
> +modparam("rtpproxy", "rtp_inst_avp", "$avp(RTP_INSTANCE)")
> +...
> +
>   5. Functions
>   
>      5.1. set_rtp_proxy_set(setid)
> @@ -401,7 +418,7 @@ modparam("rtpproxy", "table_name", "my_rtpp_sets")
>      This   function   can   be  used  from  REQUEST_ROUTE,  ONREPLY_ROUTE,
>      BRANCH_ROUTE.
>   
> -   Example 1.11. set_rtp_proxy_set usage
> +   Example 1.12. set_rtp_proxy_set usage
>   ...
>   set_rtp_proxy_set("2");
>   rtpproxy_offer();
> @@ -507,7 +524,7 @@ rtpproxy_offer();
>   
>      This function can be used from ANY_ROUTE.
>   
> -   Example 1.12. rtpproxy_offer usage
> +   Example 1.13. rtpproxy_offer usage
>   route {
>   ...
>       if (is_method("INVITE")) {
> @@ -551,7 +568,7 @@ onreply_route[2]
>      This   function   can   be  used  from  REQUEST_ROUTE,  ONREPLY_ROUTE,
>      FAILURE_ROUTE, BRANCH_ROUTE.
>   
> -   Example 1.13. rtpproxy_answer usage
> +   Example 1.14. rtpproxy_answer usage
>   
>      See rtpproxy_offer() function example above for example.
>   
> @@ -587,7 +604,7 @@ onreply_route[2]
>               unused  rtpproxy  call  when  200 OK is received on a branch,
>               where rtpproxy is not needed.
>   
> -   Example 1.14. rtpproxy_destroy usage
> +   Example 1.15. rtpproxy_destroy usage
>   ...
>   rtpproxy_destroy();
>   ...
> @@ -621,7 +638,7 @@ rtpproxy_destroy();
>   
>      This function can be used from ANY_ROUTE.
>   
> -   Example 1.15. rtpproxy_manage usage
> +   Example 1.16. rtpproxy_manage usage
>   ...
>   rtpproxy_manage();
>   ...
> @@ -657,7 +674,7 @@ rtpproxy_manage();
>          -1  means  that it will be streaming in a loop indefinitely, until
>          the appropriate rtpproxy_stop_stream2xxx is issued.
>   
> -   Example 1.16. rtpproxy_stream2xxx usage
> +   Example 1.17. rtpproxy_stream2xxx usage
>   ...
>       if (is_method("INVITE")) {
>           rtpproxy_offer();
> @@ -690,7 +707,7 @@ rtpproxy_manage();
>   
>      This function can be used from REQUEST_ROUTE and ONREPLY_ROUTE.
>   
> -   Example 1.17. start_recording usage
> +   Example 1.18. start_recording usage
>   ...
>   start_recording();
>   ...
> @@ -710,7 +727,7 @@ start_recording();
>      packet-counters.  The  statistics must be retrieved before the session
>      is deleted (before unforce_rtpproxy()).
>   
> -   Example 1.18. $rtpstat-Usage
> +   Example 1.19. $rtpstat-Usage
>   ...
>       append_hf("X-RTP-Statistics: $rtpstat\r\n");
>   ...
> @@ -733,7 +750,7 @@ start_recording();
>      NOTE:  if  a  rtpproxy  is  defined  multiple  times  (in  the same or
>      diferente sete), all of its instances will be enables/disabled.
>   
> -   Example 1.19.  nh_enable_rtpp usage
> +   Example 1.20.  nh_enable_rtpp usage
>   ...
>   $ kamctl fifo nh_enable_rtpp udp:192.168.2.133:8081 0
>   ...
> @@ -745,7 +762,7 @@ $ kamctl fifo nh_enable_rtpp udp:192.168.2.133:8081 0
>   
>      No parameter.
>   
> -   Example 1.20.  nh_show_rtpp usage
> +   Example 1.21.  nh_show_rtpp usage
>   ...
>   $ kamctl fifo nh_show_rtpp
>   ...
> diff --git a/modules/rtpproxy/doc/rtpproxy_admin.xml b/modules/rtpproxy/doc/rtpproxy_admin.xml
> index 7a60c17..c4f2c86 100644
> --- a/modules/rtpproxy/doc/rtpproxy_admin.xml
> +++ b/modules/rtpproxy/doc/rtpproxy_admin.xml
> @@ -321,6 +321,24 @@ modparam("rtpproxy", "table_name", "my_rtpp_sets")
>   </programlisting>
>   		</example>
>   	</section>
> +	<section>
> +		<title><varname>rtp_inst_avp</varname> (string)</title>
> +		<para>
> +			An avp to store the chosen RTPProxy IP address.
> +			If this parameter is set, the IP address and port of the instance chosen in a rtpproxy_manage() call will be stored in the given AVP.
> +		</para>
> +		<para>
> +			By default, this parameter is not set.
> +		</para>
> +		<example>
> +		<title>Set <varname>rtp_inst_avp</varname> parameter</title>
> +		<programlisting format="linespecific">
> +...
> +modparam("rtpproxy", "rtp_inst_avp", "$avp(RTP_INSTANCE)")
> +...
> +</programlisting>
> +		</example>
> +	</section>
>   	</section>
>   
>   	<section>
> diff --git a/modules/rtpproxy/rtpproxy.c b/modules/rtpproxy/rtpproxy.c
> index ae9d291..8cea776 100644
> --- a/modules/rtpproxy/rtpproxy.c
> +++ b/modules/rtpproxy/rtpproxy.c
> @@ -308,6 +308,8 @@ static int mod_init(void);
>   static int child_init(int);
>   static void mod_destroy(void);
>   
> +static int set_rtp_inst_avp(const str * const uri);
> +
>   /* Pseudo-Variables */
>   static int pv_get_rtpstat_f(struct sip_msg *, pv_param_t *, pv_value_t *);
>   
> @@ -337,6 +339,9 @@ struct rtpp_set * default_rtpp_set=0;
>   static char *ice_candidate_priority_avp_param = NULL;
>   static int ice_candidate_priority_avp_type;
>   static int_str ice_candidate_priority_avp;
> +static char *rtp_inst_avp_param = NULL;
> +static int rtp_inst_avp_type;
> +static int_str rtp_inst_avp;
>   
>   /* array with the sockets used by rtpporxy (per process)*/
>   static unsigned int rtpp_no = 0;
> @@ -437,6 +442,7 @@ static param_export_t params[] = {
>   	{"extra_id_pv",           STR_PARAM, &extra_id_pv_param.s },
>   	{"db_url",                STR_PARAM, &rtpp_db_url.s },
>   	{"table_name",            STR_PARAM, &rtpp_table_name.s },
> +	{"rtp_inst_avp",          STR_PARAM, &rtp_inst_avp_param },
>   	{0, 0, 0}
>   };
>   
> @@ -970,6 +976,19 @@ mod_init(void)
>   	    ice_candidate_priority_avp_type = avp_flags;
>   	}
>   
> +	if (rtp_inst_avp_param) {
> +	    s.s = rtp_inst_avp_param; s.len = strlen(s.s);
> +	    if (pv_parse_spec(&s, &avp_spec) == 0 || avp_spec.type != PVT_AVP) {
> +		LM_ERR("malformed or non AVP definition <%s>\n", rtp_inst_avp_param);
> +		return -1;
> +	    }
> +	    if (pv_get_avp_name(0, &(avp_spec.pvp), &rtp_inst_avp, &avp_flags) != 0) {
> +		LM_ERR("invalid AVP definition <%s>\n", rtp_inst_avp_param);
> +		return -1;
> +	    }
> +	    rtp_inst_avp_type = avp_flags;
> +	}
> +
>   	if (extra_id_pv_param.s && *extra_id_pv_param.s) {
>   		extra_id_pv_param.len = strlen(extra_id_pv_param.s);
>   		if(pv_parse_format(&extra_id_pv_param, &extra_id_pv) < 0) {
> @@ -1761,6 +1780,9 @@ select_rtpp_node(str callid, int do_test)
>   		node = selected_rtpp_set->rn_first;
>   		if (node->rn_disabled && node->rn_recheck_ticks <= get_ticks())
>   			node->rn_disabled = rtpp_test(node, 1, 0);
> +		if (!node->rn_disabled) {
> +			set_rtp_inst_avp(&node->rn_url);
> +		}
>   		return node->rn_disabled ? NULL : node;
>   	}
>   
> @@ -1811,6 +1833,7 @@ found:
>   		if (node->rn_disabled)
>   			goto retry;
>   	}
> +	set_rtp_inst_avp(&node->rn_url);
>   	return node;
>   }
>   
> @@ -2987,3 +3010,18 @@ pv_get_rtpstat_f(struct sip_msg *msg, pv_param_t *param,
>       return pv_get_strval(msg, param, res, &ret_val);
>   }
>   
> +static int set_rtp_inst_avp(const str * const uri) {
> +	int_str avp_val;
> +	avp_val.s = *uri;
> +
> +	if (rtp_inst_avp_param == NULL)
> +		return 0;
> +
> +	if (add_avp(AVP_VAL_STR | rtp_inst_avp_type, rtp_inst_avp, avp_val) != 0)
> +	{
> +		LM_ERR("Failed to add RTPProxy URI to avp\n");
> +		return -1;
> +	}
> +	return 0;
> +}
> +
>
>
> _______________________________________________
> sr-dev mailing list
> sr-dev at lists.sip-router.org
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

-- 
Daniel-Constantin Mierla - http://www.asipto.com
http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda




More information about the sr-dev mailing list