[OpenSIPS-Users] Limit calls over IP between Opensips Servers
Bakko
asannucci at gmail.com
Wed Dec 12 15:42:36 CET 2012
Hello,
maybe I resolved this configuration. My escenario:
- load balancing environment
- some clients register to opensips with a softphone and IP change.
- some clients sending only INVITE to Opensips and Asterisk Servers
authenticate the INVITE.
Configuration:
I created a new table on Opensips database with this fields:
IP
Max calls permitted
company name
On both Opensips configuration I created a shared profile dialog:
Opensips 1
#### DIALOG module
loadmodule "dialog.so"
modparam("dialog","cachedb_url","redis://localhost:6379/")
modparam("dialog", "default_timeout", 21600)
modparam("dialog", "profiles_with_value", "calls/s")
Opensips2
loadmodule "dialog.so"
modparam("dialog","cachedb_url","redis://localhost:6380/")
modparam("dialog", "default_timeout", 21600)
modparam("dialog", "profiles_with_value", "calls/s")
On both record route:
record_route();
setflag(1); # do accounting
if (load_balance("1","voip/s")) {
set_dlg_profile("calls/s","$si");
get_profile_size("calls/s","$si","$avp(size)");
avp_db_query("select canales from canales where
IP='$si'","$avp(calls)");
if($retcode == 1){
xlog("L_INFO", "Canales activos = $avp(size) Canales
disponibles = $avp(calls) $si\n");
if($avp(size) <= $avp(calls)){
xlog("L_INFO", "Llamada de $fu a $tu para $du \n");
route(RELAY);
exit;
}
else {
xlog("L_INFO", "Se ha superado el numero de
canales disponibles [$avp(size)/$avp(calls)]\n");
route(2);
exit;
}
}
xlog("L_INFO", "Llamada de $fu a $tu para $du \n");
route(RELAY);
exit;
}
route[RELAY] {
if (!t_relay()) {
xlog("L_ERR", "route [RELAY]\n");
sl_reply_error();
};
exit;
}
route[2] {
xlog("desviando la llamada a contexto Opensip - extension
canales\n");
rewriteuri("sip:canales at sip.mydomain.net");
forward();
exit;
}
The logic:
when Opensips receive a INVITE set the profile size for the originating
IP and get the profile size saving the value on the $avp(size) variable,
then check the database to looking for for the IP on the INVITE. If IP
exist, the function return 1 and save the max channels value on the
$avp(calls) variable. If $avp(size) is <= $avp(calls) opensips route
the call to one of Asterisk servers else process route(2). In process
route[2] rewrite the URI and send the calls to one of Asterisk Servers
where on context opensip, extension canales, a prompt announce to caller
"no more channels availables" and hangup the call.
With this configuration I can share between the two opensips servers the
MAX calls over IP permitted.
Maybe there is some syntax error on the script. Any suggestion?
Regards
More information about the Users
mailing list