<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Hello,</div>
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
I added this line to my code, in fact it's better to decrease the counter if I drop the call.</div>
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
But my problem is that the rl_check function never drop calls, I do not enter in the IF condition.</div>
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
For the algorithm, I'm actually just trying the module, I will probably not stay with RED.</div>
<div class="elementToProof">
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<table width="0" height="0" cellpadding="0" cellspacing="0" border="0" style="">
<tbody>
<tr>
<td>
<div id="x_LSI_marker" rel="LSI_marker" style="font-size:0px"> </div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>De :</b> Users <users-bounces@lists.opensips.org> de la part de Wadii ELMAJDI | Evenmedia <wadii@evenmedia.fr><br>
<b>Envoyé :</b> vendredi 27 octobre 2023 17:39<br>
<b>À :</b> OpenSIPS users mailling list <users@lists.opensips.org><br>
<b>Objet :</b> Re: [OpenSIPS-Users] Ratelimit usage</font>
<div> </div>
</div>
<style>
<!--
@font-face
        {font-family:Helvetica}
@font-face
        {font-family:"Cambria Math"}
@font-face
        {font-family:Calibri}
@font-face
        {font-family:Aptos}
p.x_MsoNormal, li.x_MsoNormal, div.x_MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif}
span.x_contentpasted6
        {}
span.x_EmailStyle20
        {font-family:"Calibri",sans-serif;
        color:windowtext}
.x_MsoChpDefault
        {font-size:10.0pt}
@page WordSection1
        {margin:70.85pt 70.85pt 70.85pt 70.85pt}
div.x_WordSection1
        {}
-->
</style>
<div lang="FR" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="x_WordSection1">
<p class="x_MsoNormal"><span lang="EN-US" style="">Hello Adrien<br>
<br>
Try : <br>
<br>
</span><span lang="EN-US" style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black">if (!rl_check("test1", 1, "RED"))                       
</span></p>
<p class="x_MsoNormal"><span lang="EN-US" style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black">{</span></p>
<p class="x_MsoNormal"><span lang="EN-US" style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black">   rl_dec_count("test1")</span></p>
<p class="x_MsoNormal"><span lang="EN-US" style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black">   send_reply(487, "Request Terminated: CPS limit exceeded");</span></p>
<p class="x_MsoNormal"><span lang="EN-US" style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black">   exit;</span></p>
<p class="x_MsoNormal"><span lang="EN-US" style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black">}</span><span lang="EN-US" style=""><br>
<br>
</span><span lang="EN-US" style="font-size:9.0pt; font-family:"Helvetica",sans-serif; color:black; background:white">* If you are using ratelimit to limit only successful traffic, you need to explicitely decrease the counter for the declined calls using the <em><span style="font-family:"Helvetica",sans-serif">rl_dec_count()</span></em> function<br>
also I’m not sure RED is the best algorithm for your usecase.</span><span lang="EN-US" style=""></span></p>
<p class="x_MsoNormal"><span lang="EN-US" style=""> </span></p>
<div>
<div style="border:none; border-top:solid #E1E1E1 1.0pt; padding:3.0pt 0cm 0cm 0cm">
<p class="x_MsoNormal"><b>De :</b> Users <users-bounces@lists.opensips.org> <b>De la part de</b> Adrien LACOMME<br>
<b>Envoyé :</b> vendredi 27 octobre 2023 17:06<br>
<b>À :</b> users@lists.opensips.org<br>
<b>Objet :</b> [OpenSIPS-Users] Ratelimit usage</p>
</div>
</div>
<p class="x_MsoNormal"> </p>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black">Hi,</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black">I'm trying to implement CPS limitation on OpenSIPS and I got some difficulties to understand how ratelimit module works.</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black">Here is the setup (I want to limit cps to 1) :</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black">if (!rl_check("test1", 1, "RED")) {</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black">      send_reply(487, "Request Terminated: CPS limit exceeded");</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black">}</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black">I tried to make few calls simultaneously but rl_check return is always FALSE.</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black">Here is the log I got :</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black">2023-10-27T16:52:19.792337 SBC /usr/sbin/opensips[137782]: DBG:ratelimit:w_rl_check: Pipe test1 counter:1 load:0 limit:1 should NOT be blocked (0x7fcae1504888)</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black">2023-10-27T16:52:19.804064 SBC /usr/sbin/opensips[137781]: DBG:ratelimit:w_rl_check: Pipe
<span style="background:white">test1</span> counter:2 load:0 limit:1 should NOT be blocked (0x7fcae1504888)</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black">2023-10-27T16:52:22.872991 SBC /usr/sbin/opensips[137782]: DBG:ratelimit:w_rl_check: Pipe
<span class="x_contentpasted6"><span style="background:white">test1</span></span> counter:3 load:0 limit:1 should NOT be blocked (0x7fcae1504888)</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black">2023-10-27T16:52:22.918123 SBC /usr/sbin/opensips[137781]: DBG:ratelimit:w_rl_check: Pipe
<span style="background:white">test1</span> counter:4 load:0 limit:1 should NOT be blocked (0x7fcae1504888)</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black">Shouldn't the module block calls when the counter goes to 2 ? Or is he checking the load value to block ? If yes, why the load value isn't incremented ?</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black">Regards,</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:"Aptos",sans-serif; color:black">Adrien LACOMME</span></p>
</div>
<div>
<div>
<table class="x_MsoNormalTable" border="0" cellspacing="0" cellpadding="0" width="0">
<tbody>
<tr>
<td style="padding:0cm 0cm 0cm 0cm">
<div id="x_x_LSI_marker">
<p class="x_MsoNormal"><span style="font-size:1.0pt"> </span></p>
</div>
</td>
</tr>
</tbody>
</table>
<p class="x_MsoNormal"> </p>
</div>
</div>
</div>
</div>
</body>
</html>