Connect Metaswitch to Asterisk as a SIP trunk

Recently, I had the task of setting up a Metaswitch trunk with our trixbox server. I figured it would go like the other 3 trunks, and I'd be done in 15 minutes. Yeah, right.

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.
But, the trunk status was sitting at "No Auth". I was like "...what?"

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:

type=peer
qualify=yes
insecure=very
host=host.anotherdomain.net
fromuser=9025551234
fromdomain=anotherdomain.net
username=9025551234
secret=1234567890
dtmfmode=auto
disallow=all
allow=ulaw
allow=alaw
context=from-trunk
canreinvite=no
;NAT is off because the Metaswitch is 'local'
nat=no

Now the From: field looks like this: "Unknown" <9025551234@anotherdomain.net>. Much better.

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!

So that was my first experence with Metaswitch, and it wasn't so good. I hope others trying to get Asterisk and Metaswitch to talk to each other may find this page useful.
Copyright © 2016 - tyler.anairo.com