[SR-Users] SIP and RTP Proxy for multiple Servers

sewlist at gmail.com sewlist at gmail.com
Thu Aug 23 09:42:09 CEST 2018


Im very new to kamailio,

we have some ptime issues which causes one way audio due to varies PBX
vendors connecting to our class 5 softswitches

I would like to use Kamailio as the SIP/RTP proxy in front of our class 5
soft switches

I followed the example of freeswitch and kamailio. However the config is
still hard for me

below setup works, however RTP not being proxied, Looks like its its not,
because im not using NAT, so RTP goes direct

https://freeswitch.org/confluence/display/FREESWITCH/Kamailio+basic+setup+as+proxy+for+FreeSWITCH

I would like to to ensure RTP proxy is always used(possible re-framing
ptime) and we have  multiple soft switches

Is it possible to setup kamailio.cfg so my customers can point the endpoint
to kamailio and domain names contains the server we want to use to register
with?



eg, softswitch 1 = 1.1.1.2
     softswitch 2 = 1.1.1.3
     softswitch 3 = 1.1.1.4

etc etc

my current config

#!KAMAILIO

#!define IPADDRESS "1.1.1.1"

#!define SWITCH_IPADDRESS "1.1.1.2"


#!define FLAG_FROM_SWITCH 1
#!define FLAG_FROM_USER 2

# ------------------ module loading ----------------------------------
loadmodule "tm.so"
loadmodule "rr.so"
loadmodule "pv.so"
loadmodule "sl.so"
loadmodule "maxfwd.so"
loadmodule "nathelper.so"
loadmodule "textops.so"
loadmodule "siputils.so"
loadmodule "xlog.so"
loadmodule "sanity.so"
loadmodule "path.so"

loadmodule "rtpproxy.so"


# ----------------- setting module-specific parameters ---------------
modparam("nathelper|registrar", "received_avp", "$avp(s:rcv)")
# -------------------------  request routing logic -------------------

#!ifdef WITH_NAT
# ----- rtpproxy params -----
modparam("rtpproxy", "rtpproxy_sock", "udp:127.0.0.1:7722")

# ----- nathelper params -----
modparam("nathelper", "natping_interval", 30)
modparam("nathelper", "ping_nated_only", 1)
modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)
modparam("nathelper", "sipping_from", "sip:pinger at kamailio.org")

# params needed for NAT traversal in other modules
modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)")
modparam("usrloc", "nat_bflag", FLB_NATB)
#!endif



# main routing logic

route {

       # per request initial checks
       route(SANITY_CHECK);

       # CANCEL processing
       if (is_method("CANCEL")) {
               if (t_check_trans()) {
                       t_relay();
               }
               exit;
       }

       route(CHECK_SOURCE_IP);

       ##################################
       ### HANDLE SEQUENTIAL REQUESTS ###
       route(WITHINDLG);

       ###############################
       ### HANDLE INITIAL REQUESTS ###
       t_check_trans();

       if (is_method("INVITE|REFER")) {
               record_route();
       }

       if (is_method("REGISTER")) {
           add_path();
       }

       if (isflagset(FLAG_FROM_SWITCH)) {
               # don't send INVITE from SWITCH back to SWITCH, set reply
route to handle NAT and forward them along
               t_on_reply("EXTERNAL_REPLY");
       } else {
               # set destination to your SWITCH
               $du = "sip:1.1.1.2:5060";
       }

       route(RELAY);


}


route[SANITY_CHECK]
{
       if (!sanity_check()) {
               #xlog("L_WARN", "$ci|end|message is insane");
               exit;
       }

       if (!mf_process_maxfwd_header("10")) {
               #xlog("L_WARN", "$ci|end|too much hops, not enough barley");
               send_reply("483", "Too Many Hops");
               exit;
       }

       if ($ua == "friendly-scanner" ||
               $ua == "sundayddr" ||
               $ua =~ "sipcli" ) {
               #xlog("L_WARN", "$ci|end|dropping message with user-agent
$ua");
               exit;
       }

       if ($si == IPADDRESS) {
               #xlog("L_WARN", "$ci|end|dropping message");
               exit;
       }

}


route[CHECK_SOURCE_IP]
{
       if ($si == SWITCH_IPADDRESS) {
               setflag(FLAG_FROM_SWITCH);
       } else {
               setflag(FLAG_FROM_USER);
       }
}

# Handle requests within SIP dialogs
route[WITHINDLG]
{
       if (has_totag()) {
               # sequential request withing a dialog should
               # take the path determined by record-routing
               if (loose_route()) {
                       route(RELAY);
               } else {
                       if (is_method("NOTIFY")) {
                               route(RELAY);
                       }
                       if (is_method("SUBSCRIBE") && uri == myself) {
                               # in-dialog subscribe requests
                               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
                                       t_relay();
                                       exit;
                               } else {
                                       # ACK without matching transaction
... ignore and discard
                                       #xlog("ACK without matching
transaction ... ignore and discard");
                                       exit;
                               }
                       }
                       sl_send_reply("404","Not here");
               }
               exit;
       }
}

onreply_route[EXTERNAL_REPLY]
{
       route(NAT_TEST_AND_CORRECT);
}


route[NAT_TEST_AND_CORRECT]
{
       if (nat_uac_test("3")) {
               if (is_method("REGISTER")) {
                       fix_nated_register();
               } else {
                       fix_nated_contact();
               }
               force_rport();
       }
       if (has_body("application/sdp") && nat_uac_test("8")) {
               fix_nated_sdp("10");
       }
}

route[RELAY]
{


#!ifdef WITH_NAT
       if (check_route_param("nat=yes")) {
               #setbflag(FLB_NATB);
               route(RTPPROXY);
       }
       if (isflagset(FLT_NATS) || isbflagset(FLB_NATB)) {
               route(RTPPROXY);
       }
#!endif

               route(RTPPROXY);

       /* example how to enable some additional event routes */
       if (is_method("INVITE")) {
               #t_on_branch("BRANCH_ONE");
               t_on_reply("REPLY_ONE");
               t_on_failure("FAIL_ONE");
       }

       if (!t_relay()) {
               sl_reply_error();
       }
       exit;


#        if (!t_relay()) {
#                sl_reply_error();
#        }
#        exit;
}


# RTPProxy control
route[RTPPROXY] {
#!ifdef WITH_NAT
       if (is_method("BYE")) {
               #unforce_rtp_proxy();
               force_rtp_proxy();
       } else if (is_method("INVITE")){
               force_rtp_proxy();
       }
       if (!has_totag()) add_rr_param(";nat=yes");
#!endif
       return;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-users/attachments/20180823/ab98b37a/attachment.html>


More information about the sr-users mailing list