For 2 or more Trunks limit max calls per trunk and dyancially route if trunk is up

Hi guys

I have scenario in which i have 2 SIP Trunks for outbound calling.
Each Trunk is limited at the far end to only allow 60 calls max (at call 61 it fails)

Now my current setup allows to dial out via these 2 Trunks after first checking if they are UP/Available
so if one trunk is down it will Dynamically chose the other trunk.
This is working perfectly.

What I need now is the ability to check the status of each trunk before attempting to call out on it, but also check if the trunk currently has 60 or less calls on it, if the trunk reaches 60 calls, it should be marked as busy/unavailable and my dial plan should then dynamically chose the second trunk.

I am kind of new to dial plans in Asterisk which seem very programtical (and I’m not a programmer :smiley: ) and I’m struggling to work out the logic to implement this.

It would be extremely helpful if i could get some working examples of how to achieve this.

My current sip.conf (stripped down to just include a single Extension and my 2 Trunks)

[1100]
secret=123456
context=local
callerid=1100
type=friend
host=dynamic
nat=force_rtport,comedia
transport=tcp,udp

[trunk_1] ; Max allowed calls 60
type=peer
host=10.10.10.10
canreinvite=no
allow=all
qualify=yes
insecure=port,invite
autocreatepeer=yes
context=incoming


[trunk_2] ; Max allowed calls 60
type=peer
host=10.10.10.11
canreinvite=no
allow=all
qualify=yes
insecure=port,invite
autocreatepeer=yes
context=incoming

and my current extensions.conf

; Context for incoming calls

[incoming]
exten => _X.,1,Dial(SIP/${EXTEN},300)
exten => _X.,n,Congestion(10)

; Context for outgoing calls

[local]
exten => _X.,1,GotoIf($[${DB_EXISTS(SIP/Registry/${EXTEN})}]?10:15)
exten => _X.,10,Dial(SIP/${EXTEN},300)
exten => _X.,15,ChanIsAvail(SIP/trunk_cucm1&SIP/trunk_cucm2)
exten => _X.,16,Set(AVAILCHAN=${CUT(AVAILCHAN,-,1)})
exten => _X.,17,Dial(${AVAILCHAN}/${EXTEN},300)
exten => _X.,n,Congestion(10)

Many thanks

https://wiki.asterisk.org/wiki/display/AST/Function_GROUP_COUNT

Also, there is no option force_rtport, so it is probably lucky that nat= isn’t actually needed in the more common NAT configurations.

Also insecure=invite has no effect when there is no secret configured (and insecure=port is rarely needed, although you might need it on the local device, because of the TCP transport option, but don’t have it there).

canreinvite was renamed to directmedia many years ago.

type=peer is almost always better than type=friend, unless two devices share an IP address.

Hi David

Thank you so much for taking the time to reply :wink:

type=friend will be needed, as i am using an external system which will be registering to (All) the defined Extensions from the same IP address :slight_smile:

Thanks for all the other pointers, ill def look into them.

The general section of my sip.conf has

[general]
language=en
tcpenable=yes
allow=all
port = 5060
bindaddr = 0.0.0.0
qualify=yes
srvlookup=yes
context=incoming

I believe we found a working solution to my initial question above with the below extension.conf

; Context for outgoing calls
[local]
exten => _.,1,GotoIf($[${DB_EXISTS(SIP/Registry/${EXTEN})}]?10:20)
exten => _.,10,Dial(SIP/${EXTEN},300)
exten => _.,20,ChanIsAvail(SIP/trunk1&SIP/trunk2)
exten => _.,21,Set(GROUP()=trunkgroup1)
exten => _.,22,Set(VOIPMAX=60)
exten => _.,23,GotoIf($[${GROUP_COUNT(trunkgroup1)} < ${VOIPMAX}]?30:40)
exten => _.,30,Set(AVAILCHAN=${CUT(AVAILCHAN,-,1)})
exten => _.,31,Dial(${AVAILCHAN}/${EXTEN},300)
exten => _.,40,ChanIsAvail(SIP/trunk2&SIP/trunk1)
exten => _.,41,Set(AVAILCHAN=${CUT(AVAILCHAN,-,1)})
exten => _.,42,Dial(${AVAILCHAN}/${EXTEN},300)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.