bsc: Introduce test TC_srvcc_eutran_to_geran_ho_out

Related: SYS#5337
Change-Id: Id34924bbf0a5cf08b4b6f5ea56a10cef6b69c877
diff --git a/bsc/BSC_Tests.ttcn b/bsc/BSC_Tests.ttcn
index 16afbf8..bc243b1 100644
--- a/bsc/BSC_Tests.ttcn
+++ b/bsc/BSC_Tests.ttcn
@@ -4767,19 +4767,12 @@
 	BSSAP.receive(tr_BSSMAP_ClearComplete);
 }
 
-private function f_tc_ho_out_of_this_bsc(charstring id) runs on MSC_ConnHdlr {
-	g_pars := f_gen_test_hdlr_pars();
-
-	var PDU_BSSAP ass_req := f_gen_ass_req();
-	ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
-	ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
-	var template PDU_BSSAP exp_compl := f_gen_exp_compl();
-	f_establish_fully(ass_req, exp_compl);
+private function f_ho_out_of_this_bsc(template (omit) BSSMAP_oldToNewBSSIEs exp_oldToNewBSSIEs := omit) runs on MSC_ConnHdlr {
 
 	f_bts_0_cfg(BSCVTY, {"neighbor lac 99 arfcn 123 bsic any"});
 	f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
 
-	BSSAP.receive(tr_BSSMAP_HandoverRequired);
+	BSSAP.receive(tr_BSSMAP_HandoverRequired(exp_oldToNewBSSIEs));
 
 	f_sleep(0.5);
 	/* The MSC negotiates Handover Request and Handover Request Ack with
@@ -4820,6 +4813,17 @@
 
 	f_expect_dlcx_conns();
 	setverdict(pass);
+}
+
+private function f_tc_ho_out_of_this_bsc(charstring id) runs on MSC_ConnHdlr {
+	g_pars := f_gen_test_hdlr_pars();
+	var PDU_BSSAP ass_req := f_gen_ass_req();
+	ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
+	ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
+	var template PDU_BSSAP exp_compl := f_gen_exp_compl();
+	f_establish_fully(ass_req, exp_compl);
+
+	f_ho_out_of_this_bsc();
 	f_sleep(1.0);
 }
 testcase TC_ho_out_of_this_bsc() runs on test_CT {
@@ -5105,14 +5109,12 @@
 	f_shutdown_helper();
 }
 
-private function f_tc_ho_into_this_bsc(charstring id) runs on MSC_ConnHdlr {
+private function f_ho_into_this_bsc(charstring id, template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit) runs on MSC_ConnHdlr {
 	/* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
 	 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
 	 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
 	 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
 	 * before we get started. */
-	var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit;
-	var template PDU_ML3_NW_MS exp_rr_rel_tmpl := tr_RRM_RR_RELEASE;
 	var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
 	f_rslem_register(0, new_chan_nr);
 	g_chan_nr := new_chan_nr;
@@ -5122,11 +5124,6 @@
 	f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
 	activate(as_Media());
 
-	if (not istemplatekind(g_pars.last_used_eutran_plmn, "omit")) {
-		oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
-		exp_rr_rel_tmpl := tr_RRM_RR_RELEASE_CellSelectInd;
-	}
-
 	BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
 				     f_gen_handover_req(aoip_tla := g_pars.host_aoip_tla,
 							oldToNewBSSIEs := oldToNewBSSIEs)));
@@ -5174,7 +5171,17 @@
 				enc_PDU_ML3_MS_NW(l3_tx)));
 
 	BSSAP.receive(tr_BSSMAP_HandoverComplete);
+	setverdict(pass);
+}
 
+private function f_tc_ho_into_this_bsc(charstring id) runs on MSC_ConnHdlr {
+	var template PDU_ML3_NW_MS exp_rr_rel_tmpl := tr_RRM_RR_RELEASE;
+	var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit;
+	if (not istemplatekind(g_pars.last_used_eutran_plmn, "omit")) {
+		oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
+		exp_rr_rel_tmpl := tr_RRM_RR_RELEASE_CellSelectInd;
+	}
+	f_ho_into_this_bsc(id, oldToNewBSSIEs);
 	f_perform_clear(RSL, exp_rr_rel_tmpl);
 	setverdict(pass);
 }
@@ -5213,7 +5220,7 @@
 }
 
 /* Similar to TC_ho_into_this_bsc, but when in SRVCC, HO Req contains "Old BSS
-   to New BSS Information" IE with "Last Used E-UTRAN PLMN Id", whihch, when the
+   to New BSS Information" IE with "Last Used E-UTRAN PLMN Id", which, when the
    channel is later released (RR CHannel Release), should trigger inclusion of
    IE "Cell Selection Indicator after Release of all TCH and SDCCH" with E-UTRAN
    neighbors. */
@@ -5224,6 +5231,43 @@
 	f_shutdown_helper();
 }
 
+private function f_tc_srvcc_eutran_to_geran_ho_out(charstring id) runs on MSC_ConnHdlr {
+	var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs;
+	oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
+	f_ho_into_this_bsc(id, oldToNewBSSIEs);
+	f_ho_out_of_this_bsc(oldToNewBSSIEs);
+	setverdict(pass);
+}
+/* First, HO into BSC from EUTRAN (SRVCC): HO Request contains "Old BSS to New
+   BSS Information" IE with "Last Used E-UTRAN PLMN Id".
+   Second, HO to another BSC: HO Required contains "Old BSS to New BSS Information"
+   IE with "Last Used E-UTRAN PLMN Id" from first step. */
+testcase TC_srvcc_eutran_to_geran_ho_out() runs on test_CT {
+	var MSC_ConnHdlr vc_conn;
+	var TestHdlrParams pars := f_gen_test_hdlr_pars();
+
+	f_init(1, true);
+	f_sleep(1.0);
+
+	f_ctrs_bsc_and_bts_init();
+
+	pars.last_used_eutran_plmn := '323454'O;
+	pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
+	pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
+
+	vc_conn := f_start_handler(refers(f_tc_srvcc_eutran_to_geran_ho_out), pars);
+	vc_conn.done;
+
+	f_ctrs_bsc_and_bts_add(0, "handover:attempted", 2);
+	f_ctrs_bsc_and_bts_add(0, "handover:completed", 2);
+	f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted", 1);
+	f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:completed", 1);
+	f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted", 1);
+	f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:completed", 1);
+	f_ctrs_bsc_and_bts_verify();
+	f_shutdown_helper();
+}
+
 private function f_tc_ho_in_fail_msc_clears(charstring id) runs on MSC_ConnHdlr {
 	var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
 	f_rslem_register(0, new_chan_nr);
@@ -8673,6 +8717,7 @@
 		execute( TC_ho_into_this_bsc_tla_v6() );
 	}
 	execute( TC_srvcc_eutran_to_geran() );
+	execute( TC_srvcc_eutran_to_geran_ho_out() );
 	execute( TC_ho_in_fail_msc_clears() );
 	execute( TC_ho_in_fail_msc_clears_after_ho_detect() );
 	execute( TC_ho_in_fail_no_detect() );