mgw: Introduce tests TC_two_crcx_mdcx_and_iuup_(rtp_)mdcx_recvonly

Change-Id: I34d47d0cdde855900798e4cb3efd26af22f5b049
diff --git a/mgw/MGCP_Test.ttcn b/mgw/MGCP_Test.ttcn
index ad564c1..b75fd69 100644
--- a/mgw/MGCP_Test.ttcn
+++ b/mgw/MGCP_Test.ttcn
@@ -10,6 +10,7 @@
  */
 
 module MGCP_Test {
+	import from Misc_Helpers all;
 	import from Osmocom_Types all;
 	import from MGCP_Types all;
 	import from MGCP_Templates all;
@@ -2955,6 +2956,80 @@
 					   mp_local_ipv4, mp_remote_ipv4);
 	}
 
+	/* Test that once IuUP->RTP has been set up, if the RTP/IuUP conn is set
+	 * as "recvonly", no more RTP/IuUP packets get out of the MGW. */
+	function f_tc_two_crcx_mdcx_and_iuup_mdcx_recvonly(charstring local_ip_a, charstring remote_ip_a,
+							       IuUP_RabFlowCombinationList rfcl_a,
+							       charstring local_ip_b, charstring remote_ip_b) runs on dummy_CT {
+		var RtpFlowData flow[2];
+		var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "2@" & c_mgw_domain;
+		var MgcpCallId call_id := '1227'H;
+		var RtpemStats stats[2];
+
+		f_init(ep);
+
+		/* Create the first connection in receive only mode (RNC side, IuUP-Init active) */
+		flow[0] := valueof(t_RtpFlow(local_ip_a, remote_ip_a, 96, "VND.3GPP.IUFP/16000"));
+		flow[0].em.portnr := 10000;
+		flow[0].rtp_cfg := c_RtpemDefaultCfg;
+		flow[0].rtp_cfg.rx_payloads[0].payload_type := flow[0].codec_descr[0].pt;
+		flow[0].rtp_cfg.tx_payloads[0].payload_type := flow[0].codec_descr[0].pt;
+		flow[0].rtp_cfg.iuup_mode := true;
+		flow[0].rtp_cfg.iuup_cfg.active_init := true;
+		flow[0].rtp_cfg.iuup_cfg.rab_flow_combs := rfcl_a;
+
+		/* Create the second connection. This connection will be also
+		 * in receive only mode (CN side, IuUP-Init passive) */
+		flow[1] := valueof(t_RtpFlow(local_ip_b, remote_ip_b, 96, "VND.3GPP.IUFP/16000"));
+		flow[1].em.portnr := 20000;
+		flow[1].rtp_cfg := c_RtpemDefaultCfg;
+		flow[1].rtp_cfg.rx_payloads[0].payload_type := flow[1].codec_descr[0].pt;
+		flow[1].rtp_cfg.tx_payloads[0].payload_type := flow[1].codec_descr[0].pt;
+		flow[1].rtp_cfg.iuup_mode := true;
+		flow[1].rtp_cfg.iuup_cfg.active_init := false;
+
+		f_two_crcx_mdcx_data_transfer(ep, call_id, flow[0], flow[1], false);
+
+		/* Now validate we don't receive more RTP packets after setting it to recvonly: */
+		f_rtpem_mode(RTPEM[1], RTPEM_MODE_RXONLY);
+		f_flow_modify(RTPEM[1], ep, call_id, "recvonly", flow[1]);
+		f_sleep(0.5);
+		stats[0] := f_rtpem_stats_get(RTPEM[1]);
+		f_sleep(0.5);
+		stats[1] := f_rtpem_stats_get(RTPEM[1]);
+		if (stats[1].num_pkts_rx > stats[0].num_pkts_rx) {
+			Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
+						log2str("received ", stats[1].num_pkts_rx - stats[0].num_pkts_rx, " RTP packets from MGW on recvonly connection 1"));
+		}
+
+		/* Now do the same on the IuUP port: */
+		f_rtpem_mode(RTPEM[0], RTPEM_MODE_RXONLY);
+		f_rtpem_mode(RTPEM[1], RTPEM_MODE_TXONLY);
+		f_flow_modify(RTPEM[0], ep, call_id, "recvonly", flow[0]);
+		f_sleep(0.5);
+		stats[0] := f_rtpem_stats_get(RTPEM[0]);
+		f_sleep(0.5);
+		stats[1] := f_rtpem_stats_get(RTPEM[0]);
+		if (stats[1].num_pkts_rx > stats[0].num_pkts_rx) {
+			Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
+						log2str("received ", stats[1].num_pkts_rx - stats[0].num_pkts_rx, " IuUP packets from MGW on recvonly connection 1"));
+		}
+
+		/* Tear down */
+		f_flow_delete(RTPEM[0]);
+		f_flow_delete(RTPEM[1], ep, call_id);
+		setverdict(pass);
+	}
+	testcase TC_two_crcx_mdcx_and_iuup_mdcx_recvonly() runs on dummy_CT {
+		var template (value) IuUP_RabFlowCombinationList rfcl := {
+			t_IuUP_RFC_AMR_12_2(0),
+			t_IuUP_RFC_AMR_SID(1),
+			t_IuUP_RFC_AMR_NO_DATA(2)
+		};
+		f_tc_two_crcx_mdcx_and_iuup_mdcx_recvonly(mp_local_ipv4, mp_remote_ipv4, valueof(rfcl),
+							  mp_local_ipv4, mp_remote_ipv4);
+	}
+
 	/* create two local emulations (1 RTP, 1 RTP+IuUP) and pass data in both directions */
 	function f_tc_two_crcx_mdcx_and_iuup_rtp(charstring local_ip_a, charstring remote_ip_a,
 					    IuUP_RabFlowCombinationList rfcl_a,
@@ -3013,6 +3088,86 @@
 					   mp_local_ipv4, mp_remote_ipv4);
 	}
 
+	/* Test that once IuUP->RTP has been set up, if the RTP/IuUP conn is set
+	 * as "recvonly", no more RTP/IuUP packets get out of the MGW. */
+	function f_tc_two_crcx_mdcx_and_iuup_rtp_mdcx_recvonly(charstring local_ip_a, charstring remote_ip_a,
+							       IuUP_RabFlowCombinationList rfcl_a,
+							       charstring local_ip_b, charstring remote_ip_b) runs on dummy_CT {
+		var RtpFlowData flow[2];
+		var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "2@" & c_mgw_domain;
+		var MgcpCallId call_id := '1227'H;
+		var RtpemStats stats[2];
+
+		f_init(ep);
+
+		/* Create the first connection in receive only mode (RNC side, IuUP-Init active) */
+		flow[0] := valueof(t_RtpFlow(local_ip_a, remote_ip_a, 96, "VND.3GPP.IUFP/16000"));
+		flow[0].em.portnr := 10000;
+		flow[0].rtp_cfg := c_RtpemDefaultCfg;
+		flow[0].rtp_cfg.tx_payloads[0].payload_type := flow[0].codec_descr[0].pt;
+		flow[0].rtp_cfg.rx_payloads[0].payload_type := flow[0].codec_descr[0].pt;
+		flow[0].rtp_cfg.tx_payloads[0].fixed_payload := '4f28959ffeb80181f5c4e83d176c897b4a4e333298333419a493ca63ded6e0'O;
+		/* flow[1].rtp_cfg.rx_payloads[0].fixed_payload converted AMR-BE-RTP->AMR-IUUP*/
+		flow[0].rtp_cfg.rx_payloads[0].fixed_payload := '08556d944c71a1a081e7ead204244480000ecd82b81118000097c4794e7740'O;
+		flow[0].rtp_cfg.iuup_mode := true;
+		flow[0].rtp_cfg.iuup_cfg.active_init := true;
+		flow[0].rtp_cfg.iuup_cfg.rab_flow_combs := rfcl_a;
+
+		/* Create the second connection. This connection will be also
+		 * in receive only mode (CN side, regular RTP) */
+		flow[1] := valueof(t_RtpFlow(local_ip_b, remote_ip_b, 112, "AMR/8000"));
+		flow[1].em.portnr := 20000;
+		flow[1].rtp_cfg := c_RtpemDefaultCfg;
+		flow[1].rtp_cfg.tx_payloads[0].payload_type := flow[1].codec_descr[0].pt;
+		flow[1].rtp_cfg.rx_payloads[0].payload_type := flow[1].codec_descr[0].pt;
+		flow[1].rtp_cfg.tx_payloads[0].fixed_payload := '0382155b65131c68682079fab4810911200003b360ae0446000025f11e539dd0'O;
+		/* flow[0].rtp_cfg.rx_payloads[0].fixed_payload converted AMR-IuUP->AMR-BE-RTP*/
+		flow[1].rtp_cfg.rx_payloads[0].fixed_payload := 'f3d3ca2567ffae00607d713a0f45db225ed2938ccca60ccd066924f298f7b5b8'O;
+		flow[1].rtp_cfg.iuup_mode := false;
+
+		f_two_crcx_mdcx_data_transfer(ep, call_id, flow[0], flow[1], false);
+
+		/* Now validate we don't receive more RTP packets after setting it to recvonly: */
+		f_rtpem_mode(RTPEM[1], RTPEM_MODE_RXONLY);
+		f_flow_modify(RTPEM[1], ep, call_id, "recvonly", flow[1]);
+		f_sleep(0.5);
+		stats[0] := f_rtpem_stats_get(RTPEM[1]);
+		f_sleep(0.5);
+		stats[1] := f_rtpem_stats_get(RTPEM[1]);
+		if (stats[1].num_pkts_rx > stats[0].num_pkts_rx) {
+			Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
+						log2str("received ", stats[1].num_pkts_rx - stats[0].num_pkts_rx, " RTP packets from MGW on recvonly connection 1"));
+		}
+
+		/* Now do the same on the IuUP port: */
+		f_rtpem_mode(RTPEM[0], RTPEM_MODE_RXONLY);
+		f_flow_modify(RTPEM[0], ep, call_id, "recvonly", flow[0]);
+		f_rtpem_mode(RTPEM[1], RTPEM_MODE_TXONLY);
+		f_flow_modify(RTPEM[1], ep, call_id, "sendrecv", flow[1]);
+		f_sleep(0.5);
+		stats[0] := f_rtpem_stats_get(RTPEM[0]);
+		f_sleep(0.5);
+		stats[1] := f_rtpem_stats_get(RTPEM[0]);
+		if (stats[1].num_pkts_rx > stats[0].num_pkts_rx) {
+			Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
+						log2str("received ", stats[1].num_pkts_rx - stats[0].num_pkts_rx, " IuUP packets from MGW on recvonly connection 1"));
+		}
+
+		/* Tear down */
+		f_flow_delete(RTPEM[0]);
+		f_flow_delete(RTPEM[1], ep, call_id);
+		setverdict(pass);
+	}
+	testcase TC_two_crcx_mdcx_and_iuup_rtp_mdcx_recvonly() runs on dummy_CT {
+		var template (value) IuUP_RabFlowCombinationList rfcl := {
+			t_IuUP_RFC_AMR_12_2(0),
+			t_IuUP_RFC_AMR_SID(1),
+			t_IuUP_RFC_AMR_NO_DATA(2)
+		};
+		f_tc_two_crcx_mdcx_and_iuup_rtp_mdcx_recvonly(mp_local_ipv4, mp_remote_ipv4, valueof(rfcl),
+							      mp_local_ipv4, mp_remote_ipv4);
+	}
+
 	control {
 		execute(TC_selftest());
 		execute(TC_auep_null());
@@ -3099,8 +3254,10 @@
 
 		execute(TC_two_crcx_mdcx_and_iuup());
 		execute(TC_two_crcx_mdcx_and_iuup_rfci_unordered());
+		execute(TC_two_crcx_mdcx_and_iuup_mdcx_recvonly());
 		execute(TC_two_crcx_mdcx_and_iuup_rtp());
 		execute(TC_two_crcx_mdcx_and_iuup_rtp_rfci_unordered());
+		execute(TC_two_crcx_mdcx_and_iuup_rtp_mdcx_recvonly());
 
 		execute(TC_two_crcx_mdcx_and_rtp_clearmode());