[SR-Users] kamailio 5.0 with asterisks

Aidar Kamalov aidar.kamalov at gmail.com
Thu Jul 20 08:31:37 CEST 2017


Hello!

I'm new with kamailio, so may be don't understand some basic.
I'm tryin to load balance asterisk servers with kamailio and dispatcher
module. My ip phones registered at kamailio, for example:

[root at sipchel ~]# kamctl ul show 101
{
  "jsonrpc":  "2.0",
  "result": {
    "AoR":  "101",
    "Contacts": [{
        "Contact":  {
          "Address":  "sip:101 at 192.168.2.62;line=4733c4bfa459eea",
          "Expires":  2953,
          "Q":  -1,
          "Call-ID":  "1361221648",
          "CSeq": 136,
          "User-Agent": "Linphone/3.6.1 (eXosip2/3.6.0)",
          "Received": "[not set]",
          "Path": "[not set]",
          "State":  "CS_SYNC",
          "Flags":  0,
          "CFlags": 0,
          "Socket": "udp:192.168.10.54:5060",
          "Methods":  -1,
          "Ruid": "uloc-596f5abc-2ce5-2",
          "Instance": "[not set]",
          "Reg-Id": 0,
          "Last-Keepalive": 1500530337,
          "Last-Modified":  1500530337
        }
      }]
  },
  "id": 15024
}


I have realtime asterisk server.
[root at sipchel ~]# kamctl dispatcher dump
{
  "jsonrpc":  "2.0",
  "result": {
    "NRSETS": 1,
    "RECORDS":  [{
        "SET":  {
          "ID": 1,
          "TARGETS":  [{
              "DEST": {
                "URI":  "sip:192.168.4.16",
                "FLAGS":  "IX",
                "PRIORITY": 0
              }
            }, {
              "DEST": {
                "URI":  "sip:192.168.10.47",
                "FLAGS":  "AX",
                "PRIORITY": 0
              }
            }]
        }
      }]
  },
  "id": 15087
}


So I want if 101 call to 102 it will process by asterisk(for call recording
and other features). Now if I call from 101 to 102 kamailio will forward to
asterisk and asterisk dialplan cannot find that extesion(as expected,
because it is not registed on asterisk)
[kamailio]
exten => _1XX,1,Dial(SIP/${EXTEN})
exten => _1XX,n,Hangup
If I change dialplan to Dial(SIP/KAMAILIO/${EXTEN}) call wil return to
kamailio, but kamailio send it back to asterisk...

I hope I explained correctly, my English is terrible.
Is my screnario proper? How this usually done? Should I forward sip
registrations to asterisks?




My kamailio config
# dispatcher params
modparam("dispatcher", "db_url", "mysql://kamailio:kamailiorw@localhost
/kamailio")
modparam("dispatcher", "ds_ping_interval", 30)
modparam("dispatcher", "table_name", "dispatcher")
modparam("dispatcher", "flags", 2)
modparam("dispatcher", "dst_avp", "$avp(AVP_DST)")
modparam("dispatcher", "grp_avp", "$avp(AVP_GRP)")
modparam("dispatcher", "cnt_avp", "$avp(AVP_CNT)")

modparam("auth_db", "db_url", DBASTURL)
modparam("auth_db", "calculate_ha1", yes)
modparam("auth_db", "user_column", "name")
modparam("auth_db", "password_column", "sippasswd")
modparam("auth_db", "load_credentials", "")
#modparam("auth_db", "version_table", 0)


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")) {
<------><------>record_route();
<------>}

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

<------># dispatch requests to foreign domains
<------>route(SIPOUT);
------>### requests for my local domains

<------># handle presence related requests
<------>route(PRESENCE);

<------># handle registrations
<------>route(REGISTRAR);

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

<------># dispatch destinations to PSTN
<------>route(PSTN);

<------># user location service
<------>route(LOCATION);
}

# User location service
route[LOCATION] {

#!ifdef WITH_SPEEDDIAL
<------># search for short dialing - 2-digit extension
<------>if($rU=~"^[0-9][0-9]$") {
<------><------>if(sd_lookup("speed_dial")) {
<------><------><------>route(SIPOUT);
<------><------>}
<------>}
#!endif

#!ifdef WITH_ALIASDB
<------># search in DB-based aliases
<------>if(alias_db_lookup("dbaliases")) {
<------><------>route(SIPOUT);
<------>}
#!endif

<------>$avp(oexten) = $rU;
<------>if (!lookup("location")) {
<------><------>$var(rc) = $rc;
<------><------>route(TOVOICEMAIL);
<------><------>t_newtran();
<------><------>switch ($var(rc)) {
<------><------><------>case -1:
<------><------><------>case -3:
<------><------><------><------>send_reply("404", "Not Found");
<------><------><------><------>exit;
<------><------><------>case -2:
<------><------><------><------>send_reply("405", "Method Not Allowed");
<------><------><------><------>exit;
<------><------>}
<------>}

<------># when routing via usrloc, log the missed calls also
<------>if (is_method("INVITE")) {
<------><------>setflag(FLT_ACCMISSED);
<------>}

        route(DISPATCH);
<------>route(RELAY);
<------>exit;
}

# Dispatch requests
route[DISPATCH] {
<------># round robin dispatching on gateways group '1'
<------>if(!ds_select_dst("1", "4"))
<------>{
<------>    xlog("aaaa--- SCRIPT: going to <$ru> via <$du>\n");
<------>    send_reply("404", "No destination");
<------>    exit;
<------>}
<------>xlog("--- SCRIPT: going to <$ru> via <$du>\n");
<------>t_on_failure("RTF_DISPATCH");
<------>return;
}


-- 
Aydar A. Kamalov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-users/attachments/20170720/0d4c8b47/attachment.html>


More information about the sr-users mailing list