BSC_Tests: Prepare for tests based on {RSL,BSSMAP}_Emulation

The existing tests were implemented directly on top of the BSSMAP
and RSL CodecPorts.  If we loop in the RSL_Emulation and
BSSMAP_Emulation components, we can properly multiplex/demultiplex
multiple MS (radio channels) on both the RSL and the MSC (SCCP
connection) side.

In order to have a single component that handles both the RSL and the
BSSAP side of a given channel/subscriber/call, we introduce the concept
of BSSMAP "Expects", where the test csse can register the L3 INFO that
it sends in the RLL ESTablish INDication on the RSL side, so the BSSMAP
handler cna route the BSC-originated SCCP connection with that L3 INFO
back to the same component.  This is a bit inspired "in spirit" of the
"expect" mechanism of netfilter connection tracking.

Change-Id: I71f777cd4f290422fa68897952b6505875e35f0e
diff --git a/bsc/BSC_Tests.ttcn b/bsc/BSC_Tests.ttcn
index 42de6be..c824415 100644
--- a/bsc/BSC_Tests.ttcn
+++ b/bsc/BSC_Tests.ttcn
@@ -12,6 +12,7 @@
 import from IPA_Emulation all;
 import from IPA_Types all;
 import from RSL_Types all;
+import from RSL_Emulation all;
 
 import from Osmocom_CTRL_Functions all;
 import from Osmocom_CTRL_Types all;
@@ -75,10 +76,13 @@
 type record IPA_Client {
 	IPA_Emulation_CT vc_IPA,
 	IPA_CCM_Parameters ccm_pars,
-	charstring id
+	charstring id,
+
+	RSL_Emulation_CT vc_RSL optional
 }
 
-function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i)
+function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i,
+			 boolean handler_mode := false)
 runs on test_CT {
 	timer T := 10.0;
 
@@ -87,11 +91,22 @@
 	clnt.ccm_pars := c_IPA_default_ccm_pars;
 	clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
 	clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0";
+	if (handler_mode) {
+		clnt.vc_RSL := RSL_Emulation_CT.create(clnt.id & "-RSL");
+	}
 
 	map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
-	connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
+	if (handler_mode) {
+		connect(clnt.vc_IPA:IPA_RSL_PORT, clnt.vc_RSL:IPA_PT);
+	} else {
+		connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
+	}
 
 	clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", 10000+i, clnt.ccm_pars));
+	if (handler_mode) {
+		clnt.vc_RSL.start(RSL_Emulation.main());
+		return;
+	}
 
 	/* wait for IPA RSL link to connect and send ID ACK */
 	T.start;
@@ -170,7 +185,7 @@
 		}
 }
 
-function f_init() runs on test_CT {
+function f_init(boolean handler_mode := false) runs on test_CT {
 	var integer i;
 
 	if (g_initialized) {
@@ -180,14 +195,14 @@
 
 	/* Call a function of our 'parent component' BSSAP_Adapter_CT to start the
 	 * MSC-side BSSAP emulation */
-	f_bssap_init("VirtMSC");
+	f_bssap_init("VirtMSC", handler_mode);
 	f_ipa_ctrl_start(ctrl, mp_bsc_ip, mp_bsc_ctrl_port, 0);
 
 	for (i := 0; i < NUM_BTS; i := i+1) {
 		/* wait until osmo-bts-omldummy has respawned */
 		f_wait_oml(i, "degraded", 5.0);
 		/* start RSL connection */
-		f_ipa_rsl_start(bts[i].rsl, mp_bsc_ip, mp_bsc_rsl_port, i);
+		f_ipa_rsl_start(bts[i].rsl, mp_bsc_ip, mp_bsc_rsl_port, i, handler_mode);
 		/* wait until BSC tells us "connected" */
 		f_wait_oml(i, "connected", 5.0);
 	}