%docentities; ] >
Functions
<function>iptrtpproxy_alloc(gate_a_to_b [, existing_sess_ids])</function> Parses SDP content and allocates for each RTP media stream one RTP proxy session. SDP is updates to reflect allocated sessions. Switchboard/aggregation is set using iptrtpproxy_set_param(by_sip_ip) or iptrtpproxy_set_param("switchboard/aggregation"). Aggregation supports load balancing among more RTP proxies controlled by RPC. The module try to allocate at machines/switchboards in following order (priorities) not yet asked (or being heartbeated) machines, responsive machines, switchboards having percentualy more free slots, non responsive machines. Proxy may hide caller identity provided at o= line using @iptrtpproxy.o_name/addr and iptrtpproxy_set_param(o_name/addr) functions. But the script is responsible for rewritting to original values in a response or a callee initiated re-INVITE. Therefore original value need to be stored in-dialog. if gate_a_to_b bit 0 is set then SDP regards to gate-a to gate-b direction. protected_session_ids list of existing sessions enables reusing already allocated sessions in re-INVITE without allocating new sessions for each stream in SDP regardless a IP/port is required. It's mostly undesirable, typically "hold-on" is done via re-INVITE without any change. There is drawback because callee cannot change IP:port in 200OK which is legal case in RFC3264. But because some non-RFC3264 compliant phones dislike proactively changed IP:port at RTP proxy it seems it's less evil. function returns true is a session was created, identifier is available via select @iptrtpproxy.session_ids. <function>iptrtpproxy_alloc</function> usage ... if (!iptrtpproxy_set_param("aggregation_by_sip_ip_a", "@received.ip")) { if (!iptrtpproxy_set_param("switchboard_by_sip_ip_a", "@received.ip")) { t_reply("500", "RTP proxy error"); drop; } } eval_push("x:%@next_hop.src_ip"); if (@eval.get[-1] == @received.ip) { if (@iptrtpproxy.aggregation_a) { iptrtpproxy_set_param("aggregation_b", "@iptrtpproxy.aggregation_a"); } else { iptrtpproxy_set_param("switchboard_b", "@iptrtpproxy.switchboard_a"); } } else { if (!iptrtpproxy_set_param("aggregation_by_sip_ip_b", "@eval.get[-1]")) { if (!iptrtpproxy_set_param("switchboard_by_sip_ip_b", "@eval.get[-1]")) { t_reply("500", "RTP proxy error"); drop; } } } eval_remove(-1, 1); if (!iptrtpproxy_alloc("1")) { t_reply("500", "RTP proxy error"); drop; } $sess_ids = @iptrtpproxy.session_ids; ...
<function>iptrtpproxy_update(gate_a_to_b, session_ids)</function> Parses SDP content and updates sessions provided by session_ids and updates SDP. If succesfull then session_ids may be changed (in case e.g. media stream has port zero particular session is released), the result of @iptrtpproxy.session_ids should be stored for future in-dialog usage. The SDP contect is also affected by iptrtpproxy_set_param(o_name/addr) functions. If a stream is deactivated in SDP then Sessions may be deleted unless mentioned in protected_session_ids. if gate_a_to_b bit 0 is set then SDP regards to gate-a to gate-b direction. if gate_a_to_b bit 1 is set then SDP is updated only, no RTP session are affected. Should be used when handling retransmission in onreply route, retransmission replies are not eaten be tm module! <function>iptrtpproxy_update</function> usage ... # load $sess_ids from dialog if (iptrtpproxy_update("0", $sess_ids)) { $sess_ids = @iptrtpproxy.session_ids; # save sess_ids in dialog } ...
<function>iptrtpproxy_adjust_timeout(gate_a_to_b, session_ids)</function> Adjust timeout for particular gate. It's useful in "200 OK" decrease timeout to learning timeout if INVITE has set (long) ringing timeout. if gate_a_to_b bit 0 is set then it regards to gate-a to gate-b direction. <function>iptrtpproxy_adjust_timeout</function> usage ... # load $sess_ids from dialog if (status=~"18[0-9]") { iptrtpproxy_set_param("learning_timeout", "60"); } else { iptrtpproxy_set_param("learning_timeout", "5"); } if (iptrtpproxy_adjust_timeout("0", $sess_ids)) { } ...
<function>iptrtpproxy_delete(session_ids)</function> Delete sessions identified by session_ids. May be used when dialog is being destroyed (BYE) or when INVITE failed in failure route. If protected_session_ids list is provided then this set is excluded from sessions to be deleted. <function>iptrtpproxy_delete</function> usage ... # load $sess_ids from dialog iptrtpproxy_delete($sess_ids); ...
<function>iptrtpproxy_authorize_media()</function> Authorizes SDP media according currect codec_set. If bit AND operation between rights in codec set and remove_codec_mask is non zero then such a codec are to be removed. The result may be obtained from @iptrtpproxy.auth_rights which returns max. right which has been applied when processing all codecs of enabled streams. The function MUST NOT be called after iptrtpproxy_alloc/update! But the function may be called several times to authorize using more codec sets. <function>iptrtpproxy_authorize_media</function> usage ... if (@iptrtpproxy.active_media_num == "0") break; iptrtpproxy_set_param("codec_set", "cs2"); iptrtpproxy_set_param("remove_codec_mask", "1"); if (!iptrtpproxy_authorize_media()) { t_reply("415", "Cannot authorize media"); drop; } iptrtpproxy_set_param("codec_set", "cs3"); if (!iptrtpproxy_authorize_media()) { t_reply("415", "Cannot authorize media"); drop; } if (@iptrtpproxy.active_media_num == "0") { t_reply("488", "Not acceptable here"); drop; } if (@iptrtpproxy.auth_rights == "2") { append_hf_value("Contact: <sip:1.2.3.4>"); t_reply("301", "Redirect to transcoder"); drop; } ...
<function>iptrtpproxy_set_param(param, value)</function> Set particular parameter needed mainly by iptrtpproxy_alloc/update/adjust_timeout. The paramter value is availble via @iptrtpproxy.<param>. Supported parameters: expiration_timeout, ttl, learning_timeout, always_learn, aggregation_a, aggregation_b, switchboard_a, switchboard_b, throttle_mark, throttle_rtp_max_bytes, throttle_rtp_max_packets, throttle_rtcp_max_bytes, throttle_rtcp_max_packets.
<function>iptrtpproxy_set_param("(aggregation/switchboard)_by_sip_ip_(a/b)", sip_ip)</function> Find corresponding aggregation or switchboard and set @iptrtpproxy.aggregation_a/b or @iptrtpproxy.switchboard_a/b. Switchboards/aggregations are compared against sip-addr, it allow separate SIP and RTP traffic and RTP aggregation. sip_ip IP to be compared, typically @received.ip or @next_hop.src_ip. function returns true if switchboard/aggregation was found
<function>iptrtpproxy_set_param("protected_session_ids", sess_ids)</function> Used for reusing sessions in iptrtpproxy_alloc, iptrtpproxy_update and iptrtpproxy_delete.
<function>iptrtpproxy_set_param("o_name", value)</function> Username to be rewritten at o= line by iptrtpproxy_alloc/update to hide caller identity. If value is blank then username is left unchanged.
<function>iptrtpproxy_set_param("o_addr", value)</function> Address to be rewritten at o= line by iptrtpproxy_alloc/update to hide caller identity. If value is blank then address is left unchanged.
<function>iptrtpproxy_set_param("codec_set", value)</function> Codec set for iptrtpproxy_authorize_media. Current codec set may be obtained by @iptrtpproxy.codec_set.
<function>iptrtpproxy_set_param("remove_codec_mask", value)</function> Mask used in iptrtpproxy_authorize_media. Current mask may be obtained by @iptrtpproxy.remove_codec_mask.