วันอาทิตย์ที่ 12 สิงหาคม พ.ศ. 2555

SBC Setup

Introduction

Below you'll find a step by step setup for installing FS as a SBC. The LCR engine is provided by Kamailio and its module carrierroute. Kamailio is an opensource SIP Proxy (not a B2BUA).In this setup, the dialplan is detailed only for inbound to outbound traffic, but it could be easily extended for outbound to inbound traffic (or DID).The design is the following:FS is configured with an internal and an external profile, each profile listening on a different network interface.Kamailio is listening on the loopback interface, and is not used by any other process than FS.

Internal--------FS--------External
|
|
Kamailio

When FS receives an INVITE, FS fires this event in the default context, where it always matches the extension named LOOKUP_ROUTE. In this extension, FS sends the INVITE to Kamailio, that will replies with a 302 Redirect SIP message that contains the route FS has to use to reach the number dialed. The call is then transfered in the context ROUTING where FS will match the associated Gateway (in this setup it is an associated code) that will route the call.If Kamailio has no route for the dialed number, it replies with a "604 unable to route the call" that FS will relay.So Kamailio is used only for route lookup by FS, and FS is the only equipment that is seen in the SIP transaction.

This design has been choosen cause I needed a way to store big LCR table (it's now more than 450 000 routes on the production server) and LCR module was not available when I began playing with FS (version 1.0.1).I extensively tested this setup on an Intel Quad Core server (Q9550 running at 2.83Ghz with 8GB RAM. 4GB should have been far enough).I ran some tests using SIPP with 750 simultaneous calls and between 50 to 100 calls per second (CPS) for more than 10 days with 25%-30% CPU ressource free. FS version was 1.2 at this time.

AdvantagesStable with quite huge routing table: Kamailio was using less than 3% CPU when doing the SIPP tests with 160 000 entries in LCR table.Scalable: some people are using carrierroute module with LCR table up to 1 million entries.Correct call per second rate: up to 100cps.

DrawbacksEach INVITE you send to FS will first send an INVITE to Kamailio, and once FS receives the Kamailio answer, FS will bridge the call to the Peer that will process the call.I'm feeling that if you want to process more call per seconds (more than 100 CPS), the fact that the Sofia library is monothreaded and that it has to deal with one more session (FS to Kamailio) before processing the call to the Peer could prevent FS to reach a higher CPS rate. (For everybody that has a better internal knowledge of FS than me, feel free to correct this assumption).

Other ways to go to achieve the same (not tested)Trymod_lcrthat has been introduced in FS 1.0.3 and report on the list and Wiki.Use the XML CURL module to process the call routing using your preferred script language running on yout HTTP server.

Check TCP or UDP services runningnetstat -tnlponly SSH (port 22) should be listeningnetstat -unlponly dhclient3 (port 68) should be listening (I need dhcp for my tests and to get an IP for administration of the test server)

Edit sip_profiles to use these IPcd /opt/freeswitch/conf/sip_profilesedit internal.xml and replace $${local_ip_v4} with internal IP (10.10.10.254)edit external.xml and replace $${local_ip_v4} and $${external_rtp_ip} with external IP (10.10.20.254)

Start FreeSWITCH/opt/freeswitch/bin/freeswitch -nc -hp-nc stands for no console-hp stands for high priority

Connect on FreeSWITCH via fs_cli/opt/freeswitch/bin/fs_cliwith this tool you'll be able to get a console connection to FSthe log level has not been changed so it could be very verboseto disable log, type /nolog in console

Then launch Kamailio utils to create database/opt/kamailio/sbin/kamdbctl createYou'll be prompted for root sql password (remember you used 1234 or ...) and don't forget to set yes for carrierroute table creation

You have inserted your first route, that will match prefix 1000 and route this to PEER_01 with a description, FRANCE in this example. PEER_01 will be defined later in FS dialplan. The description parameter could be exported, for billing purpose for example. In this setup, I'll export the description to an AREA variable in FS.

In fact PEER_01 is used as an index for a combination of peers. I do this to have a failover mechanism to a backup peer if the 1st peer is down.

You can load balance to different PEER combinations by using probability in carrierroute table. Ex: using 2 routes pointing to PEER_01 and PEER_02 with a probability of 0.5 and you will share the load between these 2 peers combination.

Test connectivity between FreeSWITCH and Kamailio

Test that FS and Kamailio are talking to each othersRegister an IP phone using credentials in /opt/freeswitch/conf/directory/default/1001 for exampleto dump traffic on the loopback interface for SIP messages between FS and Kamailiongrep -d lo -nn -W byline

When your phone is registered, dial 1000You should see this in the ngrep trace

Disable Presence Support in SIP_Profilesemacs /opt/freeswitch/conf/sip_profiles/internal.xml

<param name="manage-presence" value="false"/>

emacs /opt/freeswitch/conf/sip_profiles/external.xml

<param name="manage-presence" value="false"/>

Check that your Network Interfaces Cards (NIC) are not sharing IRQcat /proc/interruptsideally, your ethernet cards should be put on different IRQ, and if you have more than one CPU, you can force affinity of a NIC with a specific CPU (I will add a note later on this)

The last 2 columns are interesting:id: idle, same as before for mpstat, the higher is betterwa: waiting IO, when this number is high it means that your CPU is waiting for IO (ex: HDD with too much access) and it will have a negative impact on performance