IAX2 Multiple Trunks Incoming Call Load Balancing

2 asterisk servers (A & B) are connected using 05 IAX2 trunks between them. The machine A is running asterisk & Openvpn server in TUN mode (5 instances with difference IP addresses for clients). The machine B is running asterisk with 05 OpenVPN clients using 05 bandwidths. The IAX trunks are established between each pair of P-2-P ip address of machine A (The OPENVPN Server) & machine B (The Openvpn client).
Required dial plan configuration at machine A for incoming calls from VoIP Switch/VOS which can forward the calls to IAX2 trunks in round robin fashion like Load Balancing. If any trunk goes down it starts forwarding the traffic to other available trunks & when it gets UP the dialplan should perform as desired. Like L.B & Fail-over scenarios.
Any support is much appreciated. Thanks.

Increment a global variable. If strict round robin is required, uses locks to protect the updates.

Thanks for your response. I don’t know how it will check the status of trunks for this. Can you gide me to define the scripts for this ?

Thanks in advance.

Try and make a call and examine the resulting hangup cause to see if it is likely to have failed in the network, or at the destination. I believe FreePBX has code to do this sort of thing. If you want custom code writing, you should use the Biz and Jobs forum to find a consultant.