[asterisk-dev] Adding a call preemption feature

Jean Aunis jean.aunis at prescom.fr
Mon Nov 13 03:31:38 CST 2017


Hello,

As I highlighted recently on the asterisk-users list 
(http://lists.digium.com/pipermail/asterisk-users/2017-November/292079.html), 
there is no native way in Asterisk to implement call preemption. By call 
preemption, I mean the following :

- given calls have a priority, which may be notified by the network (see 
the SIP header Priority for instance), or which may be set by another way

- given the number of calls to or from a given peer is limited

- when this limit is reached, and an additional call comes in with a 
higher priority than previous ones, one of these calls should be hanged 
up to leave room to the new call.

At the moment, it is possible to limit the number of calls to a peer 
using the GROUP/GROUP_COUNT functions. It is also possible to list all 
channels in Asterisk and choose one to hangup in an AGI script, but 
there is no way to list channels in a particular group. And there is no 
concept of priority attached to a channel.

Therefore, I plan to add a new dialplan application which would preempt 
a channel in a particular group, below a given priority. It would be 
used this way : ChannelPreempt(mygroup,5) where "mygroup" is the group 
in which to look for a channel to hangup, and "5" is the priority below 
which the channel must by chosen. The application would return the 
preemption status and the preempted channel in channel variables.

I would like to have your opinions about the best way to implement this. 
Here are my thoughts so far:

1- add a "priority" field to the channel structure

2- allow the CHANNEL function to read and write this field

3- inside the new ChannelPreempt application:

     - loop through the group list, and find the channel in the given 
group with the lowest priority

     - if this priority is lower than the provided one, hangup the 
selected channel with ast_softhangup

     - otherwise, do nothing

     - set the following dialplan variables on completion:

         * PREEMPTION_STATUS: "SUCCESS" if we found a channel to hang 
up, "FAILURE" otherwise

         * PREEMPTED_CHANNEL: the name of the channel that was hanged up 
in case of success, empty otherwise

By the way, would this feature have a chance to be merged upstream ?

Regards

Jean Aunis




More information about the asterisk-dev mailing list