کد:
http://blogs.breezetraining.com.au/mickb/2009/07/31/FinallyConnectedOCS2007R2ToTrixboxAsteriskToAPSTNPBX.aspx
I’ve been through many integration projects and I think now I’ve found a product more complicated than BizTalk.
For the last 6 weeks internally we’ve been ‘rolling out’ (more like dragging through the mud) an OCS/UM setup – it now finally works!!!! (Inbound/outbound and UM Voicemail).
OCS – goes from 1 sever to 3!
In this post I’ll aim to take you through linking a working OCS system to a Trixbox connected to MyNetFone (SIP Trunk provider). After countless weeks, forum posts and beyond weird error messages – I’ll simplify it for you.
Me – no OCS, SIP, Trunk, Asterisk expert – great developer, can look at network packets if I *really* have to.
I’m assuming you have OCS setup for IM and A/V between Communicator clients. The OCS Mediation Server is where we are going to focus a little bit also.
Ok – what I wanted to do…this sounds simple.
The Aim:

  1. OCS (Mediation Server) connecting to my Virtual PBX ‘PSTN’ so phone calls can go inbound and outbound.
  2. Create SIP Trunk ‘connection’ to our SIP Trunk ‘provider’ – in our case MyNetFone.
    SIP Trunks are similar to regular VOIP Accts, but a trunk allows you to have multiple voip numbers running over it. Similar to Proxy Servers for ‘http’ connections.

    Generally speaking the SIP Trunks going externally need some form of authentication with the external SIP Trunk provider. This can come in many forms from username/pass, to special ‘secrets’ being passed in certain packets.

    This took me some time to get right.
  3. Each user will be assigned a phone number (from the SIP Trunk) and all devices/phones/users will be managed by OCS.

The Problem(s):

  1. OCS talks SIP/TCP and ‘the rest of the world’ talks SIP/UDP. Some translator is needed here – raging debates about this, but essentially we’re dealing with the last 40 odd years of the evolution of telephony systems.

    In short – get Trixbox 2.8… based on Asterisk 1.6 this DOES the translation.
    (Trixbox performs a huge array of functions, but with OCS in place we really need it only to do about 5% of it’s feature set – hence alot of the menu items we needed worry about)
  2. The bits you’ll need before you start:
    1. IP:X = IP address of your Mediation Server (if your server has multiple IP Addresses select the IP Addr that will be sending out (eventually) your Trixbox
    2. IP:Y = IP address of your new Trixbox Server (to install)
    3. External SIP Trunk Details (or VOIP acct details)
    4. OCS 2007 R2 Resource Kit Tools installed on the Mediation Server - http://www.microsoft.com/downloads/details.aspx?familyid=9E79A236-C0DF-4A72-ABA6-9A9602A93ED0&displaylang=en
      - great log analyser tool called snooper.exe
    5. Putty.exe – this allows you to ‘rdp’ onto your new Trixbox (as this is a linux box)
      http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
  3. Plan of Attack – what I’ll walk you through below.
    1. Installing Trixbox – taking a fresh install and configuring.
    2. Turning on SIP/TCP support in Asterisk 1.6
    3. Creating 2 SIP Trunks in Asterisk 1.6
    4. Configuring the Next Hop Properties in OCS Mediation Server
    5. Check the Settings in the Asterisk World.
    6. Creating the Routing between the 2 Trunks by editing the Extensions_Custom.conf file.
    7. Sample successful outputs.

  4. Installing Trixbox
    This piece is pretty simple – for our test case I installed this onto a Virtual Machine (in practice it’s generally advisable to install this on a physical machine, as the trixbox needs to use codecs and encode/decode which a typically time dependent)

    It’s an ISO so install it as you would any other ISO – it in a unix box but don’t be nervous, the Trixbox guys have put a great web interface over alot of the underlying stuff.

    Important to note:
    Seeing Trixbox is open source and is based on another product called ‘Asterisk’, which in turn has components such as FreePBX and others, sometimes reference material for FreePBX may be applicable to your Trixbox.

    NOTE: I called my trixbox = xlator

    Installation Complete:
    Once initial installation is complete (if installing to a VHD the size is around 6GB), you should be able to go a browser and do:

    (at some point you’ll probably want to change your ‘root’ password and also a user called ‘maint’ which is used in the webinterface to perform admin tasks)

    http://xlator (the default install will also setup https://xlator for you)


    As shown, we’re interested in switching to ‘maintenance mode’ clicking switch in the top left hand corner.
  5. Configuring the Trixbox environment
    1. As I mentioned earlier, we’ll only use about 5% of what Trixbox does. There’s some really key areas to make sure are setup and I’ll show you what they are.
    2. Turning on SIP/TCP capabilities for Asterisk
      Currently this isn’t a web interface checkbox, we need to modify a file called sip_general_custom.conf found in the /etc/asterisk directory.
      (the web interface has web config editor which we’ll use later with so many config files we can edit, *unfortunately* SIP.CONF isn’t one of them.
      1. Fire up Putty.exe (from your windows client) and type the address of your Trixbox in
      2. and hit OK, (you may be asked to OK a Security Token with the remote machine – part of SSH, just OK that)
      3. Login with root and the password you setup during the install. (welcome to the world of command lines – brings back the uni days, grep, ls, chmod…. gee how I missed it)
      4. cd to the /etc/asterisk directory as follows
      5. Type nano sip_general_custom.conf and add the following lines:

      6. Press Ctrl-X then Y then press return to complete the save (pretty simple here really)
      7. Type cd /root to return back to your home directory.
      8. Listen to Asterisk with the Command Line Interface. This is sort of the interactive debugger in Asterisk.

        type asterisk –r

        this will show you what asterisk is doing when it receives calls and trys to dial them out.

        sip set debug on – lets you see what’s happening with SIP packets.
        sip set debug off – turns if off.

        *** VERY VERY HANDY when trying to establish connectivity ***
      9. (another folder of interest is the LOGS directory /var/log/asterisk – handy to keep in mind, but the web interface lets you see the logs)

    3. Add your OCS ‘Connection’ or SIP TRUNK
      1. From the Admin Web Interface select PBX Settings (this and PBX Status are the 2 main areas we’ll go into)
      2. On the next page under Basic (on the LHS Menu) select Trunks
      3. Select Add Trunk –> Sip Trunk and fill in as follows:
      4. Leave everything blank or default except for the following sections:
      5. Key information above:
        1. Trunk Name – Connect-with-OCS. This name is used later to basically ‘route’ incoming calls from our ‘external’ SIP trunk to internal. (you can call it your own name if you like – just keep things simple)
        2. context=from-Super-OCS. In all my troubles, contexts in Asterisk are the solution. This I set so that it won’t conflict with any other ‘system’ contexts (e.g. from-pstn, from-internal).

          When a call is received via the trunk, in our case from OCS mediation server sending out, Asterisk will associate a context with it (if not, you’ll get ‘received number from an unknown peer’)

          The key here is that we will create a section in a config file that will allow us to define *exactly* what happens around this context. (this piece took another week)
        3. host=10.1.1.30 – this should be the IP Address of YOUR MEDIATION server. Asterisk will use the IP address of the incoming SIP request to try and associate it to a context, without this entry, your request will come from unknown.
        4. Inbound/Outbound – inbound messages are messages received at Trixbox FROM OCS. Outbound Messages are messages send to OCS FROM Asterisk. They are then given a context and any other details needed.

      6. Save the above configuration by going to the bottom of the page and clicking Submit Changes.
      7. You should have your first Trunk (don’t apply changes yet, we’re creating another Trunk)

      8. Notice these names above (I’ve got the 2nd one added too, you’ll have 1 at this point)

        Later we will ‘Dial’ calls out to these trunks with syntax like:
        Dial(SIP/<the number/extension>@Connect-with-OCS)

        (took me 2 days to find that gem)

    4. Creating your External Trunk – MyNetFone (in my case)
      This is where alot of the magic happens for the REGISTER SIP packets – if you have trouble with your external provider, sit with SIP SET DEBUG ON in the ‘asterisk –r’ interface in the PUTTY app to try and make heads or tails of it.

      Also you can see failures in the logs and your SIP Trunk won’t be registered in the PBX Status screen.
      1. Click on Add Trunk –> SIP Trunk
      2. Fill it in as follows (for MyNetFone) (took me a bit of trial and error)
        1. General Settings
          1. Outbound CallerID: "61555555555" <sip:61555555555@<your public IP>

            the 6155… number *should* be replaced with your own number allocated to your TRUNK.

            Your public IP is potentially NAT-ed from your Trixbox to the outside world. The web admin will show you your Public IP in the Top RH Corner.
          2. Never Override CallerID=checked
            (I’m currently still playing with this setting, but this works for now)

        2. Rest defaults until
        3. Outgoing Settings
          1. Trunk Name=MyNetFone (important to remember your name)
          2. PEER DETAILS
            1. disallow=all
              allow=alaw&ulaw
              authname=61555555555
              canreinvite=yes
              dtmfmode=rfc2833
              host=sip20.mynetfone.com.au
              insecure=very
              nat=yes
              pedantic=no
              qualify=yes
              type=peer
              username=61555555555
              fromdomain=sip20.mynetfone.com.au
              context=from-MyNetFone
            2. Note the context=from-MyNetFone which is one of the most important things here.

              Also the ‘canreinvite=true’

              Note: 61555555555= should be replaced with <your user name or phone number>
            3. In honesty this section took me about a week to work out – nat on, off?? tweaks here and there. You’ll see other posts that include ‘secret=…’.
              My setup didn’t require this.

          3. Incoming Settings
            1. User Context=from-MyNetFone
            2. USER DETAILS
              1. canreinvite=yes
                fromuser=61555555555
                insecure=very
                qualify=no
                type=peer
                username=61555555555
                host=sip20.mynetfone.com.au
                context=from-MyNetFone

              Note: 61555555555= should be replaced with <your user name or phone number>

          4. Registration
            1. Register String = 61555555555@sip20.mynetfone.com.au/61555555555

        4. Click Submit Changes to save your work.
        5. Click Apply Changes to apply changes
        6. You may get a warning – continue with Reload.

    5. Well done – at this point we’ve setup 2 trunks and we now need to ‘route’ calls between the two.

      Trawling the forums, if you set the context to from-internal any call received on the Trunk, Asterisk will examine all other trunks for a possible match. Let’s not confuse the issue right now
    6. Let’s Config OCS Mediation at this point – we can really do this any time, but the screen shots I’m showing you shortly will have OCS Mediation plugged in. So let’s do it.
      1. Jump onto your OCS Mediation Server and open up the OCS Server Admin tool as follows:
      2. Points to Note here: we’re interested in the next hop settings.
      3. Right Click on your Mediation Server and select Properties.
      4. Configure as follows:
      5. Under PSTN Gateway next hop – the address: xlator
        (you should have internal DNS resolution to your trixbox)
      6. Click OK and restart the Mediation Service (right click on the server and select stop, then start)
      7. Let’s flick back to the Web Admin of the Trixbox to see how things are going.

    7. Check that all things are setup and working – mainly your Registrations.

      1. The Web Admin in Trixbox gives a detailed view of what’s going on, also your Putty.exe session should be chatting away nicely – what it means, is another story!
      2. From the Web Admin –> PBX –> PBX Status to see something like…

      3. The Key areas that you need to keep an eye on are:
        1. SIP Peers – make sure that under Hosts there are no Unknown(s), as call routing won’t work the way I’ve outlined.
        2. Our connection with OCS doesn’t need to be registered.
        3. Our External Registration *should* be Registered by now – if not, go back to your trunk and configure the Outbound Settings and the Register String at the bottom of that page. ** DON’T MOVE ON UNTIL THIS IS COMPLETE **

      4. If you’ve set your dialing rules up in OCS on the Mediation Side, you should be able to dial a number and see activity in the Trixbox logs and in your Putty Terminal.
      5. Almost there…..

    8. Setting up Call Routing between our two worlds.
      At this point we could setup a bunch of extensions, inbound routes, outbound routes etc – and I did do that the first time through (10 users, 10 numbers, inbound routes etc etc – just pain).

      I thought there’s got to be a better way and here something that took 1 week to figure out – Trixbox forums are a great place to start with all of this, but they tend to be focused around building Trixbox out as the ‘OCS equivalent’, setting up receptionists, etc etc. I found I was spinning my wheels alot here, make a tweak, doesn’t work, read the forum, make another change, go back and redo a change etc.

      Here’s the simplest solution I’ve found: (for the code syntax – this was a great place to start)
      1. From the Web Admin select PBX –> Config File Editor and select extensions_custom.conf

      2. (you will have to scroll down this list, but it’s there)
      3. Scroll to the bottom of this file until you find the line
        #include extensions-away-status.conf
      4. Insert this code above that line.
        1. Setup OCS/Communicator clients Dialling OUT
          1. [from-Super-OCS]
            exten => _X.,1,Answer
            exten => _X.,2,Dial(SIP/${EXTEN}@MyNetFone,,tr)
          2. What does this do??? yeah good question…had to ask myself that as well.

            Ok – hopefully you recognise the from-Super-OCS text in []. Remember from our OCS Trunk, anything that Asterisk/Trixbox receives FROM OCS via that Trunk was associated with this Context.

            So what we’re saying here is that “If you have a message from from-Super-OCS do the following steps”
            1. exten => _X.,1,Answer

              exten = something to do with when Asterisk goes searching for the right extension that matches the one that it has been given.

              _X. = saw this on a few other config files, it’s part of a dialing plan, X=any digit, . = any number of following digits.

              This will match *all* numbers dialled.

              _ = no idea (maybe some pattern match)

              ,1 = believe it or not, this is how we say “run me 1st”

              Answer = predefined function or application that will pickup the call. We can then work out what to do with the call.
            2. exten => _X.,2,Dial(SIP/${EXTEN}@MyNetFone,,tr)

              _X. = match all numbers.

              ,2 = run me 2nd

              Dial(SIP/${EXTEN}@MyNetFone,,tr) = here we’re dialling a SIP trunk – called SIP/MyNetFone. Later if you look at your SIP TRUNKS page, you’ll see your Trunks listed this way.

              What I wanted was SIP/<number to dial>@<outgoing trunk name>

              ${EXTEN} = variable that holds the ‘extension’ dialled from the communicator client. This is the phone number.

              NOTE: sometimes parties at the other end of the trunk want a certain dial prefix e.g. +61…
              you could use something like:
              Dial(SIP/+61${EXTEN}@MyNetFone)

              The '+61’ & ${EXTEN} get appended together in the above line.

              ,,tr = something to do with allowing the calls to be transferred.

              I originally didn’t have this, and my inbound calls to OCS worked, then when I tried to transfer them the Exchange UM Voicemail, they hung up.

              I added this in for inbound and Exchange Voicemail worked, so I figured it can’t hurt for outgoing.

              How fiddley is all this stuff!!!

        2. Setup External Calls Coming to OCS

          According to my OCS Expert buddy Dan, our internal OCS setup is such that all extensions have a +61… appended to them. the ‘+’ in ‘+61’.

          Checking on the ‘asterisk –r’ interface, MyNetFone will pass 02… and not +612…. So I needed to do a little tweaking of these numbers.

          Here’s the result
          1. Below the code you’ve added above add this.
            [from-MyNetFone]
            exten => _0X.,1,Set(numDialled=+61${EXTEN:1}) ;get all but the first digit from the Extension dialled.
            exten => _0X.,2,Set(__FROM_DID=${EXTEN}) ;sets a global variable.
            exten => _0X.,3,Answer
            exten => _0X.,4,Dial(SIP/${numDialled}@Connect-with-OCS,,tr)

            exten => _X.,1,Set(numDialled=+61${EXTEN})
            exten => _X.,2,Set(__FROM_DID=${EXTEN})
            exten => _X.,3,Answer
            exten => _X.,4,Dial(SIP/${numDialled}@Connect-with-OCS,,tr)
            Note: firstly from-MyNetFone in the above code, once again this is the context from our corresponding Trunk.
            exten=> _0X.,1,Set(…) = the _0X. here will match all the numbers passed to us from MyNetFone with a ‘0’ at the front.
            e.g. 02… – so I need to strip the ‘0’ off and add +61(0)2…

            Here I created a local variable called ‘numDialled’ to hold the translated number. You can see the ‘+61’ added to ${EXTEN:1}.

            ${EXTEN:1} = give me all numbers except the first.

        3. Your file should look like this now:
          1. [from-Super-OCS]
            exten => _X.,1,Answer
            exten => _X.,2,Dial(SIP/${EXTEN}@MyNetFone,,tr)
            [from-MyNetFone]
            exten => _0X.,1,Set(numDialled=+61${EXTEN:1}) ;get all but the first digit from the Extension dialled.
            exten => _0X.,2,Set(__FROM_DID=${EXTEN}) ;sets a global variable.
            exten => _0X.,3,Answer
            exten => _0X.,4,Dial(SIP/${numDialled}@Connect-with-OCS,,tr)
            exten => _X.,1,Set(numDialled=+61${EXTEN})
            exten => _X.,2,Set(__FROM_DID=${EXTEN})
            exten => _X.,3,Answer
            exten => _X.,4,Dial(SIP/${numDialled}@Connect-with-OCS)
            #include extensions-away-status.conf

      5. Click on Update to save the file.
      6. Click on ReRead Configs from the top menu. You may need to scroll to the top.
      7. You’re Asterisk/Trixbox is ready to go!

    9. What Successful Calls Look like here: (you can get these from your Putty session, running ‘asterisk –r’
      1. OCS client going OUT

        1. I’ve scrubbed the actual number dialled, but you can see where the number appears, the fact we Answer, and then Dial.

          Also where the ‘Contexts’ appear.

      2. Inbound to OCS



In conclusion:

Hopefully this will help unravel the huge mystery on how to connect these systems together. There’s many other ways this can be achieved, and I’d love to say it’s the silver bullet for this, but there’s just so many factors in your solutions.
This should certainly get you a large step down that path.
Good luck.
Mick.





موضوعات مشابه: