4 trunks same vivavox ip

hi to all, I searched a lot without a solution so I hope that someone can help me cause this is for a production environment. I’m writing from italy and I’m a customer of the voip provider vivavox/ehiweb. With this provider I have 4 different accounts, every account is a geographical telephone number with a unique did. In my side I have the last updated freepbx inside a virtualized ha cluster, with this unique instance I want to pass the 4 dids to the groups that are placed in the four differents areas through vpn. My connectivity is good around 100/100Mb in each area. so I created 4 different trunks following the instructions of my provider and obviously all the inbund routes matching the did for each area. Everything works very good but in asterisk log everytime someone calls one of the 4 numbers, I see that is always using the first trunk in the list. This have some disvantages, for example I cannot limit the number of channels cause is using only the first trunk. Searching around I found that this is impossible to fix but the newest post is around 3 years old… maybe there is some workaround, I thinked that I can create a freepbx VM for each number but maybe is really a dirt solution. any suggestions?
many many thanks

Outbound calls should use the corresponding trunks, so there should be no problem limiting the number of concurrent outbound calls on each trunk (using the normal Maximum Channels setting). I assume that inbound calls are free and any channel limit would be imposed by the provider.

However, FreePBX does auto-generate a context for each trunk named e.g. from-trunk-pjsip-vivavox1. If you want to have a channel limit per trunk where inbound calls count against the maximum, set Context for your trunks to a custom context. Then, write some dial plan code that determines which trunk was called (I assume that vivavox puts the DID number or an account number in the SIP URI or the To header) and does a goto to the corresponding auto-generated context.

thank you for your response.
yes my provider gives me free and unlimited inbound outbound channels with DID number in sip uri and you are right for outbound routes there is no problem(howewer is not very important to me to limit outbund calls).
I’m not very good with custom context because is the first time that I need to configure them, usualy in the incoming trunk section I simply add context=from-trunk and everything works. I will try to understand how to apply your suggestions and past the results tomorrow. many many thanks

I searched a lot but I cannot really understand how to build the scenario you suggested. Maybe you can give me some tips, however I’m missing the reason why I cannot insert in the trunk parameters some sort of rule that matches the DID number before enabling the trunk itself.

I found this that maybe is a clean solution

http://www.dusek.eu/asterisk-freepbx-what-number-was-called-more-trunks-wrong-did/

but something is wrong cause is for an older version of freepbx and needs some edit, for example CDR function is deprecated

This is a known limitation of chan_sip trunks if you have multiple registered trunks to the same host. When the provider sends a call (a SIP INVITE) to your PBX, Asterisk looks at the source IP of the INVITE and matches it against the IPs of the registered configured trunks. If there are multiple matching IPs, it will just take the first one it sees.

There is a parameter in pjsip (the name of which I have completely forgotten) which addresses this issue, but IIRC it is not supported yet in FreePBX. Since I can’t recall the parameter, I can’t search for an open ticket, but I am pretty sure there is a feature request on this in our issue tracker.

edit - Remembered, it’s the pjsip line parameter, and its available now in ver. 14 only.
https://issues.freepbx.org/browse/FREEPBX-14812

thank you my friend, but even if you find this parameter my provider gives to me only sip_chan not pjsip

What exactly are you trying to do? I understand that depending on which of four DIDs is called, you want different behavior, beyond what is accomplished by Inbound Routes. But when you gave an example of limiting inbound channels per DID and we presented an outline for doing that, you said that your provider offered unlimited incoming channels and calls.

If you are trying to have the DIDs behave differently at the Asterisk level, for example to negotiate different codecs, as @lgaetz said, that’s not going to happen. But if you just need different behavior at the FreePBX level, for example different logging, announcements or other aspects of call handling, you can send the trunks to a custom context that checks which DID was called and jumps to dialplan (built-in or that you write) specific for that DID.

For example, you have trunk1 with DID 1111, trunk2 with DID 2222, trunk3 with DID 3333 and trunk4 with DID 4444, you set the context for these trunks to check-did. Then, in the file extensions_custom.conf, you put something like:

[check-did]
exten => _X!,1,GotoIf($["${EXTEN}" = “1111”]?from-trunk-sip-trunk1,${EXTEN},1)
exten => _X!,1,GotoIf($["${EXTEN}" = “2222”]?from-trunk-sip-trunk2,${EXTEN},1)
exten => _X!,1,GotoIf($["${EXTEN}" = “3333”]?from-trunk-sip-trunk3,${EXTEN},1)
exten => _X!,1,GotoIf($["${EXTEN}" = “4444”]?from-trunk-sip-trunk4,${EXTEN},1)
Goto(from-trunk,${EXTEN},1)

The above is more complex than needed for the case where the DID number is in the SIP URI, but shows a general method also applicable to other situations.

If needed, you can further customize the behavior for each DID by creating contexts such as from-trunk-sip-trunk1-custom – see (but don’t attempt to edit) your extensions_additional.conf for details.

If this is still not useful, please post a specific example of a desired behavior change.

Slightly off topic: Are you locked into vivavox? I would think that your job would be simpler if you chose a provider where one account could have as many DIDs as you need, all with one trunk. Also, looking at their site, their rates didn’t seem very attractive. What plans are you using? What is your estimated monthly calls and minutes to fixed lines? To mobiles?

yes I’m locked with a very convenient contract with vivavox, maybe in the next year I will try for a different solution. But for now I’m locked. For the rest you were very clear.

I will try to explain you what I’m trying to do.
My provider gives me unlimited inbound/oubound calls for each account.
we have four offices geographically dislocated:

office venice
4 employers - here I want a max of 6 incoming calls, the 7th must hang up
office bari
4 employers - here I want a max of 6 incoming calls the 7th must hang up
office ancona
4 employers - here I want a max of 6 incoming calls the 7th must hang up
office rome
20 employers - here I want a max of 24 incoming calls the 25th must hang up

I don’t want any limitation for outgoing calls, because there are some individual employers that use their extension only for calling and not for receiving(like accounting dep etc).

for the moment, all trunks are correctly registred and even if calls are passing all through the first trunk, an inbound route based on the DID number is routing the calls to the corrects extensions. This seems not a problem cause the first trunk has unlimited channels, so that’s not a problem(I don’t care about codecs). But how I can build this incoming limitations? and most important thing, is correct to leave things as thery are? considering that I have a lot of resources in my cluster, I can easily create 4 freepbx vms, place a trunk in each one and than a trunk between the four freepbx vms.

There are some things about your specific situation that will illuminate your situation.

  1. Can you have more than one DID per trunk?
    1a) Do each of your inbound trunks have a single DID?
  2. Are you running this on a single instance of FreePBX?
  3. Are these all part of the same company, just in four locations, or is this four clients running on your server?
  4. Why are you trying to limit the inbound calling?
  5. Do you want the company’s customers to get a disconnect or a busy signal?
  6. You keep talking about incoming and outgoing calls and using the terms interchangeably. It is very confusing. Define what you are talking about when you talk about incoming and outgoing calls.

With those questions unanswered, here are some hints:

Inbound and outbound calling in Asterisk are exclusive of one another. The rules you specify for incoming calls (calls from outside your company and come from your ITSP) are largely unrelated to the rules you apply to outgoing calls (calls you place from your company through your ITSP).

Your connected trunks mix all of your inbound calls together so that they can be sent through the incoming to your “inbound route” module. The calls are then processed (regardless of trunk) and routed to wherever they need to go based on the DID and/or CID of the incoming call.

When your employees place an outbound call, the call is typically sent from the “from-internal” context to the “Outbound Routes” module, which routes your calls to the trunks. Asterisk will send the call (based on the Outbound Route and Trunk modification rules) to the first trunk that qualifies. The problem, typically, is that if you have more than one trunk to a specific provider, the call with be sent out over whatever trunk is available to that provider. Trying to control the trunk selection is deliberately hard to do - almost all of the reasons for doing it are because the person setting up the system doesn’t understand SIP or is unwilling to learn the same.

To limit inbound calls on a “per trunk” basis, you need to limit the number of concurrent channels (which effects both inbound and outbound calling) or you need to set up a custom context that keeps some kind of scoreboard on the number of concurrent calls from each trunk. Using ‘concurrent channel’ limits works fine, except that it isn’t going to work for you without a lot of set up and manipulation of your inbound and outbound calls.

There may be a commercial module that helps you do that - you’d have to check with Sangoma on that.

  1. no one DID per trunk
    1a) yes each inbound have a single DID
  2. yes one virtualized last FREEPBX kvm in an HA cluster
  3. we are all the same company, and we can ping each other IP phone through VPN based on a PFsense kvm inside the same cluster.
  4. This is because the kind of work we do in our company, is a little difficoult to explain, but is better for us that the customers receive hangup if we are full of work.
  5. I want a message like “we are busy now please call later”
  6. incoming calls: the max number of calls that we can receive simultaneous after that I want the message in point 5.
    outgoing calls: I don’t want this to be limited in any way so every time an employer want to make a call the channel have to be always free(but this is working now)

I’m a senior IT, and I have a lot of freepbx around, but this is the first time that I’m building a configuration with multiple sip trunks, and I’m migrating from an old ISDN avaya system to voip technology. For sure I’m noob but I think that the situation is clear:
I cannot have multiple trunks from the same ip address cause incoming calls will be set to the first trunk in the list. this is how sip technology works so there is no solution(maybe I can fix this with multiple freepbx vms??)
but considering that my provider gives to me unlimited channels for the first trunk in the list too, this is working perfect, problems is that I cannot figure out how to limit the inbound calls. Another problem is that in the future this provider will give to us a flat rate but with limited channels, so when this will happens the first trunk will limit all the others.

Thanks for the answers.

Switching from a proprietary PBX to FreePBX often requires changes in the way one thinks about how your operations work. With PRIs, what you are trying to do is simple - you set up each trunk so that the extensions go out over a specific trunk, and you have the provider limit the number of channels on the PRI for each PRI.

The model that SIP uses turns all of that on it’s head. In SIP connections, you almost always want to allow unlimited incoming and outgoing connections, since the ITSP is charging by the channel-minute. More Channels x the same number of minutes = more money.

Since you are using (and are limited to) one DID per trunk, there are a couple ways to go.

Four Virtual Machines seems like a possible solution, but then you have to set up all of the interconnections between the servers for Intercom/Local calling to work.

Setting the max channels isn’t going to work for you because it limits both inbound and outbound calling. You only want inbound limited.

Have you looked at the Ring Group/Queue processing options? Since you are one DID per trunk, is it safe to assume you want all four phones (if they are not in use) at one location to ring when the phone number is called? If you go with a Queue, you can limit the number of people waiting to talk to those four phones. You can also send your callers to Voice Mail or a Hang Up message from there if they exceed the number you specified.

Setting this up on the trunk end is going to be exceedingly complex, but using queues or ring groups could make this relatively simple.

yes you are right, in the last 5 minutes I searched documentation about your solution and I think that this is the way to go. But as I told you I will have to face this problem when my provider will limit my channels due the new flat rate… maybe at that point a clear solution will be the 4 vms, I really don’t like to play with an hard context/trunk customization cause for my experience the more I’m editing staffs in freepbx this way the more I will face problems after updates or future configurationa… any way thank you my friend for your usefull tips about the queue

Get your system working like you want it to. We can explore trunk-selection technology when you have more time and the system is working. With less pressure, you can do more research and don’t have to fight the system.

1 Like

Just for anyone that have to face the same problem, I fixed this using pjsip protocol instead of sip, just put the parameter
line=yes
context=from-pstn-toheader
and you will see the 4 trunks working indipendently.
I think this is a very clean solution, and from some reason the call quality is increased(???)
Many thanks for your help.

1 Like

Hello @wassy83

This is a good solution, but just for your common knowledge, you can setup the same with chan_sip as well. In a case that you have multiple trunks to the same provider (with the same ip) you need to add another trunk for incoming calls with the DID as the extension number. You can do it in the Freepbx trunk configuration in the incoming section of the trunk.
You must set the type field to user in the incoming section and it is better to set the type to peer in the outgoing section although it is not necessary.

Quotes from Kevin Fleming of Digium on Asterisk 
Mailing list Dec 23, 2005:

As of Asterisk 1.2, there is no reason to actually 
use 'user' entries any more at all; you can use 
'type=peer' for everything and the behavior
will be much more consistent.

All configuration options supported under 
'type=user' are also supported under 'type=peer'.

The difference between friend and peer is the 
same as defining both a user and peer, since that is 
what 'type=friend' does internally.
 
The only benefit of type=user is when you want 
to match on username regardless of IP the calls 
originate from. If the peer is registering to
you, you don't need it. If they are on a fixed IP, you 
don't need it.
'type=peer' is never matched on username for 
incoming calls, only matched on IP address/port 
number (unless you use insecure=port or higher).

Thank you,

Daniel Friedman

thank you my friend for your suggestions but I searched a lot and I have already found your solution but this doesn’t work… really the only way was pjsip. I’m a little noob so I was thinking that from the side of the provider there must be some compatibily for pjsip to work, but I understood that even if my provider gives me only sip authentication I can use the same credentials for a pjsip trunk. I really can’t understand why there is a boost in call quality with pjsip., but is reallt good compared to sip

Hello @wassy83,

It is working well on all my pbx’s, and I have a lot. As for the PJSIP, it is an extension of the SIP protocol and you can use it to interconnect with any provider (SIP or PJSIP). Digium wrote the SIP stack from scratch. The problem is that sometimes, it does not integrate well because of new features and a new behavior that needs to be explored by the administrators. So, keep an eye on your new PJSIP trunk for the near future.

By the way, you can coexist with chan_sip and chan_pjsip on the same pbx, just with different ports.

Thank you,

Daniel Friedman

Sorry Daniel,
just to be clear… when you said

you need to add another trunk for incoming calls with the DID as the extension number. You can do it in the Freepbx trunk configuration in the incoming section of the trunk.
You must set the type field to user in the incoming section and it is better to set the type to peer in the outgoing section although it is not necessary.

what you mean with "you need to add another trunk?"
Let’s say I have 4 trunks with the same provider, and for each trunk I have a configuration in the outgoing tab and in the ingoing tab like this

Trunk office

  • in_0039123456789
  • out_0039123456789

Trunk office2

  • in_0039223456789
  • out_0039223456789

Trunk office3

  • in_0039323456789
  • out_0039323456789

Trunk office4

  • in_0039423456789
  • out_0039423456789

following your instructions I have to put a conf sample like this

out_0039123456789
username=0039123456789
user=0039123456789
type=peer
secret=secret
qualifyfreq=600
qualify=yes
host=voip.vivavox.it
fromuser=0039123456789
fromdomain=voip.vivavox.it

in_0039123456789
username=0039123456789
user=0039123456789
type=user
secret=secret
qualifyfreq=600
qualify=yes
insecure=invite
host=voip.vivavox.it
fromuser=0039123456789
context=from-trunk

register string 0039123456789:[email protected]:5060/0039123456789

am I right? or you mean to add other trunks in another way? cause this is already my setup and is not working(I can call receive in the right way but always the first trunk is used)
Many thanks this is just to clarify if am I doing something wrong

This is new information for me too, so this is partly a guess. Knowing what I know about registration and based on reading the quoted text from Kevin Fleming, I think it means that you should probably be setting your trunk up like this:

out_0039123456789
username=0039123456789
user=0039123456789
type=peer
secret=secret
qualifyfreq=600
qualify=yes
insecure=invite
host=voip.vivavox.it
fromuser=0039123456789
fromdomain=voip.vivavox.it
context=from-trunk

in_0039123456789
<empty>

register string 0039123456789:[email protected]:5060/0039123456789

If that doesn’t work (or you lose incoming calls) you can try changing the type from ‘peer’ to ‘friend’ to match the user information on the trunk.