Using the Module - POSSA/freepbx-trunk-balancing GitHub Wiki
Last edited August 1, 2013 by lgaetz for version 1.1.1. If following this guide for another version, expect very minor differences.
Usage
Trunk description: the name of the 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 disable this rule, choose 'none selected'
Matching rules: This is the matching request that will be send to the CDR 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. Separate multiple rules by a comma.
Apply all matching rules: If multiple matching rules are defined, by default limits are calculated if any single rule matches. Enable this setting if all rules must be satisfied for a match.
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. Separate multiple rules by a comma.
Apply all non-matching rules: If multiple not matching rules are defined, by default limits are calculated if any single rule matches. Enable this setting if all rules must be satisfied for a match.
Billing Cycle: Choose the frequency with which the billing cycle resets. Traditionally, the phone billing cycle would be monthly, that is that usage resets monthly on a specific date and time. There is also support for weekly, daily and floating cycles.
Billing Time: Time of day that the billing cycle resets in 24 hour format separated by colons (i.e. 13:30:00 for 1:30pm). Leave blank for midnight. This value is used for all non-floating billing cycles.
Billing Day: This is the day of the week when the weekly billing cycle resets. This is only used for weekly billing cycles.
Billing Date: This is the day of the month when the monthly billing cycle is reset and is only used when monthly billing cycle is selected.
Floating Billing Time: This is the number of hours starting at the time of the outgoing call that is used to determine current usage. This is only used when the Floating cycle is selected. NOTE - Previous versions of this module labelled this field "Billing Period" and it expected user input in DAYS not HOURS, when upgrading from versions prior to 1.1.0, carefully check your trunk definitions to ensure this field is set properly.
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 (LR): If the LR is defined with an integer > 1, the module will randomly allow or deny the outbound call based only on the load ratio. There is no determination of previous trunk usage and it does not attempt to balance minutes or number of calls. If you want to randomly balance outbound calls equally over three (n) trunks, you must create 2 (n-1) balanced trunks, one with a load ratio of 3 (n) and one with a load ratio of 2 (n-1). When you define the outbound route, you will order trunks such that the balanced trunk with LR=3 is first, LR=2 is the second and an unbalanced, unrestricted trunk will be the third. The odds of the call being handled by the first trunk is 1/3, the odds of the second call is 1/3 (more precisely, half of the remaining 2/3) and the third trunk will receive 1/3 (or all of the remaining). To disable this rule enter 1.
Include Inbound Calls: By default, usage limits are determined by outgoing calls only. Select this option to include inbound calls.
Include Unanswered Calls: By default, usage limits are determined from answered calls only. Select this option to include unanswered calls.
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.
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:
balancedtrunk/ProviderA_freedays
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:
ProviderA (you don't need to use a balanced trunk here as there is no rules needed for Mars)
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:
balancedtrunk/ProviderB_bundle
ProviderC
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:
balancedtrunk/ProviderA_1800
balancedtrunk/ProviderB_1800
ProviderC
ProviderA (in case of ProviderC failing when it's its turn to handle the call).
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