I'm trying to implement a load balancer for asterisk servers using kamailio and the tutorial at http://kb.asipto.com/asterisk:realtime:kamailio-4.0.x-asterisk-11.3.0-astdb
I must fit the balancer in an infrastructure without touching the other media servers (asterisk) which require a username/password authentication.
The sample implementation constructs a register request from scratch, but does not handle authorization and thus fails. I cannot change the current sip servers and their configuration as these are a live system and I'm not allowed to touch it.
I would really appreciate some hints on how to proceed.
# Forward REGISTER to Asterisk 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); $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(); }
Thank you, Paul.
Hello all,
I'm trying to implement a load balancer for asterisk servers using kamailio and the tutorial at http://kb.asipto.com/asterisk:realtime:kamailio-4.0.x-asterisk-11.3.0-astdb
I must put kamailio in front of the media servers (asterisk) without modifying their configuration (like a transparent proxy). It's a live system and I cannot touch it.
The problem is that the asterisks require the devices to authenticate themselves (and register with user and password too).
The sample implementation constructs a register request from scratch, but does not handle the authorisation part
I guess that the uac_req should contain the user and password fetched from the asterisk database. I would really appreciate some hints on how to proceed.
Here's the current implementation of the register from kamailio->asterisk. # Forward REGISTER to Asterisk 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); $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(); }
Thank you, Paul.
I think, it will be much better to plane reorganization of whole process. To start using Kamailio as registrar and load balance, and Asterisk as media servers, dial plan etc. But, in current situation, I can suggest next: 1. You can not use authorization of Kamailio. You can use Kamailio only and alone as load balance. All requests to Kamailio you can forward to Asterisk servers. 2. When you get first request from somebody - you can do something like: ds_select_dst("1","4"); $sht(forw=>$ft)=$du; This way you will store address of Asterisk, where you forwarded request. 3. When you have next request from same "person" you can do: $du=$sht(forw=>$ft); I am using something alike, but only for active calls. All my registrations are handled by Kamailio, and Asterisk servers do not participate in authentication.
On Sun, Sep 29, 2013 at 3:27 AM, Paul Penev ppquant@gmail.com wrote:
Hello all,
I'm trying to implement a load balancer for asterisk servers using kamailio and the tutorial at http://kb.asipto.com/asterisk:realtime:kamailio-4.0.x-asterisk-11.3.0-astdb
I must put kamailio in front of the media servers (asterisk) without modifying their configuration (like a transparent proxy). It's a live system and I cannot touch it.
The problem is that the asterisks require the devices to authenticate themselves (and register with user and password too).
The sample implementation constructs a register request from scratch, but does not handle the authorisation part
I guess that the uac_req should contain the user and password fetched from the asterisk database. I would really appreciate some hints on how to proceed.
Here's the current implementation of the register from kamailio->asterisk. # Forward REGISTER to Asterisk 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); $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(); }
Thank you, Paul.
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
2013/9/29 Stoyan Mihaylov stoyan.v.mihaylov@gmail.com:
I think, it will be much better to plane reorganization of whole process. To start using Kamailio as registrar and load balance, and Asterisk as media servers, dial plan etc.
I agree. This is the next for me. I kind of hope to use freeswitch for that too.
But, in current situation, I can suggest next:
- You can not use authorization of Kamailio. You can use Kamailio only and
alone as load balance. All requests to Kamailio you can forward to Asterisk servers. 2. When you get first request from somebody - you can do something like: ds_select_dst("1","4"); $sht(forw=>$ft)=$du; This way you will store address of Asterisk, where you forwarded request. 3. When you have next request from same "person" you can do: $du=$sht(forw=>$ft); I am using something alike, but only for active calls. All my registrations are handled by Kamailio, and Asterisk servers do not participate in authentication.
I guess you're registering in Kamailio but your "TOASTERISK" and "FROMASTERISK" routes relay the entire session directly to the asterisk server that was selected without touching it. I must look in this.
Regarding the "easy" solution you proposed, if I understand correctly, I need to implement a single route function with a simple dipatcher, like the example in the dipatcher module:
route{ if ( !mf_process_maxfwd_header("10") ) { sl_send_reply("483","To Many Hops"); drop(); };
ds_select_dst("2", "0");
forward(); # t_relay(); }
How do I modify that example to recognize that a request is coming from the same "user" ?
How do I modify that example to recognize that a request is coming from the same "user" ?
Reading, and making experiments :)
At least I worked such way. Logic must look like: If you have associated variable with that user - use already selected route. Else, ds_select_dst and associate user with that route. You can check $sht(forw=>$ft) and how it is used.