From 1537eddff6bbbdbc29af69641996ad65ac83b89d Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 7 Aug 2020 13:05:08 -0400 Subject: [PATCH] TT#88750 add SRTP test script Change-Id: I352f24cc6cc229ffd0635adafe89aa20b5f9ef31 --- perl/NGCP/Rtpengine/AutoTest.pm | 15 +++-- t/auto-daemon-tests-redis.pl | 98 +++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 5 deletions(-) create mode 100755 t/auto-daemon-tests-redis.pl diff --git a/perl/NGCP/Rtpengine/AutoTest.pm b/perl/NGCP/Rtpengine/AutoTest.pm index d3871e8ef..b00258e0a 100644 --- a/perl/NGCP/Rtpengine/AutoTest.pm +++ b/perl/NGCP/Rtpengine/AutoTest.pm @@ -20,7 +20,8 @@ BEGIN { require Exporter; @ISA = qw(Exporter); our @EXPORT = qw(autotest_start new_call offer answer ft tt snd srtp_snd rtp rcv srtp_rcv - srtp_dec escape rtpm rtpmre reverse_tags new_tt crlf sdp_split rtpe_req offer_answer); + srtp_dec escape rtpm rtpmre reverse_tags new_tt crlf sdp_split rtpe_req offer_answer + autotest_init); }; @@ -50,6 +51,10 @@ sub autotest_start { ok $rtpe_pid, 'daemon launched in background'; } + return autotest_init(); +} + +sub autotest_init { # keep trying to connect to the control socket while daemon is starting up for (1 .. 300) { $c = NGCP::Rtpengine->new($ENV{RTPENGINE_HOST} // '127.0.0.1', $ENV{RTPENGINE_PORT} // 2223); @@ -135,11 +140,11 @@ sub answer { return offer_answer('answer', $name, $req, $sdps); } sub snd { - my ($sock, $dest, $packet) = @_; - $sock->send($packet, 0, pack_sockaddr_in($dest, inet_aton('203.0.113.1'))) or die; + my ($sock, $dest, $packet, $addr) = @_; + $sock->send($packet, 0, pack_sockaddr_in($dest, inet_aton($addr // '203.0.113.1'))) or die; } sub srtp_snd { - my ($sock, $dest, $packet, $srtp_ctx) = @_; + my ($sock, $dest, $packet, $srtp_ctx, $addr) = @_; if (!$srtp_ctx->{skey}) { my ($key, $salt) = NGCP::Rtpclient::SRTP::decode_inline_base64($srtp_ctx->{key}, $srtp_ctx->{cs}); @$srtp_ctx{qw(skey sauth ssalt)} = NGCP::Rtpclient::SRTP::gen_rtp_session_keys($key, $salt); @@ -147,7 +152,7 @@ sub srtp_snd { my ($enc, $out_roc) = NGCP::Rtpclient::SRTP::encrypt_rtp(@$srtp_ctx{qw(cs skey ssalt sauth roc)}, '', 0, 0, 0, $packet); $srtp_ctx->{roc} = $out_roc; - $sock->send($enc, 0, pack_sockaddr_in($dest, inet_aton('203.0.113.1'))) or die; + $sock->send($enc, 0, pack_sockaddr_in($dest, inet_aton($addr // '203.0.113.1'))) or die; } sub rtp { my ($pt, $seq, $ts, $ssrc, $payload) = @_; diff --git a/t/auto-daemon-tests-redis.pl b/t/auto-daemon-tests-redis.pl new file mode 100755 index 000000000..297c26f47 --- /dev/null +++ b/t/auto-daemon-tests-redis.pl @@ -0,0 +1,98 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use NGCP::Rtpengine::Test; +use NGCP::Rtpclient::SRTP; +use NGCP::Rtpengine::AutoTest; +use Test::More; + + +autotest_init() or die; + + +my ($sock_a, $sock_b, $port_a, $port_b, $ssrc, $resp, $srtp_ctx_a, $srtp_ctx_b, $crypto); + + + + +# SDES in + +($sock_a, $sock_b) = new_call([qw(192.168.1.149 20010)], [qw(192.168.1.149 20012)]); + +($port_a) = offer('SDES in', { ICE => 'remove', + replace => ['origin'], + 'transport-protocol' => 'RTP/AVP', + }, < 'remove', + replace => ['origin'], + DTLS => 'off', + }, < $NGCP::Rtpclient::SRTP::crypto_suites{AES_CM_128_HMAC_SHA1_80}, + key => 'zC6Ea9EK/7YmDM79CK+TAnNXTI1pVmZuCMjUPMph', +}; +$srtp_ctx_b = { + cs => $NGCP::Rtpclient::SRTP::crypto_suites{AES_CM_128_HMAC_SHA1_80}, + key => $crypto, +}; + + +snd($sock_b, $port_a, rtp(0, 1000, 3000, 0x1234, "\x00" x 160), '192.168.1.149'); +srtp_rcv($sock_a, $port_b, rtpm(0, 1000, 3000, 0x1234, "\x00" x 160), $srtp_ctx_b); +srtp_snd($sock_a, $port_b, rtp(0, 2000, 4000, 0x3456, "\x00" x 160), $srtp_ctx_a, '192.168.1.149'); +rcv($sock_b, $port_a, rtpm(0, 2000, 4000, 0x3456, "\x00" x 160)); + +print("wait for restart...\n"); +sleep(10); + +snd($sock_b, $port_a, rtp(0, 1000, 3000, 0x1234, "\x00" x 160), '192.168.1.149'); +srtp_rcv($sock_a, $port_b, rtpm(0, 1000, 3000, 0x1234, "\x00" x 160), $srtp_ctx_b); +srtp_snd($sock_a, $port_b, rtp(0, 2000, 4000, 0x3456, "\x00" x 160), $srtp_ctx_a, '192.168.1.149'); +rcv($sock_b, $port_a, rtpm(0, 2000, 4000, 0x3456, "\x00" x 160)); + + +done_testing();