Author Topic: Limit number of calls per trunk  (Read 17270 times)

arts111199

  • Newbie
  • *
  • Posts: 28
    • View Profile
Limit number of calls per trunk
« on: July 09, 2014, 01:46:40 AM »
Hi,

How can i limit number of simultaneous calls per trunk in regexroute.conf  or from another config file?

Thank You in Advance

marian

  • Hero Member
  • *****
  • Posts: 513
    • View Profile
Re: Limit number of calls per trunk
« Reply #1 on: July 10, 2014, 12:53:23 AM »
What kind of trunk?
What protocol?

If you want to limit the number of sip or iax calls you may set them in ysipchan.conf and yiaxchan.conf, [general] section, 'maxchans' option.

arts111199

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Limit number of calls per trunk
« Reply #2 on: July 10, 2014, 01:18:03 AM »
Hi Marian,

Thank You for your prompt reply,
i want to limit number of calls per one sip trunk not for all,
e.g.

Is there any variable in regexroute or something elsewhere to use for limiting for some provider
;^+7\(.*\)$=sip/99013307\1;line=someprovider;caller=${caller};domain=${domain};forward_sdp=yes;callername=${caller};formats=alaw,mulaw,g729; (limitiing)



marian

  • Hero Member
  • *****
  • Posts: 513
    • View Profile
Re: Limit number of calls per trunk
« Reply #3 on: July 10, 2014, 03:06:51 AM »
It is not easy to do it from regexroute.

I attached a javascript example for it.
The example can be used for your purposes.

Copy the file in share directory.
Add it in javascript.conf:
[scripts]
route=route.js

A simple reload will load the script.
NOTE: If you change the script and reload it channel tracking array will be lost.
You may use shared vars instead of local variables to avoid it

I didn't checked the script. Let me know if it's working.


arts111199

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Limit number of calls per trunk
« Reply #4 on: July 10, 2014, 08:28:33 AM »
Dear Marian,
Please see the log below

20140710141613.461201 <sip/2:ALL> YateSIPConnection::YateSIPConnection(0x7fbb1c00cd50,0x7fbb2801fa10) [0x7fbb1c001db0]
20140710141613.461360 <sip/2:ALL> NAT address is '(null)' [0x7fbb1c001db0]
20140710141613.461656 <sip/2:ALL> Set media: audio=alaw,mulaw,g729 [0x7fbb1c001db0]
20140710141613.461897 <INFO> Could not classify call from '185236654321', wasted 3 usec
20140710141613.461980 <cdrbuild:INFO> Got message 'call.route' for untracked id 'sip/2'
20140710141613.462113 <RegexRoute:ALL> Jumping to context 'from_internal' by rule #1 '${module}sip'
20140710141613.462366 <INFO> Routing call to '456789' in context 'default' via 'external/nodata/route.js' in 345 usec
20140710141613.462403 <sip/2:ALL> NAT address is '(null)' [0x7fbb1c001db0]
20140710141613.462599 <ALL> ExtModChan::ExtModChan(1) [0x7fbb1000b490]
20140710141613.462632 <ALL> ExtModReceiver::ExtModReceiver("route.js","(null)") [0x7fbb100081f0]
20140710141613.463146 <INFO> Launched External Script '/usr/src/yate/share/scripts/route.js' ''
20140710141613.463913 <ExtModule:INFO> Read EOF on 0x7fbb14000900 [0x7fbb100081f0]
20140710141613.463973 <INFO> ExtModReceiver releasing 1 pending messages [0x7fbb100081f0]




20140710141613.468567 <WARN> ExtMod 'route.js' did not handle call message
20140710141613.468609 >>> ExtModChan::~ExtModChan() [0x7fbb1000b490]
20140710141613.468621   <ALL> ExtModReceiver::die() pid=774 dead=no [0x7fbb100081f0]
20140710141613.468637   <ALL> ExtModReceiver::die() waiting for pid=774 to die [0x7fbb100081f0]
20140710141613.469090   <ExtModule:WARN> Never got anything valid from terminated 'route.js' ''
20140710141613.469228   <ALL> ExtModReceiver::~ExtModReceiver() pid=0 [0x7fbb100081f0]
20140710141613.469261   <ALL> ExtModReceiver::die() pid=0 dead=yes [0x7fbb100081f0]
20140710141613.469271 <<< ExtModChan::~ExtModChan()
20140710141613.469335 <sip/2:MILD> Call rejected error='noconn' reason='Could not connect to target' [0x7fbb1c001db0]
20140710141613.469419 <sip/2:ALL> YateSIPConnection::hangup() state=0 trans=0x7fbb2801fa10 error='noconn' code=503 reason='Could not connect to target' [0x7fbb1c001db0]
20140710141613.469467 <sip/2:ALL> YateSIPConnection::~YateSIPConnection() [0x7fbb1c001db0]

my server configuration
in regex
${module}sip=goto from_internal
${address}^1\.1\.1\.1:=external/nodata/route.js

also i have modified the route.js


marian

  • Hero Member
  • *****
  • Posts: 513
    • View Profile
Re: Limit number of calls per trunk
« Reply #5 on: July 10, 2014, 08:37:51 AM »
I said nothing about routing to it through external module!!!

Just add it in javascript.conf and reload the javascript module.
The javascript module will execute it.
It's a global script, not a channel one so there is no need to route to it.

arts111199

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Limit number of calls per trunk
« Reply #6 on: July 10, 2014, 09:07:27 AM »
Dear Marian,

i have done the configuration as you mentioned,but the call  is routed via regex,not with javascript,maybe there must be done some priority changes?

Thank You

marian

  • Hero Member
  • *****
  • Posts: 513
    • View Profile
Re: Limit number of calls per trunk
« Reply #7 on: July 10, 2014, 09:09:27 AM »
Change priority or remove regex routing.

arts111199

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Limit number of calls per trunk
« Reply #8 on: July 11, 2014, 06:25:03 AM »
Dear Marian,

I will check and inform you ASAP.

Thank You

IIIMEJIb

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Limit number of calls per trunk
« Reply #9 on: February 25, 2016, 09:03:40 AM »
Scripts in these posts are lost.  :'( Anyone can send it again please?

arts111199

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Limit number of calls per trunk
« Reply #10 on: February 29, 2016, 12:01:42 PM »
The route.js script file content



################
Engine.debugName("route");
Message.trackName(Engine.debugName());

line = "asteradmin";
line.count = 0;
line.max = 2;
line.chans = [];

function onHangup(msg)
{
    var id = "" + msg.id;
    var idx = line.chans.indexOf(id);
    if (idx >= 0) {
        line.count--;
        delete line.chans[idx];
        Engine.debug(Engine.DebugAll,"Line " + line + " removed chan " + id +
            " count=" + line.count);
    }
    return false;
}

function onRoute(msg)
{
    var called = "" + msg.called;
    if (!called)
        return false;
    if (called.startsWith("456")) {
        // Route to 'someprovider' line
        if (line.count >= line.max) {
            msg.retValue("-");
            // Return some error (optional)
            msg.error = "busy";
            return true;
        }
        line.chans.push(msg.id);
        line.count++;
        Engine.debug(Engine.DebugAll,"Line " + line + " added chan " + msg.id +
            " count=" + line.count);
        msg.line = line;
        msg.forward_sdp = true;
        msg.callername = msg.caller;
        msg.formats = "alaw,mulaw,g729";
        msg.retValue("sip/99013307" + called.substr(2));
        return true;
    }
    return false;
}

Message.install(onHangup,"chan.hangup");
Message.install(onRoute,"call.route",10);

IIIMEJIb

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Limit number of calls per trunk
« Reply #11 on: March 10, 2016, 02:26:46 AM »
Thank You