randomizing outbound gateway or other method for calls distribution

alexmed

New Member
Jan 17, 2019
3
4
3
51
hello all!

i wanted to ask for advice on the topic, below a bit more formal description

case: have gsm-gateway box wtih several GSM-channels having sim-cards inserted. All cards are from same carrier. Each GSM-channel connected to fusionpbx as a gateway (separate SIP-credentials login as per SIM from provider). I want to avoid overusing first simcard in the pool but blend calls over few gateways (sims) automatically by certain method.

goal: find settings to use in "Outbound route" configuration (regex already covers all carrier prefixes) or other method

background: what i found on the net
- use gateway name generated with constructions like ${expr(randomize(&x);floor(random(1,2,&x)))}
but no luck as Fusion reFuse to find gateway by generated name (as i can see in logs) but instead accets only id like sofia/gateway/59b64fb2-9842-48d5-a7df-48389dbf05aa/$1
- use mod_distributor (somewhere on this forum probably) i.e. using https://freeswitch.org/confluence/display/FREESWITCH/mod_distributor
found and activated in FusionPBX GUI (modules) but sincerely have no idea how to make it working it further via Fusion

ideas: use smth like Kamalio or OpenSIPs for exposing bunch of gateways as a single gateway (via load balancing) to FusionPBX, but sound like too much effort for a simple task, also its better if i can still see which GW was chosen for each call in FusionPBX CDR as well as user can see it as well.


it feels like there should be something simple to put into Outbound route settings to randomize Gateways choise or setup mod_distributor but how...


Cheers! Alex
 
Last edited:

DigitalDaz

Administrator
Staff member
Sep 29, 2016
2,542
421
83
It looks like it would be straightforward with mod distributor. Just pay someone to do it who knows freeswitch/fusionpbx better is the easiest way.

Maybe contact fusionpbx official support?
 

alexmed

New Member
Jan 17, 2019
3
4
3
51
thanks for pointing me to the direction ( i mean mod_distributor)

i made one more effort to it and its working great
in fact its far from rocket science but if someone interested here is the approach for choosing gateways (based on freeswitch DOC link above):

1. make sure mod_distributor in FusionPBX modules is enabled
2. changing the mod_distributor config xml:
- in fpbx top menu Advanced/XML Editor
- on left panel choose autoload_configs/distributor.conf.xml
- on the right the example will be like
...
<list name="test" total-weight="10">
<node name="foo1" weight="1"/>
<node name="foo2" weight="9"/>
</list>
...
all we need is to add own <list....> (or change current one) and type in nodes the gateways, here im adding list "my_list_001", giving total weight of 2 and nodes weight 1 each, so they will be engaged 50/50

...
<list name="test" total-weight="10">
<node name="foo1" weight="1"/>
<node name="foo2" weight="9"/>
</list>
<list name="my_list_001" total-weight="2">
<node name="my_gateway_01" weight="1"/>
<node name="my_gateway_02" weight="1"/>
</list>
...

BUT if we going to use mod_distributor to generate gateways for Outbound routes we need to use names Not like my_gateway_01 (at least i didnt found how to adopt them) and the dialplan will throw errors (can see them in Status/Log Viewer menu), we need to use Gateways ID's (long digits with dashes like 2a8d448d-e06e-3dab-b6f9-5421a98e4d8e), so we need to make 1 more step to prepare data for config

2a. Getting gateways IDs
There probably easy way to do it but this is one i found: go to menu Dialplan/Outbound routes and create new Route (just click + and pretend you creating it). First line of form is Gateway so go through list and choose gateway. you will immediately see line like "2a8d448d-e06e-3dab-b6f9-5421a98e4d8e:may_gateway_001", copy this line to Notepad or some storage, now repeat for all gateways you want to distribute calls to (click button with triangle at the end of field to get plain list again and choose again)

2b. After collecting all gateway ID's just click Back - we dont need to create anything here

so now you have a list of IDs like
2a8d448d-e06e-3dab-b6f9-5421a98e4d8e:my_gateway_001
1a8d448d-e06e-2dab-b6f9-4421a98e4d8e:my_gateway_002
etc.

3. Getting back to mod_distributor config xml and filling data like this

<list name="my_list_001" total-weight="2">
<node name="2a8d448d-e06e-3dab-b6f9-5421a98e4d8e" weight="1"/> <!-- my_gateway_001 - its just comment with actual GW name -->
<node name="1a8d448d-e06e-2dab-b6f9-4421a98e4d8e" weight="1"/> <!-- my_gateway_002 -->
</list>

So as you can see - in config we use only long-dashed IDs but not names.

4. Save !

5. go to Fpbx menu Advanced/Command and input few commands to get fresh settings inside FS (not sure if need both commands but i do both)
having Switch CLI chosen type:

reloadxml

click Execute button, you should get Ok responce
then type:

distributor_ctl reload

click Execute button, you should get Ok responce


6. in Outbound route setting, bridge line you have now smth like:
action bridge sofia/gateway/some_gateway_name/$1

need to change to
sofia/gateway/${distributor(my_list_001)}/$1

so each time its coming to this line - distributor is queried for the item from the list "my_list_001"


P.S.
in fact the mod_distributor its just generator, so you don't need to stick with Gateways only, but its ok with anything you can put into lists and need to get in the random/weighted manner, like special prefixes etc.
 

itia

New Member
May 29, 2020
22
2
3
USA
@alexmed You are a rock star! Thanks for sharing this.

A few things have been updated in FusionPBX since your post, so here are a few notes to help others:

Doesn't seem to be an Advanced / XML Editor any more:
SSH into each node of your cluster and edit the file directly
$ sudo nano /etc/freeswitch/autoload_configs/distributor.conf.xml

Also seems to be no Advanced / Commands any more:
FusionPBX GUI / Advanced / Modules to stop and start the module.
You could also SSH into each node:
$ fs_cli
$ distributor_ctl reload
$ /quit

One gotcha I noticed on the Outbound Routes was that my existing outbound route bridge line ended with "/1$1". This caused trouble for Skyetel but not Flowroute. Yet if I changed this to "/$1" it worked fine for both of them.