[OpenSIPS-Users] load balancing in opensips
Bogdan-Andrei Iancu
bogdan at voice-system.ro
Thu Aug 6 16:35:14 CEST 2009
Hi Ghaith,
are your calls hiting the usrloc after setting the outbound socket?
because, looking at the script, I think so . And the lookup("location")
function does override the outbound socket setting.
Regards,
Bogdan
Ghaith ALKAYYEM wrote:
> Hi,
>
> I'm trying to connect OpenSIP to 3 WAN links, and I want to distribute
> the traffic between those links according to the dialing number. So, I
> tried some modules like lcr and load_balance but the test didn't succeed
> because those modules are forwarding the traffic to another SIP gateway
> or media gateway.
>
> I tried to change the outbound interface via force_send_socket and
> setting mhomed=1 and OpenSIPS still connect through the main interface.
>
> The IPs of the system are:
> 172.23.1.20
> 172.23.1.19
> 172.23.1.18
> and the originating IP is always 172.23.1.20
>
> please find a part of my configuration file:
>
>
>
>
> # main request routing logic
>
> mhomed=1
>
> route{
>
> if($ct=~"2000.*")
> {
> #load_balance("2","conf");
> force_send_socket(172.23.1.19:5060);
> };
> if($ct=~"3000.*")
> {
> #load_balance("1","conf");
> force_send_socket(172.23.1.18:5060);
> };
>
> 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 {
> /* uncomment the following lines if you want to
> enable presence */
> ##if (is_method("SUBSCRIBE") && $rd ==
> "your.server.ip.address") {
> ## # in-dialog subscribe requests
> ## route(2);
> ## exit;
> ##}
> 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;
> }
>
> t_check_trans();
>
> # authenticate if from local subscriber (uncomment to enable
> auth)
> # authenticate all initial non-REGISTER request that pretend to
> be
>
> # 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)
> ## replace with following line if multi-domain support is used
> ##if (!is_uri_host_local())
> {
> append_hf("P-hint: outbound\r\n");
> # if you have some interdomain connections via TLS
> ##if($rd=="tls_domain1.net") {
> ## t_relay("tls:domain1.net");
> ## exit;
> ##} else if($rd=="tls_domain2.net") {
> ## t_relay("tls:domain2.net");
> ## exit;
> ##}
> route(1);
> }
>
> # requests for my domain
>
> ## uncomment this if you want to enable presence server
> ## and comment the next 'if' block
> ## NOTE: uncomment also the definition of route[2] from below
> ##if( is_method("PUBLISH|SUBSCRIBE"))
> ## route(2);
>
> if (is_method("PUBLISH"))
> {
> sl_send_reply("503", "Service Unavailable");
> exit;
> }
>
> if (is_method("REGISTER"))
> {
> # authenticate the REGISTER requests (uncomment to enable
> auth)
> ##if (!www_authorize("", "subscriber"))
> ##{
> ## www_challenge("", "0");
> ## exit;
> ##}
> ##
> ##if (!check_to())
> ##{
> ## sl_send_reply("403","Forbidden auth ID");
> ## exit;
> ##}
>
> if (!save("location"))
> sl_reply_error();
>
> exit;
> }
>
> if ($rU==NULL) {
> # request with no Username in RURI
> sl_send_reply("484","Address Incomplete");
> exit;
> }
> # apply DB based aliases (uncomment to enable)
> ##alias_db_lookup("dbaliases");
>
> if (!lookup("location")) {
> switch ($retcode) {
> case -1:
> case -3:
> t_newtran();
> t_reply("404", "Not Found");
> exit;
> case -2:
> sl_send_reply("405", "Method Not
> Allowed");
> exit;
> }
> }
>
> # when routing via usrloc, log the missed calls also
> setflag(2);
>
> route(1);
> }
>
>
>
>
> Many thnaks.
>
>
>
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>
>
More information about the Users
mailing list