Sip Trunk, Parsing DID

Home » Asterisk Users » Sip Trunk, Parsing DID
Asterisk Users No Comments

Hello,

I am using a Swiss VoIP provider called sipcall. They have what they call a SIP trunk, and it is less expensive than individual accounts. From Asterisk’s point of view, this is just a regular SIP account, which can however receive and send calls from multiple numbers. I just migrated from individual SIP accounts terminated on my Asterisk to one single SIP trunk.

It works perfectly (in and out). For outgoing calls, it’s just sufficient to set CALLERID(num) to the appropriate number you want the call to originate from (easy!).

For incoming calls, here is an example SIP message, with MY_IP, SIPCALL_IP, DEST_NUMBER AND SRC_NUMBER replacing the actual values:

INVITE sip:s@MY_IP:5060 SIP/2.0
Via: SIP/2.0/UDP SIPCALL_IP:5060;branch=z9hG4bK3ee1k92090iihapdm420.1
Max-Forwards: 67
Contact:
To:
From: ;tag=hy4fwr752woo42uj.o
Call-ID: 1663976908-326811297@1~1o
CSeq: 867 INVITE
Expires: 300
Allow: INVITE, ACK, BYE, CANCEL, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS, UPDATE
Content-Disposition: session
Content-Type: application/sdp
User-Agent: PortaSIP
h323-conf-id: 3912070954-288423879-3678105731-1479596074
cisco-GUID: 3912070954-288423879-3678105731-1479596074
Content-Length: 262

Since it looks that only the To: header contains the real destination number, and debugging shows that it is not copied in ${CALLERID(all)} nor ${EXTEN}, I
had to revert to this hack, which works great:

exten => s,1,Log(NOTICE, Incoming call from sipcall-trunk ${CALLERID(all)} to ${EXTEN} DID ${SIP_HEADER(To)})
exten => s,n,Set(DID=${SIP_HEADER(To):})
exten => s,n,Set(DID=${DID:5:11})
exten => s,n,Log(NOTICE, Parsed DID: ${DID})
exten => s,n,Goto(sipcall-trunk,sipcall-${DID},1)
exten => s,n,Hangup()

I then have individual sipcall-NUMBER handling the actions for the individual numbers.

Is there a simpler way? Is there a safer way (check that DID only contains numbers, e.g.?)

Thank you for any ideas or pointers.