bsc: TC_emerg_premption: check BSSMAP Clear Req cause

On the first TCH, establish Layer 3 so that the BSC will issue a Clear
Request at all.

Verify the cause value of the Clear Request.

Tear down the established Layer 3: clean up for the leak check.

Related: OS#5535
Depends: I20108f7b4769400b89b7b0d65c8dab883bf87c46 (osmo-bsc)
Change-Id: Ib13be73119cfc96712f32899c02e655e1751d547
diff --git a/bsc/BSC_Tests.ttcn b/bsc/BSC_Tests.ttcn
index 59b87dd..5779990 100644
--- a/bsc/BSC_Tests.ttcn
+++ b/bsc/BSC_Tests.ttcn
@@ -9029,6 +9029,12 @@
 	var octetstring l3 := '00010203040506'O;
 	f_ipa_tx(0, ts_RSL_EST_IND(first_tch, valueof(ts_RslLinkID_DCCH(0)), l3));
 
+	/* Accept BSSAP conn, so we get to test the Clear Request cause */
+	var BSSAP_N_CONNECT_ind rx_c_ind;
+	BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
+	var integer sccp_conn_id := rx_c_ind.connectionId;
+	BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
+
 	/* Send Channel request for emegergency call */
 	f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
 
@@ -9036,6 +9042,15 @@
 	f_expect_chan_rel(0, first_tch, expect_rr_chan_rel := true, expect_rll_rel_req := false,
 			  expect_rr_cause := GSM48_RR_CAUSE_PREMPTIVE_REL);
 
+	/* Also expect a BSSMAP Clear Request with PREEMPTION */
+	var BSSAP_N_DATA_ind rx_clear_req;
+	const myBSSMAP_Cause preemption := GSM0808_CAUSE_PREEMPTION;
+	BSSAP.receive(tr_BSSAP_DATA_ind(sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_clear_req;
+	log("XXX ", rx_clear_req);
+	if (rx_clear_req.userData.pdu.bssmap.clearRequest.cause.causeValue != int2bit(enum2int(preemption), 7)) {
+		setverdict(fail, "BSSMAP Clear Request: expected cause PREEMPTION");
+	}
+
 	/* Expect the BSC to send activate/assign the channel for the emergency call */
 	rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
 	if (first_tch != rx_rsl.ies[0].body.chan_nr) {
@@ -9044,6 +9059,12 @@
 	f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(first_tch, 33));
 	rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
 
+	/* complete the BSSMAP Clear to satisfy the conn leak check */
+	BSSAP.send(ts_BSSAP_DATA_req(sccp_conn_id, ts_BSSMAP_ClearCommand(enum2int(preemption))));
+	BSSAP.receive(tr_BSSAP_DATA_ind(sccp_conn_id, tr_BSSMAP_ClearComplete)) {
+		BSSAP.send(ts_BSSAP_DISC_req(sccp_conn_id, 0));
+	}
+
 	f_shutdown_helper();
 }