<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Aptos;
panose-1:2 11 0 4 2 2 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:10.0pt;
font-family:"Aptos",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Aptos",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt">The drouting module supports the concept of groups for rules. The module can determine the group for the request automatically, or you can provide the group directly. You can determine the group based on the
source and then drouting will only use the rules for that group.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black">Ben Newlin</span><span style="font-size:11.0pt"><o:p></o:p></span></p>
</div>
</div>
</div>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<div id="mail-editor-reference-message-container">
<div>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;color:black">Users <users-bounces@lists.opensips.org> on behalf of Alexey <slackway2me@gmail.com><br>
<b>Date: </b>Monday, October 14, 2024 at 3:00</span><span style="font-size:12.0pt;font-family:"Arial",sans-serif;color:black"> </span><span style="font-size:12.0pt;color:black">PM<br>
<b>To: </b>users@lists.opensips.org <users@lists.opensips.org><br>
<b>Subject: </b>[OpenSIPS-Users] Dynamic Routing: dr_rules with the same prefix<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="font-size:11.0pt"> EXTERNAL EMAIL - Please use caution with links and attachments <br>
<br>
Hi list,<br>
<br>
the situation is that there are 2 VoIP providers which send us INVITEs<br>
with rU not in e164 format - just subscriber's phone number without country code<br>
and without city code.<br>
<br>
For example, a provider with the IP address 1.1.1.1 sends us 999999,<br>
and a provider with the IP address 2.2.2.2 sends us 999999.<br>
<br>
Our inner logic of incoming calls processing is based on the Drouting<br>
module [1].<br>
So we differentiate incoming calls by the username in the request-uri,<br>
and it means that the column 'prefix' of the 'dr_rules' table [2] is used.<br>
Then we fetch some useful (for us) extra data from the 'attrs' column<br>
of the same table.<br>
<br>
And this also means that there are 2 rules with the same 'prefix'.<br>
If the INVITE is from provider/gateway 1.1.1.1 , we have to fetch<br>
attrs of the first rule,<br>
if the INVITE is from provider/gateway 2.2.2.2 , we have to fetch<br>
attrs of the second rule.<br>
<br>
Everything is clear if the prefix is unique.<br>
But now I'm trying to understand what is the best way to fetch right attrs<br>
when prefixes are the same.<br>
<br>
The first idea is to use the 'routeid' parameter of the 'dr_rules' table -<br>
go to some extra route in the script in case of some certain prefix matched,<br>
'999999' in our case.<br>
And then to check the source address of the INVITE in that route<br>
and make some decision, depending on the $si:<br>
<br>
route[routedr] {<br>
xlog("L_INFO", "[$ci] . cfg_line: $cfg_line . route $route .<br>
call from specific gw $avp(dr_gw_id) with specific rU . src is<br>
$si:$sp");<br>
<br>
# reset the value first.<br>
$var(rule_attrs)=NULL;<br>
<br>
# we know gw's IP addresses, from which we receive calls with<br>
the same rU in INVITE.<br>
if( $si == "1.1.1.1" ) {<br>
$var(rule_attrs) = "Office-XXX 1333999999";<br>
} else {<br>
$var(rule_attrs) = "Office-YYY 1555999999";<br>
}<br>
xlog("L_INFO", "[$ci] . cfg_line: $cfg_line . route $route .<br>
call from gw $avp(dr_gw_id) . src is $si:$sp . var rule_attrs is<br>
$var(rule_attrs)");<br>
}<br>
<br>
<br>
But I'm not sure if this is the best way.<br>
Maybe there is some more elegant solution.<br>
<br>
[1] <a href="https://opensips.org/docs/modules/3.2.x/drouting.html">
https://url.us.m.mimecastprotect.com/s/PiZfCpYXzWfnYDKNLFPf1FGwR6u?domain=opensips.org</a><br>
[2] <a href="https://www.opensips.org/Documentation/Install-DBSchema-3-2#GEN-DB-DR-RULES">
https://url.us.m.mimecastprotect.com/s/BK9kCqxM2Wf8qWlPrCXh9FEhzO3?domain=opensips.org</a><br>
<br>
-- <br>
best regards, Alexey<br>
<a href="https://alexeyka.zantsev.com">https://alexeyka.zantsev.com</a><br>
<br>
_______________________________________________<br>
Users mailing list<br>
Users@lists.opensips.org<br>
<a href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a><o:p></o:p></span></p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>