<div dir="ltr">Hi Guys,<div><br></div><div>I am using Kamailio-4.2.1. Earlier I was using shared memory of 16GB, which started popping out of memory error, within few seconds of generating load from sipp.</div><div><br></div><div>I used sipp following command:</div><div><br></div><div><span style="color:rgb(0,0,0);font-family:'Sans Serif';font-size:12px;line-height:21.59375px">sipp -s 999999999999 MY_KAM_IP -l 2500 -r 50</span><br></div><div><span style="color:rgb(0,0,0);font-family:'Sans Serif';font-size:12px;line-height:21.59375px"><br></span></div><div><span style="color:rgb(0,0,0);font-family:'Sans Serif';font-size:12px;line-height:21.59375px"><b><i>Error coming is :</i></b></span></div><div><div style><font color="#000000" face="Sans Serif"><span style="font-size:12px;line-height:21.59375px"><b><i>Feb  4 14:12:23 kamailio_us_ha1 /usr/local/sbin/kamailio[27389]: ERROR: tm [t_reply.c:1946]: relay_reply(): ERROR: relay_reply: cannot alloc reply shmem</i></b></span></font></div><div style="color:rgb(0,0,0);font-family:'Sans Serif';font-size:12px;line-height:21.59375px"><br></div></div><div><span style="color:rgb(0,0,0);font-family:'Sans Serif';font-size:12px;line-height:21.59375px"><br></span></div><div><span style="color:rgb(0,0,0);font-family:'Sans Serif';font-size:12px;line-height:21.59375px"><br></span></div><div><span style="color:rgb(0,0,0);font-family:'Sans Serif';font-size:12px;line-height:21.59375px">After changing the shared memory to 1 GB, this error came quite late when</span></div><div><span style="color:rgb(0,0,0);font-family:'Sans Serif';font-size:12px;line-height:21.59375px">generate load at 200 CPS.</span></div><div><span style="color:rgb(0,0,0);font-family:'Sans Serif';font-size:12px;line-height:21.59375px">sipp -s 999999999999MY_KAM_IP -l 2500 -r 200</span><span style="color:rgb(0,0,0);font-family:'Sans Serif';font-size:12px;line-height:21.59375px"> </span></div><div><span style="color:rgb(0,0,0);font-family:'Sans Serif';font-size:12px;line-height:21.59375px"><br></span></div><div><font color="#000000" face="Sans Serif"><span style="font-size:12px;line-height:21.59375px">Why this is happening?</span></font></div><div><font color="#000000" face="Sans Serif"><span style="font-size:12px;line-height:21.59375px">I am using following configuration file( kamailio.cfg). Earliest possible help will be appreciated a lot!!</span></font></div><div><font color="#000000" face="Sans Serif"><span style="font-size:12px;line-height:21.59375px"><br></span></font></div><div><font color="#000000" face="Sans Serif"><span style="font-size:12px;line-height:21.59375px"><div style>#!KAMAILIO</div><div style>#</div><div style># Kamailio (OpenSER) SIP Server v4.0 - default configuration script</div><div style>#     - web: <a href="http://www.kamailio.org">http://www.kamailio.org</a></div><div style>#     - git: <a href="http://sip-router.org">http://sip-router.org</a></div><div style>#</div><div style># Direct your questions about this file to: <<a href="mailto:sr-users@lists.sip-router.org">sr-users@lists.sip-router.org</a>></div><div style>#</div><div style># Refer to the Core CookBook at <a href="http://www.kamailio.org/wiki/">http://www.kamailio.org/wiki/</a></div><div style># for an explanation of possible statements, functions and parameters.</div><div style>#</div><div style># Several features can be enabled using '#!define WITH_FEATURE' directives:</div><div style>#</div><div style># *** To run in debug mode: </div><div style>#     - define WITH_DEBUG</div><div style>#</div><div style># *** To enable mysql: </div><div style>#     - define WITH_MYSQL</div><div style>#</div><div style># *** To enable authentication execute:</div><div style>#     - enable mysql</div><div style>#     - define WITH_AUTH</div><div style>#     - add users using 'kamctl'</div><div style>#</div><div style># *** To enable IP authentication execute:</div><div style>#     - enable mysql</div><div style>#     - enable authentication</div><div style>#     - define WITH_IPAUTH</div><div style>#     - add IP addresses with group id '1' to 'address' table</div><div style>#</div><div style># *** To enable persistent user location execute:</div><div style>#     - enable mysql</div><div style>#     - define WITH_USRLOCDB</div><div style>#</div><div style># *** To enable nat traversal execute:</div><div style>#     - define WITH_NAT</div><div style>#     - install RTPProxy: <a href="http://www.rtpproxy.org">http://www.rtpproxy.org</a></div><div style>#     - start RTPProxy:</div><div style>#        rtpproxy -l _your_public_ip_ -s udp:localhost:7722</div><div style>#</div><div style># *** To enable TLS support execute:</div><div style>#     - adjust CFGDIR/tls.cfg as needed</div><div style>#     - define WITH_TLS</div><div style>#</div><div style># *** To enhance accounting execute:</div><div style>#     - enable mysql</div><div style>#     - define WITH_ACCDB</div><div style>#     - add following columns to database</div><div style># define WITH_LCR to enable LCR</div><div style># define WITH_CR to enable carrier route</div><div style><br></div><div style>#!define WITH_MYSQL</div><div style>#!define DBURL</div><div style>#!define WITH_USRLOCDB</div><div style>#!define WITH_FREESWITCH</div><div style>#!define WITH_ACCDB</div><div style>#!define WITH_AUTH</div><div style>#!define WITH_DEBUG</div><div style>#!define WITH_NAT</div><div style>#----#!define WITH_ANTIFLOOD</div><div style>#!define WITH_CR</div><div style><br></div><div style>#!ifdef WITH_FREESWITCH</div><div style>#freeswitch.bindip = "10.60.23.81" desc "FreeSWITCH IP Address"</div><div style>freeswitch.bindip = "54.254.97.209" desc "FreeSWITCH IP Address"</div><div style>freeswitch.bindport = "5060" desc "FreeSWITCH Port"</div><div style>#!endif</div><div style><br></div><div style><br></div><div style>#!ifdef ACCDB_COMMENT</div><div style>  ALTER TABLE acc ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';</div><div style>  ALTER TABLE acc ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';</div><div style>  ALTER TABLE acc ADD COLUMN src_ip varchar(64) NOT NULL default '';</div><div style>  ALTER TABLE acc ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';</div><div style>  ALTER TABLE acc ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';</div><div style>  ALTER TABLE acc ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';</div><div style>  ALTER TABLE missed_calls ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';</div><div style>  ALTER TABLE missed_calls ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';</div><div style>  ALTER TABLE missed_calls ADD COLUMN src_ip varchar(64) NOT NULL default '';</div><div style>  ALTER TABLE missed_calls ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';</div><div style>  ALTER TABLE missed_calls ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';</div><div style>  ALTER TABLE missed_calls ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';</div><div style>#!endif</div><div style><br></div><div style>####### Include Local Config If Exists #########</div><div style>import_file "kamailio-local.cfg"</div><div style>import_file "ip.cfg"</div><div style><br></div><div style>####### Defined Values #########</div><div style><br></div><div style># *** Value defines - IDs used later in config</div><div style>#!ifdef WITH_MYSQL</div><div style># - database URL - used to connect to database server by modules such</div><div style>#       as: auth_db, acc, usrloc, a.s.o.</div><div style>#!ifndef DBURL</div><div style>#!define DBURL "mysql://<a href="http://kamailio:kamailiorw@kamailio-us.cejtf390jur8.us-east-1.rds.amazonaws.com/kamailio">kamailio:kamailiorw@kamailio-us.cejtf390jur8.us-east-1.rds.amazonaws.com/kamailio</a>"</div><div style>#!endif</div><div style>#!endif</div><div style>#!define MULTIDOMAIN 0</div><div style><br></div><div style># - flags</div><div style>#   FLT_ - per transaction (message) flags</div><div style>#<span class="" style="white-space:pre">        </span>FLB_ - per branch flags</div><div style>#!define FLT_ACC 1</div><div style>#!define FLT_ACCMISSED 2</div><div style>#!define FLT_ACCFAILED 3</div><div style>#!define FLT_NATS 5</div><div style><br></div><div style>#!define FLB_NATB 6</div><div style>#!define FLB_NATSIPPING 7</div><div style><br></div><div style>####### Global Parameters #########</div><div style><br></div><div style>### LOG Levels: 3=DBG, 2=INFO, 1=NOTICE, 0=WARN, -1=ERR</div><div style>#!ifdef WITH_DEBUG</div><div style>debug=-1</div><div style>log_stderror=no</div><div style>#!else</div><div style>debug=-1</div><div style>log_stderror=no</div><div style>#!endif</div><div style><br></div><div style>memdbg=2</div><div style>memlog=2</div><div style><br></div><div style>log_facility=LOG_LOCAL0</div><div style><br></div><div style>fork=yes</div><div style>children=8</div><div style><br></div><div style>/* uncomment the next line to disable TCP (default on) */</div><div style>#disable_tcp=yes</div><div style><br></div><div style>/* uncomment the next line to disable the auto discovery of local aliases</div><div style>   based on reverse DNS on IPs (default on) */</div><div style>auto_aliases=no</div><div style><br></div><div style>/* add local domain aliases */</div><div style>#alias="<a href="http://sip.mydomain.com">sip.mydomain.com</a>"</div><div style><br></div><div style>/* uncomment and configure the following line if you want Kamailio to </div><div style>   bind on a specific interface/port/proto (default bind on all available) */</div><div style>#listen=udp:<a href="http://10.0.0.10:5060">10.0.0.10:5060</a></div><div style>#listen=udp:<a href="http://172.31.42.191:5060">172.31.42.191:5060</a> advertise <a href="http://54.254.97.209:5060">54.254.97.209:5060</a></div><div style>listen=LOCAL_BIND_PROTO_IP_UDP_PORT advertise ADVERTISED_BIND_IP_PORT</div><div style>listen=LOCAL_BIND_PROTO_IP_TCP_PORT advertise ADVERTISED_BIND_IP_PORT</div><div style>/* port to listen to</div><div style> * - can be specified more than once if needed to listen on many ports */</div><div style>port=5060</div><div style>mhomed=0</div><div style><br></div><div style>#!ifdef WITH_TLS</div><div style>enable_tls=yes</div><div style>#!endif</div><div style><br></div><div style># life time of TCP connection when there is no traffic</div><div style># - a bit higher than registration expires to cope with UA behind NAT</div><div style>tcp_connection_lifetime=3605</div><div style><br></div><div style>####### Modules Section ########</div><div style><br></div><div style># set paths to location of modules (to sources or installation folders)</div><div style>#!ifdef WITH_SRCPATH</div><div style>mpath="modules_k:modules"</div><div style>#!else</div><div style>mpath="/usr/local/lib/kamailio/modules_k/:/usr/local/lib64/kamailio/modules/"</div><div style>#!endif</div><div style><br></div><div style>#!ifdef WITH_MYSQL</div><div style>loadmodule "db_mysql.so"</div><div style>#!endif</div><div style><br></div><div style>loadmodule "mi_fifo.so"</div><div style>loadmodule "kex.so"</div><div style>loadmodule "corex.so"</div><div style>loadmodule "tm.so"</div><div style>loadmodule "tmx.so"</div><div style>loadmodule "sl.so"</div><div style>loadmodule "rr.so"</div><div style>loadmodule "pv.so"</div><div style>loadmodule "maxfwd.so"</div><div style>loadmodule "usrloc.so"</div><div style>loadmodule "registrar.so"</div><div style>loadmodule "textops.so"</div><div style>loadmodule "siputils.so"</div><div style>loadmodule "xlog.so"</div><div style>loadmodule "sanity.so"</div><div style>loadmodule "ctl.so"</div><div style>loadmodule "cfg_rpc.so"</div><div style>loadmodule "mi_rpc.so"</div><div style>loadmodule "acc.so"</div><div style>loadmodule "rtimer.so"</div><div style>loadmodule "sqlops.so"</div><div style>loadmodule "dispatcher.so"</div><div style>loadmodule "pdt.so"</div><div style>loadmodule "mi_datagram.so"</div><div style>loadmodule "domain.so"</div><div style>loadmodule "htable.so"</div><div style>loadmodule "pike.so"</div><div style><br></div><div style>#!ifdef WITH_LCR</div><div style>#Neeraj: Load LCR Module</div><div style>loadmodule "lcr.so"</div><div style>#!endif</div><div style><br></div><div style>#!ifdef WITH_CR</div><div style>#Neeraj: Load CR Module</div><div style>loadmodule "carrierroute.so"</div><div style>loadmodule "avpops.so"</div><div style>#!endif</div><div style><br></div><div style>#loadmodule "nat_traversal.so"</div><div style><br></div><div style>#!ifdef WITH_AUTH</div><div style>loadmodule "auth.so"</div><div style>loadmodule "auth_db.so"</div><div style>#!ifdef WITH_IPAUTH</div><div style>loadmodule "permissions.so"</div><div style>#!endif</div><div style>#!endif</div><div style><br></div><div style>#!ifdef WITH_NAT</div><div style>loadmodule "nathelper.so"</div><div style>loadmodule "rtpproxy.so"</div><div style>#!endif</div><div style><br></div><div style>#!ifdef WITH_TLS</div><div style>loadmodule "tls.so"</div><div style>#!endif</div><div style><br></div><div style>#!ifdef WITH_DEBUG</div><div style>loadmodule "debugger.so"</div><div style>#!endif</div><div style><br></div><div style># ----------------- setting module-specific parameters ---------------</div><div style><br></div><div style># for mi_datagram</div><div style>modparam("mi_datagram", "socket_name", "udp:<a href="http://127.0.0.1:8033">127.0.0.1:8033</a>")</div><div style><br></div><div style># for sqlops</div><div style>modparam("rtimer", "timer", "name=cdr;interval=300;mode=1;")</div><div style>modparam("rtimer", "exec", "timer=cdr;route=CDRS")</div><div style>modparam("sqlops", "sqlcon", "cb=>mysql://<a href="http://kamailio:kamailiorw@kamailio-us.cejtf390jur8.us-east-1.rds.amazonaws.com/kamailio">kamailio:kamailiorw@kamailio-us.cejtf390jur8.us-east-1.rds.amazonaws.com/kamailio</a>")</div><div style><br></div><div style># for domain</div><div style>modparam("domain", "db_url", "mysql://<a href="http://kamailio:kamailiorw@kamailio-us.cejtf390jur8.us-east-1.rds.amazonaws.com/kamailio">kamailio:kamailiorw@kamailio-us.cejtf390jur8.us-east-1.rds.amazonaws.com/kamailio</a>")</div><div style>#modparam("domain", "db_mode", 1)   # Use caching</div><div style>modparam("domain", "domain_table", "domain")</div><div style>modparam("domain", "register_myself", 1)</div><div style><br></div><div style># ----- mi_fifo params -----</div><div style>modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")</div><div style><br></div><div style><br></div><div style># ----- tm params -----</div><div style># auto-discard branches from previous serial forking leg</div><div style>modparam("tm", "failure_reply_mode", 3)</div><div style># default retransmission timeout: 3sec</div><div style>modparam("tm", "fr_timer", 30000)</div><div style># default invite retransmission timeout after 1xx: 5sec</div><div style>modparam("tm", "fr_inv_timer", 30000)</div><div style><br></div><div style># ----- dispatcher params -----</div><div style>modparam("dispatcher", "db_url","mysql://<a href="http://kamailio:kamailiorw@kamailio-us.cejtf390jur8.us-east-1.rds.amazonaws.com/kamailio">kamailio:kamailiorw@kamailio-us.cejtf390jur8.us-east-1.rds.amazonaws.com/kamailio</a>")</div><div style>modparam("dispatcher", "table_name", "dispatcher")</div><div style>modparam("dispatcher", "flags", 2)</div><div style>modparam("dispatcher", "dst_avp", "$avp(AVP_DST)")</div><div style>modparam("dispatcher", "grp_avp", "$avp(AVP_GRP)")</div><div style>modparam("dispatcher", "cnt_avp", "$avp(AVP_CNT)")</div><div style><br></div><div style># ---- pdt params------</div><div style>modparam("pdt", "db_url","mysql://<a href="http://kamailio:kamailiorw@kamailio-us.cejtf390jur8.us-east-1.rds.amazonaws.com/kamailio">kamailio:kamailiorw@kamailio-us.cejtf390jur8.us-east-1.rds.amazonaws.com/kamailio</a>")</div><div style>#modparam("pdt", "table_name", "pdt")</div><div style>modparam("pdt", "fetch_rows", 4000)</div><div style>modparam("pdt", "check_domain", 0)</div><div style><br></div><div style># ----- rr params -----</div><div style># add value to ;lr param to cope with most of the UAs</div><div style>modparam("rr", "enable_full_lr", 1)</div><div style># do not append from tag to the RR (no need for this script)</div><div style>modparam("rr", "append_fromtag", 1)</div><div style><br></div><div style><br></div><div style># ----- registrar params -----</div><div style>modparam("registrar", "method_filtering", 1)</div><div style>/* uncomment the next line to disable parallel forking via location */</div><div style>modparam("registrar", "append_branches", 0)</div><div style>/* uncomment the next line not to allow more than 1 contacts per AOR */</div><div style>modparam("registrar", "max_contacts", 1)</div><div style># max value for expires of registrations</div><div style>modparam("registrar", "max_expires", 3600)</div><div style># set it to 1 to enable GRUU</div><div style>modparam("registrar", "gruu_enabled", 0)</div><div style><br></div><div style><br></div><div style># ----- acc params -----</div><div style>/* what special events should be accounted ? */</div><div style>modparam("acc", "early_media", 0)</div><div style>modparam("acc", "report_ack", 0)</div><div style>modparam("acc", "report_cancels", 0)</div><div style>/* by default ww do not adjust the direct of the sequential requests.</div><div style>   if you enable this parameter, be sure the enable "append_fromtag"</div><div style>   in "rr" module */</div><div style>modparam("acc", "detect_direction", 1)</div><div style>/* account triggers (flags) */</div><div style>modparam("acc", "log_flag", FLT_ACC)</div><div style>modparam("acc", "log_missed_flag", FLT_ACCMISSED)</div><div style>modparam("acc", "log_extra", </div><div style><span class="" style="white-space:pre">      </span>"src_user=$fU;src_domain=$fd;src_ip=$si;"</div><div style><span class="" style="white-space:pre">  </span>"dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")</div><div style>modparam("acc", "failed_transaction_flag", FLT_ACCFAILED)</div><div style>/* enhanced DB accounting */</div><div style>#!ifdef WITH_ACCDB</div><div style>modparam("acc", "db_flag", FLT_ACC)</div><div style>modparam("acc", "db_missed_flag", FLT_ACCMISSED)</div><div style>modparam("acc", "db_url", "mysql://<a href="http://kamailio:kamailiorw@kamailio-us.cejtf390jur8.us-east-1.rds.amazonaws.com/kamailio">kamailio:kamailiorw@kamailio-us.cejtf390jur8.us-east-1.rds.amazonaws.com/kamailio</a>")</div><div style>modparam("acc", "db_extra",</div><div style><span class="" style="white-space:pre">      </span>"src_user=$fU;src_domain=$fd;src_ip=$si;"</div><div style><span class="" style="white-space:pre">  </span>"dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")</div><div style>#!endif</div><div style><br></div><div style><br></div><div style># ----- usrloc params -----</div><div style>/* enable DB persistency for location entries */</div><div style>#!ifdef WITH_USRLOCDB</div><div style>modparam("usrloc", "db_url", "mysql://<a href="http://kamailio:kamailiorw@kamailio-us.cejtf390jur8.us-east-1.rds.amazonaws.com/kamailio">kamailio:kamailiorw@kamailio-us.cejtf390jur8.us-east-1.rds.amazonaws.com/kamailio</a>")</div><div style># Neeraj : Disabled Saving Location in DB</div><div style>#modparam("usrloc", "db_mode", 2)</div><div style>modparam("usrloc", "db_mode", 0)</div><div style># Neeraj : Enabling Multiple Domain</div><div style>modparam("usrloc", "use_domain", MULTIDOMAIN)</div><div style>#!endif</div><div style><br></div><div style><br></div><div style># ----- auth_db params -----</div><div style>#!ifdef WITH_AUTH</div><div style>modparam("auth_db", "db_url","mysql://<a href="http://kamailio:kamailiorw@kamailio-us.cejtf390jur8.us-east-1.rds.amazonaws.com/kamailio">kamailio:kamailiorw@kamailio-us.cejtf390jur8.us-east-1.rds.amazonaws.com/kamailio</a>")</div><div style>modparam("auth_db", "calculate_ha1", yes)</div><div style>modparam("auth_db", "password_column", "password")</div><div style>modparam("auth_db", "load_credentials", "")</div><div style>modparam("auth_db", "use_domain", MULTIDOMAIN)</div><div style><br></div><div style># ----- permissions params -----</div><div style>#!ifdef WITH_IPAUTH</div><div style>modparam("permissions", "db_url", DBURL)</div><div style>modparam("permissions", "db_mode", 1)</div><div style>#!endif</div><div style><br></div><div style>#!endif</div><div style><br></div><div style><br></div><div style>#!ifdef WITH_NAT</div><div style># ----- rtpproxy params -----</div><div style>#modparam("rtpproxy", "rtpproxy_sock", "udp:<a href="http://127.0.0.1:7722">127.0.0.1:7722</a>")</div><div style>modparam("rtpproxy", "rtpproxy_sock", "udp:<a href="http://10.0.0.121:22222">10.0.0.121:22222</a>")</div><div style><br></div><div style># ----- nathelper params -----</div><div style>modparam("nathelper", "natping_interval", 30)</div><div style>modparam("nathelper", "ping_nated_only", 1)</div><div style>modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)</div><div style>modparam("nathelper", "sipping_from", "<a href="mailto:sip%3Apinger@kamailio.org">sip:pinger@kamailio.org</a>")</div><div style><br></div><div style># params needed for NAT traversal in other modules</div><div style>modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)")</div><div style>modparam("usrloc", "nat_bflag", FLB_NATB)</div><div style>#!endif</div><div style><br></div><div style><br></div><div style>#!ifdef WITH_TLS</div><div style># ----- tls params -----</div><div style>modparam("tls", "config", "/usr/local/etc/kamailio/tls.cfg")</div><div style>#!endif</div><div style><br></div><div style>#!ifdef WITH_DEBUG</div><div style># ----- debugger params -----</div><div style>modparam("debugger", "cfgtrace", 0)</div><div style>#!endif</div><div style><br></div><div style><br></div><div style>#!ifdef WITH_LCR</div><div style>modparam("lcr", "db_url", "mysql://<a href="http://kamailioro:kamailioro@kamailio-us.cejtf390jur8.us-east-1.rds.amazonaws.com/kamailio">kamailioro:kamailioro@kamailio-us.cejtf390jur8.us-east-1.rds.amazonaws.com/kamailio</a>")</div><div style>modparam("lcr", "gw_uri_avp", "$avp(i:709)")</div><div style>modparam("lcr", "ruri_user_avp", "$avp(i:500)")</div><div style>modparam("lcr", "tag_avp", "$avp(lcr_tag)")</div><div style>modparam("lcr", "flags_avp", "$avp(i:712)")</div><div style>modparam("lcr", "lcr_id_avp", "$avp(s:lcr_id_avp)")</div><div style>modparam("lcr", "defunct_gw_avp", "$avp(s:defunct_gw_avp)")</div><div style>#!endif</div><div style><br></div><div style>#!ifdef WITH_CR</div><div style>#Neeraj: ----carrierroute params-------</div><div style>modparam("carrierroute", "config_source", "db")</div><div style>modparam("carrierroute", "db_url", "mysql://<a href="http://kamailioro:kamailioro@kamailio-us.cejtf390jur8.us-east-1.rds.amazonaws.com/kamailio">kamailioro:kamailioro@kamailio-us.cejtf390jur8.us-east-1.rds.amazonaws.com/kamailio</a>")</div><div style>modparam("carrierroute", "carrierroute_table", "carrierroute")</div><div style>modparam("carrierroute", "default_tree", "default")</div><div style>modparam("carrierroute", "fetch_rows", 2000)</div><div style>#!endif</div><div style>####### Routing Logic ########</div><div style><br></div><div style><br></div><div style># Main SIP request routing logic</div><div style># - processing of any incoming SIP request starts with this route</div><div style># - note: this is the same as route { ... }</div><div style>request_route {</div><div style><br></div><div style><span class="" style="white-space:pre"> </span># per request initial checks</div><div style><span class="" style="white-space:pre"> </span>route(REQINIT);</div><div style><br></div><div style><span class="" style="white-space:pre">       </span># NAT detection</div><div style><span class="" style="white-space:pre">      </span>route(NATDETECT);</div><div style><br></div><div style><span class="" style="white-space:pre">     </span># CANCEL processing</div><div style><span class="" style="white-space:pre">  </span>if (is_method("CANCEL")) {</div><div style><span class="" style="white-space:pre">         </span>if (t_check_trans()) {</div><div style><span class="" style="white-space:pre">                       </span>route(RELAY);</div><div style><span class="" style="white-space:pre">                </span>}</div><div style><span class="" style="white-space:pre">            </span>exit;</div><div style><span class="" style="white-space:pre">        </span>}</div><div style><br></div><div style><span class="" style="white-space:pre">     </span># handle requests within SIP dialogs</div><div style><span class="" style="white-space:pre"> </span>route(WITHINDLG);</div><div style><br></div><div style><span class="" style="white-space:pre">     </span>### only initial requests (no To tag)</div><div style><br></div><div style><span class="" style="white-space:pre"> </span>t_check_trans();</div><div style><br></div><div style><span class="" style="white-space:pre">      </span># authentication</div><div style><span class="" style="white-space:pre">     </span>route(AUTH);</div><div style><br></div><div style><span class="" style="white-space:pre">  </span># record routing for dialog forming requests (in case they are routed)</div><div style><span class="" style="white-space:pre">       </span># - remove preloaded route headers</div><div style><span class="" style="white-space:pre">   </span>remove_hf("Route");</div><div style><span class="" style="white-space:pre">        </span>if (is_method("INVITE|SUBSCRIBE"))</div><div style><span class="" style="white-space:pre">         </span>record_route();</div><div style><br></div><div style><span class="" style="white-space:pre">       </span># account only INVITEs</div><div style><span class="" style="white-space:pre">       </span>if (is_method("INVITE")) {</div><div style><span class="" style="white-space:pre">         </span>setflag(FLT_ACC); # do accounting</div><div style><span class="" style="white-space:pre">    </span>}</div><div style><br></div><div style>#!ifdef WITH_LCR</div><div style>        #Neeraj: oute request to LCR</div><div style>        route(LCR);</div><div style>#!endif</div><div style><br></div><div style><span class="" style="white-space:pre">    </span># dispatch requests to foreign domains</div><div style><span class="" style="white-space:pre">       </span>route(SIPOUT);</div><div style><br></div><div style><span class="" style="white-space:pre">        </span>### requests for my local domains</div><div style><br></div><div style><span class="" style="white-space:pre">     </span># handle registrations</div><div style><span class="" style="white-space:pre">       </span>route(REGISTRAR);</div><div style><br></div><div style><span class="" style="white-space:pre">     </span>if ($rU==$null) {</div><div style><span class="" style="white-space:pre">            </span># request with no Username in RURI</div><div style><span class="" style="white-space:pre">           </span>sl_send_reply("484","Address Incomplete");</div><div style><span class="" style="white-space:pre">               </span>exit;</div><div style><span class="" style="white-space:pre">        </span>}</div><div style><br></div><div style>#!ifdef WITH_CR</div><div style>#        route(CARRIER_ROUTE);</div><div style>#!endif</div><div style><span class="" style="white-space:pre">      </span># user location service</div><div style><span class="" style="white-space:pre">      </span>route(LOCATION);</div><div style><br></div><div style>}</div><div style>#!ifdef WITH_CR</div><div style>route[CARRIER_ROUTE]</div><div style>{</div><div style>if(!cr_route("default", "default", "$rU", "$rU", "call_id")){</div><div style><span class="" style="white-space:pre">         </span>sl_send_reply("403", "Not Carrier Found");</div><div style>                exit;</div><div style><span class="" style="white-space:pre">     </span>} else {</div><div style><span class="" style="white-space:pre">             </span># In case of failure, re-route the request</div><div style><span class="" style="white-space:pre">           </span>#t_on_failure(1);</div><div style>                t_on_failure("MANAGE_FAILURE");</div><div style><span class="" style="white-space:pre">              </span># Relay the request to the gateway</div><div style>#<span class="" style="white-space:pre">          </span>t_relay();</div><div style><span class="" style="white-space:pre">   </span>}</div><div style>}</div><div style><br></div><div style>failure_route[1] {</div><div style>        xlog("route[FAILOVER_ROUTE: called");</div><div style><span class="" style="white-space:pre">        </span># In case of failure, send it to an alternative route:</div><div style><span class="" style="white-space:pre">       </span>if (t_check_status("403|5[0-9][0-9]")) {</div><div style><span class="" style="white-space:pre">           </span>#choose route domain 1 of the default carrier</div><div style><span class="" style="white-space:pre">        </span>if(!cr_route("failover", "failover", "$rU", "$rU", "call_id")){</div><div style><span class="" style="white-space:pre">                    </span>t_reply("403", "Not allowed");</div><div style><span class="" style="white-space:pre">           </span>} else {</div><div style><span class="" style="white-space:pre">                     </span>t_on_failure("2");</div><div style>#<span class="" style="white-space:pre">                        </span>t_relay();</div><div style><span class="" style="white-space:pre">           </span>}</div><div style><span class="" style="white-space:pre">    </span>}</div><div style>}</div><div style>#!endif</div><div style><br></div><div style><br></div><div style>#!ifdef WITH_CR_OLD</div><div style>route[CARRIER_ROUTE]</div><div style>{</div><div style>        xlog("route[CARRIER_ROUTE: called");</div><div style>        # LOOKUP ROUTE TABLE WHEN ASKED BY HEADER: X-ROUTE:LOOKUP</div><div style>        if (is_method("INVITE") && $hdr(X-ROUTE)=="LOOKUP"){</div><div style>                if(!cr_route("default", "default", "$rU", "$rU", "call_id","$avp(s:route_desc)")){</div><div style>                     xlog("CARRIER_ROUTE:ROUTING FAILED: no route found for $rU");</div><div style>                     sl_send_reply("604", "Unable to route this call");</div><div style>                     exit;</div><div style>                } else {</div><div style>                     xlog("CARRIER_ROUTE:LOOKUP FOUND: $rd $avp(s:route_desc)");</div><div style><span class="" style="white-space:pre">                </span>     avp_pushto("$ru/username", "$avp(s:route_desc)");<span class="" style="white-space:pre">                      </span>       </div><div style>                     sl_send_reply("302", "$rd");</div><div style>                     exit;</div><div style>                }</div><div style>        } else {</div><div style><br></div><div style>        xlog("route[CARRIER_ROUTE: method is not either INVITE or X-ROUTE LOOKUP");</div><div style><br></div><div style>        }</div><div style>}</div><div style>#!endif</div><div style><br></div><div style>#!ifdef WITH_LCR</div><div style>route[LCR] {</div><div style>if (status=="200")</div><div style>{</div><div style>  xlog("LCR: Inside the LCR route\n");</div><div style>}</div><div style><br></div><div style>if(method=="INVITE")</div><div style>{</div><div style>  xlog("We got an invite for: '$rU'");</div><div style>  if(!load_gws(1, $rU, $var(caller_uri))) {</div><div style>    xlog("Couldn't load gateways");</div><div style>    sl_send_reply("500", "Server Internal Error - Cannot load gateways");</div><div style>    exit;</div><div style>  } else {</div><div style>        xlog("GW Selected '$avp(i:709)'\n");</div><div style>        xlog("Domain of destination: $dd\n");</div><div style>        xlog("To URI: $tu\n");</div><div style>  }</div><div style><br></div><div style>  if(!next_gw()) {</div><div style>    xlog("Couldn't proceed to next gateway");</div><div style>    sl_send_reply("503", "Service not available, no gateways found");</div><div style>    exit;</div><div style>  } else {</div><div style>        xlog("Calling the first matched gateway\n");</div><div style>        xlog("ruri_user_avp: '$avp(i:500)'\n");</div><div style>        xlog("To URI after next_gw: $tu\n");</div><div style>        xlog("Request URI: $rU\n");</div><div style><br></div><div style>  }</div><div style><br></div><div style>};</div><div style>}</div><div style>#!endif</div><div style><br></div><div style>route[FSDISPATCH] {</div><div style>        # dial number selection</div><div style>        route(FSRELAY);</div><div style>        exit;</div><div style>}</div><div style><br></div><div style>route[FSRELAY] {</div><div style>        $du = "sip:" + $sel(cfg_get.freeswitch.bindip) + ":" + $sel(cfg_get.freeswitch.bindport);</div><div style>        if($var(newbranch)==1)</div><div style>        {</div><div style>                append_branch();</div><div style>                $var(newbranch) = 0;</div><div style>        }</div><div style>        route(RELAY);</div><div style>        exit;</div><div style>}</div><div style><br></div><div style><br></div><div style>route[RELAY] {</div><div style>#!ifdef WITH_NAT</div><div style>        if (check_route_param("nat=yes")) {</div><div style>                setbflag(FLB_NATB);</div><div style>        }</div><div style>#!endif</div><div style><span class="" style="white-space:pre">       </span># enable additional event routes for forwarded requests</div><div style><span class="" style="white-space:pre">      </span># - serial forking, RTP relaying handling, a.s.o.</div><div style><span class="" style="white-space:pre">    </span>if (is_method("INVITE|BYE|SUBSCRIBE|UPDATE")) {</div><div style><span class="" style="white-space:pre">            </span>if(!t_is_set("branch_route")) t_on_branch("MANAGE_BRANCH");</div><div style><span class="" style="white-space:pre">      </span>}</div><div style><span class="" style="white-space:pre">    </span>if (is_method("INVITE|SUBSCRIBE|UPDATE")) {</div><div style><span class="" style="white-space:pre">                </span>if(!t_is_set("onreply_route")) t_on_reply("MANAGE_REPLY");</div><div style><span class="" style="white-space:pre">       </span>}</div><div style><span class="" style="white-space:pre">    </span>if (is_method("INVITE")) {</div><div style><span class="" style="white-space:pre">         </span>if(!t_is_set("failure_route")) t_on_failure("MANAGE_FAILURE");</div><div style><span class="" style="white-space:pre">   </span>}</div><div style><br></div><div style><span class="" style="white-space:pre">     </span>if (!t_relay()) {</div><div style><span class="" style="white-space:pre">            </span>sl_reply_error();</div><div style><span class="" style="white-space:pre">    </span>}</div><div style><span class="" style="white-space:pre">    </span>exit;</div><div style>}</div><div style><br></div><div style># Per SIP request initial checks</div><div style>route[REQINIT] {</div><div style>#!ifdef WITH_ANTIFLOOD</div><div style><span class="" style="white-space:pre">      </span># flood dection from same IP and traffic ban for a while</div><div style><span class="" style="white-space:pre">     </span># be sure you exclude checking trusted peers, such as pstn gateways</div><div style><span class="" style="white-space:pre">  </span># - local host excluded (e.g., loop to self)</div><div style><span class="" style="white-space:pre"> </span>if(src_ip!=myself) {</div><div style><span class="" style="white-space:pre">         </span>if($sht(ipban=>$si)!=$null) {</div><div style><span class="" style="white-space:pre">                     </span># ip is already blocked</div><div style><span class="" style="white-space:pre">                      </span>xdbg("request from blocked IP - $rm from $fu (IP:$si:$sp)\n");</div><div style><span class="" style="white-space:pre">                     </span>exit;</div><div style><span class="" style="white-space:pre">                </span>}</div><div style><span class="" style="white-space:pre">            </span>if (!pike_check_req()) {</div><div style><span class="" style="white-space:pre">                     </span>xlog("L_ALERT","ALERT: pike blocking $rm from $fu (IP:$si:$sp)\n");</div><div style><span class="" style="white-space:pre">                      </span>$sht(ipban=>$si) = 1;</div><div style><span class="" style="white-space:pre">                     </span>exit;</div><div style><span class="" style="white-space:pre">                </span>}</div><div style><span class="" style="white-space:pre">    </span>}</div><div style>#!endif</div><div style><br></div><div style><span class="" style="white-space:pre"> </span>if (!mf_process_maxfwd_header("10")) {</div><div style><span class="" style="white-space:pre">             </span>sl_send_reply("483","Too Many Hops");</div><div style><span class="" style="white-space:pre">            </span>exit;</div><div style><span class="" style="white-space:pre">        </span>}</div><div style><br></div><div style><span class="" style="white-space:pre">     </span>if(!sanity_check("1511", "7")) {</div><div style><span class="" style="white-space:pre">         </span>xlog("Malformed SIP message from $si:$sp\n");</div><div style><span class="" style="white-space:pre">              </span>exit;</div><div style><span class="" style="white-space:pre">        </span>}</div><div style>}</div><div style><br></div><div style># Handle requests within SIP dialogs</div><div style>route[WITHINDLG] {</div><div style><span class="" style="white-space:pre">       </span>if (has_totag()) {</div><div style><span class="" style="white-space:pre">           </span># sequential request withing a dialog should</div><div style><span class="" style="white-space:pre">         </span># take the path determined by record-routing</div><div style><span class="" style="white-space:pre">         </span>if (loose_route()) {</div><div style><span class="" style="white-space:pre">                 </span>route(DLGURI);</div><div style><span class="" style="white-space:pre">                       </span>if (is_method("BYE")) {</div><div style><span class="" style="white-space:pre">                            </span>setflag(FLT_ACC); # do accounting ...</div><div style><span class="" style="white-space:pre">                                </span>setflag(FLT_ACCFAILED); # ... even if the transaction fails</div><div style><span class="" style="white-space:pre">                  </span>}</div><div style><span class="" style="white-space:pre">                    </span>else if ( is_method("ACK") ) {</div><div style><span class="" style="white-space:pre">                             </span># ACK is forwarded statelessy</div><div style><span class="" style="white-space:pre">                                </span>route(NATMANAGE);</div><div style><span class="" style="white-space:pre">                    </span>}</div><div style><span class="" style="white-space:pre">                    </span>else if ( is_method("NOTIFY") ) {</div><div style><span class="" style="white-space:pre">                          </span># Add Record-Route for in-dialog NOTIFY as per RFC 6665.</div><div style><span class="" style="white-space:pre">                             </span>record_route();</div><div style><span class="" style="white-space:pre">                      </span>}</div><div style><span class="" style="white-space:pre">                    </span>route(RELAY);</div><div style><span class="" style="white-space:pre">                </span>} else {</div><div style><span class="" style="white-space:pre">                     </span>if ( is_method("ACK") ) {</div><div style><span class="" style="white-space:pre">                          </span>if ( t_check_trans() ) {</div><div style><span class="" style="white-space:pre">                                     </span># no loose-route, but stateful ACK;</div><div style><span class="" style="white-space:pre">                                  </span># must be an ACK after a 487</div><div style><span class="" style="white-space:pre">                                 </span># or e.g. 404 from upstream server</div><div style><span class="" style="white-space:pre">                                   </span>route(RELAY);</div><div style><span class="" style="white-space:pre">                                        </span>exit;</div><div style><span class="" style="white-space:pre">                                </span>} else {</div><div style><span class="" style="white-space:pre">                                     </span># ACK without matching transaction ... ignore and discard</div><div style><span class="" style="white-space:pre">                                    </span>exit;</div><div style><span class="" style="white-space:pre">                                </span>}</div><div style><span class="" style="white-space:pre">                    </span>}</div><div style><span class="" style="white-space:pre">                    </span>sl_send_reply("404","Not here");</div><div style><span class="" style="white-space:pre">         </span>}</div><div style><span class="" style="white-space:pre">            </span>exit;</div><div style><span class="" style="white-space:pre">        </span>}</div><div style>}</div><div style><br></div><div style># Handle SIP registrations</div><div style>route[REGISTRAR] {</div><div style><span class="" style="white-space:pre"> </span>if (is_method("REGISTER")) {</div><div style><span class="" style="white-space:pre">               </span>if(isflagset(FLT_NATS)) {</div><div style><span class="" style="white-space:pre">                    </span>setbflag(FLB_NATB);</div><div style><span class="" style="white-space:pre">                  </span># uncomment next line to do SIP NAT pinging </div><div style><span class="" style="white-space:pre">                        </span>setbflag(FLB_NATSIPPING);</div><div style><span class="" style="white-space:pre">            </span>}</div><div style><span class="" style="white-space:pre">            </span>if (!save("location",5))</div><div style><span class="" style="white-space:pre">                   </span>sl_reply_error();</div><div style><br></div><div style><span class="" style="white-space:pre">             </span>exit;</div><div style><span class="" style="white-space:pre">        </span>}</div><div style>}</div><div style><br></div><div style># USER location service</div><div style>route[LOCATION] {</div><div style><span class="" style="white-space:pre">     </span>if (!lookup("location")) {</div><div style><span class="" style="white-space:pre">         </span>$var(rc) = $rc;</div><div style><span class="" style="white-space:pre">              </span>t_newtran();</div><div style><span class="" style="white-space:pre">         </span>switch ($var(rc)) {</div><div style><span class="" style="white-space:pre">                  </span>case -1:</div><div style><span class="" style="white-space:pre">                     </span>case -3:</div><div style>                                if(!cr_route("default", "default", "$rU", "$rU", "call_id")){</div><div style><span class="" style="white-space:pre">         </span>                  sl_send_reply("403", "Not Carrier Found"); </div><div style>                                  exit;</div><div style>                                }</div><div style>                                break;</div><div style><span class="" style="white-space:pre">                    </span>case -2:</div><div style><span class="" style="white-space:pre">                             </span>send_reply("405", "Method Not Allowed");</div><div style><span class="" style="white-space:pre">                         </span>exit;</div><div style><span class="" style="white-space:pre">                </span>}</div><div style><span class="" style="white-space:pre">    </span>}</div><div style><br></div><div style><span class="" style="white-space:pre">     </span># when routing via usrloc, log the missed calls also</div><div style><span class="" style="white-space:pre"> </span>if (is_method("INVITE")) {</div><div style><span class="" style="white-space:pre">         </span>setflag(FLT_ACCMISSED);</div><div style><span class="" style="white-space:pre">      </span>}</div><div style><br></div><div style><span class="" style="white-space:pre">     </span>route(RELAY);</div><div style><span class="" style="white-space:pre">        </span>exit;</div><div style>}</div><div style><br></div><div style># Authentication route</div><div style>route[AUTH] {</div><div style>#!ifdef WITH_AUTH</div><div style><br></div><div style>#!ifdef WITH_IPAUTH</div><div style><span class="" style="white-space:pre"> </span>if((!is_method("REGISTER")) && allow_source_address()) {</div><div style><span class="" style="white-space:pre">           </span># source IP allowed</div><div style><span class="" style="white-space:pre">          </span>return;</div><div style><span class="" style="white-space:pre">      </span>}</div><div style>#!endif</div><div style><br></div><div style><span class="" style="white-space:pre"> </span>if (is_method("REGISTER") || from_uri==myself) {</div><div style><span class="" style="white-space:pre">           </span># authenticate requests</div><div style><span class="" style="white-space:pre">              </span>if (!auth_check("$fd", "subscriber", "1")) {</div><div style><span class="" style="white-space:pre">                   </span>auth_challenge("$fd", "0");</div><div style><span class="" style="white-space:pre">                      </span>exit;</div><div style><span class="" style="white-space:pre">                </span>}</div><div style><span class="" style="white-space:pre">            </span># user authenticated - remove auth header</div><div style><span class="" style="white-space:pre">            </span>if(!is_method("REGISTER|PUBLISH"))</div><div style><span class="" style="white-space:pre">                 </span>consume_credentials();</div><div style><span class="" style="white-space:pre">       </span>}</div><div style><span class="" style="white-space:pre">    </span># if caller is not local subscriber, then check if it calls</div><div style><span class="" style="white-space:pre">  </span># a local destination, otherwise deny, not an open relay here</div><div style><span class="" style="white-space:pre">        </span>if (from_uri!=myself && uri!=myself) {</div><div style><span class="" style="white-space:pre">               </span>sl_send_reply("403","Not relaying");</div><div style><span class="" style="white-space:pre">             </span>exit;</div><div style><span class="" style="white-space:pre">        </span>}</div><div style><br></div><div style>#!endif</div><div style><span class="" style="white-space:pre"> </span>return;</div><div style>}</div><div style><br></div><div style># Caller NAT detection route</div><div style>route[NATDETECT] {</div><div style>#!ifdef WITH_NAT</div><div style><span class="" style="white-space:pre">    </span>force_rport();</div><div style><span class="" style="white-space:pre">       </span>if (nat_uac_test("19")) {</div><div style><span class="" style="white-space:pre">          </span>if (is_method("REGISTER")) {</div><div style><span class="" style="white-space:pre">               </span>#<span class="" style="white-space:pre"> </span>fix_nated_register();</div><div style>                        fix_nated_contact();</div><div style><span class="" style="white-space:pre">           </span>} else {</div><div style><span class="" style="white-space:pre">                     </span>add_contact_alias();</div><div style><span class="" style="white-space:pre">         </span>}</div><div style><span class="" style="white-space:pre">            </span>setflag(FLT_NATS);</div><div style><span class="" style="white-space:pre">   </span>}</div><div style>#!endif</div><div style><span class="" style="white-space:pre">        </span>return;</div><div style>}</div><div style><br></div><div style># RTPProxy control</div><div style>route[NATMANAGE] {</div><div style>#!ifdef WITH_NAT</div><div style><span class="" style="white-space:pre">      </span>if (is_request()) {</div><div style><span class="" style="white-space:pre">          </span>if(has_totag()) {</div><div style><span class="" style="white-space:pre">                    </span>if(check_route_param("nat=yes")) {</div><div style><span class="" style="white-space:pre">                         </span>setbflag(FLB_NATB);</div><div style><span class="" style="white-space:pre">                  </span>}</div><div style><span class="" style="white-space:pre">            </span>}</div><div style><span class="" style="white-space:pre">    </span>}</div><div style><span class="" style="white-space:pre">    </span>if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB)))</div><div style><span class="" style="white-space:pre">          </span>return;</div><div style><br></div><div style><span class="" style="white-space:pre">       </span>rtpproxy_manage("co");</div><div style><br></div><div style><span class="" style="white-space:pre">      </span>if (is_request()) {</div><div style><span class="" style="white-space:pre">          </span>if (!has_totag()) {</div><div style><span class="" style="white-space:pre">                  </span>if(t_is_branch_route()) {</div><div style><span class="" style="white-space:pre">                            </span>add_rr_param(";nat=yes");</div><div style><span class="" style="white-space:pre">                  </span>}</div><div style><span class="" style="white-space:pre">            </span>}</div><div style><span class="" style="white-space:pre">    </span>}</div><div style><span class="" style="white-space:pre">    </span>if (is_reply()) {</div><div style><span class="" style="white-space:pre">            </span>if(isbflagset(FLB_NATB)) {</div><div style><span class="" style="white-space:pre">                   </span>add_contact_alias();</div><div style><span class="" style="white-space:pre">         </span>}</div><div style><span class="" style="white-space:pre">    </span>}</div><div style>#!endif</div><div style><span class="" style="white-space:pre">        </span>return;</div><div style>}</div><div style><br></div><div style># URI update for dialog requests</div><div style>route[DLGURI] {</div><div style>#!ifdef WITH_NAT</div><div style><span class="" style="white-space:pre">   </span>if(!isdsturiset()) {</div><div style><span class="" style="white-space:pre">         </span>handle_ruri_alias();</div><div style><span class="" style="white-space:pre"> </span>}</div><div style>#!endif</div><div style><span class="" style="white-space:pre">        </span>return;</div><div style>}</div><div style><br></div><div style>route[CDRS] {</div><div style><span class="" style="white-space:pre">       </span>sql_query("cb","call kamailio_cdrs()","rb");</div><div style><span class="" style="white-space:pre">   </span>sql_query("cb","call kamailio_rating('default')","rb");</div><div style> </div><div style>}</div><div style><br></div><div style># Routing to foreign domains</div><div style>route[SIPOUT] {</div><div style><span class="" style="white-space:pre">       </span>if (!uri==myself) {</div><div style><span class="" style="white-space:pre">          </span>append_hf("P-hint: outbound\r\n");</div><div style><span class="" style="white-space:pre">         </span>route(RELAY);</div><div style><span class="" style="white-space:pre">        </span>}</div><div style>}</div><div style><br></div><div style># manage outgoing branches</div><div style>branch_route[MANAGE_BRANCH] {</div><div style><span class="" style="white-space:pre">      </span>xdbg("new branch [$T_branch_idx] to $ru\n");</div><div style><span class="" style="white-space:pre">       </span>route(NATMANAGE);</div><div style>}</div><div style><br></div><div style># manage incoming replies</div><div style>onreply_route[MANAGE_REPLY] {</div><div style><span class="" style="white-space:pre">       </span>xdbg("incoming reply\n");</div><div style><span class="" style="white-space:pre">  </span>if(status=~"[12][0-9][0-9]")</div><div style><span class="" style="white-space:pre">               </span>route(NATMANAGE);</div><div style>}</div><div style><br></div><div style># manage failure routing cases</div><div style>failure_route[MANAGE_FAILURE] {</div><div style><span class="" style="white-space:pre">        </span>route(NATMANAGE);</div><div style><br></div><div style><span class="" style="white-space:pre">     </span>if (t_is_canceled()) {</div><div style><span class="" style="white-space:pre">               </span>exit;</div><div style><span class="" style="white-space:pre">        </span>}</div><div style>}</div><div style><br></div><div style># Dispatch requests</div><div style>route[DISPATCH] {</div><div style><span class="" style="white-space:pre"> </span># round robin dispatching on gateways group '1'</div><div style><span class="" style="white-space:pre">      </span>if(!ds_select_dst("1", "4"))</div><div style><span class="" style="white-space:pre">     </span>{</div><div style><span class="" style="white-space:pre">            </span>send_reply("404", "No destination");</div><div style><span class="" style="white-space:pre">             </span>exit;</div><div style><span class="" style="white-space:pre">        </span>}</div><div style><span class="" style="white-space:pre">    </span>xlog("L_DBG", "--- SCRIPT: going to <$ru> via <$du>\n");</div><div style><span class="" style="white-space:pre">     </span>t_on_failure("RTF_DISPATCH");</div><div style><span class="" style="white-space:pre">      </span>return;</div><div style>}</div><div style> </div><div style># Sample failure route</div><div style>failure_route[RTF_DISPATCH] {</div><div style><span class="" style="white-space:pre">    </span>if (t_is_canceled()) {</div><div style><span class="" style="white-space:pre">               </span>exit;</div><div style><span class="" style="white-space:pre">        </span>}</div><div style><span class="" style="white-space:pre">    </span># next DST - only for 500 or local timeout</div><div style><span class="" style="white-space:pre">   </span>if (t_check_status("500")</div><div style><span class="" style="white-space:pre">                  </span>or (t_branch_timeout() and !t_branch_replied()))</div><div style><span class="" style="white-space:pre">     </span>{</div><div style><span class="" style="white-space:pre">            </span>if(ds_next_dst())</div><div style><span class="" style="white-space:pre">            </span>{</div><div style><span class="" style="white-space:pre">                    </span>t_on_failure("RTF_DISPATCH");</div><div style><span class="" style="white-space:pre">                      </span>route(RELAY);</div><div style><span class="" style="white-space:pre">                        </span>exit;</div><div style><span class="" style="white-space:pre">                </span>}</div><div style><span class="" style="white-space:pre">    </span>}</div><div style>}</div></span></font></div><div><font color="#000000" face="Sans Serif"><span style="font-size:12px;line-height:21.59375px"><br></span></font></div><div><span style="color:rgb(0,0,0);font-family:'Sans Serif';font-size:12px;line-height:21.59375px"><br></span></div><div><span style="color:rgb(0,0,0);font-family:'Sans Serif';font-size:12px;line-height:21.59375px"><br></span></div><div><span style="color:rgb(0,0,0);font-family:'Sans Serif';font-size:12px;line-height:21.59375px">Regards</span></div><div><span style="color:rgb(0,0,0);font-family:'Sans Serif';font-size:12px;line-height:21.59375px">Neeraj Swarnkar</span></div></div>