Discussion:
[SR-Users] How to limit number of calls in Kamailio proxy
Austin Einter
2011-10-29 02:57:53 UTC
Permalink
This is continuation with limiting number of calls per Kamailio proxy
server.
I modified kamailio.cfg as below.

1. loadmodule "dialog.so"
2. modparam("dialog", "enable_stats", 1)
3. modparam("dialog", "dlg_flag", 4)
Next, as dialog module I can use either active_dialogs() or $DLG_count to
find number of calls present at any given point of time.
However if I use active_dialogs() I get parse error when I run kamailio
proxy.
Next I used $DLG_count , but always I am getting value of $DLG_count as 0.

In *route* section, I added code as below.

if (is_method("INVITE"))
{
if($DLG_count > 1)
{
sl_send_reply("503","RESOURCE UNAVAILABLE");
exit;
}
else
{
xlog("Dialog count = $DLG_count\n");
}
}
Everytime a new call starts , it prints $DLG_count as 0.

Kindly let me know whats going wrong here.

Regards
Austin
Alex Balashov
2011-10-29 03:28:16 UTC
Permalink
Are you calling dlg_manage() when processing the initial INVITE request?

--
This message was painstakingly thumbed out on my mobile, so apologies for brevity, errors, and general sloppiness.

Alex Balashov - Principal
Evariste Systems LLC
260 Peachtree Street NW
Suite 2200
Atlanta, GA 30303
Tel: +1-678-954-0670
Fax: +1-404-961-1892
Web: http://www.evaristesys.com/
This is continuation with limiting number of calls per Kamailio proxy server.
I modified kamailio.cfg as below.
1. loadmodule "dialog.so"
2. modparam("dialog", "enable_stats", 1)
3. modparam("dialog", "dlg_flag", 4)
Next, as dialog module I can use either active_dialogs() or $DLG_count to find number of calls present at any given point of time.
However if I use active_dialogs() I get parse error when I run kamailio proxy.
Next I used $DLG_count , but always I am getting value of $DLG_count as 0.
In route section, I added code as below.
if (is_method("INVITE"))
{
if($DLG_count > 1)
{
sl_send_reply("503","RESOURCE UNAVAILABLE");
exit;
}
else
{
xlog("Dialog count = $DLG_count\n");
}
}
Everytime a new call starts , it prints $DLG_count as 0.
Kindly let me know whats going wrong here.
Regards
Austin
_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
Austin Einter
2011-10-29 09:10:14 UTC
Permalink
Alex
Initially I did not put dlg_manage(), after reading your post I added the
dlg_manage(). Now in route section my code in kamailio.config looks as
below.


* dlg_manage();
if (is_method("INVITE"))
{
if (!has_totag())
{
if($DLG_count > 1)
{
sl_send_reply("503","RESOURCE UNAVAILABLE");
exit;
}
else
{
setflag(FLD_DLG);
xlog("Dialog count = $DLG_count\n");
}
}
*
The end result still remains same. The DLG_count still shows as 0
irrespective of number of calls present in system.

Can somebody points whats wrong I am doing here.

Regards,
Austin
Post by Alex Balashov
Are you calling dlg_manage() when processing the initial INVITE request?
--
This message was painstakingly thumbed out on my mobile, so apologies for
brevity, errors, and general sloppiness.
Alex Balashov - Principal
Evariste Systems LLC
260 Peachtree Street NW
Suite 2200
Atlanta, GA 30303
Tel: +1-678-954-0670
Fax: +1-404-961-1892
Web: http://www.evaristesys.com/
Post by Austin Einter
This is continuation with limiting number of calls per Kamailio proxy
server.
Post by Austin Einter
I modified kamailio.cfg as below.
1. loadmodule "dialog.so"
2. modparam("dialog", "enable_stats", 1)
3. modparam("dialog", "dlg_flag", 4)
Next, as dialog module I can use either active_dialogs() or $DLG_count to
find number of calls present at any given point of time.
Post by Austin Einter
However if I use active_dialogs() I get parse error when I run kamailio
proxy.
Post by Austin Einter
Next I used $DLG_count , but always I am getting value of $DLG_count as
0.
Post by Austin Einter
In route section, I added code as below.
if (is_method("INVITE"))
{
if($DLG_count > 1)
{
sl_send_reply("503","RESOURCE UNAVAILABLE");
exit;
}
else
{
xlog("Dialog count = $DLG_count\n");
}
}
Everytime a new call starts , it prints $DLG_count as 0.
Kindly let me know whats going wrong here.
Regards
Austin
_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
Austin Einter
2011-10-30 01:53:10 UTC
Permalink
Hi All
Still I am struggling to find a solution how to control the number of calls.

I have few more doubts regarding this.

1. Do I need to enable mysql , so that these counters such as $DLG_count
will be updated properly. Now I am getting 0 always irrespective of number
of calls in system.

2. For testing purpose, I wanted to set max calls at any point of time
should not be more than 1.
So I had the check as below

*if($DLG_count > 1) *

I read in some previous posts where someone was mentioning the check as

*if ( avp_check("$DLG_count", "gt/i:10") )
*
Please let me know which one is correct.


3. How do I debug whats going wrong. Why $DBG_count is not updated.

Thanks in advance.

Regards,
Austin
Post by Austin Einter
Alex
Initially I did not put dlg_manage(), after reading your post I added the
dlg_manage(). Now in route section my code in kamailio.config looks as
below.
* dlg_manage();
if (is_method("INVITE"))
{
if (!has_totag())
{
if($DLG_count > 1)
{
sl_send_reply("503","RESOURCE UNAVAILABLE");
exit;
}
else
{
setflag(FLD_DLG);
xlog("Dialog count = $DLG_count\n");
}
}
*
The end result still remains same. The DLG_count still shows as 0
irrespective of number of calls present in system.
Can somebody points whats wrong I am doing here.
Regards,
Austin
Post by Alex Balashov
Are you calling dlg_manage() when processing the initial INVITE request?
--
This message was painstakingly thumbed out on my mobile, so apologies for
brevity, errors, and general sloppiness.
Alex Balashov - Principal
Evariste Systems LLC
260 Peachtree Street NW
Suite 2200
Atlanta, GA 30303
Tel: +1-678-954-0670
Fax: +1-404-961-1892
Web: http://www.evaristesys.com/
Post by Austin Einter
This is continuation with limiting number of calls per Kamailio proxy
server.
Post by Austin Einter
I modified kamailio.cfg as below.
1. loadmodule "dialog.so"
2. modparam("dialog", "enable_stats", 1)
3. modparam("dialog", "dlg_flag", 4)
Next, as dialog module I can use either active_dialogs() or $DLG_count
to find number of calls present at any given point of time.
Post by Austin Einter
However if I use active_dialogs() I get parse error when I run kamailio
proxy.
Post by Austin Einter
Next I used $DLG_count , but always I am getting value of $DLG_count as
0.
Post by Austin Einter
In route section, I added code as below.
if (is_method("INVITE"))
{
if($DLG_count > 1)
{
sl_send_reply("503","RESOURCE UNAVAILABLE");
exit;
}
else
{
xlog("Dialog count = $DLG_count\n");
}
}
Everytime a new call starts , it prints $DLG_count as 0.
Kindly let me know whats going wrong here.
Regards
Austin
_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
Alex Balashov
2011-10-30 01:55:28 UTC
Permalink
Have you tried using dialog profiles instead of $DLG_count?
--
Alex Balashov - Principal
Evariste Systems LLC
260 Peachtree Street NW
Suite 2200
Atlanta, GA 30303
Tel: +1-678-954-0670
Fax: +1-404-961-1892
Web: http://www.evaristesys.com/
Austin Einter
2011-10-30 02:38:46 UTC
Permalink
Alex
Thansk for quick answer.

I have not used profiles yet.
I just observed some interesting stuff.

In route section if I put code as below I see $DLG_count value is being
changed, but it does not look consistent.

*setflag(FLD_DLG);
if (is_method("INVITE"))
{
*
So if I put setflag before if check, $DLG_count I can see changing. Looks
it is only incrementing, but not decrementing.

You have any idea, why it is behaving so.

Can somebody point me what is the best way to put a limit for maximum
number of concurrent calls.

Regards
Austin
Post by Alex Balashov
Have you tried using dialog profiles instead of $DLG_count?
--
Alex Balashov - Principal
Evariste Systems LLC
260 Peachtree Street NW
Suite 2200
Atlanta, GA 30303
Tel: +1-678-954-0670
Fax: +1-404-961-1892
Web: http://www.evaristesys.com/
______________________________**_________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
http://lists.sip-router.org/**cgi-bin/mailman/listinfo/sr-**users<http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users>
Austin Einter
2011-10-30 04:00:29 UTC
Permalink
Hi Alex
I tried using profile. I added below code to kamailio.cfg in route section.

if (is_method("INVITE")) {
if (!has_totag()) {
get_profile_size("caller", "$fu", "$var(SIZE)");
if( $var(SIZE) >= MAX_NUMBER_OF_CALLS ) {
sl_send_reply("503", "Simultaneous calls
limit reached");
xlog("Rejected calls with 503 Simultaneous
calls limit reached\n");
exit;
}
else {
xlog("Max calls limit not reached yet\n");
}
}
}
set_dlg_profile("caller","$fu");

When I run kamailio, I get below error.

0(4925) CRITICAL: dialog [dialog.c:297]: profile <caller> not definited
0(4925) ERROR: <core> [route.c:1161]: fixing failed (code=-6) at
cfg:/usr/local/etc/kamailio/kamailio.cfg:423
0(4925) ERROR: <core> [route.c:1161]: fixing failed (code=-6) at
cfg:/usr/local/etc/kamailio/kamailio.cfg:433
0(4925) ERROR: <core> [route.c:1161]: fixing failed (code=-6) at
cfg:/usr/local/etc/kamailio/kamailio.cfg:434
ERROR: error -6 while trying to fix configuration

Any idea why this error comes and how to fix it.

-Regds
Austin
Post by Austin Einter
This is continuation with limiting number of calls per Kamailio proxy
server.
I modified kamailio.cfg as below.
1. loadmodule "dialog.so"
2. modparam("dialog", "enable_stats", 1)
3. modparam("dialog", "dlg_flag", 4)
Next, as dialog module I can use either active_dialogs() or $DLG_count to
find number of calls present at any given point of time.
However if I use active_dialogs() I get parse error when I run kamailio
proxy.
Next I used $DLG_count , but always I am getting value of $DLG_count as 0.
In *route* section, I added code as below.
if (is_method("INVITE"))
{
if($DLG_count > 1)
{
sl_send_reply("503","RESOURCE UNAVAILABLE");
exit;
}
else
{
xlog("Dialog count = $DLG_count\n");
}
}
Everytime a new call starts , it prints $DLG_count as 0.
Kindly let me know whats going wrong here.
Regards
Austin
Andrew Pogrebennyk
2011-10-30 06:58:46 UTC
Permalink
Post by Austin Einter
When I run kamailio, I get below error.
0(4925) CRITICAL: dialog [dialog.c:297]: profile <caller> not definited
[...]
Any idea why this error comes and how to fix it.
You should really define profile caller by putting it into
profiles_with_value module parameter:
http://kamailio.org/docs/modules/3.1.x/modules_k/dialog.html#id2523534
Austin Einter
2011-10-30 11:08:45 UTC
Permalink
Thanks Andrew
I added profile_with_value module parameter and with that I am able to
overcome this error.

My code looks as below.

dlg_manage();
if (is_method("INVITE")) {
if (!has_totag()) {
#$var(SIZE) = 0;
get_profile_size("caller", "$fu", "$var(SIZE)");
xlog("Number of calls present now is
$var(SIZE)\n");
if( $var(SIZE) > MAX_NUMBER_OF_CALLS ) {
sl_send_reply("503", "Simultaneous calls
limit reached");
xlog("Rejected calls with 503 Simultaneous
calls limit reached\n");
exit;
}
else {
xlog("Allowed call. Looks max calls limit
not reached. Calls= $var(SIZE)\n");
}
set_dlg_profile("caller","$fu");
}
}
Whole purpose is to limit number of active calls at any point of time.
$var(SIZE) gives the number of calls are being established, but not the
number of calls are already established.

So if I am making multiple calls at a point of time, it is blocking call
attempts beyond limit. But after all call setup complete, again $var(SIZE)
becomes zero and allows new calls.


Has anybody done this (limiting number of calls at any point of time). If
so can you please share the configuration file changes.


To get $var(SIZE) working properly, do I need to enable MySql, please
advice.

Regards
Austin



On Sun, Oct 30, 2011 at 12:28 PM, Andrew Pogrebennyk <
Post by Andrew Pogrebennyk
Post by Austin Einter
When I run kamailio, I get below error.
0(4925) CRITICAL: dialog [dialog.c:297]: profile <caller> not definited
[...]
Any idea why this error comes and how to fix it.
You should really define profile caller by putting it into
http://kamailio.org/docs/modules/3.1.x/modules_k/dialog.html#id2523534
_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
Andrew Pogrebennyk
2011-10-31 11:07:38 UTC
Permalink
Austin,
That is strange, because I am using similar setup successfully. Actually
I don't know if it counts the calls that are being established, I didn't
care for it.

While looking through the docs:
http://kamailio.org/docs/modules/3.1.x/modules_k/dialog.html#id2524304
the following note caught my eye:

IMPORTANT: Users of this function should make sure that the dialog
created is further processed statefully. Specifically, if a stateless
response is sent out after dlg_manage() is called, the dialog cannot be
handled properly. So make sure that a transaction exists or create it
explicitly using the tm module. This is a shortcoming of the current
implementation that may be resolved in a future version hopefully.

Could it be that you are forwarding the INVITE statelessly?
Regards,
Andrew
Post by Austin Einter
Thanks Andrew
I added profile_with_value module parameter and with that I am able to
overcome this error.
My code looks as below.
dlg_manage();
if (is_method("INVITE")) {
if (!has_totag()) {
#$var(SIZE) = 0;
get_profile_size("caller", "$fu", "$var(SIZE)");
xlog("Number of calls present now is
$var(SIZE)\n");
if( $var(SIZE) > MAX_NUMBER_OF_CALLS ) {
sl_send_reply("503", "Simultaneous calls
limit reached");
xlog("Rejected calls with 503
Simultaneous calls limit reached\n");
exit;
}
else {
xlog("Allowed call. Looks max calls
limit not reached. Calls= $var(SIZE)\n");
}
set_dlg_profile("caller","$fu");
}
}
Whole purpose is to limit number of active calls at any point of time.
$var(SIZE) gives the number of calls are being established, but not the
number of calls are already established.
So if I am making multiple calls at a point of time, it is blocking
call attempts beyond limit. But after all call setup complete, again
$var(SIZE) becomes zero and allows new calls.
Has anybody done this (limiting number of calls at any point of time).
If so can you please share the configuration file changes.
To get $var(SIZE) working properly, do I need to enable MySql, please
advice.
Regards
Austin
Austin Einter
2011-11-03 01:00:52 UTC
Permalink
Dear Andrew, Henning
Thanks for sharing very useful information.
I am bit new to kamailio, probably askingvery easy questions, please bear
with me.

I am not sure if I am forwording the INVITE statelessly or not.
How do I check if INVITE is forwarded statelessly.
Andrew you have mentioned 'So make sure that a transaction exists or create
it
explicitly using the tm module".

Not sure, how do I check if transaction exists or not. And how can I create
it.

Please give me some pointers or a sample config file.

Regards,
Austin


On Mon, Oct 31, 2011 at 4:37 PM, Andrew Pogrebennyk <
Post by Andrew Pogrebennyk
Austin,
That is strange, because I am using similar setup successfully. Actually
I don't know if it counts the calls that are being established, I didn't
care for it.
http://kamailio.org/docs/modules/3.1.x/modules_k/dialog.html#id2524304
IMPORTANT: Users of this function should make sure that the dialog
created is further processed statefully. Specifically, if a stateless
response is sent out after dlg_manage() is called, the dialog cannot be
handled properly. So make sure that a transaction exists or create it
explicitly using the tm module. This is a shortcoming of the current
implementation that may be resolved in a future version hopefully.
Could it be that you are forwarding the INVITE statelessly?
Regards,
Andrew
Post by Austin Einter
Thanks Andrew
I added profile_with_value module parameter and with that I am able to
overcome this error.
My code looks as below.
dlg_manage();
if (is_method("INVITE")) {
if (!has_totag()) {
#$var(SIZE) = 0;
get_profile_size("caller", "$fu", "$var(SIZE)");
xlog("Number of calls present now is
$var(SIZE)\n");
if( $var(SIZE) > MAX_NUMBER_OF_CALLS ) {
sl_send_reply("503", "Simultaneous calls
limit reached");
xlog("Rejected calls with 503
Simultaneous calls limit reached\n");
exit;
}
else {
xlog("Allowed call. Looks max calls
limit not reached. Calls= $var(SIZE)\n");
}
set_dlg_profile("caller","$fu");
}
}
Whole purpose is to limit number of active calls at any point of time.
$var(SIZE) gives the number of calls are being established, but not the
number of calls are already established.
So if I am making multiple calls at a point of time, it is blocking
call attempts beyond limit. But after all call setup complete, again
$var(SIZE) becomes zero and allows new calls.
Has anybody done this (limiting number of calls at any point of time).
If so can you please share the configuration file changes.
To get $var(SIZE) working properly, do I need to enable MySql, please
advice.
Regards
Austin
_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
Jason Penton
2011-11-03 05:15:35 UTC
Permalink
Hi Austin,

Have a look at the TM module docs. You will find the appropriate commands
there.

HTH
Post by Austin Einter
Dear Andrew, Henning
Thanks for sharing very useful information.
I am bit new to kamailio, probably askingvery easy questions, please bear
with me.
I am not sure if I am forwording the INVITE statelessly or not.
How do I check if INVITE is forwarded statelessly.
Andrew you have mentioned 'So make sure that a transaction exists or
create it
explicitly using the tm module".
Not sure, how do I check if transaction exists or not. And how can I
create it.
Please give me some pointers or a sample config file.
Regards,
Austin
On Mon, Oct 31, 2011 at 4:37 PM, Andrew Pogrebennyk <
Post by Andrew Pogrebennyk
Austin,
That is strange, because I am using similar setup successfully. Actually
I don't know if it counts the calls that are being established, I didn't
care for it.
http://kamailio.org/docs/modules/3.1.x/modules_k/dialog.html#id2524304
IMPORTANT: Users of this function should make sure that the dialog
created is further processed statefully. Specifically, if a stateless
response is sent out after dlg_manage() is called, the dialog cannot be
handled properly. So make sure that a transaction exists or create it
explicitly using the tm module. This is a shortcoming of the current
implementation that may be resolved in a future version hopefully.
Could it be that you are forwarding the INVITE statelessly?
Regards,
Andrew
Post by Austin Einter
Thanks Andrew
I added profile_with_value module parameter and with that I am able to
overcome this error.
My code looks as below.
dlg_manage();
if (is_method("INVITE")) {
if (!has_totag()) {
#$var(SIZE) = 0;
get_profile_size("caller", "$fu", "$var(SIZE)");
xlog("Number of calls present now is
$var(SIZE)\n");
if( $var(SIZE) > MAX_NUMBER_OF_CALLS ) {
sl_send_reply("503", "Simultaneous calls
limit reached");
xlog("Rejected calls with 503
Simultaneous calls limit reached\n");
exit;
}
else {
xlog("Allowed call. Looks max calls
limit not reached. Calls= $var(SIZE)\n");
}
set_dlg_profile("caller","$fu");
}
}
Whole purpose is to limit number of active calls at any point of time.
$var(SIZE) gives the number of calls are being established, but not the
number of calls are already established.
So if I am making multiple calls at a point of time, it is blocking
call attempts beyond limit. But after all call setup complete, again
$var(SIZE) becomes zero and allows new calls.
Has anybody done this (limiting number of calls at any point of time).
If so can you please share the configuration file changes.
To get $var(SIZE) working properly, do I need to enable MySql, please
advice.
Regards
Austin
_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
Andrew Pogrebennyk
2011-11-03 09:03:30 UTC
Permalink
Austin,

Actually you could share your config to the mailing list, I will tell
you if there is something blatantly wrong ;-)

Regards,
Andrew
Post by Henning Westerholt
Hi Austin,
Have a look at the TM module docs. You will find the appropriate
commands there.
HTH
Dear Andrew, Henning
Thanks for sharing very useful information.
I am bit new to kamailio, probably askingvery easy questions, please
bear with me.
I am not sure if I am forwording the INVITE statelessly or not.
How do I check if INVITE is forwarded statelessly.
Andrew you have mentioned 'So make sure that a transaction exists or
create it
explicitly using the tm module".
Not sure, how do I check if transaction exists or not. And how can I
create it.
Please give me some pointers or a sample config file.
Regards,
Austin
Austin Einter
2011-11-05 02:02:49 UTC
Permalink
Dear Andrew
Here I am attaching the config file I am using currently.
Please suggest me if something is wrong there. Also how do I limit the
maximum number of calls.
Thanks, Austin
Post by Andrew Pogrebennyk
Austin,
Actually you could share your config to the mailing list, I will tell
you if there is something blatantly wrong ;-)
Regards,
Andrew
Post by Henning Westerholt
Hi Austin,
Have a look at the TM module docs. You will find the appropriate
commands there.
HTH
Dear Andrew, Henning
Thanks for sharing very useful information.
I am bit new to kamailio, probably askingvery easy questions, please
bear with me.
I am not sure if I am forwording the INVITE statelessly or not.
How do I check if INVITE is forwarded statelessly.
Andrew you have mentioned 'So make sure that a transaction exists or
create it
explicitly using the tm module".
Not sure, how do I check if transaction exists or not. And how can I
create it.
Please give me some pointers or a sample config file.
Regards,
Austin
_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
Andrew Pogrebennyk
2011-11-10 07:16:24 UTC
Permalink
Austin,
the block beginning with dlg_manage() should be placed between
route(AUTH) and route(PSTN). It is commented out and put outside the
main routing block so I'm not sure if that was the case..

If the problem persists please get the dialogs list before calling,
while the callee's phone is ringing after the call is established and
after the call is cleared. If I am not mistaken the command is:
kamctl fifo profile_list_dlgs caller
Post by Austin Einter
Dear Andrew
Here I am attaching the config file I am using currently.
Please suggest me if something is wrong there. Also how do I limit the
maximum number of calls.
Thanks, Austin
Henning Westerholt
2011-10-31 16:03:52 UTC
Permalink
Post by Austin Einter
[...]
To get $var(SIZE) working properly, do I need to enable MySql, please
advice.
Hi Austin,

its not necessary to enable mySQL database support in the dialog module to use
the dialog profile support to e.g. get the number of concurrent calls.

Best regards,

Henning
Loading...