Login | Register

Documentation

Documentation -> Tutorials -> Concurrent calls limitation 1.8

This page has been visited 19819 times.

This scripting is valid for OpenSIPS versions 1.8 up to 2.1 .

OpenSIPS server can implement concurrent calls limitation by using the call profiles support provided by the dialog module. The call profiles are a simple mechanism that allows to group certain calls and to count them. The grouping can be extended by using labels (values inside a group). This allows a better granularity when comes to counting calls.

Different keys can be used to group calls (like the incoming IP address, the caller user, the outbound GW, etc). Once we create a profile for such a group of call, when handling the call in the OpenSIPS script, we add the call to such a group, eventually with an extra label (where the label is the actual value of the incoming IP or of the caller or of the GW).

In the below example we create a generic route to implement the limitation of concurrent calls from the same caller. The Route takes two parameters, the caller SIP username and the value of the limit. This Route is to be used when calls are created (when initial INVITEs are handled) after the dialog was created in script.

....
# define the profile
modparam("dialog", "profiles_with_value", "caller")
....

########################################################################
# This route is to be called for initial INVITEs, after 
#   the dialog was created
# Parameters:
#    * the caller URI (string)
#    * the limit (integer)
########################################################################
route[do_limit]
{
	# first add to the profile, just to avoid "test and set" false results
	set_dlg_profile("caller","$param(1)");


	# do the actual test - see how many calls the user has so far
	get_profile_size("caller","$param(1)","$var(calls)");
	xlog("User $param(1) has $var(calls) ongoing calls so far, limit is $param(2)\n");

	# check within limit
	if( $var(calls)>$param(2) )
	{	
		xlog("do_limit: user $param(1) exceeded number of calls [$var(calls)/$param(2)]\n");
		send_reply("487", "Request Terminated: Channel limit exceeded\n");
		exit;
		# terminating this call will automatically remove the call from the profile
	}

	# call was added to the profile without exceeding the limit, simply continue
}
....
....
route {
	.....
	# initial INVITES
	route(do_limit,$fu, 10);
	.....
}

MRM?30 March 2017, 12:26

There is a typo in the snippet/example:

get_profile_size("caller","$param(2)","$var(calls)");

would be correct

PS?17 May 2017, 16:37

Nope. $param(2) is the CallLimit - you need to supply the uuid in $param(1) for get_profile_size!

02 July 2018, 14:26

and I can not find where $var(calls) is set.

Alexey K?02 July 2018, 14:27

oh. excuse me. understood.

get_profile_size("caller","$param(1)","$var(calls)");

here we set this variable. not read it value.

clear.

tranghuynh76-QN?23 November 2021, 10:02

nhu cc

Rafael?25 June 2022, 01:40

send_reply("487", "Request Terminated: Channel limit exceeded\n");

The \n should be removed as it cause the response not to be acknowledged.

Btw can this work for several users? I tried but the If condition seems not working when I use multiple users under the same profile.

Add Comment 
Sign as Author 
Enter code 601


Page last modified on June 25, 2022, at 01:40 AM