Round Robin Routing
Round-robin routing cases
Round-robin routing with fallback
Let's suppose we route all numbers starting with 031 through two main SIP providers and we have one H.323 provider as fallback.
We set in regexroute.conf an entry like this:
^031.*$=fork $(rotate,$idx031,| sip/sip:\email@example.com,| sip/sip:\firstname.lastname@example.org) | h323/1010\email@example.com;maxcall=20000
How it works
We defined a list of two SIP call targets inside a rotate function. We also use a global (persistent between calls) variable conveniently named $idx031 so we remember it only rotates calls to the 031 prefix. Any other global variable name could be used.
The H.323 fallback route is placed outside the rotate function so it's always called last. The maxcall parameter of the message applies to all outgoing calls. There is currently no way of setting separate parameters for each individual call.
The first call comes in - let's suppose for 0310123. The initial value of variable $idx031 is undefined so zero will be assumed. The following targets will be tried in sequence, each for 20 seconds (set by the maxcall parameter):
SIP: sip:firstname.lastname@example.org SIP: sip:email@example.com H.323: firstname.lastname@example.org
The first that answers will continue the call. If any of them fails the call will attempt the next target. A side effect of the rotate function is to update the value of the global $idx031 variable. Since we defined only two rotation targets the value will cycle between the values 0 and 1.
Now a call comes in for 0319876. Since the previous call has changed $idx031 to 1 the attempted targets will be:
SIP: sip:email@example.com SIP: sip:firstname.lastname@example.org H.323: email@example.com
Round-robin routing without fallback
If instead of rotate we use the index function we will get round-robin routing without fallback between the two SIP providers, only with H.323 fallback route. Suppose we route:
^031.*$=fork $(index,$idx031,| sip/sip:\firstname.lastname@example.org,| sip/sip:\email@example.com) | h323/1010\firstname.lastname@example.org;maxcall=20000
The same incoming calls will generate outgoing calls to:
SIP: sip:email@example.com H.323: firstname.lastname@example.org
SIP: sip:email@example.com H.323: firstname.lastname@example.org