From d8771320d7c2d50b780b5ca0a610b93f6b8eda6c Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Sun, 5 Aug 2012 17:53:38 +0000 Subject: [PATCH] new call simulator script for testing against udp protocol --- tests/simulator-udp.pl | 69 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 tests/simulator-udp.pl diff --git a/tests/simulator-udp.pl b/tests/simulator-udp.pl new file mode 100755 index 000000000..eb4d91dd7 --- /dev/null +++ b/tests/simulator-udp.pl @@ -0,0 +1,69 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use Socket; +use UUID; +use BSD::Resource; + +$SIG{ALRM} = sub { print "alarm!\n"; }; +setrlimit(RLIMIT_NOFILE, 8000, 8000); + +my @chrs = ('a' .. 'z', 'A' .. 'Z', '0' .. '9'); +sub rand_str { + my ($len) = @_; + return join('', (map {$chrs[rand(@chrs)]} (1 .. $len))); +} + +my $fd; +sub msg { + my ($l) = @_; + my $cookie = $$ . '_' . rand_str(10); + send($fd, "$cookie $l", 0) or die $!; + my $r; + recv($fd, $r, 0xffff, 0) or die $!; + $r =~ s/^\Q$cookie\E +//s or die $r; + $r =~ s/[\r\n]+$//s; + return $r; +} + +socket($fd, AF_INET, SOCK_DGRAM, 0) or die $!; +connect($fd, sockaddr_in(12222, inet_aton("127.0.0.1"))) or die $!; + +msg('V') eq '20040107' or die; + +my @calls; +for my $iter (1 .. 1000) { + ($iter % 10 == 0) and print("$iter\n"); + + my $callid = rand_str(50); + + my @prefixes = qw(USII LS); + my (@fds,@ports,@ips,@tags,@outputs); + for my $i (0,1) { + socket($fds[$i], AF_INET, SOCK_DGRAM, 0) or die $!; + bind($fds[$i], sockaddr_in(0, INADDR_ANY)) or die $!; + my $addr = getsockname($fds[$i]); + ($ports[$i]) = sockaddr_in($addr); + $ips[$i] = '127.0.0.1'; + $tags[$i] = rand_str(15); + my $o = msg("$prefixes[$i] $callid $ips[$i] $ports[$i] $tags[$i];1"); + $o =~ /^(\d+) ([\d.]+) 4[\r\n]*$/s or die $o; + $outputs[$i] = [$1,$2]; + } + + push(@calls, [\(@fds,@ports,@ips,@tags,@outputs)]); + + for my $c (@calls) { + my ($fds,$outputs) = @$c[0,4]; + for my $i ([0,1],[1,0]) { + my ($a, $b) = @$i; + send($$fds[$a], 'rtp', 0, sockaddr_in($$outputs[$b][0], inet_aton($$outputs[$b][1]))) or die $!; + my $x; + alarm(1); + recv($$fds[$b], $x, 0xffff, 0) or die $!; + alarm(0); + $x eq 'rtp' or die $x; + } + } +}