harp1814
harp1814

Reputation: 1658

Asterisk: How to implement outbound rate limiting (calls per second)

My VoIP provider has limited cps. When my Asterisk exceed the threshold, provider sends SIP 503 response and call goes through spare provider. How to make a call to wait for a while and then proceed? I guess there is should be some "locks counter". So a scheduler check this counter, pauses and awakes a call process. What is the preferable mechanism to do that? It seems a kind of AGI script that has as a parameter CallerID, which accesses the server. If the counter is exceeded, then the server pauses the call process through the ARI mechanism. Any hints, ideas are appreciated

Upvotes: 0

Views: 3455

Answers (2)

Kaii
Kaii

Reputation: 20550

Example:

[globals]
calls_per_sec=20

[OUTBOUND]
exten => _X.,1,NoOp(Rate Limited Calling)
 same => n,Set(GROUP()=${EPOCH})
 same => n,GotoIf($[${GROUP_COUNT(${EPOCH})}>${calls_per_sec}]?DELAY,${EXTEN},1)
 same => n,Dial(SIP/provider/${EXTEN})

[DELAY]
exten => _X.,1,NoOp(Half Second Delay)
 same => n,Wait(0.5)
 same => n,Goto(OUTBOUND,${EXTEN},1)

Taken from Asterisk Community Board

Upvotes: 1

arheops
arheops

Reputation: 15259

There are no any realible way do that for asterisk.

You can count in AGI script, external app or check GROUP_COUNT(${EPOCH}@control).

You can limit CPS naturally in kamailio using ratelimit module.

Upvotes: 0

Related Questions