Asterisk dialplan to dial over multiple trunks with call limit set

Asterisk dialplan to load balance between trunks with call limit

asterisk dialplan sip trunk call limit


  Topic: Sip Trunk grouping with call limit 

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

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

same dialplan can be used as grouping of multiple sip trunks together with call limit set.
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 dialover 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

    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)

  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


Previous Post
No Comment
Add Comment
comment url