bsc-tests: Add BTS_Simulation, RSL_Tests and .cfg file
diff --git a/bsc/BSC_Tests.cfg b/bsc/BSC_Tests.cfg
new file mode 100644
index 0000000..dde224c
--- /dev/null
+++ b/bsc/BSC_Tests.cfg
@@ -0,0 +1,28 @@
+[LOGGING]
+#FileMask := LOG_ALL | TTCN_DEBUG | TTCN_MATCHING | DEBUG_ENCDEC;
+#ConsoleMask := ERROR | WARNING | TESTCASE | TTCN_MATCHING | DEBUG_ENCDEC
+FileMask := LOG_ALL | TTCN_MATCHING;
+
+[TESTPORT_PARAMETERS]
+#*.*.udpReuseAddress := "yes";
+
+[MODULE_PARAMETERS]
+#mp_bsc_port := 49999;
+#mp_bsc_ip   := "127.0.0.1";
+#mp_msc_port := 5100;
+#mp_msc_ip   := "127.0.0.1";
+#mp_nat_port := 5000;
+#mp_nat_ip   := "127.0.0.1";
+
+#mp_ipa_mgcp_uses_osmo_ext := true;
+
+#mp_mgcp_uses_udp := true;
+#mp_callagent_ip := "127.0.0.1";
+#mp_callagent_udp_port := 2727;
+#mp_mgw_ip := "127.0.0.1";
+#mp_mgw_udp_port := 2427;
+
+[MAIN_CONTROLLER]
+
+[EXECUTE]
+BSC_Tests.TC_recv_dump
diff --git a/bsc/BSC_Tests.ttcn b/bsc/BSC_Tests.ttcn
index 4629e6e..9b26800 100644
--- a/bsc/BSC_Tests.ttcn
+++ b/bsc/BSC_Tests.ttcn
@@ -13,8 +13,10 @@
 import from SCCP_Emulation all;
 
 import from MSC_Simulation all;
+import from BTS_Simulation all;
 
 const integer NUM_MSC := 1;
+const integer NUM_BTS := 1;
 
 type record MscState {
 	MSC_CT MSC,
@@ -22,8 +24,13 @@
 	SCCP_PAR_Address sccp_addr_own
 }
 
+type record BtsState {
+	BTS_CT BTS
+}
+
 type component test_CT {
 	var MscState msc[NUM_MSC];
+	var BtsState bts[NUM_BTS];
 
 	var boolean g_initialized := false;
 	var octetstring g_sio := '83'O;
@@ -40,6 +47,9 @@
 
 	integer mp_msc_pc := 185;	/* 0.23.1 */
 	integer mp_msc_ssn := 254;
+
+	charstring mp_bsc_ip := "127.0.0.1";
+	integer mp_bsc_rsl_port := 3003;
 }
 
 /* construct a SCCP_PAR_Address with just PC + SSN and no GT */
@@ -89,6 +99,12 @@
 		msc[i].MSC.start(MSC_Simulation.main(mp_msc_ip, mp_msc_port + i, msc[i].sccp_pars, msc[i].sccp_addr_own, id));
 	}
 
+	for (i := 0; i < NUM_BTS; i := i+1) {
+		bts[i].BTS := BTS_CT.create;
+		id := "BTS" & int2str(i);
+		bts[i].BTS.start(BTS_Simulation.main(mp_bsc_ip, mp_bsc_rsl_port, id));
+	}
+
 }
 
 testcase TC_recv_dump() runs on test_CT {
diff --git a/bsc/BTS_Simulation.ttcn b/bsc/BTS_Simulation.ttcn
new file mode 100644
index 0000000..de78231
--- /dev/null
+++ b/bsc/BTS_Simulation.ttcn
@@ -0,0 +1,44 @@
+module BTS_Simulation {
+
+/* Start an IPA client and bind the RSL Emulation on top; we assume that OML
+ * is handled elsewhere! */
+
+import from IPL4asp_Types all;
+import from IPA_Emulation all;
+import from RSL_Emulation all;
+import from RSL_Tests all;
+
+type component BTS_CT {
+	var IPA_Emulation_CT vc_IPA;
+	var RSL_Emulation_CT vc_RSL;
+	var IPA_CCM_Parameters ccm_pars;
+}
+
+function main(charstring bsc_host, PortNumber bsc_port, charstring id) runs on BTS_CT
+{
+	vc_IPA := IPA_Emulation_CT.create(id & "-IPA");
+	vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
+	ccm_pars := c_IPA_default_ccm_pars;
+	ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
+	ccm_pars.unit_id := "1234/0/0";
+
+	map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
+	connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
+
+	vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", -1, ccm_pars));
+	vc_RSL.start(RSL_Emulation.main());
+
+	var RSL_Tests_CT vc_DCHAN;
+	vc_DCHAN := RSL_Tests_CT.create(id & "-DCHAN");
+	connect(vc_DCHAN:RSL, vc_RSL:CLIENT_PT);
+	vc_DCHAN.start(RSL_Tests.test_mahlzeit('901700123456789'H));
+
+
+	/* wait until termination of respective component */
+	vc_RSL.done;
+	vc_IPA.done;
+}
+
+
+
+}
diff --git a/bsc/README.txt b/bsc/README.txt
new file mode 100644
index 0000000..aa82f32
--- /dev/null
+++ b/bsc/README.txt
@@ -0,0 +1,72 @@
+Integration Tests for OsmoBSC which we can perform from TTCN-3
+
+= exhaustion of resources
+
+* send many CHAN RQD (any) and count if all channels get actually allocated
+** verify BTS_CTR_CHREQ_TOTAL reflects number sent on RSL
+** verify how quickly they get released again
+** verify that CHAN RQD with same RA + FN get only on allocation
+* verify that we get IMM_ASS_REJ once channels are exhausted
+** verify BTS_CTR_CHREQ_NO_CHANNEL increments accordigly
+* verify for particular channel type / cause values
+* verify that IMM.ASS.REJ has increasing back-off
+* verify how BSC reacts to AGCH overload (DELETE IND)
+
+
+= paging
+
+* page by TMSI vs. page by IMSI
+* verify if CCCH_LOAD_IND(PCH) slot count is observed
+* verify paging expiration
+* paging with different identity (lac/cgi/...) on A interface -> expect on right BSC(s)
+
+= hand-over
+
+* intra-BSC HO
+* handover detect when not expected
+
+= erroneous channel release
+
+* no response to CHAN ACT
+* CONN FAIL IND from BTS
+** verify counter increment of BTS_CTR_CHAN_RF_FAIL
+* no (or late?) response to RF CHAN REL
+* no (or late?) response to RLL RELEASE REQ
+* RLL messages on not-activated channels
+
+= misc
+
+* SMS-CB
+* behavior in case of CHAN ACT NACK
+* EST REQ for SAPI3 originating from core
+* behavior of BSC in various error cases  (ERR IND)
+** BTS_CTR_CHAN_RLL_ERR increment on T200_EXPIRED
+* MODE MODIFY with ACK / NACK / no response
+
+= IPA voice related
+
+* expect IPA CRCX, send UDP flows, expect them on AoIP
+* expect RTCP 
+* missing RTP flow?
+* missing RTCP?
+* missing / drop-outs in RTP flow[s]
+* no response to IPA CRCX / MDCX / DLCX
+
+= counters
+
+* test each and every counter in BSC, validate via CTRL interface
+** RSL/OML failure: drop link, expect BTS_CTR_BTS_xxx_FAIL +1
+** paging
+*** send PAGING from MSC side
+*** expect BSC_CTR_PAGING_ATTEMPTED increase by one
+*** expect BSC_CTR_PAGING_EXPIRED on T3113 expiration
+** BTS_CTR_CODEC_* on CHAN_ACT_ACK
+* new counter ideas
+** number of SCCP CR timeouts
+** number of incoming RESET from MSC
+
+= VTY based/corresponding tests
+
+* changes in BCCH FILLING
+* changes in SACCH FILLING
+
diff --git a/bsc/RSL_Tests.ttcn b/bsc/RSL_Tests.ttcn
new file mode 100644
index 0000000..7c0cf7d
--- /dev/null
+++ b/bsc/RSL_Tests.ttcn
@@ -0,0 +1,40 @@
+module RSL_Tests {
+
+import from GSM_Types all;
+import from RSL_Types all;
+import from MobileL3_Types all;
+import from MobileL3_CommonIE_Types all;
+import from L3_Templates all;
+import from RSL_Emulation all;
+
+type component RSL_Tests_CT extends RSL_DchanHdlr {
+}
+
+private function f_rx_l3(PDU_ML3_NW_MS l3) runs on RSL_Tests_CT {
+	log("L3 received ", l3);
+	if (ischosen(l3.msgs.rrm.channelRelease)) {
+	}
+}
+
+function test_mahlzeit(hexstring imsi) runs on RSL_Tests_CT {
+
+	var RSL_Message rsl;
+	var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
+	var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(imsi));
+	var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ('0001'B, mi));
+	timer T := 1.0;
+
+	f_chan_est('23'O, enc_PDU_ML3_MS_NW(l3_info), link_id, 23);
+	/* if we reach here, we have established a dedicated channel */
+
+	alt {
+	[] RSL.receive(tr_RSL_MsgTypeR(RSL_MT_DATA_REQ)) -> value rsl {
+		var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
+		f_rx_l3(l3);
+		}
+	}
+}
+
+
+
+}
diff --git a/bsc/gen_links.sh b/bsc/gen_links.sh
index 7be9a2d..9743398 100755
--- a/bsc/gen_links.sh
+++ b/bsc/gen_links.sh
@@ -55,5 +55,5 @@
 gen_links $DIR $FILES
 
 DIR=../library
-FILES="General_Types.ttcn Osmocom_Types.ttcn IPA_Types.ttcn IPA_CodecPort.ttcn IPA_CodecPort_CtrlFunct.ttcn IPA_CodecPort_CtrlFunctDef.cc IPA_Emulation.ttcn L3_Templates.ttcn BSSMAP_Templates.ttcn BSSMAP_Emulation.ttcn MGCP_Types.ttcn MGCP_Templates.ttcn MGCP_CodecPort.ttcn MGCP_CodecPort_CtrlFunct.ttcn MGCP_CodecPort_CtrlFunctDef.cc"
+FILES="General_Types.ttcn Osmocom_Types.ttcn IPA_Types.ttcn IPA_CodecPort.ttcn IPA_CodecPort_CtrlFunct.ttcn IPA_CodecPort_CtrlFunctDef.cc IPA_Emulation.ttcn L3_Templates.ttcn BSSMAP_Templates.ttcn BSSMAP_Emulation.ttcn MGCP_Types.ttcn MGCP_Templates.ttcn MGCP_CodecPort.ttcn MGCP_CodecPort_CtrlFunct.ttcn MGCP_CodecPort_CtrlFunctDef.cc RLCMAC_CSN1_Types.ttcn GSM_RR_Types.ttcn RSL_Emulation.ttcn"
 gen_links $DIR $FILES
diff --git a/bsc/regen_makefile.sh b/bsc/regen_makefile.sh
index d94af3d..6bedd28 100755
--- a/bsc/regen_makefile.sh
+++ b/bsc/regen_makefile.sh
@@ -9,3 +9,7 @@
 sed -i -e 's/LDFLAGS = /LDFLAGS = -L \/usr\/lib\/titan /' Makefile
 #sed -i -e 's/TTCN3_LIB = ttcn3-parallel/TTCN3_LIB = ttcn3/' Makefile
 sed -i -e 's/CPPFLAGS = -D$(PLATFORM) -I$(TTCN3_DIR)\/include/CPPFLAGS = -D$(PLATFORM) -I$(TTCN3_DIR)\/include -I\/usr\/include\/titan/' Makefile
+
+# for TITAN 6.3.0
+sed -i -e 's/TTCN3_DIR = /TTCN3_DIR = \/usr/' Makefile
+sed -i -e 's/\/bin\/compiler/\/bin\/ttcn3_compiler/' Makefile