Skip to content

Asterisk dialplan to dial over multiple trunks with call limit set

    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.

    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 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.,n,Hangup()

    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)

    Dialplan Description

    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

    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 Dial plan 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

    Leave a Reply

    Your email address will not be published. Required fields are marked *