Author Topic: round robin routing using db query  (Read 32046 times)

jehanzaib_kiani

  • Newbie
  • *
  • Posts: 45
    • View Profile
round robin routing using db query
« on: July 22, 2014, 05:19:16 PM »
hi folks,
i am new in yate, just installed. i want to achieve round robin but need to check first the incoming registered user IP and then route it to appropiate IP.
like my users would register on yate, the incoming call IP will be checked from db and then i will be able to set the server for routing.
i know the static round robin routing can be achieved like ^00.*$=fork $(index,$idx00,| sip/sip:\0@provider1.com,| sip/sip:\0@provider2.com) | sip/sip:\0@provider3.com

anyone who has done this before? please guide.

Monica Tepelus

  • Administrator
  • Full Member
  • *****
  • Posts: 198
    • View Profile
Re: round robin routing using db query
« Reply #1 on: July 30, 2014, 02:27:17 AM »
Hi,

You can install a handler in the register module/javascript routing script/external module global script with a higher priority  and make a query that verifies the ip address. You can reject the call here. If call is not rejected, you let it was and it will be handled by regexroute where you set up round robin.

jehanzaib_kiani

  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: round robin routing using db query
« Reply #2 on: August 07, 2014, 10:16:01 PM »
hi thanks for the reply. sorry i m newbee did not understand where i need to write a script. i will use php if i have to write a script.
so my scanrio will be like if the incoming user is not registered then check its ip if it is in my db then let it dial. if it is registered user then let it dial. everything else will be rejected.

right now i am using regexroute.conf where my unauthenticated user is rejected and registered user is able to dialout. the only bit left is where i have to check the IP
can you please guide me which file i have to write a query for valid ip?
thanks


Monica Tepelus

  • Administrator
  • Full Member
  • *****
  • Posts: 198
    • View Profile
Re: round robin routing using db query
« Reply #3 on: August 08, 2014, 08:04:34 AM »
Hi,

Look in share/scripts/route.php from yate's sources.
Modify below to check the "address"
            if ($ev->getValue("called") == "321") {
                $ev->retval = "tone/dial";
                $ev->handled = true;
            }

Something like this:
           if (!in_array($ev->getValue("address"),array("ip1","ip2"...)) {
                 $ev->error = "noroute";
                 $ev->handled = true;
           }


jehanzaib_kiani

  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: round robin routing using db query
« Reply #4 on: August 11, 2014, 05:34:32 PM »
Hi thanks for the reply,
yes i found /usr/local/share/yate/scripts/route.php
and modified like like. where $trunk_ip is having my all the allowed ips . but the piece of code is not called thats what the logs are showing.

         if (!in_array($ev->getValue("address"),$trunk_ip)) {
                 $ev->error = "noroute";
                 $ev->handled = true;
           }
here are the logs. it should not send calls to my mysipserver.com as this is not a registered user neither the ip is in the trunk_info array. can you suggest anything please. thanks

20140811233228.371866 <INFO> Could not classify call from 'test', wasted 2 usec
20140811233228.371938 <cdrbuild:INFO> Got message 'call.route' for untracked id 'sip/623'
20140811233228.372097 <INFO> Routing call to '12022899898' in context 'default' via 'fork | sip/sip:12022899898@mysipserver.com' in 92 usec
20140811233228.422545 <callfork:CALL> Call 'sip/623' calling on regular 'fork/303/1' target 'sip/sip:12022899898@mysipserver.com'
20140811233234.119916 <callfork:NOTE> Call 'sip/623' lost slave 'fork/303/1' reason 'forbidden' remaining 0 regulars, 0 auxiliars, 0 persistent



Monica Tepelus

  • Administrator
  • Full Member
  • *****
  • Posts: 198
    • View Profile
Re: round robin routing using db query
« Reply #5 on: August 14, 2014, 05:14:47 AM »
Did you edit extmodule.conf to set script to start? Check the start of the route.php script for instructions on how to start it.

jehanzaib_kiani

  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: round robin routing using db query
« Reply #6 on: August 14, 2014, 10:03:59 PM »
hi thank you for your reply thanks
can you please have a look what else i have to change in this file ? the route.php path is /usr/local/share/yate/scripts/route.php
thanks


here is my [root@gw ~]# vim /usr/local/etc/yate/extmodule.conf


[general]
; General settings for the external module

; scripts_dir: string: The absolute or relative path used by default to load
;  scripts if no full path is specified
; Note that a trailing path separator should be added
; Uncomment the following line when running in the sources directory
scripts_dir=share/yate/scripts/

; priority: int: Priority of the call.execute handler
;priority=100

; timeout: int: How many milliseconds to wait for a module to answer
;timeout=10000

; timebomb: bool: Kill the module instance if it timed out
;timebomb=false

; waitflush: int: Milliseconds to wait at script shutdown after waiting messages
;  and message relays are flushed, valid range 1-100 ms
;waitflush=5
; trackparam: bool: Add the external module to the handler tracking parameter
;  The default of false lets each external script do so
trackparam=true

[scripts]
; Add one entry in this section for each global external module that is to be
;  loaded on Yate startup
; Each line has to be on the form:
scriptname=share/yate/scripts/route.php
; The script name should hold either the absolute path and name or the path
;  and name relative to the scripts_dir in section [general]
; The parameter is optional and if present is passed to the script as the first
;  (and single) parameter
[execute]
; Add one entry in this section for each external program that is to be
;  executed on Yate startup
; Each line has to be on the form:
;   progname=parameter
; The program name should hold the absolute path to the program
; The parameter is optional and if present is passed to the program as the first
;  (and single) parameter


Monica Tepelus

  • Administrator
  • Full Member
  • *****
  • Posts: 198
    • View Profile
Re: round robin routing using db query
« Reply #7 on: August 19, 2014, 06:05:33 AM »
If you are running yate from sources or you installed it, and you didn't modify the scripts directory by hand then this is how extmodule.conf should look.

[scripts]
route.php=

jehanzaib_kiani

  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: round robin routing using db query
« Reply #8 on: August 20, 2014, 01:35:29 AM »
hi
i have installed it from the source but my /usr/local/etc/yate/extmodule.conf file is not having only 1 line. its a big file like i already sent you the contents of the file.

so the scripts directory path is

[scripts]
scriptname=share/yate/scripts/route.php

Monica Tepelus

  • Administrator
  • Full Member
  • *****
  • Posts: 198
    • View Profile
Re: round robin routing using db query
« Reply #9 on: August 20, 2014, 07:18:05 AM »
This what you need to have in [scripts] section in that file:

[scripts]
route.php=

This is not correct:
scriptname=share/yate/scripts/route.php

If you want to set a path to the script it would look like this:
share/yate/scripts/route.php=

You won't need to set a path to the script there. Just "route.php=" should be enough.
The length on the file doesn't matter. The majority of those line are comments.


jehanzaib_kiani

  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: round robin routing using db query
« Reply #10 on: August 25, 2014, 02:23:11 AM »
please see the attached sniffer. when i dial 99 i can see the script route.php is called but i cant see any effect. i have also put
Yate::Output("gw.conf247.com routing \n");
so it should show this line but i cant see in the logs, any idea?

Monica Tepelus

  • Administrator
  • Full Member
  • *****
  • Posts: 198
    • View Profile
Re: round robin routing using db query
« Reply #11 on: August 25, 2014, 12:47:17 PM »
You routed from regexroute or someplace else to this script. That is wrong. You have to route to a channel script. Ex: voicemail.php

route.php is a global script. Don't send calls to it from other modules. If the script was started it will catch the calls on it's own. So i guess you didn't set it in extmodule.conf. I don't see handlers from extmodule in call.route message so script was not started.


jehanzaib_kiani

  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: round robin routing using db query
« Reply #12 on: August 26, 2014, 02:11:17 AM »
ok let me sum up what i did. see the below extmodule.conf i have already set the script what else i need to do ?

in /usr/local/etc/yate/regexroute.conf
[default]
^99$=/usr/local/share/yate/scripts/route.php

in /usr/local/etc/yate/extmodule.conf

[general]
scripts_dir=share/yate/scripts/
trackparam=true
[scripts]
route.php=
share/yate/scripts/route.php=

jehanzaib_kiani

  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: round robin routing using db query
« Reply #13 on: August 28, 2014, 08:50:58 AM »
by the way my regexroute.conf have these lines. i have removed the direct call of route.php from the regexroute.conf file

[$once]
sip_srv=198.23.194.134
[default]
^001.*$=fork $(index,$idx01,| sip/sip:\0@myprovider1.com,| sip/sip:\0@myprovider2.com);osip_Yatebillid=${billid};rtp_forward=true;maxcall=30000
[user.auth]

my extmodule.conf have below lines. but i still cant see the route.php to run. is there any other settings i have to change? any priority or anything else. i have not touched anything else yet.

[general]
scripts_dir=share/yate/scripts/
trackparam=true
[scripts]
route.php=
share/yate/scripts/route.php=

Monica Tepelus

  • Administrator
  • Full Member
  • *****
  • Posts: 198
    • View Profile
Re: round robin routing using db query
« Reply #14 on: August 28, 2014, 02:13:08 PM »
Post a log with -vvvvv of yate starting. This way we can see if there were any issues when yate tries to start the script.