Re: Inquiry about rtpengine subscribe functionality
xf han via sr-users <[email protected]>
| Newsgroups | gmane.comp.voip.ser |
|---|---|
| Message-ID | <[email protected]> |
https://www.kamailio.org/docs/modules/6.1.x/modules/rtpengine.html There seem to be some mistaken here. The routing script below works: ``` # kamailio 6.1.1 #!define DBGLEVEL 2 #!define FLT_NATS 5 #!define FLB_NATB 6 #!define FLB_NATSIPPING 7 debug=DBGLEVEL log_stderror=no #!substdef "!DBURL!mysql://root:[email protected]/kamailio!g" #!substdef "!RTPENGINE_SOCK!udp:127.0.0.1:2223!g" #!substdef "!SRS_URL!sip:192.168.1.118:6666!g" memdbg=5 memlog=5 disable_sctp = yes log_facility=LOG_LOCAL0 log_prefix="{$mt $hdr(CSeq) $ci} " auto_aliases=no loadmodule "db_mysql.so" loadmodule "jsonrpcs.so" loadmodule "kex.so" loadmodule "corex.so" loadmodule "tm.so" loadmodule "tmx.so" loadmodule "sl.so" loadmodule "rr.so" loadmodule "pv.so" loadmodule "maxfwd.so" loadmodule "usrloc.so" loadmodule "registrar.so" loadmodule "textops.so" loadmodule "textopsx.so" loadmodule "siputils.so" loadmodule "xlog.so" loadmodule "sanity.so" loadmodule "ctl.so" loadmodule "cfg_rpc.so" loadmodule "counters.so" loadmodule "kemix.so" loadmodule "nathelper.so" loadmodule "rtpengine.so" loadmodule "dialog.so" loadmodule "uuid.so" # loadmodule "app_lua.so" modparam("tm", "failure_reply_mode", 3) modparam("tm", "fr_timer", 30000) modparam("tm", "fr_inv_timer", 120000) modparam("rr", "enable_full_lr", 0) modparam("rr", "append_fromtag", 0) modparam("registrar", "method_filtering", 1) modparam("registrar", "max_expires", 3600) modparam("usrloc", "db_url", "DBURL") modparam("usrloc", "db_mode", 2) #modparam("usrloc", "preload", "location") modparam("usrloc", "timer_interval", 60) modparam("usrloc", "timer_procs", 1) modparam("usrloc", "use_domain", 0) modparam("rtpengine", "rtpengine_sock", "RTPENGINE_SOCK") modparam("nathelper", "natping_interval", 30) modparam("nathelper", "ping_nated_only", 1) modparam("nathelper", "sipping_bflag", FLB_NATSIPPING) modparam("nathelper", "sipping_from", "sip:[email protected]") modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)") modparam("usrloc", "nat_bflag", FLB_NATB) # modparam("app_lua", "load", "/etc/kamailio/kamailio.lua") request_route { # per request initial checks route(REQINIT); # NAT detection route(NATDETECT); # CANCEL processing if (is_method("CANCEL")) { if (t_check_trans()) { route(RELAY); } exit; } # handle retransmissions if (!is_method("ACK")) { if(t_precheck_trans()) { t_check_trans(); exit; } t_check_trans(); } # handle requests within SIP dialogs route(WITHINDLG); ### only initial requests (no To tag) # authentication route(AUTH); # record routing for dialog forming requests (in case they are routed) # - remove preloaded route headers remove_hf("Route"); if (is_method("INVITE|SUBSCRIBE|REFER")) { dlg_manage(); record_route(); } ### requests for my local domains # handle registrations route(REGISTRAR); if ($rU==$null) { # request with no Username in RURI sl_send_reply("484", "Address Incomplete"); exit; } # user location service route(LOCATION); return; } # Wrapper for relaying requests route[RELAY] { # enable additional event routes for forwarded requests # - serial forking, RTP relaying handling, a.s.o. if (is_method("INVITE|BYE|SUBSCRIBE|UPDATE")) { if(!t_is_set("branch_route")) t_on_branch("MANAGE_BRANCH"); } if (is_method("INVITE|SUBSCRIBE|UPDATE")) { if(!t_is_set("onreply_route")) t_on_reply("MANAGE_REPLY"); } if (is_method("INVITE")) { if(!t_is_set("failure_route")) t_on_failure("MANAGE_FAILURE"); } if (!t_relay()) { send_reply_error(); } exit; } # Per SIP request initial checks route[REQINIT] { # no connect for sending replies set_reply_no_connect(); # enforce symmetric signaling # - send back replies to the source address of request force_rport(); if(is_method("OPTIONS")) { sl_send_reply("200", "Keepalive"); exit; } if(!sanity_check("17895", "7")) { xlog("Malformed SIP request from $si:$sp\n"); exit; } } # Handle requests within SIP dialogs route[WITHINDLG] { if (!has_totag()) return; # sequential request within a dialog should # take the path determined by record-routing if (loose_route()) { route(DLGURI); if ( is_method("ACK") ) { # ACK is forwarded statelessly route(NATMANAGE); } else if ( is_method("NOTIFY|REFER") ) { # Add Record-Route for in-dialog NOTIFY and REFER (RFC6665, RFC3515) record_route(); } route(RELAY); exit; } if ( is_method("ACK") ) { if ( t_check_trans() ) { # no loose-route, but stateful ACK; # must be an ACK after a 487 # or e.g. 404 from upstream server route(RELAY); exit; } else { # ACK without matching transaction ... ignore and discard exit; } } sl_send_reply("404", "Not here"); exit; } # Handle SIP registrations route[REGISTRAR] { if (!is_method("REGISTER")) return; if(isflagset(FLT_NATS)) { setbflag(FLB_NATB); setbflag(FLB_NATSIPPING); } if (!save("location")) { send_reply_error(); } exit; } # User location service route[LOCATION] { if (!lookup("location")) { $var(rc) = $rc; t_newtran(); switch ($var(rc)) { case -1: case -3: send_reply("404", "Not Found"); exit; case -2: send_reply("405", "Method Not Allowed"); exit; } } route(RELAY); exit; } # IP authorization and user authentication route[AUTH] { return; } # Caller NAT detection route[NATDETECT] { if (nat_uac_test("19")) { if (is_method("REGISTER")) { fix_nated_register(); } else { if(is_first_hop()) { set_contact_alias(); } } setflag(FLT_NATS); } return; } # RTP relaying management and signaling updates for NAT traversal route[NATMANAGE] { if (is_request()) { if(has_totag()) { if(check_route_param("nat=yes")) { setbflag(FLB_NATB); } } } if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB))) return; rtpengine_manage("SIP-source-address replace-origin replace-session-connection"); if (is_request()) { if (!has_totag()) { if(t_is_branch_route()) { add_rr_param(";nat=yes"); } } } if (is_reply()) { if(isbflagset(FLB_NATB)) { if(is_first_hop()) set_contact_alias(); } } if(isbflagset(FLB_NATB)) { # no connect message in a dialog involving NAT traversal if (is_request()) { if(has_totag()) { set_forward_no_connect(); } } } return; } # URI update for dialog requests route[DLGURI] { if(!isdsturiset()) { handle_ruri_alias(); } return; } # Manage outgoing branches branch_route[MANAGE_BRANCH] { xinfo("new branch [$T_branch_idx] to $ru\n"); route(NATMANAGE); return; } # Manage incoming replies reply_route { if(!sanity_check("17604", "6")) { xlog("Malformed SIP response from $si:$sp\n"); drop; } return; } # Manage incoming replies in transaction context onreply_route[MANAGE_REPLY] { xinfo("incoming reply\n"); if(status=~"[12][0-9][0-9]") { route(NATMANAGE); } if (has_body("application/sdp") && !dlg_isflagset("1")) { route("rtpengine_subscribe_request"); dlg_setflag("1"); } return; } # Manage failure routing cases failure_route[MANAGE_FAILURE] { route(NATMANAGE); if (t_is_canceled()) exit; return; } route[rtpengine_subscribe_request] { if (has_body("application/sdp")) { rtpengine_subscribe_request("all siprec", "$avp(siprec_offer)", "$avp(siprec_to_tag)", "siprec_streams", "none"); xinfo("rtpengine_subscribe_request\n"); xinfo("SIPREC participant $xavp(siprec_streams[0]=>tag) with label $xavp(siprec_streams[0]=>label[0])\n"); xinfo("SIPREC participant $xavp(siprec_streams[1]=>tag) with label $xavp(siprec_streams[0]=>label[0])\n"); $dlg_var(orig_to_tag) = $tt; $dlg_var(siprec_contact) = "sip:uac@" + $Ri; $dlg_var(siprec_to_tag) = $avp(siprec_to_tag); $dlg_var(siprec_callid) = $uuid(g) + "@local"; t_uac_send("INVITE","SRS_URL", "SRS_URL", "", "To: <$tu>\r\n" + "From: <$fu>\r\n" + "Call-ID: $dlg_var(siprec_callid)\r\n" + "Contact: <$dlg_var(siprec_contact)>\r\n" + "Content-Type: application/sdp\r\n", "$avp(siprec_offer)"); } } route[rtpengine_subscribe_answer] { if (has_body("application/sdp")) { xinfo("rtpengine_subscribe_answer\n"); rtpengine_subscribe_answer("from-tag=$avp(orig_from_tag) to-tag=$avp(siprec_to_tag) call-id=$avp(orig_callid)"); } } event_route [tm:local-request] { xinfo("tm:local-request\n"); if (is_method("INVITE")) { # save information from the original dialog to the new invite transaction $avp(orig_callid) = $dlg(callid); $avp(orig_from_tag) = $dlg(from_tag); $avp(orig_to_tag) = $dlg_var(orig_to_tag); $avp(siprec_to_tag) = $dlg_var(siprec_to_tag); $avp(siprec_contact) = $dlg_var(siprec_contact); t_on_reply("SRS_REPLY"); } else if (is_method("ACK")) { # save the routeset in the original dialog dlg_get("$avp(orig_callid)", "$avp(orig_from_tag)", "$avp(orig_to_tag)"); $dlg_var(siprec_cseq) = $cs; $dlg_var(siprec_to_hdr) = $hdr(To); $dlg_var(siprec_from_hdr) = $hdr(From); append_hf("Contact: <$dlg_var(siprec_contact)>\r\n"); # the same dialog information can be used to send the BYE with t_uac_send } } onreply_route[SRS_REPLY] { xinfo("SRS_REPLY, callid=$ci, siprec_from_hdr=$dlg_var(siprec_from_hdr)\n"); route("rtpengine_subscribe_answer"); } event_route [dialog:end] { #call over, stop recording rtpengine_unsubscribe("from-tag=$avp(orig_from_tag) to-tag=$avp(siprec_to_tag) call-id=$avp(orig_callid)"); $var(new_cseq) = $dlg_var(siprec_cseq) + 1; xinfo("To: $dlg_var(siprec_to_hdr)\n"); xlog("From: $dlg_var(siprec_from_hdr)\n"); xlog("Call-ID: $dlg_var(siprec_callid)\n"); xlog("CSeq: $var(new_cseq) BYE\n"); xlog("Contact: $dlg_var(siprec_contact)\r\n"); t_uac_send("BYE", "SRS_URL", "SRS_URL", "", "To: $dlg_var(siprec_to_hdr)\r\n" + "From: $dlg_var(siprec_from_hdr)\r\n" + "Call-ID: $dlg_var(siprec_callid)\r\n" + "CSeq: $var(new_cseq) BYE\r\n" + "Contact: <$dlg_var(siprec_contact)>\r\n", ""); } ``` The message sent to SRS is: ``` INVITE sip:192.168.1.118:6666 SIP/2.0 Via: SIP/2.0/UDP 192.168.1.118;branch=z9hG4bK8ada.980ba735000000000000000000000000.0 To: <sip:[email protected]> From: <sip:[email protected]>;tag=3393f0703fb0ccaca74109ff37de39f5-7d9d9a5c CSeq: 10 INVITE Call-ID: 3befe4e0-f051-47d7-a3c0-23d466aa592b@local Max-Forwards: 70 Content-Length: 506 User-Agent: kamailio (6.1.1 (x86_64/Linux)) Contact: <sip:[email protected]> Content-Type: application/sdp v=0 o=- 5 2 IN IP4 192.168.1.171 s=CounterPath eyeBeam 1.5 t=0 0 m=audio 34812 RTP/AVP 0 101 c=IN IP4 192.168.1.118 a=label:0 a=rtpmap:0 PCMU/8000 a=rtpmap:101 telephone-event/8000 a=fmtp:101 0-16 a=x-rtp-session-id:CF63FB5BB550477FB5BB5D0A3A795CE3 a=sendonly a=rtcp:34813 m=audio 31398 RTP/AVP 0 101 c=IN IP4 192.168.1.118 b=TIAS:64000 a=label:1 a=rtpmap:0 PCMU/8000 a=rtpmap:101 telephone-event/8000 a=fmtp:101 0-16 a=ssrc:1817986895 cname:21c45d12403443d6 a=inactive a=rtcp:31399 ``` __________________________________________________________ Kamailio - Users Mailing List - Non Commercial Discussions -- [email protected] To unsubscribe send an email to [email protected] Important: keep the mailing list in the recipients, do not reply only to the sender!