Get IP/Port of registered user (or from Location table?)

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Get IP/Port of registered user (or from Location table?)

bluerain
How do I get the IP and Port of registered user (probably a stupid question)?  I check the usrloc module, I don't see function like that.  
 
The reason I need this is that when we were only using Asterisk server, we were able to sent INVITE out with the DNIS.  So what I mean is that I can dial out to customer's SIP server by using Asterisk dial command:

DIAL(SIP/peername/2135551212,60)

Which means sent an INVITE to peername (a registerd peer) and the TO-URI (and Request-URI) will have 2135551212@cust_ip_address

Now, we add OpenSIP in front of asterisk, so when asterisk server sent call out, it can only do

DIAL (SIP/opensipname/registered username,60)

Which in the INVITE, both TO-URI and Request_URI is the actual registered username instead of the phone number I would like to relay over the customer's SIP server.

Thus what I want is then to sent to Opensip

DIAL(SIP/opensipname/2135551212,60)

And then in Opensip, when I see the username in TO-URI 2135551212, I will get the ip/port of the actual registered user (all user registered to opensips) and then rewrite the INVITE using the IP/port that is in the location table (or wherever/however OpenSIP get it).

Is that possible?
Reply | Threaded
Open this post in threaded view
|

Re: Get IP/Port of registered user (or from Location table?)

bluerain
Or will location("username") function do it?

So what I mean is that if I do

If(is_method("INVITE")) {
  lookup("username");
  t_relay();
}

So that if

1. asterisk server sent an INVITE to OpenSIP (with an username of unknown by OpenSIPs)
2. Opensips goes into the code above
3. rewrite the INVITE destination IP/port to the IP/port of the username it finds in the location table
4. sent the INVITE to that server.

So what I mean is that when the INVITE came from the Asterisk Server, the TO-URI looks like:

2135551212@IP_address

will, Opensips, obviously don't know who is "2135551212" because the registered user is, let say, Chris1234.

So thus I need to replace find the IP/port of registered user Chris1234 and then rewrite the original INVITE (came from Asterisk) with the IP/port of the registered user Chris1234 and then sent it out.

Well, you say why don't I just do Chris1234@IP_address, then this way, Opensips will automatically sent out to the user because Chris1234 is an registerd user.

The issue is that the end user do not want to see call come in with Chris1234, they want to see the number 2135551212.
Reply | Threaded
Open this post in threaded view
|

Re: Get IP/Port of registered user (or from Location table?)

Bogdan-Andrei Iancu-2
Hello,

yes, the lookup("location") function (from the REGISTRAR module) is the
right one.

Also take a look at the dbalises module to see how you can create an
alias from 2135551212 to Chris1234 .

Regards,

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


On 11/14/2013 12:31 AM, bluerain wrote:

> Or will location("username") function do it?
>
> So what I mean is that if I do
>
> If(is_method("INVITE")) {
>   lookup("username");
>   t_relay();
> }
>
> So that if
>
> 1. asterisk server sent an INVITE to OpenSIP (with an username of unknown by
> OpenSIPs)
> 2. Opensips goes into the code above
> 3. rewrite the INVITE destination IP/port to the IP/port of the username it
> finds in the location table
> 4. sent the INVITE to that server.
>
> So what I mean is that when the INVITE came from the Asterisk Server, the
> TO-URI looks like:
>
> 2135551212@IP_address
>
> will, Opensips, obviously don't know who is "2135551212" because the
> registered user is, let say, Chris1234.
>
> So thus I need to replace find the IP/port of registered user Chris1234 and
> then rewrite the original INVITE (came from Asterisk) with the IP/port of
> the registered user Chris1234 and then sent it out.
>
> Well, you say why don't I just do Chris1234@IP_address, then this way,
> Opensips will automatically sent out to the user because Chris1234 is an
> registerd user.
>
> The issue is that the end user do not want to see call come in with
> Chris1234, they want to see the number 2135551212.
>
>
>
>
> --
> View this message in context: http://opensips-open-sip-server.1449251.n2.nabble.com/Get-IP-Port-of-registered-user-or-from-Location-table-tp7588494p7588495.html
> Sent from the OpenSIPS - Users mailing list archive at Nabble.com.
>
> _______________________________________________
> Users mailing list
> [hidden email]
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>

_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Get IP/Port of registered user (or from Location table?)

bluerain
Thank you!  I'll give that a shot!
Reply | Threaded
Open this post in threaded view
|

Re: Get IP/Port of registered user (or from Location table?)

bluerain
In reply to this post by Bogdan-Andrei Iancu-2
Hello Bogdan,

I tried to use lookup("location","d","FRANK101") and it seems opensips can not find the user, even though the username "FRANK101" is in the subcriber table.

So it is my syntax is wrong on the "lookup" function call?

And please correct me if I am wrong also, I was under the impression that if an INVITE comes in from Asterisk with

R-URI: 2135551212@IP
TO-URI: 2135551212@IP

And obviously opensip will not know who is "2135551212" because "2135551212" is NOT in the subscriber table.

So here is my code
if (is_method("INVITE")) {

                        if (!lookup("location","m")){
                                switch($rc)
                                {
                                        case -1:
                                                if (!lookup("location","d","FRANK101")) {
                                                    t_reply("404","Not Found");
                                                    exit;
                                                }
                                        case -3:
                                                t_newtran();
                                                t_reply("404","Not Found");
                                                exit;
                                        case -2:
                                                sl_send_reply("405", "Method Not Allowed");
                                                exit;
                                }
                        }

                        route(relay);
}

So with the code above, I:

1. lookup to see if the INVITE is a valid user in subscriber database
2. If not an valid user, which in this case it is because asterisk sent in an invite with "2135551212"
3. Thus I use the funcation call, lookup("location","d","FRANK101"), which "FRANK101" is a valid user in the "subscriber" table.  
4. by calling the funcation call, lookup("location","d","FRANK101"), I am expecting that opensips will NOT TOUCH either the TO-URI NOR the R-URI.  It will keep those the same as 2135551212@IP, BUT now opensips will sent the INVTIE to FRANK101 BECAUES the "lookup" function call only change the IP/Port of the INVITE where it suppose to go?

Is my assumption correct?  Or will "lookup" function also change the R-URI and the TO-URI?  If that is the case, then is useless.

And if lookup is work the way I thought, then please tell me what is the exact syntax in reference to a user in the subscriber table?  

What is the AOR parameter for the lookup?  Is it not simply as the username?  Or do I need to put username@IP  then what is the "@IP"?  is the "@IP" the "domain" field in the subscriber table?  Or is it what is in the location table?  and if is in the location table, then do I take the entire "contact" field and stuff that in to the lookup AOR parameter?

Thank you!
Reply | Threaded
Open this post in threaded view
|

Re: Get IP/Port of registered user (or from Location table?)

bluerain
In reply to this post by Bogdan-Andrei Iancu-2
sorry I type wrong the syntax for location, please ignore the "d", I got it confused with the db_alias lookup command.  I have in my code only lookup("location","","FRANK101")
Reply | Threaded
Open this post in threaded view
|

Re: Get IP/Port of registered user (or from Location table?)

Liviu Chircu
In reply to this post by bluerain
Hello bluerain,

A couple of useful information:

* a user may be subscribed (in the "subscriber" table), but the lookup
call may fail, because he is not registered (in the "location" table)
* lookup indeed performs a lookup based on the Request-URI username, and
rewrites the same URI in case the operation is successful
* with "lookup("location","d","FRANK101")", OpenSIPS should not start.
Correct this as follows:

$var(aor) = "sip:FRANK101@ip";
lookup("location","d","$var(aor)")

Notice how the parameter MUST be a pseudo-variable containing a sip URI.

Liviu Chircu
OpenSIPS Developer
http://www.opensips-solutions.com

On 11/15/2013 07:30 PM, bluerain wrote:

> Hello Bogdan,
>
> I tried to use lookup("location","d","FRANK101") and it seems opensips can
> not find the user, even though the username "FRANK101" is in the subcriber
> table.
>
> So it is my syntax is wrong on the "lookup" function call?
>
> And please correct me if I am wrong also, I was under the impression that if
> an INVITE comes in from Asterisk with
>
> R-URI: 2135551212@IP
> TO-URI: 2135551212@IP
>
> And obviously opensip will not know who is "2135551212" because "2135551212"
> is NOT in the subscriber table.
>
> So here is my code
> if (is_method("INVITE")) {
>
> if (!lookup("location","m")){
> switch($rc)
> {
> case -1:
>                                                  if
> (!lookup("location","d","FRANK101")) {
>    t_reply("404","Not Found");
>    exit;
>                                                  }
> case -3:
> t_newtran();
> t_reply("404","Not Found");
> exit;
> case -2:
> sl_send_reply("405", "Method Not Allowed");
> exit;
> }
> }
>
> route(relay);
> }
>
> So with the code above, I:
>
> 1. lookup to see if the INVITE is a valid user in subscriber database
> 2. If not an valid user, which in this case it is because asterisk sent in
> an invite with "2135551212"
> 3. Thus I use the funcation call, lookup("location","d","FRANK101"), which
> "FRANK101" is a valid user in the "subscriber" table.
> 4. by calling the funcation call, lookup("location","d","FRANK101"), I am
> expecting that opensips will NOT TOUCH either the TO-URI NOR the R-URI.  It
> will keep those the same as 2135551212@IP, BUT now opensips will sent the
> INVTIE to FRANK101 BECAUES the "lookup" function call only change the
> IP/Port of the INVITE where it suppose to go?
>
> Is my assumption correct?  Or will "lookup" function also change the R-URI
> and the TO-URI?  If that is the case, then is useless.
>
> And if lookup is work the way I thought, then please tell me what is the
> exact syntax in reference to a user in the subscriber table?
>
> What is the AOR parameter for the lookup?  Is it not simply as the username?
> Or do I need to put username@IP  then what is the "@IP"?  is the "@IP" the
> "domain" field in the subscriber table?  Or is it what is in the location
> table?  and if is in the location table, then do I take the entire "contact"
> field and stuff that in to the lookup AOR parameter?
>
> Thank you!
>
>
>
>
> --
> View this message in context: http://opensips-open-sip-server.1449251.n2.nabble.com/Get-IP-Port-of-registered-user-or-from-Location-table-tp7588494p7588540.html
> Sent from the OpenSIPS - Users mailing list archive at Nabble.com.
>
> _______________________________________________
> Users mailing list
> [hidden email]
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users


_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Get IP/Port of registered user (or from Location table?)

bluerain
Hello Liviu,

thanks for the help.  Although one more question, on your "sip:FRANK101@ip";

What is the "@ip"?  is that the IP of the "domain" field in the subscriber table, or the IP in the "contact" field of the location table?

here is an example of what in my "contact" field of the "location" table:

sip:FRANK101@192.168.2.160:5060;transport=udp

So, do I put the entire line in the $var(aor) or I have to search for the ";" and then truncate and manipulate the "contact" field to just "sip:FRANK101@192.168.2.160"  and then put it in the variable?

And sorry, lastly, just a side question regarding the location table, why is it sometime I would see all my data in the "location" table disappear, but when I do a "opensipsctl ul show --brief" I do see all the AOR entry and that all the device are registered with OpenSIP.  And then even if I do a "opensipsctl fifo ul_flush"  it still does not update the mysql database.

Sorry, another question, I also tried to use MS SQL SERVER 2008 as backend database for usr_loc module, but it simply won't start.  I have many other module running on SQL SERVER 2008 R2, the only 2 module I have problem is the usr_loc and dialog module.

I even did a SQL profilier on the database, I do see opensips query the database (select fields from location), but after that, it just won't start.  The only way can use SQL SERVER 2008 as backend for usr_loc is if I do db_mode 3, but I think OpenSIP crashes when it tries to read from the database when in db_mode 3.

anyhow. Sorry for all the question, the most important one is the AOR format for the lookup function call, if you can help me out on that, it will be great!

Thank you!
Reply | Threaded
Open this post in threaded view
|

Re: Get IP/Port of registered user (or from Location table?)

Liviu Chircu
On 15.11.2013 21:38, bluerain wrote:
> What is the "@ip"?  is that the IP of the "domain" field in the subscriber
> table, or the IP in the "contact" field of the location table?
"contact" field of the location table.
> So, do I put the entire line in the $var(aor) or I have to search for the
> ";" and then truncate and manipulate the "contact" field to just
> "sip:FRANK101@192.168.2.160"  and then put it in the variable?
Any extra parameters should be simply ignored by OpenSIPS.
> And sorry, lastly, just a side question regarding the location table, why is
> it sometime I would see all my data in the "location" table disappear, but
> when I do a "opensipsctl ul show --brief" I do see all the AOR entry and
> that all the device are registered with OpenSIP.  And then even if I do a
> "opensipsctl fifo ul_flush"  it still does not update the mysql database.
First of all, "opensipsctl ul show" does not do any DB queries! If
"ul_flush" fails, what sort of errors do you see in the OpenSIPS logs?
(regardless of DB engine)

Best regards,

--
Liviu Chircu
OpenSIPS Developer
http://www.opensips-solutions.com


_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Get IP/Port of registered user (or from Location table?)

bluerain
Hello Liviu,

thanks for your help again!  Ok, so I tried that and is weird, is kinda working but is working weirdly.  Not sure, maybe I don't truely understand how opensips works?  But here is my code:

        if (is_method("INVITE")) {

                        trace_dialog();

                        if (!lookup("location","m")){
                                switch($rc)
                                {
                                        case -1:
                                                $var(aor)="sip:FRANK101@22.22.22.22:5062";
                                                if(!lookup("location","","$var(aor)")) {
                                                        t_reply("404","Not Found new $rc");
                                                        exit;
                                                }
                                        case -3:
                                                #$var(aor)="sip:FRANK101@22.22.22.22:5062";
                                                #if(!lookup("location","","$var(aor)")) {
                                                        t_newtran();
                                                        t_reply("404","Not Found");
                                                        exit;
                                                #}
                                        case -2:
                                                #$var(aor)="sip:FRANK101@22.22.22.22:5062";
                                                #if(!lookup("location","","$var(aor)")) {
                                                        sl_send_reply("405", "Method Not Allowed");
                                                        exit;
                                                #}
                                }
                        }

                        route(relay);
                }

So if I use the code above, it would reply "404","Not Found" which means the lookup() function returned "-3"

And then if I unquote the all the "#" in "-3" section", since that is where the error happend, now when I sent the INVITE, it would return "405 Method Not Allowed", which means now lookup() function returned "-2"

So lastly if I unquote the "#"in "-2", the call actually worked!  But it seems the code must got iterated 3 times before it reach the "method not found" section and thus finally sent the call out?

So what I mean is that if I sent an "unknown" user in the INVITE, from the code above, it will jump to "-1" section (because it return error code -1) and then when it execute again the lookup() in the "-1" section, it jump to -3 and then execute lookup() again in "-3" and then finally it jump to "-2" to execute the finally lookup.  Why?

Shouldn't it simply jump to "-1" and then do the lookup("frank101") which IS IN THE LOCATION table and then proceed with jumping to the route(relay) and FRANK101 phone should ring, no?

but instead it seems it looped back into the "invite" and then do the lookup again with blah errors, until it finally reach the finally possibility of "-2", then call works... weird, why?

Thank you!
Reply | Threaded
Open this post in threaded view
|

Re: Get IP/Port of registered user (or from Location table?)

bluerain
In reply to this post by Liviu Chircu
On top of that, I get one way voice... need to wireshark more...
Reply | Threaded
Open this post in threaded view
|

Re: Get IP/Port of registered user (or from Location table?)

Liviu Chircu
In reply to this post by bluerain
Hello bluerain,

Everything you said makes perfect sense and, surprisingly, it is (and should be) the expected behaviour, given that exact piece of code.

In a switch statement, the default behaviour is to go to the next block if a block does not end with the break keyword. It is normal for that script to perform exactly 4 lookups.

Your code now becomes:

"
case -1: 
$var(aor)=[hidden email];
if(!lookup("location","","$var(aor)")) {
	t_reply("404","Not Found new $rc");
	exit;
}
break;

case -3:
#$var(aor)=[hidden email];
#if(!lookup("location","","$var(aor)")) {
	t_newtran();
	t_reply("404","Not Found");
	exit;
#}
break;

...
"

Best regards,
Liviu Chircu
OpenSIPS Developer
http://www.opensips-solutions.com
On 11/18/2013 03:14 AM, bluerain wrote:
Hello Liviu,

thanks for your help again!  Ok, so I tried that and is weird, is kinda
working but is working weirdly.  Not sure, maybe I don't truely understand
how opensips works?  But here is my code:

	if (is_method("INVITE")) {

		        trace_dialog();

			if (!lookup("location","m")){
				switch($rc) 
				{
					case -1: 
						$var(aor)=[hidden email];
						if(!lookup("location","","$var(aor)")) {
							t_reply("404","Not Found new $rc");
							exit;
						}
					case -3:
						#$var(aor)=[hidden email];
						#if(!lookup("location","","$var(aor)")) {
							t_newtran();
							t_reply("404","Not Found");
							exit;
						#}
					case -2:
						#$var(aor)=[hidden email];
						#if(!lookup("location","","$var(aor)")) {
							sl_send_reply("405", "Method Not Allowed");
							exit;
						#}
				}
			}

			route(relay);
		}

So if I use the code above, it would reply "404","Not Found" which means the
lookup() function returned "-3"

And then if I unquote the all the "#" in "-3" section", since that is where
the error happend, now when I sent the INVITE, it would return "405 Method
Not Allowed", which means now lookup() function returned "-2"

So lastly if I unquote the "#"in "-2", the call actually worked!  But it
seems the code must got iterated 3 times before it reach the "method not
found" section and thus finally sent the call out?

So what I mean is that if I sent an "unknown" user in the INVITE, from the
code above, it will jump to "-1" section (because it return error code -1)
and then when it execute again the lookup() in the "-1" section, it jump to
-3 and then execute lookup() again in "-3" and then finally it jump to "-2"
to execute the finally lookup.  Why?

Shouldn't it simply jump to "-1" and then do the lookup("frank101") which IS
IN THE LOCATION table and then proceed with jumping to the route(relay) and
FRANK101 phone should ring, no?

but instead it seems it looped back into the "invite" and then do the lookup
again with blah errors, until it finally reach the finally possibility of
"-2", then call works... weird, why?

Thank you!




--
View this message in context: http://opensips-open-sip-server.1449251.n2.nabble.com/Get-IP-Port-of-registered-user-or-from-Location-table-tp7588494p7588550.html
Sent from the OpenSIPS - Users mailing list archive at Nabble.com.

_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Get IP/Port of registered user (or from Location table?)

bluerain
Really?!  So the "exit" statement I put does not EXIT from the entire script?  Then what does "exit" do?  Hey by the way, thanks again for taking the time answering my question.

And if it go next block, the return code should been "-1" why it would execute in code block in "-3" or "-2"?  
Reply | Threaded
Open this post in threaded view
|

Re: Get IP/Port of registered user (or from Location table?)

bluerain
In reply to this post by Liviu Chircu
So anyhow, I probabaly better off to go with "IF" statement then "switch" in this type of scenario,huh...