Percentage routing across SiP trunks on asterisk

Is there anyone who can advise us on how to route traffic across 2 or more sip trunks based on the percentage of traffic.

For example sending 80% of traffic to SIP Trunk A, 20% to SIP trunk B.

We can not find any way of implementing this.

Use random numbers, or you could use global variables to maintaing total traffic counts for your SIP peers.

What are you talking about ? use random numbers ?

please do not reply with dumb comments like this.

These are just examples and the list could be longer with variable parameters… we would loike the solution to look something like this :

;exten => _71.,2,Dial 80% (SIP/02076462185@
;exten => _71.,2,Dial 20% (SIP/${EXTEN}@

There is no built in ability for it. You have to use fundamentals and building blocks that exist in Asterisk to write the functionality, such as the global variables that were mentioned to store traffic count information.

You could maybe make this work using the GROUP and GROUP_COUNT functions.

If Provider A allows you to have 10 channels then when GROUP_COUNT > 8 send calls to Provider B.

I do not think that the reply was dumb.

You need to do a little math and pick a suitable probability density function. Generate a random number (maybe something derived from a time stamp is good enough), feed the pdf and according to your thresholds you pick this or that line. At the level of the dialplan this is a simple function that tells you which line to call. One would probably write a little AGI routine for that, or implement it somewhere else and call curl. There are a couple of ways to implement this, but it’s always the same straightforward and solid idea.