User Manual

Install

Same as for any other FreePBX module.
Need a FreePBX version 2.6 or above.

Uninstall

Same as for any other Freepbx module.
You will however want to check your outbound routes that were using a balanced trunk as these routes may then not route anywhere anymore.

The Module

Trunk description: the name of the balanced trunk.

General settings applied on all the rules for this balanced trunk
Trunk Destination: Select the real trunk that will be used if the rules passed.

Time Group: Select one of the FreePBX time group to add a time related condition. To ignore this rule, select 'none selected'

Matching rules: This is the matching request that will be send to the crd MySQL database. It has nothing to do with the actual number you have dialed. It should be entered in as a MySQL LIKE format. For instance if you want to match in the database all the international calls and you are dialing 011 for these calls, your matching rule will be '011%'. The % means any number of characters, the _ means one character only.
To disable clear the entry.
Note: at this time, only one matching rule can be entered in this box. Future version may allow to enter more than one rule.

Not Matching rules: This is to exclude some numbers from the MySQL query in the database. It does use the same syntax than the Matching rules. For instance if you want to exclude local calls from the count and your local area code is 321 you will enter '321%'.
To disable, clear the entry.
Note: at this time, only one not matching rule can be entered in this box. Future version may allow to enter more than one rule.

Billing Day: this is the day of the month when your counter reset. To disable enter 0, then your cdr will be evaluated from the beginning.

Billing Period: if you want to use a number of floating days to reset the counter instead of doing it monthly. For instance if you want to limit the number of calls within the last 7 days you will enter 7 in this field. When using this field, you need to set Billing Day to 0.

Rules:
Ending Date: The date when this balanced trunk will expire. Enter the date with the YYYY-MM-DD [HH:mm optional] format. The time is based on the server clock. Useful for providers giving you freedays or free trial days. To disable enter 0.

Load ratio: To balance the load between different trunks. Enter an integer above 1. If you want to balance equally three trunks then you will have in your outbound route the first balanced trunk with a ratio of 3, the second balanced trunk with a ratio of 2 and the third trunk. Each of them will then have 1 chance out of three to pass the call. To disable this rule enter 1.

Maximum time: The maximum numbers of outbound answered minutes that you are allowing through this balanced trunk. Be aware that the decision to let the call proceed is made before the call, and this module will not break a call even if it lasts 10 hours and exceed your rule. You maybe want to put a limit a few minutes lower than your maximum allowed. Enter 0 to disable.

Maximum number of calls: The maximum numbers of outbound answered call allowed on this balanced trunk. Enter 0 to disable.

Max. Different Calls: The maximum numbers of different outbound answered dialed numbers allowed on this balanced trunk. Enter 0 to disable. Useful for some provider that are not counting the number of calls, but the number of different calls during a billing period.

note: Each rule can be independently enabled or disabled. To let a call go through ALL the enabled rules need to pass.

Outbound routes

When you have created your 'balanced trunk' you need to select them in your outbound routes. Go in the Outbound Route tab and select the proper balancedtrunk/ in the order you want.

Examples

Freedays

Provider A is a provider you've chosen because it provides you with the best rate for calls to Mars. As a bonus, every time you resupply your account they are giving you 60 freedays of call to the Moon.

Create the following balanced trunk:
Description: ProviderA_freedays
Trunk Destination: ProviderA
Ending Date: enter the date when your freedays expire (ie 60 days from your last refill).

Create the following outbound route:
Route Name: To the Moon
Dial Pattern: the proper dial code for the Moon
Trunk Sequence:
  1. balancedtrunk/ProviderA_freedays
  2. the other more expensive trunks in the order you may want to use for the Moon. That can include also the regular trunk Provider A if you still want to keep it as backup even when it's not free anymore.
Route Name: To Mars
Dial Pattern: the proper dial code for Mars
Trunk Sequence:
  1. ProviderA (you don't need to use a balanced trunk here as there is no rules needed for Mars)
  2. the other more expensive trunk you may want to use for Mars

Bundle

Provider B had a bundle including 500 local/national free minutes per month. However the additional minutes are more expensive than through your provider C. You want to use your 500 minutes first before going to provider C.

Create the following balanced trunk:
Description: ProviderB_bundle
Trunk Destination: ProviderB
Not Matching Rule: 011% (to count only the national/local calls and not the international ones)
Billing Day: the day of the month when your provider reset his counter.
Maximum time: 500 (or a few minutes less if you want to keep some safety margin)

Create the following outbound route:
Route Name: Local/National
Dial pattern: the proper dial pattern for your local/national calls (for instance: 1NXXNXXXXXX, NXXNXXXXX)
Trunk Sequence:
  1. balancedtrunk/ProviderB_bundle
  2. ProviderC
  3. ProviderB (in case you have used all your bundle minutes, but C is unavailable for any reason, you still want to use B to make the call even if it's more expensive).

Load balancing

Your providers A, B and C are giving you free calls to 1800 numbers, but they are stating that it cost them some to do it and you should not abuse it.
You want to balance equally the 1800 calls between these three providers.

Create the following balanced trunks:
Description: ProviderA_1800
Trunk Destination: ProviderA
Load Ratio:3

Description: ProviderB_1800
Trunk Destination: ProviderB
Load Ratio:2

Create the following outbound route:
Route Name: 1800
Dial pattern: 1800XXXXXXX
Trunk Sequence:
  1. balancedtrunk/ProviderA_1800
  2. balancedtrunk/ProviderB_1800
  3. ProviderC
  4. ProviderA (in case of ProviderC failing when it's its turn to handle the call).
  5. ProviderB (in case of ProviderC and A failing when it's C turn to handle the call).

Free night and week-end

Your provider A is cheaper than provider B. However provider B is free during night and week-end.

Create a new time group:
Create a new FreePBX time group with the following settings:
Description: Night and week-end
1st time:
Time to start: 19:00
Time to finish: 7:00
2nd time:
Week Day Start: Sat
Week Day finish: Sun

Create the following balanced trunks:
Description: ProviderB_Night_WeekEnd
Trunk Destination: ProviderB
Time group: Night and week-end

Modify you outbound route:
Your outbound route should then be modified as follow:
Trunk Sequence:
balancedtrunk/ProviderB_Night_WeekEnd
ProviderA
ProviderB

Limitations:

At this time:
- Dundi and Enum trunk cannot be balanced.
- The cdrb can not be queried for calls send through zap trunk (the cdrb does not use the zap trunk name as channel name). Only Timegroup, Load ratio and expiration date rules will work with zap trunk. Any rule based on the cdr query on the zap trunk will not return a valid result.

Also available in: HTML TXT