blob: 31bf68a86606357e10e01824147522655a91a32d [file] [log] [blame]
Harald Welte067d66e2017-12-13 17:24:03 +01001module RTP_Emulation {
2
3/* Functionalities that we want this module to imeplement:
4 * * act as a RTP source that generates a RTP Stream
5 * * act asaa RTP sink that consumes a RTP Stream
6 *
7 * for all of the above, we want to be able to
8 * * specify the payload type
9 * * specify the interval / sample rate
10 * * create drop-outs in the stream
11 * * detect reordered or lost frames
12 * * validate if the size of the frames matches epectations
13 * * play back real audio (at least some tones?)
14 * * enable/disable generation/verification of RTCP
15 */
16
Harald Welte34b5a952019-05-27 11:54:11 +020017/* (C) 2017-2018 Harald Welte <laforge@gnumonks.org>
18 * (C) 2018-2019 sysmocom - s.f.m.c. GmbH
19 * All rights reserved.
20 *
21 * Released under the terms of GNU General Public License, Version 2 or
22 * (at your option) any later version.
23 *
24 * SPDX-License-Identifier: GPL-2.0-or-later
25 */
26
27
Harald Weltea4ca4462018-02-09 00:17:14 +010028/* Ideas:
29
30* each component consists of transmitter and receiver
31* transmitters and receivers can be operated as tuple?
32* high-level operation
33** set-up config at transmitter + receiver
34** transmit sequence of payloads
35** verify receiption of those payloads
36* can operate full-duplex/bi-directional as needed
37
38* transmitter
39** trigger transmission of n number of packets
40** transmit them at normal ptime interval
41** payload size configurable
42** payload contents PRBS or the like
43
44* receiver
45** count number of related packets at receiver
46** check received payload type
47** check received timestamp increments
48** check received seq_nr increments
49** (optionally) check for SSRC
50** (optionally) check for payload size
51** (optionally) check for payload contents
52
53* later
54** how to test transcoding?
55** how to test pure play-out endpoints (rx only)?
56** how to test "Rx from wrong IP/port" scenarios?
57** how to test RTCP?
58** maybe keep ports un-connected to show wrong src -lrt
59
60*/
61
62
63
64
Harald Welte067d66e2017-12-13 17:24:03 +010065import from General_Types all;
66import from Osmocom_Types all;
67import from IPL4asp_Types all;
68import from RTP_Types all;
69import from RTP_CodecPort all;
70import from RTP_CodecPort_CtrlFunct all;
71
Harald Welte80981642017-12-24 23:59:47 +010072import from IuUP_Types all;
73import from IuUP_Emulation all;
74
Harald Welte067d66e2017-12-13 17:24:03 +010075type component RTP_Emulation_CT {
76 /* down-facing ports for RTP and RTCP codec ports on top of IPL4asp */
77 port RTP_CODEC_PT RTP;
78 var integer g_rtp_conn_id := -1;
79 port RTP_CODEC_PT RTCP;
80 var integer g_rtcp_conn_id := -1;
81
82 /* user-facing port for controlling the binding */
83 port RTPEM_CTRL_PT CTRL;
84
85 /* configurable by user, should be fixed */
Harald Welte80981642017-12-24 23:59:47 +010086 var RtpemConfig g_cfg := c_RtpemDefaultCfg;
Harald Welte067d66e2017-12-13 17:24:03 +010087
Harald Weltecb8b4272018-03-28 19:57:58 +020088 /* statistics */
89 var RtpemStats g_stats_rtp := c_RtpemStatsReset;
90 var RtpemStats g_stats_rtcp := c_RtpemStatsReset;
91
Harald Welte067d66e2017-12-13 17:24:03 +010092 var HostName g_remote_host;
93 var PortNumber g_remote_port;
94 var HostName g_local_host;
95 var PortNumber g_local_port;
96
97 /* state variables, change over time */
98 var boolean g_rx_enabled := false;
Pau Espin Pedrole38bfe02019-05-17 18:40:43 +020099 var boolean g_tx_connected := false; /* Set to true after connect() */
Harald Welte067d66e2017-12-13 17:24:03 +0100100 var LIN2_BO_LAST g_tx_next_seq := 0;
101 var uint32_t g_tx_next_ts := 0;
102
103 var INT7b g_rx_payload_type := 0;
104 var LIN2_BO_LAST g_rx_last_seq;
105 var uint32_t g_rx_last_ts;
Harald Welte80981642017-12-24 23:59:47 +0100106
107 var IuUP_Entity g_iuup_ent; // := valueof(t_IuUP_Entity(1));
Harald Welte067d66e2017-12-13 17:24:03 +0100108}
109
110type enumerated RtpemMode {
111 RTPEM_MODE_NONE,
112 RTPEM_MODE_TXONLY,
113 RTPEM_MODE_RXONLY,
114 RTPEM_MODE_BIDIR
115};
116
Harald Weltecb8b4272018-03-28 19:57:58 +0200117type record RtpemStats {
118 /* number of packets transmitted */
119 integer num_pkts_tx,
120 /* number of RTP payload bytes transmitted */
121 integer bytes_payload_tx,
122
123 /* number of packets received */
124 integer num_pkts_rx,
125 /* number of RTP payload bytes received */
126 integer bytes_payload_rx,
127 /* number of packets received out-of-sequence */
128 integer num_pkts_rx_err_seq,
129 /* number of packets received wrong timestamp */
130 integer num_pkts_rx_err_ts,
Philipp Maierc290d722018-07-24 18:51:36 +0200131 /* number of packets received wrong payload type */
132 integer num_pkts_rx_err_pt,
Harald Weltecb8b4272018-03-28 19:57:58 +0200133 /* number of packets received during Rx disable */
Philipp Maiera071ee42019-02-21 16:17:32 +0100134 integer num_pkts_rx_err_disabled,
135 /* number of packets received with mismatching payload */
136 integer num_pkts_rx_err_payload
Harald Weltecb8b4272018-03-28 19:57:58 +0200137}
138
139const RtpemStats c_RtpemStatsReset := {
140 num_pkts_tx := 0,
141 bytes_payload_tx := 0,
142 num_pkts_rx := 0,
143 bytes_payload_rx := 0,
144 num_pkts_rx_err_seq := 0,
145 num_pkts_rx_err_ts := 0,
Philipp Maierc290d722018-07-24 18:51:36 +0200146 num_pkts_rx_err_pt := 0,
Philipp Maiera071ee42019-02-21 16:17:32 +0100147 num_pkts_rx_err_disabled := 0,
148 num_pkts_rx_err_payload := 0
Harald Weltecb8b4272018-03-28 19:57:58 +0200149}
150
Harald Welte3f6f48f2017-12-24 21:48:33 +0100151type record RtpemConfig {
152 INT7b tx_payload_type,
153 integer tx_samplerate_hz,
154 integer tx_duration_ms,
155 BIT32_BO_LAST tx_ssrc,
Harald Welte80981642017-12-24 23:59:47 +0100156 octetstring tx_fixed_payload optional,
Philipp Maiera071ee42019-02-21 16:17:32 +0100157 octetstring rx_fixed_payload optional,
Harald Welte80981642017-12-24 23:59:47 +0100158 boolean iuup_mode,
159 boolean iuup_tx_init
Harald Welte3f6f48f2017-12-24 21:48:33 +0100160};
161
Harald Welte80981642017-12-24 23:59:47 +0100162const RtpemConfig c_RtpemDefaultCfg := {
Harald Welte3f6f48f2017-12-24 21:48:33 +0100163 tx_payload_type := 0,
164 tx_samplerate_hz := 8000,
165 tx_duration_ms := 20,
166 tx_ssrc := '11011110101011011011111011101111'B,
Harald Welte80981642017-12-24 23:59:47 +0100167 tx_fixed_payload := '01020304'O,
Philipp Maiera071ee42019-02-21 16:17:32 +0100168 rx_fixed_payload := '01020304'O,
Harald Welte80981642017-12-24 23:59:47 +0100169 iuup_mode := false,
170 iuup_tx_init := true
Harald Welte3f6f48f2017-12-24 21:48:33 +0100171}
172
Harald Welte067d66e2017-12-13 17:24:03 +0100173signature RTPEM_bind(in HostName local_host, inout PortNumber local_port);
174signature RTPEM_connect(in HostName remote_host, in PortNumber remote_port);
175signature RTPEM_mode(in RtpemMode mode);
Harald Welte3f6f48f2017-12-24 21:48:33 +0100176signature RTPEM_configure(in RtpemConfig cfg);
Harald Weltecb8b4272018-03-28 19:57:58 +0200177signature RTPEM_stats_get(out RtpemStats stats, in boolean rtcp);
Harald Welte067d66e2017-12-13 17:24:03 +0100178
179type port RTPEM_CTRL_PT procedure {
Harald Weltecb8b4272018-03-28 19:57:58 +0200180 inout RTPEM_bind, RTPEM_connect, RTPEM_mode, RTPEM_configure, RTPEM_stats_get;
Harald Welte067d66e2017-12-13 17:24:03 +0100181} with { extension "internal" };
182
Harald Welte1af40332018-03-29 08:50:33 +0200183function f_rtpem_bind(RTPEM_CTRL_PT pt, in HostName local_host, inout PortNumber local_port) {
184 pt.call(RTPEM_bind:{local_host, local_port}) {
185 [] pt.getreply(RTPEM_bind:{local_host, ?}) -> param (local_port) {};
186 }
187}
188function f_rtpem_connect(RTPEM_CTRL_PT pt, in HostName remote_host, in PortNumber remote_port) {
189 pt.call(RTPEM_connect:{remote_host, remote_port}) {
190 [] pt.getreply(RTPEM_connect:{remote_host, remote_port}) {};
191 }
192}
193function f_rtpem_mode(RTPEM_CTRL_PT pt, in RtpemMode mode) {
194 pt.call(RTPEM_mode:{mode}) {
195 [] pt.getreply(RTPEM_mode:{mode}) {};
196 }
197}
198function f_rtpem_configure(RTPEM_CTRL_PT pt, in RtpemConfig cfg) {
199 pt.call(RTPEM_configure:{cfg}) {
200 [] pt.getreply(RTPEM_configure:{cfg}) {};
201 }
202}
203function f_rtpem_stats_get(RTPEM_CTRL_PT pt, boolean rtcp := false) return RtpemStats {
204 var RtpemStats stats;
205 pt.call(RTPEM_stats_get:{-, rtcp}) {
206 [] pt.getreply(RTPEM_stats_get:{?, rtcp}) -> param(stats) {};
207 }
208 return stats;
209}
210
Philipp Maier2321ef92018-06-27 17:52:04 +0200211function f_rtpem_stats_compare_value(integer a, integer b, integer tolerance := 0) return boolean {
212 var integer temp;
Harald Welte5c49ba42018-03-29 08:51:20 +0200213
Philipp Maier2321ef92018-06-27 17:52:04 +0200214 temp := (a - b)
215 if (temp < 0) {
216 temp := -temp;
217 }
218
219 if (temp > tolerance) {
Harald Welte5c49ba42018-03-29 08:51:20 +0200220 return false;
221 }
Philipp Maier2321ef92018-06-27 17:52:04 +0200222
Harald Welte5c49ba42018-03-29 08:51:20 +0200223 return true;
224}
Harald Welte1af40332018-03-29 08:50:33 +0200225
Philipp Maier2321ef92018-06-27 17:52:04 +0200226/* Cross-compare two rtpem-statistics. The transmission statistics on the a side
227 * must match the reception statistics on the other side and vice versa. The
228 * user may also supply a tolerance value (number of packets) when deviations
229 * are acceptable */
230function f_rtpem_stats_compare(RtpemStats a, RtpemStats b, integer tolerance := 0) return boolean {
231 var integer plen;
232
233 log("stats A: ", a);
234 log("stats B: ", b);
235 log("tolerance: ", tolerance, " packets");
236
237 if (f_rtpem_stats_compare_value(a.num_pkts_tx, b.num_pkts_rx, tolerance) == false) {
238 return false;
239 }
240
241 if (f_rtpem_stats_compare_value(a.num_pkts_rx, b.num_pkts_tx, tolerance) == false) {
242 return false;
243 }
244
245 if(a.num_pkts_tx > 0) {
246 plen := a.bytes_payload_tx / a.num_pkts_tx;
247 } else {
248 plen := 0;
249 }
250
251 if (f_rtpem_stats_compare_value(a.bytes_payload_tx, b.bytes_payload_rx, tolerance * plen) == false) {
252 return false;
253 }
254
255 if (f_rtpem_stats_compare_value(a.bytes_payload_rx, b.bytes_payload_tx, tolerance * plen) == false) {
256 return false;
257 }
258
259 return true;
260}
Harald Welte1af40332018-03-29 08:50:33 +0200261
Philipp Maier36291392018-07-25 09:40:44 +0200262/* Check the statistics for general signs of errors. This is a basic general
263 * check that will fit most situations and is intended to be executed by
264 * the testcases as as needed. */
265function f_rtpem_stats_err_check(RtpemStats s) {
266 log("stats: ", s);
267
268 /* Check if there was some activity at either on the RX or on the
269 * TX side, but complete silence would indicate some problem */
270 if (s.num_pkts_tx < 1 and s.num_pkts_rx < 1) {
271 setverdict(fail, "no RTP packet activity detected (packets)");
272 mtc.stop;
273 }
274 if (s.bytes_payload_tx < 1 and s.bytes_payload_rx < 1) {
275 setverdict(fail, "no RTP packet activity detected (bytes)");
276 mtc.stop;
277 }
278
279 /* Check error counters */
280 if (s.num_pkts_rx_err_seq != 0) {
281 setverdict(fail, "RTP packet sequence number errors occurred");
282 mtc.stop;
283 }
284 if (s.num_pkts_rx_err_ts != 0) {
285 setverdict(fail, "RTP packet timestamp errors occurred");
286 mtc.stop;
287 }
288 if (s.num_pkts_rx_err_pt != 0) {
289 setverdict(fail, "RTP packet payload type errors occurred");
290 mtc.stop;
291 }
292 if (s.num_pkts_rx_err_disabled != 0) {
293 setverdict(fail, "RTP packets received while RX was disabled");
294 mtc.stop;
295 }
Philipp Maiera071ee42019-02-21 16:17:32 +0100296 if (s.num_pkts_rx_err_payload != 0) {
297 setverdict(fail, "RTP packets with mismatching payload received");
298 mtc.stop;
299 }
Philipp Maier36291392018-07-25 09:40:44 +0200300}
301
Harald Welte067d66e2017-12-13 17:24:03 +0100302template PDU_RTP ts_RTP(BIT32_BO_LAST ssrc, INT7b pt, LIN2_BO_LAST seq, uint32_t ts,
303 octetstring payload, BIT1 marker := '0'B) := {
304 version := 2,
305 padding_ind := '0'B,
306 extension_ind := '0'B,
307 CSRC_count := 0,
308 marker_bit := marker,
309 payload_type := pt,
310 sequence_number := seq,
Harald Welte8a4d3952017-12-24 21:30:23 +0100311 time_stamp := int2bit(ts, 32),
Harald Welte067d66e2017-12-13 17:24:03 +0100312 SSRC_id := ssrc,
313 CSRCs := omit,
314 ext_header := omit,
315 data := payload
316}
317
318private function f_tx_rtp(octetstring payload, BIT1 marker := '0'B) runs on RTP_Emulation_CT {
Harald Welte80981642017-12-24 23:59:47 +0100319 if (g_cfg.iuup_mode) {
320 payload := f_IuUP_Em_tx_encap(g_iuup_ent, payload);
321 }
Harald Welte3f6f48f2017-12-24 21:48:33 +0100322 var PDU_RTP rtp := valueof(ts_RTP(g_cfg.tx_ssrc, g_cfg.tx_payload_type, g_tx_next_seq,
Harald Welte067d66e2017-12-13 17:24:03 +0100323 g_tx_next_ts, payload, marker));
324 RTP.send(t_RTP_Send(g_rtp_conn_id, RTP_messages_union:{rtp:=rtp}));
325 /* increment sequence + timestamp for next transmit */
326 g_tx_next_seq := g_tx_next_seq + 1;
Harald Welte3f6f48f2017-12-24 21:48:33 +0100327 g_tx_next_ts := g_tx_next_ts + (g_cfg.tx_samplerate_hz / (1000 / g_cfg.tx_duration_ms));
Harald Welte067d66e2017-12-13 17:24:03 +0100328}
329
330function f_main() runs on RTP_Emulation_CT
331{
332 var Result res;
Harald Weltecb8b4272018-03-28 19:57:58 +0200333 var boolean is_rtcp
Harald Welte067d66e2017-12-13 17:24:03 +0100334
Harald Welte3f6f48f2017-12-24 21:48:33 +0100335 timer T_transmit := int2float(g_cfg.tx_duration_ms)/1000.0;
Harald Welte067d66e2017-12-13 17:24:03 +0100336 var RTP_RecvFrom rx_rtp;
Harald Welte3f6f48f2017-12-24 21:48:33 +0100337 var RtpemConfig cfg;
Harald Welte067d66e2017-12-13 17:24:03 +0100338 var template RTP_RecvFrom tr := {
339 connId := ?,
340 remName := ?,
341 remPort := ?,
342 locName := ?,
343 locPort := ?,
344 msg := ?
345 };
346 var template RTP_RecvFrom tr_rtp := tr;
347 var template RTP_RecvFrom tr_rtcp := tr;
Harald Welte067d66e2017-12-13 17:24:03 +0100348 tr_rtp.msg := { rtp := ? };
Harald Welte067d66e2017-12-13 17:24:03 +0100349 tr_rtcp.msg := { rtcp := ? };
350
Harald Welte80981642017-12-24 23:59:47 +0100351 g_iuup_ent := valueof(t_IuUP_Entity(g_cfg.iuup_tx_init));
352
Harald Welte067d66e2017-12-13 17:24:03 +0100353 while (true) {
354 alt {
355 /* control procedures (calls) from the user */
356 [] CTRL.getcall(RTPEM_bind:{?,?}) -> param(g_local_host, g_local_port) {
357 if (g_local_port rem 2 == 1) {
358 //CTRL.raise(RTPEM_bind, "Local Port is not an even port number!");
359 log("Local Port is not an even port number!");
360 continue;
361 }
Pau Espin Pedrole38bfe02019-05-17 18:40:43 +0200362
363 g_tx_connected := false; /* will set it back to true upon next connect() call */
Harald Welte067d66e2017-12-13 17:24:03 +0100364 res := RTP_CodecPort_CtrlFunct.f_IPL4_listen(RTP, g_local_host,
365 g_local_port, {udp:={}});
Harald Welte9220f632018-05-23 20:27:02 +0200366 if (not ispresent(res.connId)) {
367 setverdict(fail, "Could not listen on RTP socket, check your configuration");
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200368 mtc.stop;
Harald Welte9220f632018-05-23 20:27:02 +0200369 }
Harald Welte067d66e2017-12-13 17:24:03 +0100370 g_rtp_conn_id := res.connId;
Harald Welte9774e7a2018-03-29 08:49:38 +0200371 tr_rtp.connId := g_rtp_conn_id;
Harald Welte98eb1bf2018-04-02 18:18:44 +0200372 res := RTP_CodecPort_CtrlFunct.f_IPL4_listen(RTCP, g_local_host,
Harald Welte067d66e2017-12-13 17:24:03 +0100373 g_local_port+1, {udp:={}});
Harald Welte9220f632018-05-23 20:27:02 +0200374 if (not ispresent(res.connId)) {
375 setverdict(fail, "Could not listen on RTCP socket, check your configuration");
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200376 mtc.stop;
Harald Welte9220f632018-05-23 20:27:02 +0200377 }
Harald Welte067d66e2017-12-13 17:24:03 +0100378 g_rtcp_conn_id := res.connId;
Harald Welte9774e7a2018-03-29 08:49:38 +0200379 tr_rtcp.connId := g_rtcp_conn_id;
Harald Welte067d66e2017-12-13 17:24:03 +0100380 CTRL.reply(RTPEM_bind:{g_local_host, g_local_port});
381 }
382 [] CTRL.getcall(RTPEM_connect:{?,?}) -> param (g_remote_host, g_remote_port) {
383 if (g_remote_port rem 2 == 1) {
384 //CTRL.raise(RTPEM_connect, "Remote Port is not an even number!");
385 log("Remote Port is not an even number!");
386 continue;
387 }
388 res := RTP_CodecPort_CtrlFunct.f_IPL4_connect(RTP, g_remote_host,
389 g_remote_port,
390 g_local_host, g_local_port,
391 g_rtp_conn_id, {udp:={}});
Harald Welte9220f632018-05-23 20:27:02 +0200392 if (not ispresent(res.connId)) {
393 setverdict(fail, "Could not connect to RTP socket, check your configuration");
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200394 mtc.stop;
Harald Welte9220f632018-05-23 20:27:02 +0200395 }
Harald Welte067d66e2017-12-13 17:24:03 +0100396 res := RTP_CodecPort_CtrlFunct.f_IPL4_connect(RTCP, g_remote_host,
397 g_remote_port+1,
398 g_local_host, g_local_port+1,
399 g_rtcp_conn_id, {udp:={}});
Harald Welte9220f632018-05-23 20:27:02 +0200400 if (not ispresent(res.connId)) {
401 setverdict(fail, "Could not connect to RTCP socket, check your configuration");
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200402 mtc.stop;
Harald Welte9220f632018-05-23 20:27:02 +0200403 }
Pau Espin Pedrole38bfe02019-05-17 18:40:43 +0200404 g_tx_connected := true;
Harald Welte067d66e2017-12-13 17:24:03 +0100405 CTRL.reply(RTPEM_connect:{g_remote_host, g_remote_port});
406 }
407 [] CTRL.getcall(RTPEM_mode:{RTPEM_MODE_NONE}) {
408 T_transmit.stop;
409 g_rx_enabled := false;
Harald Welte80981642017-12-24 23:59:47 +0100410 CTRL.reply(RTPEM_mode:{RTPEM_MODE_NONE});
Harald Welte067d66e2017-12-13 17:24:03 +0100411 }
412 [] CTRL.getcall(RTPEM_mode:{RTPEM_MODE_TXONLY}) {
413 /* start transmit timer */
414 T_transmit.start;
415 g_rx_enabled := false;
Harald Welte80981642017-12-24 23:59:47 +0100416 CTRL.reply(RTPEM_mode:{RTPEM_MODE_TXONLY});
Harald Welte067d66e2017-12-13 17:24:03 +0100417 }
418 [] CTRL.getcall(RTPEM_mode:{RTPEM_MODE_RXONLY}) {
419
420 T_transmit.stop;
421 if (g_rx_enabled == false) {
422 /* flush queues */
423 RTP.clear;
424 RTCP.clear;
425 g_rx_enabled := true;
426 }
Harald Welte80981642017-12-24 23:59:47 +0100427 CTRL.reply(RTPEM_mode:{RTPEM_MODE_RXONLY});
Harald Welte067d66e2017-12-13 17:24:03 +0100428 }
429 [] CTRL.getcall(RTPEM_mode:{RTPEM_MODE_BIDIR}) {
430 T_transmit.start;
431 if (g_rx_enabled == false) {
432 /* flush queues */
433 RTP.clear;
434 RTCP.clear;
435 g_rx_enabled := true;
436 }
Harald Welte80981642017-12-24 23:59:47 +0100437 CTRL.reply(RTPEM_mode:{RTPEM_MODE_BIDIR});
Harald Welte067d66e2017-12-13 17:24:03 +0100438 }
Harald Welte3f6f48f2017-12-24 21:48:33 +0100439 [] CTRL.getcall(RTPEM_configure:{?}) -> param (cfg) {
440 g_cfg := cfg;
Harald Welte80981642017-12-24 23:59:47 +0100441 g_iuup_ent.cfg.active_init := g_cfg.iuup_tx_init;
442 CTRL.reply(RTPEM_configure:{cfg});
Harald Welte3f6f48f2017-12-24 21:48:33 +0100443 }
Harald Weltecb8b4272018-03-28 19:57:58 +0200444 [] CTRL.getcall(RTPEM_stats_get:{?, ?}) -> param (is_rtcp) {
445 if (is_rtcp) {
446 CTRL.reply(RTPEM_stats_get:{g_stats_rtcp, is_rtcp});
447 } else {
448 CTRL.reply(RTPEM_stats_get:{g_stats_rtp, is_rtcp});
449 }
450 }
Harald Welte067d66e2017-12-13 17:24:03 +0100451
Harald Weltecb8b4272018-03-28 19:57:58 +0200452
453
454 /* simply ignore any RTTP/RTP if receiver not enabled */
455 [g_rx_enabled==false] RTP.receive(tr_rtp) {
456 g_stats_rtp.num_pkts_rx_err_disabled := g_stats_rtp.num_pkts_rx_err_disabled+1;
457 }
Harald Welte98eb1bf2018-04-02 18:18:44 +0200458 [g_rx_enabled==false] RTCP.receive(tr_rtcp) {
Harald Weltecb8b4272018-03-28 19:57:58 +0200459 g_stats_rtcp.num_pkts_rx_err_disabled := g_stats_rtcp.num_pkts_rx_err_disabled+1;
460 }
Harald Welte067d66e2017-12-13 17:24:03 +0100461
462 /* process received RTCP/RTP if receiver enabled */
463 [g_rx_enabled] RTP.receive(tr_rtp) -> value rx_rtp {
Harald Weltecb8b4272018-03-28 19:57:58 +0200464 /* increment counters */
Philipp Maierc290d722018-07-24 18:51:36 +0200465 if (rx_rtp.msg.rtp.payload_type != g_cfg.tx_payload_type) {
466 g_stats_rtp.num_pkts_rx_err_pt := g_stats_rtp.num_pkts_rx_err_pt+1;
467 }
Harald Weltecb8b4272018-03-28 19:57:58 +0200468 g_stats_rtp.num_pkts_rx := g_stats_rtp.num_pkts_rx+1;
469 g_stats_rtp.bytes_payload_rx := g_stats_rtp.bytes_payload_rx +
470 lengthof(rx_rtp.msg.rtp.data);
Philipp Maiera071ee42019-02-21 16:17:32 +0100471 if (ispresent(g_cfg.rx_fixed_payload) and rx_rtp.msg.rtp.data != g_cfg.rx_fixed_payload) {
472 g_stats_rtp.num_pkts_rx_err_payload := g_stats_rtp.num_pkts_rx_err_payload + 1;
473 }
Harald Welte80981642017-12-24 23:59:47 +0100474 if (g_cfg.iuup_mode) {
475 rx_rtp.msg.rtp.data := f_IuUP_Em_rx_decaps(g_iuup_ent, rx_rtp.msg.rtp.data);
476 }
Harald Welte067d66e2017-12-13 17:24:03 +0100477 }
478 [g_rx_enabled] RTCP.receive(tr_rtcp) -> value rx_rtp {
Harald Welte8d3ea0e2018-03-29 08:50:18 +0200479 //log("RX RTCP: ", rx_rtp);
Harald Weltecb8b4272018-03-28 19:57:58 +0200480 g_stats_rtcp.num_pkts_rx := g_stats_rtcp.num_pkts_rx+1;
Harald Welte067d66e2017-12-13 17:24:03 +0100481 }
482
483 /* transmit if timer has expired */
Pau Espin Pedrole38bfe02019-05-17 18:40:43 +0200484 [g_tx_connected] T_transmit.timeout {
Harald Welte067d66e2017-12-13 17:24:03 +0100485 /* send one RTP frame, re-start timer */
Harald Welte3f6f48f2017-12-24 21:48:33 +0100486 f_tx_rtp(g_cfg.tx_fixed_payload);
Harald Welte067d66e2017-12-13 17:24:03 +0100487 T_transmit.start;
Harald Weltecb8b4272018-03-28 19:57:58 +0200488 /* update counters */
489 g_stats_rtp.num_pkts_tx := g_stats_rtp.num_pkts_tx+1;
490 g_stats_rtp.bytes_payload_tx := g_stats_rtp.bytes_payload_tx +
491 lengthof(g_cfg.tx_fixed_payload);
Harald Welte067d66e2017-12-13 17:24:03 +0100492 }
493
494 /* fail on any unexpected messages */
495 [] RTP.receive {
496 setverdict(fail, "Received unexpected type from RTP");
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200497 mtc.stop;
Harald Welte067d66e2017-12-13 17:24:03 +0100498 }
499 [] RTCP.receive {
500 setverdict(fail, "Received unexpected type from RTCP");
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200501 mtc.stop;
Harald Welte067d66e2017-12-13 17:24:03 +0100502 }
503 }
504 }
505}
506
507
508}