Reputation: 2613
I have a number of simple SIP endpoints that can be registered on a backend SIP registrars. They can be configured to be registred only on one of the call precessing engines. I want to use Kamailio to relay REGISTER (and later INVITE) requests to the backend.
So far I have the following config
route[REGISTRAR] {
if (is_method("REGISTER")){
rewritehost("1.2.3.4");
xlog("Registering $(fu{uri.user}) with 1.2.3.4\n");
$var(frst) = "sip:" + $(fu{uri.user}) +"@1.2.3.4";
$var(scnd) = "sip:" + $(fu{uri.user}) +"@2.3.4.5";
uac_replace_from("$var(frst)");
uac_replace_to("$var(frst)");
if( !t_relay_to_tcp("1.2.3.4","5060") ) {
rewritehost("2.3.4.5");
uac_replace_from("$var(scnd)");
uac_replace_to("$var(scnd)");
xlog("Registering $(fu{uri.user}) with 2.3.4.5\n");
if( !t_relay_to_tcp("2.3.4.5","5060") ) {
sl_reply_error();
}
}
exit;
}
else return;
}
This route[REGISTRAR] is called from main SIP request routing. If 1.2.3.4 is UP my test endpoint registers and available for call from other endpoints (though I have to work with INVITE from test endpoint as well). But when 1.2.3.4 is down I get
ERROR: <core> [tcp_main.c:4249]: tcpconn_main_timeout(): connect 1.2.3.4:5060 failed (timeout)
in the /var/log/syslog. I thought that is t_relay_to_tcp fails I can repeat mangling of From and To headers and relay everything to 2.3.4.5, but this doesn't happen.
It might be because of the asyncronous nature of the transmission - kamailio scripts goes further while relayed tcp session is hanging in some backgroud thread.
How should I edit route[REGISTRAR] to relay to the 2.3.4.5 in case of tcp timeout?
Maybe the whole idea of relaying messages that way is wrong?
Some forums shows examples of registreing endpoints on kamailio itself, but it doesn't suit me. I believe that kamailio is powerful enough to solve my problem.
Upvotes: 0
Views: 3176
Reputation: 2613
Looks like Kamailio doesn't work this way. So I changed my config like that:
route[REGISTRAR] {
if (is_method("REGISTER")){
rewritehost("1.2.3.4");
xlog("Registering $(fu{uri.user}) with 1.2.3.4\n");
$var(frst) = "sip:" + $(fu{uri.user}) +"@1.2.3.4";
uac_replace_from("$var(frst)");
uac_replace_to("$var(frst)");
t_on_failure("REGISTERBACKUP");
t_relay_to_tcp("1.2.3.4","5060");
}
else return;
failure_route[REGISTERBACKUP] {
rewritehost("2.3.4.5");
xlog("Registering $(fu{uri.user}) with 2.3.4.5\n");
#Edited to relay to 2.3.4.5
t_relay_to_tcp("2.3.4.5","5060");
}
When 1.2.3.4 is down my endpoint registers on 2.3.4.5. When 1.2.3.4 is up is of course registers on it.
Upvotes: 1