Maximum Channels Not working?

I am having a problem with my outgoing trunks and the Maximum Channels option in the Trunk section. I have a trunk that I want to set for 2 maximum channels.

Once I set that up and goto my outgoing route I set that trunk as first in the sequence and zap trunk as second. Now if I try to make 3 calls it still tries to call the 1st trunk in the sequence.

What can I do to fix this!!??

the code will skip the trunk once the max is reached. However, it does not count inbound calls as part of that max at this point, which provides some limitations but also depends on how your providers (assuming VoIP) count channels. (This matches how some providers work - not others). In the future there will be more flexibility but for now - that is how it works, and it has not changed and should work if properly configured.

My problem is specifically with outbound calling…it simply does not want to skip it.

Let me give you an example:

Trunk 1 - Settings

Maximum Channel - 2

Trunk 2 -Settings

Maximum Channel - 3

Outgoing Route -

Trunk Sequence:
Trunk 1
Trunk 2

Sequence of events:

  1. Make first call on Outbound Route - Goes through Trunk 1
  2. Make Second call on Outbound Route - Goes Through Trunk 1
  3. Make Third call on Outbound Route - Goes through Trunk 1!!!

As you can see I have Trunk 1 with Maximum Channels set to 2. The system shouldn’t try to make another outgoing call on Trunk 1 on the Third attempt…unless I am misreading documentation?

This is running 2.2.2 - 2.3.0rc1. I have tried those versions and the problem still persists.

Has anyone else had any issues with this?? Is there some files I need to check to make sure I don’t have something misplaced?

I was able to fix this problem myself.

For future notes I had to goto extensions.conf under the macro-dialout-trunk context I modified this line

exten => s,n(checkmax),GotoIf($[ ${GROUP_COUNT()} > ${OUTMAXCHANS_${DIAL_TRUNK}} ]?chanfull)


exten => s,n(checkmax),GotoIf($[ ${GROUP_COUNT(OUT_${DIAL_TRUNK})} > ${OUTMAXCHANS_${DIAL_TRUNK}} ]?chanfull)


what version of Asterisk are you running?


This is under Trixbox as well…version 2.2.3.

it would be quite interesting to get a CLI and log trace of that section of the dialplan with and without your patch.

GROUP_COUNT() defaults the the group of the current channel if not specified, which is the same. It has been like this since ‘forever’ so something odd is happening or there is a bug in 1.2.22?


I could PM you the CLI if you would like?

But, the way I figured it out was I NoOp’d the variables for the group_count and the ${OUTMAXCHANS_${DIAL_TRUNK}}.

I noticed the Group_count() always returned zero when documentation clearly stated that it supposed to use the current channels group.

Forcing the variable in the Group_Count function made it work…shrug.

If you would like the information please reply back. I know how to get the CLI but, the log trace I will need you to tell me how to generate that.

the log trace is in /var/log/asterisk/full

I’d rather not PM - can you just paste the trace into a codeblock here - just that section of the trace where it fails and works for both log and CLI. It is easy enough to replace you phone numbers with Xs or something to deal with privacy concerns. PMing it keeps other developers and people from reviewing and helping to see what is happening.


First, big sorry for my BAD-BAD English - this is not my native language.

I’m use freePBX (in TrixBox) with FXO gate.
To this gate connected 4 PSTN lines.
For example with numbers
In freePBX i’m create 4 trunks - for each line with same name (111111, …, 444444)
Maximum channel for this trunks 1.
I’m use this trunk for incoming and outgoing calls.
For this i’m create out route (with 9 prefix) and using this 4 trunks.
Problem №1.
Out calls always routed over first trunk.
When i’m use solution from On August 14th, 2007 m2oore out calls work propertly:

  • fist call use first trunk
  • second call use second trunk
    … and i’m got Problem № 2
  • when i’m receive incoming call over first trunk out calls not work - system try route out calls over first (busy) trunk…
    How resolve this problem?

P.S. i’m use freePBX with last updates and asterisk 1.4.11.

if you are using zap trunks, then just make one zap group, (e.g. g0) and one trunk. Zap channels will automatically choose the free channels, there is no need to have FreePBX do it. (You can leave max channels blank).

Philippe Lindheimer - FreePBX Project Lead
http// - IRC #freepbx

… i’m use external FXO gateway - Welltech 3804

it sounds to me like something is broken somewhere. The GROUP() function that is used works unless Asterisk broke something or you have something wrong going on with your system (same with the previous post). For incoming calls, they are not counted against the number of channels and if your gateway is reporting ‘busy’ instead of ‘congested’ then it will fail. The 2.3 branch of the core, which has not yet been published to the online module system, has some enhancements that will generate new contexts for you that can be used in your trunk configurations. One per trunk. If you use these instead of from-pstn then it will count the incoming calls in that trunk group and allow FreePBX to bypass the trunk that has an incoming call on it. This assumes that things are working properly on your system though and it sounds like you may have issues from what you describe. You may want to try loading Asterisk 1.2 and see if you still have the same issue for the outbound max not being achieved.

Philippe Lindheimer - FreePBX Project Lead
http// - IRC #freepbx

I now have an FXO card with one usable port. I would like to limit to one call at a time, inbound OR outbound. I am using pbx in a flash with freepbx version 2.5. I am using the from-zaptel context to allow the ZAPTEL DID stuff. What should I be doing to get the functionality you describe above? Thx…

I put a custom context to catch the start of the incoming PSTN call, and do this:

exten => s,n,Set(GROUP()=OUT_2)

since OUT_2 is actually ZAP/1, my PSTN port. I’d like it to not be dependent on which slot is assigned to the ZAP trunk, but I’m not sure offhand how to do that?