How you route every N call to different carrier

Dear Asterisk community,
I’m very confused on making an extension in asterisk.
So the scenario is:

I want to route every 5 call to the extension to go to differnent peer. It is for load balancing purposes.
Ex: From 10 calls made to extension 1215 - 8 calls go to prov1 and 2 calls to go to provide prov2

I need your help in doing that.

Thank you.

Use a global variable as a counter and ExecIf or GotoIf, for the conditional logic.

Race conditions may mean that sometimes you don’t get exactly the right sequence of carrrier selections, but I don’t see that that is critical here.

Hello,
I’ve tested some things, but still I’m confused. Can you write some example ?

Thank you.

Should look into something like Kamailio (recommended) or OpenSIPs (not much experience). They are both derivatives of the OpenSER (Open Sip Express Router) project.

When you want to get into complex SIP routing, failover, load balancing, etc… it is by far the best solution. You can, of course, “shoe-horn” asterisk into doing the work, but it anytime you need to work hacks into your dial plan, there is probably a better solution.

SRV records may also be a good solution.