MGCP_Test: add tests to verify actual RTP flows

The test coverage of the RTP aspects of the MGW is currently very
minima. Lets add a few more testcase to verify RTP behaves as
expected in various situations.

- Add testcase TC_one_crcx_receive_only_rtp:
  Test recvonly mode of the MGW. All packets must be absorbed by
  the MGW, no packets must come back.

- Add testcase TC_one_crcx_loopback_rtp:
  Test loopback mode of the MGW. All packet sent to the MGW must
  come back.

- Add testcase TC_two_crcx_and_rtp_bidir:
  We already test unidirectional transmissions. This test does
  the same as TC_two_crcx_and_rtp but for both directions.

- Add testcase TC_two_crcx_mdcx_and_rtp:
  Simulate a typical behaviour of a normal call. First create
  two half open connections and complete the connections later
  using MDCX.

- Add testcase TC_two_crcx_and_unsolicited_rtp:
  Test what happens when a RTP packets from rogue source are mixed
  into the RTP stream.

- Add testcase TC_two_crcx_and_one_mdcx_rtp_ho:
  Test a typical handover situation. An existing connection is
  handovered to another source on one end but the old source will
  keep transmitting for a while.

Change-Id: I556a6efff0e74aab897bd8165200eec36e46629f
Closes: OS#2703
diff --git a/library/RTP_Emulation.ttcn b/library/RTP_Emulation.ttcn
index 20e4299..475b478 100644
--- a/library/RTP_Emulation.ttcn
+++ b/library/RTP_Emulation.ttcn
@@ -188,19 +188,56 @@
 	return stats;
 }
 
-function f_rtpem_stats_compare(RtpemStats a, RtpemStats b) return boolean {
-	log("stats A: ", a);
-	log("stats B: ", b);
+function f_rtpem_stats_compare_value(integer a, integer b, integer tolerance := 0) return boolean {
+	var integer temp;
 
-	if (a.num_pkts_tx != b.num_pkts_rx or
-	    a.num_pkts_rx != b.num_pkts_tx or
-	    a.bytes_payload_tx != b.bytes_payload_rx or
-	    a.bytes_payload_rx != b.bytes_payload_tx) {
+	temp := (a - b)
+	if (temp < 0) {
+		temp := -temp;
+	}
+
+	if (temp > tolerance) {
 		return false;
 	}
+
 	return true;
 }
 
+/* Cross-compare two rtpem-statistics. The transmission statistics on the a side
+ * must match the reception statistics on the other side and vice versa. The
+ * user may also supply a tolerance value (number of packets) when deviations
+ * are acceptable */
+function f_rtpem_stats_compare(RtpemStats a, RtpemStats b, integer tolerance := 0) return boolean {
+	var integer plen;
+
+	log("stats A: ", a);
+	log("stats B: ", b);
+	log("tolerance: ", tolerance, " packets");
+
+	if (f_rtpem_stats_compare_value(a.num_pkts_tx, b.num_pkts_rx, tolerance) == false) {
+		return false;
+	}
+
+	if (f_rtpem_stats_compare_value(a.num_pkts_rx, b.num_pkts_tx, tolerance) == false) {
+		return false;
+	}
+
+	if(a.num_pkts_tx > 0) {
+		plen := a.bytes_payload_tx / a.num_pkts_tx;
+	} else {
+		plen := 0;
+	}
+
+	if (f_rtpem_stats_compare_value(a.bytes_payload_tx, b.bytes_payload_rx, tolerance * plen) == false) {
+		return false;
+	}
+
+	if (f_rtpem_stats_compare_value(a.bytes_payload_rx, b.bytes_payload_tx, tolerance * plen) == false) {
+		return false;
+	}
+
+	return true;
+}
 
 template PDU_RTP ts_RTP(BIT32_BO_LAST ssrc, INT7b pt, LIN2_BO_LAST seq, uint32_t ts,
 			octetstring payload, BIT1 marker := '0'B) := {