BSC_Tests: add testcases to verify S15-S0 handling

The handling of the AMR rate configuration bits S15-S0 is currently only
superficially checked. Lets add more some more elaborated testcases to
check through varios different situations. Also make sure that the
resulting mr configuration IE is verified

Change-Id: Ica323deb9836deea72982e093c9cb31deb5a216b
Related: SYS#4470
diff --git a/bsc/BSC_Tests.ttcn b/bsc/BSC_Tests.ttcn
index 58001e5..659b3f6 100644
--- a/bsc/BSC_Tests.ttcn
+++ b/bsc/BSC_Tests.ttcn
@@ -1953,6 +1953,10 @@
 		ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
 		exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
 								g_pars.ass_codec_list.codecElements[0];
+		if (isvalue(g_pars.expect_mr_s0_s7)) {
+			exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
+								g_pars.expect_mr_s0_s7;
+		}
 	}
 	ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
 				f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
@@ -1994,6 +1998,22 @@
 	}
 }
 
+private function f_TC_assignment_codec_fail(charstring id) runs on MSC_ConnHdlr {
+
+	var PDU_BSSAP ass_cmd := f_gen_ass_req();
+	var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
+
+	/* puzzle together the ASSIGNMENT REQ for given codec[s] */
+	if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
+		ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
+	}
+	ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
+				f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
+	log("expecting ASS FAIL like this: ", exp_fail);
+
+	f_establish_fully(ass_cmd, exp_fail);
+}
+
 testcase TC_assignment_codec_fr() runs on test_CT {
 	var TestHdlrParams pars := f_gen_test_hdlr_pars();
 	var MSC_ConnHdlr vc_conn;
@@ -2030,6 +2050,37 @@
 	vc_conn.done;
 }
 
+/* Allow 5,90k only (current default config) */
+private function f_allow_amr_rate_5_90k() runs on test_CT {
+	f_vty_enter_cfg_msc(BSCVTY, 0);
+	f_vty_transceive(BSCVTY, "amr-config 12_2k forbidden");
+	f_vty_transceive(BSCVTY, "amr-config 10_2k forbidden");
+	f_vty_transceive(BSCVTY, "amr-config 7_95k forbidden");
+	f_vty_transceive(BSCVTY, "amr-config 7_40k forbidden");
+	f_vty_transceive(BSCVTY, "amr-config 6_70k forbidden");
+	f_vty_transceive(BSCVTY, "amr-config 5_90k allowed");
+	f_vty_transceive(BSCVTY, "amr-config 5_15k forbidden");
+	f_vty_transceive(BSCVTY, "amr-config 4_75k forbidden");
+	f_vty_transceive(BSCVTY, "exit");
+	f_vty_transceive(BSCVTY, "exit");
+}
+
+/* Allow 4,75k, 5,90k, 4,70k and 12,2k, which are the most common rates
+ * ("Config-NB-Code = 1") */
+private function f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k() runs on test_CT {
+	f_vty_enter_cfg_msc(BSCVTY, 0);
+	f_vty_transceive(BSCVTY, "amr-config 12_2k allowed");
+	f_vty_transceive(BSCVTY, "amr-config 10_2k forbidden");
+	f_vty_transceive(BSCVTY, "amr-config 7_95k forbidden");
+	f_vty_transceive(BSCVTY, "amr-config 7_40k allowed");
+	f_vty_transceive(BSCVTY, "amr-config 6_70k forbidden");
+	f_vty_transceive(BSCVTY, "amr-config 5_90k allowed");
+	f_vty_transceive(BSCVTY, "amr-config 5_15k forbidden");
+	f_vty_transceive(BSCVTY, "amr-config 4_75k allowed");
+	f_vty_transceive(BSCVTY, "exit");
+	f_vty_transceive(BSCVTY, "exit");
+}
+
 testcase TC_assignment_codec_amr_f() runs on test_CT {
 	var TestHdlrParams pars := f_gen_test_hdlr_pars();
 	var MSC_ConnHdlr vc_conn;
@@ -2080,6 +2131,160 @@
 	vc_conn.done;
 }
 
+function f_TC_assignment_codec_amr(boolean fr, octetstring mrconf, bitstring s8_s0, bitstring exp_s8_s0)
+runs on test_CT {
+
+	var TestHdlrParams pars := f_gen_test_hdlr_pars();
+	var MSC_ConnHdlr vc_conn;
+
+	/* See note above */
+	var RSL_IE_Body mr_conf := {
+		other := {
+			len := lengthof(mrconf),
+			payload := mrconf
+		}
+	};
+
+	if (fr) {
+		pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
+	} else {
+		pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
+	}
+	pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
+	pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
+	pars.expect_mr_conf_ie := mr_conf;
+	pars.expect_mr_s0_s7 := exp_s8_s0;
+
+	f_init(1, true);
+	f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
+	f_sleep(1.0);
+
+	vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
+	vc_conn.done;
+	f_allow_amr_rate_5_90k();
+}
+
+function f_TC_assignment_codec_amr_fail(boolean fr, bitstring s8_s0)
+runs on test_CT {
+
+	var TestHdlrParams pars := f_gen_test_hdlr_pars();
+	var MSC_ConnHdlr vc_conn;
+
+	if (fr) {
+		pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
+	} else {
+		pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
+	}
+	pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
+	pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
+
+	f_init(1, true);
+	f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
+	f_sleep(1.0);
+
+	vc_conn := f_start_handler(refers(f_TC_assignment_codec_fail), pars);
+	vc_conn.done;
+	f_allow_amr_rate_5_90k();
+}
+
+
+/* Set S1, we expect an AMR multirate configuration IE with all four rates
+ * set. */
+testcase TC_assignment_codec_amr_f_S1() runs on test_CT {
+	 f_TC_assignment_codec_amr(true, '289520882208'O, '00000010'B, '00000010'B);
+}
+
+/* Set S1, we expect an AMR multirate configuration IE with the lower three
+ * rates set. */
+testcase TC_assignment_codec_amr_h_S1() runs on test_CT {
+	 f_TC_assignment_codec_amr(false, '2815208820'O, '00000010'B, '00000010'B);
+}
+
+/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
+ * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
+testcase TC_assignment_codec_amr_f_S124() runs on test_CT {
+	 f_TC_assignment_codec_amr(true, '289520882208'O, '00010110'B, '00000010'B);
+}
+
+/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
+ * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
+testcase TC_assignment_codec_amr_h_S124() runs on test_CT {
+	 f_TC_assignment_codec_amr(false, '2815208820'O, '00010110'B, '00000010'B);
+}
+
+/* The following block of tests selects more and more rates until all four
+ * possible rates are in the active set (full rate) */
+testcase TC_assignment_codec_amr_f_S0() runs on test_CT {
+	 f_TC_assignment_codec_amr(true, '2801'O, '00000001'B, '00000001'B);
+}
+
+testcase TC_assignment_codec_amr_f_S02() runs on test_CT {
+	 f_TC_assignment_codec_amr(true, '28052080'O, '00000101'B, '00000101'B);
+}
+
+testcase TC_assignment_codec_amr_f_S024() runs on test_CT {
+	 f_TC_assignment_codec_amr(true, '2815208820'O, '00010101'B, '00010101'B);
+}
+
+testcase TC_assignment_codec_amr_f_S0247() runs on test_CT {
+	 f_TC_assignment_codec_amr(true, '289520882208'O, '10010101'B, '10010101'B);
+}
+
+/* The following block of tests selects more and more rates until all three
+ * possible rates are in the active set (half rate) */
+testcase TC_assignment_codec_amr_h_S0() runs on test_CT {
+	 f_TC_assignment_codec_amr(false, '2801'O, '00000001'B, '00000001'B);
+}
+
+testcase TC_assignment_codec_amr_h_S02() runs on test_CT {
+	 f_TC_assignment_codec_amr(false, '28052080'O, '00000101'B, '00000101'B);
+}
+
+testcase TC_assignment_codec_amr_h_S024() runs on test_CT {
+	 f_TC_assignment_codec_amr(false, '2815208820'O, '00010101'B, '00010101'B);
+}
+
+/* The following block tests what happens when the MSC does offer rate
+ * configurations that are not supported by the BSC. Normally such situations
+ * should not happen because the MSC gets informed by the BSC in advance via
+ * the L3 COMPLETE message which rates are applicable. The MSC should not try
+ * to offer rates that are not applicable anyway. */
+
+testcase TC_assignment_codec_amr_h_S0247() runs on test_CT {
+	 /* Try to include 12,2k in into the active set even though the channel
+	  * is half rate only. The BSC is expected to remove the 12,0k */
+	 f_TC_assignment_codec_amr(false, '2815208820'O, '10010101'B, '00010101'B);
+}
+
+testcase TC_assignment_codec_amr_f_S01234567() runs on test_CT {
+	 /* See what happens when all rates are selected at once. Since then
+	  * Also S1 is selected, this setting will be prefered and we should
+	  * get 12.2k, 7,40k, 5,90k, and 4,75k in the active set. */
+	 f_TC_assignment_codec_amr(true, '289520882208'O, '11111111'B, '00000010'B);
+}
+
+testcase TC_assignment_codec_amr_f_S0234567() runs on test_CT {
+	 /* Same as above, but with S1 missing, the MSC is then expected to
+	  * select the currently supported rates, which are also 12.2k, 7,40k,
+	  * 5,90k, and 4,75k, into the active set. */
+	 f_TC_assignment_codec_amr(true, '289520882208'O, '11111101'B, '10010101'B);
+}
+
+testcase TC_assignment_codec_amr_f_zero() runs on test_CT {
+	 /* Try to select no rates at all */
+	 f_TC_assignment_codec_amr_fail(true, '00000000'B);
+}
+
+testcase TC_assignment_codec_amr_f_unsupp() runs on test_CT {
+	 /* Try to select only unsupported rates */
+	 f_TC_assignment_codec_amr_fail(true, '01101000'B);
+}
+
+testcase TC_assignment_codec_amr_h_S7() runs on test_CT {
+	 /* Try to select 12,2k for half rate */
+	 f_TC_assignment_codec_amr_fail(false, '10000000'B);
+}
+
 private function f_disable_all_tch_f() runs on test_CT {
 	f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 borken");
 	f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 borken");
@@ -3753,6 +3958,23 @@
 	execute( TC_assignment_codec_efr() );
 	execute( TC_assignment_codec_amr_f() );
 	execute( TC_assignment_codec_amr_h() );
+	execute( TC_assignment_codec_amr_f_S1() );
+	execute( TC_assignment_codec_amr_h_S1() );
+	execute( TC_assignment_codec_amr_f_S124() );
+	execute( TC_assignment_codec_amr_h_S124() );
+	execute( TC_assignment_codec_amr_f_S0() );
+	execute( TC_assignment_codec_amr_f_S02() );
+	execute( TC_assignment_codec_amr_f_S024() );
+	execute( TC_assignment_codec_amr_f_S0247() );
+	execute( TC_assignment_codec_amr_h_S0() );
+	execute( TC_assignment_codec_amr_h_S02() );
+	execute( TC_assignment_codec_amr_h_S024() );
+	execute( TC_assignment_codec_amr_h_S0247() );
+	execute( TC_assignment_codec_amr_f_S01234567() );
+	execute( TC_assignment_codec_amr_f_S0234567() );
+	execute( TC_assignment_codec_amr_f_zero() );
+	execute( TC_assignment_codec_amr_f_unsupp() );
+	execute( TC_assignment_codec_amr_h_S7() );
 
 	execute( TC_assignment_codec_fr_exhausted_req_hr() );
 	execute( TC_assignment_codec_fr_exhausted_req_fr() );