Asterisk dialplan to dial over multiple trunks with call limit set

Asterisk Dialplan to dial over multiple sip trunk with call limit set

    In this Article i have provided the asterisk Dialplan to dial over multiple trunks which also includes the call limit for each Trunk and dial out in random between the trunks.

asterisk dialplan sip trunk call limit
asterisk sip trunk grouping with call limit

same Dialplan can be used as grouping of multiple sip trunks together with call limit set.

Asterisk Trunk Grouping

As part of this tutorial i have three sip trunks which are named as TRUNKA, TRUNKB, and TRUNKC.
The call limit for each trunks are
TRUNKA    =    6
TRUNKB    =    8
TRUNKC    =    4
The intension of this Dialplan is to dial over or grouping multiple sip trunks and each trunk is having a call limitation.

Asterisk application and Functions:

    Below are the asterisk applications and functions used in this Dialplan.

RAND
   RAND(min,max) Choose a random number between min and max, used to generate a random number between 1 and 3 
GROUP and GROUP_COUNT
  Group and Group_Count function used to set the call limit for each trunk based on number of active channels count
GotoIf
   GotoIf function used to validate the Call limit count , 

Asterisk Dialplan with Group and Group_Count

    Below is the sample Dialplan to dial over multiple trunks with call limit set and dial in random mode.

exten => _X.,1,Goto(trunk${RAND(1,3)})
exten => _X.,n(trunk1),Set(GROUP()=TRUNKA)
exten => _X.,n,Set(COUNTA=${GROUP_COUNT(TRUNKA)})
exten => _X.,n,NoOp(MY current COUNT is ${COUNTA})
exten => _X.,n,GotoIf($[${COUNTA} > 6]?trunk2:trunkA)
exten => _X.,n(trunkA),Dial(SIP/TRUNKA/${EXTEN},,Tto)
exten => _X.,n,Hangup()
exten => _X.,n(trunk2),NoOp(Dialing TRUNKB)
exten => _X.,n,Set(GROUP()=TRUNKB)
exten => _X.,n,Set(COUNTB=${GROUP_COUNT(TRUNKB)})
exten => _X.,n,GotoIf($[${COUNTB} > 8]?trunk3:trunkB)
exten => _X.,n(trunkB),Dial(SIP/TRUNKB/${EXTEN},Tto)
exten => _X.,n,Hangup()
exten => _X.,n(trunk3),NoOp(Dialing TRUNKC)
exten => _X.,n,Set(GROUP()=TRUNKC)
exten => _X.,n,Set(COUNTC=${GROUP_COUNT(TRUNKC)})
exten => _X.,n,GotoIf($[${COUNTC} > 4]?recheck:trunkC)
exten => _X.,n(trunkC),Dial(SIP/TRUNKC/${EXTEN},Tto)
exten => _X.,n,Hangup()
exten => _X.,n(recheck),Set(GROUP()=tryagain)
exten => _X.,n,Set(COUNTD=${GROUP_COUNT(tryagain)})
exten => _X.,n,GotoIf($[${COUNTD} > 1]?hangup:trunk1)
exten => _X.,n(hangup),Set(DIALSTATUS=CHANUNAVAIL)
exten => _X.,n,Hangup()

Dialplan Description

    In Priority 1 i used RAND function to choose a random number from 1 to 3  and set the variable as trunk1 or trunk2 or trunk3, with the Goto applicaiton the respective Labels will be selected eg n(trunk1) or n(trunk2) or n(trunk3)

exten => _X.,1,Goto(trunk${RAND(1,3)})

    Folowed to that trunk selection, GROUP and GROUP_COUNT are used to set a Count value based on number of active channels dialed with the variable as COUNTA, COUNTB , COUNTC, COUNTD
here COUNTD is used to recheck once for any free channel available to dialout.

exten => _X.,n(trunk1),Set(GROUP()=TRUNKA)
exten => _X.,n,Set(COUNTA=${GROUP_COUNT(TRUNKA)})

    Next with the GotoIf application the COUNTx variable value is checked with call limit value using greater than mathematical syntax (>)  ,if the count is greater than the value mentioned then proceed with next trunk.

exten => _X.,n,GotoIf($[${COUNTA} > 6]?trunk2:trunkA)

    Finally we will hangup the call with hangup status of CHANUNAVAIL for logging purpose.

exten => _X.,n(hangup),Set(DIALSTATUS=CHANUNAVAIL)

For Basic tutorial on Dial Plan check my article on Dialplan Entry Tutorial 

Conclusion

    Hope the Dialplan is helpful for dialing over multiple trunks with call limit also loadbalance between the trunks, if you like my article kindly subscribe ,share . For professional support reach me on skype telegram - striker24x7

1 Comments
  • Anonymous
    Anonymous April 3, 2023 at 4:25 PM

    how can configure multiple gsm dinstar gateway.

Add Comment
comment url