[OpenSIPS-Users] Load Balance Working Script Issue

rajib deka rajibdk at gmail.com
Wed Dec 9 20:44:31 CET 2009


Hi Bogdan,

Will the following script work properly with probing mode 2 with two
asterisk gateways, we want to introduce it in our production environment.

route{

    if (!mf_process_maxfwd_header("10")) {
        sl_send_reply("483","Too Many Hops");
        exit;
    }

    if (has_totag())
    {
        if (loose_route())
        {
            if (is_method("BYE"))
            {
                setflag(1);
                setflag(3);
            }
            else if (is_method("INVITE"))
            {
                record_route();
            }
            route(1);
        }
        else
        {
            if ( is_method("ACK") )
            {
                if ( t_check_trans() )
                {
                    exit;
                }
                else
                {
                    # ACK without matching transaction ->
                    # ignore and discard
                    exit;
                }
            }
            sl_send_reply("404","Not here");
        }
        exit;
    }

    #initial requests

    # CANCEL processing
    if (is_method("CANCEL"))
    {
        if (t_check_trans())
            t_relay();
        exit;
    }

    t_check_trans();

    if (loose_route())
    {
        xlog("L_ERR","Attempt to route with preloaded Route's
[$fu/$tu/$ru/$ci]");
        if (!is_method("ACK"))
            sl_send_reply("403","Preload Route denied");
        exit;
    }

    # record routing
    if (!is_method("REGISTER|MESSAGE"))
        record_route();

    # account only INVITEs
    if (is_method("INVITE"))
    {
        setflag(1); # do accounting
        if(!load_balance("1","pstn"))
        {
            sl_send_reply("500", "Service full");
            exit;
        }
    }

    if (!uri==myself)
    {
        append_hf("P-hint: outbound\r\n");
        route(1);
    }

    if (is_method("PUBLISH"))
    {
        sl_send_reply("503", "Service Unavailable");
        exit;
    }


    if (is_method("REGISTER"))
    {
        if (!save("location"))
            sl_reply_error();

        exit;
    }

    if ($rU==NULL) {
        # request with no Username in RURI
        sl_send_reply("484","Address Incomplete");
        exit;
    }
    route(1);
}


route[1]
{
    # for INVITEs enable some additional helper routes
    if (is_method("INVITE"))
    {
        t_on_branch("2");
        t_on_reply("2");
        t_on_failure("1");
    }

    if (!t_relay())
    {
        sl_reply_error();
    };
    exit;
}

branch_route[2]
{
    xlog("new branch at $ru\n");
}


onreply_route[2]
{
    xlog("incoming reply\n");
}


failure_route[1]
{
    if (t_was_cancelled())
    {
        exit;
    }

    # uncomment the following lines if you want to block client
    # redirect based on 3xx replies.

    if (t_check_status("3[0-9][0-9]"))
    {
        t_reply("404","Not found");
        exit;
    }

    # uncomment the following lines if you want to redirect the failed
    # calls to a different new destination
    ##if (t_check_status("486|408")) {
    ##    sethostport("192.168.2.100:5060");
    ##    # do not set the missed call flag again
    ##    t_relay();
    ##}
}

-- 
Rajib Deka
Software Engineer

Mobile No: + 91 80157 09130
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.opensips.org/pipermail/users/attachments/20091210/80a2511c/attachment-0001.htm 


More information about the Users mailing list