官方论坛产品帮助刷图视频问题反馈

如何在opensips集成asterisk 实现媒体服务

发表于 秦海传媒

    本文档按照官方文档的指导进行了重新的配置说明,官方文档的cfg 文件不是完全正确,在启动opensips 时有一些模块名称和参数已经更新,所以如果安装官方的cfg文件,可能导致opensips 启动失败。所以我们不能完全安装官方的例子来测试,需要修改opensips.cfg 文件.

    这里,opensips 作为一个注册服务器,asterisk 仅执行媒体功能,例如语音邮箱,播报,或者会议等等。

    获得完整配置文档和测试信息,请访问:

    http://kamailio.org.cn/doku.php?id=opensips-asterisk

    修改后的opensips 配置文件:

    opensips.cfg 文件:

    $Id: opensips.cfg 8758 2012-02-29 11:59:26Z vladut-paiu $
    OpenSIPS residential configuration script
    by OpenSIPS Solutions
    This script was generated via “make menuconfig”, from
    the “Residential” scenario.
    You can enable / disable more features / functionalities by
    re-generating the scenario with different options.#
    Please refer to the Core CookBook at:
    http://www.opensips.org/Resources/DocsCookbooks
    for a explanation of possible statements, functions and parameters.
    Global Parameters #########
    debug=5
    log_stderror=yes
    log_facility=LOG_LOCAL0

    fork=yes
    children=4

    /* uncomment the following lines to enable debugging */

    debug=6
    fork=no
    log_stderror=yes
    /* uncomment the next line to enable the auto temporary blacklisting of
    not available destinations (default disabled) */
    disable_dns_blacklist=yes

    /* 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 revers DNS on IPs */
    /* auto_aliases=yes */
    /* alias=test.com */

    port = 5060
    listen=udp:192.168.1.104:5060 # CUSTOMIZE ME
    disable_tcp=yes

    disable_tls=yes
    Modules Section ########
    set module path
    mpath=”/usr/local/lib/opensips/modules/”

    loadmodule “db_mysql.so”
    loadmodule “signaling.so”
    loadmodule “sl.so”
    loadmodule “tm.so”
    loadmodule “rr.so”
    loadmodule “maxfwd.so”
    loadmodule “usrloc.so”
    loadmodule “registrar.so”
    loadmodule “textops.so”
    loadmodule “mi_fifo.so”

    loadmodule “uri_db.so”
    loadmodule “uri.so”

    loadmodule “xlog.so”
    loadmodule “acc.so”
    loadmodule “auth.so”
    loadmodule “auth_db.so”
    loadmodule “sipmsgops.so”
    loadmodule “domain.so”

    —————– setting module-specific parameters —————
    —– mi_fifo params —–
    modparam(“mi_fifo”, “fifo_name”, “/tmp/opensips_fifo”)

    —– rr params —–
    add value to ;lr param to cope with most of the UAs
    modparam(“rr”, “enable_double_rr”, 1)

    do not append from tag to the RR (no need for this script)
    modparam(“rr”, “append_fromtag”, 0)

    —– usrloc params —–
    modparam(“usrloc”, “db_mode”, 2)
    modparam(“usrloc”, “db_url”,
    “mysql://opensips:opensipsrw@localhost/opensips”)

    —– uri_db params —–
    modparam(“uri_db”, “use_uri_table”, 0)
    modparam(“uri_db”, “db_url”, “”)
    —– acc params —–
    /* what sepcial events should be accounted ? */
    modparam(“acc”, “early_media”, 1)

    modparam(“acc”, “report_ack”, 1)
    modparam(“acc”, “report_cancels”, 1)
    /* account triggers (flags) */
    modparam(“acc”, “failed_transaction_flag”, 3)
    modparam(“acc”, “log_flag”, 1)
    modparam(“acc”, “log_missed_flag”, 2)
    /* uncomment the following lines to enable DB accounting also */
    modparam(“acc”, “db_flag”, 1)
    modparam(“acc”, “db_missed_flag”, 2)

    —– auth_db params —–
    modparam(“auth_db”, “calculate_ha1″, yes)
    modparam(“auth_db”, “password_column”, “password”)
    modparam(“auth_db”, “db_url”,
    “mysql://opensips:opensipsrw@localhost/opensips”)
    modparam(“auth_db”, “load_credentials”, “”)

    —– domain params —–
    modparam(“domain”, “db_url”,
    “mysql://opensips:opensipsrw@localhost/opensips”)
    modparam(“domain”, “db_mode”, 1) # Use caching

    —– multi-module params —–
    /* uncomment the following line if you want to enable multi-domain support
    in the modules (dafault off) */
    modparam(“alias_db|auth_db|usrloc|uri_db”, “use_domain”, 1)

    Routing Logic ########
    main request routing logic
    route{

    if (!mf_process_maxfwd_header(“10″)) {
    send_reply(“483″,”Too Many Hops”);
    exit;
    }

    if (has_totag()) {

    sequential request withing a dialog should
    take the path determined by record-routing
    if (loose_route()) {
    if (is_method(“BYE”)) {
    setflag(1); # do accounting …
    setflag(3); # … even if the transaction fails
    } else if (is_method(“INVITE”)) {

    even if in most of the cases is useless, do RR for
    re-INVITEs alos, as some buggy clients do change route set
    during the dialog.
    record_route();
    }

    route it out to whatever destination was set by loose_route()
    in $du (destination URI).
    route(1);
    } 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
    t_relay();
    exit;
    } else {

    ACK without matching transaction ->
    ignore and discard
    exit;
    }
    }
    send_reply(“404″,”Not here”);
    }
    exit;
    }

    initial requests
    CANCEL processing
    if (is_method(“CANCEL”)) {
    if (t_check_trans())
    t_relay();
    exit;
    }

    t_check_trans();

    authenticate if from local subscriber
    if (!(method==”REGISTER”) && is_from_local()) {
    if (!proxy_authorize(“”, “subscriber”)) {
    proxy_challenge(“”, “0″);
    exit;
    }
    if (!db_check_from()) {
    send_reply(“403″,”Forbidden auth ID”);
    exit;
    }

    consume_credentials();

    caller authenticated
    }

    preloaded route checking
    if (loose_route()) {
    xlog(“L_ERR”,
    “Attempt to route with preloaded Route’s [$fu/$tu/$ru/$ci]“);
    if (!is_method(“ACK”))
    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 not a targetting a local SIP domain, just send it out
    based on DNS (calls to foreign SIP domains)
    if (!is_uri_host_local()) {
    append_hf(“P-hint: outbound\r\n”);
    route(1);
    }

    requests for my domain
    if (is_method(“REGISTER”)) {

    authenticate the REGISTER requests
    if (!www_authorize(“”, “subscriber”)) {
    www_challenge(“”, “0″);
    exit;
    }
    if (!db_check_to()) {
    send_reply(“403″,”Forbidden auth ID”);
    exit;
    }

    if (!save(“location”))
    sl_reply_error();

    exit;
    }

    if ($rU==NULL) {

    request with no Username in RURI
    send_reply(“484″,”Address Incomplete”);
    exit;
    }

    ASTERISK HOOK – BEGIN
    media service number? (digits starting with *)
    if ($rU=~”^\*[1-9]+”) {

    we do provide access to media services only to our
    subscribers, who were previously authenticated
    if (!is_from_local()) {
    send_reply(“403″,”Forbidden access to media service”);
    exit;
    }

    identify the services and translate to Asterisk extensions
    if ($rU==”*1111″) {

    access to own voicemail IVR
    seturi(“sip:VM_pickup@192.168.1.104:5090″); // 访问asterisk IP 和端口
    } else
    if ($rU==”*2111″) {

    access to the “say time” announcement
    seturi(“sip:AN_time@192.168.1.104:5090″);
    } else
    if ($rU==”*2112″) {

    access to the “say date” announcement
    seturi(“sip:AN_date@192.168.1.104:5090″);
    } else
    if ($rU==”*2113″) {

    access to the “echo” service
    seturi(“sip:AN_echo@192.168.1.104:5090″);
    } else
    if ($rU=~”\*3[0-9]{3}”) {

    access to the conference service
    remove the “*3″ prefix and place the “CR_” prefix
    strip(2);
    prefix(“CR_”);
    rewritehostport(“192.168.1.104:5090″);
    } else {

    unknown service
    seturi(“sip:AN_notavailable@192.168.1.104:5090″);
    }

    after setting the proper RURI (to point to corresponding ASTERISK extension),
    simply forward the call
    t_relay();
    exit;
    }

    ASTERISK HOOK – END
    do lookup
    if (!lookup(“location”)) {

    ASTERISK HOOK – BEGIN
    callee is not registered, so different to Voicemail
    First add the VM recording prefix to the RURI
    prefix(“VMR_”);

    forward to the call to Asterisk (replace below with real IP and port)
    rewritehostport(“192.168.1.104:5090″);
    route(1);

    ASTERISK HOOK – END
    exit;
    }

    when routing via usrloc, log the missed calls also
    setflag(2);

    arm a failure route in order to catch failed calls
    targeting local subscribers; if we fail to deliver
    the call to the user, we send the call to voicemail
    t_on_failure(“1″);

    route(1);
    }
    route[1] {
    if (!t_relay()) {
    sl_reply_error();
    };
    exit;
    }
    failure_route[1] {
    if (t_was_cancelled()) {
    exit;
    }

    if the failure code is “408 – timeout” or “486 – busy”,
    forward the calls to voicemail recording
    if (t_check_status(“486|408″)) {

    ASTERISK HOOK – BEGIN
    First revert the RURI to get the original user in RURI
    Then add the VM recording prefix to the RURI
    revert_uri();
    prefix(“VMR_”);

    forward to the call to Asterisk (replace below with real IP and port)
    rewritehostport(“192.168.1.104:5090″);
    t_relay();

    ASTERISK HOOK – END
    exit;
    }
    }

    opensipsctl ul show 检查命令价格

    root@opensips-1:/usr/src# opensipsctl ul show
    Domain:: location table=512 records=2
    AOR:: 104@192.168.1.104
    Contact:: sip:104@192.168.1.103:5060 Q=
    Expires:: 121
    Callid:: 623004373-5060-1@BJC.BGI.B.BAD
    Cseq:: 2106
    User-agent:: Grandstream GXP2124 1.0.4.10 // 潮流注册话机
    State:: CS_SYNC
    Flags:: 0
    Cflag:: 0
    Socket:: udp:192.168.1.104:5060
    Methods:: 6015
    AOR:: 103@192.168.1.104
    Contact:: sip:103@192.168.1.200:15590;rinstance=148938c9ce8d11b6 Q=
    Expires:: 3536
    Callid:: OTJlZjBlMmYyMjhjOTE2YmExM2E3ZjdlOGI5ZDYwZGI.
    Cseq:: 10
    User-agent:: X-Lite release 1011s stamp 41150
    State:: CS_SYNC
    Flags:: 0
    Cflag:: 0
    Socket:: udp:192.168.1.104:5060
    Methods:: 5951
    root@opensips-1:/usr/src#

    asterisk测试日期播报,拨打*2112 或者*2111播报日期或者时间

    ACL Port Status Realtime 0 sip peers [Monitored: 0 online, 0 offline Unmonitored: 0 online, 0 offline] *CLI> == Using SIP RTP CoS mark 5

    - Executing [AN_time@default:1] Ringing(“SIP/103-00000004”, ””) in new stack
    - Executing [AN_time@default:2] Wait(“SIP/103-00000004”, “1”) in new stack
    - Executing [AN_time@default:3] SayUnixTime(“SIP/103-00000004”, ”,Europe/Bucharest,HMp”) in new stack
    - Playing ‘digits/oh.gsm’ (language ‘en’)
    -
    Playing ‘digits/9.gsm’ (language ‘en’)
    -
    Playing ‘digits/20.gsm’ (language ‘en’)
    -
    Playing ‘digits/4.gsm’ (language ‘en’)
    -
    Playing ‘digits/a-m.gsm’ (language ‘en’)
    - Executing [AN_time@default:4] Hangup(“SIP/103-00000004”, ””) in new stack

  • 此条目发表在 闲言碎语 分类目录。将固定链接加入收藏夹。

Google ADs

除非另有声明,本站文章遵循知识共享署名-非商业性使用 2.5 中国大陆许可协议。 Copyright © 2008-2012 99288.NET.CN.