Using FreeSWITCH as a TCP/UDP bridge for Lync

In our Lync lab, we are always running into scenarios where we would like to test various functionality against known VOIP providers and equipment.  This usually results in an increased levels of frustration as Lync does not play well in the land of UDP SIP.  Enter FreeSWITCH.
Over the past two years, we have cooked up several FreeSWITCH configurations which support:

  • UDP to TCP bridging which allows Lync to work with VOIP providers such as FlowRoute and PBXs such as 3CX.
  • Full NAT support for those times when you just have to be behind a firewall.
  • Much better support for direct inbound (private) phone numbers into a Lync system using extensions.
  • Support for non-Lync conference phones such as the Polycom IP 6000.
  • Support for Lync 2010 as well as Lync 2013!

Disclaimer
The configurations documented in this article are non-standard and, as such, are not supported by any of the vendors referenced within.  These configurations are designed in, and for a test environment.  Utilizing these configurations in a production environment will be undertaken at your own risk.
(OK, with that out of the way, on to the configurations)

IMPORTANT:  It is recommend you read and understand this entire blog entry before making configuration changes… it’ll make your life much easier.

Article Assumptions about Lync Versions
Lync 2010, 2013, Enterprise, and standard, oh my!
For brevity, this article was written using screen shots of a Lync 2013 Standard Edition install.  Most configuration instructions will directly apply to Enterprise Editions as well as Lync 2010 with some minor tweaking.

Prerequisites

  1. A functioning install of Lync front end server
  2. A DNS entry pointing to the location running FreeSWITCH
    NOTE: In this article, the DNS entry is FREESWITCH.MYCOMPANY.COM
  3. Coffee or your caffeine of choice.

Configuring Lync Topology

  1. Launch Lync Server Topology Builder and load the current topology.
  2. Drill down to Mediation pools and highlight the mediation pool which will service outbound calls.
  3. Check the Enable TCP port and verify the TCP port range is set to 5068 – 5068image
  4. Close the dialog
  5. Drill down to Shared Components –> PSTN gateways
  6. Right click on PSTN gateways and select New IP/PSTN Gateway from the menuimage
  7. At Define the PSTN Gateway FQDN, enter your FreeSWITCH DNS entry
    our example is FREESWITCH.MYCOMPANY.COM
    image
  8. At Define the IP address, take the defaults
  9. At Define the root trunk, make the following changes:
    Set the SIP Transport Protocol to TCP
    Set the Listening port for IP/PSTN gateway to 5060
    Set the Associated Mediation Server port to 5068 (it should already be set, but check it)image
  10. Publish your topology

 

Configure Lync Voice Routing

  1. Launch the Lync configuration web page and select Voice Routingimage
  2. Click Trunk Configuration, double click the Global record
     image
  3. Set the following details for the trunk configuration
    Encryption support level to Not Supported
    Refer support to None
    Uncheck Enable media bypass
    Check Centralized media processing
    Uncheck all others.
    image
  4. Click OK to save the trunk configuration
  5. Create PSTN routes to your preferences
    See http://technet.microsoft.com/en-us/library/gg399027.aspx for complete details

 

Configure FreeSWITCH

  1. Install FreeSWITCH using the Complete / Full option
    IMPORTANT: Be sure to install FreeSWITCH on the server pointed to by your DNS entry!
  2. Locate the \conf directory under the FreeSWITCH install and delete ALL the files
  3. Download the FreeSWITCH XML configuration file
    Configuration file (.ZIP’d) is available at http://blog.armgasys.com/wp-content/uploads/2013/05/FreeSWITCH-with-Lync-Configuration.zip
  4. Modify the FreeSWITCH configuration file to meet your needs and copy it into the \conf directory
    See FreeSWITCH Configuration XML below for more details
  5. Locate the FreeSWITCH Multi Protocol Switch service and set the service to Startup type of Automatic

FreeSWITCH Configuration XML

Include Section

  • published-name=SIPGateway
    This defines the name FreeSWITCH will respond with during SIP communication.
    Can be set to any value you desire
  • inbound-sip-port=6000
    The inbound SIP port used by external VOIP traffic.
    Make sure you configure you VOIP provider to communicate with FreeSWITCH using this port.
  • outbound-sip-port=5060
    The port used by your internal Lync and VOIP devices.
  • codec-prefs
    The default codec preferences for FreeSWITCH
  • internal-ip
    The internal IP for your FreeSWITCH server.
    Under a NAT/Firewall scenario, this will usually be a non-routable IP such at 169.1.1.1
  • external-ip
    The external IP address exposed outside your firewall

 

Inbound Gateway Profile
See <profile name=”Inbound”>

  • username=none
    Lync does not support user name registration.  Leave as none
  • password=none
    Lync does not support user name registration. Leave as none
  • proxy
    Set to the IP address and port of your Lync server.  I.E. 169.1.1.1:5068

 

Outbound Gateway Profile
See <profile name=”Inbound”>

  • username=none
    Username provided by your VOIP provider
  • password=none
    Password provided by your VOIP provider
  • proxy
    IP or URL of your VOIP provider
  • register=true/false
    Set according to your VOIP providers configuration.

 

Dial Plans
See the .XML file for example inbound and outbound routing.
NOTE: All examples assume Lync is configured with three digit extensions

FreeSWITCH, Lync 2013 and AppFabric
Astute observers will have noticed the inbound (outside your firewall) SIP Port is set to 6000 in the FreeSWITCH configuration file.  This is not by accident.  Lync 2013 uses AppFabric under the hood.   As of this writing of this article, AppFabric will attempt to use several ports between 5060 and 5080.  If FreeSWITCH starts BEFORE Lync, the Lync Server Front-End service will fail to start.  There are two solutions:

Solution #1: Make sure nothing other than Lync’s own services use ports between 5060 and 5080.
This is the solution we selected as it is quick and easy.

Solution #2: Make sure FreeSwitch starts AFTER Lync Server Front-End service has started.

 

Happy calling!

17 thoughts on “Using FreeSWITCH as a TCP/UDP bridge for Lync

  1. James Body

    This is good work – but I believe that configuring the FreeSWITCH platform as a PSTN end point will constrain you to narrow band codecs only (e.g. G.711 and/or MS RTA (8kHz)).

    In order to make use of WB codecs (G.722 (16kHz) or Siren (16kHz)) – I believe that it is necessary to set up the FreeSWITCH platform as an A/V Conferencing service.

  2. ArmgaSys Post author

    James,

    Great points. Codec negotiation is something which must be considered for any production quality installation.

    Reviewing FreeSWITCH documentation, the default is early negotiation between the A and B legs. This should always pick the best codec as support by each leg (including the wideband codecs you mention).
    See http://wiki.freeswitch.org/wiki/Codec_negotiation

    This, however, is a double edged sword. If your VOIP provider does not support wideband codecs, FreeSWITCH will have to perform transcoding between the A and B legs (not a good thing from a performance perspective). In our test bench scenarios, we always set the preferred codecs to those supported by the downstream VOIP provider (usually G.711-ulaw or G.729) to prevent transcoding via FreeSWITCH.

    We can’t speak to the using the conferencing service within FreeSWITCH as we have not played with the server enough to have in-depth knowledge. But our initial impression is the conferencing server will not solve the Lync to UDP VOIP provider issue.

  3. Karen

    Hello
    My Server have 2 NIC, one to local network, other to SIP provider.
    Can you help, how configure freeswitch.xml file.
    Thanks.

  4. admin

    Based on the multi-home documentation
    (see: http://wiki.freeswitch.org/wiki/Multi_Homed_Dual_NIC_How_To)

    Add the following lines to both of the following Profiles
    <profile name=”Inbound””> <Settings>
    <profile name=”Outbound”> <Settings>
    sections:

    <param name=”force-register-domain” value=”$${public-ip}”/>

    WARNING: These configurations have not been tested in our Lync Lab.

  5. Robin

    This certainly helped me out. One note though, if you have a sip trunk from a provider that requires registration, you need to add a second gateway to the inbound profile, else it will always process the outbound one.

    Now, I can call/connect to and from my mobile using lync 2013, … but there is no sound. Any idea where to begin to look on this one?

  6. ArmgaSys Post author

    Regarding Lync 2013 on your mobile: because I don’t know your setup and configuration I will tackle the two most common issues.

    1st: If you are using Lync2013 Mobile client you must have a Lync edge server installed and configured. See http://social.technet.microsoft.com/wiki/contents/articles/16931.installing-lync-2013-edge-server.aspx for more details

    2nd: If you are just making VOIP calls using your cell phone as a test device and have no audio then you have a firewall problem. In 99% of our client’s cases when audio failed, the issue was tracked to a firewall blocking the RTP traffic.

  7. Robin

    I was using option 2 actually. Firewall was wide open on every device/server, since that is indeed the first thing you might expect. After sifting through the logs, I found an sdp error (unable to decode or some such). In the end I found that turning on the refer option (either choice) in the Lync trunk configuration, did the trick. Tested it several times, so if that helps anyone.

    Im still struggling with the inbound/bound configs though. Adding a second gateway works for just inbound traffic (because of the registering requirement I mentioned earlier), but messes up the outbound one when you add it (it will just grab the first declared sip gateway). Its not really clear what triggers the sequence; is it the gateway declaration or the dial plan?

  8. Robin

    After some more experimenting, it seems it is not possible to have the in/outbound context approach this way, when you need to register your sip trunk. Unless you register on two different ports, or do something messy with port forwarding in the firewall (not even completely sure it that will work even).

    The way I solved it, is just one profile, with 2 gateways. Then in the dialplan you filter out what is inbound and outbound (for instance on your assigned number block or the user agent).

  9. Sanjeev

    I am trying to configure SIP trunk with FreeSwitch but not working. I have one Lync mediation server with Two Interface (10.1.0.1 Towards Internal and 10.1.2.1 towards SIP trunk Provider) I have installed Lync mediation role and FreeSwitch on same server. I am trying to dial my trunk ID and needs that call forward to internal Lync server (10.1.0.2) to connect from conference.Could you please help me a sample configuration?

  10. ArmgaSys Post author

    Sanjeev,

    The FreeSwitch configuration should be the same as a single homed (single NIC) setup. You treat everything in the configuration based on the external IP (I.E. FreeSwitch talks to the external IP only). The mediation server is then responsible for forwarding the VOIP traffic to the internal network.

    We recommend reviewing mediation server dual-home configuration and setup to verify your mediation server is correctly routing traffic. See Google: https://www.google.com/#q=lync+mediation+server+dual+homed.

    Good Luck!

  11. Bernhard

    Hello,

    I still have trouble with two nic setup… although only with external IP for both (internal and external) the setup works, but I already found some robots trying to misuse…

    Adding a second NIC or just a second non routeable IP on the nic breaks the config, and nothing works anymore..

    Currently it’s ok because no (payable) outbound is defined….

    Where to but what (exactly please) to get a two nic setup running…

    and btw: why an internal address… as far as I understand the mediation server only listens on the external IP ?!?

    Thanks Bernhard

  12. ArmgaSys Post author

    Bernhard,

    We would love to be able to give you exact advice regarding your configuration issues. But, we have no clue what your configuration looks like in its entirety 🙁

    Our recommendation for complex configurations is to contact your Lync integrator, FreeSWITCH support, or our ArmgaSys support team. It won’t be free, but it will be a much more detailed review of your situation and will have much better odds of resolving your issues.

  13. David

    I am setting this up with a new Sip provider and lync 2013. This is all new to me so I have some questions if I remove all the files from the conf directory how will the Freeswitch.xml use Sophia codecs and Vars.xml contains the Master password that I will need to lock down the software since it will be internet facing. Also feel free to direct this newb in a direction that will guide me through this nightmare. Thanks

  14. NonekDan

    Great write up on this..
    I am having an issue with running your config though. It will load but then I get a big red con’t load switch.conf.. Have you ever seen that? I’m somewhat new to freeswitch and I was hoping that there would be a line number or something in the error that would direct me, but of course that would be too easy.
    Things that might affect this are the fact that I’m running 2012 R2 with the latest version of 64bit freeswitch.
    I actually managed to get this working with Lync at work but my home lab is proving to be more of a challenge.
    Anyway.. I’m sure i’ll have other things to work out, but I just want your config to load. I actually started chopping out your lines to see if there was a typo or something that it doesn’t like, but after cutting it down to almost nothing it’s starting to look like maybe something that is getting loaded normally that isn’t with your config..
    Anyway.. I plan on trying 32bit, but I’m stuck with windows as that is my Hyper-v server that is also my gateway and my AD / Lync environment / routing and remote access server..
    This is my attempt at a fully functioning Lync implementation on a single IP and I’m close.. 😉

  15. Philipp Kayser

    Hi guys,

    the connection between Skype for Business 2015 and Freeswitch is working but it cant trandfer the calls correctly to placetel sip trunk.

    Could anyone help me?

    Best regards

Leave a Reply

Your email address will not be published. Required fields are marked *