[Spce-user] Limit CPS per peer gw

Jon Bonilla (Manwe) manwe at sipdoc.net
Mon Aug 8 17:07:28 EDT 2022


Hi all

Recently a customer of mine (Questblue Inc) asked me a way of limiting CAPS
to their peer gateways. So I created a custom preference and a patch for them.

Here's de howto:

- Create a peer preference custom_caps to set the maximum number of INVITE
request per second a peer gateway could allow (attached
custompreferences_caps.sql)

- Send the preference to the lb in proxy.cfg:

if(pv_isset("$xavp(callee_peer_prefs[0]=>custom_caps)")) {
  $(x_hdr(P-QB-CAPS)[*]) = $xavp(callee_peer_prefs[0]=>custom_caps);
}

- whitelist the header in sems sbcprofile (trivial)

- Add a new htable entry in lb (I also added separate timer processes for high
  load):

modparam("htable", "htable", "caps=>size=11;initval=0;autoexpire=5;")
modparam("htable", "timer_interval", 10)
modparam("htable", "timer_procs", 4)


- Set the logic in the kamailio lb to check for caps:

if(is_present_hf("P-QB-CAPS")) {
  $var(cps) = $rd + ":" + $timef(%S);
  $var(cps) = $shtinc(caps=>$var(cps));
  $var(capslimit) = $hdr(P-QB-CAPS);
  if ($var(cps) > $var(capslimit)) {
     sl_send_reply("503", "CAPS limit reached for this destination $rd");
     exit;
  }
}


I'm using $rd because my customer doesn't use "hostname" in the gw definition
but it could be changed for destination IP based on P-D-URI or similar.

This setup has been running in Questblue's sip:carrier like spce cluster with
more than 1500CAPS of traffic without issues.

Questblue agrees on upstreaming this patch if Sipwise is interested on it. I
think it can be a useful feature.


cheers,

Jon


-- 
PekePBX, the multitenant PBX solution
https://pekepbx.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: custompreferences_caps.sql
Type: application/sql
Size: 477 bytes
Desc: not available
URL: <http://lists.sipwise.com/pipermail/spce-user_lists.sipwise.com/attachments/20220808/4b39f6a6/attachment.sql>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: Firma digital OpenPGP
URL: <http://lists.sipwise.com/pipermail/spce-user_lists.sipwise.com/attachments/20220808/4b39f6a6/attachment.sig>


More information about the Spce-user mailing list