[SR-Users] Kamailio 3.x and Asterisk Realtime Integration plus

Barry Flanagan barry at flanagan.ie
Wed May 1 00:02:20 CEST 2013


On 30 April 2013 17:23, Aldo Antignano <aldo at antignano.it> wrote:

> Thank you very much for your reply Barry.
> Can you explain us yours ip 10.5.75. and 10.5.76. ?
> Seems your asterisks have two interfaces, one private and one public?
>
>
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.


> In my infrastructure I have:
> SIP client -> Kamailio  ---> Asterisk 01
>                                 ---> Asterisk 02
>                                 ...
>                                 ---> Asterisk N
>
> Only Kamailio has a public IP address.
>
> In the REGFWD route you send all the registrations to ALL the Asterisks?
> If so, why?
>
>
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.

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

Regards,

-Barry Flanagan


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


More information about the sr-users mailing list