[asterisk-users] Help with semaphores

Mitch Thompson mitchthompson at satx.rr.com
Wed Jan 31 11:13:05 MST 2007


I'm looking for some help from any Asterisk "heavy" who might be doing 
something similar to what I'm trying to do...

Background:

I work for a research lab, testing telephony products and tools.  
Historically, we used Ameritec Crescendos and Fortissimos to act as load 
generators and call "sinks" when testing equipment.  However, the 
equipment we are testing gets more and more complex, and the scripted 
scenarios the Ameritecs give have become a limiting factor for testing.  
Therefore, Asterisk was chosen as a possible solution (we're a cheap lab).

I've been learning Asterisk as I go, but I've learned a lot.  Here's the 
basic scenario:

We are using an Asterisk (AAH 2.8, specifically) to sink calls.  I do 
this by taking the ${EXTEN} and breaking it down by sections until I get 
to the last 4 digits (i.e., 2105551212).  Once I get to the 4-digit 
extension, I am trying to set a flag, or semaphore, to do Busy/Idle 
testing.  Here is my extensions_custom.conf fragment:


[SATX_555_Extensions]

exten => 1212,1,System(cat /tmp/{orig_num})  ; ${orig_num} is set at the 
beginning of [from-trunk-custom] to the full dialed digits in ${EXTEN}, 
before I break it down.
exten => 1212,n,Busy(); if the file exists, someone else has already 
called this number, return busy

exten => 1212,102,System(echo ${UNIQUEID} > /tmp/${orig_num}) ; 
basically, create a file in /tmp whose name is the full number from the 
beginning.  In this case, the full
                                                                                                              
; filename would be /tmp/2105551212.  I don't really care about the 
contents, though.
exten => 1212,103, Goto(Idle,1) ; from here, we jump to a new extension 
called Idle, where we do a Random to decide whether to simulate no one 
home (ring no answer) or
                                                    ; we send ring for 
about 10 seconds, then Answer() and play some .wav files, then hangup.  
The last thing we do in either case is to delete
                                                    ; the 
/tmp/${orig_num} file.

The above code works very well at low call volumes.  However, I'm 
running into race conditions at high call volumes where several calls 
are getting through the test in priority 1 before the file is created in 
priority 102 (n+101).

I've tried to implement semaphores by using both local and global 
variables, but it doesn't seem to work.

My ultimate question:  Is anyone doing something similar, and what did 
you do to implement the busy/idle.

I appreciate any help anyone can offer.

Mitch Thompson



More information about the asterisk-users mailing list