Subscribe
Lync,Exchange,VoIP,telephony

Using Asterisk to pass and receive SIP calls from Microsoft OCS to a SIP Trunk in UDP

August 04, 2009 By: Yann Espanet Category: Hardware Device, Interoperability, SIP trunk

Enabling Any SIP Phone & Any SIP Trunking Service Provider with OCS 2007 R2 !

Goals of the demo :

Use asterisk like a UPD/TCP translator between OCS and a SIP trunking services in UDP mode.

  • make calls from Microsoft Office Communicator to the sip trunk
  • dial froma external mobile or a PSTN phonetrough the sip trunk and answer the call on eithera hard or soft phone or Office Communicator.
  • control forwarding and simultaneous ringing options from the Communicator

I use Asterisk 1.6 which support TCP and UDP installed on CentOS 5 – Kernel 2.6.18

Installation steps :

  1. Add a mediation server to the OCS infrastructure
  2. Add an asterisk server
  3. Configure Mediation server to use the asterisk box
  4. Resolve NAT problem (if needed)
  5. Create two SIP trunks :
    1. Asterisk to OCS
    2. Asterisk to SIP Trunk service
  6. Define the context used by this trunks
  7. Configure follow me
  8. Test the infrastructure

Basic schema :

OCS R2 —- Mediation —- Asterisk —— Firewall — SIPTrunk
MTLS —- TCP —- UDP —- NAT —– UDP

I use Hyper-V for the two OCS servers and VMware for the Asterisk server.

Step-by-steps

Step 1 : Add a mediation server to your infrastructure

  1. Install a mediation server
  2. Configure certificate
  3. Add the OCS reskit tools (useful for troubleshooting)
  4. Create a dial plan
  5. Create a location profile with two normalization rules.
The first will be use for internal numbering and the second is a generic rule that redirect all call that do not correspond to a valid extension number in OCS to the default gateway.
Internal : OCS user have an three digit extension beginning by 2
Phone pattern : ^2(\d{2})$
Translation pattern : +2$1
Generic rule : All number are concerned (be careful to put this rule in second position in your location profile)
Phone pattern : ^(.*)$
Translation pattern : $1
Assign your location profile to front-end server (properties of the pool / properties of front-end / Voice Tab)
NB : Test your dial plan using the Enterprise Voice route helper

The first will be use for internal numbering and the second is a generic rule that redirect all call that do not correspond to a valid extension number in OCS to the default gateway.

  • Internal : OCS user have an three digit extension beginning by 2

Phone pattern : ^2(\d{2})$

Translation pattern : +2$1

  • Generic rule : All number are concerned (be careful to put this rule in second position in your location profile)

Phone pattern : ^(.*)$

Translation pattern : $1

Assign the location profile to the front-end server (properties of the pool / properties of front-end / Voice Tab)
NB : Test your dial plan using the Enterprise Voice route helper

Step 2 : Add an asterisk server

  1. Download trixbox 2.2 Virtual Appliance from VMware website http://www.vmware.com/appliances/directory/939
  2. Configure basic settings (Ip address, ..)
  3. Add this line in the begining of sip.conf

tcpenable = yes
bindport = 5060

  1. Access the web Trixbox interface (use Mozilla) In system menu / Network / Configure IP, Subnet, DNS and a valid hostname on internet : Ex : sip.mydomain.com

Step 3 : Configure Mediation server to use the asterisk box

  1. Open the properties of your mediation server verify that :
  2. in General tab : the gateway listening port is 5060
  3. In next hop connections tab : put the IP address of your asterisk server in PSTN gateway next hop with 5060 for the port number

Step 4 : Resolve NAT problems (if needed)

  1. In Asterisk, Go to PBX / Config File Editor / and edit SIP_NAT.conf

nat=yes

externip=Valid_FQDN

localnet=Your_Localnet/Your_Subnet

  1. Open in your firewall port
    • 5060 in UDP and TCP for SIP
    • RTP: 10000 to 20000 UDP
  2. Verify that you can see you valid public IP in the Trixbox system status

Step 5 : Create two SIP trunk in Trixbox : asterisk to OCS and Asterisk to SIP Trunk service

  • Asterisk to OCS

Trunk Name : ocs

PEER Details :

host=ip-mediation-server

type=peer

qualify=yes

transport=tcp

insecure=very

port=5060

canreinvite=yes

fromdomain=yourdomain

context=from-ocs

Incoming Settings :

User context : (I put a OCS username here)

User details :

host=ip-mediation-server

type=peer

transport=tcp

insecure=very

port=5060

context=from-ocs

register string :

(leave blank)

  • Asterisk to SIP Trunk service

Trunk Name : siptrunk

PEER Details :

type=friend

disallow=all

allow=ilbc&speex&gsm&alaw&ulaw

username=username

secret=password

host=yoursipregistrar

canreinvite=no

context=from-siptrunk

Incoming Settings :

Clear all

register string :

username:password@yoursipregistrar (/yournumber if needded)

Step 6 : configure context

Edit Extension_Custom.conf and add a the end of the file :

[from-ocs]

exten => _X.,1,Answer

exten => _X.,2,Dial(SIP/${EXTEN}@siptrunk,,tr)

#include extensions-away-status.conf

[from-siptrunk]

exten => _X.,1,Set(numDialled=+${EXTEN:Number_of_X_to_ignore})

exten => _X.,2,Set(__FROM_DID=${EXTEN})

exten => _X.,3,Answer

exten => _X.,4,Dial(SIP/${numDialled}@ocs,,tr)

exten => _X.,4,Dial(SIP/${numDialled}@ocs)

Step 7 : Configure follow-me in Asterisk

Assign line number from your sip trunk to Asterisk extension and redirect to phone extension in OCS by using a # after the number.
DID number from your SIP trunk provider —> Extension in Asterisk —> Follow-me to OCS extention (use # after the number to precise that it’s external to asterisk)

Step 8 : Test the infrastructure

  1. Troubleshooting tools that you can use in Asterisk :
    1. Log as root with a terminal tools (putty) / Type asterisk –r / Type sip set debug on
    2. Assign a line prefix to test the trunk from a softphone directly connected to Asterisk
      Ex : Create a outbound route with “9|.” to test the trunk by dialing 9 before the number
  2. Troubleshooting tools that you can use in OCS :
    1. Eventviewer
    2. Use the Debug tools (right click your mediation server)
    3. MS Netmon
    4. OCS Route helper to validate your dial plan.

Have fun with that and leave me a message if encounter some problems!

It’s probably possible to do the same withother IP/PBX like : Freeswitch, OpenSer, SipxECS, …

Date : 04/08:2009 – Author : Yann Espanet – mail : yann@unifiedcommunications.eu

2 Comments to “Using Asterisk to pass and receive SIP calls from Microsoft OCS to a SIP Trunk in UDP”


  1. Thanks Yann. I would love to see a demonstration. We are certified Microsoft voice partner located in souther California and we would love to be able to offer this to our clients.

    1
  2. Hello,

    I can’t dial from OCS to Asterisk, but i can dial from asterisk to ocs

    2