For instructions on how to set up a SIP trunk with Asterisk with FreePBX (like most trixbox, PBX in a flash, and AsteriskNOW installations use), check out my guide.
I started by creating a new trunk and put in my default near-universal configuration, simple register string, and hit submit. I reloaded the configuration and expected to see the trunk registered and all would be good.
After some experimenting with the register string, I found that you can't put an @ symbol in the username, as Asterisk sees anything after the @ to be the server info.
I removed everything after the @ in the username, and it worked.
Ok, so now it registers, good. Then I set up the routes to make a test oubound call. When I made the call, I got the standard "All circuits are busy now, please try your call again later." *sigh*
I looked in the Asterisk console, and it sent the INVITE request, but the Metaswitch returned "400: From: header field invalid". This Metaswitch requires all SIP traffic to be from a certain domain.
What made everything more compilcated, it that the username is in the format telephonenumber@domain.net and the domain that the switch needed all traffic from was anotherdomain.net,
so when I set the fromdomain field to the 2nd domain, the INVITE's From: field looked like this: "Unknown" <9025551234@domain.net@anotherdomain.net>, which was why the Metaswitch was refusing the INVITEs.
So, I tried several different things until I finally got a confguration that worked:
Ok, now outbound calls work, but what about inbound calls? When I was trying to get outbound working, I did as most Metaswitch-Asterisk setup pages suggest, leave the register string blank.
At first, the INVITEs were coming from a different IP address than the Metaswitch's IP. Again I was thinking WTF?.
I'm not sure if the above configuration fixed it, or if it was just a network glitch, because a couple days later, I started working on the trunk again, and when I called in, I was greeted with a "your call cannot be completed" message.
That ment that the Metaswitch didn't know where to send the SIP data. I added the register string back, and inbound calls started working. Woo!