Created
April 15, 2020 15:38
-
-
Save trdenton/69ff5ed43ca944bd349c4149694c239a to your computer and use it in GitHub Desktop.
test a range of numbers via local freeswitch install, for number porting confirmation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use ESL::Dispatch; | |
# take in number range as individual args | |
# e.g. | |
# perl test_range.pl 2042223000-3999 will test a range of 1000 numbers | |
# | |
# 2042223000-3999/50 will test every 50th number | |
# if the /50 is omitted, default is 25 | |
# | |
# can also run multiple ranges | |
# perl test_range.pl 2042223000-3099 2043332000-2099 | |
# | |
# you will be prompted for each range and receive a confirmation | |
# of the # of tests configured | |
my @queue; | |
sub ask_yn { | |
print ("y/n> "); | |
chomp ($_=<STDIN>); | |
print ("\n"); | |
if (/^[yY]/) | |
{ | |
return 1; | |
} | |
return 0; | |
} | |
sub add_to_queue { | |
my $n1 = shift; | |
my $n2 = shift; | |
my $stride = shift; | |
my $i; | |
for($i = $n1; $i <= $n2; $i += $stride) | |
{ | |
push(@queue,$i); | |
} | |
} | |
################ | |
# MAIN LOGIC | |
################ | |
#the queue that holds numbers | |
my $daemon = init ESL::Dispatch({}); | |
$|=1; | |
#max concurrent numbers | |
my $MAX_CALLS=4; | |
my $available=$MAX_CALLS; | |
sub worker { | |
if ($available > 0) { | |
$available--; | |
my $num = pop(@queue); | |
if (defined $num) { | |
print "Calling $num\n"; | |
qx(fs_cli -x 'originate {origination_caller_id_number=2042222222,call_timeout=30}sofia/gateway/foo/$num &playback(/tmp/tone.wav)') | |
} | |
} | |
} | |
sub hangup { | |
my $event = shift; | |
print "hangup received\n"; | |
$available++; | |
if ($available > $MAX_CALLS) | |
{ | |
$available = $MAX_CALLS; | |
} | |
} | |
sub create { | |
my $event = shift; | |
print "create received\n"; | |
} | |
foreach my $arg (@ARGV) | |
{ | |
if ($arg =~ /(\d+)-(\d+)(\/(\d+))?/) | |
{ | |
my $n1 = $1; | |
my $n2 = $n1; | |
my $stride = 25; | |
substr($n2,-length($2)) = $2; | |
my $num1 = int($n1); | |
my $num2 = int($n2); | |
if ($num2 <= $num1) | |
{ | |
print "$arg is invalid, Z should be > Y in (XXXXXXYYYY-ZZZZ)\n"; | |
next; | |
} | |
if (defined $4) | |
{ | |
$stride = $4; | |
} | |
my $range = $num2 - $num1 + 1; | |
my $num_tests = int($range / $stride); | |
print "process $num1 to $num2\n"; | |
print " range of ".$range." numbers\n"; | |
print " checking every ${stride}th number\n"; | |
print " this results in $num_tests tests - proceed?\n"; | |
print "\n"; | |
if (ask_yn()) { | |
print "adding number range to queue\n"; | |
add_to_queue($num1,$num2,$stride); | |
} else { | |
print "Skipping number range.\n"; | |
} | |
print "\n"; | |
} else { | |
print "$arg is invalid, must be numeric XXXXXXXXXX-YYYY\n"; | |
} | |
} | |
$daemon->set_worker(\&worker,1000); | |
$daemon->set_callback("channel_hangup",\&hangup); | |
$daemon->set_callback("channel_create",\&create); | |
$daemon->run; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment