<div dir="ltr">On 30 April 2013 17:23, Aldo Antignano <span dir="ltr"><<a href="mailto:aldo@antignano.it" target="_blank">aldo@antignano.it</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Thank you very much for your reply Barry.<br>
Can you explain us yours ip 10.5.75. and 10.5.76. ?<br>
Seems your asterisks have two interfaces, one private and one public?<br>
<br></blockquote><div><br></div><div style>Sorry, yeah. you should probably ignore that part :-) The same dispatcher deals with client connections from the "public" network as well as inbound calls from a pstn gateway which is on a "private" network. Asterisk is behind NAT for the public clients (Openstack cloud) so by sending the request on the .76 network Asterisk uses its externhost setting as the IP address for the RTP. Unless you are running this on a virtualized environment it is probably not relevant.</div>

<div style>    </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
In my infrastructure I have:<br>
SIP client -> Kamailio  ---> Asterisk 01<br>
                                ---> Asterisk 02<br>
                                ...<br>
                                ---> Asterisk N<br>
<br>
Only Kamailio has a public IP address.<br>
<br>
In the REGFWD route you send all the registrations to ALL the Asterisks?<br>
If so, why?<br>
<br></blockquote><div><br></div><div style>By sending the registration to all the available Asterisk servers then they all know  where each SIP client can be located. If a call comes in from the PSTN or from a SIP client Kamailio can just be sent it to any of the * servers and it will find the registered client. This will work even with multiple load balancers/dispatchers using DNS SRV. </div>

<div style><br></div><div style>In this scenario Kamailio is mainly acting as a load balancer, topology hider and security/anti-flood front-end to create a scalable and redundant Asterisk PBX system. Really depends what you are after. For this particular implementation I was not overly concerned with having too many registrations for it to be a problem for Asterisk, so sending them to all servers was not an issue</div>

<div style><br></div><div style>Regards,</div><div style><br></div><div style>-Barry Flanagan</div><div style><br></div><div style><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


I'm trying to achieve something like:<br>
<br>
SIP clientA ---> REG ---> Kamailio  Is Asterisk01 alive?        Yes --> REG     ---> Asterisk 01<br>
                                                                                NO  --> Choose next one<br>
                                                                                                        ---> Asterisk 02<br>
                                                                                                        ...<br>
                                                                                                        ---> Asterisk N<br>
<br>
                                                                                                ---> Asterisk 01<br>
SIP clientB ---> REG ---> Kamailio  Is Asterisl02 alive?        Yes --> REG     ---> Asterisk 02<br>
                                                                                NO  --> Choose next one<br>
                                                                                                        ---> Asterisk 03<br>
                                                                                                        ...<br>
                                                                                                        ---> Asterisk N<br>
and so on, with a round robin algorithm.<br>
<br>
When Sip ClientA want to call Sip ClientB, it asks Kamailio, that know that SIP Client B is<br>
registered on Asterisk 02 and so send the invite to it.<br>
<br>
<br>
I'm going to work over this in the next few days and let you know the result,<br>
if positive I'll write a new complete guide on this topic with your valuable suggestions.<br>
<br>
Any suggestion is welcome<br>
<br>
BR,<br>
Anty<br>
<br>
<br>
------------------------------------------------------------------------------------------------------<br>
>> I have read and applied the excellent guide found on:<br>
>> <a href="http://kb.asipto.com/asterisk:realtime:kamailio-3.3.x-asterisk-10.7.0-astdb" target="_blank">http://kb.asipto.com/asterisk:realtime:kamailio-3.3.x-asterisk-10.7.0-astdb</a><br>
>><br>
>> Now I have added to Kamailio the HA/Load Balancer support, with the<br>
>> "dispatcher" module.<br>
>> This way I have 1 Kamailio and 2 Asterisk machines.<br>
>><br>
>> How can I change the routing logic of the sections route[REGFWD] |<br>
>> route[FROMASTERISK] route[TOASTERISK] to use the dispatcher module? (in the<br>
>> guide above the asterisk binded ip address is cabled in the kamailio config<br>
>> code)<br>
<br>
I have done that. Relevant route entries below.<br>
<br>
# Forward REGISTER to Asterisk<br>
route[REGFWD] {<br>
if(!is_method("REGISTER"))<br>
 {<br>
return;<br>
}<br>
<br>
# for each Asterisk server in setid=2 (External) we send a registration on<br>
behalf of the user.<br>
 sql_xquery("ca", "SELECT SUBSTRING_INDEX(destination,':',-1) AS port,<br>
SUBSTRING_INDEX(SUBSTRING(destination,5),':',1) AS address<br>
 FROM dispatcher WHERE setid = 2", "ra");<br>
$var(i) = 0;<br>
    while($xavp(ra[$var(i)]) != $null)<br>
    {<br>
$var(rip) = $xavp(ra[$var(i)]=>address);<br>
$uac_req(method)="REGISTER";<br>
$uac_req(ruri)="sip:" + $var(rip) + ":" + $xavp(ra[$var(i)]=>port);<br>
 $uac_req(furi)="sip:" + $au + "@" + $var(rip);<br>
$uac_req(turi)="sip:" + $au + "@" + $var(rip);<br>
 $uac_req(hdrs)="Contact: <sip:" + $au +  "@"<br>
+ $sel(cfg_get.kamailio.bindip)<br>
 + ":" + $sel(cfg_get.kamailio.bindport) + ">\r\n";<br>
if($sel(contact.expires) != $null)<br>
 $uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + $sel(contact.expires) +<br>
"\r\n";<br>
else<br>
 $uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + $hdr(Expires) + "\r\n";<br>
uac_req_send();<br>
        $var(i) = $var(i) + 1;<br>
    }<br>
 sql_result_free("ra");<br>
<br>
}<br>
<br>
# Test if coming from Asterisk. We check the dispatcher "ds_is_from_list()"<br>
function to see if this is one of our Asterisk IPs<br>
route[FROMASTERISK] {<br>
if(ds_is_from_list())<br>
{<br>
return 1;<br>
 } else {<br>
return -1;<br>
}<br>
}<br>
<br>
# Send to Asterisk<br>
route[TOASTERISK] {<br>
<br>
# If call comes in to the .75 iface, we need to send it to the .75 iface of<br>
Asterisk as well.<br>
 # otherwise we send to the .76 iface. We do this by calling different<br>
dispatcher sets. This is<br>
# because Asterisk needs to use NAT on the .76. (public) interface but not<br>
on the .75.<br>
 if($td=~"10.5.75.")<br>
{<br>
$var(setid) = 4;<br>
 xlog("SCRIPT: Call to 10.5.75. ip - using set $var(setid) \n");<br>
} else {<br>
$var(setid) = 2;<br>
 xlog("SCRIPT: Call from $fn to 10.5.76. ip - using set $var(setid) \n");<br>
}<br>
    # round robin dispatching on set determined above<br>
    if(!ds_select_dst($var(setid), "4"))<br>
    {<br>
        send_reply("404", "No destination");<br>
        exit;<br>
    }<br>
    t_on_failure("RTF_DISPATCH");<br>
    route(RELAY);<br>
  exit;<br>
}<br>
<br>
<br>
Hope this helps.<br>
<br>
-Barry Flanagan<br>
<br>
<br>
<br>
_______________________________________________<br>
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list<br>
<a href="mailto:sr-users@lists.sip-router.org">sr-users@lists.sip-router.org</a><br>
<a href="http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users" target="_blank">http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users</a><br>
</blockquote></div><br></div></div>