Round robin on outbound trunks

Is there a way i can distribute outbound calls on my outbound trunks?

at the moment i have 4 outbound voip trunks which include free local, national and usa calls, the itsp i use has a fair usage policy which i sometimes exceed on the first outbound trunk line. i would like the ability evenly distribute the calls between the outbound calls.

Last week for instance we made 3000 calls out of which 2500 went out on the first trunk, 450 went out on the second trunk and 50 went out on the third trunk. None went out at all over our fourth trunk. If I could round robin the outbound trunks then 750 calls would have gone out over each trunk.

Thanks in advance

Thanks for the prompt reply Bubba, I will download and play. I will post back to let you know how I get on.

Well it is not a Round Robin but the custom context module
will allow you to break up the time the trunks are used.

The module is a NON-supported module and the functions of it will be
included in FPBX by version 3 along with some better tools to manage
the trunks.

but the module works great…
as the aussie site is down…
cd /usr/src
cd /var/www/html/admin/modules/
tar -zxvf /usr/src/customcontexts.tgz


click on the cache pages and then the text version

Possible Uses

Restrict access to certain outbound routes or feature codes by a particular extension or group of extensions.
Give particular extension(s) priority access to certain outbound routes, such as a particular emergency route associated with their geographic location.
Give certain outbound routes top priority for use during “free” or low cost calling periods, while making those same routes lower priority (or disallowing access entirely) during higher cost time periods.
Disallow access to outbound routes (with possible exception of Emergency access) to certain (or all) extensions during particular time periods (don’t let night cleaning crew make long distance calls, or disallow outgoing night calls from telephones in children’s rooms, while still allowing emergency number calls).
Allow two or more families/companies/organizations to use the same FreePBX box, while still allowing each to have access only to “their” outgoing routes and trunks.
If you have a SIP provider that does not send DID (normally a pain to handle because you can’t create a normal Inbound Route), set up a new custom context (call it idiot-provider), give them no access to anything (deny all), and then specify where you want their calls to go in the Failover Destination. Then put context=idiot-provider in that provider’s trunk user details.

This help me to make the round-robin on trunks of outbound route.

We can add into /admin/modules/core/ instead (lines from line 1802 )

foreach ($trunks as $trunk_id) {
if (isset($trunk_table[$trunk_id])) switch(strtolower($trunk_table[$trunk_id][‘tech’])) {
case ‘dundi’:
$trunk_macro = ‘dialout-dundi’;
case ‘enum’:
$trunk_macro = ‘dialout-enum’;
$trunk_macro = ‘dialout-trunk’;
$ext->add($context, $exten, ‘’, new ext_macro($trunk_macro,$trunk_id.’,’.$pattern[‘prepend_digits’].’${EXTEN’.$offset.’},’.$password));
$password = ‘’;


following lines:

      $nl = 1; 
      $dbrt = $route['name'].'/trunk'; //DB family key the number of current trunk of  outboud route trunks
      $cnt_trunks = count($trunks); 
      $ext->add($context, $exten, '', new ext_gotoif('$[${DB_EXISTS('.$dbrt.')} = 1]','dbexist')); 
      $ext->add($context, $exten, '', new ext_setvar('DB('.$dbrt.')',1));
      $ext->add($context, $exten, 'dbexist', new ext_noop('DB '.$dbrt.' has value: ${DB('.$dbrt.')}'));
      $ext->add($context, $exten, 'dbexist', new ext_gotoif('$[${DB('.$dbrt.')} != 0]','dbok'));
      $ext->add($context, $exten, '', new ext_setvar('DB('.$dbrt.')',1));
      $ext->add($context, $exten, 'dbok', new ext_noop('DB '.$dbrt.' has value: ${DB('.$dbrt.')}'));
      $ext->add($context, $exten, 'dbok', new ext_gotoif('$[${DB('.$dbrt.')} <= '.$cnt_trunks.']','dbok1'));
      $ext->add($context, $exten, '', new ext_setvar('DB('.$dbrt.')',1));
      $ext->add($context, $exten, 'dbok1', new ext_noop('DB '.$dbrt.' has value: ${DB('.$dbrt.')}'));
      foreach ($trunks as $trunk_id) {
            $ext->add($context, $exten, '', new ext_gotoif('$[${DB('.$dbrt.')} = '.$nl.']', 'tr'.$nl));
      foreach ($trunks as $trunk_id) {
        if (isset($trunk_table[$trunk_id])) switch(strtolower($trunk_table[$trunk_id]['tech'])) {
        case 'dundi':
          $trunk_macro = 'dialout-dundi';
        case 'enum':
          $trunk_macro = 'dialout-enum';
          $trunk_macro = 'dialout-trunk';
      $ext->add($context, $exten, 'tr'.$nl, new ext_setvar('DB('.$dbrt.')','$[${DB('.$dbrt.')}+1]'));
      $ext->add($context, $exten, '', new ext_macro($trunk_macro,$trunk_id.','.$pattern['prepend_digits'].'${EXTEN'.$offset.'},'.$password));  
      $nl = $nl + 1;
      $password = '';

and we get the following lines in the extensions_additional.conf

[outrt-7] ; Mobile
include => outrt-7-custom
exten => _039XXXXXXX,1,Macro(user-callerid,SKIPTTL,)
exten => _039XXXXXXX,n,Noop(Calling Out Route: Mobile)
exten => _039XXXXXXX,n,Set(MOHCLASS=${IF($["${MOHCLASS}"=""]?default:${MOHCLASS})})
exten => _039XXXXXXX,n,Set(_NODEST=)
exten => _039XXXXXXX,n,Macro(record-enable,${AMPUSER},OUT,)
exten => _039XXXXXXX,n,GotoIf($[${DB_EXISTS(Mobile/trunk)} = 1]?dbexist)
exten => _039XXXXXXX,n,Set(DB(Mobile/trunk)=1)
exten => _039XXXXXXX,n(dbexist),GotoIf($[${DB(Mobile/trunk)} != 0]?dbok)
exten => _039XXXXXXX,n,Set(DB(Mobile/trunk)=1)
exten => _039XXXXXXX,n(dbok),GotoIf($[${DB(Mobile/trunk)} <= 2]?dbok1)
exten => _039XXXXXXX,n,Set(DB(Mobile/trunk)=1)
exten => _039XXXXXXX,n(dbok1),Noop(DB Mobile/trunk info - Next Trunk is: ${DB(Mobile/trunk)})
exten => _039XXXXXXX,n,GotoIf($[${DB(Mobile/trunk)} = 1]?tr1)
exten => _039XXXXXXX,n,GotoIf($[${DB(Mobile/trunk)} = 2]?tr2)
exten => _039XXXXXXX,n(tr1),Set(DB(Mobile/trunk)=$[${DB(Mobile/trunk)}+1])
exten => _039XXXXXXX,n,Macro(dialout-trunk,8,${EXTEN},)
exten => _039XXXXXXX,n(tr2),Set(DB(Mobile/trunk)=$[${DB(Mobile/trunk)}+1])
exten => _039XXXXXXX,n,Macro(dialout-trunk,9,${EXTEN},)
exten => _039XXXXXXX,n,Macro(outisbusy,)

And then we can add checkbox on the page.routing.php and set variable that stored in the mysql.
And control round-robin trunks of outbound route.

While the method above may work (I haven’t tried it), it will not survive a FreePBX upgrade and would not be recommended.

The third party FreePBX module, Trunk Balancing can be used to evenly distribute outbound calls as well as other features.