A trunk normally handles both inbound and outbound calling. Since you show both trunks are using the same host, it’s not clear witch direction you want to address.
The inbound behavior of Asterisk when two (2) trunks use the same host and port is a little unpredictable. I forget which, think it’s the first match.
If I write it like an Apache config, the below shows is how Asterisk sees inbound calling. Changing the host and/or port will disable the inbound side of the trunk. This approach could be used to switch the dialplan context for inbound calling.
# Showing inbound calling using the Apache config format
# It's an example and does NOT work in Asterisk
<SipTrunk 1.2.3.4:5060>
name=trunk_A
context=from-trunk_A-dialplan
</SipTrunk>
<SipTrunk 1.2.3.4:5060>
name=trunk_B
context=from-trunk_B-dialplan
</SipTrunk>
<SipTrunk *:5060>
name=default
context=default-dialplan
</SipTrunk>
For outbound calling, the following Dial() statements are basically identical.
# extensions.conf
same => n,Dial(SIP/1.2.3.4:9999/18004052200)
same => n,Dial(SIP/my_trunk/18004052200)
# sip.conf
[my_trunk]
host=1.2.3.4
port=9999
What you may be asking, is how to make outbound calls go to trunk B when trunk A does not work. Useful when you have a different host to send an outbound call through.
# extensions.conf
[outbound-trunk-a]
...
same => n,Dial(SIP/trunk-a/${EXTEN})
same => n,GotoIf($["${DIALSTATUS}"="CHANUNAVAIL"]?outbound-trunk-b,${EXTEN},1)
[outbound-trunk-b]
...
same => n,Dial(SIP/trunk-b/${EXTEN})
# sip.conf
[trunk-a]
host=1.2.3.4
[trunk-b]
host=5.6.7.8
You do not want to use a different context for the inbound and outbound calling in sip.conf. As the Apache example above shows, you end up creating multiple matches with the following. Which could break the inbound calling, if context (only used by inbound calling) is not defined, as shown below.
[trunk-a-in]
host=1.2.3.4
context=inbound
[trunk-a-out]
host=1.2.3.4
// no context here = default dialplan
[trunk-b-in]
host=5.6.7.8
context=inbound
[trunk-b-out]
host=5.6.7.8
// no context here = default dialplan