msc: Test closing BSSAP connection of LU by ClearCommand

Change-Id: I9194da2f9324ee17c920458cb920a6fa718ac739
diff --git a/library/BSSMAP_Templates.ttcn b/library/BSSMAP_Templates.ttcn
index 925a8e6..5331505 100644
--- a/library/BSSMAP_Templates.ttcn
+++ b/library/BSSMAP_Templates.ttcn
@@ -609,6 +609,18 @@
 	}
 }
 
+template (value) PDU_BSSAP ts_BSSMAP_ClearRequest(BssmapCause cause)
+modifies ts_BSSAP_BSSMAP := {
+	pdu := {
+		bssmap := {
+			clearRequest := {
+				messageType := '22'O,	/* overwritten */
+				cause := ts_BSSMAP_IE_Cause(cause)
+			}
+		}
+	}
+}
+
 template PDU_BSSAP tr_BSSMAP_ClearRequest modifies tr_BSSAP_BSSMAP := {
 	pdu := {
 		bssmap := {
diff --git a/msc_tests/MSC_Tests.ttcn b/msc_tests/MSC_Tests.ttcn
index 9f8dd69..a21ad50 100644
--- a/msc_tests/MSC_Tests.ttcn
+++ b/msc_tests/MSC_Tests.ttcn
@@ -588,6 +588,38 @@
 	vc_conn.done;
 }
 
+/* Test LU but BSC will send a clear request in the middle */
+private function f_tc_lu_clear_request(charstring id, BSC_ConnHdlrPars pars) runs on BSC_ConnHdlr {
+	g_pars := pars;
+
+	var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi)
+	var PDU_DTAP_MT dtap_mt;
+
+	/* tell GSUP dispatcher to send this IMSI to us */
+	f_create_gsup_expect(hex2str(g_pars.imsi));
+
+	/* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
+	f_bssap_compl_l3(l3_lu);
+
+	/* Send Early Classmark, just for the fun of it */
+	BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
+
+	f_sleep(1.0);
+	/* send clear request in the middle of the LU */
+	BSSAP.send(ts_BSSMAP_ClearRequest(0));
+	BSSAP.receive(tr_BSSMAP_ClearCommand);
+	BSSAP.send(ts_BSSMAP_ClearComplete);
+	BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
+	setverdict(pass);
+}
+testcase TC_lu_clear_request() runs on MTC_CT {
+	var BSC_ConnHdlr vc_conn;
+	f_init();
+
+	vc_conn := f_start_handler(refers(f_tc_lu_clear_request), testcasename(), 8);
+	vc_conn.done;
+}
+
 
 
 control {