<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Denys Pozniak on Medium]]></title>
        <description><![CDATA[Stories by Denys Pozniak on Medium]]></description>
        <link>https://medium.com/@denys-pozniak?source=rss-e620970a734d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*90PW8-l1iJuovOo3biYNzQ.png</url>
            <title>Stories by Denys Pozniak on Medium</title>
            <link>https://medium.com/@denys-pozniak?source=rss-e620970a734d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 00:08:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@denys-pozniak/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Kamailio Internals Handbook I Wrote With an LLM — and Why I Think It’s Worth Your Time]]></title>
            <link>https://denys-pozniak.medium.com/the-kamailio-internals-handbook-i-wrote-with-an-llm-and-why-i-think-its-worth-your-time-28a2a6c78914?source=rss-e620970a734d------2</link>
            <guid isPermaLink="false">https://medium.com/p/28a2a6c78914</guid>
            <dc:creator><![CDATA[Denys Pozniak]]></dc:creator>
            <pubDate>Wed, 27 May 2026 15:43:15 GMT</pubDate>
            <atom:updated>2026-05-27T15:43:15.682Z</atom:updated>
            <content:encoded><![CDATA[<p>The official wiki and the per-module reference pages will tell you <em>what to call</em> — record_route(), t_relay(), lookup(&quot;location&quot;). They will not tell you what happens between those calls. They will not tell you why pkg memory and shm memory behave differently, why your return 0 in a KEMI Lua function flips meaning compared to the native cfg script, what topos actually rewrites on the wire, or how a child process is picked to handle an incoming SIP packet.</p><p>That stuff lives in the source. It lives in commit messages from 2014. It lives in mailing-list threads. It lives in the heads of a handful of people who have been close to the project for a decade.</p><p>For a VoIP engineer ramping up on Kamailio, that gap is a wall. I have hit it. Every engineer I have ever onboarded onto Kamailio has hit it.</p><p>So I wrote a handbook.</p><h3>What it is</h3><p>The <a href="http://denyspozniak.github.io/kamailio-handbook"><strong>Kamailio Handbook</strong></a> is a structured deep-dive into how Kamailio works on the inside. It is not a tutorial on how to register users. It is not a config cookbook. It is not a re-telling of the wiki. It covers the parts that the existing documentation skips because — historically — the people who needed to know already knew.</p><p>The chapters are organized around the things you actually have to understand to operate Kamailio confidently:</p><ul><li><strong>The runtime.</strong> Process model, fork layout, pkg vs shm memory, locks, lifecycle.</li><li><strong>The SIP message lifecycle.</strong> Reception, the parser’s lazy strategy, data lumps, the routing engine, forwarding.</li><li><strong>The script engine.</strong> The cfg DSL, the AST it compiles to, how module functions are dispatched, what pseudo-variables really are.</li><li><strong>KEMI.</strong> The bridge to Lua / Python / JS / Ruby. Why the same return 0 means different things in different worlds. Tradeoffs against the native script.</li><li><strong>State.</strong> Transactions in tm, the dialog module, the usrloc cache pattern, the timer wheels under all of it.</li><li><strong>The control plane.</strong> JSON-RPC, BINRPC, kamcmd, event routes — how Kamailio is observed and managed at runtime.</li><li><strong>Architectural tricks.</strong> topos, async transactions, htable, dispatcher, dmq.</li><li><strong>Reference.</strong> Process roles, the terminology map.</li></ul><p>Each chapter is short, focused, and ends with the kind of “wait, but what about…” callout that you only get from somebody who has been burned by the thing.</p><h3>How I wrote it</h3><p>This part needs to be said up front: <strong>the handbook is an AI-assisted document.</strong> I did not write every sentence by hand. I worked with a language model — feeding it the Kamailio 6.1.x source tree, the developer notes, the wiki, my own working knowledge from years of building VoIP systems on top of Kamailio — and drafted each chapter as a collaboration.</p><h3>Who it’s for</h3><p>The primary audience is <strong>VoIP engineers who are starting out on Kamailio</strong>. The wiki gets you to a running proxy. This handbook gets you to understanding the running proxy.</p><p>It is also for:</p><ul><li>Engineers from other backgrounds — Go, Python, networking — who have inherited a Kamailio config and need to figure out what is actually happening underneath it.</li><li>Operators who have run Kamailio in production for years on muscle memory, and want a coherent map of the parts they have only ever touched through cfg.</li><li>Anyone deciding whether to adopt Kamailio for a project, who needs to evaluate the runtime model before committing.</li></ul><p>It is <strong>not</strong> for people looking for “how do I add a user to my proxy” or “how do I configure SRTP.” Those answers exist already. Go read the official docs. This handbook starts where those end.</p><h3>What it isn’t</h3><p>A few things to be clear about:</p><ul><li>It is not a substitute for the official Kamailio documentation. The module references on kamailio.org are authoritative on the API surface; this handbook is opinionated commentary on what happens behind it.</li><li>It is not affiliated with the Kamailio project. Any mistakes are mine, not theirs.</li><li>It is not a step-by-step tutorial. The chapters assume you have a Kamailio instance you can experiment with.</li><li>It is not finished. Kamailio keeps evolving. The handbook will too.</li></ul><h3>Bilingual and open</h3><p>The handbook is published in <strong>English and Ukrainian</strong> under MIT. Both trees are mirrored chapter-for-chapter. Fixing a typo in one tree and forgetting the other is, currently, the most common kind of issue.</p><p>If you find a mistake, an omission, or something that just reads unclearly — open an issue or a PR. I would rather be corrected than authoritative.</p><h3>Where to read it</h3><p><a href="http://denyspozniak.github.io/kamailio-handbook"><strong>denyspozniak.github.io/kamailio-handbook</strong></a></p><p>The site is built from the same repository the source markdown lives in, auto-deployed from main. If you want to read offline, clone the repo; every chapter is plain Markdown with Mermaid diagrams that render natively on GitHub.</p><p>Start with chapter 1 if you want the mental model first. Jump to chapter 3 if you already know the SIP basics and want the message lifecycle. Skim chapter 7 if you have ever wondered what kamcmd is actually doing when you type a command.</p><p>If even one chapter saves you the afternoon of source-diving I had to do to understand the same thing — the handbook has done its job.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28a2a6c78914" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kamailio workaround for FreeSWITCH un-hold (RFC 6337) problem]]></title>
            <link>https://denys-pozniak.medium.com/kamailio-workaround-for-freeswitch-un-hold-rfc-6337-problem-386a116adfee?source=rss-e620970a734d------2</link>
            <guid isPermaLink="false">https://medium.com/p/386a116adfee</guid>
            <dc:creator><![CDATA[Denys Pozniak]]></dc:creator>
            <pubDate>Mon, 28 Aug 2023 08:04:11 GMT</pubDate>
            <atom:updated>2023-08-28T08:06:23.098Z</atom:updated>
            <content:encoded><![CDATA[<p>In my opinion, FreeSWITCH does not properly handle hold call release in the context of an RTP media stream (RFC6337), to work around this issue I had to modify the SIP/SDP part.</p><p>Below is an example of a Kamailio configuration for solving this problem.</p><p><a href="https://github.com/signalwire/freeswitch/issues/846">RFC6337 hold-unhold issue · Issue #846 · signalwire/freeswitch</a></p><pre>onreply_route[RFC6337_REPLY] {<br> route(RFC6337);<br>}<br><br>route[RFC6337] {<br> if ( is_reply() ) {<br>  if ( $rs == 200 &amp;&amp; $dlg_var(unhold_from) != $null ) {<br>   if ( $ua =~ &quot;FreeSWITCH&quot; &amp;&amp; $ct =~ &quot;mod_sofia&quot; ) {<br>    replace_body(&quot;a=recvonly&quot;, &quot;a=sendrecv&quot;);<br>   }<br>  }<br>  return;<br> }<br><br> if ( is_method(&quot;INVITE&quot;) &amp;&amp; has_totag() &amp;&amp; $si == &#39;192.168.100.100&#39; ) {<br>  if( !t_is_set(&quot;onreply_route&quot;) ) t_on_reply(&quot;RFC6337_REPLY&quot;);<br><br>  if ( is_audio_on_hold() &amp;&amp; $dlg_var(hold_lock) != 1 ) {<br>   $dlg_var(hold_from) = $var(from_who);<br>   $dlg_var(hold_body) = $rb;<br>   $dlg_var(hold_lock) = &quot;1&quot;;<br>  } else if ( !has_body(&quot;application/sdp&quot;) &amp;&amp; $dlg_var(hold_lock) == &quot;1&quot; ) {<br>   $dlg_var(unhold_from) = $var(from_who);<br>   $dlg_var(unhold_cseq) = $cs;<br>   $dlg_var(hold_lock)   = &quot;0&quot;;<br>   xlog(&quot;L_WARN&quot;, &quot;[RFC6337] *SDP attached* $rm/fU=$fU/tU=$tU/$si $ci \n&quot;);<br>   $var(hold_body) = $(dlg_var(hold_body){re.subst,/a=sendonly/a=sendrecv/g});<br>   set_body(&quot;$var(hold_body)&quot;, &quot;application/sdp&quot;);<br>  }<br> }<br><br> if ( is_method(&quot;ACK&quot;) &amp;&amp; has_body(&quot;application/sdp&quot;) &amp;&amp; search_body(&quot;a=sendrecv&quot;) ) {<br>  if ( $dlg_var(hold_from) == $dlg_var(unhold_from) &amp;&amp; $dlg_var(unhold_cseq) == $cs ) {<br>   xlog(&quot;L_WARN&quot;, &quot;[RFC6337] *SDP un-hold detected* $rm/fU=$fU/tU=$tU/$si $ci \n&quot;);<br>   remove_hf(&quot;Content-Type&quot;);<br>   remove_body();<br>   msg_apply_changes();<br>  }<br> }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=386a116adfee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OpenSIPS anycast SIP balancer]]></title>
            <link>https://denys-pozniak.medium.com/opensips-anycast-sip-balancer-c0e9e8884eb?source=rss-e620970a734d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0e9e8884eb</guid>
            <category><![CDATA[opensips]]></category>
            <category><![CDATA[sip]]></category>
            <category><![CDATA[voip]]></category>
            <category><![CDATA[anycast]]></category>
            <category><![CDATA[kamailio]]></category>
            <dc:creator><![CDATA[Denys Pozniak]]></dc:creator>
            <pubDate>Mon, 19 Jun 2023 09:07:40 GMT</pubDate>
            <atom:updated>2023-06-19T09:07:40.391Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I will try to outline the main points of building an incoming anycast SIP traffic balancer based on OpenSIPS. There will be no details of the network architecture.</p><p>For a better understanding, please read the article:</p><p><a href="https://blog.opensips.org/2018/03/21/full-anycast-support-in-opensips-2-4/">Full Anycast support in OpenSIPS 2.4</a></p><p>The main task was to build an additional upper layer over the existing legacy topology so that it would be possible to dynamically distribute the load and be able to completely remove traffic from the node for maintenance.</p><p>During the research, two similar products were considered: Kamailio and OpenSIPS, but the choice fell on the last one since it has native support for anycast, plus it is also possible to enable SBC functionality to hide the internal topology.</p><p>Below is a link to an example of configuration based on Kamailio (here the main difference is that “replication” is based on SIP protocol, in the case of OpenSIPS this happens through the internal bin interface of the clusterer module).</p><p><a href="https://github.com/kamailio/kamailio/blob/master/misc/examples/mixed/kamailio-minimal-anycast.cfg">https://github.com/kamailio/kamailio/blob/master/misc/examples/mixed/kamailio-minimal-anycast.cfg</a></p><p><a href="https://github.com/kamailio/kamailio/blob/master/misc/examples/mixed/kamailio-minimal-anycast.cfg">kamailio/misc/examples/mixed/kamailio-minimal-anycast.cfg at master · kamailio/kamailio</a></p><p>The diagram below shows the block architecture of the solution. From the Internet side, the OpenSIPS proxy group is seen as a single anycast address 1.1.1.1, the metrics on routers are configured equivalently, and incoming traffic is distributed almost evenly. But a situation is possible when SIP replies or part of the dialog will be served on different nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LG7IInyPv6l5Iu89" /></figure><p>As for registrations from clients, they are proxied to the legacy server with the addition of a Path header, so there will be a known way to reach back the client from the core of the network.</p><pre>if ( is_method(&quot;REGISTER|SUBSCRIBE&quot;) ) {<br>  remove_hf(&quot;Route&quot;);<br>  remove_hf(&quot;Path&quot;);<br><br>  if ( is_present_hf(&quot;Supported&quot;) &amp;&amp; !$hdr(Supported) =~ &quot;path&quot; ) {<br>    $var(supported) = $hdr(Supported) + &quot;, path&quot;;<br>    remove_hf(&quot;Supported&quot;);<br>    insert_hf(&quot;Supported: $var(supported)\r\n&quot;,&quot;Content-Length&quot;);<br>  } else {<br>    insert_hf(&quot;Supported: path\r\n&quot;,&quot;Content-Length&quot;);<br>  }<br>  add_path_received();<br>  ...</pre><p>For in-dialog requests, we check for the presence of a local transaction and, if not, we replicate the message to another node.</p><pre>route[WITHINDIALOG] {<br>if ( has_totag() ) {<br>  if ( !loose_route() &amp;&amp; !t_check_trans() ) {<br>    if ( is_method(&quot;ACK&quot;) ) {<br>      t_anycast_replicate();<br>      exit;<br>    }<br>  }<br><br>  if ( is_method(&quot;ACK&quot;) &amp;&amp; t_check_trans() ) {<br>    route(RELAY);<br>    exit;<br>  }<br><br>  if ( !loose_route() ) {<br>    send_reply(404,&quot;Not in dialog&quot;);<br>    exit;<br>  }<br><br>  route(RELAY);<br>  exit;<br>}<br><br>if ( is_method(&quot;CANCEL&quot;) ) {<br>  if ( t_check_trans() ) {<br>    route(RELAY);<br>  } else {<br>    t_anycast_replicate();<br>  }<br>}<br><br>t_check_trans();<br>}</pre><p>To enable the functionality of replicating data about the transaction owner, do not forget to enable the option below:</p><pre>modparam(&quot;tm&quot;, &quot;tm_replication_cluster&quot;, 1)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0e9e8884eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[VoIP SBC SEMS configuration example]]></title>
            <link>https://denys-pozniak.medium.com/voip-sbc-sems-configuration-example-2a056bec6089?source=rss-e620970a734d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a056bec6089</guid>
            <category><![CDATA[kamailio]]></category>
            <category><![CDATA[sbc]]></category>
            <category><![CDATA[opensips-development]]></category>
            <category><![CDATA[sip]]></category>
            <dc:creator><![CDATA[Denys Pozniak]]></dc:creator>
            <pubDate>Mon, 25 Jan 2021 14:14:32 GMT</pubDate>
            <atom:updated>2021-04-09T08:11:25.693Z</atom:updated>
            <content:encoded><![CDATA[<p>The <a href="https://github.com/sems-server/sems">SEMS (SIP Express Media Server</a>) is a powerful open-source VoIP SBC that can be widely used for interconnection with VoIP ISP.</p><pre>SEMS is a free, high performance, extensible media server <br>for SIP (RFC3261) based VoIP services. <br><br>It is intended to complement proxy/registrar servers<br>in VoIP networks for all applications where server-<br>side processing of audio is required, for example away <br>or pre-call announcements, voicemail, or network side <br>conferencing. Another use case is for interconnecting<br>SIP networks, where a back-to-back user agent (B2BUA)<br>is required.</pre><p>To install it visit the <a href="https://github.com/sems-server/sems/wiki">Wiki page</a> and choose the operating system that you like.</p><p>The SEMS supports a number of applications, now let’s look at the work of the most popular <strong>sbc</strong> app:</p><pre>Back-to-back User Agent<br>  <br>  * sbc  flexible SBC application, supports<br>         - identity change<br>         - header manipulation (filter etc)<br>         - (multihomed) RTP relay, NAT handling,transcoding  <br>         - SIP authentication <br>         - Session timer, call timer, prepaid<br>        etc</pre><p>Let&#39;s use the server with 2 interfaces enp0s3 (192.168.11.102) and enp0s8 (192.168.56.101), and configure the call routing logic.</p><p>Below is the minimum possible configuration tree for call routing:</p><pre>sems<br>├── etc<br>│   ├── in2out.sbcprofile.conf<br>│   └── sbc.conf<br>└── sems.conf</pre><p>The configuration file <strong>/etc/sems/sems.conf</strong> describes network parameters, daemon startup options and required applications.</p><pre>[root@localhost sems]# cat /etc/sems/sems.conf<br>interfaces=in,out<br>sip_ip_in=192.168.56.101<br>sip_port_in=5060<br>media_ip_in=192.168.56.101</pre><pre>sip_ip_out=192.168.11.102<br>sip_port_out=5060<br>media_ip_out=192.168.11.102</pre><pre>plugin_path=/usr/lib64/sems/plug-in/<br>plugin_config_path=/etc/sems/etc/<br>load_plugins=sbc;<br>application=sbc</pre><pre>fork=yes<br>loglevel=2</pre><p>The configuration file <strong>/etc/sems/etc/sbc.conf</strong> describes sbc application parameters, like profiles, regex maps and some core options.</p><pre>[root@localhost etc]# cat /etc/sems/etc/sbc.conf<br>profiles=in2out<br>active_profile=in2out</pre><p>The profile <strong>/etc/sems/etc/in2out.sbcprofile.conf</strong> describes call routing logic. In the case below it does SIP CallID modifications and enables media relaying through a SEMS.</p><pre>[root@localhost etc]# cat /etc/sems/etc/in2out.sbcprofile.conf<br>Call-ID=$ci_in2out<br>outbound_interface=out<br>outbound_proxy=sip:192.168.11.115:50605<br>enable_rtprelay=yes</pre><p>There are lots of profile <a href="https://github.com/sems-server/sems/blob/master/doc/Readme.sbc.txt">parameters</a> for security purposes and to hide the network topology.</p><p>The resulting call flow diagram shows two separate legs (signaling and media):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QfgCPfLmRlYjI2AL7vuOUg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a056bec6089" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kamailio registration replication with DMQ]]></title>
            <link>https://denys-pozniak.medium.com/kamailio-registration-replication-with-dmq-be3b9b8478d?source=rss-e620970a734d------2</link>
            <guid isPermaLink="false">https://medium.com/p/be3b9b8478d</guid>
            <category><![CDATA[replication]]></category>
            <category><![CDATA[denys-pozniak]]></category>
            <category><![CDATA[cluster]]></category>
            <category><![CDATA[kamailio]]></category>
            <category><![CDATA[sip]]></category>
            <dc:creator><![CDATA[Denys Pozniak]]></dc:creator>
            <pubDate>Mon, 27 May 2019 07:40:50 GMT</pubDate>
            <atom:updated>2019-05-27T07:42:52.155Z</atom:updated>
            <content:encoded><![CDATA[<p>To replicate SIP REGISTER messages can be used <a href="https://www.kamailio.org/docs/modules/devel/modules/dmq.html#dmq.f.dmq_t_replicate">dmq_t_replicate()</a> function.</p><blockquote>Replicates the current SIP message to all active nodes (except self). Useful for replicating REGISTER, PUBLISH etc. in a clustered environment.</blockquote><p>So your config will be like below:</p><pre>loadmodule &quot;dmq.so&quot;<br>modparam(&quot;dmq&quot;, &quot;server_address&quot;, &quot;sip:10.1.1.10:5060&quot;)<br>...</pre><pre>request_route {<br>...</pre><pre>  if ( is_method(&quot;REGISTER&quot;) ) {<br>    route(AUTH);<br>    route(LOCATION);<br>    dmq_t_replicate();<br>  }</pre><pre>...<br>}</pre><p>A call-flow from sngrep:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*3ACbt8KhID3sV8fB3QB10Q.png" /></figure><p>A picture is from article <a href="https://medium.com/@tumalevich/kamailio-registration-replication-without-dmq-65e225f9a8a7"><strong>Kamailio registration replication without dmq</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be3b9b8478d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Failure SIP call rerouting with Kamailio]]></title>
            <link>https://denys-pozniak.medium.com/failure-sip-call-rerouting-with-kamailio-5a80a8778d53?source=rss-e620970a734d------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a80a8778d53</guid>
            <category><![CDATA[denys-pozniak]]></category>
            <category><![CDATA[rerouting]]></category>
            <category><![CDATA[kamailio]]></category>
            <category><![CDATA[sip]]></category>
            <dc:creator><![CDATA[Denys Pozniak]]></dc:creator>
            <pubDate>Fri, 05 Apr 2019 07:40:38 GMT</pubDate>
            <atom:updated>2019-04-05T07:40:38.261Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>This example shows how to build a simple call rerouting solution based on <a href="https://www.kamailio.org/">Kamailio</a> in case of failure detection.</blockquote><p>The main logic will be implemented by function <a href="https://kamailio.org/docs/modules/devel/modules/tm.html#tm.f.t_on_failure">t_on_failure(failure_route)</a>.</p><p>So if Kamailio forwards SIP request and detects the negative response, original request will be “caught” by failure_route[] routing block to send this call to another destination. This time origin party will be in the waiting state (does not receive the negative response).</p><p>In our example we are trying to reach the user using information from the location database, if we get error response (Busy Here or Request Timeout), we are routing call to the 192.168.100.100.</p><p>Let’s check configuration example:</p><pre>request_route {</pre><pre>if ( !lookup(&quot;location&quot;) ) {<br>  sl_send_reply(&quot;404&quot;, &quot;Not found&quot;);<br>exit;<br>}</pre><pre>t_on_failure(&quot;FAILURE_ROUTE&quot;);<br>t_relay();<br>}</pre><pre>}</pre><pre>failure_route[FAILURE_ROUTE] {<br>if ( t_is_canceled() ) {<br>  exit;<br>}</pre><pre>if ( t_check_status(&quot;486|408&quot;) ) {<br>  # Building $ru for the new destination<br>  $ru = &quot;sip:&quot; + $oU + &quot;@192.168.100.100&quot;;<br>  t_relay();<br>  exit;<br>}</pre><pre>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a80a8778d53" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apple Push Notification with Kamailio]]></title>
            <link>https://denys-pozniak.medium.com/apple-push-notification-with-kamailio-eeca2f8e08d?source=rss-e620970a734d------2</link>
            <guid isPermaLink="false">https://medium.com/p/eeca2f8e08d</guid>
            <category><![CDATA[asterisk]]></category>
            <category><![CDATA[lua]]></category>
            <category><![CDATA[sip]]></category>
            <category><![CDATA[kamailio]]></category>
            <category><![CDATA[push-notification]]></category>
            <dc:creator><![CDATA[Denys Pozniak]]></dc:creator>
            <pubDate>Fri, 28 Dec 2018 11:55:06 GMT</pubDate>
            <atom:updated>2019-01-15T16:24:15.675Z</atom:updated>
            <content:encoded><![CDATA[<h3>Push Notification with Kamailio</h3><p>This brief tutorial shows how to “freeze” SIP transaction to the moment the subscriber wakes up. The logic is simple here:</p><ul><li>Asterisk sends SIP INVITE to Kamailio SIP Proxy</li><li>Kamailio detects device type by specific X-header and freezes incoming SIP transaction</li><li>Kamailio sends “push” via http request to PHP script</li><li>Once Kamailio detects new REGISTER from device, it resumes transaction</li><li>Kamailio sends SIP INVITE to the subscriber</li></ul><p>Module settings:</p><pre>#htable module setting. vtp keeps transaction details.</pre><pre>modparam(&quot;htable&quot;, &quot;htable&quot;, &quot;vtp=&gt;size=10;autoexpire=120;&quot;)</pre><p>Kamailio script building blocks:</p><pre>#Detecting device type via custom SIP header X-phone.</pre><pre>if ( (is_method(&quot;INVITE&quot;)) &amp;&amp; (!has_totag()) &amp;&amp; ($(hdr(X-phone) =~ &quot;iphone&quot;) ) {<br>  send_reply(&quot;100&quot;, &quot;Suspending&quot;);<br>  route(SUSPEND);<br>}</pre><pre>#Suspending transaction and store index and label in vtp for the future needs.</pre><pre>route[SUSPEND] {<br>  if ( !t_suspend() ) {<br>    xlog(&quot;L_ERROR&quot;,&quot;[SUSPEND]  failed suspending trasaction [$T(id_index):$T(id_label)]\n&quot;);<br>    send_reply(&quot;501&quot;, &quot;Suspending error&quot;);<br>    exit;<br>  } else {<br>    xlog(&quot;L_INFO&quot;,&quot;[SUSPEND]  suspended transaction [$T(id_index):$T(id_label)] $fU=&gt; $rU\n&quot;);<br>    $sht(vtp=&gt;id_index::$rU) = $T(id_index);<br>    $sht(vtp=&gt;id_label::$rU) = $T(id_label);<br>    xlog(&quot;L_INFO&quot;,&quot;[SUSPEND] htable key value [$sht(vtp=&gt;id_index::$rU)   --   $sht(vtp=&gt;id_label::$rU)]\n&quot;);<br>    route(SENDPUSH);<br>    exit;<br>  }<br></pre><p>In my case <a href="https://kamailio.org/docs/modules/5.2.x/modules/rtpengine.html">Kamailio</a> runs the intermediate PHP script (push.php) with needed parameters for sending request to APN. You might use <a href="https://kamailio.org/docs/modules/devel/modules/app_lua.html">app_lua</a> module to push directly from Kamailio.</p><pre>#Below is a pushing service. It calls push.php script with parameters. Htable $sht(tokens=&gt;$rU) keeps needed token. And after PHP script connects to APN.</pre><pre>route[SENDPUSH] {<br>  ...<br>  http_client_query(&quot;<a href="http://omnivoice.smartchoiceus.com/iphone_push/push.php">http://url/push.php</a>&quot;, &quot;user=$rU\r\npn-tok=$sht(tokens=&gt;$rU)\r\n&quot;,&quot;Content-Type: text/plain&quot;, &quot;$var(result)&quot;);<br>  ...<br>  sl_send_reply(&quot;100&quot;, &quot;Pushing&quot;);<br>}</pre><p>Here we are detecting incoming REGISTER message from pushed device:</p><pre>#Unfreezing by new incoming REGISTER message. </pre><pre>if ( (is_method(&quot;REGISTER&quot;)) &amp;&amp; (($hdr(Expires) != &quot;0&quot;) || ($hdr(Contact) !~ &quot;expires=0&quot;)) &amp;&amp; ($sht(vtp=&gt;id_index::$tU) != $null) ) {<br>  xlog(&quot;L_INFO&quot;, &quot;New $rm ru=$ru tu=$tu \n&quot;);<br>  route(JOIN);<br>}</pre><p>Resuming SIP transaction using stored label and index:</p><pre>#Resuming transaction.</pre><pre>route[JOIN] {<br>  xlog(&quot;L_INFO&quot;,&quot;[JOIN] htable key value [$sht(vtp=&gt;id_index::$tU)   --   $sht(vtp=&gt;id_label::$tU)]\n&quot;);<br>  t_continue(&quot;$sht(vtp=&gt;id_index::$tU)&quot;, &quot;$sht(vtp=&gt;id_label::$tU)&quot;, &quot;RESUME&quot;);<br>}</pre><pre>#Lookup into location database and relaying.</pre><pre>route[RESUME] {<br>  lookup(&quot;location&quot;);<br>  xlog(&quot;L_INFO&quot;,&quot;[RESUME] rm=$rm ru=$ru du=$du \n&quot;);<br>  t_relay();<br>  exit;<br>}</pre><p>Sngrep call-flow example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*l8S6SdWLfQ-ivwv6o53lDQ.png" /></figure><p>Useful link:</p><iframe src="https://drive.google.com/viewerng/viewer?url=https%3A//www.voztovoice.org/sites/default/files/KamilioWorld2015%2520-Federico.Cabiddu-TSILO.pdf&amp;embedded=true" width="600" height="780" frameborder="0" scrolling="no"><a href="https://medium.com/media/e7c73bda85663aae90ca24053f1cab06/href">https://medium.com/media/e7c73bda85663aae90ca24053f1cab06/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eeca2f8e08d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting RTP stream statistics from RTPengine]]></title>
            <link>https://denys-pozniak.medium.com/getting-rtp-stream-statistics-from-rtpengine-d5b92e408d28?source=rss-e620970a734d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5b92e408d28</guid>
            <category><![CDATA[rtpengine]]></category>
            <category><![CDATA[kamailio]]></category>
            <category><![CDATA[moses]]></category>
            <category><![CDATA[sip]]></category>
            <category><![CDATA[rtp]]></category>
            <dc:creator><![CDATA[Denys Pozniak]]></dc:creator>
            <pubDate>Sat, 24 Nov 2018 21:34:55 GMT</pubDate>
            <atom:updated>2019-04-09T07:48:52.786Z</atom:updated>
            <content:encoded><![CDATA[<p>This tutorial helps you to understand how to collect RTP <a href="https://en.wikipedia.org/wiki/Mean_opinion_score">MOS</a> parameters from <a href="https://github.com/sipwise/rtpengine">RTPengine</a>. As SIP Proxy server we will use <a href="https://kamailio.org/docs/modules/5.2.x/modules/rtpengine.html">Kamailio</a>.</p><p>You need to add additional module parameters to be able to collect statistics from specific call leg:</p><pre>modparam(&quot;rtpengine&quot;, &quot;mos_A_label_pv&quot;, &quot;$avp(mos_A_label)&quot;)<br>modparam(&quot;rtpengine&quot;, &quot;mos_average_packetloss_A_pv&quot;, &quot;$avp(mos_average_packetloss_A)&quot;)<br>modparam(&quot;rtpengine&quot;, &quot;mos_average_jitter_A_pv&quot;, &quot;$avp(mos_average_jitter_A)&quot;)<br>modparam(&quot;rtpengine&quot;, &quot;mos_average_roundtrip_A_pv&quot;, &quot;$avp(mos_average_roundtrip_A)&quot;)<br>modparam(&quot;rtpengine&quot;, &quot;mos_average_A_pv&quot;, &quot;$avp(mos_average_A)&quot;)</pre><p>Also you need to modify script section where RTPengine is called in the way to detect direction, it can be like this:</p><pre>...<br>if ($si != &quot;192.168.100.100&quot;) {<br>  rtpengine_manage(&quot;<strong>... label=WAN</strong>&quot;);<br>}<br>...</pre><p>And also you need to add <em>rtpengine_query()</em> when call ends:</p><pre>...<br>if (is_method(&quot;BYE&quot;) {<br>  $avp(mos_A_label) = &quot;WAN&quot;;<br>  rtpengine_query();<br>  rtpengine_delete();<br>}</pre><pre>xlog(&quot;L_INFO&quot;, &quot;$ci|mos= $avp(mos_average_A)\n&quot;);<br>xlog(&quot;L_INFO&quot;, &quot;$ci|jitter= $avp(mos_average_jitter_A)\n&quot;);<br>xlog(&quot;L_INFO&quot;, &quot;$ci|p_loss= $avp(mos_average_packetloss_A)\n&quot;);</pre><pre>...</pre><p>As result you will have in syslog:</p><pre>INFO: &lt;script&gt;: 804F4788–43E7-E811–99FD-50D89|mos= 4.3<br>INFO: &lt;script&gt;: 804F4788–43E7-E811–99FD-50D89|jitter= 3<br>INFO: &lt;script&gt;: 804F4788–43E7-E811–99FD-50D89|p_loss= 0</pre><p>Useful link:</p><p><a href="https://lists.kamailio.org/pipermail/sr-users/2018-February/100320.html">[SR-Users] RTPEngine QoS statistics and leg labelling</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5b92e408d28" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Voice transcoding with Kamailio and RTPengine]]></title>
            <link>https://denys-pozniak.medium.com/voice-transcoding-with-kamailio-and-rtpengine-241754a55894?source=rss-e620970a734d------2</link>
            <guid isPermaLink="false">https://medium.com/p/241754a55894</guid>
            <category><![CDATA[kamailio]]></category>
            <category><![CDATA[sip]]></category>
            <category><![CDATA[transcoding]]></category>
            <category><![CDATA[rtpengine]]></category>
            <category><![CDATA[opera]]></category>
            <dc:creator><![CDATA[Denys Pozniak]]></dc:creator>
            <pubDate>Wed, 31 Oct 2018 13:46:54 GMT</pubDate>
            <atom:updated>2018-10-31T16:47:24.184Z</atom:updated>
            <content:encoded><![CDATA[<p>This example shows how to transcode RTP stream from G.729 to G.711 using <a href="https://www.kamailio.org/">Kamailio</a> SIP proxy and <a href="https://github.com/sipwise/rtpengine">RTPenging</a> as media proxy.</p><p>To build RTPengine with supporting G.729 you need to have the bgc729 library in advance. For testing purpose I used my own <a href="https://copr.fedorainfracloud.org/coprs/denysp/rtpengine/">CentOS 6/7 repo</a>. You can try to use it also, as is. Be sure you have added needed repositories to resolve dependencies (links below External Repository List).</p><p>After installation you will have something like below:</p><pre><em>[root@kamailio]# rtpengine  — codecs</em></pre><pre><em> PCMA: fully supported<br> PCMU: fully supported<br> G723: fully supported<br> G722: fully supported<br> QCELP: supported for decoding only<br> </em><strong><em>G729: fully supported</em></strong><em><br> speex: fully supported<br> GSM: fully supported<br> iLBC: not supported<br> opus: fully supported<br> vorbis: fully supported<br> ac3: fully supported<br> eac3: fully supported<br> ATRAC3: supported for decoding only<br> ATRAC-X: supported for decoding only<br> AMR: fully supported<br> AMR-WB: fully supported<br> PCM-S16LE: fully supported<br> MP3: fully supported</em></pre><p>After that you need to modify your Kamailio script and call <a href="https://www.kamailio.org/docs/modules/5.0.x/modules/rtpengine.html">rtpengine module</a> with additional parameters :</p><pre>...</pre><pre>if (is_method(&quot;INVITE&quot;)) {<br>  if (has_body(&quot;application/sdp&quot;)) {<br>    rtpengine_manage(&quot;... <strong>codec-mask-all codec-transcode-PCMA</strong>&quot;);<br>...</pre><p>RTPengine will mask all codecs from the offer and transcode to PCMA, in my case I am sending G.729 only (but in your case it might be OPUS as example) and have G.711 as result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BZaUEqsE3xVUA1DOBDBbvA.png" /></figure><p>Incoming INVITE SDP:</p><pre><em>m=audio 11846 RTP/AVP 18 101<br>a=rtpmap:18 G729/8000<br>a=fmtp:18 annexb=no<br>a=ptime:20<br>a=sendrecv<br>a=rtpmap:101 telephone-event/8000<br>a=fmtp:101 0–15</em></pre><p>Outgoing INVITE SDP:</p><pre>m=audio 31094 RTP/AVP 8<br>a=rtpmap:8 PCMA/8000<br>a=sendrecv<br>a=rtcp:31095<br>a=ptime:20</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=241754a55894" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>