Monday, December 17, 2007

Interim information on integration OCS and Asterisk

Disclaimer: This guide hasn't been tested and verified like the Exchange UM guide - it may not be 100% accurate. It is not a step-by-step detailed and assumes you know your way around trixbox, sipX and OCS, or at least have configured Exchange UM using my guide. It is provided only for early adopters that want to experiment in a test environment. It WILL NOT work with the trixbox version (2.2) used in the Exchange UM guide. See my post here on issues with Asterisk and OCS integration FIRST. Please feel free to provide comments, feedback and results of your own testing (via email please).

Overview: In order to make this work, we need to install the follow-me module in Asterisk, define a custom voicemail macro for follow-me, and configure some new dial rules in sipx. I use a single extension range (400-499), and use sipx to do some fancy number transformations to allow calls to flow back and forth correctly.

Step 1: Install the folllow-me module in freePBX.

Step 2:  Edit extensions_custom.conf and add the following code;

[custom-exchangevm]
exten => s,1,NoOp(Entering custom-exchangevm for a call to ${DNID})
exten => s,n,Set(EXTTOCALL=${BLKVM_BASE})
exten => s,n,NoOp(Sending to Voicemail box ${EXTTOCALL})
exten => s,n,SIPAddHeader(Diversion: <tel:${EXTTOCALL}>\;reason=no-answer\;screen=no\;privacy=off)
exten => s,n,Dial(
SIP/222@sipx.lithnet.local|30)

Step 3: Configure follow-me for your extensions. The extension list should contain both the extension number, and the extension number followed by a numerical prefix. I used the number 4. You can use whatever you want, as long as you can route it in your dial plan - adapt this guide as appropriate. Make sure the the external numbers are followed by '#' so the module knows it needs to route outside of asterisk. Select 'Custom app' for the no answer destination, and type custom-exchangevm,s,1 in the text box.

image

Step 4. Configure an outbound route. You can either create a new route to send 4xxx calls to sipx, or add 4xxx to your existing sipx route as shown below.

image

Step 5. Now we need to configure sipX to strip off the prefix ('4') we added, and replace it with a plus sign (+). OCS requires that numbers be in E164 format, I'm not going to go into that in detail, but for testing purposes, we can just add a + at the start of the number, and it will be happy.

Add the following to your /etc/sipxpbx/external_mappingrules.xml file.

   <!-- Asterisk-OCS Dial Rule -->
    <userMatch>
      <userPattern>4xxx</userPattern>
      <permissionMatch>
        <transform>
          <user>+{vdigits}</user>
          <host>ocs-med.lithnet.local</host>
          <urlparams>transport=tcp</urlparams>
          <fieldparams>q=0.9</fieldparams>
        </transform>
      </permissionMatch>
    </userMatch>

Add this to your external_authrules.xml file:

  <hostMatch>
    <!--OCS Mediation Dial Rule (IPs and hostnames of your OCS mediation and OCS comms server-->
    <hostPattern>ocs-med.lithnet.local</hostPattern>
    <hostPattern>192.168.0.80</hostPattern>
    <hostPattern>ocs-main.lithnet.local</hostPattern>
    <hostPattern>192.168.0.70</hostPattern>
    <userMatch>
      <userPattern>.</userPattern>
      <permissionMatch/>
    </userMatch>
  </hostMatch> 

Step 6: In the sipx web interface, add a new dial rule called OCS-Asterisk Dial Rule. In the dialed number field, put + as the prefix, and select ‘3 digits’ (or however many digits you have in your extension). Leave all the ‘required permissions’ unticked. In resulting call, leave the prefix blank, and select  ‘variable part of dialed number’. Select Asterisk as your gateway. Activate your dial plans and you are done.

image

Step 7: In the OCS Management console, right click on your mediation server, and click properties. Type the IP Address of your sipX server as the next hop destination.

image

Step 8: Configure users for PBX integration. Note the "+" before the number.

image

Step 9: Add an outbound route in OCS by right clicking on your forest in the OCS Management Console, selecting 'Voice Properties', clicking on the 'Routes' tab, clicking 'Add', and entering the information shown below. The regular expression basically says to route all calls to numbers beginning with a + to the Mediation Server.

image

Step 10: Add normalization rules. Back on the Voice Properties tab, click Location profiles and add a new profile. Add a new normalization rule. Use the information below to create a basic normalization rule. This example will take any 3 digit number starting with '4', and append a + sign to it. This gives us a number that is formatted and can understood by the dial rule we set up in step 9.

image

That should be it. Add other normalization and dial rules as required to accommodate your needs. OCS uses SIP/TLS for encrypted communication between OCS servers and clients by default. If you run into difficulties and need to troubleshoot, turn off TLS and you will be able to see the SIP packets, rather than encrypted TCP traffic.

Once again, I stress that this is not a complete guide. Just something to get started with, as many people have been asking for this. Please contact me via email if there are any errors you come across in this post.

5 comments :

Alvaro said...

maybe by "sipx" around your post you mean "either sipx or asterisk"... ?

Alvaro said...

sorry for previous post (I'm a newbie in VoIP)... didn't understand I're integrating Asterisk and OCS through SIPX. Actually I'm trying to integrate OCS and SIPX only (SIPX is used as IP-PBX also). I used your suggestions and I get calls from OCS to SIPX managed phones, but cannot do the reverse (call MOC from SIPX managed phones).

Any suggestion ?

Erik said...

Hi,
I noticed the same behavior (sending packets to RTP port 0). It seems to help if you make sure to let Asterisk send 'session in progress' packets with the correct SDP values before ít sends 'ringing'.

Erik@twiyo.nl
http://www.twiyo.nl/

drhookson said...

@erik: how do i convince asterisk to send this 'session in progress'. looking at my wireshark-trace i do not see any of "183 Session Progress" SIP packet.

besides the problem of sending to RTP port 0 also the destination address (which should be the asterisk box) is not correct. it points to the gateway inbetween and the only RTP packet sent from the mediation server (wrongly) to the
gateway has following payload:

00.. .... = Version: Old VAT Version (0)

any help is appreciated...

Ryan Newington said...

hi drhookson,

this is an unresolved issue at the moment.

http://forums.microsoft.com/unifiedcommunications/ShowPost.aspx?PostID=2392353&SiteID=57

ryan