<HTML>
<HEAD>
<TITLE>Re: [Freeswitch-users] Mod LCR SQL sub-query for better routing</TITLE>
</HEAD>
<BODY>
<FONT FACE="Monaco, Courier New"><SPAN STYLE='font-size:11pt'>You should never simply re-order just by rate... When you select the rate for the route you _must_<SPAN STYLE='font-size:14px'> select the longest prefix... You can just fall back to 1 since it matches 1876 also... This is not valid just for non-US areas in NANPA but for globally... Its not uncommon to see something like +44 @ 0.0095 (UK London Landline) then see something like +447938 @ 0.0150 (O2 Mobile) if you tried to route this off the cheapest prefix you would always be doing it wrong...<BR>
<BR>
And don’t even get started with ignoring things like LRN in the US with a ratedeck that has per NPA-NXX(-X) pricing while respecting LRN<BR>
<SPAN STYLE='font-size:11pt'><BR>
<BR>
On 12/16/13 5:36 PM, "DP ." <<a href="hi-tecc@hotmail.com">hi-tecc@hotmail.com</a>> wrote:<BR>
<BR>
</SPAN></SPAN></SPAN></FONT><BLOCKQUOTE><SPAN STYLE='font-size:11pt'><SPAN STYLE='font-size:14px'><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12pt'>I agree. This definitely sounds like he simply needed the "reorder_by_rate" param. It will reorder the initial sql results strictly by rate: <BR>
<BR>
</SPAN></FONT></SPAN></SPAN><UL><LI><SPAN STYLE='font-size:11pt'><SPAN STYLE='font-size:14px'><FONT FACE="Calibri, Verdana, Helvetica, Arial"><FONT SIZE="2"><SPAN STYLE='font-size:10pt'>reorder_by_rate - Forces the LCR module to re-order the query strictly on rate basis. By default this is turned off, but enabling this will always prefer rate over anything else.<BR>
</SPAN></FONT></FONT></SPAN></SPAN></UL><SPAN STYLE='font-size:11pt'><SPAN STYLE='font-size:14px'><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12pt'><BR>
Beware this may have an adverse effect! I initially had this turned on then quickly realized it would sometimes try to route ALL calls by the lowest rate found. <BR>
<BR>
Ex: flowroute lists all calls for the US with a default NPA of "1" at .0098. Now a user trying to call Jamaica with "1876" at a rate of 0.19 (or whatever) will get both flowroute rates returned. The reorder by rate will assume 0.0098 is a valid rate since it will now be the "cheapest" in the list and send the call along its way to flowroute, whom will now bill you at 0.19. Now if you have another carrier in your list with 1876 at 0.15 you can see why this would be a problem.<BR>
<BR>
In this case you will always want the longest matched NPANXX rate. <BR>
<BR>
<HR ALIGN=CENTER SIZE="3" WIDTH="100%">Date: Fri, 13 Dec 2013 15:58:54 -0500<BR>
From: <a href="intralanman@freeswitch.org">intralanman@freeswitch.org</a><BR>
To: <a href="freeswitch-users@lists.freeswitch.org">freeswitch-users@lists.freeswitch.org</a><BR>
Subject: Re: [Freeswitch-users] Mod LCR SQL sub-query for better routing<BR>
<BR>
<BR>
On 12/12/2013 02:42 PM, Victor Chukalovskiy wrote:<BR>
<BR>
<BR>
</SPAN></FONT></SPAN></SPAN><BLOCKQUOTE><SPAN STYLE='font-size:11pt'><SPAN STYLE='font-size:14px'><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12pt'> <BR>
Hello,<BR>
<BR>
For those interested, I added a piece to mod lcr wiki. It makes sorting <BR>
/ routing logic better than default logic:<BR>
<BR>
<a href="http://wiki.freeswitch.org/wiki/Mod_lcr#Custom_SQL_with_sub-query_-_for_real-life_ratesheet_complexities">http://wiki.freeswitch.org/wiki/Mod_lcr#Custom_SQL_with_sub-query_-_for_real-life_ratesheet_complexities</a><BR>
<BR>
Why it helps:<BR>
<BR>
Rates rates can often be given both on per-NPA or per-NPANXX level <BR>
depending on the carrier and on the NPA. Moreover, some carriers may <BR>
have NPANXX rate lower than the corresponding NPA rate, while others <BR>
will have it inverse. Neither simple ORDER BY rate, prefix; nor ORDER BY <BR>
prefix, rate; give the truly cheapest route. The LCR logic should be <BR>
two-step process to accommodate this.<BR>
<BR>
Cheers,<BR>
-Victor<BR>
<BR>
</SPAN></FONT></SPAN></SPAN></BLOCKQUOTE><SPAN STYLE='font-size:11pt'><SPAN STYLE='font-size:14px'><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12pt'> Unless I misunderstand what you're saying, this is what the reorder_by_rate param does.<BR>
<BR>
You'll always want to pick the longest digit match per carrier. Then you probably want to grab the cheapest overall rate of the matches you got back.<BR>
<BR>
-Ray<BR>
<BR>
<BR>
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: <a href="consulting@freeswitch.org">consulting@freeswitch.org</a> <a href="http://www.freeswitchsolutions.com">http://www.freeswitchsolutions.com</a> FreeSWITCH-powered IP PBX: The CudaTel Communication Server <a href="http://www.cudatel.com">http://www.cudatel.com</a> Official FreeSWITCH Sites <a href="http://www.freeswitch.org">http://www.freeswitch.org</a> <a href="http://wiki.freeswitch.org">http://wiki.freeswitch.org</a> <a href="http://www.cluecon.com">http://www.cluecon.com</a> FreeSWITCH-users mailing list <a href="FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a> <a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a> UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users">http://lists.freeswitch.org/mailman/options/freeswitch-users</a> <a href="http://www.freeswitch.org">http://www.freeswitch.org</a><BR>
<BR>
<BR>
<HR ALIGN=CENTER SIZE="3" WIDTH="95%"></SPAN></FONT><FONT SIZE="2"><FONT FACE="Consolas, Courier New, Courier"><SPAN STYLE='font-size:10pt'>_________________________________________________________________________<BR>
Professional FreeSWITCH Consulting Services:<BR>
<a href="consulting@freeswitch.org">consulting@freeswitch.org</a><BR>
<a href="http://www.freeswitchsolutions.com">http://www.freeswitchsolutions.com</a><BR>
<BR>
FreeSWITCH-powered IP PBX: The CudaTel Communication Server<BR>
<a href="http://www.cudatel.com">http://www.cudatel.com</a><BR>
<BR>
Official FreeSWITCH Sites<BR>
<a href="http://www.freeswitch.org">http://www.freeswitch.org</a><BR>
<a href="http://wiki.freeswitch.org">http://wiki.freeswitch.org</a><BR>
<a href="http://www.cluecon.com">http://www.cluecon.com</a><BR>
<BR>
FreeSWITCH-users mailing list<BR>
<a href="FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><BR>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><BR>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><BR>
<a href="http://www.freeswitch.org">http://www.freeswitch.org</a><BR>
</SPAN></FONT></FONT></SPAN></SPAN></BLOCKQUOTE><SPAN STYLE='font-size:11pt'><SPAN STYLE='font-size:14px'><FONT SIZE="2"><FONT FACE="Consolas, Courier New, Courier"><SPAN STYLE='font-size:10pt'><BR>
</SPAN></FONT></FONT><FONT FACE="Monaco, Courier New"><SPAN STYLE='font-size:11pt'>-- <BR>
Ken<BR>
<FONT COLOR="#0000FF"><U><a href="http://www.FreeSWITCH.org">http://www.FreeSWITCH.org</a><BR>
<a href="http://www.ClueCon.com">http://www.ClueCon.com</a><BR>
<a href="http://www.OSTAG.org">http://www.OSTAG.org</a><BR>
</U></FONT>irc.freenode.net #freeswitch<BR>
Twitter: @FreeSWITCH<BR>
<BR>
</SPAN></FONT>
</BODY>
</HTML>