WIP: MSC_Tests: Add SGs testcases

This extens MSC_Tests.ttcn with an initial set of SGs interface test
cases for RESET, LU, DETACH, PAGING, SMS and CSFB procedures

In particular the following testcases are added:

- TC_sgsap_reset: isolated reset procedure test
- TC_sgsap_lu: isolated location update with TMSI realloc
- TC_sgsap_lu_imsi_reject: location update, reject case
- TC_sgsap_lu_and_nothing: location update with failed TMSI realloc
- TC_sgsap_expl_imsi_det_eps: detach from EPS serveces
- TC_sgsap_expl_imsi_det_noneps: detach from non-EPS services
- TC_sgsap_paging_rej: isolated paging, reject case
- TC_sgsap_paging_subscr_rej: isolated paging, subscr rejects call
- TC_sgsap_paging_ue_unr: isolated paging, ue is unreachable
- TC_sgsap_paging_and_nothing: page, but don't respond
- TC_sgsap_paging_and_lu: check paging followed by an LU
- TC_sgsap_mt_sms: mobile terminated SMS through SGs Interface
- TC_sgsap_mo_sms: mobile originated SMS through SGs Interface
- TC_sgsap_mt_sms_and_nothing: trigger SMS, but don't respond to paging
- TC_sgsap_mt_sms_and_reject: trigger SMS, but reject paging
- TC_sgsap_unexp_ud: Send unexpected unitdata (SGs Association: NULL)
- TC_sgsap_unsol_ud: Send unsolicited unitdata (subscriber not in VLR)
- TC_bssap_lu_sgsap_lu_and_mt_call: LU on 2G, LU on SGs and CSFB call
- TC_sgsap_lu_and_mt_call: LU on SGs, and CSFB call

Change-Id: I38543c35a9e74cea276e58d1d7ef01ef07ffe858
Depends: osmo-msc I73359925fc1ca72b33a1466e6ac41307f2f0b11d
Related: OS#3645
diff --git a/msc/BSC_ConnectionHandler.ttcn b/msc/BSC_ConnectionHandler.ttcn
index 43a1190..735cd21 100644
--- a/msc/BSC_ConnectionHandler.ttcn
+++ b/msc/BSC_ConnectionHandler.ttcn
@@ -39,8 +39,10 @@
 import from TELNETasp_PortType all;
 import from Osmocom_VTY_Functions all;
 
+import from SGsAP_Emulation all;
+
 /* this component represents a single subscriber connection */
-type component BSC_ConnHdlr extends BSSAP_ConnHdlr, MNCC_ConnHdlr, GSUP_ConnHdlr, MGCP_ConnHdlr, SMPP_ConnHdlr, CTRL_Adapter_CT {
+type component BSC_ConnHdlr extends BSSAP_ConnHdlr, MNCC_ConnHdlr, GSUP_ConnHdlr, MGCP_ConnHdlr, SMPP_ConnHdlr, CTRL_Adapter_CT, SGsAP_ConnHdlr {
 	var BSC_ConnHdlrPars g_pars;
 	timer g_Tguard := 60.0;
 	port TELNETasp_PT MSCVTY;
@@ -135,6 +137,8 @@
 	activate(as_Tguard());
 	/* Route all SMPP messages for our MSISDN to us */
 	f_create_smpp_expect(hex2str(pars.msisdn));
+	/* Route all SGs message for our IMSI to us */
+	f_create_sgsap_expect(pars.imsi);
 
 	if (g_pars.ipa_ctrl_enable == true) {
 		f_ipa_ctrl_start(g_pars.ipa_ctrl_ip, g_pars.ipa_ctrl_port);
@@ -452,21 +456,22 @@
 	mgcp_connection_id_mss := '0'H //
 };
 
-function f_mt_call_establish(inout CallParameters cpars)
+/* Allocate a call reference and send SETUP via MNCC to MSC */
+function f_mt_call_initate(inout CallParameters cpars)
 runs on BSC_ConnHdlr {
+	cpars.mncc_callref := f_rnd_int(2147483648);
+	MNCC.send(ts_MNCC_SETUP_req(cpars.mncc_callref, hex2str(g_pars.msisdn),
+					hex2str(cpars.called_party), hex2str(g_pars.imsi)));
+}
 
+/* Complete call, begin with a paging response message via BSSAP */
+function f_mt_call_complete(inout CallParameters cpars)
+runs on BSC_ConnHdlr {
 	var MNCC_PDU mncc;
 	var MgcpCommand mgcp_cmd;
 
 	f_bssmap_register_imsi(g_pars.imsi, g_pars.tmsi);
 
-	/* Allocate a call reference and send SETUP via MNCC to MSC */
-	cpars.mncc_callref := f_rnd_int(2147483648);
-	MNCC.send(ts_MNCC_SETUP_req(cpars.mncc_callref, hex2str(g_pars.msisdn),
-					hex2str(cpars.called_party), hex2str(g_pars.imsi)));
-	/* BSC <- MSC: Expect paging. FIXME: By TMSI or not? */
-	BSSAP.receive(tr_BSSMAP_Paging(g_pars.imsi));
-
 	f_establish_fully(EST_TYPE_PAG_RESP);
 
 	/* MS <- MSC: Expect CC SETUP */
@@ -476,7 +481,6 @@
 	BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_ALERTING(cpars.transaction_id)));
 	MNCC.receive(tr_MNCC_ALERT_ind(cpars.mncc_callref));
 
-
 	/* Create MGCP expect */
 	f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
 	/* Ask MSC via MNCC to create the RTP socket on the MSC/MGW side */
@@ -531,6 +535,20 @@
 	/* MS -> MSC: ALERTING */
 	BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
 	MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref));
+}
+
+function f_mt_call_establish(inout CallParameters cpars)
+runs on BSC_ConnHdlr {
+
+	/* Initiate the call via MNCC */
+	f_mt_call_initate(cpars);
+
+	/* BSC <- MSC: Expect paging. FIXME: By TMSI or not? */
+	f_bssmap_register_imsi(g_pars.imsi, g_pars.tmsi);
+	BSSAP.receive(tr_BSSMAP_Paging(g_pars.imsi));
+
+	/* Complete the call via BSSAP */
+	f_mt_call_complete(cpars);
 
 	setverdict(pass);
 }
@@ -1008,7 +1026,6 @@
 }
 
 
-
 }