[OpenSIPS-Users] basic load balancer setup

Bogdan-Andrei Iancu bogdan at opensips.org
Thu Mar 15 19:34:11 CET 2012


Hi Joshua,

Please keep the list at CC - whatever we talk here, should also be to 
the benefit of the entire opensips community ;)

So, to detect where the call comes from, you simply check the source at 
IP level:
     if (src_ip==11.22.33.44) {
            # call from PBXes
     } else {
            # call from carriers
     }

Regards,
Bogdan

On 03/15/2012 07:33 PM, Joshua Nankin wrote:
> Perfect!  Thanks Bogdan, you're the man!  I was having some trouble 
> with record_route_preset because I was including the port in the IP 
> string as well (I had seen others do this in alias, so I just copied 
> that in the record_route_preset function and things still didn't work).
>
> One more question: I'm trying to use the same opensips box as an 
> outbound proxy.  Now, since I automatically load balance any INVITEs, 
> when I place an outgoing call, the call is routed right back to one of 
> my Asterisk machines.  How would I tell if the request is incoming 
> (and then load balance it) or outgoing (and then relay the messages 
> outside of the network).
>
> I'm sure this involves creating another route, but I'm a complete n00b 
> when it comes to opensips - I just started messing around with it this 
> week.
>
> Thanks again for your help!
>
> On Thu, Mar 15, 2012 at 4:40 AM, Bogdan-Andrei Iancu 
> <bogdan at opensips.org <mailto:bogdan at opensips.org>> wrote:
>
>     Hi Joshua,
>
>     Ok, I see - your opensips is actually in a private network.
>     What you can do is to use instead of record_route() the
>     record_route_preset("pub_IP") function (see
>     http://www.opensips.org/html/docs/modules/1.7.x/rr.html#id250439)
>     - this will make opensips to advertise in RR the public IP.
>     Additionally set "alias = pub_IP" in your cfg (see
>     http://www.opensips.org/Resources/DocsCoreFcn17#toc26), so that
>     opensips will recognize its own pub IP in the Route hdr (in ACK)
>
>     Regards,
>     Bogdan
>
>
>     On 03/14/2012 10:54 PM, Joshua Nankin wrote:
>>     Do I need to specify the public IPs of my asterisk boxes in the
>>     load balancing table?
>>
>>     Here's is what my carrier told me:
>>
>>     After looking into this issue further, it appears you are not
>>     including the Record-route header for your public IP address. The
>>     reason the call is failing currently is because you have listed
>>     your internal IP address for us to send the call too, however
>>     since we do not have access to your internal IP address, we are
>>     unable to send this to you. You can see this in the 200 OK that
>>     you send to us, where you start with your internal IP, and go
>>     straight to our IP.
>>
>>     You can find a packet captures for the call here:
>>
>>     Capture from OpenSIPS: xxxxxxxxxxxxxx
>>     Capture from Asterisk: xxxxxxxxxxxxxx
>>
>>     Thanks,
>>     Josh
>>
>>     On Wed, Mar 14, 2012 at 1:02 PM, Joshua Nankin <jnankin at gmail.com
>>     <mailto:jnankin at gmail.com>> wrote:
>>
>>         Yeah, I'm seeing that now.  I just did a capture and
>>         verified, the
>>         200s are coming out of my Asterisk box, and OpenSIPS is
>>         relaying them
>>         properly.  I'm not getting the ACK back from my carrier.  I'm
>>         going to
>>         check with them and send the capture files I just generated -
>>         they use
>>         IP whitelists, and this may just be a authentication/security
>>         problem.
>>
>>         Thanks again!
>>
>>         -Josh
>>
>>         On Wed, Mar 14, 2012 at 12:59 PM, Bogdan-Andrei Iancu
>>         <bogdan at opensips.org <mailto:bogdan at opensips.org>> wrote:
>>         > Hi Joshua,
>>         >
>>         > It seams to be a lot of 200 OK retransmissions from
>>         Asterisk because there
>>         > is no ACK from the original caller side.
>>         >
>>         > Do you see the caller sending such ACK ? have you tried to
>>         make a network
>>         > capture ?
>>         >
>>         > Regards,
>>         > Bogdan
>>         >
>>         >
>>         >
>>         > On 03/14/2012 06:27 PM, Joshua Nankin wrote:
>>         >>
>>         >> Hey Bogdan!
>>         >>
>>         >> So, it appears that the call gets to the LB and is
>>         forwarded to
>>         >> Asterisk.  Here's what happens in both the LB logs and
>>         Asterisk:
>>         >>
>>         >> Asterisk - http://pastebin.com/
>>         >> OpenSIPS - http://pastebin.com/
>>         >>
>>         >>
>>         >> I have debug=6 on OpenSIPS, so there's quite a bit of logging
>>         >> happening for a pretty short call.  It seems that there's a
>>         >> retransmission problem here.  Also, I'm trying to
>>         negotiate T.38, so
>>         >> I'm not sure if that has something to do with this.
>>         >>
>>         >> Thanks,
>>         >> Josh
>>         >>
>>         >> On Wed, Mar 14, 2012 at 7:25 AM, Bogdan-Andrei Iancu
>>         >> <bogdan at opensips.org <mailto:bogdan at opensips.org>>  wrote:
>>         >>>
>>         >>> Hi Joshua,
>>         >>>
>>         >>> Have you checked (at network level) if the actual call
>>         (the inbound one,
>>         >>> from a client) gets to opensips LB ? and if so, if the
>>         call gets
>>         >>> forwarded
>>         >>> to Asterisk ?
>>         >>>
>>         >>> Regards,
>>         >>> Bogdan
>>         >>>
>>         >>>
>>         >>> On 03/13/2012 10:00 PM, Joshua Nankin wrote:
>>         >>>>
>>         >>>> Hello,
>>         >>>>
>>         >>>> Trying to use OpenSIPS as both a load balancer for
>>         incoming calls and
>>         >>>> as an outbound proxy to my carrier.  I have been
>>         unsuccessful to place
>>         >>>> outgoing or incoming calls, and I think I just need some
>>         help with the
>>         >>>> configuration.  Just for testing, I have one Asterisk
>>         box behind
>>         >>>> OpenSIPS and the load balancer table on OpenSIPS looks
>>         like this:
>>         >>>>
>>         >>>>
>>         >>>>
>>         >>>>
>>         +----+----------+-------------------+-----------+------------+-------------+
>>         >>>> | id | group_id | dst_uri           | resources |
>>         probe_mode |
>>         >>>> description
>>         >>>> |
>>         >>>>
>>         >>>>
>>         >>>>
>>         +----+----------+-------------------+-----------+------------+-------------+
>>         >>>> |  1 |        1 | sip:10.36.115.119 | fax=300   |      
>>            0 | tester
>>         >>>>  |
>>         >>>>
>>         >>>>
>>         >>>>
>>         +----+----------+-------------------+-----------+------------+-------------+
>>         >>>>
>>         >>>>
>>         >>>> The dst_ur is the internal IP of my asterisk box.  I'm
>>         using this for
>>         >>>> fax, so I have set the resources field to 300 channels
>>         of "fax".   On
>>         >>>> my asterisk box, I've added
>>         "outboundproxy=23.21.170.154", as the 23.*
>>         >>>> IP is the external IP of the opensips box.  Below is my
>>         simple
>>         >>>> opensips.cfg that I've adapted from the load balancing
>>         tutorial.  Any
>>         >>>> help would be much appreciated.  Additionally, for
>>         debugging purposes,
>>         >>>> I've opened all UDP and TCP ports.  Still not able to
>>         connect.
>>         >>>>
>>         >>>>
>>         >>>> debug=6
>>         >>>> memlog=1
>>         >>>>
>>         >>>> fork=yes
>>         >>>> children=2
>>         >>>> log_stderror=yes
>>         >>>> log_facility=LOG_LOCAL0
>>         >>>>
>>         >>>> disable_tcp=yes
>>         >>>> disable_dns_blacklist = yes
>>         >>>>
>>         >>>> auto_aliases=no
>>         >>>>
>>         >>>> check_via=no
>>         >>>> dns=off
>>         >>>> rev_dns=off
>>         >>>> port=5060
>>         >>>>
>>         >>>> mpath="/usr/lib/opensips/modules/"
>>         >>>> loadmodule "maxfwd.so"
>>         >>>> loadmodule "sl.so"
>>         >>>> loadmodule "db_mysql.so"
>>         >>>> loadmodule "tm.so"
>>         >>>> loadmodule "uri.so"
>>         >>>> loadmodule "rr.so"
>>         >>>> loadmodule "dialog.so"
>>         >>>> loadmodule "mi_fifo.so"
>>         >>>> loadmodule "signaling.so"
>>         >>>> loadmodule "textops.so"
>>         >>>> loadmodule "load_balancer.so"
>>         >>>>
>>         >>>> modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
>>         >>>> modparam("mi_fifo", "fifo_mode",0666)
>>         >>>>
>>         >>>> modparam("dialog", "db_mode", 1)
>>         >>>> modparam("dialog", "db_url",
>>         "mysql://root:opensips@localhost/opensips")
>>         >>>>
>>         >>>> modparam("rr","enable_double_rr",1)
>>         >>>> modparam("rr","append_fromtag",1)
>>         >>>>
>>         >>>> modparam("load_balancer",
>>         >>>> "db_url","mysql://root:opensips@localhost/opensips")
>>         >>>>
>>         >>>>
>>         >>>> route{
>>         >>>>        if (!mf_process_maxfwd_header("3")) {
>>         >>>>                sl_send_reply("483","looping");
>>         >>>>                exit;
>>         >>>>        }
>>         >>>>
>>         >>>>
>>         >>>>        if (!has_totag()) {
>>         >>>>                 # initial request
>>         >>>>                record_route();
>>         >>>>        } else {
>>         >>>>                # sequential request ->    obey Route
>>         indication
>>         >>>>                loose_route();
>>         >>>>                 t_relay();
>>         >>>>                 exit;
>>         >>>>         }
>>         >>>>
>>         >>>>         # handle cancel and re-transmissions
>>         >>>>        if ( is_method("CANCEL") ) {
>>         >>>>                if ( t_check_trans() )
>>         >>>>                        t_relay();
>>         >>>>                exit;
>>         >>>>        }
>>         >>>>
>>         >>>>
>>         >>>>         # from now on we have only the initial requests
>>         >>>>         if (!is_method("INVITE")) {
>>         >>>>                 send_reply("405","Method Not Allowed");
>>         >>>>                 exit;
>>         >>>>         }
>>         >>>>
>>         >>>>         # detect resources and do balancing
>>         >>>>        load_balance("1","fax");
>>         >>>>
>>         >>>>         # LB function returns negative if no suitable
>>         destination (for
>>         >>>> requested resources) is found,
>>         >>>>         # or if all destinations are full
>>         >>>>         if ($retcode<0) {
>>         >>>>              sl_send_reply("500","Service full");
>>         >>>>              exit;
>>         >>>>         }
>>         >>>>
>>         >>>>        xlog("Selected destination is: $du\n");
>>         >>>>
>>         >>>>         # send it out
>>         >>>>        if (!t_relay()) {
>>         >>>>                sl_reply_error();
>>         >>>>        }
>>         >>>> }
>>         >>>>
>>
>
>     -- 
>     Bogdan-Andrei Iancu
>     OpenSIPS Founder and Developer
>     http://www.opensips-solutions.com
>
>


-- 
Bogdan-Andrei Iancu
OpenSIPS Founder and Developer
http://www.opensips-solutions.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20120315/63e933ec/attachment-0001.htm>


More information about the Users mailing list