{"id":1384,"date":"2019-11-06T18:53:00","date_gmt":"2019-11-06T13:53:00","guid":{"rendered":"http:\/\/alexeyka.zantsev.com\/?p=1384"},"modified":"2022-02-07T10:05:02","modified_gmt":"2022-02-07T05:05:02","slug":"inserting-asterisk-in-your-call-flow","status":"publish","type":"post","link":"https:\/\/alexeyka.zantsev.com\/?p=1384","title":{"rendered":"Inserting Asterisk in your call flow"},"content":{"rendered":"\n<p>Let&#8217;s imagine that we&#8217;ve upgraded our VoIP network which was formerly based on geographically distributed Asterisks.<\/p>\n\n\n\n<p>We configured OpenSIPS servers as registrars, connected them together in a full-sharing usrloc cluster and now we need to route calls between endpoints not directly, but through Asterisks &#8211; to handle our calls in a familiar way (CDR records, call recording via MixMonitor, some AGI scripts, etc).<\/p>\n\n\n\n<p>We have to create something like that:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><a href=\"https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2019\/11\/usrloc_full_sharing_cluster_with_asterisks.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2019\/11\/usrloc_full_sharing_cluster_with_asterisks.png\" alt=\"\" class=\"wp-image-1383\" width=\"510\" height=\"210\"\/><\/a><\/figure>\n\n\n\n<p>This is a code snippet of OpenSIPS with IP address 10.145.213.63:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\t# initial INVITE\n\tif(is_method(\"INVITE\") &amp;&amp; !has_totag())\n\t{\n\t\tt_on_failure(\"1\");\n\n\t\t# call from registered user ->\n                # forward to mediaserver for call recording, etc.\n\t\tif(is_registered(\"location\"))\n\t\t{\n\t\t\t$ru=\"sip:\" + $oU + \"@\" + \"10.145.213.63:5067\";\n\t\t\troute(relay);\n\t\t}\n\n\t\t# call from Asterisk? -> change domain part before doing lookup\n\t\tif($sp==\"5067\")\n\t\t{\n\t\t\t$rd=\"taxsee.com\";\n\t\t}\n\n\t\t$var(lookup_flags) = \"m\";\n\t\tif(cluster_check_addr(\"1\", \"$si\")) {\n\t\t\txlog(\"si: $si . $rm from cluster, doing local lookup only\\n\");\n\t\t} else {\n\t\t\txlog(\"si: $si . $rm from outside, doing global lookup\\n\");\n\t\t\t$var(lookup_flags) = $var(lookup_flags) + \"g\";\n\t\t}\n\n\t\tif(!lookup(\"location\", \"$var(lookup_flags)\"))\n\t\t{\n\t\t\tt_reply(\"404\", \"Not Found\");\n\t\t\texit;\n\t\t}\n\n\t\tif(has_body(\"application\/sdp\"))\n\t\t{\n\t\t\trtpengine_offer(\"RTP\/AVP replace-origin replace-session-connection ICE=remove\");\n\t\t}\n\n\t} # initial INVITE end\n\n\troute(relay);\n<\/code><\/pre>\n\n\n\n<p>A SIP peer to this OpenSIPS in Asterisk sip.conf looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n&#91;opensips]\ntype=peer\ncontext=office\nhost=10.145.213.63\nport=5060<\/code><\/pre>\n\n\n\n<p>And a dialplan for CDR\/MixMonitor\/etc:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>context office\n{\n\t_XXX =&gt;\n\t{\n\t\tNoOp(imagine this is CDR, MixMonitor, AGI);\n\t\tDial(SIP\/opensips\/${EXTEN});\n\t\tHangup();\n\t};\n};<\/code><\/pre>\n\n\n\n<p>UPD: assuming your SIP acoounts DB has moved from Asterisk to OpenSIPS cluster, its desirable not just processing REGISTER requests and doing authentication, but also <a href=\"https:\/\/alexeyka.zantsev.com\/?p=1406\" target=\"_blank\" rel=\"noreferrer noopener\">adding caller ids<\/a> to your SIP accounts.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s imagine that we&#8217;ve upgraded our VoIP network which was formerly based on geographically distributed Asterisks. We configured OpenSIPS servers as registrars, connected them together in a full-sharing usrloc cluster and now we need to route calls between endpoints not directly, but through Asterisks &#8211; to handle our calls in a familiar way (CDR records, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[208],"class_list":["post-1384","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-opensips"],"_links":{"self":[{"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/posts\/1384","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1384"}],"version-history":[{"count":13,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/posts\/1384\/revisions"}],"predecessor-version":[{"id":12180,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/posts\/1384\/revisions\/12180"}],"wp:attachment":[{"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1384"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1384"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}