Thanks, Sammy. I fixed the error re: transport on Kamailio, but now nothing is sent as the dispatcher doesn't seem to work as expected by me. Here's the output you requested, any help is appreciated:

root@kamailio:/etc/kamailio# kamctl dispatcher show
dispatcher gateways
+----+-------+--------------------------------------+-------+----------+------------+-------------+
| id | setid | destination                          | flags | priority | attrs      | description |
+----+-------+--------------------------------------+-------+----------+------------+-------------+
|  1 |     1 | sip:192.168.1.102:5060;transport=tcp |     0 |        0 | weight=100 | Asterisk A  |
+----+-------+--------------------------------------+-------+----------+------------+-------------+

root@kamailio:/etc/kamailio# netstat -pln | grep kamailio
tcp        0      0 0.0.0.0:5060            0.0.0.0:*               LISTEN      4453/kamailio   
unix  2      [ ACC ]     STREAM     LISTENING     789407   4447/kamailio       /tmp/kamailio_ctl
root@opensipsA:/etc/kamailio# 


And on the Asterisk server:

root@asterisk:~# netstat -pln | grep asterisk
tcp        0      0 0.0.0.0:5060            0.0.0.0:*               LISTEN      2826/asterisk   
tcp        0      0 0.0.0.0:2000            0.0.0.0:*               LISTEN      2826/asterisk   
udp        0      0 0.0.0.0:5000            0.0.0.0:*                           2826/asterisk   
udp        0      0 0.0.0.0:4520            0.0.0.0:*                           2826/asterisk   
udp        0      0 0.0.0.0:4569            0.0.0.0:*                           2826/asterisk   
udp        0      0 0.0.0.0:49207           0.0.0.0:*                           2826/asterisk   
udp        0      0 0.0.0.0:54857           0.0.0.0:*                           2826/asterisk   
udp        0      0 0.0.0.0:2727            0.0.0.0:*                           2826/asterisk   
unix  2      [ ACC ]     STREAM     LISTENING     31087    2826/asterisk       /var/run/asterisk/asterisk.ctl


Now, the ds_select in the REGFWD does not seem to select anything (and so nothing is forwarded).

My complete, current kamailio.cfg is here: https://gist.github.com/ticklingcontest/0b46e8e53bf50aa3875395c8fb86ff66

BTW, I moved away from dispatcher.list file as I could not get it to work (the DB values always registered, but the list file didn't take).

Any insight is appreciated.

Thanks!



On Sun, Jul 24, 2016 at 5:34 PM, SamyGo <govoiper@gmail.com> wrote:

Hey,
Can you show whats the output of the following commands on Kamailio server:
"kamctl dispatcher dump"
"netstat -pln | grep kamailio"

Send the output of the second command from asterisk server as well i.e
"netstat -pln | grep asterisk"

Looking at the error it seems like you are trying to reach asterisk on a protocol which kamailio is not listening on.

Regards,
Sammy


On Jul 24, 2016 14:38, "Tickling Contest" <tickling.contest@gmail.com> wrote:
Hey guys,

I dug a little deeper and I found these logs in /var/log/kamailio where 192.168.1.102 is my asterisk server:

ul 24 14:25:32 kamailio /usr/sbin/kamailio[3726]: ERROR: tm [ut.h:343]: uri2dst2(): no corresponding socket for af 2
Jul 24 14:25:32 kamailio /usr/sbin/kamailio[3726]: ERROR: tm [uac.c:266]: t_uac_prepare(): t_uac: no socket found
Jul 24 14:25:32 kamailio /usr/sbin/kamailio[3726]: ERROR: dispatcher [dispatch.c:2436]: ds_check_timer(): unable to ping [sip:192.168.1.102:5060]

I can broadly tell that the message was not even sent, but the asterisk server VM is alive and well (and indeed on the same physical machine as kamailio VM).

What am I missing? Why is this failing? I am running kamailio 4.0.4.

On Sat, Jul 23, 2016 at 8:07 PM, Tickling Contest <tickling.contest@gmail.com> wrote:
I corrected an error with my dispatcher configuration and now, I do hit the code where 

ds_select_dst ("1", "4")

is no longer null.

However, while the xlog I added says uac_req_send () is called, nothing is sent. The xlog prints out the value of $uac_req(hdrs) as

 Contact: <sip:101@192.168.1.101:5060>#015#012Expires: 600#015

after which the uac_req_send () is called.

I am not sure if this is the correct way? What am I missing?

Oh, nothing shows up in the tcpdump trace (only the OPTIONS message for the asterisk<->kamailio peering shows up).

On Sat, Jul 23, 2016 at 3:48 PM, Tickling Contest <tickling.contest@gmail.com> wrote:
Thanks, guys!

Sammy, I tried your code in REGFWD, but unfortunately, it does not forward anything to Asterisk. I can confirm this because it keeps going into the else clause in the REGFWD (which I added to confirm). My current REGFWD looks like this:

route[REGFWD] {
        if(!is_method("REGISTER"))
        {
                return;
        }
        xlog ("L_DEBUG", "MYDEBUG: In REGFWD");
        if(!ds_select_dst("1", "4"))    {
               $var(rip) = $(du{s.select,1,:});
               $var(rport) = $(du{s.select,2,:});
               $uac_req(method)="REGISTER";
               $uac_req(ruri)="sip:" + $var(rip) + ":" + $var(rport) + ";transport=tcp";
               $uac_req(furi)="sip:" + $au + "@" + $var(rip);
               $uac_req(turi)="sip:" + $au + "@" + $var(rip);
               $uac_req(hdrs)="Contact: <sip:" + $au + "@192.168.1.101:5060" + ">\r\n";
                xlog ("L_DEBUG", "MYDEBUG: In REGFWD, sending registration info to Asterisk at $uac_req(ruri)");
               if($sel(contact.expires) != $null)
                            $uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + $sel(contact.expires) + "\r\n";
                else
                            $uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + $hdr(Expires) + "\r\n";
                uac_req_send();
        }
        else
        {
                xlog ("L_DEBUG", "In REGFWD, not forwarding!");
        }

}




Any insight is appreciated. Thanks again.

My dispatcher at the moment has only one Asterisk server. My endpoint registers (auth with realtime DB in Mysql), but the registration information does not reach Asterisk.

My kamailio box is peering with the asterisk box like so:

root@asterisk:~# more /etc/asterisk/pjsip_wizard.conf
[kamailio]
type = wizard
sends_auth = no
sends_registrations = no
remote_hosts = 192.168.1.101
server_uri_pattern = sip:${REMOTE_HOST}\;transport=tcp
client_uri_pattern = sip:${REMOTE_HOST}\;transport=tcp
contact_pattern = sip:${REMOTE_HOST}\;transport=tcp
outbound_auth/username = dispatcher
aor/qualify_frequency = 0
endpoint/context = from-external ;;; change later
endpoint/disallow = all ;;; change later
endpoint/allow = ulaw ;;; change later
endpoint/dtmf_mode=rfc4733
endpoint/media_address=192.168.1.101 ;;
aor/qualify_frequency = 15

BTW, my intention is to store the registrations on the Asterisk servers as well as my ARI code depends on it. As soon I get the single Asterisk situation working, I intend adding more servers to check the load balancing and REGISTER forwarding, and to Colin's point, the business of just using Kamailio as an outbound proxy.

Again, any insight wrt why no REGISTERs are forwarding to Asterisk is appreciated. Why is ds_select_dst("1", "4") evaluating to false for me?

My dispatcher info:

root@kamailio:/etc/kamailio# kamctl dispatcher show
dispatcher gateways
+----+-------+-------------------+-------+----------+-------+-------------+
| id | setid | destination       | flags | priority | attrs | description |
+----+-------+-------------------+-------+----------+-------+-------------+
|  1 |     1 | sip:192.168.1.102 |     1 |        0 |       | AsteriskA   |
|  2 |     1 | sip:192.168.1.102 |     1 |        0 |       | AsteriskA   |
+----+-------+-------------------+-------+----------+-------+-------------+


Thanks!

On Fri, Jul 22, 2016 at 11:01 AM, Colin Morelli <colin.morelli@gmail.com> wrote:
If you're using Kamailio as a registrar, then it would make the most sense to also use it as your outbound proxy for Asterisk.

This would mean whenever Asterisk needs to dial an extension, it would instead make a SIP call to your Kamailio instance which would then perform the lookup, forking, and forwarding.

Is there a reason this wouldn't work in your infrastructure? If for some reason it can't - though I can't imagine how - then I don't see the purpose in using Kamailio as a registrar at all. You should just forward everything to Asterisk since it needs to be there anyway.

Best,
Colin

On Fri, Jul 22, 2016 at 9:58 AM SamyGo <govoiper@gmail.com> wrote:
Hi Tickles,

a) Have you tried doing this on Asterisk realtime ? for any regular direct registering extension w/o kamailio(even before kamailio) ? If an extension registers to one asterisk the rest of the boxes would know where to contact this extension via realtime-db ? I'd say give that a try and it may solve your problem, else using this REGFWD block you can parallel fork this register request to ALL of your boxes and everybox would think it is registered locally ! (not a recommended option I must say)

b) If you ignore my previous comment of parallel forking registers, using this  REGFWD block you can use dispatcher module to replace the $var(rip) and $sel(cfg_get.asterisk.bindport) by changing your REGFWD block like this:

route[REGFWD] {
        if(!is_method("REGISTER"))
        {
                return;
        }
        if(!ds_select_dst("1", "4"))    { 
               $var(rip) = $(du{s.select,1,:});
               $var(rport) = $(du{s.select,2,:});
               $uac_req(method)="REGISTER";
               $uac_req(ruri)="sip:" + $var(rip) + ":" + $var(rport) + ";transport=tcp";
               $uac_req(furi)="sip:" + $au + "@" + $var(rip);
               $uac_req(turi)="sip:" + $au + "@" + $var(rip);
               $uac_req(hdrs)="Contact: <sip:" + $au + "@"
                                + $sel(cfg_get.kamailio.bindip)
                                + ":" + $sel(cfg_get.kamailio.bindport) + ">\r\n";
               if($sel(contact.expires) != $null)
                            $uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + $sel(contact.expires) + "\r\n";
                else
                            $uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + $hdr(Expires) + "\r\n";
                uac_req_send();
        }

}


In summary, depending upon your business logic/use case there could be other ways to make this work as well.

Regards,
Sammy


On Fri, Jul 22, 2016 at 8:53 AM, Tickling Contest <tickling.contest@gmail.com> wrote:
Hello,

When using Kamailio with the dispatcher module for Asterisk load balancing, I am offloading REGISTERs to Kamailio (works fine), but would like to forward the REGISTERs to Asterisk so that outgoing calls from Asterisk will be possible. I know this is not strictly necessary (e.g., just use Kamailio to forward everything), but I have a lot of application logic behind my Asterisk boxes (using ARI) and so I don't want that to break. Thereby, I do need this information in Asterisk as soon as possible from Kamailio.

Let's say I have three boxes Asterisk_1, Asterisk_2 and Asterisk_3 in the dispatcher module like so:

1 sip:192.168.1.201:5060;transport=tcp
1 sip:192.168.1.202:5060;transport=tcp
1 sip:192.168.1.203:5060;transport=tcp

My system has endpoints as numerical extensions, from 101 to 110. When a new endpoint registers with kamailio (and authenticates), I would like to send the REGISTER to Asterisk. But I have the following questions:

(a) Which Asterisk? I could send it to a round-robinned Asterisk (say, Asterisk_2), but that Asterisk may not be the one responsible for handling calls outbound for the endpoint that just registered. Even if I use "hash over auth username" instead of round-robin (In http://www.kamailio.org/docs/modules/4.0.x/modules/dispatcher.html#idp16940048, choose 5 for "alg", for example) that wont solve this problem as an outbound request may come from another Asterisk box which won't have the requisite registration information. Should I forward REGISTERs to all Asterisk boxes? Maybe I won't have to deal with this issue as I use realtime and so the REGISTER information, sent to one Asterisk box, is available to all Asterisk boxes after the write to the realtime DB. Is my understanding correct?

(b) How do I do this in kamailio.cfg? With some examples on the Internet for WITH_ASTERISK directive, I see that you do 

route[REGFWD] {
        if(!is_method("REGISTER"))
        {
                return;
        }
        $var(rip) = $sel(cfg_get.asterisk.bindip);
        $uac_req(method)="REGISTER";
        $uac_req(ruri)="sip:" + $var(rip) + ":" + $sel(cfg_get.asterisk.bindport) + ";transport=tcp";
        $uac_req(furi)="sip:" + $au + "@" + $var(rip);
        $uac_req(turi)="sip:" + $au + "@" + $var(rip);
        $uac_req(hdrs)="Contact: <sip:" + $au + "@"
                                + $sel(cfg_get.kamailio.bindip)
                                + ":" + $sel(cfg_get.kamailio.bindport) + ">\r\n";
        if($sel(contact.expires) != $null)
                $uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + $sel(contact.expires) + "\r\n";
        else
                $uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + $hdr(Expires) + "\r\n";
        uac_req_send();
}

What is the equivalent for when you are using the dispatcher module and the kamailio.bindip and asterisk.bindip etc. are not set in the configuration, but instead should be procured from elsewhere?

Any help is appreciated.



_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users


_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users

_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users





_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users


_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users