Connecting a Cisco Gateway to Twilio Elastic SIP Trunking

While I was turning up the new Cloverhound office, we needed to find a Telco to hook up to our CME. Previously, I had used some pretty reasonable providers, however this time since I have been doing a bunch of work with Twilio, I thought I would try their new Elastic SIP Trunking service. I signed up for their BETA, and was given 4 numbers in which I could receive incoming calls. I was told this would be public very shortly.

We are using it with GREAT success for our Charlotte office, and audio quality has been spectacular. We are even using it over a B2B tunnel from the origination point to our office, and it still works amazing.

This is a perfect way to get your Cisco LAB online with PSTN number overnight. Twilio charges only $1/month per number and less than a penny a minute. Most other providers charge $70/mo minimum. Another way Twilio is changing the game!

Provisioning you Twilio SIP Trunk

The first thing your going to need to do is provision your SIP domain and credentials after logging into Twilio. You can find it by browsing to SIP -> Credentials List. The picture shows our configuration of the Cloverhound site below.

Screen Shot 2015-02-09 at 11.25.04 PM

You will also need to create an IP Access Control List with the IP Address of any WAN IP that the SIP requests could be sourced from. This can be found under SIP -> IP Access Control Lists

Screen Shot 2015-02-09 at 11.27.02 PM
The final step is to go to your number and configure it to point to your SIP Trunk for incoming calls . This can be found under Numbers -> <Number> and looks like the following. (Please note you must be in the Twilio SIP Trunking BETA to get the SIP: Option).

Screen Shot 2015-02-09 at 11.29.16 PM

These are all the steps necessary to configure Twilio, now you only must configure your SIP Router with credentials.

Configuring your Cisco ISR for Twilio SIP Trunking

Pretty much any ISR that supports CUBE will be fine for hooking up to Twilio. Cisco 28xx, 29xx, 38xx, 39xx, 43xx etc.. will all work just fine. I am going to recommend 15.2(4)M7 as the IOS to use for now (or the newest 15.1(4)M train out for older routers)

Twilio require that you use credentials for outbound calls, so this means you MUST use the B2BUA built into Cisco IOS. Posted below is the configuration I am using in my lab.

sip-ua
authentication username cloverhound password 7 XXXXXXXXXXXXXXXXXXX realm sip.twilio.com
registrar dns:cloverhound.pstn.twilio.com expires 3600
sip-server dns:cloverhound.pstn.twilio.com
!

As you can see the configuration is simple but there are some more things that are going to be important by default. First of all, one real dumb thing to do is put a CUBE on the internet without ANY kind of security. Toll fraud is RAMPANT on the internet with open SIP providers. In 15.x IOS Cisco introduced the IOS Trust List. You MUST use this if your putting your device on the open Internet. The second I did, within 2 days I saw random sip invite being sent from all over the net. Below is a good template for your IOS device, with the Twilio IP’s included.

voice service voip
ip address trusted list
ipv4 54.84.237.137
ipv4 54.85.131.135
ipv4 54.85.131.188
ipv4 54.85.123.45
ipv4 54.72.246.65
ipv4 54.77.209.170
ipv4 54.77.210.162
allow-connections sip to sip
fax protocol t38 version 0 ls-redundancy 0 hs-redundancy 0 fallback none
sip
 bind control source-interface GigabitEthernet0/0.100
 bind media source-interface GigabitEthernet0/0.100
 registrar server expires max 3600 min 600
!

Next, Twilio wants all numbers in full E.164 format, so we are going to need to transform all outbound calls to E.164 before sending to Twilio. The rules below are doing 2 things, A.) they are changing this outbound call from 919803331212 to +19803331212 and B.) it is changing my ANI from 4002 to 9802180999.

voice translation-rule 1
 rule 1 /^91/ /+1/
!
voice translation-rule 2
 rule 1 /4004/ /9802180971/
 rule 2 /4002/ /9802180999/
 rule 3 /4005/ /9802180980/
!
!
voice translation-profile twilio
 translate calling 2
 translate called 1
!

Lastly I have a dial-peer with 91[2-9]..[2-9]…… in order to catch the calls. You can see the translation profile that is applied to translated the number to E.164. Also it seems Twilio appreciates G.711. the ‘session target sip-server’ is what target the sip B2BUA configured above with the ‘sip-ua’ command.

dial-peer voice 200 voip
translation-profile outgoing twilio
destination-pattern 91[2-9]..[2-9]......
session protocol sipv2
session target sip-server
dtmf-relay rtp-nte sip-kpml sip-notify
codec g711ulaw
no vad
!

Verification

The easiest way to verify is to run the ‘debug ccsip messages’ command and verify good SIP messaging with Twilio as seen below on an outbound call.

You will see that I smashed enter twice during the debug…. The first time I smashed it is right before I answered the call….The second time I smashed it is right before I hung up the call. It was obviously successful

CUBE#debug ccsip message

SIP Call messages tracing is enabled

CUBE#term mon

CUBE#

*Feb 10 04:35:57.584: //6043/22B80C5A897C/SIP/Msg/ccsipDisplayMsg:

Sent:

INVITE sip:+19803338415@cloverhound.pstn.twilio.com:5060 SIP/2.0

Via: SIP/2.0/UDP 142.100.64.254:5060;branch=z9hG4bK150022AE

Remote-Party-ID: <sip:5001@142.100.64.254>;party=calling;screen=no;privacy=off

From: <sip:5001@cloverhound.pstn.twilio.com>;tag=154E0454-1016

To: <sip:+19803338415@cloverhound.pstn.twilio.com>

Date: Tue, 10 Feb 2015 04:35:57 GMT

Call-ID: 2426DD76-B01511E4-8981A9DD-9B8A76F9@142.100.64.254

Supported: 100rel,timer,resource-priority,replaces,sdp-anat

Min-SE: 1800

Cisco-Guid: 0582487130-2954170852-2306648541-2609542905

User-Agent: Cisco-SIPGateway/IOS-15.4.2.T2

Allow: INVITE, OPTIONS, BYE, CANCEL, ACK, PRACK, UPDATE, REFER, SUBSCRIBE, NOTIFY, INFO, REGISTER

CSeq: 101 INVITE

Max-Forwards: 70

Timestamp: 1423542957

Contact: <sip:5001@142.100.64.254:5060>

Call-Info: <sip:142.100.64.254:5060>;method="NOTIFY;Event=telephone-event;Duration=2000"

Expires: 180

Allow-Events: kpml, telephone-event

Content-Type: application/sdp

Content-Disposition: session;handling=required

Content-Length: 253

 

v=0

o=CiscoSystemsSIP-GW-UserAgent 7266 5317 IN IP4 142.100.64.254

s=SIP Call

c=IN IP4 142.100.64.254

t=0 0

m=audio 17228 RTP/AVP 0 101

c=IN IP4 142.100.64.254

a=rtpmap:0 PCMU/8000

a=rtpmap:101 telephone-event/8000

a=fmtp:101 0-16

a=ptime:20

 

*Feb 10 04:35:57.608: //6043/22B80C5A897C/SIP/Msg/ccsipDisplayMsg:

Received:

SIP/2.0 100 Giving a try

Via: SIP/2.0/UDP 142.100.64.254:5060;branch=z9hG4bK150022AE

From: <sip:5001@cloverhound.pstn.twilio.com>;tag=154E0454-1016

To: <sip:+19803338415@cloverhound.pstn.twilio.com>

Call-ID: 2426DD76-B01511E4-8981A9DD-9B8A76F9@142.100.64.254

CSeq: 101 INVITE

Server: Twilio Gateway

Content-Length: 0

 

 

*Feb 10 04:35:57.732: //6043/22B80C5A897C/SIP/Msg/ccsipDisplayMsg:

Received:

SIP/2.0 407 Proxy Authentication required

Timestamp: 1423542957

To: <sip:+19803338415@cloverhound.pstn.twilio.com>;tag=06501101_6772d868_c382207e-0d5c-4952-be36-3359476bb98b

Via: SIP/2.0/UDP 142.100.64.254:5060;branch=z9hG4bK150022AE

CSeq: 101 INVITE

Call-ID: 2426DD76-B01511E4-8981A9DD-9B8A76F9@142.100.64.254

From: <sip:5001@cloverhound.pstn.twilio.com>;tag=154E0454-1016

Contact: <sip:172.18.23.118:5060>

Proxy-Authenticate: Digest realm="sip.twilio.com",qop="auth",nonce="d842ff84ae369af850c516166706ca5e",opaque="0c5a7251499f157b23a75933081502df"

Content-Length: 0

 

 

*Feb 10 04:35:57.732: //6043/22B80C5A897C/SIP/Msg/ccsipDisplayMsg:

Sent:

ACK sip:+19803338415@cloverhound.pstn.twilio.com:5060 SIP/2.0

Via: SIP/2.0/UDP 142.100.64.254:5060;branch=z9hG4bK150022AE

From: <sip:5001@cloverhound.pstn.twilio.com>;tag=154E0454-1016

To: <sip:+19803338415@cloverhound.pstn.twilio.com>;tag=06501101_6772d868_c382207e-0d5c-4952-be36-3359476bb98b

Date: Tue, 10 Feb 2015 04:35:57 GMT

Call-ID: 2426DD76-B01511E4-8981A9DD-9B8A76F9@142.100.64.254

Max-Forwards: 70

CSeq: 101 ACK

Allow-Events: kpml, telephone-event

Content-Length: 0

 

 

*Feb 10 04:35:57.732: //6043/22B80C5A897C/SIP/Msg/ccsipDisplayMsg:

Sent:

INVITE sip:+19803338415@cloverhound.pstn.twilio.com:5060 SIP/2.0

Via: SIP/2.0/UDP 142.100.64.254:5060;branch=z9hG4bK1501CD1

Remote-Party-ID: <sip:5001@142.100.64.254>;party=calling;screen=no;privacy=off

From: <sip:5001@cloverhound.pstn.twilio.com>;tag=154E0454-1016

To: <sip:+19803338415@cloverhound.pstn.twilio.com>

Date: Tue, 10 Feb 2015 04:35:57 GMT

Call-ID: 2426DD76-B01511E4-8981A9DD-9B8A76F9@142.100.64.254

Supported: 100rel,timer,resource-priority,replaces,sdp-anat

Min-SE: 1800

Cisco-Guid: 0582487130-2954170852-2306648541-2609542905

User-Agent: Cisco-SIPGateway/IOS-15.4.2.T2

Allow: INVITE, OPTIONS, BYE, CANCEL, ACK, PRACK, UPDATE, REFER, SUBSCRIBE, NOTIFY, INFO, REGISTER

CSeq: 102 INVITE

Max-Forwards: 70

Timestamp: 1423542957

Contact: <sip:5001@142.100.64.254:5060>

Call-Info: <sip:142.100.64.254:5060>;method="NOTIFY;Event=telephone-event;Duration=2000"

Expires: 180

Allow-Events: kpml, telephone-event

Proxy-Authorization: Digest username="cloverhound",realm="sip.twilio.com",uri="sip:+19803338415@cloverhound.pstn.twilio.com:5060",response="6f5041450f97842b4c09d771c78c2f20",nonce="d842ff84ae369af850c516166706ca5e",opaque="0c5a7251499f157b23a75933081502df",cnonce="08F661BB",qop=auth,algorithm=md5,nc=00000001

Content-Type: application/sdp

Content-Disposition: session;handling=required

Content-Length: 253

 

v=0

o=CiscoSystemsSIP-GW-UserAgent 7266 5317 IN IP4 142.100.64.254

s=SIP Call

c=IN IP4 142.100.64.254

t=0 0

m=audio 17228 RTP/AVP 0 101

c=IN IP4 142.100.64.254

a=rtpmap:0 PCMU/8000

a=rtpmap:101 telephone-event/8000

a=fmtp:101 0-16

a=ptime:20

 

*Feb 10 04:35:57.768: //6043/22B80C5A897C/SIP/Msg/ccsipDisplayMsg:

Received:

SIP/2.0 100 Giving a try

Via: SIP/2.0/UDP 142.100.64.254:5060;branch=z9hG4bK1501CD1

From: <sip:5001@cloverhound.pstn.twilio.com>;tag=154E0454-1016

To: <sip:+19803338415@cloverhound.pstn.twilio.com>

Call-ID: 2426DD76-B01511E4-8981A9DD-9B8A76F9@142.100.64.254

CSeq: 102 INVITE

Server: Twilio Gateway

Content-Length: 0

 

 

*Feb 10 04:36:01.300: //6043/22B80C5A897C/SIP/Msg/ccsipDisplayMsg:

Received:

SIP/2.0 183 Session progress

Timestamp: 1423542957

To: <sip:+19803338415@cloverhound.pstn.twilio.com>;tag=17631643_6772d868_1c147767-5272-4157-8a30-9309e1d70436

Via: SIP/2.0/UDP 142.100.64.254:5060;branch=z9hG4bK1501CD1

Record-Route: <sip:54.85.131.188:5060;lr;ftag=154E0454-1016>

CSeq: 102 INVITE

Call-ID: 2426DD76-B01511E4-8981A9DD-9B8A76F9@142.100.64.254

From: <sip:5001@cloverhound.pstn.twilio.com>;tag=154E0454-1016

Contact: <sip:172.18.6.218:5060>

Content-Type: application/sdp

X-Twilio-CallSid: CA5bdfbaece341a2dd773e8e2a9b37709d

Content-Length: 231

 

v=0

o=- 2025479834 2025479834 IN IP4 52.0.14.47

s=SIP Media Capabilities

c=IN IP4 52.0.14.47

t=0 0

m=audio 19350 RTP/AVP 0 101

a=rtpmap:0 PCMU/8000

a=rtpmap:101 telephone-event/8000

a=fmtp:101 0-15

a=sendrecv

a=ptime:20

 

CUBE#

CUBE#

CUBE#

CUBE#

CUBE#

*Feb 10 04:36:07.988: //6043/22B80C5A897C/SIP/Msg/ccsipDisplayMsg:

Received:

SIP/2.0 200 OK

Timestamp: 1423542957

To: <sip:+19803338415@cloverhound.pstn.twilio.com>;tag=17631643_6772d868_1c147767-5272-4157-8a30-9309e1d70436

Via: SIP/2.0/UDP 142.100.64.254:5060;branch=z9hG4bK1501CD1

Record-Route: <sip:54.85.131.188:5060;lr;ftag=154E0454-1016>

CSeq: 102 INVITE

Call-ID: 2426DD76-B01511E4-8981A9DD-9B8A76F9@142.100.64.254

From: <sip:5001@cloverhound.pstn.twilio.com>;tag=154E0454-1016

Contact: <sip:172.18.6.218:5060>

Content-Type: application/sdp

X-Twilio-CallSid: CA5bdfbaece341a2dd773e8e2a9b37709d

Content-Length: 231

 

v=0

o=- 1520895951 1520895951 IN IP4 52.0.14.47

s=SIP Media Capabilities

c=IN IP4 52.0.14.47

t=0 0

m=audio 19350 RTP/AVP 0 101

a=rtpmap:0 PCMU/8000

a=rtpmap:101 telephone-event/8000

a=fmtp:101 0-15

a=sendrecv

a=ptime:20

 

*Feb 10 04:36:07.992: //6043/22B80C5A897C/SIP/Msg/ccsipDisplayMsg:

Sent:

ACK sip:172.18.6.218:5060 SIP/2.0

Via: SIP/2.0/UDP 142.100.64.254:5060;branch=z9hG4bK1502E73

From: <sip:5001@cloverhound.pstn.twilio.com>;tag=154E0454-1016

To: <sip:+19803338415@cloverhound.pstn.twilio.com>;tag=17631643_6772d868_1c147767-5272-4157-8a30-9309e1d70436

Date: Tue, 10 Feb 2015 04:35:57 GMT

Call-ID: 2426DD76-B01511E4-8981A9DD-9B8A76F9@142.100.64.254

Route: <sip:54.85.131.188:5060;lr;ftag=154E0454-1016>

Max-Forwards: 70

CSeq: 102 ACK

Proxy-Authorization: Digest username="cloverhound",realm="sip.twilio.com",uri="sip:+19803338415@cloverhound.pstn.twilio.com:5060",response="6f5041450f97842b4c09d771c78c2f20",nonce="d842ff84ae369af850c516166706ca5e",opaque="0c5a7251499f157b23a75933081502df",cnonce="08F661BB",qop=auth,algorithm=md5,nc=00000001

Allow-Events: kpml, telephone-event

Content-Length: 0

 

 

CUBE#

CUBE#

CUBE#

CUBE#

CUBE#

CUBE#

CUBE#

*Feb 10 04:36:15.740: //-1/xxxxxxxxxxxx/SIP/Msg/ccsipDisplayMsg:

Received:

BYE sip:5001@142.100.64.254:5060 SIP/2.0

CSeq: 1 BYE

From: <sip:+19803338415@cloverhound.pstn.twilio.com>;tag=17631643_6772d868_1c147767-5272-4157-8a30-9309e1d70436

To: <sip:5001@cloverhound.pstn.twilio.com>;tag=154E0454-1016

Call-ID: 2426DD76-B01511E4-8981A9DD-9B8A76F9@142.100.64.254

Max-Forwards: 69

Via: SIP/2.0/UDP 54.85.131.188:5060;branch=z9hG4bKacf3.a324f7b7.0

Via: SIP/2.0/UDP 172.18.6.218:5060;received=52.0.14.47;branch=z9hG4bK1c147767-5272-4157-8a30-9309e1d70436_6772d868_468366558747437

X-Twilio-CallSid: CA5bdfbaece341a2dd773e8e2a9b37709d

Content-Length: 0

 

 

*Feb 10 04:36:15.744: //-1/xxxxxxxxxxxx/SIP/Msg/ccsipDisplayMsg:

Sent:

SIP/2.0 200 OK

Via: SIP/2.0/UDP 54.85.131.188:5060;branch=z9hG4bKacf3.a324f7b7.0,SIP/2.0/UDP 172.18.6.218:5060;received=52.0.14.47;branch=z9hG4bK1c147767-5272-4157-8a30-9309e1d70436_6772d868_468366558747437

From: <sip:+19803338415@cloverhound.pstn.twilio.com>;tag=17631643_6772d868_1c147767-5272-4157-8a30-9309e1d70436

To: <sip:5001@cloverhound.pstn.twilio.com>;tag=154E0454-1016

Date: Tue, 10 Feb 2015 04:36:15 GMT

Call-ID: 2426DD76-B01511E4-8981A9DD-9B8A76F9@142.100.64.254

Server: Cisco-SIPGateway/IOS-15.4.2.T2

CSeq: 1 BYE

Reason: Q.850;cause=16

P-RTP-Stat: PS=717,OS=114720,PR=711,OR=113760,PL=0,JI=0,LA=0,DU=7

Content-Length: 0

Conclusion

As you can see configuring Twilio with Cisco Gateway isn’t that hard at all. I didn’t see another tutorial on the net yet, so figured I would write one up if the Twilio guys wanted to share!

Chad