Created
July 27, 2015 22:28
-
-
Save seven1240/94213aaac09da298480e to your computer and use it in GitHub Desktop.
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 | |
# apt-get install libxml-simple-perl | |
use List::Permutor; | |
use XML::Simple; | |
use Data::Dumper; | |
use strict; | |
use warnings; | |
require ESL; | |
my $test; | |
my $con = new ESL::ESLconnection("localhost", "8021", "ClueCon"); | |
my $e; | |
my $permutor = List::Permutor->new( 'OPUS@1c', 'OPUS@2c', 'PCMU'); | |
while ( my @codec = $permutor->next() ) { | |
print "@codec\n"; | |
# Hangup All Channels | |
$e = $con->api("fsctl", "hupall"); | |
print $e->getBody(); | |
# Get Local IPv4 | |
$e = $con->api("global_getvar", "local_ip_v4"); | |
my $ipv4 = $e->getBody(); | |
# Originate 4 channels. | |
$e = $con->api("originate", "{sip_h_X-Party-B-Codec=$codec[0],sip_h_X-Party-A-Codec=$codec[1],absolute_codec_string=$codec[1]}sofia/external/sip:bridge\@$ipv4:5090 partya XML public"); | |
print $e->getBody(); | |
# Originate 2 channels | |
$e = $con->api("originate", "{sip_h_X-Eavesdrop-Codec=$codec[2]}sofia/external/sip:eavesdrop\@$ipv4:5090 eavesdroper XML public"); | |
print $e->getBody(); | |
# Give everything time to come up. | |
sleep(2); | |
# Get channel list. | |
$e = $con->api("show", "channels as xml"); | |
# Draw UUID to role Map. | |
if ($e) { | |
my $ref = XMLin($e->getBody(), KeepRoot => 1, Keyattr => [ 'row_id' ]); | |
foreach my $key (keys %{$ref->{result}->{row}}) { | |
$e = $con->api("uuid_getvar", "$ref->{result}->{row}->{$key}->{uuid} test_role"); | |
# build map of test roles to uuid | |
if ($e) { | |
my $role = $e->getBody(); | |
$test->{$role} = $ref->{result}->{row}->{$key}->{uuid}; | |
} | |
} | |
} | |
# Dump Map. | |
print Dumper $test; | |
#Schedule API for tonestream in 3 seconds. | |
$con->api("sched_api", "+3 test1 uuid_broadcast $test->{partya} tone_stream://d=300;w=100;12345"); | |
# Subscribe to DTMF Events. | |
$con->events("plain", "DTMF"); | |
my $loops = 0; | |
my $digits = undef; | |
my $edigits = undef; | |
print "Collecting DTMF\n"; | |
while($con->connected()) { | |
my $e = $con->recvEventTimed(100); | |
my $hash = {}; | |
if ($e) { | |
my $h = $e->firstHeader(); | |
while ($h) { | |
$hash->{"$h"} = $e->getHeader($h); | |
$h = $e->nextHeader(); | |
} | |
if ($hash->{'Channel-Call-UUID'} eq $test->{partyb}) { | |
$digits = $digits . "$hash->{'DTMF-Digit'}"; | |
} | |
if ($hash->{'Channel-Call-UUID'} eq $test->{eavesdrop_source}) { | |
$edigits = $edigits . "$hash->{'DTMF-Digit'}"; | |
} | |
} | |
if ($loops > 100) { | |
if($digits && $digits eq '12345') { | |
print "partya -> partyb PASSED[$digits]\n"; | |
} else { | |
print "partya -> partyb FAILED[$digits]\n"; | |
} | |
if($edigits && $edigits eq '12345') { | |
print "partya -> eavesdrop_source PASSED[$edigits]\n"; | |
} else { | |
print "partya -> eavesdrop_source FAILED[$edigits]\n"; | |
} | |
last; | |
} | |
$loops++; | |
} | |
$con->api("sched_api", "+3 test1 uuid_broadcast $test->{partyb} tone_stream://d=300;w=100;12345"); | |
$loops = 0; | |
$digits = undef; | |
$edigits = undef; | |
print "Collecting DTMF\n"; | |
while($con->connected()) { | |
my $e = $con->recvEventTimed(100); | |
my $hash = {}; | |
if ($e) { | |
my $h = $e->firstHeader(); | |
while ($h) { | |
$hash->{"$h"} = $e->getHeader($h); | |
$h = $e->nextHeader(); | |
} | |
if ($hash->{'Channel-Call-UUID'} eq $test->{partya}) { | |
$digits = $digits . "$hash->{'DTMF-Digit'}"; | |
} | |
if ($hash->{'Channel-Call-UUID'} eq $test->{eavesdrop_source}) { | |
$edigits = $edigits . "$hash->{'DTMF-Digit'}"; | |
} | |
} | |
if ($loops > 100) { | |
if($digits && $digits eq '12345') { | |
print "partyb -> partya PASSED[$digits]\n"; | |
} else { | |
print "partyb -> partya FAILED[$digits]\n"; | |
} | |
if($edigits && $edigits eq '12345') { | |
print "partyb -> eavesdrop_source PASSED[$edigits]\n"; | |
} else { | |
print "partyb -> eavesdrop_source FAILED[$edigits]\n"; | |
} | |
last; | |
} | |
$loops++; | |
} | |
print "eavesdrop_source send dtmf 1\n"; | |
$con->api("uuid_send_dtmf", "$test->{eavesdrop_source} 1"); | |
$con->api("sched_api", "+3 test1 uuid_broadcast $test->{eavesdrop_source} tone_stream://d=300;w=100;12345"); | |
$loops = 0; | |
my $adigits = undef; | |
my $bdigits = undef; | |
$edigits = undef; | |
print "Collecting DTMF\n"; | |
while($con->connected()) { | |
my $e = $con->recvEventTimed(100); | |
my $hash = {}; | |
if ($e) { | |
my $h = $e->firstHeader(); | |
while ($h) { | |
$hash->{"$h"} = $e->getHeader($h); | |
$h = $e->nextHeader(); | |
} | |
if ($hash->{'Channel-Call-UUID'} eq $test->{partya}) { | |
$adigits = $adigits . "$hash->{'DTMF-Digit'}"; | |
} | |
if ($hash->{'Channel-Call-UUID'} eq $test->{partyb}) { | |
$bdigits = $bdigits . "$hash->{'DTMF-Digit'}"; | |
} | |
} | |
if ($loops > 100) { | |
if($adigits && $adigits eq '12345') { | |
print "eavesdrop_source -> partya PASSED[$adigits]\n"; | |
} else { | |
if($adigits) { | |
print "eavesdrop_source -> partya FAILED[$adigits]\n"; | |
} else { | |
print "eavesdrop_source -> partya PASSED[NODTMF]\n"; | |
} | |
} | |
if($bdigits && $bdigits eq '12345') { | |
print "eavesdrop_source -> partyb PASSED[$bdigits]\n"; | |
} else { | |
if($bdigits) { | |
print "eavesdrop_source -> partyb FAILED[$bdigits]\n"; | |
} else { | |
print "eavesdrop_source -> partyb PASSED[NODTMF]\n"; | |
} | |
} | |
last; | |
} | |
$loops++; | |
} | |
print "eavesdrop_source send dtmf 2\n"; | |
$con->api("uuid_send_dtmf", "$test->{eavesdrop_source} 2"); | |
$con->api("sched_api", "+3 test1 uuid_broadcast $test->{eavesdrop_source} tone_stream://d=300;w=100;12345"); | |
$loops = 0; | |
$adigits = undef; | |
$bdigits = undef; | |
$edigits = undef; | |
print "Collecting DTMF\n"; | |
while($con->connected()) { | |
my $e = $con->recvEventTimed(100); | |
my $hash = {}; | |
if ($e) { | |
my $h = $e->firstHeader(); | |
while ($h) { | |
$hash->{"$h"} = $e->getHeader($h); | |
$h = $e->nextHeader(); | |
} | |
if ($hash->{'Channel-Call-UUID'} eq $test->{partya}) { | |
$adigits = $adigits . "$hash->{'DTMF-Digit'}"; | |
} | |
if ($hash->{'Channel-Call-UUID'} eq $test->{partyb}) { | |
$bdigits = $bdigits . "$hash->{'DTMF-Digit'}"; | |
} | |
} | |
if ($loops > 100) { | |
if($adigits && $adigits eq '12345') { | |
print "eavesdrop_source -> partya PASSED[$adigits]\n"; | |
} else { | |
if($adigits) { | |
print "eavesdrop_source -> partya FAILED[$adigits]\n"; | |
} else { | |
print "eavesdrop_source -> partya PASSED[NODTMF]\n"; | |
} | |
} | |
if($bdigits && $bdigits eq '12345') { | |
print "eavesdrop_source -> partyb PASSED[$bdigits]\n"; | |
} else { | |
if($bdigits) { | |
print "eavesdrop_source -> partyb FAILED[$bdigits]\n"; | |
} else { | |
print "eavesdrop_source -> partyb PASSED[NODTMF]\n"; | |
} | |
} | |
last; | |
} | |
$loops++; | |
} | |
print "eavesdrop_source send dtmf 3\n"; | |
$con->api("uuid_send_dtmf", "$test->{eavesdrop_source} 3"); | |
$con->api("sched_api", "+3 test1 uuid_broadcast $test->{eavesdrop_source} tone_stream://d=300;w=100;12345"); | |
$loops = 0; | |
$adigits = undef; | |
$bdigits = undef; | |
$edigits = undef; | |
print "Collecting DTMF\n"; | |
while($con->connected()) { | |
my $e = $con->recvEventTimed(100); | |
my $hash = {}; | |
if ($e) { | |
my $h = $e->firstHeader(); | |
while ($h) { | |
$hash->{"$h"} = $e->getHeader($h); | |
$h = $e->nextHeader(); | |
} | |
if ($hash->{'Channel-Call-UUID'} eq $test->{partya}) { | |
$adigits = $adigits . "$hash->{'DTMF-Digit'}"; | |
} | |
if ($hash->{'Channel-Call-UUID'} eq $test->{partyb}) { | |
$bdigits = $bdigits . "$hash->{'DTMF-Digit'}"; | |
} | |
} | |
if ($loops > 100) { | |
if($adigits && $adigits eq '12345') { | |
print "eavesdrop_source -> partya PASSED[$adigits]\n"; | |
} else { | |
if($adigits) { | |
print "eavesdrop_source -> partya FAILED[$adigits]\n"; | |
} else { | |
print "eavesdrop_source -> partya PASSED[NODTMF]\n"; | |
} | |
} | |
if($bdigits && $bdigits eq '12345') { | |
print "eavesdrop_source -> partyb PASSED[$bdigits]\n"; | |
} else { | |
if($bdigits) { | |
print "eavesdrop_source -> partyb FAILED[$bdigits]\n"; | |
} else { | |
print "eavesdrop_source -> partyb PASSED[NODTMF]\n"; | |
} | |
} | |
last; | |
} | |
$loops++; | |
} | |
$con->api("sched_api", "+3 test1 uuid_broadcast $test->{partya} tone_stream://d=300;w=100;12345"); | |
$loops = 0; | |
$digits = undef; | |
$edigits = undef; | |
print "Collecting DTMF\n"; | |
while($con->connected()) { | |
my $e = $con->recvEventTimed(100); | |
my $hash = {}; | |
if ($e) { | |
my $h = $e->firstHeader(); | |
while ($h) { | |
$hash->{"$h"} = $e->getHeader($h); | |
$h = $e->nextHeader(); | |
} | |
if ($hash->{'Channel-Call-UUID'} eq $test->{partyb}) { | |
$digits = $digits . "$hash->{'DTMF-Digit'}"; | |
} | |
if ($hash->{'Channel-Call-UUID'} eq $test->{eavesdrop_source}) { | |
$edigits = $edigits . "$hash->{'DTMF-Digit'}"; | |
} | |
} | |
if ($loops > 100) { | |
if($digits && $digits eq '12345') { | |
print "partya -> partyb PASSED[$digits]\n"; | |
} else { | |
print "partya -> partyb FAILED[$digits]\n"; | |
} | |
if($edigits && $edigits eq '12345') { | |
print "partya -> eavesdrop_source PASSED[$edigits]\n"; | |
} else { | |
print "partya -> eavesdrop_source FAILED[$edigits]\n"; | |
} | |
last; | |
} | |
$loops++; | |
} | |
$con->api("sched_api", "+3 test1 uuid_broadcast $test->{partyb} tone_stream://d=300;w=100;12345"); | |
$loops = 0; | |
$digits = undef; | |
$edigits = undef; | |
print "Collecting DTMF\n"; | |
while($con->connected()) { | |
my $e = $con->recvEventTimed(100); | |
my $hash = {}; | |
if ($e) { | |
my $h = $e->firstHeader(); | |
while ($h) { | |
$hash->{"$h"} = $e->getHeader($h); | |
$h = $e->nextHeader(); | |
} | |
if ($hash->{'Channel-Call-UUID'} eq $test->{partya}) { | |
$digits = $digits . "$hash->{'DTMF-Digit'}"; | |
} | |
if ($hash->{'Channel-Call-UUID'} eq $test->{eavesdrop_source}) { | |
$edigits = $edigits . "$hash->{'DTMF-Digit'}"; | |
} | |
} | |
if ($loops > 100) { | |
if($digits && $digits eq '12345') { | |
print "partyb -> partya PASSED[$digits]\n"; | |
} else { | |
print "partyb -> partya FAILED[$digits]\n"; | |
} | |
if($edigits && $edigits eq '12345') { | |
print "partyb -> eavesdrop_source PASSED[$edigits]\n"; | |
} else { | |
print "partyb -> eavesdrop_source FAILED[$edigits]\n"; | |
} | |
last; | |
} | |
$loops++; | |
} | |
sleep(1); | |
} | |
print "Ending Test.\n"; | |
$e = $con->api("fsctl", "hupall"); | |
__DATA__ | |
<!-- Eavesdrop Test Rig --> | |
<!-- Target Bridge To Spy On --> | |
<extension name="party-a-to-party-b-bridge"> | |
<condition field="destination_number" expression="^bridge$"> | |
<action application="set" data="test_role=bridge_partya"/> | |
<action application="set" data="eavesdrop_group=bridge"/> | |
<action application="set" data="absolute_codec_string=${sip_h_X-Party-A-Codec}"/> | |
<action application="bridge" data="{test_role=bridge_partyb,eavesdrop_group=bridge,absolute_codec_string=${sip_h_X-Party-B-Codec}}sofia/external/sip:partyb@${local_ip_v4}:5090"/> | |
</condition> | |
</extension> | |
<!-- Eavesdrop Target App --> | |
<extension name="eavesdrop-target"> | |
<condition field="destination_number" expression="^eavesdrop$"> | |
<action application="set" data="test_role=eavesdrop_target"/> | |
<action application="set" data="eavesdrop_require_group=bridge"/> | |
<action application="set" data="absolute_codec_string=${sip_h_X-Eavesdrop-Codec}"/> | |
<action application="answer"/> | |
<action application="eavesdrop" data="all"/> | |
</condition> | |
</extension> | |
<!-- Target Party B --> | |
<extension name="party-b-answer"> | |
<condition field="destination_number" expression="^partyb$"> | |
<action application="set" data="test_role=partyb"/> | |
<action application="set" data="absolute_codec_string=${sip_h_X-Party-B-Codec}"/> | |
<action application="answer"/> | |
<action application="spandsp_start_dtmf"/> | |
<action application="playback" data="silence_stream://-1"/> | |
</condition> | |
</extension> | |
<!-- Source Party A --> | |
<extension name="party-a-playback"> | |
<condition field="destination_number" expression="^partya$"> | |
<action application="set" data="test_role=partya"/> | |
<action application="answer"/> | |
<action application="spandsp_start_dtmf"/> | |
<action application="playback" data="silence_stream://-1"/> | |
</condition> | |
</extension> | |
<!-- Eavesdrop Party --> | |
<extension name="eavesdroper"> | |
<condition field="destination_number" expression="^eavesdroper$"> | |
<action application="set" data="test_role=eavesdrop_source"/> | |
<action application="answer"/> | |
<action application="spandsp_start_dtmf"/> | |
<action application="playback" data="silence_stream://-1"/> | |
</condition> | |
</extension> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment