OpenSIPS部署

        笔者尝试在Ubuntu上部署OpenSIPS,部署成功了。部署的过程参考了其他博主的安装步骤。

https://www.cnblogs.com/jomzhang/p/15039846.htmlicon-default.png?t=N7T8https://www.cnblogs.com/jomzhang/p/15039846.html        不同的是,我选择的版本是2.4.11,mysql版本是5.7.31,Ubuntu的版本是22.10。如下图所示:

         因为一开始部署的时候,我装的是OpenSIPS3.x版本,结果一路下来没有部署成功。最后还是2.4.11版本部署没有问题。

         我的步骤是先装mysql,参照其他博主的步骤进行安装,过程也有失败但折腾一会儿就安装好了,下面是我找到的一篇安装博文,给大家提供一个参考。

Ubuntu环境下安装部署mysql5.7&开启远程访问连接&修改数据存放位置&卸载mysql_mysql5.7允许远程访问_爱敲代码的boy的博客-CSDN博客本文档适用于在Ubuntu20.04系统下部署mysql5.7,是有网的情况下。提供了两种安装mysql5.7的方法,并且还讲解了开启mysql远程访问权限,允许远程连接;以及讲解了如何修改数据库数据的存放路径。_mysql5.7允许远程访问https://blog.csdn.net/m0_52985087/article/details/132477049        然后就是安装OpenSIPS。需要安装一堆依赖,也是参考安装博文一步步装下去。需要注意的是openssl的版本。下图是我安装的一些依赖项的版本,希望能帮到您。

        安装好以后,可以尝试着创建一些用户,配置freeSWITCH。其中的配置文件部分笔者的是这样的。有些地方笔者也是不明其意,从其他处拷贝过来的。 

####### Global Parameters #########

log_level=3
log_stderror=no
log_facility=LOG_LOCAL0

children=4

/* uncomment the following lines to enable debugging */
#debug_mode=yes

/* uncomment the next line to enable the auto temporary blacklisting of
   not available destinations (default disabled) */
#disable_dns_blacklist=no

/* uncomment the next line to enable IPv6 lookup after IPv4 dns
   lookup failures (default disabled) */
#dns_try_ipv6=yes

/* comment the next line to enable the auto discovery of local aliases
   based on reverse DNS on IPs */
auto_aliases=no

######################################################################
## Aliases
######################################################################
auto_aliases=yes
alias=localhost
alias=localhost.localdomain

listen=udp:192.168.110.42:5060   # CUSTOMIZE ME
listen=tcp:192.168.110.42:5060   # CUSTOMIZE ME
listen=tls:192.168.110.42:5061
listen=ws:192.168.110.42:5062    # CUSTOMIZE ME
listen=wss:192.168.110.42:7443  # CUSTOMIZE ME

####### Modules Section ########

#set module path
mpath="/opt/opensips/lib64/opensips/modules/"

loadmodule "path.so"

#### SIGNALING module
loadmodule "signaling.so"

#### StateLess module
loadmodule "sl.so"

#### Transaction Module
loadmodule "tm.so"
modparam("tm", "fr_timeout", 5)
modparam("tm", "fr_inv_timeout", 30)
modparam("tm", "restart_fr_on_each_reply", 0)
modparam("tm", "onreply_avp_mode", 1)

#### Record Route Module
loadmodule "rr.so"
/* do not append from tag to the RR (no need for this script) */
modparam("rr", "append_fromtag", 0)

#### MAX ForWarD module
loadmodule "maxfwd.so"

#### SIP MSG OPerationS module
loadmodule "sipmsgops.so"

#### FIFO Management Interface
loadmodule "mi_fifo.so"
modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
modparam("mi_fifo", "fifo_mode", 0666)

#### URI module
loadmodule "uri.so"
modparam("uri", "use_uri_table", 0)

#### MYSQL module
loadmodule "db_mysql.so"

#### USeR LOCation module
loadmodule "usrloc.so"
#modparam("usrloc", "nat_bflag", "NAT")
#modparam("usrloc", "db_mode",   2)
modparam("usrloc", "nat_bflag", 6)
modparam("usrloc", "use_domain", 1)
modparam("usrloc", "desc_time_order", 0)
modparam("usrloc", "timer_interval", 60)
modparam("usrloc", "matching_mode", 0)
modparam("usrloc", "cseq_delay", 20)
modparam("usrloc", "hash_size", 9)
modparam("usrloc", "db_mode", 0)
#modparam("usrloc", "fetch_rows", 2000)
modparam("usrloc", "user_column", "username")
modparam("usrloc", "domain_column", "domain")
modparam("usrloc", "contact_column", "contact")
modparam("usrloc", "expires_column", "expires")
modparam("usrloc", "q_column", "q")
modparam("usrloc", "callid_column", "callid")
modparam("usrloc", "cseq_column", "cseq")
modparam("usrloc", "methods_column", "methods")
modparam("usrloc", "flags_column", "flags")
modparam("usrloc", "cflags_column", "cflags")
modparam("usrloc", "user_agent_column", "user_agent")
modparam("usrloc", "received_column", "received")
modparam("usrloc", "socket_column", "socket")
modparam("usrloc", "path_column", "path")

#### REGISTRAR module
loadmodule "registrar.so"
modparam("registrar", "tcp_persistent_flag", "TCP_PERSISTENT")
/* uncomment the next line not to allow more than 10 contacts per AOR */
#modparam("registrar", "max_contacts", 10)

#### ACCounting module
loadmodule "acc.so"
/* what special events should be accounted ? */
modparam("acc", "early_media", 0)
modparam("acc", "report_cancels", 0)
/* by default we do not adjust the direct of the sequential requests.
   if you enable this parameter, be sure the enable "append_fromtag"
   in "rr" module */
modparam("acc", "detect_direction", 0)
modparam("acc", "db_url",
        "mysql://opensips:opensipsrw@localhost/opensips") # CUSTOMIZE ME


### vip, load uac, uac_auth, and uac_registrant
loadmodule "uac.so"
loadmodule "uac_auth.so"
loadmodule "uac_registrant.so"
modparam("uac_registrant", "db_url",
        "mysql://opensips:opensipsrw@localhost/opensips") # CUSTOMIZE ME
modparam("uac_registrant", "hash_size", 4)
modparam("uac_registrant", "timer_interval", 32)

#### AUTHentication modules
loadmodule "auth.so"
loadmodule "auth_db.so"
modparam("auth_db", "calculate_ha1", yes)
modparam("auth_db", "password_column", "password")
modparam("auth_db|uri", "db_url",
        "mysql://opensips:opensipsrw@localhost/opensips") # CUSTOMIZE ME
modparam("auth_db", "load_credentials", "")

#### DIALOG module
loadmodule "dialog.so"
modparam("dialog", "dlg_match_mode", 1)
modparam("dialog", "default_timeout", 21600)  # 6 hours timeout
modparam("dialog", "db_mode", 2)
modparam("dialog", "db_url",
        "mysql://opensips:opensipsrw@localhost/opensips") # CUSTOMIZE ME

#loadmodule "rtpproxy.so"
#modparam("rtpproxy", "rtpproxy_sock", "udp:192.168.110.41:12221") # CUSTOMIZE ME
#modparam("rtpproxy", "db_url","mysql://opensips:opensipsrw@192.168.110.42/opensips") # CUSTOMIZE ME
#modparam("rtpproxy", "default_set", 1)
#modparam("rtpproxy", "rtpproxy_retr", 1)
#modparam("rtpproxy", "rtpproxy_autobridge", 1)


####  NAT modules
loadmodule "nathelper.so"
modparam("nathelper", "natping_interval", 10)
modparam("nathelper", "ping_nated_only", 1)
modparam("nathelper", "sipping_bflag", "SIP_PING_FLAG")
modparam("nathelper", "sipping_from", "sip:1002@192.168.110.42") # CUSTOMIZE ME
modparam("nathelper", "received_avp", "$avp(received_nh)")

#### RTPengine protocol
loadmodule "rtpengine.so"
modparam("rtpengine", "db_url", "mysql://opensips:opensipsrw@192.168.110.42/opensips")
modparam("rtpengine", "socket_column", "socket")

#### HTTPD module
loadmodule "httpd.so"
modparam("httpd", "ip", "192.168.110.42")

#### MI HTTP module
loadmodule "mi_http.so"

loadmodule "proto_udp.so"
loadmodule "proto_tcp.so"

loadmodule "proto_tls.so"
loadmodule "proto_ws.so"
loadmodule "proto_wss.so"
modparam("proto_ws", "ws_port", 5062)
modparam("proto_wss", "wss_port", 7443)


#loadmodule "proto_tls.so"

loadmodule "tls_mgm.so"

modparam("tls_mgm","tls_method", "TLSv1_2")
modparam("tls_mgm","verify_cert", "0")
modparam("tls_mgm","require_cert", "0")
modparam("tls_mgm","certificate", "/opt/opensips/certs/opsips.pem")
modparam("tls_mgm","private_key", "/opt/opensips/certs/opsips_key.pem")
modparam("tls_mgm","ca_list", "/opt/opensips/certs/ca.crt")
modparam("tls_mgm", "ca_dir", "/opt/opensips/certs")

loadmodule "dispatcher.so"

modparam("dispatcher", "db_url", "mysql://opensips:opensipsrw@localhost/opensips")
#modparam("dispatcher", "flags", 2)
#modparam("dispatcher", "use_default", 0)
#modparam("dispatcher", "force_dst", 1)
modparam("dispatcher", "dst_avp", "$avp(271)")
modparam("dispatcher", "attrs_avp", "$avp(272)")
modparam("dispatcher", "grp_avp", "$avp(273)")
modparam("dispatcher", "cnt_avp", "$avp(274)")
modparam("dispatcher", "hash_pvar", "$avp(273)")
# modparam("dispatcher", "setid_pvar", "$var(setid)")
modparam("dispatcher", "ds_ping_method", "OPTIONS")
modparam("dispatcher", "ds_ping_from", "sip:1000@192.168.110.42:5060")
modparam("dispatcher", "ds_ping_interval", 10)
# modparam("dispatcher", "ds_ping_sock", "udp:192.168.110.42:5060")
modparam("dispatcher", "ds_probing_threshhold", 3)
modparam("dispatcher", "ds_probing_mode", 1)
modparam("dispatcher", "options_reply_codes", "501,403,404,400,200")

#loadmodule "nathelper.so"
loadmodule "nat_traversal.so"
loadmodule "uac_redirect.so"

loadmodule "cachedb_local.so"
####### Routing Logic ########
route
{
    # log the basic info regarding this call
    xlog("L_INFO", "$ci|start|recieved $oP request $rm $ou");
    xlog("L_INFO", "$ci|log|source $si:$sp");
    xlog("L_INFO", "$ci|log|from $fu");
    xlog("L_INFO", "$ci|log|to $tu");

    # check that hop cound for this request and make sure it is under 10
    # to prevent endless loops
    if (!mf_process_maxfwd_header("10"))
    {
        xlog("L_WARN", "$ci|end|to many hops");

        sl_send_reply("483", "We refuse to process this endless imbroglio");

        exit;
    }

    # this check detemines if the opensips has routed the request to itself,
    # this happens because the server is the destination of the request but
    # we mangle it to send it else where. When that mangeling fails and we
    # still relay it then it just comes right back to us...
    # if (src_ip==myself)
    # {
    #     xlog("L_WARN", "$ci|end|sourced from this server");
    #
    #     exit;
    # }

    # currently we dont support subscribe so to keep the noise down
    # just end the request here. For options just end the request here as well.
    if (is_method("OPTIONS"))
    {
        xlog("L_NOTICE", "$ci|end|unsupported method");

        sl_send_reply("503", "Rawr!!");

        exit;
    }

    # if the source IP/port are in one of the server dispatch lists
    # then this request originated from one of our media servers, mark it
    # as such by setting flag 26
    if (ds_is_in_list("$si", "", "1"))
    {
        xlog("L_INFO", "$ci|log|originated from internal sources");

        # Flag 26 marks the source as a on-net server
        setflag(26);

        setbflag(26);
    }
    # if the request source IP/port was not in any dispatcher lists
    # this this originated outside our equipment (carrier, client, ect)
    else
    {
        xlog("L_INFO", "$ci|log|originated from external sources");
    }

    if ($pr == "ws" || $pr == "wss") {
                setflag(SRC_WS);
                xlog("ws: $pr " );
    }

    # if the to header has a tag attached then it implies this request
    # has been processed by us before (IE: a media server has added
    # its tag on the to header in prior messages)
    if (has_totag())
    {
        # sequential request within a dialog should
        # take the path determined by record-routing
        if (loose_route())
        {
            append_hf("P-hint: rr-enforced\r\n");

            # if we have locked this call to a media server then
            # maintain that association
            if (cache_fetch("local", "$ci", $avp(55)))
            {
                if (is_method("BYE"))
                {
                    # remove the association between the call-id and the media server (if one)
                    # but leave the contact user and server to support transfers
                    cache_remove("local", "$ci");

                    xlog("L_INFO", "$ci|log|cleaned up call id from cache");
                }
                else if (isflagset(26))
                {
                    cache_store("local", "$tU", "$avp(55)", 3600);

                    xlog("L_INFO", "$ci|log|maintaining associated $tU with media server $avp(55)");
                }
                else if ($ct.fields(uri))
                {
                    cache_store("local", "$(ct.fields(uri){uri.user})", "$avp(55)", 3600);

                    xlog("L_INFO", "$ci|log|maintaining associated $(ct.fields(uri){uri.user}) with media server $avp(55)");
                }

                cache_store("local", "$ci", "$avp(55)", 3600);
            }

            xlog("L_INFO", "$ci|log|forwarding based on the route set");

            if (isflagset(26))
            {
                route(internal_to_external_relay);
            }
            else
            {
                route(external_to_internal_relay);
            }

            exit();
        }
        else if ( is_method("ACK") )
        {
            if ( t_check_trans() )
            {
                # non loose-route, but stateful ACK; must be an ACK after
                # a 487 or e.g. 404 from upstream server
                xlog("L_INFO", "$ci|log|in dialog request belongs to a known transaction");

                route(logged_relay);
            }
            else
            {
                # ACK without matching transaction ->
                # ignore and discard
                xlog("L_NOTICE", "$ci|end|no matching transaction");
            }

            exit();
        }
        else if ( is_method("NOTIFY") )
        {
            route(logged_relay);

            exit();
        }

        # request with a to tag that cant be routed loosly and is not an ACK
        # ignor eand discard
        xlog("L_WARN", "$ci|end|could not route in dialog");

        sl_send_reply("486", "PC Load Letter");

        exit();
    }

    # if the request is to cancel a transaction process it now
    if (is_method("CANCEL"))
    {
        # If this cancel is part of a transaction
        # then pass it along to concerned parties
        if (t_check_trans())
        {
            xlog("L_INFO", "$ci|log|request belogs to a known transaction");

            route(logged_relay);
        }
        # if the cancel does not belong to a known transaction or a
        # request that has not progressed outside this server dont relay it
        else
        {
            xlog("L_NOTICE", "$ci|end|no matching transaction");
        }

        # remove the association between the call-id and the media server (if one)
        # but leave the contact user and server to support transfers
        cache_remove("local", "$ci");

        xlog("L_INFO", "$ci|log|cleaned up call id from cache");

        exit;
    }

    # If this is a retransmission it will break/stop the script
    # and do standard processing of the message
    t_check_trans();

    # Except for an ACK no request should have a route set with no to tag, this would
    # indicate that the intial request has the Route headers and is likely someone trying
    # to get us to send the request were they want
    if (loose_route())
    {
        if (!is_method("ACK"))
        {
            xlog("L_WARN", "$ci|end|initial request contained a preloaded route set");

            sl_send_reply("403", "The only winning move it not to play");

            exit;
        }
    }

    # If the request is a register we will pass it along but we need
    # to add the path header (along with the received IP/port info)
    if (is_method("REGISTER"))
    {
        # if we fail to add the path header then dont let it
        # register because it will cause issues later...
        if (!add_path_received())
        {
            xlog("L_ERR", "$ci|log|unable to add path");

            sl_send_reply("503", "Internal path befuddlement");

            # remove the association between the call-id and the media server (if one)
            # but leave the contact user and server to support transfers
            cache_remove("local", "$ci");

            xlog("L_INFO", "$ci|end|cleaned up call id from cache");

            exit;
        }

        xlog("L_INFO", "$ci|log|added path");
    }

    # for all initial request (not having been processed above in the has_totag)
    # that are not a register or message add this sever to the route set on the
    # request so subsequent messages come through this server
    if (!is_method("REGISTER|MESSAGE"))
    {
        # Record the route that this request has taken
        # so we remain in the signaling path
        record_route();

        xlog("L_INFO", "$ci|log|added this server to the route set");
    }

    # if the request is from a media server send it out
    if (isflagset(26))
    {
        route(internal_to_external_relay);

        exit();
    }

    # if the request is not from a media server it must be for one,
    # there is much work to do!

    # load a list of currently active media servers
    # if no media server could be set with ds_select_domain then there are no
    # active servers, no need to conitnue
    if (!ds_select_domain("1", "4"))
    {
        xlog("L_ERR", "$ci|end|no servers avaliable");

        sl_send_reply("480", "The cake is a lie!");

        exit;
    }

    if (cache_fetch("local", "$ou", $avp(55)))
    {
        xlog("L_INFO", "$ci|log|request $ou is associated with media server $avp(55)");

        cache_remove("local", "$ou");

        cache_store("local", "$ci", "$avp(55)", 3600);
    }
    # if the request is not from our media severs but has a call-id in localcache
    # then change the routing to go to the server previously associated with it.
    else if (cache_fetch("local", "$ci", $avp(55)))
    {
        cache_store("local", "$ci", "$avp(55)", 3600);

        xlog("L_INFO", "$ci|log|call-id is associated with media server $avp(55)");
    }
    # if the request is not from our media severs but has a contact uri in localcache
    # then change the routing to go to the server previously associated with it.
    else if ($ct.fields(uri) && cache_fetch("local", "$(ct.fields(uri){uri.user})", $avp(55)))
    {
        cache_store("local", "$(ct.fields(uri){uri.user})", "$avp(55)", 3600);

        xlog("L_INFO", "$ci|log|contact $(ct.fields(uri){uri.user}) is associated with media server $avp(55)");
    }
    # if the request is not from our media servers and no associations in localcache
    # then use the distribute list as is
    else
    {
        xlog("L_INFO", "$ci|log|routing call to arbitrary media server $rd:$rp");
    }

    # if the dispatcher list (in 271) does not start with
    # the request domain/port that we are sending this call
    # to, re-order the list so that it does
    if($avp(55) && $(avp(271)[0]) != $avp(55))
    {
        # create a index var for our loop (arrays are start at 0 and this is a count)
        $var(i) = $avp(274) - 1;

        # loop over the dispatcher list
        while($var(i) > 0)
        {
            # if this element in the dispatch list is the same
            # as the call destination
            if($(avp(271)[$var(i)]) == $avp(55))
            {
                # replace it with the first element of the list
                $(avp(271)[$(var(i))]) = $(avp(271)[0]);

                # break out of the loop
                $var(i) = -1;
            }

            $var(i) = $var(i) - 1;
        }

        # handles the case were we only have two servers
        # and the one that we are locked to has failed
        if ($var(i) >= 0)
        {

            xlog("L_INFO", "$ci|log|associated media server is inactive, moving to $rd");

            if ($ct.fields(uri) && cache_fetch("local", "$ci", $avp(56)))
            {
                cache_store("local", "$(ct.fields(uri){uri.user})", "sip:$rd:$rp", 3600);

                xlog("L_INFO", "$ci|log|associated contact $(ct.fields(uri){uri.user}) with media server sip:$rd:$rp");
            }

            # update the callid cache
            cache_store("local", "$ci", "sip:$rd:$rp", 3600);
        }
        # the server we are locked to is in the active server list from then
        # dispatcher so re-arrange the list to try it first
        else
        {
            xlog("L_INFO", "$ci|log|re-ordering the dispatcher list to keep associated server first");

            # set the first element of the list to the destination
            #$(avp(271)[0]) = $avp(55);


            if ($avp(271) != NULL)
               $(avp(271)[0]) = $avp(55);
            else
               $avp(271) = $avp(55);

            # set the domain for this request (server IP to route to)
            $rd = $(avp(55){uri.host});

            # set the port for this request (server IP to route to)
            $rp = $(avp(55){uri.port});
        }
    }

    route(external_to_internal_relay);
}

route[external_to_internal_relay]
{
    # 1. correct any nat issues
    # 2. remove any X-AUTH-IP headers so we will be the only one to set it
    # 3. set the X-AUTH-IP header for freeswitch ACLs
    # 4. set the final reply timer to two seconds, so we failover faster
    # 5. arm a logging branch for replies
    # 6. arm a failure branch that will try another one of our media servers when possible

    route("nat_test_and_correct");

    remove_hf("X-AUTH-IP");

    append_hf("X-AUTH-IP: $si\r\n");

    xlog("L_INFO", "$ci|log|X-AUTH-IP: $si");

    $avp(final_reply_timer) = 2;

    t_on_reply("internal_reply");

    t_on_failure("internal_fault");

    route("logged_relay");

    exit;
}

route[internal_to_external_relay]
{
    # if the request is from a media server then assume it is going somewhere
    # outside our control and give that equipment longer to respond.
    # Also arm a branch to log the replies

    $avp(final_reply_timer) = 6;

    t_on_reply("external_reply");

    route("logged_relay");

    exit;
}

route[logged_relay]
{
    # try to send the request on its way, if it fails send back a
    # stateless error to the requestor
    if (t_relay())
    {
        xlog("L_INFO", "$ci|pass|$rd:$rp");
    }
    else
    {
        xlog("L_ERR", "$ci|end|unable to relay message");

        sl_reply_error();
    }
}

route[nat_test_and_correct]
{
    # 1. Contact header field is searched for occurrence of RFC1918 addresses
# if (nat_uac_test("1"))
# {
# xlog("L_INFO", "$ci|log|contact header field contains a RFC1918 address");
#
# fix_contact();
# }

    # 2 - the "received" test is used: address in Via is compared against source IP address of signaling
    if (nat_uac_test("2"))
    {
        xlog("L_INFO", "$ci|log|address in Via differs from source IP");

        # adds the rport parameter to the first Via header
        force_rport();

        fix_contact();
    }

    # if the request has a body see if it needs NAT corrections as well,
    # this check looks at:
    # 8. SDP is searched for occurrence of RFC1918 addresses
    if (has_body("application/sdp") && nat_uac_test("8"))
    {
        xlog("L_INFO", "$ci|log|SDP contains a RFC1918 address");

        # alters the SDP information in order to facilitate NAT traversal.
        # 2. rewrite media IP address (c=) with source IP
        # 8. rewrite IP from origin description (o=) with source IP
        fix_nated_sdp("10");
    }
}

onreply_route[external_reply]
{
    # this branch handles replies that are comming from equipment
    # outside our control

    xlog("L_INFO", "$ci|start|recieved external reply $rs $rr");
    xlog("L_INFO", "$ci|log|source $si:$sp");

    # This ensures that if a endpoint recieves a call they can properly
    # transfer that call
    # TODO: this will track calls made to carriers when we start sending carrier
    # traffic through opensips
    # Target: A endpoint answering a call made from one of our media
    # servers should lock that endpoint to the server
    if (t_check_status("200") && is_method("INVITE") && $(fd{ip.isip}) && ds_is_in_list("$fd", "", "1"))
    {
        $var(d) = $(fu{uri.host});

        if ($(fu{uri.port}) == 0)
        {
            $var(p) = 5060;
        }
        else
        {
            $var(p) = $(fu{uri.port});
        }

        if ($ct.fields(uri))
        {
            cache_store("local", "$(ct.fields(uri){uri.user})", "sip:$var(d):$var(p)", 3600);

            xlog("L_INFO", "$ci|log|associated $(ct.fields(uri){uri.user}) with media server sip:$var(d):$var(p)");
        }

        cache_store("local", "$ci", "sip:$var(d):$var(p)", 3600);

        xlog("L_INFO", "$ci|log|associated call-id with media server sip:$var(d):$var(p)");
    }

    if (is_method("BYE"))
    {
        # remove the association between the call-id and the media server (if one)
        # but leave the contact user and server to support transfers
        cache_remove("local", "$ci");

        xlog("L_INFO", "$ci|log|cleaned up call id from cache");
    }

    route("nat_test_and_correct");

    xlog("L_INFO", "$ci|pass|$(<request>si):$(<request>sp)");

    # if the reply is not dropped (only provisional replies can be),
    # it will be injected and processed by the transaction engine.
}

onreply_route[internal_reply]
{
    # this branch handles replies that are comming from our media server
    if(t_local_replied("last"))
    {
        xlog("L_INFO", "$ci|start|recieved local internal reply $T_reply_code $rr");
    }
    else
    {
        xlog("L_INFO", "$ci|start|recieved internal reply $T_reply_code $rr");
        xlog("L_INFO", "$ci|log|source $si:$sp");
    }

    # Ensure that if we challenge an endpoint its response is not round-robin'd
    # We have to do it in the reply so we have the correct call id
    # Target: Endpoint intiated a request that was challenged, lock that
    # call id to the challenging server so it recieves the reply
    if (t_check_status("(407)|(401)") && $(si{ip.isip}) && ds_is_in_list("$si", "", "1"))
    {
        cache_store("local", "$ci", "sip:$si:$sp", 3600);

        xlog("L_INFO", "$ci|log|associated call-id with media server sip:$si:$sp");
    }

    if (is_method("BYE"))
    {
        # remove the association between the call-id and the media server (if one)
        # but leave the contact user and server to support transfers
        cache_store("local", "$ci", "sip:$si:$sp", 360);

        xlog("L_INFO", "$ci|log|cleaned up call id from cache");
    }

    if ($rs < 300)
    {
        xlog("L_INFO", "$ci|pass|$(<request>si):$(<request>sp)");
    }

    # if the reply is not dropped (only provisional replies can be),
    # it will be injected and processed by the transaction engine.
}

failure_route[internal_fault]
{
    # this branch handles failures (>=300) to our media servers,
    # which we can sometimes overcome by routing to another server

    # if the failure cause was due to the transaction being
    # cancelled then we are complete
    if (t_was_cancelled())
    {
        xlog("L_INFO", "$ci|log|transaction was cancelled");

        # remove the association between the call-id and the media server (if one)
        # but leave the contact user and server to support transfers
        cache_remove("local", "$ci");

        xlog("L_INFO", "$ci|end|cleaned up call id from cache");

        exit;
    }

    # if the failure case was soemthing that we should recover
    # from then try to find a new media server
    if (t_check_status("(401)|(407)|(403)"))
    {
        xlog("L_INFO", "$ci|log|failure route ignoring auth reply $T_reply_code $rr");
    }
    else if (t_check_status("402"))
    {
        send_reply("486", "More money please");

        exit();
    }
    else if (t_check_status("(4[0-9][0-9])|(5[0-9][0-9])"))
    {
        xlog("L_INFO", "$ci|start|received failure reply $T_reply_code $rr");

        if (cache_fetch("local", "$ci-failure", $avp(55)))
        {
            $avp(55) = $(avp(55){s.int});
        }
        else
        {
            $avp(55) = 0;
        }

        xlog("L_INFO", "$ci|log|attempting retry $avp(55) of failed request");

        # try to find a new media server to send the call to
        if($avp(55) < 3 && ds_next_domain())
        {
            xlog("L_INFO", "$ci|log|routing call to next media server $rd:$rp");

            # store the new callid association
            cache_store("local", "$ci", "sip:$rd:$rp", 3600);

            # if the request has a contact and is an INVITE then store the new
            # association
            if ($ct.fields(uri) && is_method("INVITE"))
            {
                cache_store("local", "$(ct.fields(uri){uri.user})", "sip:$rd:$rp", 3600);

                xlog("L_INFO", "$ci|log|associated contact $(ct.fields(uri){uri.user}) with media server sip:$rd:$rp");
            }

            # reset the final reply timer
            $avp(final_reply_timer) = 2;

            t_on_reply("internal_reply");

            t_on_failure("internal_fault");

            xlog("L_INFO", "$ci|pass|$rd:$rp");

            # relay the request to the new media server
            t_relay();

            $avp(55) = $avp(55) + 1;

            cache_store("local", "$ci-failure", "$avp(55)", 60);

            exit();
        }
        else
        {
            cache_remove("local", "$ci-failure");

            xlog("L_ERR", "$ci|log|no other media servers avaliable");
        }
    }
    else if (t_check_status("302"))
    {
        if( $(<reply>hdr(X-Redirect-Server)) && $(<reply>ct.fields(uri)) )
        {
            $var(redirect_host) = $(<reply>hdr(X-Redirect-Server){uri.host});

            $var(redirect_port) = $(<reply>hdr(X-Redirect-Server){uri.port});

            cache_store("local", "$(<reply>ct.fields(uri))", "sip:$var(redirect_host):$var(redirect_port)", 60);

            xlog("L_INFO", "$ci|log|stored redirect mapping for $(<reply>ct.fields(uri)) to sip:$var(redirect_host):$var(redirect_port)");
            xlog("L_INFO", "$ci|log|stored redirect mapping for $(<reply>ct.fields(uri)) to sip:$var(redirect_host):$var(redirect_port)");

            remove_hf("X-Redirect-Server");
        }
    }
    else
    {
        xlog("L_INFO", "$ci|log|failure route ignoring reply $T_reply_code $rr");
    }

    if (!t_check_status("(407)|(401)|(302)"))
    {
        # remove the association between the call-id and the media server (if one)
        # but leave the contact user and server to support transfers
        cache_remove("local", "$ci");

        xlog("L_INFO", "$ci|log|cleaned up call id from cache");
    }

    xlog("L_INFO", "$ci|pass|$(<request>si):$(<request>sp)");

    # if no new branch is generated or no reply is forced over, by default,
    # the winning reply will be sent back to UAC.
}

route[rtpengine_offer] {
    if (isflagset(SRC_WS) && isbflagset(DST_WS))
        # - Web to web
        $var(reflags) = "trust-addres sreplace-origin replace-session-connection SDES-off ICE=force";
    else if (isflagset(SRC_WS))
        # - Web to SIP
        $var(reflags) = "trust-addres replace-origin replace-session-connection rtcp-mux-demux ICE=remove RTP/AVP";
    else if (isbflagset(DST_WS))
        # - SIP to web
        $var(reflags) = "trust-addres replace-origin replace-session-connection rtcp-mux-offer ICE=force transcode-opus transcode-G722 transcode-PCMU SDES-off UDP/TLS/RTP/SAVP";
    else
        # - SIP to SIP
        $var(reflags) = "trust-addres replace-origin replace-session-connection rtcp-mux-demux ICE=remove RTP/AVP";

    rtpengine_use_set("1");
    rtpengine_offer("$var(reflags)");
}

route[rtpengine_answer] {
    if (isflagset(SRC_WS) && isbflagset(DST_WS))
        # - Web to web
        $var(reflags) = "trust-addres replace-origin replace-session-connection SDES-off ICE=force";
    else if (isflagset(SRC_WS))
        # - Web to SIP
        $var(reflags) = "trust-addres replace-origin replace-session-connection rtcp-mux-require ICE=force RTP/SAVPF";
    else if (isbflagset(DST_WS))
        # - SIP to web
        $var(reflags) = "trust-addres replace-origin replace-session-connection rtcp-mux-offer ICE=force transcode-opus transcode-G722 transcode-PCMU SDES-off UDP/TLS/RTP/SAVP";
    else
        # - SIP to SIP
        $var(reflags) = "trust-addres replace-origin replace-session-connection rtcp-mux-demux ICE=remove RTP/AVP";

    rtpengine_use_set("1");
    rtpengine_answer("$var(reflags)");
}

        这里面涉及到的知识点,本篇博文是说不清楚的。 还有证书的配置,准备单独开一篇博文来详细讲一讲,就不在这里赘述了。

        OpenSIPS需要创建用户,然后需要在表里面设置一些信息,具体参考博文。

opensipsctl add 1002 123 new user '1002' added

        在库中,可以看到添加进来了一些用户。

        另外,添加一些freeSWITCH服务器,并且给它们配置权重。

         最后,启动OpenSIPS。使用 以下命令:

cd /opt/opensips/sbin
 ./opensipsctl start
 查看日志 cat /var/log/syslog

这时候去到freeswitch的控制台,会看到option的消息源源不断的过来,就说明部署成功了。 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值