Wednesday, June 12, 2013

How to Integrate Microsoft Lync 2010, Asterisk, and a sip trunk.


Objective:
  • Setup Asterisk
  • Configure a SIP trunk between Asterisk and the SIP provider of your choice.
  • Integrate Lync Server 2010 with Asterisk
  • Configure a dial plan

Requirements:
  • I’ll be using Windows 2008 R2 hyper-v to run Lync server 2010 and Asterisk.
  • You should assign a minimal of 2gb of memory to Lync and 512mb to Asterisk.
  • You’ll need to obtain a SIP trunk from a SIP trunk provider. In my case I’m using Thinktel.
You will need to download a copy of AsteriskNow, I opted for the 64-bit version here. While it’s downloading create your VM if you have not already done so.
Create a name. I’m using the ever popular Asterisk.
image
Set memory (512mb)
image
Don’t connect to your network, Running Linux on Hyper-v requires a legacy network adapter which we will add after the VM is created.
image
Accept the default options when configuring the virtual disk. If this was a production system we would check something else for what we are doing the default is fine.
image
I chose install the operating system now. You’ll want to select “Install an Operating system from a boot CD/DVD-ROM” and choose the previously downloaded Asterisk ISO.
image
Hooray, click Finish and we have a VM.
Before we start the Asterisk Install, you’ll need to add the legacy network adapter. Go to settings select Add Hardware, Select Legacy Network Adapter. Select Add. Make sure it’s connected to your virtual network!!
image
In my case the network is titled Internal Lan.
image
Let’s start the VM. We will boot from the AsteriskNOW ISO and the install will commence. ….Select Option 5. “To Install with Asterisk 1.6, only.”
image
Select yes, to accept the creation of partitions and wiping of data
image
The default partition scheme is fine, select next, Set your region, select next and create a root password then click next.
image
The install will now commence, Time for a drink.
image
Once the install is complete eject the ISO via the hyper-v toolbar.
image
Once the boot sequence completes (it should end with [ OK ]. Upon completion you’ll see a setup agent, quit this and you’ll be presented with a logon screen. Login with your root account and start the network configuration utility, type system-config-network. You will then be presented with the screen below
image
Select “Edit Devices”, Select your device “eth0 – Digital Equipment Corporation DECchip 21140 [FasterNet]”, remove the DHCP option and set a static address, in my case 10.1.1.65.
image
Once you save back to the startup screen edit your DNS Configuration, add a primary server of your choice.
Save and now edit your DNS configuration. In my case I’m use a DNS server in my VM infrastructure.
Once your back to the command line type: service network restart this will result in the network service restarting and your settings taking affect.
Ping www.asterisk.org to make sure everything is working. If this fails you can always reboot the system with: shutdown –r now which will reboot.
to update Asterisk. Type: yum update asterisk16, accept the update package byinputting Y and hitting enter.
image
Once complete we are ready to configure the Asterisk PBX. You will need to edit a number of text files. You could use VI but if you don’t have prior experience with it there are some handy other tools to use. One such tool that will allow you to edit the tools from a windows PC is an SSH client called WinSCP. You can download a free copy from their websitehere. Once installed add a new site. Enter the IP address of your Asterisk Server, and the user name should read root
image
Change the default remote directory to /etc/asterisk see below and save the site.
image
Once saved click logon. The first time you connect you will be prompted to save your Asterisk server key, click yes to add the host key to your cache. Finally enter your password. Once connected a user friendly explorer type view of your Asterisk’s file system will be displayed.
image
First and foremost make a backup copy of your sip.conf and extensions.conf files. To do this right click on the sip.conf file and select copy. I copied mine to sip.conf.bak and do the same with extensions.conf.
We will be editing two files: (right click and “edit” within WinSCP)
  1. Sip.conf
  2. Extensions.conf for dial plans
  3. sip_nat.conf
First sip.conf, in the Device Configuration section replace the content of your file with the following settings.

sip.conf 

[1001]                         ; A locally attached SIP extension
type=friend
callerid=1001
canreinvite=no
dtmfmode=rfc2833
mailbox=1001
disallow=all
allow=ulaw
transport=tcp
secret=password
host=dynamic
context=default

[1002]                         ; A locally attached SIP extension
type=friend
callerid=1002
canreinvite=no
dtmfmode=rfc2833
mailbox=1002
disallow=all
allow=ulaw
transport=tcp
secret=password
host=dynamic
context=default

[Lync_Trunk]      ; Lync trunk
type=friend
port=5060         ; This is the default Lync Server TCP listening port
host=10.1.1.65    ; This should be the IP address of your Lync Server
dtmfmode=rfc2833
context=from-lync
qualify=yes
transport=tcp,udp

[Thinktel]
disallow=all
allow=ulaw
dtmfmode=rfc2833
fromdomain=vp.thinktel.ca
host=159.18.xxx.xx  ;You’ll need to modify this for your siptrunk provider
fromuser=780xxxxxxx ;This is what will show on outbound calls
username=780xxxxxxx ;Your username and
secret=yeah right   ;password.
nat=yes
insecure=invite,port
type=friend

[general]

static=yes
;
; if static=yes and writeprotect=no, you can save dialplan by
; CLI command "dialplan save" too
;
writeprotect=no
[globals]

[default]
;Routes calls originationg from asterisk with 1 followed by 3 digits
;to local extensions listed in sip.conf
exten=>_1XXX,1,Dial(SIP/${EXTEN},20)
exten=>_1XXX,n,hangup()

;Routes calls originationg from asterisk with 2 followed by 3 digits
;to Lync_Trunk
exten=>_2XXX,1,Dial(SIP/Lync_Trunk/${EXTEN},20)
exten=>_2XXX,n,hangup()

;This listens for sip end point connected directly to asterisk and
;will listen for traffic that starts with a 9 and send every digit
;after 9 to Thinktel for Asterisk
exten=>_9.,1,Dial(SIP/Thinktel/${EXTEN:1},20)
exten=>_9.,n,hangup()

[from-thinktel]
;This line "Set(CALLERID(name)=${CALLERID(num)})" sets the caller ID
;display field to the incoming 10 digit number otherwise calls
;would display as E164 or unknown on the client. 

;This line is a hack to trigger early media negoiation by playing
;a beep, it pokes a hole in the firewall with
;this command. "exten=>_.,n,Playback(beep,noanswer)"

exten=>h,1,Hangup()
exten=>_.,1,Progress()
exten=>_.,n,Playback(beep,noanswer)
exten=>_.,n,Set(CALLERID(num)=+1${CALLERID(num)})
exten=>_.,n,Set(CALLERID(name)=${CALLERID(num)})
exten=>_.,n,Dial(SIP/Lync_Trunk/+1${EXTEN},60)
exten=>_.,n,Hangup()

[from-lync]

;Routes with 1 followed by three digits to local extensions
exten=>_1XXX,1,Dial(SIP/${EXTEN},20)
exten=>_1XXX,n,hangup()
;send other calls to Thinktel for Asterisk
exten=>_+1.,1,Progress()
exten=>_+1.,n,Dial(SIP/Thinktel/${EXTEN:2},60)
exten=>_+1.,n,Hangup()

exten=>_XXXXXXXXXX,1,Progress()
exten=>_XXXXXXXXXX,n,Dial(SIP/Thinktel/${EXTEN},60)
exten=>_XXXXXXXXXX,n,Hangup()

sip_nat.conf

;External nat info
internip=10.1.1.65
externip=xx.xx.xxx.xxx
;Your external IP address goes here.
localnet=10.1.1.0/255.255.255.0

Once you have configured your sip.conf and extensions.conf and sip_nat.conf you will need to restart Asterisk. At the command line type Asterisk –r to load the Asterisk console and then type reload. Congratulations you have now installed and configured Asterisk. You will need to configure Lync.
Lync Configuration:
You will need to open the Lync Topology Builder. Most likely you do not have a PSTN gateway setup so that’s what we are going to do now.
Once you have downloaded the topology select PSTN gateways Select add new gateway. Enter the IP address of your Asterisk box. In my case 10.1.1.65. Select a listening port for the IP/PSTN Gateway: 5060. For the Sip transport protocol select TCP.
PSTN Gateway
Once you have added the PSTN gateway you will have to re-publish the Topology, this will update the existing Topology with the new configuration settings, click finish
Mediation_association
Your configuration should look like the above screenshots.
Configuring the Lync Voice Routes
To permit call flow between both Lync and Asterisk we need to define Voice Routing within Lync Server 2010. There are two ways to do this, either via the Lync Server Control Panel or via the Lync Server management shell. I am going to detail steps for both.
Define dial rules via the Lync Server control Panel.
Open the Lync Server Control Panel and access the Voice Routing options. We’ll need to configure our Dial Plan, Voice Policy, Route and PSTN Usage.
Select the Global Dial Plan
You’ll need the following normalization rules. 10 and 11 digit rules from Lync to Asterisk, a 1xxx rule for local asterisk extensions, a 2xxx internal extension rule. In my case I’m in the US so I want to normalize a dialed 10 digit or 11 digit number. Make sure you test your rules to make sure they work.
I’m really enabling three call paths here:
  • Giving users directly connect to Asterisk with a 1xxx extensions the ability to dial 2xxx directly to Lync.
  • Giving the ability for Lync users to call dial Asterisk users directly using 1xxx
  • Giving the ability for Lync users to make inbound and outbound calls using Asterisk as a back to back user agent.
image

Next the voice policy. The default Global Policy should have the following PSTN Usage records.
image
Add the routes:
image
You’ll need the following PSTN usage:
image
Creating Test users:
On the Lync server you’ll need a couple of test users. In my environment I have the following:
  • Mark Hanson with extension 2001
  • Reid Miles with extension 2002
  • Mike Ray with extension 7801234567 (this would be the number assigned via my sip trunk.)
Once you have the settings completed and the users created you should be able to make calls in the following directions:
Lync <> Asterisk
Lync <> Sip Trunk
X-Lite is a great free client you can use for logging into Asterisk to test with. You can download it from here
I would like to give a big thanks to Adam Jacobs who wrote How to integrate Lync 2010, Asterisk and Skype as inspiration for this post.

No comments:

Post a Comment