Skip to content

Commit

Permalink
serail , parallel forking
Browse files Browse the repository at this point in the history
  • Loading branch information
altanai committed Sep 18, 2019
1 parent dc9ec1b commit 148b34e
Show file tree
Hide file tree
Showing 2 changed files with 333 additions and 0 deletions.
54 changes: 54 additions & 0 deletions forking/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,57 @@ adds to request a new destination set that includes the highest priority contact
**t_next_contact_flow()**

adds a new branch to the request that includes the first contact from contact_flows_avp that matches the +sip.instance value of the flow that has failed. Upon each call, Request URI is rewritten with the contact. The used contact is removed from contact_flows_avp.

## Debugging

**Issue1** ERROR: dialog [dlg_handlers.c:503]: dlg_onreply(): missing TAG param in TO hdr :-/
**solution** After inspection of 200 message we can see that it misses the tag ahead of To header

SIP/2.0 200 OK.
Via: SIP/2.0/UDP y.y.y.y:5060;branch=z9hG4bK32b3.18f1ec7de2b150859efcf052bef016bd.1.
From: <sip:[email protected]>;tag=6bc95850.
To: <sip:[email protected]:5077>.
Call-ID: 99140NWIyNGJlMTFhYTJhNGI4NjJiZmQyY2ZlODViNTM5MDQ.
CSeq: 1 INVITE.
Contact: <sip:127.0.1.1:5077;transport=UDP>.
Content-Length: 0.

A correct SIP 200 ok would be

U y.y.y.y:5077 -> y.y.y.y:5060
SIP/2.0 200 OK.
Via: SIP/2.0/UDP y.y.y.y:5060;branch=z9hG4bKcd78.edfd5d41eed4ad1a9983b6085c930464.1.
From: <sip:[email protected]>;tag=e84b2c42.
To: <sip:[email protected]:5077>;tag=7568SIPpTag011.
Call-ID: 99140NjJkODE4MmYyMjA2ODRkZDlkZDBmZGQ3NDEyZjI1MjQ.
CSeq: 1 INVITE.
Contact: <sip:127.0.1.1:5077;transport=UDP>.
Content-Type: application/sdp.
Content-Length: 129.

Also show in SIPP uas 200 ok construction

```xml
<send>
<![CDATA[
SIP/2.0 200 OK
[last_Via:]
[last_From:]
[last_To:];tag=[call_number]
[last_Call-ID:]
[last_CSeq:]
[last_Record-route:]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
Content-Type: application/sdp
Content-Length: 0
v=0
o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
s=-
c=IN IP[media_ip_type] [media_ip]
t=0 0
m=audio [media_port] RTP/AVP 0
a=rtpmap:0 PCMU/8000
]]>
</send>
```
279 changes: 279 additions & 0 deletions forking/kamailio_parallel_forking.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@

####### Defined Values #########


#!substdef "!MY_IP_ADDR!<MY_IP_ADDR>!g"
#!substdef "!MY_EXTERNAL_IP!<MY_EXTERNAL_IP>!g"
#!substdef "!MY_UDP_PORT!<MY_UDP_PORT>!g"
#!substdef "!MY_TCP_PORT!<MY_TCP_PORT>!g"
#!substdef "!MY_UDP_ADDR!udp:MY_IP_ADDR:MY_UDP_PORT!g"
#!substdef "!MY_TCP_ADDR!tcp:MY_IP_ADDR:MY_TCP_PORT!g"


#!define MULTIDOMAIN 0

# - flags
# FLT_ - per transaction (message) flags
# FLB_ - per branch flags
#!define FLT_ACC 1
#!define FLT_ACCMISSED 2
#!define FLT_ACCFAILED 3
#!define FLT_NATS 5

#!define FLB_NATB 6
#!define FLB_NATSIPPING 7

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

### LOG Levels: 3=DBG, 2=INFO, 1=NOTICE, 0=WARN, -1=ERR
debug=2
log_stderror=no

memdbg=5
memlog=5

log_facility=LOG_LOCAL0
log_prefix="{$mt $hdr(CSeq) $ci} "

/* number of SIP routing processes */
children=2

/* uncomment the next line to disable TCP (default on) */
# disable_tcp=yes

/* uncomment the next line to disable the auto discovery of local aliases
* based on reverse DNS on IPs (default on) */
# auto_aliases=no

/* add local domain aliases */
# alias="sip.mydomain.com"

/* listen addresses */
# listen=udp:127.0.0.1:5060
listen = MY_UDP_ADDR advertise MY_EXTERNAL_IP:MY_UDP_PORT
listen = MY_TCP_ADDR advertise MY_EXTERNAL_IP:MY_TCP_PORT

####### Custom Parameters #########

/* These parameters can be modified runtime via RPC interface
* - see the documentation of 'cfg_rpc' module.
*
* Format: group.id = value 'desc' description
* Access: $sel(cfg_get.group.id) or @cfg_get.group.id */

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

/* set paths to location of modules */
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 "textops.so"
loadmodule "siputils.so"
loadmodule "xlog.so"
loadmodule "sanity.so"
loadmodule "ctl.so"
loadmodule "cfg_rpc.so"
loadmodule "acc.so"
loadmodule "counters.so"

# ----------------- setting module-specific parameters ---------------


# ----- jsonrpcs params -----
modparam("jsonrpcs", "pretty_format", 1)
/* set the path to RPC fifo control file */
# modparam("jsonrpcs", "fifo_name", "/var/run/kamailio/kamailio_rpc.fifo")
/* set the path to RPC unix socket control file */
# modparam("jsonrpcs", "dgram_socket", "/var/run/kamailio/kamailio_rpc.sock")

# ----- ctl params -----
/* set the path to RPC unix socket control file */
# modparam("ctl", "binrpc", "unix:/var/run/kamailio/kamailio_ctl")

# ----- tm params -----
# auto-discard branches from previous serial forking leg
modparam("tm", "failure_reply_mode", 3)
# default retransmission timeout: 30sec
modparam("tm", "fr_timer", 30000)
# default invite retransmission timeout after 1xx: 120sec
modparam("tm", "fr_inv_timer", 120000)

# ----- rr params -----
# set next param to 1 to add value to ;lr param (helps with some UAs)
modparam("rr", "enable_full_lr", 0)
# do not append from tag to the RR (no need for this script)
modparam("rr", "append_fromtag", 0)

# ----- acc params -----
/* what special events should be accounted ? */
modparam("acc", "early_media", 0)
modparam("acc", "report_ack", 0)
modparam("acc", "report_cancels", 0)
/* by default ww 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)
/* account triggers (flags) */
modparam("acc", "log_flag", FLT_ACC)
modparam("acc", "log_missed_flag", FLT_ACCMISSED)
modparam("acc", "log_extra",
"src_user=$fU;src_domain=$fd;src_ip=$si;"
"dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
modparam("acc", "failed_transaction_flag", FLT_ACCFAILED)

####### Routing Logic ########


/* Main SIP request routing logic
* - processing of any incoming SIP request starts with this route
* - note: this is the same as route { ... } */
request_route {

# per request initial checks
route(REQINIT);

# 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)

# record routing for dialog forming requests (in case they are routed)
# - remove preloaded route headers
remove_hf("Route");
if (is_method("INVITE|SUBSCRIBE")) {
record_route();
}

# account only INVITEs
if (is_method("INVITE")) {
setflag(FLT_ACC); # do accounting
}

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

# update $du to set the destination address for proxying
$du = "sip:" + $rd + ":9";
route(RELAY);
exit;
}

# 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()) {
sl_reply_error();
}
exit;
}

# Per SIP request initial checks
route[REQINIT] {
if($ua =~ "friendly-scanner|sipcli|VaxSIPUserAgent") {
# silent drop for scanners - uncomment next line if want to reply
# sl_send_reply("200", "OK");
exit;
}

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

if(is_method("OPTIONS") && uri==myself && $rU==$null) {
sl_send_reply("200","Keepalive");
exit;
}

if(!sanity_check("1511", "7")) {
xlog("Malformed SIP message from $si:$sp\n");
exit;
}
}

# Handle requests within SIP dialogs
route[WITHINDLG] {
if (!has_totag()) return;

# sequential request withing a dialog should
# take the path determined by record-routing
if (loose_route()) {
if (is_method("BYE")) {
setflag(FLT_ACC); # do accounting ...
setflag(FLT_ACCFAILED); # ... even if the transaction fails
} else if ( is_method("NOTIFY") ) {
# Add Record-Route for in-dialog NOTIFY as per RFC 6665.
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;
}

# Manage outgoing branches
branch_route[MANAGE_BRANCH] {
xdbg("new branch [$T_branch_idx] to $ru\n");
}

# Manage incoming replies
onreply_route[MANAGE_REPLY] {
xdbg("incoming reply\n");
}

# Manage failure routing cases
failure_route[MANAGE_FAILURE] {
if (t_is_canceled()) exit;
}

0 comments on commit 148b34e

Please sign in to comment.