bts: Implement testcase for RR response frame loss

Test is implemented as BTS_Tests_LAPDm.TC_rr_response_frame_loss()

Change-Id: I32340fff6666fee0ebfb9b31b55e0982d0d917a1
diff --git a/bts/BTS_Tests_LAPDm.ttcn b/bts/BTS_Tests_LAPDm.ttcn
index 3c39a5a..bf359f2 100644
--- a/bts/BTS_Tests_LAPDm.ttcn
+++ b/bts/BTS_Tests_LAPDm.ttcn
@@ -942,6 +942,63 @@
 	f_testmatrix_each_chan(pars, refers(f_TC_t200_n200));
 }
 
+/* Ensure BTS repeats RR frame after retransmitting I frame to emulate RR loss;
+   Inspired by TS 51.010-1 25.2.4.3 */
+private function f_TC_rr_response_frame_loss(charstring id) runs on ConnHdlr {
+	var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
+	var integer sapi := link_id.sapi;
+	var boolean is_sacch := false;
+	if (link_id.c == SACCH) {
+		is_sacch := true;
+	}
+	timer T := 3.0;
+	var default d;
+
+	fp_common_init();
+
+	/* some common altstep for meas res and other background noise */
+	d := activate(as_ignore_background(true));
+	RSL.clear;
+	LAPDM.clear;
+
+	f_establish_mo(link_id);
+
+	var octetstring l3_mo := f_rnd_octstring(10);
+	/* Send an I frame to the BTS: SAPI = 0, C = 1, P = 0, M = 0, L = 3, N(S) = 0, N(R) = 0 */
+	LAPDM.send(t_PH_DATA(0, is_sacch, ts_LAPDm_I(sapi, c_r:=cr_MO_CMD, p:=false, nr:=0, ns:=0,
+						     l3:=l3_mo)));
+	RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3_mo));
+	/* SAPI = 0, R = 1, F = 0, M = 0, L = 0, N(R) = 1. */
+	LAPDM.receive(t_PH_DATA(0, is_sacch, tr_LAPDm_RR(sapi, c_r:=cr_MT_RSP, p:=false, nr:=1)));
+
+	/* Re-send I frame: SAPI = 0, C = 1, P = 1, M = 0, L = 3, N(S) = 0, N(R) = 0. */
+	LAPDM.send(t_PH_DATA(0, is_sacch, ts_LAPDm_I(sapi, c_r:=cr_MO_CMD, p:=true, nr:=0, ns:=0,
+						     l3:=l3_mo)));
+
+	T.start;
+	alt {
+	/* RR: SAPI = 0, R = 1, F = 1, M = 0, L = 0, N(R) = 1. */
+	[] LAPDM.receive(t_PH_DATA(0, is_sacch, tr_LAPDm_RR(sapi, c_r:=cr_MT_RSP, p:=true, nr:=1))) {
+		setverdict(pass);
+		}
+	/* REJ: SAPI = 0, R = 1, F = 1, M = 0, L = 0, N(R) = 1. */
+	[] LAPDM.receive(t_PH_DATA(0, is_sacch, tr_LAPDm_REJ(sapi, c_r:=cr_MT_RSP, p:=true, nr:=1))) {
+		setverdict(pass);
+		}
+	[] T.timeout {
+		setverdict(fail, "Timeout waiting for RR or REJ");
+		}
+	}
+
+	deactivate(d);
+
+	fp_common_fini();
+}
+testcase TC_rr_response_frame_loss() runs on test_CT {
+	var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
+	f_testmatrix_each_chan(pars, refers(f_TC_rr_response_frame_loss));
+}
+
 control {
 	execute(TC_foo());
 	execute(TC_sabm_ua_dcch_sapi0());
@@ -959,6 +1016,7 @@
 	execute(TC_segm_concat_dcch());
 	execute(TC_segm_concat_sacch());
 	execute(TC_t200_n200());
+	execute(TC_rr_response_frame_loss());
 }
 
 }