Search code examples
asterisksipvoiprate-limiting

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


Solution

  • 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