blob: 900a196a774ba9e3a8b8479fcac75a44fe750261 [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 *
Pau Espin Pedrol08005d72020-09-08 13:16:14 +02007 * for all of the above, we want to be able to
Harald Welte067d66e2017-12-13 17:24:03 +01008 * * 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));
Oliver Smith216019f2019-06-26 12:21:38 +0200108
109 var boolean g_conn_refuse_expect := false;
110 var boolean g_conn_refuse_received := false;
Harald Welte067d66e2017-12-13 17:24:03 +0100111}
112
113type enumerated RtpemMode {
114 RTPEM_MODE_NONE,
115 RTPEM_MODE_TXONLY,
116 RTPEM_MODE_RXONLY,
117 RTPEM_MODE_BIDIR
118};
119
Harald Weltecb8b4272018-03-28 19:57:58 +0200120type record RtpemStats {
121 /* number of packets transmitted */
122 integer num_pkts_tx,
123 /* number of RTP payload bytes transmitted */
124 integer bytes_payload_tx,
125
126 /* number of packets received */
127 integer num_pkts_rx,
128 /* number of RTP payload bytes received */
129 integer bytes_payload_rx,
130 /* number of packets received out-of-sequence */
131 integer num_pkts_rx_err_seq,
132 /* number of packets received wrong timestamp */
133 integer num_pkts_rx_err_ts,
Philipp Maierc290d722018-07-24 18:51:36 +0200134 /* number of packets received wrong payload type */
135 integer num_pkts_rx_err_pt,
Harald Weltecb8b4272018-03-28 19:57:58 +0200136 /* number of packets received during Rx disable */
Philipp Maiera071ee42019-02-21 16:17:32 +0100137 integer num_pkts_rx_err_disabled,
138 /* number of packets received with mismatching payload */
139 integer num_pkts_rx_err_payload
Harald Weltecb8b4272018-03-28 19:57:58 +0200140}
141
142const RtpemStats c_RtpemStatsReset := {
143 num_pkts_tx := 0,
144 bytes_payload_tx := 0,
145 num_pkts_rx := 0,
146 bytes_payload_rx := 0,
147 num_pkts_rx_err_seq := 0,
148 num_pkts_rx_err_ts := 0,
Philipp Maierc290d722018-07-24 18:51:36 +0200149 num_pkts_rx_err_pt := 0,
Philipp Maiera071ee42019-02-21 16:17:32 +0100150 num_pkts_rx_err_disabled := 0,
151 num_pkts_rx_err_payload := 0
Harald Weltecb8b4272018-03-28 19:57:58 +0200152}
153
Harald Welte3f6f48f2017-12-24 21:48:33 +0100154type record RtpemConfig {
155 INT7b tx_payload_type,
156 integer tx_samplerate_hz,
157 integer tx_duration_ms,
158 BIT32_BO_LAST tx_ssrc,
Harald Welte80981642017-12-24 23:59:47 +0100159 octetstring tx_fixed_payload optional,
Philipp Maiera071ee42019-02-21 16:17:32 +0100160 octetstring rx_fixed_payload optional,
Harald Welte80981642017-12-24 23:59:47 +0100161 boolean iuup_mode,
162 boolean iuup_tx_init
Harald Welte3f6f48f2017-12-24 21:48:33 +0100163};
164
Harald Welte80981642017-12-24 23:59:47 +0100165const RtpemConfig c_RtpemDefaultCfg := {
Harald Welte3f6f48f2017-12-24 21:48:33 +0100166 tx_payload_type := 0,
167 tx_samplerate_hz := 8000,
168 tx_duration_ms := 20,
169 tx_ssrc := '11011110101011011011111011101111'B,
Harald Welte80981642017-12-24 23:59:47 +0100170 tx_fixed_payload := '01020304'O,
Philipp Maiera071ee42019-02-21 16:17:32 +0100171 rx_fixed_payload := '01020304'O,
Harald Welte80981642017-12-24 23:59:47 +0100172 iuup_mode := false,
173 iuup_tx_init := true
Harald Welte3f6f48f2017-12-24 21:48:33 +0100174}
175
Harald Welte067d66e2017-12-13 17:24:03 +0100176signature RTPEM_bind(in HostName local_host, inout PortNumber local_port);
177signature RTPEM_connect(in HostName remote_host, in PortNumber remote_port);
178signature RTPEM_mode(in RtpemMode mode);
Harald Welte3f6f48f2017-12-24 21:48:33 +0100179signature RTPEM_configure(in RtpemConfig cfg);
Harald Weltecb8b4272018-03-28 19:57:58 +0200180signature RTPEM_stats_get(out RtpemStats stats, in boolean rtcp);
Oliver Smith216019f2019-06-26 12:21:38 +0200181signature RTPEM_conn_refuse_expect(in boolean expect);
182signature RTPEM_conn_refuse_received(out boolean received);
Harald Welte067d66e2017-12-13 17:24:03 +0100183
184type port RTPEM_CTRL_PT procedure {
Oliver Smith216019f2019-06-26 12:21:38 +0200185 inout RTPEM_bind, RTPEM_connect, RTPEM_mode, RTPEM_configure, RTPEM_stats_get, RTPEM_conn_refuse_expect,
186 RTPEM_conn_refuse_received;
Harald Welte067d66e2017-12-13 17:24:03 +0100187} with { extension "internal" };
188
Harald Welte1af40332018-03-29 08:50:33 +0200189function f_rtpem_bind(RTPEM_CTRL_PT pt, in HostName local_host, inout PortNumber local_port) {
190 pt.call(RTPEM_bind:{local_host, local_port}) {
191 [] pt.getreply(RTPEM_bind:{local_host, ?}) -> param (local_port) {};
192 }
193}
194function f_rtpem_connect(RTPEM_CTRL_PT pt, in HostName remote_host, in PortNumber remote_port) {
195 pt.call(RTPEM_connect:{remote_host, remote_port}) {
196 [] pt.getreply(RTPEM_connect:{remote_host, remote_port}) {};
197 }
198}
199function f_rtpem_mode(RTPEM_CTRL_PT pt, in RtpemMode mode) {
200 pt.call(RTPEM_mode:{mode}) {
201 [] pt.getreply(RTPEM_mode:{mode}) {};
202 }
203}
204function f_rtpem_configure(RTPEM_CTRL_PT pt, in RtpemConfig cfg) {
205 pt.call(RTPEM_configure:{cfg}) {
206 [] pt.getreply(RTPEM_configure:{cfg}) {};
207 }
208}
209function f_rtpem_stats_get(RTPEM_CTRL_PT pt, boolean rtcp := false) return RtpemStats {
210 var RtpemStats stats;
211 pt.call(RTPEM_stats_get:{-, rtcp}) {
212 [] pt.getreply(RTPEM_stats_get:{?, rtcp}) -> param(stats) {};
213 }
214 return stats;
215}
216
Philipp Maier2321ef92018-06-27 17:52:04 +0200217function f_rtpem_stats_compare_value(integer a, integer b, integer tolerance := 0) return boolean {
218 var integer temp;
Harald Welte5c49ba42018-03-29 08:51:20 +0200219
Philipp Maier2321ef92018-06-27 17:52:04 +0200220 temp := (a - b)
221 if (temp < 0) {
222 temp := -temp;
223 }
224
225 if (temp > tolerance) {
Harald Welte5c49ba42018-03-29 08:51:20 +0200226 return false;
227 }
Philipp Maier2321ef92018-06-27 17:52:04 +0200228
Harald Welte5c49ba42018-03-29 08:51:20 +0200229 return true;
230}
Harald Welte1af40332018-03-29 08:50:33 +0200231
Philipp Maier2321ef92018-06-27 17:52:04 +0200232/* Cross-compare two rtpem-statistics. The transmission statistics on the a side
233 * must match the reception statistics on the other side and vice versa. The
234 * user may also supply a tolerance value (number of packets) when deviations
235 * are acceptable */
236function f_rtpem_stats_compare(RtpemStats a, RtpemStats b, integer tolerance := 0) return boolean {
237 var integer plen;
238
239 log("stats A: ", a);
240 log("stats B: ", b);
241 log("tolerance: ", tolerance, " packets");
242
243 if (f_rtpem_stats_compare_value(a.num_pkts_tx, b.num_pkts_rx, tolerance) == false) {
244 return false;
245 }
246
247 if (f_rtpem_stats_compare_value(a.num_pkts_rx, b.num_pkts_tx, tolerance) == false) {
248 return false;
249 }
250
251 if(a.num_pkts_tx > 0) {
252 plen := a.bytes_payload_tx / a.num_pkts_tx;
253 } else {
254 plen := 0;
255 }
256
257 if (f_rtpem_stats_compare_value(a.bytes_payload_tx, b.bytes_payload_rx, tolerance * plen) == false) {
258 return false;
259 }
260
261 if (f_rtpem_stats_compare_value(a.bytes_payload_rx, b.bytes_payload_tx, tolerance * plen) == false) {
262 return false;
263 }
264
265 return true;
266}
Harald Welte1af40332018-03-29 08:50:33 +0200267
Philipp Maier36291392018-07-25 09:40:44 +0200268/* Check the statistics for general signs of errors. This is a basic general
269 * check that will fit most situations and is intended to be executed by
270 * the testcases as as needed. */
271function f_rtpem_stats_err_check(RtpemStats s) {
272 log("stats: ", s);
273
274 /* Check if there was some activity at either on the RX or on the
275 * TX side, but complete silence would indicate some problem */
276 if (s.num_pkts_tx < 1 and s.num_pkts_rx < 1) {
277 setverdict(fail, "no RTP packet activity detected (packets)");
278 mtc.stop;
279 }
280 if (s.bytes_payload_tx < 1 and s.bytes_payload_rx < 1) {
281 setverdict(fail, "no RTP packet activity detected (bytes)");
282 mtc.stop;
283 }
284
285 /* Check error counters */
286 if (s.num_pkts_rx_err_seq != 0) {
287 setverdict(fail, "RTP packet sequence number errors occurred");
288 mtc.stop;
289 }
290 if (s.num_pkts_rx_err_ts != 0) {
291 setverdict(fail, "RTP packet timestamp errors occurred");
292 mtc.stop;
293 }
294 if (s.num_pkts_rx_err_pt != 0) {
295 setverdict(fail, "RTP packet payload type errors occurred");
296 mtc.stop;
297 }
298 if (s.num_pkts_rx_err_disabled != 0) {
299 setverdict(fail, "RTP packets received while RX was disabled");
300 mtc.stop;
301 }
Philipp Maiera071ee42019-02-21 16:17:32 +0100302 if (s.num_pkts_rx_err_payload != 0) {
303 setverdict(fail, "RTP packets with mismatching payload received");
304 mtc.stop;
305 }
Philipp Maier36291392018-07-25 09:40:44 +0200306}
307
Oliver Smith216019f2019-06-26 12:21:38 +0200308function f_rtpem_conn_refuse_expect(RTPEM_CTRL_PT pt) {
309 pt.call(RTPEM_conn_refuse_expect:{true}) {
310 [] pt.getreply(RTPEM_conn_refuse_expect:{true}) {};
311 }
312}
313
314function f_rtpem_conn_refuse_verify(RTPEM_CTRL_PT pt) {
315 pt.call(RTPEM_conn_refuse_received:{?}) {
316 [] pt.getreply(RTPEM_conn_refuse_received:{true}) {};
317 [] pt.getreply(RTPEM_conn_refuse_received:{false}) {
318 setverdict(fail, "Expected to receive connection refused");
319 };
320 }
321}
322
Harald Welte067d66e2017-12-13 17:24:03 +0100323template PDU_RTP ts_RTP(BIT32_BO_LAST ssrc, INT7b pt, LIN2_BO_LAST seq, uint32_t ts,
324 octetstring payload, BIT1 marker := '0'B) := {
325 version := 2,
326 padding_ind := '0'B,
327 extension_ind := '0'B,
328 CSRC_count := 0,
329 marker_bit := marker,
330 payload_type := pt,
331 sequence_number := seq,
Harald Welte8a4d3952017-12-24 21:30:23 +0100332 time_stamp := int2bit(ts, 32),
Harald Welte067d66e2017-12-13 17:24:03 +0100333 SSRC_id := ssrc,
334 CSRCs := omit,
335 ext_header := omit,
336 data := payload
337}
338
339private function f_tx_rtp(octetstring payload, BIT1 marker := '0'B) runs on RTP_Emulation_CT {
Harald Welte80981642017-12-24 23:59:47 +0100340 if (g_cfg.iuup_mode) {
341 payload := f_IuUP_Em_tx_encap(g_iuup_ent, payload);
342 }
Harald Welte3f6f48f2017-12-24 21:48:33 +0100343 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 +0100344 g_tx_next_ts, payload, marker));
345 RTP.send(t_RTP_Send(g_rtp_conn_id, RTP_messages_union:{rtp:=rtp}));
346 /* increment sequence + timestamp for next transmit */
347 g_tx_next_seq := g_tx_next_seq + 1;
Harald Welte3f6f48f2017-12-24 21:48:33 +0100348 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 +0100349}
350
351function f_main() runs on RTP_Emulation_CT
352{
353 var Result res;
Harald Weltecb8b4272018-03-28 19:57:58 +0200354 var boolean is_rtcp
Harald Welte067d66e2017-12-13 17:24:03 +0100355
Harald Welte3f6f48f2017-12-24 21:48:33 +0100356 timer T_transmit := int2float(g_cfg.tx_duration_ms)/1000.0;
Harald Welte067d66e2017-12-13 17:24:03 +0100357 var RTP_RecvFrom rx_rtp;
Harald Welte3f6f48f2017-12-24 21:48:33 +0100358 var RtpemConfig cfg;
Harald Welte067d66e2017-12-13 17:24:03 +0100359 var template RTP_RecvFrom tr := {
360 connId := ?,
361 remName := ?,
362 remPort := ?,
363 locName := ?,
364 locPort := ?,
365 msg := ?
366 };
367 var template RTP_RecvFrom tr_rtp := tr;
368 var template RTP_RecvFrom tr_rtcp := tr;
Harald Welte067d66e2017-12-13 17:24:03 +0100369 tr_rtp.msg := { rtp := ? };
Harald Welte067d66e2017-12-13 17:24:03 +0100370 tr_rtcp.msg := { rtcp := ? };
371
Oliver Smith216019f2019-06-26 12:21:38 +0200372 var template ASP_Event tr_conn_refuse := {result := { errorCode := ERROR_SOCKET,
373 connId := ?,
374 os_error_code := 111,
375 os_error_text := ? /* "Connection refused" */}};
376
Harald Welte80981642017-12-24 23:59:47 +0100377 g_iuup_ent := valueof(t_IuUP_Entity(g_cfg.iuup_tx_init));
378
Harald Welte067d66e2017-12-13 17:24:03 +0100379 while (true) {
380 alt {
381 /* control procedures (calls) from the user */
382 [] CTRL.getcall(RTPEM_bind:{?,?}) -> param(g_local_host, g_local_port) {
383 if (g_local_port rem 2 == 1) {
384 //CTRL.raise(RTPEM_bind, "Local Port is not an even port number!");
385 log("Local Port is not an even port number!");
386 continue;
387 }
Pau Espin Pedrole38bfe02019-05-17 18:40:43 +0200388
389 g_tx_connected := false; /* will set it back to true upon next connect() call */
Pau Espin Pedrol08005d72020-09-08 13:16:14 +0200390
391 if (g_rtp_conn_id != -1) {
392 res := RTP_CodecPort_CtrlFunct.f_IPL4_close(RTP, g_rtp_conn_id, {udp := {}});
393 g_rtp_conn_id := -1;
394 }
Harald Welte067d66e2017-12-13 17:24:03 +0100395 res := RTP_CodecPort_CtrlFunct.f_IPL4_listen(RTP, g_local_host,
396 g_local_port, {udp:={}});
Harald Welte9220f632018-05-23 20:27:02 +0200397 if (not ispresent(res.connId)) {
398 setverdict(fail, "Could not listen on RTP socket, check your configuration");
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200399 mtc.stop;
Harald Welte9220f632018-05-23 20:27:02 +0200400 }
Harald Welte067d66e2017-12-13 17:24:03 +0100401 g_rtp_conn_id := res.connId;
Harald Welte9774e7a2018-03-29 08:49:38 +0200402 tr_rtp.connId := g_rtp_conn_id;
Pau Espin Pedrol08005d72020-09-08 13:16:14 +0200403
404 if (g_rtcp_conn_id != -1) {
405 res := RTP_CodecPort_CtrlFunct.f_IPL4_close(RTCP, g_rtcp_conn_id, {udp := {}});
406 g_rtcp_conn_id := -1;
407 }
Harald Welte98eb1bf2018-04-02 18:18:44 +0200408 res := RTP_CodecPort_CtrlFunct.f_IPL4_listen(RTCP, g_local_host,
Harald Welte067d66e2017-12-13 17:24:03 +0100409 g_local_port+1, {udp:={}});
Harald Welte9220f632018-05-23 20:27:02 +0200410 if (not ispresent(res.connId)) {
411 setverdict(fail, "Could not listen on RTCP socket, check your configuration");
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200412 mtc.stop;
Harald Welte9220f632018-05-23 20:27:02 +0200413 }
Harald Welte067d66e2017-12-13 17:24:03 +0100414 g_rtcp_conn_id := res.connId;
Harald Welte9774e7a2018-03-29 08:49:38 +0200415 tr_rtcp.connId := g_rtcp_conn_id;
Harald Welte067d66e2017-12-13 17:24:03 +0100416 CTRL.reply(RTPEM_bind:{g_local_host, g_local_port});
417 }
418 [] CTRL.getcall(RTPEM_connect:{?,?}) -> param (g_remote_host, g_remote_port) {
419 if (g_remote_port rem 2 == 1) {
420 //CTRL.raise(RTPEM_connect, "Remote Port is not an even number!");
421 log("Remote Port is not an even number!");
422 continue;
423 }
424 res := RTP_CodecPort_CtrlFunct.f_IPL4_connect(RTP, g_remote_host,
425 g_remote_port,
426 g_local_host, g_local_port,
427 g_rtp_conn_id, {udp:={}});
Harald Welte9220f632018-05-23 20:27:02 +0200428 if (not ispresent(res.connId)) {
429 setverdict(fail, "Could not connect to RTP socket, check your configuration");
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200430 mtc.stop;
Harald Welte9220f632018-05-23 20:27:02 +0200431 }
Harald Welte067d66e2017-12-13 17:24:03 +0100432 res := RTP_CodecPort_CtrlFunct.f_IPL4_connect(RTCP, g_remote_host,
433 g_remote_port+1,
434 g_local_host, g_local_port+1,
435 g_rtcp_conn_id, {udp:={}});
Harald Welte9220f632018-05-23 20:27:02 +0200436 if (not ispresent(res.connId)) {
437 setverdict(fail, "Could not connect to RTCP socket, check your configuration");
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200438 mtc.stop;
Harald Welte9220f632018-05-23 20:27:02 +0200439 }
Pau Espin Pedrole38bfe02019-05-17 18:40:43 +0200440 g_tx_connected := true;
Harald Welte067d66e2017-12-13 17:24:03 +0100441 CTRL.reply(RTPEM_connect:{g_remote_host, g_remote_port});
442 }
443 [] CTRL.getcall(RTPEM_mode:{RTPEM_MODE_NONE}) {
444 T_transmit.stop;
445 g_rx_enabled := false;
Harald Welte80981642017-12-24 23:59:47 +0100446 CTRL.reply(RTPEM_mode:{RTPEM_MODE_NONE});
Harald Welte067d66e2017-12-13 17:24:03 +0100447 }
448 [] CTRL.getcall(RTPEM_mode:{RTPEM_MODE_TXONLY}) {
449 /* start transmit timer */
450 T_transmit.start;
451 g_rx_enabled := false;
Harald Welte80981642017-12-24 23:59:47 +0100452 CTRL.reply(RTPEM_mode:{RTPEM_MODE_TXONLY});
Harald Welte067d66e2017-12-13 17:24:03 +0100453 }
454 [] CTRL.getcall(RTPEM_mode:{RTPEM_MODE_RXONLY}) {
455
456 T_transmit.stop;
457 if (g_rx_enabled == false) {
458 /* flush queues */
459 RTP.clear;
460 RTCP.clear;
461 g_rx_enabled := true;
462 }
Harald Welte80981642017-12-24 23:59:47 +0100463 CTRL.reply(RTPEM_mode:{RTPEM_MODE_RXONLY});
Harald Welte067d66e2017-12-13 17:24:03 +0100464 }
465 [] CTRL.getcall(RTPEM_mode:{RTPEM_MODE_BIDIR}) {
466 T_transmit.start;
467 if (g_rx_enabled == false) {
468 /* flush queues */
469 RTP.clear;
470 RTCP.clear;
471 g_rx_enabled := true;
472 }
Harald Welte80981642017-12-24 23:59:47 +0100473 CTRL.reply(RTPEM_mode:{RTPEM_MODE_BIDIR});
Harald Welte067d66e2017-12-13 17:24:03 +0100474 }
Harald Welte3f6f48f2017-12-24 21:48:33 +0100475 [] CTRL.getcall(RTPEM_configure:{?}) -> param (cfg) {
476 g_cfg := cfg;
Harald Welte80981642017-12-24 23:59:47 +0100477 g_iuup_ent.cfg.active_init := g_cfg.iuup_tx_init;
478 CTRL.reply(RTPEM_configure:{cfg});
Harald Welte3f6f48f2017-12-24 21:48:33 +0100479 }
Harald Weltecb8b4272018-03-28 19:57:58 +0200480 [] CTRL.getcall(RTPEM_stats_get:{?, ?}) -> param (is_rtcp) {
481 if (is_rtcp) {
482 CTRL.reply(RTPEM_stats_get:{g_stats_rtcp, is_rtcp});
483 } else {
484 CTRL.reply(RTPEM_stats_get:{g_stats_rtp, is_rtcp});
485 }
486 }
Oliver Smith216019f2019-06-26 12:21:38 +0200487 [] CTRL.getcall(RTPEM_conn_refuse_expect:{?}) -> param(g_conn_refuse_expect) {
488 CTRL.reply(RTPEM_conn_refuse_expect:{g_conn_refuse_expect});
489 }
490 [] CTRL.getcall(RTPEM_conn_refuse_received:{?}) {
491 CTRL.reply(RTPEM_conn_refuse_received:{g_conn_refuse_received});
492 }
Harald Weltecb8b4272018-03-28 19:57:58 +0200493
494
495 /* simply ignore any RTTP/RTP if receiver not enabled */
496 [g_rx_enabled==false] RTP.receive(tr_rtp) {
497 g_stats_rtp.num_pkts_rx_err_disabled := g_stats_rtp.num_pkts_rx_err_disabled+1;
498 }
Harald Welte98eb1bf2018-04-02 18:18:44 +0200499 [g_rx_enabled==false] RTCP.receive(tr_rtcp) {
Harald Weltecb8b4272018-03-28 19:57:58 +0200500 g_stats_rtcp.num_pkts_rx_err_disabled := g_stats_rtcp.num_pkts_rx_err_disabled+1;
501 }
Harald Welte067d66e2017-12-13 17:24:03 +0100502
503 /* process received RTCP/RTP if receiver enabled */
504 [g_rx_enabled] RTP.receive(tr_rtp) -> value rx_rtp {
Harald Weltecb8b4272018-03-28 19:57:58 +0200505 /* increment counters */
Philipp Maierc290d722018-07-24 18:51:36 +0200506 if (rx_rtp.msg.rtp.payload_type != g_cfg.tx_payload_type) {
507 g_stats_rtp.num_pkts_rx_err_pt := g_stats_rtp.num_pkts_rx_err_pt+1;
508 }
Harald Weltecb8b4272018-03-28 19:57:58 +0200509 g_stats_rtp.num_pkts_rx := g_stats_rtp.num_pkts_rx+1;
510 g_stats_rtp.bytes_payload_rx := g_stats_rtp.bytes_payload_rx +
511 lengthof(rx_rtp.msg.rtp.data);
Philipp Maiera071ee42019-02-21 16:17:32 +0100512 if (ispresent(g_cfg.rx_fixed_payload) and rx_rtp.msg.rtp.data != g_cfg.rx_fixed_payload) {
513 g_stats_rtp.num_pkts_rx_err_payload := g_stats_rtp.num_pkts_rx_err_payload + 1;
514 }
Harald Welte80981642017-12-24 23:59:47 +0100515 if (g_cfg.iuup_mode) {
516 rx_rtp.msg.rtp.data := f_IuUP_Em_rx_decaps(g_iuup_ent, rx_rtp.msg.rtp.data);
517 }
Harald Welte067d66e2017-12-13 17:24:03 +0100518 }
519 [g_rx_enabled] RTCP.receive(tr_rtcp) -> value rx_rtp {
Harald Welte8d3ea0e2018-03-29 08:50:18 +0200520 //log("RX RTCP: ", rx_rtp);
Harald Weltecb8b4272018-03-28 19:57:58 +0200521 g_stats_rtcp.num_pkts_rx := g_stats_rtcp.num_pkts_rx+1;
Harald Welte067d66e2017-12-13 17:24:03 +0100522 }
523
524 /* transmit if timer has expired */
Pau Espin Pedrole38bfe02019-05-17 18:40:43 +0200525 [g_tx_connected] T_transmit.timeout {
Harald Welte067d66e2017-12-13 17:24:03 +0100526 /* send one RTP frame, re-start timer */
Harald Welte3f6f48f2017-12-24 21:48:33 +0100527 f_tx_rtp(g_cfg.tx_fixed_payload);
Harald Welte067d66e2017-12-13 17:24:03 +0100528 T_transmit.start;
Harald Weltecb8b4272018-03-28 19:57:58 +0200529 /* update counters */
530 g_stats_rtp.num_pkts_tx := g_stats_rtp.num_pkts_tx+1;
531 g_stats_rtp.bytes_payload_tx := g_stats_rtp.bytes_payload_tx +
532 lengthof(g_cfg.tx_fixed_payload);
Harald Welte067d66e2017-12-13 17:24:03 +0100533 }
534
Oliver Smith216019f2019-06-26 12:21:38 +0200535 /* connection refused */
536 [g_conn_refuse_expect] RTP.receive(tr_conn_refuse) {
537 log("Connection refused (expected)");
538 g_conn_refuse_received := true;
539 }
540 [not g_conn_refuse_expect] RTP.receive(tr_conn_refuse) {
541 setverdict(fail, "Connection refused (unexpected)");
542 mtc.stop;
543 }
544
Harald Welte067d66e2017-12-13 17:24:03 +0100545 /* fail on any unexpected messages */
546 [] RTP.receive {
547 setverdict(fail, "Received unexpected type from RTP");
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200548 mtc.stop;
Harald Welte067d66e2017-12-13 17:24:03 +0100549 }
550 [] RTCP.receive {
551 setverdict(fail, "Received unexpected type from RTCP");
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200552 mtc.stop;
Harald Welte067d66e2017-12-13 17:24:03 +0100553 }
554 }
555 }
556}
557
558
559}