How to Load Balance the SIP REGISTER

  • Avestan

    Avestan - 2010-10-11


    Can someone explain how the following code can be used in the Load-Balancing scenario to detect resources and carry the LB?

            # detect resources and do balancing
            if ($rU=~"^1") {
                    # looks like a Conference call
            } else if ($rU=~"^2") {
                    # looks like a VoiceMail call
            } else {
                    # PSTN call, but the GWs supports only G711
                    # for calls without G711, transcoding will be used on the GW
                    if ( !search_body("G711") ) {
                    } else {
    I don't understand how $rU=~"^1" means the call is a conference call and the same goes for $rU=~"^2"

    I have spent a decent time reading the OpenSER book by Flavio E. Goncalves and been searching online but I am unable to find any information.

    I am trying to use Asterisk Realtime for the SIP Registration while the OpenSIPS is used only for the load balancing.

    I think I need something similar to the following:

            if (is_method("REGISTER")) {
                    xlog(“Register process starts here! \n”);
                    load_balance(“1”, “reg”)

    While the information in the database is as follow:

    | id | group_id | dst_uri                | resources                                                   |
    |  1 |        1 | | reg=30; pstn=32                                  |
    |  2 |        1 | | reg=100; transc=10                            |
    |  3 |        1 | | vm=50; conf=300                                 |
    |  4 |        1 | | vm=10;conf=10;transc=10;pstn=32 |

    Thank you very much for your help.


  • Avestan

    Avestan - 2010-10-28

    I wish to use a combination of the OpenSIPS and Asterisk Boxes for SIP registration.  In this scenario I wish the Asterisk to act as the Registrar while the OpenSIPS is operating as a Load Balancer of the SIP registration.  In this scenario, I have the Two Asterisk Boxes for the High-Availability in addition that the SIP registration is load balanced between the Two Asterisk Boxes.
    This is the setting I would like to have:
    UAC ---> OpenSIPS  ---> Asterisk 1 and 2 ---> Location Server
    Initially, I tried the following which uses the variable $du to set the dst URI and send the Registration request to the Asterisk Box.
            if (is_method("REGISTER"))   {

                    $du = "sip:XXX.XXX.XXX.XXX:5060";

    In this scenario if the Asterisk Box goes down, no UAC would be able to make a SIP Registration. Therefore, I decided to add the second Asterisk Box and use the OpenSIPS to load balance the SIP Registration between the two asterisk boxes. In this case if one Asterisk box goes down, there would be the second Asterisk Box to deal with the SIP registration.

    I tried the load_balance module for doing this as follow:

            if (is_method("REGISTER"))   {


    While I have added the resource “reg” to the table “load_balancer” under the “opensips” database, as shown here”

    mysql> SELECT * FROM load_balancer;
    | id | group_id | dst_uri             | resources                             | probe_mode | description |
    |  1 |        1 | | transc=5; pstn=5; vm=5; conf=5        |          2 |             |
    |  2 |        1 | | transc=5; pstn=5; vm=5; conf=5; reg=5 |          2 |             |
    |  3 |        1 | | transc=5; pstn=5; vm=5; conf=5; reg=5 |          2 |             |
    3 rows in set (0.00 sec)

    Even though I don’t think this is a right way to do this, but I can get this working for few Registered/ Unregistered of a SIP UAC.

    The reason for the load_balance module not being the right module is evidenced under table “dialog”.

    Can someone tell me if the OpenSIPS is equipped with such a module for load balancing SIP Registration for the High Availability configuration?

    I am aware the I can have the second Asterisk Box with floating IP address and Heartbeat and mon  or similar software for server and service High Availability.  But I wish to do this as I explained at the start.

    Can someone point me to the right module?




Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks