[OpenSIPS-Users] Not able to make Load Balancer work
Mayur Koshal
mayurkoshal at gmail.com
Wed Mar 7 12:20:54 EST 2018
Hi Bogdan,
Sorry for the delayed reply.
I resumed to look into this issue after a break and I confirmed that
the invite request is going back and forth between the load balancer
and the proxy. Just to revisit the setup as the IP's got changed :
UAC(192.168.100.21:5065)-------LB (192.168.100.21:5060)------SIP Proxy
(192.168.100.17:5060)------------UAS(192.168.100.17:5080)
sipp commands used :
./sipp -sf uac_mod.xml 192.168.100.21:5060 -s archana -i
192.168.100.21 -p 5065 -r 1 -rp 1000 -m 10
./sipp -sf uas_mod_orig.xml -rsa 192.168.100.21:5060 -i 192.168.100.17 -p 5080
where I have registered user archana in the SIP proxy server .
The problem looks like not a loop within the load balancer but the
fact that the proxy returns the INVITE back to the load balancer
instead of sending it to the server (UAS ).
The LB, when handling the INVITE, properly routes it to the proxy but
does not change the request-uri. The proxy then routes the INVITE
according to the unchanged request-uri which means that it sends it
back to the LB.
when I hardcoded the request uri in the Proxy script to the UAS uri I
can see the invite request reaching the UAS.
In the LB script as well as proxy script I could see the record
routing of initial request (INVITE).(Not sure if record routing
changes the uri for initial request as it does for sequential request)
There is some issue in the script either in LB or Proxy which I am not
able to figure out.
Request your help for the same.
The LB and Proxy script snnipets as below :
Load Balancer Script :
----------------------------------------
route{
if (!mf_process_maxfwd_header("10")) {
sl_send_reply("483","Too Many Hops");
exit; }
if (has_totag()) {
# sequential request withing a dialog should
# take the path determined by record-routing
if (loose_route()) {
# validate the sequential request against dialog
if ( $DLG_status!=NULL && !validate_dialog() ) {
xlog("In-Dialog $rm from $si (callid=$ci) is not valid according to dialog\n");
## exit;
}
if (is_method("BYE")) {
setflag(ACC_DO); # do accounting ...
setflag(ACC_FAILED); # ... even if the transaction fails
} else if (is_method("INVITE")) {
# even if in most of the cases is useless, do RR for
# re-INVITEs alos, as some buggy clients do change route set
# during the dialog.
record_route();
}
# route it out to whatever destination was set by loose_route()
# in $du (destination URI).
route(RELAY);
} else {
if ( is_method("ACK") ) {
if ( t_check_trans() ) {
# non loose-route, but stateful ACK; must be an ACK after
# a 487 or e.g. 404 from upstream server
t_relay();
exit;
} else {
# ACK without matching transaction ->
# ignore and discard
exit;
}
}
sl_send_reply("404","Not here");
}
exit;
}
#### INITIAL REQUESTS
# CANCEL processing
if (is_method("CANCEL")) {
if (t_check_trans())
t_relay();
exit;
} else if (!is_method("INVITE")) {
send_reply("405","Method Not Allowed");
exit;
}
if ($rU==NULL) {
# request with no Username in RURI
sl_send_reply("484","Address Incomplete");
exit;
}
t_check_trans();
# preloaded route checking
if (loose_route()) {
xlog("L_ERR",
"Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci]");
if (!is_method("ACK"))
sl_send_reply("403","Preload Route denied");
exit;
}
record_route();
setflag(ACC_DO); # do accounting
if ( !load_balance("1","sip")) {
xlog("\n");
send_reply("500","No Destination available");
exit;
}
t_on_failure("GW_FAILOVER");
route(RELAY);
}
route[RELAY] {
if (!t_relay()) {
sl_reply_error();
};
exit;
}
failure_route[GW_FAILOVER] {
if (t_was_cancelled()) {
exit;
}
# failure detection with redirect to next available trunk
if (t_check_status("(408)|([56][0-9][0-9])")) {
xlog("Failed trunk $rd/$du detected \n");
if ( load_balance("1","sip") ) {
t_on_failure("GW_FAILOVER");
t_relay();
exit;
}
send_reply("500","All GW are down");
}
}
local_route {
if (is_method("BYE") && $DLG_dir=="UPSTREAM") {
acc_log_request("200 Dialog Timeout");
}
}
*************************************************
Proxy Script :
----------------
route{
if (!mf_process_maxfwd_header("10")) {
sl_send_reply("483","Too Many Hops");
exit;
}
if (has_totag()) {
# sequential request withing a dialog should
# take the path determined by record-routing
if (loose_route()) {
if (is_method("BYE")) {
setflag(1); # do accounting ...
setflag(3); # ... even if the transaction fails
} else if (is_method("INVITE")) {
# even if in most of the cases is useless, do RR for
# re-INVITEs alos, as some buggy clients do change route set
# during the dialog.
record_route();
}
# route it out to whatever destination was set by loose_route()
# in $du (destination URI).
route(1);
} else {
if ( is_method("ACK") ) {
if ( t_check_trans() ) {
# non loose-route, but stateful ACK; must be an ACK after
# a 487 or e.g. 404 from upstream server
t_relay();
exit;
} else {
# ACK without matching transaction ->
# ignore and discard
exit;
}
}
sl_send_reply("404","Not here");
}
exit;
}
# CANCEL processing
if (is_method("CANCEL"))
{
if (t_check_trans())
t_relay();
exit;
}
xlog("Outside has to tag \n");
t_check_trans();
# preloaded route checking
if (loose_route()) {
xlog("L_ERR",
"Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci]");
if (!is_method("ACK"))
sl_send_reply("403","Preload Route denied");
exit;
}
# record routing
if (!is_method("REGISTER|MESSAGE")){
record_route();
}
# account only INVITEs
if (is_method("INVITE")) {
setflag(1); # do accounting
}
if (!uri==myself) {
append_hf("P-hint: outbound\r\n");
$ru = "sip:archana at 192.168.100.17:5080"; # Hard coding
route(1);
}
# requests for my domain
if (is_method("PUBLISH|SUBSCRIBE"))
{
sl_send_reply("503", "Service Unavailable");
exit;
}
if (is_method("REGISTER"))
{
# authenticate the REGISTER requests
if (!save("location"))
sl_reply_error();
exit;
}
if ($rU==NULL) {
# request with no Username in RURI
sl_send_reply("484","Address Incomplete");
exit;
}
Regards
Mayur
More information about the Users
mailing list