Browse Source

TT#144701 support JSON in tests and CLI tool

Change-Id: Idd1b413d720b7be8f36849660c547332a344a698
mika/coverity
Richard Fuchs 4 years ago
parent
commit
11549cc3a2
5 changed files with 21 additions and 4 deletions
  1. +1
    -0
      debian/control
  2. +3
    -2
      perl/NGCP/Rtpengine.pm
  3. +6
    -1
      perl/NGCP/Rtpengine/AutoTest.pm
  4. +1
    -0
      t/auto-daemon-tests-pubsub.pl
  5. +10
    -1
      utils/rtpengine-ng-client

+ 1
- 0
debian/control View File

@ -27,6 +27,7 @@ Build-Depends:
libio-socket-ip-perl,
libiptc-dev,
libjson-glib-dev,
libjson-perl,
libmosquitto-dev,
libnet-interface-perl,
libpcap0.8-dev,


+ 3
- 2
perl/NGCP/Rtpengine.pm View File

@ -8,6 +8,7 @@ use IO::Socket;
use IO::Socket::IP;
use Bencode;
use Data::Dumper;
use JSON;
sub new {
my ($class, $addr, $port) = @_;
@ -30,12 +31,12 @@ sub req {
my ($self, $packet) = @_;
my $cookie = rand() . ' ';
my $p = $cookie . Bencode::bencode($packet);
my $p = $cookie . ($self->{json} ? encode_json($packet) : Bencode::bencode($packet));
$self->{socket}->send($p, 0) or die $!;
my $ret;
$self->{socket}->recv($ret, 65535) or die $!;
$ret =~ s/^\Q$cookie\E//s or die $ret;
my $resp = Bencode::bdecode($ret, 1);
my $resp = $self->{json} ? decode_json($ret) : Bencode::bdecode($ret, 1);
$resp->{result} or die Dumper $resp;


+ 6
- 1
perl/NGCP/Rtpengine/AutoTest.pm View File

@ -21,7 +21,7 @@ BEGIN {
@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_ft new_tt crlf sdp_split rtpe_req offer_answer
autotest_init subscribe_request subscribe_answer publish);
autotest_init subscribe_request subscribe_answer publish use_json);
};
@ -290,6 +290,11 @@ sub terminate {
die "error: $msg\n";
}
sub use_json {
my $bool = shift;
$c->{json} = $bool;
}
END {
if ($rtpe_pid) {


+ 1
- 0
t/auto-daemon-tests-pubsub.pl View File

@ -24,6 +24,7 @@ my ($sock_a, $sock_b, $sock_c, $sock_d, $port_a, $port_b, $port_c, $ssrc_a, $ssr
use_json(1);
new_call;


+ 10
- 1
utils/rtpengine-ng-client View File

@ -12,6 +12,7 @@ use NGCP::Rtpengine;
my %options = ('proxy-address' => 'localhost', 'proxy-port' => 2223);
GetOptions(
'json' => \$options{'json'},
'proxy-address=s' => \$options{'proxy-address'},
'proxy-port=s' => \$options{'proxy-port'},
'from-tag=s' => \$options{'from-tag'},
@ -109,7 +110,14 @@ my $cmd = shift(@ARGV) or die;
my %packet = (command => $cmd);
for my $x (split(/,/, 'from-tag,to-tag,call-id,transport protocol,media address,ICE,address family,DTLS,via-branch,media address,ptime,xmlrpc-callback,metadata,address,file,db-id,code,DTLS-fingerprint,ICE-lite,media echo,label,set-label,from-label,to-label')) {
defined($options{$x}) and $packet{$x} = \$options{$x};
if (defined($options{$x})) {
if (!$options{json}) {
$packet{$x} = \$options{$x};
}
else {
$packet{$x} = $options{$x};
}
}
}
for my $x (split(/,/, 'TOS,delete-delay')) {
defined($options{$x}) and $packet{$x} = $options{$x};
@ -190,6 +198,7 @@ if (defined($packet{sdp})) {
}
my $engine = NGCP::Rtpengine->new($options{'proxy-address'}, $options{'proxy-port'});
$engine->{json} = $options{json};
my $resp = $engine->req(\%packet);
#print Dumper $resp;


Loading…
Cancel
Save