BSC_Tests: Add TC_chan_exhaustion to test for channel exhaustion

We ensure that all channels are allocated, and that the first allocation
beyond the avialable channels will fail and generate an IMM_ASS_REJ.

WE also verify that the related counters are incremented as expected.

Change-Id: Iade77321588190cec89cfcd9c18d84a7144e0198
diff --git a/bsc/BSC_Tests.ttcn b/bsc/BSC_Tests.ttcn
index 9cdfe27..5988b28 100644
--- a/bsc/BSC_Tests.ttcn
+++ b/bsc/BSC_Tests.ttcn
@@ -25,6 +25,9 @@
 const integer NUM_BTS := 3;
 const float T3101_MAX := 12.0;
 
+/* make sure to sync this with the osmo-bts.cfg you're using */
+const integer NUM_TCHF_PER_BTS := 5;
+
 
 /* BSC specific CTRL helper functions */
 function f_ctrl_get_bts(IPA_CTRL_PT pt, integer bts_nr, charstring suffix) return CtrlValue {
@@ -331,6 +334,53 @@
 	setverdict(pass);
 }
 
+/* Test for channel exhaustion due to RACH overload */
+testcase TC_chan_exhaustion() runs on test_CT {
+	var ASP_RSL_Unitdata rsl_ud;
+	var integer i;
+	var integer chreq_total, chreq_nochan;
+
+	f_init();
+	f_bssap_reset();
+
+	chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
+	chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
+
+	/* expect 5xTCH/F to succeed */
+	for (i := 0; i < NUM_TCHF_PER_BTS; i := i+1) {
+		f_chreq_act_ack('23'O, i);
+	}
+
+	IPA_RSL[0].clear;
+
+	f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total", chreq_total+NUM_TCHF_PER_BTS);
+
+	/* now expect additional channel activations to fail */
+	f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
+
+	alt {
+	[] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
+				tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
+		setverdict(fail, "Received CHAN ACT ACK without resources?!?");
+		}
+	[] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
+		var GsmRrMessage rr;
+		/* match on IMM ASS REJ */
+		rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
+		if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
+			f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
+						   chreq_total+NUM_TCHF_PER_BTS+1);
+			f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
+						   chreq_nochan+1);
+			setverdict(pass);
+		} else {
+			repeat;
+		}
+		}
+	[] IPA_RSL[0].receive { repeat; }
+	}
+}
+
 
 type record DchanTuple {
 	integer sccp_conn_id,
@@ -1012,6 +1062,7 @@
 	execute( TC_chan_act_ack_est_ind_noreply() );
 	execute( TC_chan_act_ack_est_ind_refused() );
 	execute( TC_chan_act_nack() );
+	execute( TC_chan_exhaustion() );
 	execute( TC_chan_rel_rll_rel_ind() );
 	execute( TC_chan_rel_conn_fail() );
 	execute( TC_chan_rel_hard_clear() );