blob: e48c05aac34b7e11079fee72b9f362ba90d2514b [file] [log] [blame]
Harald Welte70767382018-02-21 12:16:40 +01001module BTS_Tests {
2
Harald Welte14906952019-05-27 09:19:49 +02003/* Integration Tests for OsmoBTS
Harald Welte34b5a952019-05-27 11:54:11 +02004 * (C) 2018-2019 by Harald Welte <laforge@gnumonks.org>
Harald Welte14906952019-05-27 09:19:49 +02005 * contributions by Vadim Yanitskiy and sysmocom - s.f.m.c. GmbH
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 *
Harald Welte34b5a952019-05-27 11:54:11 +020011 * SPDX-License-Identifier: GPL-2.0-or-later
12 *
Harald Welte14906952019-05-27 09:19:49 +020013 * This test suite tests OsmoBTS by attaching to the external interfaces
14 * such as Abis RSL, PCU, VTY as well as by attaching to a MS L1 implementation
15 * using the L1CTL protocol/interface.
16 *
17 * You can run the tests with
18 * a) osmo-bts-trx + trxcon + fake_trx (without any hardware)
19 * b) any osmo-bts-* + OsmocomBB layer1 + osmocon (with real BTS hardware)
20 * c) osmo-bts-virtual + virt_phy (without any hardware)
21 *
22 * Some of the tests will only run on a subset of those three configurations
23 * due to limitations in the respective L1.
24 */
25
Daniel Willmann0fcc4d32018-10-23 20:32:19 +020026import from Misc_Helpers all;
Harald Welte70767382018-02-21 12:16:40 +010027import from General_Types all;
28import from GSM_Types all;
29import from GSM_RR_Types all;
30import from Osmocom_Types all;
31import from GSM_Types all;
Harald Welte82ccef72018-02-25 16:17:33 +010032import from GSM_SystemInformation all;
Harald Welte70767382018-02-21 12:16:40 +010033import from L1CTL_PortType all;
34import from L1CTL_Types all;
35import from LAPDm_Types all;
Harald Weltead033dc2019-05-25 17:28:16 +020036import from LAPDm_RAW_PT all;
Harald Welte70767382018-02-21 12:16:40 +010037import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020038import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010039
40import from RSL_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010041import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010042import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020043import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010044import from RSL_Emulation all;
45
46import from IPL4asp_Types all;
47import from TRXC_Types all;
48import from TRXC_CodecPort all;
49import from TRXC_CodecPort_CtrlFunct all;
50
Harald Welte883340c2018-02-28 18:59:29 +010051import from PCUIF_Types all;
52import from PCUIF_CodecPort all;
Harald Weltea2e0e942019-05-27 18:12:53 +020053import from UD_Types all;
Harald Welte883340c2018-02-28 18:59:29 +010054
Harald Welte7484fc42018-02-24 14:09:45 +010055import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010056import from MobileL3_RRM_Types all;
57import from MobileL3_Types all;
58import from L3_Templates all;
Harald Welteeaa9a862019-05-26 23:01:08 +020059import from L3_Common all;
60import from MobileL3_GMM_SM_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010061
Harald Welte8da48242018-02-27 20:41:32 +010062import from Osmocom_VTY_Functions all;
63import from TELNETasp_PortType all;
Harald Welte2f2b2b72019-05-31 22:24:57 +020064import from BTS_Tests_LAPDm all;
Harald Welte8da48242018-02-27 20:41:32 +010065
Harald Welte505cf9b2018-09-15 17:47:23 +030066friend module BTS_Tests_SMSCB;
Harald Weltead033dc2019-05-25 17:28:16 +020067friend module BTS_Tests_virtphy;
Harald Welte2f2b2b72019-05-31 22:24:57 +020068friend module BTS_Tests_LAPDm;
Harald Welte505cf9b2018-09-15 17:47:23 +030069
Harald Welte70767382018-02-21 12:16:40 +010070/* The tests assume a BTS with the following timeslot configuration:
71 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020072 * TS1 : TCH/F
73 * TS2 : TCH/F
74 * TS3 : TCH/F_PDCH (IPA Style)
75 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010076 * TS5 : TCH/H
77 * TS6 : SDCCH/8
78 * TS7 : PDCH
79 */
80
81modulepar {
82 charstring mp_rsl_ip := "127.0.0.2";
83 integer mp_rsl_port := 3003;
84 integer mp_trx0_arfcn := 871;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070085 charstring mp_bts_trxc_ip := "127.0.0.1";
86 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010087 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020088 charstring mp_ctrl_ip := "127.0.0.1";
89 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020090 charstring mp_bsc_ctrl_ip := "127.0.0.1";
91 integer mp_bsc_ctrl_port := 4249;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020092 integer mp_tolerance_rxqual := 1;
93 integer mp_tolerance_rxlev := 3;
94 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +020095 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +020096 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +020097 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020098 integer mp_ms_actual_ta_exp := 0;
99 integer mp_timing_offset_256syms_exp := 512;
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100100 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200101 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200102 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200103 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
104 boolean mp_l1_supports_gprs := false;
Harald Welte70767382018-02-21 12:16:40 +0100105}
106
Harald Welte629cc6b2018-03-11 17:19:05 +0100107type record of RslChannelNr ChannelNrs;
108
Harald Welte70767382018-02-21 12:16:40 +0100109type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100110 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100111 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100112 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100113 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100114 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100115 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100116
117 /* L1CTL port (for classic tests) */
118 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100119
Harald Welte54a2a2d2018-02-26 09:14:05 +0100120 /* TRXC port (for classic tests) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700121 port TRXC_CODEC_PT BTS_TRXC;
122 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100123
Harald Weltef50e3ae2018-09-10 10:27:56 +0200124 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100125 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200126 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100127
Harald Welte883340c2018-02-28 18:59:29 +0100128 /* PCU Interface of BTS */
129 port PCUIF_CODEC_PT PCU;
130 var integer g_pcu_conn_id;
131 /* Last PCU INFO IND we received */
132 var PCUIF_Message g_pcu_last_info;
133
Harald Welte48494ca2018-02-25 16:59:50 +0100134 /* SI configuration */
135 var SystemInformationConfig si_cfg := {
136 bcch_extended := false,
137 si1_present := false,
138 si2bis_present := false,
139 si2ter_present := false,
140 si2quater_present := false,
141 si7_present := false,
142 si8_present := false,
143 si9_present := false,
144 si13_present := false,
145 si13alt_present := false,
146 si15_present := false,
147 si16_present := false,
148 si17_present := false,
149 si2n_present := false,
150 si21_present := false,
151 si22_present := false
152 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100153
154 /* all logical channels available on the BTS */
155 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100156 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100157}
158
159/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200160type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100161 port L1CTL_PT L1CTL;
162
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700163 port TRXC_CODEC_PT BTS_TRXC;
164 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100165
166 timer g_Tguard;
167 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
168
169 var ConnHdlrPars g_pars;
170 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100171 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200172
173 /* PCU Interface of BTS */
174 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100175}
176
177function f_init_rsl(charstring id) runs on test_CT {
178 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
179 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
180
181 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
182 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
183 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
184
185 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
186 vc_RSL.start(RSL_Emulation.main(false));
187}
188
189type record ConnHdlrPars {
190 RslChannelNr chan_nr,
191 RSL_IE_ChannelMode chan_mode,
192 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100193 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200194 TestSpecUnion spec optional,
195 RSL_IE_EncryptionInfo encr optional
Harald Welte0472ab42018-03-12 15:02:26 +0100196}
197
198/* Test-specific parameters */
199type union TestSpecUnion {
200 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100201}
202
Harald Welte82ccef72018-02-25 16:17:33 +0100203template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100204 max_retrans := RACH_MAX_RETRANS_7,
205 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100206 cell_barr_access := false,
207 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100208 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100209};
210
Harald Weltef10153f2018-02-25 16:34:05 +0100211template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100212 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200213 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100214 acs := '0'B,
215 neci := true,
216 rxlev_access_min := 0
217}
218
219template (value) LocationAreaIdentification ts_LAI_default := {
220 mcc_mnc := '262F42'H,
221 lac := 42
222}
223
Harald Welte7484fc42018-02-24 14:09:45 +0100224/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100225template (value) SystemInformation ts_SI3_default := {
226 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100227 payload := {
228 si3 := {
229 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100230 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100231 ctrl_chan_desc := {
232 msc_r99 := true,
233 att := true,
234 bs_ag_blks_res := 1,
235 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100236 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100237 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
238 spare := '00'B,
239 bs_pa_mfrms := 0, /* 2 multiframes */
240 t3212 := 1 /* 6 minutes */
241 },
Harald Welte82ccef72018-02-25 16:17:33 +0100242 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100243 dn_ind := false,
244 pwrc := false,
245 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100246 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100247 },
Harald Weltef10153f2018-02-25 16:34:05 +0100248 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100249 rach_control := ts_RachCtrl_default,
Harald Weltebe030482019-05-27 22:29:35 +0200250 rest_octets := '2C2B2B2B'O /* GPRS present */
Harald Welte7484fc42018-02-24 14:09:45 +0100251 }
252 }
253}
Harald Welte70767382018-02-21 12:16:40 +0100254
Harald Weltef8df4cb2018-03-10 15:15:08 +0100255template (value) SystemInformation ts_SI2_default := {
256 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100257 payload := {
258 si2 := {
259 bcch_freq_list := '00000000000000000000000000000000'O,
260 ncc_permitted := '11111111'B,
261 rach_control := ts_RachCtrl_default
262 }
263 }
264}
265
Harald Weltef8df4cb2018-03-10 15:15:08 +0100266template (value) SystemInformation ts_SI4_default := {
267 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100268 payload := {
269 si4 := {
270 lai := ts_LAI_default,
271 cell_sel_par := ts_CellSelPar_default,
272 rach_control := ts_RachCtrl_default,
273 cbch_chan_desc := omit,
274 cbch_mobile_alloc := omit,
275 rest_octets := ''O
276 }
277 }
278}
279
280function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
281runs on test_CT {
282 log("Setting ", rsl_si_type, ": ", si_enc);
283 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
284}
285
286function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
287runs on test_CT {
288 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
289 log("Setting ", rsl_si_type, ": ", si_dec);
290 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
291}
292
Harald Welte505cf9b2018-09-15 17:47:23 +0300293friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100294 map(self:BTSVTY, system:BTSVTY);
295 f_vty_set_prompts(BTSVTY);
296 f_vty_transceive(BTSVTY, "enable");
297}
298
Harald Welte505cf9b2018-09-15 17:47:23 +0300299friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200300 map(self:BSCVTY, system:BSCVTY);
301 f_vty_set_prompts(BSCVTY, "OsmoBSC");
302 f_vty_transceive(BSCVTY, "enable");
303}
304
Harald Welte883340c2018-02-28 18:59:29 +0100305/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200306private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
307 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100308 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200309 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
310 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100311 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200312 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200313 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100314 }
315}
316
Harald Weltef26de0b2018-04-04 20:28:05 +0200317private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
318 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100319 timer T := 2.0;
320 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100321 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200322 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100323 return;
324 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200325 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100326
327 T.start;
328 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200329 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100330 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200331 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100332 }
333 }
334}
335
Harald Welte70767382018-02-21 12:16:40 +0100336/* global init function */
Harald Welte10474062019-05-30 16:48:17 +0200337function f_init() runs on test_CT {
338 var charstring id := testcasename();
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100339 timer T := mp_ipa_up_timeout;
Harald Welte629cc6b2018-03-11 17:19:05 +0100340 g_AllChannels := {
341 /* TS 1..4: TCH/F */
342 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
343 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
344 /* TS 5: TCH/H */
345 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
346 /* TS 0: SDCCH/4 */
347 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
348 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
349 /* TS 6: SDCCH/8 */
350 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
351 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
352 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
353 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
354 };
355
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200356 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700357 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200358 g_AllChanTypes := {
359 /* TS 1..4: TCH/F */
360 valueof(ts_RslChanNr_Bm(1)),
361 /* TS 5: TCH/H */
362 valueof(ts_RslChanNr_Lm(5,1)),
363 /* TS 0: SDCCH/4 */
364 valueof(ts_RslChanNr_SDCCH4(0,2)),
365 /* TS 6: SDCCH/8 */
366 valueof(ts_RslChanNr_SDCCH8(6,4))
367 };
368 } else {
369 g_AllChanTypes := {
370 /* TS 1..4: TCH/F */
371 valueof(ts_RslChanNr_Bm(1)),
372 /* TS 0: SDCCH/4 */
373 valueof(ts_RslChanNr_SDCCH4(0,2)),
374 /* TS 6: SDCCH/8 */
375 valueof(ts_RslChanNr_SDCCH8(6,4))
376 };
377 }
Harald Welte70767382018-02-21 12:16:40 +0100378 f_init_rsl(id);
Harald Welte83f6dbf2018-06-03 18:26:50 +0200379 T.start;
380 alt {
381 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
382 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200383 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
Harald Welte83f6dbf2018-06-03 18:26:50 +0200384 }
385 }
Harald Welte2d142592018-02-25 13:19:44 +0100386 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100387 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200388 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100389
390 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100391 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
392 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
393 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
394 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100395
Harald Weltef26de0b2018-04-04 20:28:05 +0200396 map(self:PCU, system:PCU);
397 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100398
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700399 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100400 var TrxcMessage ret;
401 /* start with a default moderate timing offset equalling TA=2 */
402 f_main_trxc_connect();
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700403 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(2*256)));
Harald Welte84271622018-03-10 17:21:03 +0100404 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200405
406 /* Wait some extra time to make sure the BTS emits a stable carrier.
407 * (this is only relevant when running the tests with a physical BTS.) */
408 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100409}
410
Harald Welte68e495b2018-02-25 00:05:57 +0100411/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
412function f_init_l1ctl() runs on test_CT {
413 map(self:L1CTL, system:L1CTL);
414 f_connect_reset(L1CTL);
415}
416
Harald Welte70767382018-02-21 12:16:40 +0100417type function void_fn(charstring id) runs on ConnHdlr;
418
419/* create a new test component */
Harald Weltef26de0b2018-04-04 20:28:05 +0200420function f_start_handler(void_fn fn, ConnHdlrPars pars, boolean pcu_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100421runs on test_CT return ConnHdlr {
422 var charstring id := testcasename();
423 var ConnHdlr vc_conn;
424
425 vc_conn := ConnHdlr.create(id);
426 /* connect to RSL Emulation main component */
427 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
428 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Harald Weltef26de0b2018-04-04 20:28:05 +0200429 if (pcu_comp) {
430 /* the ConnHdlr component wants to talk directly to the PCU, so disconnect
431 * it from the test_CT and connect it to the component. This obviously only
432 * works for one component, i.e. no concurrency */
433 unmap(self:PCU, system:PCU);
434 map(vc_conn:PCU, system:PCU);
435 }
Harald Welte70767382018-02-21 12:16:40 +0100436
437 vc_conn.start(f_handler_init(fn, id, pars));
438 return vc_conn;
439}
440
Harald Welte7484fc42018-02-24 14:09:45 +0100441template ASP_RSL_Unitdata ts_RSL_UD(template RSL_Message rsl, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
442 streamId := sid,
443 rsl := rsl
444}
445
446template ASP_RSL_Unitdata tr_RSL_UD(template RSL_Message rsl,
447 template IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
448 streamId := sid,
449 rsl := rsl
450}
451
Harald Welte70767382018-02-21 12:16:40 +0100452private altstep as_Tguard() runs on ConnHdlr {
453 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200454 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100455 }
456}
457
Harald Welte990a3612019-05-27 14:02:13 +0200458friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
459 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100460}
461
462private function f_trxc_connect() runs on ConnHdlr {
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700463 map(self:BTS_TRXC, system:BTS_TRXC);
Harald Welte70767382018-02-21 12:16:40 +0100464 var Result res;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700465 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BTS_TRXC, mp_bts_trxc_ip, mp_bts_trxc_port,
Harald Weltea4d8f352018-03-01 15:47:20 +0100466 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +0200467 if (not ispresent(res.connId)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200468 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Could not connect to trx-control interface of trxcon, check your configuration");
Harald Welte9220f632018-05-23 20:27:02 +0200469 }
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700470 g_bts_trxc_conn_id := res.connId;
Harald Welte70767382018-02-21 12:16:40 +0100471}
472
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700473private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100474 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700475 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100476}
477
478private function f_trx_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100479 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700480 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100481}
482
483/* first function started in ConnHdlr component */
484private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
485runs on ConnHdlr {
486 g_pars := pars;
487 g_chan_nr := pars.chan_nr;
488
489 map(self:L1CTL, system:L1CTL);
490 f_connect_reset(L1CTL);
491
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700492 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100493 f_trxc_connect();
494 }
Harald Welte70767382018-02-21 12:16:40 +0100495
496 g_Tguard.start(pars.t_guard);
497 activate(as_Tguard());
498
499 f_rslem_register(0, pars.chan_nr);
500
501 /* call the user-supplied test case function */
502 fn.apply(id);
503}
504
Harald Welteb1726c92018-03-30 11:56:38 +0200505function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
506 boolean ignore_other := false)
507runs on ConnHdlr return RSL_Message {
508 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100509 timer T := 3.0;
510 RSL.send(tx);
511 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100512 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200513 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100514 T.stop;
515 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100516 }
Harald Welte1eba3742018-02-25 12:48:14 +0100517 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200518 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100519 }
Harald Welte21240e62018-03-11 21:43:35 +0100520 [not ignore_other] as_l1_sacch();
521 [not ignore_other] as_meas_res();
522 [not ignore_other] as_l1_dcch();
523 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200524 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100525 }
Harald Welte21240e62018-03-11 21:43:35 +0100526 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100527 }
Harald Welteb1726c92018-03-30 11:56:38 +0200528 return rx;
529}
530
531function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
532 boolean ignore_other := false)
533runs on ConnHdlr {
534 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100535}
536
Harald Welte8b01c792019-05-19 22:51:25 +0200537function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false, RSL_IE_List more_ies := {},
538 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA) runs on ConnHdlr {
539 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200540 if (encr_enable) {
541 /* append encryption related IEs, if requested */
542 var RSL_IE_EncryptionInfo encr_info;
543 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
544 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
545encr_info})) };
546 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200547 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200548 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100549}
550
Harald Welte70767382018-02-21 12:16:40 +0100551function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100552 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
Harald Welte21240e62018-03-11 21:43:35 +0100553 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100554}
555
Harald Welte2f2b2b72019-05-31 22:24:57 +0200556friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100557 template RSL_IE_ChannelMode chan_mode,
558 float t_guard := 20.0) := {
559 chan_nr := valueof(chan_nr),
560 chan_mode := valueof(chan_mode),
561 t_guard := t_guard,
562 l1_pars := {
563 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100564 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100565 meas_ul := {
566 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200567 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100568 rxqual := 0
569 },
570 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200571 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100572 rxqual := 0
573 }
574 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200575 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100576 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200577 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200578 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100579 },
Harald Weltee613f962018-04-18 22:38:16 +0200580 spec := omit,
581 encr := omit
Harald Welte70767382018-02-21 12:16:40 +0100582}
583
Harald Welte93640c62018-02-25 16:59:33 +0100584/***********************************************************************
585 * Channel Activation / Deactivation
586 ***********************************************************************/
587
Harald Welte70767382018-02-21 12:16:40 +0100588/* Stress test: Do 500 channel activations/deactivations in rapid succession */
589function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
590 for (var integer i := 0; i < 500; i := i+1) {
591 f_rsl_chan_act(g_pars.chan_mode);
592 f_rsl_chan_deact();
593 }
594 setverdict(pass);
595}
596testcase TC_chan_act_stress() runs on test_CT {
597 var ConnHdlr vc_conn;
598 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200599 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100600 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
601 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200602 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100603}
604
605/* Test if re-activation of an already active channel fails as expected */
606function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
607 f_rsl_chan_act(g_pars.chan_mode);
608 /* attempt to activate the same lchan again -> expect reject */
609 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
610 alt {
611 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200612 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100613 }
614 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
615 setverdict(pass);
616 }
617 }
618 f_rsl_chan_deact();
619}
620testcase TC_chan_act_react() runs on test_CT {
621 var ConnHdlr vc_conn;
622 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100623 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100624 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
625 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200626 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100627}
628
629/* Attempt to de-activate a channel that's not active */
630function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
631 timer T := 3.0;
632 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
633 T.start;
634 alt {
635 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
636 setverdict(pass);
637 }
638 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200639 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100640 }
641 }
642}
643testcase TC_chan_deact_not_active() runs on test_CT {
644 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100645 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100646 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
647 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200648 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100649}
650
651/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
652function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
653 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
654 alt {
655 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200656 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100657 }
658 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
659 setverdict(pass);
660 }
661 }
662}
663private type record WrongChanNrCase {
664 RslChannelNr chan_nr,
665 charstring description
666}
667private type record of WrongChanNrCase WrongChanNrCases;
668private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
669 chan_nr := chan_nr,
670 description := desc
671}
672
673testcase TC_chan_act_wrong_nr() runs on test_CT {
674 var ConnHdlr vc_conn;
675 var ConnHdlrPars pars;
676
Harald Welte294b0a22018-03-10 23:26:48 +0100677 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100678
679 var WrongChanNrCases wrong := {
680 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
681 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
682 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
683 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
684 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
685 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
686 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
687 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
688 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
689 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
690 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
691 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
692 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
693 };
694
695 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
696 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
697 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
698 vc_conn.done;
699 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200700 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100701}
702
Harald Weltee613f962018-04-18 22:38:16 +0200703/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200704friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200705 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200706 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200707
708 /* test on each of the channels we have */
709 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
710 pars.chan_nr := valueof(g_AllChanTypes[i]);
711
712 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
713 vc_conn := f_start_handler(fn, pars);
714 vc_conn.done;
715 }
716
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200717 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200718}
719
Harald Welte93640c62018-02-25 16:59:33 +0100720/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100721 * SACCH handling
722 ***********************************************************************/
723
724private function f_exp_sacch(boolean exp) runs on ConnHdlr {
725 timer T_sacch := 3.0;
726 T_sacch.start;
727 alt {
728 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200729 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100730 }
731 [not exp] T_sacch.timeout {
732 setverdict(pass);
733 }
734 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
735 setverdict(pass);
736 }
737 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200738 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100739 }
740 [] L1CTL.receive { repeat; }
741 [] RSL.receive { repeat; }
742 }
743}
744
745/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
746private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
747 f_l1_tune(L1CTL);
748 RSL.clear;
749
750 /* activate the logical channel */
751 f_est_dchan();
752 L1CTL.clear;
753
754 /* check that SACCH actually are received as expected */
755 f_exp_sacch(true);
756
757 /* deactivate SACCH on the logical channel */
758 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
759 f_sleep(1.0);
760 L1CTL.clear;
761
762 /* check that no SACCH are received anymore */
763 f_exp_sacch(false);
764
765 /* release the channel */
766 f_rsl_chan_deact();
767 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
768}
769testcase TC_deact_sacch() runs on test_CT {
770 var ConnHdlr vc_conn;
771 var ConnHdlrPars pars;
772 f_init();
773 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
774 //for (var integer i := 0; i < 1; i := i+1) {
775 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
776 log(testcasename(), ": Starting for ", g_AllChannels[i]);
777 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
778 vc_conn.done;
779 }
780 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200781 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100782}
783
Harald Welte55700662018-03-12 13:15:43 +0100784/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100785private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
786 var L1ctlDlMessage dl;
787 /* check that the specified SI5 value is actually sent */
788 timer T_sacch := 3.0;
789 L1CTL.clear;
790 T_sacch.start;
791 alt {
792 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
793 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
794 if (match(l3, l3_exp)) {
795 setverdict(pass);
796 } else {
797 repeat;
798 }
799 }
800 [] L1CTL.receive { repeat; }
801 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200802 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100803 }
804 }
805}
806
Harald Welte55700662018-03-12 13:15:43 +0100807/* verify that given SACCH payload is not present */
808private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
809 var L1ctlDlMessage dl;
810 /* check that the specified SI5 value is actually sent */
811 timer T_sacch := 3.0;
812 L1CTL.clear;
813 T_sacch.start;
814 alt {
815 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
816 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
817 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200818 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100819 } else {
820 repeat;
821 }
822 }
823 [] L1CTL.receive { repeat; }
824 [] T_sacch.timeout {
825 setverdict(pass);
826 }
827 }
828}
829
Harald Welte629cc6b2018-03-11 17:19:05 +0100830/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100831private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
832 /* Set a known default SACCH filling for SI5 */
833 var octetstring si5 := f_rnd_octstring(19);
834 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
835
836 f_l1_tune(L1CTL);
837 RSL.clear;
838
839 /* activate the logical channel */
840 f_est_dchan();
841
842 /* check that the specified SI5 value is actually sent */
843 f_sacch_present(si5);
844
845 /* release the channel */
846 RSL.clear;
847 f_rsl_chan_deact();
848 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
849}
850testcase TC_sacch_filling() runs on test_CT {
851 var ConnHdlr vc_conn;
852 var ConnHdlrPars pars;
853 f_init();
854 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
855 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
856 log(testcasename(), ": Starting for ", g_AllChannels[i]);
857 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
858 vc_conn.done;
859 }
860 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200861 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100862}
863
Harald Welte629cc6b2018-03-11 17:19:05 +0100864/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100865private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
866 /* Set a known default SACCH filling for SI5 */
867 var octetstring si5 := f_rnd_octstring(19);
868 var octetstring si5_diff := f_rnd_octstring(19);
869 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
870
871 f_l1_tune(L1CTL);
872 RSL.clear;
873
874 log("Activating channel, expecting standard SI5");
875 /* activate the logical channel */
876 f_est_dchan();
877 /* check that the specified SI5 value is actually sent */
878 f_sacch_present(si5);
879
880 /* set channel-specific different SI5 */
881 log("Setting channel specific SACCH INFO, expecting it");
882 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
883 /* check that the specified lchan-specific value is now used */
884 f_sacch_present(si5_diff);
885
886 /* deactivate the channel and re-activate it, this should result in default SI5 */
887 log("De-activating and re-activating channel, expecting standard SI5");
888 f_rsl_chan_deact();
889 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
890 /* Verify that the TRX-wide default SACCH filling is present again */
891 f_sacch_present(si5);
892
893 /* release the channel */
894 RSL.clear;
895 f_rsl_chan_deact();
896 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
897}
898testcase TC_sacch_info_mod() runs on test_CT {
899 var ConnHdlr vc_conn;
900 var ConnHdlrPars pars;
901 f_init();
902 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
903 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
904 log(testcasename(), ": Starting for ", g_AllChannels[i]);
905 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
906 vc_conn.done;
907 }
908 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200909 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100910}
911
Harald Welte075d84c2018-03-12 13:07:24 +0100912/* Test SACCH scheduling of multiple different SI message types */
913private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
914 var octetstring si5 := f_rnd_octstring(19);
915 var octetstring si5bis := f_rnd_octstring(19);
916 var octetstring si5ter := f_rnd_octstring(19);
917 var octetstring si6 := f_rnd_octstring(19);
918
919 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
920 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
921 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
922 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
923
924 f_l1_tune(L1CTL);
925 RSL.clear;
926
927 /* activate the logical channel */
928 f_est_dchan();
929 L1CTL.clear;
930
931 /* check that SACCH actually are received as expected */
932 f_sacch_present(si5);
933 f_sacch_present(si5bis);
934 f_sacch_present(si5ter);
935 f_sacch_present(si6);
936
937 /* release the channel */
938 f_rsl_chan_deact();
939 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
940}
941testcase TC_sacch_multi() runs on test_CT {
942 var ConnHdlr vc_conn;
943 var ConnHdlrPars pars;
944 f_init();
945 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
946 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
947 log(testcasename(), ": Starting for ", g_AllChannels[i]);
948 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
949 vc_conn.done;
950 }
951 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200952 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +0100953}
954
Harald Welte55700662018-03-12 13:15:43 +0100955/* Test if SACH information is modified as expected */
956private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
957 var octetstring si5 := f_rnd_octstring(19);
958 var octetstring si6 := f_rnd_octstring(19);
959
960 /* First, configure both SI5 and SI6 to be transmitted */
961 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
962 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
963
964 f_l1_tune(L1CTL);
965 RSL.clear;
966
967 /* activate the logical channel */
968 f_est_dchan();
969 L1CTL.clear;
970
971 /* check that SACCH actually are received as expected */
972 f_sacch_present(si5);
973 f_sacch_present(si6);
974
975 /* disable SI6 */
976 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
977
978 /* check that SI5 is still transmitted */
979 f_sacch_present(si5);
980 /* check if SI6 is now gone */
981 f_sacch_missing(si6);
982
983 /* release the channel */
984 f_rsl_chan_deact();
985 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
986}
987testcase TC_sacch_multi_chg() runs on test_CT {
988 var ConnHdlr vc_conn;
989 var ConnHdlrPars pars;
990 f_init();
991 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
992 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
993 log(testcasename(), ": Starting for ", g_AllChannels[i]);
994 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
995 vc_conn.done;
996 }
997 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200998 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +0100999}
1000
Harald Weltec8d363c2019-05-19 20:36:48 +02001001/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1002private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1003 var octetstring si5 := f_rnd_octstring(19);
1004 var octetstring si6 := f_rnd_octstring(19);
1005 var octetstring si5_specific := f_rnd_octstring(19);
1006 var octetstring si6_specific := f_rnd_octstring(19);
1007
1008 /* First, configure both SI5 and SI6 to be transmitted */
1009 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1010 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1011
1012 f_l1_tune(L1CTL);
1013 RSL.clear;
1014
1015 /* activate channel with different SACCH filling */
1016 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1017 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1018 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1019 }));
1020 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1021 RSL_IE_Body:{sacch_info := sacch_info})) };
1022 f_est_dchan(more_ies := addl_ies);
1023
1024 /* check that SACCH actually are received as expected */
1025 f_sacch_present(si5_specific);
1026 f_sacch_present(si6_specific);
1027
1028 /* release the channel */
1029 f_rsl_chan_deact();
1030 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1031}
1032testcase TC_sacch_chan_act() runs on test_CT {
1033 var ConnHdlr vc_conn;
1034 var ConnHdlrPars pars;
1035 f_init();
1036
1037 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1038 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1039 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1040 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1041 vc_conn.done;
1042 }
1043 /* TODO: do the above in parallel, rather than sequentially? */
1044 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1045}
1046
Harald Welte8b01c792019-05-19 22:51:25 +02001047/* verify that SACCH DL transmission is started only if MS power IE present
1048 * see section 4.1.3 of 3GPP TS 48.058 */
1049private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1050 var octetstring si5 := f_rnd_octstring(19);
1051
1052 f_l1_tune(L1CTL);
1053 RSL.clear;
1054
1055 /* Step 1: Activate ASYNC HO channel without MS power IE */
1056
1057 /* Activate channel on BTS side */
1058 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1059 /* don't perform immediate assignment here, as we're testing non-IA case */
1060 /* enable dedicated mode */
1061 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1062
1063 /* Verify that no DL SACCH is being received */
1064 f_sacch_missing(?);
1065
1066 f_rsl_chan_deact();
1067 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1068
1069
1070 /* Step 2: Activate ASYNC HO channel with MS power IE */
1071
1072 /* Activate channel on BTS side */
1073 var RSL_IE_List addl_ies := {
1074 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1075 };
1076 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1077 /* don't perform immediate assignment here, as we're testing non-IA case */
1078 /* enable dedicated mode */
1079 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1080
1081 /* Verify that DL SACCH is being received */
1082 f_sacch_present(si5);
1083
1084 f_rsl_chan_deact();
1085 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1086}
1087testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1088 var ConnHdlr vc_conn;
1089 var ConnHdlrPars pars;
1090 f_init();
1091
1092 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1093 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1094 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1095 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1096 vc_conn.done;
1097 }
1098 /* TODO: do the above in parallel, rather than sequentially? */
1099 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1100}
1101
1102/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1103 * see section 4.1.4 of 3GPP TS 48.058 */
1104private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1105 var octetstring si5 := f_rnd_octstring(19);
1106 var RSL_IE_List addl_ies;
1107
1108 f_l1_tune(L1CTL);
1109 RSL.clear;
1110
1111 /* Step 1: Activate SYNC HO channel without MS power IE */
1112
1113 /* Activate channel on BTS side */
1114 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1115 /* don't perform immediate assignment here, as we're testing non-IA case */
1116 /* enable dedicated mode */
1117 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1118
1119 /* Verify that no DL SACCH is being received */
1120 f_sacch_missing(?);
1121
1122 f_rsl_chan_deact();
1123 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1124
1125
1126 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1127
1128 /* Activate channel on BTS side */
1129 addl_ies := {
1130 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1131 };
1132 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1133 /* don't perform immediate assignment here, as we're testing non-IA case */
1134 /* enable dedicated mode */
1135 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1136
1137 /* Verify that no DL SACCH is being received */
1138 f_sacch_missing(?);
1139
1140 f_rsl_chan_deact();
1141 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1142
1143
1144 /* Step 2b: Activate SYNC HO channel with TA IE */
1145
1146 /* Activate channel on BTS side */
1147 addl_ies := {
1148 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1149 };
1150 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1151 /* don't perform immediate assignment here, as we're testing non-IA case */
1152 /* enable dedicated mode */
1153 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1154
1155 /* Verify that no DL SACCH is being received */
1156 f_sacch_missing(?);
1157
1158 f_rsl_chan_deact();
1159 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1160
1161
1162 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1163
1164 /* Activate channel on BTS side */
1165 addl_ies := {
1166 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1167 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1168 };
1169 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1170 /* don't perform immediate assignment here, as we're testing non-IA case */
1171 /* enable dedicated mode */
1172 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1173
1174 /* Verify that DL SACCH is being received */
1175 f_sacch_present(si5);
1176
1177 f_rsl_chan_deact();
1178 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1179}
1180testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1181 var ConnHdlr vc_conn;
1182 var ConnHdlrPars pars;
1183 f_init();
1184
1185 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1186 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1187 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1188 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1189 vc_conn.done;
1190 }
1191 /* TODO: do the above in parallel, rather than sequentially? */
1192 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1193}
Harald Welte629cc6b2018-03-11 17:19:05 +01001194
1195
1196/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001197 * RACH Handling
1198 ***********************************************************************/
1199
Harald Welte8c24c2b2018-02-26 08:31:31 +01001200/* like L1SAP_IS_PACKET_RACH */
1201private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +01001202 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001203 return true;
1204 }
1205 return false;
1206}
1207
1208/* generate a random RACH for circuit-switched */
1209private function f_rnd_ra_cs() return OCT1 {
1210 var OCT1 ra;
1211 do {
1212 ra := f_rnd_octstring(1);
1213 } while (ra_is_ps(ra));
1214 return ra;
1215}
1216
Harald Welte883340c2018-02-28 18:59:29 +01001217/* generate a random RACH for packet-switched */
1218private function f_rnd_ra_ps() return OCT1 {
1219 var OCT1 ra;
1220 do {
1221 ra := f_rnd_octstring(1);
1222 } while (not ra_is_ps(ra));
1223 return ra;
1224}
1225
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07001226/* generate a random 11-bit RA (packet-switched only) */
1227private function f_rnd_ra11_ps() return BIT11 {
1228 var integer ra11 := f_rnd_int(bit2int('11111111111'B));
1229 return int2bit(ra11, 11);
1230}
1231
Harald Welte8c24c2b2018-02-26 08:31:31 +01001232/* Send 1000 RACH requests and check their RA+FN on the RSL side */
1233testcase TC_rach_content() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001234 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001235 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001236 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001237
Harald Welte8c24c2b2018-02-26 08:31:31 +01001238 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001239 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001240 for (var integer i := 0; i < 1000; i := i+1) {
1241 var OCT1 ra := f_rnd_ra_cs();
1242 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1243 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001244 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001245 }
1246 fn_last := fn;
1247
1248 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001249 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001250 alt {
Vadim Yanitskiyab448a52019-05-31 20:24:03 +07001251 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001252 T.stop;
1253 }
Vadim Yanitskiyab448a52019-05-31 20:24:03 +07001254 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001255 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001256 }
1257 [] RSL_CCHAN.receive { repeat; }
1258 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001259 test_failed := true;
1260 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001261 }
1262 }
1263 }
Maxba06feb2019-03-05 10:52:46 +01001264 if (test_failed) {
1265 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001266 }
Maxba06feb2019-03-05 10:52:46 +01001267 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001268 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001269}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001270
1271/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1272testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001273 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001274 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001275 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001276 f_l1_tune(L1CTL);
1277
1278 var GsmFrameNumber fn_last := 0;
1279 for (var integer i := 0; i < 1000; i := i+1) {
1280 var OCT1 ra := f_rnd_ra_cs();
1281 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1282 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001283 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001284 }
1285 fn_last := fn;
1286 }
1287 var integer rsl_chrqd := 0;
1288 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001289 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001290 alt {
1291 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
1292 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001293 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001294 repeat;
1295 }
1296 [] RSL_CCHAN.receive { repeat; }
1297 [] T.timeout { }
1298 }
1299 if (rsl_chrqd == 1000) {
1300 setverdict(pass);
1301 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001302 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001303 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001304 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001305}
1306
Harald Welte3453ab42019-05-24 21:19:58 +02001307private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1308 var charstring bts_str := "bts " & int2str(bts_nr);
1309 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1310}
1311
1312/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1313private template integer tr_rach_slots_per_interval := (90 .. 130);
1314
1315/* Expect 0 RACH load on an idle BTS that has just started up */
1316testcase TC_rach_load_idle_thresh0() runs on test_CT {
1317 var ASP_RSL_Unitdata rx_ud;
1318
1319 f_init_vty_bsc();
1320 /* send load indications even at 0% load */
1321 f_vty_load_ind_thresh(0);
1322 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1323 f_sleep(2.0);
1324
1325 f_init();
1326
1327 timer T := 5.0;
1328 T.start;
1329 alt {
1330 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, 0, 0))) {
1331 setverdict(pass);
1332 repeat;
1333 }
1334 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1335 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1336 repeat;
1337 }
1338 [] RSL_CCHAN.receive {
1339 repeat;
1340 }
1341 [] T.timeout { }
1342 }
1343
1344 f_vty_load_ind_thresh(10);
1345 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1346}
1347
1348/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1349testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1350 var ASP_RSL_Unitdata rx_ud;
1351
1352 f_init_vty_bsc();
1353 f_init();
1354
1355 timer T := 5.0;
1356 T.start;
1357 alt {
1358 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1359 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1360 repeat;
1361 }
1362 [] RSL_CCHAN.receive {
1363 repeat;
1364 }
1365 [] T.timeout {
1366 setverdict(pass);
1367 }
1368 }
1369
1370 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1371}
1372
1373/* Expect 0 RACH load on an idle BTS that has just started up */
1374testcase TC_rach_load_count() runs on test_CT {
1375 var ASP_RSL_Unitdata rx_ud;
1376 var integer load_access_count := 0;
1377
1378 f_init_vty_bsc();
1379 /* send load indications even at 0% load */
1380 f_vty_load_ind_thresh(0);
1381 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1382 f_sleep(2.0);
1383 f_init();
1384
1385 f_init_l1ctl();
1386 f_sleep(1.0);
1387 f_l1_tune(L1CTL);
1388
1389 var GsmFrameNumber fn_last := 0;
1390 for (var integer i := 0; i < 1000; i := i+1) {
1391 var OCT1 ra := f_rnd_ra_cs();
1392 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1393 if (fn == fn_last) {
1394 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1395 }
1396 fn_last := fn;
1397 }
1398
1399 timer T := 5.0;
1400 T.start;
1401 alt {
1402 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
1403 -> value rx_ud {
1404 var RSL_IE_Body ie;
1405 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1406 load_access_count := load_access_count + ie.rach_load.access_count;
1407 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1408 setverdict(fail, "Access count cannot be < Busy count");
1409 }
1410 repeat;
1411 }
1412 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1413 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1414 repeat;
1415 }
1416 [] RSL_CCHAN.receive {
1417 repeat;
1418 }
1419 [] T.timeout { }
1420 }
1421 if (load_access_count == 1000) {
1422 setverdict(pass);
1423 } else {
1424 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1425 }
1426
1427 f_vty_load_ind_thresh(10);
1428 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1429}
1430
1431
1432
Harald Welte54a2a2d2018-02-26 09:14:05 +01001433private function f_main_trxc_connect() runs on test_CT {
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001434 map(self:BTS_TRXC, system:BTS_TRXC);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001435 var Result res;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001436 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BTS_TRXC, mp_bts_trxc_ip, mp_bts_trxc_port,
Harald Welted3a88a62018-03-01 16:04:52 +01001437 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +02001438 if (not ispresent(res.connId)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001439 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Could not connect to trx-control interface of trxcon, check your configuration");
Harald Welte9220f632018-05-23 20:27:02 +02001440 }
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001441 g_bts_trxc_conn_id := res.connId;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001442}
1443
1444private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001445 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001446 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001447 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001448 f_sleep(0.5);
1449
1450 /* Transmit RACH request + wait for confirmation */
1451 var OCT1 ra := f_rnd_ra_cs();
1452 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1453
1454 /* Check for expected result */
1455 timer T := 1.5;
1456 T.start;
1457 alt {
1458 [expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
1459 setverdict(pass);
1460 }
1461 [not expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001462 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001463 }
1464 [] RSL_CCHAN.receive { repeat; }
1465 [not expect_pass] T.timeout {
1466 setverdict(pass);
1467 }
1468 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001469 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001470 }
1471 }
1472}
1473
1474/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1475testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001476 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001477 f_init_l1ctl();
1478 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001479 f_sleep(1.0);
1480
1481 /* default max-ta is 63 (full range of GSM timing advance */
1482
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001483 /* We allow early arrival up to 2 symbols */
1484 f_rach_toffs(-1*256, true);
1485 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001486 f_rach_toffs(-10*256, false);
1487
1488 /* 0 / 32 / 63 bits is legal / permitted */
1489 f_rach_toffs(0, true);
1490 f_rach_toffs(32*256, true);
1491 f_rach_toffs(63*256, true);
1492
1493 /* more than 63 bits is not legal / permitted */
1494 f_rach_toffs(64*256, false);
1495 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001496 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001497}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001498
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001499function f_TC_ho_rach(charstring id) runs on ConnHdlr {
1500 var GsmFrameNumber fn;
1501 var RSL_Message rm;
1502
1503 f_l1_tune(L1CTL);
1504 RSL.clear;
1505
1506 /* Generate a random Handover Reference */
1507 var integer ho_ref := oct2int(f_rnd_octstring(1));
1508
1509 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1510 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1511 RSL_IE_Body:{ handover_ref := ho_ref }));
1512
1513 /* Activate a channel on the BTS side (no encryption) */
1514 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1515 act_type := t_RSL_IE_ActType_HO_SYNC);
1516
1517 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1518 * waiting for Immediate Assignment and sending Access Burst */
1519 f_L1CTL_DM_EST_REQ(L1CTL, { false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1520
1521 /* Send handover Access Burst */
1522 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1523
1524 /* TODO: test mismatching Handover Reference, and missing IE */
1525
1526 /* Wait for handover detection */
1527 timer T := 3.0;
1528 T.start;
1529 alt {
1530 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1531 log("Handover RACH has been detected: ", rm);
1532 setverdict(pass);
1533 }
1534 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1535 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1536 log2str("RSL_CHAN_RQD was not expected: ", rm));
1537 }
1538 [] RSL.receive { repeat; }
1539 [] T.timeout {
1540 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1541 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1542 }
1543 }
1544
1545 /* Release the channel */
1546 f_rsl_chan_deact();
1547 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1548}
1549
1550/* Test handover RACH detection */
1551testcase TC_ho_rach() runs on test_CT {
1552 var ConnHdlrPars pars;
1553 var ConnHdlr vc_conn;
1554
1555 f_init();
1556
1557 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1558 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1559 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1560 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1561 vc_conn.done;
1562 }
1563
1564 /* TODO: do the above in parallel, rather than sequentially? */
1565 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1566}
1567
Harald Welte93640c62018-02-25 16:59:33 +01001568/***********************************************************************
1569 * Measurement Processing / Reporting
1570 ***********************************************************************/
1571
Harald Welte70767382018-02-21 12:16:40 +01001572template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1573 spare := '0'B,
1574 lpd := 0,
1575 sapi := sapi,
1576 c_r := c_r,
1577 ea := true
1578}
1579
Harald Welted879bd92018-03-12 15:01:23 +01001580template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001581 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001582 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001583 len := 0, /* overwritten */
1584 m := false,
1585 el := 1,
1586 payload := pl
1587}
1588
1589/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1590altstep as_l1_sacch() runs on ConnHdlr {
1591 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001592 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001593 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001594 var GsmRrL3Message meas_rep := valueof(ts_MEAS_REP(true, mp_rxlev_exp, mp_rxlev_exp, 0, 0, omit));
Harald Welted879bd92018-03-12 15:01:23 +01001595 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001596 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001597
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001598 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1599 g_pars.l1_pars.ms_power_level, false,
1600 g_pars.l1_pars.ms_actual_ta);
1601
1602 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1603 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1604
1605 log("Sending Measurement Report: ", l1h, l2);
1606 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001607 repeat;
1608 }
1609}
1610
1611altstep as_l1_dcch() runs on ConnHdlr {
1612 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001613 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001614 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1615 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001616 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1617 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001618 repeat;
1619 }
1620}
1621
1622type record MeasElem {
1623 uint6_t rxlev,
1624 uint3_t rxqual
1625}
1626
1627type record MeasElemFS {
1628 MeasElem full,
1629 MeasElem sub
1630}
1631
1632type record ConnL1Pars {
1633 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001634 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001635 MeasElemFS meas_ul,
1636 int16_t timing_offset_256syms,
1637 uint5_t bs_power_level,
1638 uint5_t ms_power_level,
1639 uint8_t ms_actual_ta
1640}
1641
1642/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1643private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1644 return 63 + (toffs256s/256);
1645}
1646
Harald Welted5684392018-03-10 18:22:04 +01001647private function f_max(integer a, integer b) return integer {
1648 if (a > b) {
1649 return a;
1650 } else {
1651 return b;
1652 }
1653}
1654
1655private function f_min(integer a, integer b) return integer {
1656 if (a < b) {
1657 return a;
1658 } else {
1659 return b;
1660 }
1661}
1662
1663/* compute negative tolerance val-tolerance, ensure >= min */
1664private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1665 val := val - tolerance;
1666 return f_max(val, min);
1667}
1668
1669/* compute positive tolerance val+tolerance, ensure <= max */
1670private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1671 val := val + tolerance;
1672 return f_min(val, max);
1673}
1674
1675/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1676private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1677return template integer {
1678 var template integer ret;
1679 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1680 return ret;
1681}
1682
1683
Harald Welte70767382018-02-21 12:16:40 +01001684/* build a template for matching measurement results against */
1685private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1686 var ConnL1Pars l1p := g_pars.l1_pars;
1687 var template RSL_IE_UplinkMeas ul_meas := {
1688 len := 3,
1689 rfu := '0'B,
1690 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001691 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001692 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001693 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001694 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001695 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1696 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001697 supp_meas_info := omit
1698 };
Harald Welte685d5982018-02-27 20:42:05 +01001699 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001700 ul_meas.len := (3+8);
1701 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001702 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001703 toa256_min := ?,
1704 toa256_max := ?,
1705 toa256_std_dev := ?
1706 }
Harald Welte685d5982018-02-27 20:42:05 +01001707 }
Harald Welte70767382018-02-21 12:16:40 +01001708 var template RSL_IE_BS_Power bs_power := {
1709 reserved := 0,
1710 epc := false,
1711 fpc := false,
1712 power_level := l1p.bs_power_level
1713 };
1714 var template RSL_IE_L1Info l1_info := {
1715 ms_power_lvl := l1p.ms_power_level,
1716 fpc := false,
1717 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001718 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001719 };
1720 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001721 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001722 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1723 ?, t_toffs);
1724}
1725
1726/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001727altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001728 var RSL_Message rsl;
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001729 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Harald Welte70767382018-02-21 12:16:40 +01001730 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1731 /* increment counter of next to-be-expected meas rep */
1732 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1733 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001734 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001735 repeat;
1736 }
1737 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001738 /* increment counter of next to-be-expected meas rep */
1739 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1740 if (g_first_meas_res) {
1741 g_first_meas_res := false;
1742 repeat;
1743 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001744 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001745 }
Harald Welte70767382018-02-21 12:16:40 +01001746 }
1747 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001748 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001749 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001750 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001751 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001752 }
1753}
1754
Harald Weltee613f962018-04-18 22:38:16 +02001755private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1756 select (rsl_alg_id) {
1757 case (RSL_ALG_ID_A5_0) { return 0; }
1758 case (RSL_ALG_ID_A5_1) { return 1; }
1759 case (RSL_ALG_ID_A5_2) { return 2; }
1760 case (RSL_ALG_ID_A5_3) { return 3; }
1761 case (RSL_ALG_ID_A5_4) { return 4; }
1762 case (RSL_ALG_ID_A5_5) { return 5; }
1763 case (RSL_ALG_ID_A5_6) { return 6; }
1764 case (RSL_ALG_ID_A5_7) { return 7; }
1765 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001766 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1767 /* Make compiler happy by calling mtc.stop here. It is already
1768 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001769 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001770 }
1771 }
1772}
1773
1774private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1775 select (rsl_alg_id) {
1776 case (RSL_ALG_ID_A5_1) { return '000'B; }
1777 case (RSL_ALG_ID_A5_2) { return '001'B; }
1778 case (RSL_ALG_ID_A5_3) { return '010'B; }
1779 case (RSL_ALG_ID_A5_4) { return '011'B; }
1780 case (RSL_ALG_ID_A5_5) { return '100'B; }
1781 case (RSL_ALG_ID_A5_6) { return '101'B; }
1782 case (RSL_ALG_ID_A5_7) { return '110'B; }
1783 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001784 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1785 /* Make compiler happy by calling mtc.stop here. It is already
1786 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001787 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001788 }
1789 }
1790}
1791
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001792/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1793private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1794 var GsmFrameNumber fn;
1795 timer T := 8.0;
1796
1797 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1798 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1799
1800 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1801 /* Send the actual RACH */
1802 fn := f_L1CTL_RACH(L1CTL, ra);
1803
1804 T.start;
1805 alt {
1806 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1807 [] T.timeout {
1808 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1809 }
1810 }
1811 T.stop
1812 return fn;
1813}
Harald Weltee613f962018-04-18 22:38:16 +02001814
Harald Welte70767382018-02-21 12:16:40 +01001815/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001816private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001817 var GsmFrameNumber fn;
1818 var ImmediateAssignment imm_ass;
1819 var integer ra := 23;
1820
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001821 /* Send RACH request and wait for ChanReq */
1822 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001823
1824 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001825 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01001826
1827 /* Send IMM.ASS via CCHAN */
1828 var ChannelDescription ch_desc := {
1829 chan_nr := g_pars.chan_nr,
1830 tsc := 7,
1831 h := false,
1832 arfcn := mp_trx0_arfcn,
1833 maio_hsn := omit
1834 };
1835 var MobileAllocation ma := {
1836 len := 0,
1837 ma := ''B
1838 };
1839 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1840 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1841
1842 /* receive IMM.ASS on MS side */
1843 var ImmediateAssignment ia_um;
1844 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1845 /* enable dedicated mode */
1846 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltee613f962018-04-18 22:38:16 +02001847 /* enable encryption, if requested */
1848 if (encr_enable) {
1849 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1850 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1851 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001852
1853 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001854}
1855
1856/* establish DChan, verify existance + contents of measurement reports */
1857function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001858 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001859 RSL.clear;
1860
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001861 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001862 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001863 f_trx_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
1864 }
Harald Welte70767382018-02-21 12:16:40 +01001865
1866 f_est_dchan();
1867
1868 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1869 * RSL measurement reports on Abis side */
1870 timer T := 8.0;
1871 T.start;
1872 alt {
1873 [] as_l1_sacch();
1874 [] as_meas_res();
1875 [] as_l1_dcch();
1876 [] L1CTL.receive { repeat; }
1877 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001878 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01001879 * of any earlier errors, so if we reach this timeout, we're good */
1880 setverdict(pass);
1881 }
1882 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001883 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01001884 }
1885 }
1886 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001887 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001888}
Harald Welte0472ab42018-03-12 15:02:26 +01001889
Harald Welte70767382018-02-21 12:16:40 +01001890testcase TC_meas_res_sign_tchf() runs on test_CT {
1891 var ConnHdlr vc_conn;
1892 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02001893 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001894 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1895 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1896 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1897 vc_conn.done;
1898 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001899 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001900}
1901testcase TC_meas_res_sign_tchh() runs on test_CT {
1902 var ConnHdlr vc_conn;
1903 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02001904 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001905 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1906 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1907 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1908 vc_conn.done;
1909 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001910 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001911}
1912testcase TC_meas_res_sign_sdcch4() runs on test_CT {
1913 var ConnHdlr vc_conn;
1914 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02001915 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001916 for (var integer ss := 0; ss <= 3; ss := ss+1) {
1917 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
1918 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1919 vc_conn.done;
1920 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001921 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001922}
1923testcase TC_meas_res_sign_sdcch8() runs on test_CT {
1924 var ConnHdlr vc_conn;
1925 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02001926 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001927 for (var integer ss := 0; ss <= 7; ss := ss+1) {
1928 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
1929 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1930 vc_conn.done;
1931 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001932 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001933}
Harald Welte685d5982018-02-27 20:42:05 +01001934testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
1935 var ConnHdlr vc_conn;
1936 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02001937 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01001938 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
1939 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1940 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1941 pars.l1_pars.toa256_enabled := true;
1942 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1943 vc_conn.done;
1944 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001945 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01001946}
1947
Philipp Maier4d1e9c92018-12-20 11:11:56 +01001948/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
1949 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
1950function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
1951 var L1ctlDlMessage l1_dl;
1952 var RSL_IE_MS_Power ms_power;
1953 var RSL_Message rsl;
1954 var uint5_t power_level := 0;
1955
1956 f_l1_tune(L1CTL);
1957 RSL.clear;
1958
1959 f_est_dchan();
1960
1961 ms_power.reserved := 0;
1962 ms_power.fpc_epc := false;
1963
1964 /* Send the first power control command. This will disable any BTS/TRX
1965 * internal power control and switch the MS (which is not in scope of
1966 * this test) to a constant power level. We start with a power level
1967 * of 0 */
1968 ms_power.power_level := power_level;
1969 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1970 RSL.send(rsl);
1971
1972 alt {
1973
1974 /* Pick all SACCH blocks for checking */
1975 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1976
1977 /* The first byte of the L1 header contains the power level.
1978 * The reserved bits and the fpc bit is set to 0, so we may
1979 * compare directly. */
1980 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
1981 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
1982 }
1983
1984 /* Signal a new power level via RSL for the next turn. */
1985 if (power_level < 31) {
1986 power_level := power_level + 1;
1987 ms_power.power_level := power_level;
1988 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1989 RSL.send(rsl);
1990 repeat;
1991 }
1992
1993 }
1994
1995 /* Ignore all other blocks */
1996 [] L1CTL.receive { repeat; }
1997
1998 }
1999
2000 f_rsl_chan_deact();
2001 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2002
2003 setverdict(pass);
2004}
2005
2006testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
2007 var ConnHdlr vc_conn;
2008 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002009 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002010
2011 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2012 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2013 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
2014 vc_conn.done;
2015 }
2016 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2017}
Harald Welte70767382018-02-21 12:16:40 +01002018
Eric Wild6833cc92019-05-23 19:34:44 +02002019/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
2020TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
2021function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
2022 var L1ctlDlMessage l1_dl;
2023 var uint5_t ta_to_test := 16;
2024
2025
2026 f_l1_tune(L1CTL);
2027 RSL.clear;
2028
2029 /* tell fake_trx to use a given timing offset for all bursts */
2030 f_trx_fake_toffs256(ta_to_test*256);
2031
2032 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
2033
2034
2035 alt {
2036
2037 /* Pick all SACCH blocks for checking */
2038 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2039
2040 /* The second byte of the L1 header contains the TA. */
2041 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
2042 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
2043 }
2044
2045 }
2046
2047 /* Ignore all other blocks */
2048 [] L1CTL.receive { repeat; }
2049
2050 }
2051
2052 f_rsl_chan_deact();
2053 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2054
2055 setverdict(pass);
2056}
2057
2058testcase TC_rsl_chan_initial_ta() runs on test_CT {
2059 var ConnHdlr vc_conn;
2060 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002061 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02002062 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2063 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars);
2064 vc_conn.done;
2065 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2066}
2067
Eric Wilde57e1a62019-05-28 13:30:55 +02002068/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
2069function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
2070 var L1ctlDlMessage l1_dl;
2071 var uint5_t ms_power_level := 7;
2072
2073 var RSL_IE_MS_Power ms_power;
2074 ms_power.reserved := 0;
2075 ms_power.fpc_epc := false;
2076 ms_power.power_level := ms_power_level;
2077
2078 f_l1_tune(L1CTL);
2079 RSL.clear;
2080
2081 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
2082
2083 timer T := 1.0;
2084 T.start;
2085 alt {
2086 /* Pick all SACCH blocks for checking */
2087 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2088 /* The first byte of the L1 header contains the power level.. */
2089 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
2090 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2091 }
2092 }
2093 /* Ignore all other blocks */
2094 [] L1CTL.receive { repeat; }
2095 [] T.timeout {
2096 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2097 }
2098 }
2099
2100 f_rsl_chan_deact();
2101 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2102 setverdict(pass);
2103}
2104
2105testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
2106 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2107 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
2108}
2109
Harald Welte0472ab42018-03-12 15:02:26 +01002110/* Test if a channel without valid uplink bursts generates RSL CONN FAIL IND (TS 48.058 4.10) */
Harald Welte70767382018-02-21 12:16:40 +01002111private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002112 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002113 RSL.clear;
2114
2115 f_est_dchan();
2116 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01002117 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01002118
2119 timer T := 40.0;
2120 T.start;
2121 alt {
2122 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
2123 setverdict(pass)
2124 }
2125 [] RSL.receive { repeat };
2126 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002127 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01002128 }
2129 }
2130 f_rsl_chan_deact();
2131}
2132testcase TC_conn_fail_crit() runs on test_CT {
2133 var ConnHdlr vc_conn;
2134 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002135 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002136 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
2137 pars.t_guard := 60.0;
2138 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
2139 vc_conn.done;
2140}
2141
Harald Welte93640c62018-02-25 16:59:33 +01002142/***********************************************************************
2143 * Paging
2144 ***********************************************************************/
2145
Harald Welte68e495b2018-02-25 00:05:57 +01002146function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
2147 if (tmsi == 'FFFFFFFF'O) {
2148 return true;
2149 } else {
2150 return false;
2151 }
2152}
Harald Welte70767382018-02-21 12:16:40 +01002153
Philipp Maier82cb0b12018-08-31 14:41:39 +02002154type record allowedFn { integer frame_nr }
2155template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
2156template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
2157template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
2158template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
2159template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
2160template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
2161template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
2162template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
2163function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
2164{
2165 var integer frame_nr_51;
2166 frame_nr_51 := frame_nr mod 51
2167
2168 var allowedFn fn_check;
2169 fn_check.frame_nr := frame_nr_51;
2170
2171 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002172 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002173 return;
2174 }
2175
2176 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
2177 return;
2178 }
2179 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
2180 return;
2181 }
2182 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
2183 return;
2184 }
2185 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
2186 return;
2187 }
2188 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
2189 return;
2190 }
2191 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
2192 return;
2193 }
2194 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
2195 return;
2196 }
2197 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
2198 return;
2199 }
2200
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002201 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002202 return;
2203}
2204
2205altstep as_l1_count_paging(inout integer num_paging_rcv_msgs, inout integer num_paging_rcv_ids, PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01002206runs on test_CT {
2207 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002208 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002209 repeat;
2210 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01002211 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01002212 var octetstring without_plen :=
2213 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
2214 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02002215
2216 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
2217
Harald Welte68e495b2018-02-25 00:05:57 +01002218 if (match(rr, tr_PAGING_REQ1)) {
2219 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2220 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2221 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
2222 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2223 }
2224 } else if (match(rr, tr_PAGING_REQ2)) {
2225 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2226 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
2227 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2228 }
2229 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
2230 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2231 }
2232 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
2233 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2234 }
2235 } else if (match(rr, tr_PAGING_REQ3)) {
2236 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2237 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
2238 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2239 }
2240 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
2241 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2242 }
2243 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
2244 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2245 }
2246 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
2247 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2248 }
2249 }
2250 repeat;
2251 }
2252}
2253
2254type record PagingTestCfg {
2255 boolean combined_ccch,
2256 integer bs_ag_blks_res,
2257 float load_factor,
2258 boolean exp_load_ind,
2259 boolean exp_overload,
2260 boolean use_tmsi
2261}
2262
2263type record PagingTestState {
2264 integer num_paging_sent,
2265 integer num_paging_rcv_msgs,
2266 integer num_paging_rcv_ids,
2267 integer num_overload
2268}
2269
2270/* receive + ignore RSL RF RES IND */
2271altstep as_rsl_res_ind() runs on test_CT {
2272 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
2273 repeat;
2274 }
2275}
2276
2277/* Helper function for paging related testing */
2278private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02002279 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01002280 f_init_l1ctl();
2281 f_l1_tune(L1CTL);
2282
2283 var PagingTestState st := {
2284 num_paging_sent := 0,
2285 num_paging_rcv_msgs := 0,
2286 num_paging_rcv_ids := 0,
2287 num_overload := 0
2288 };
2289
2290 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
2291 var float max_pch_imsi_per_sec;
2292 if (cfg.use_tmsi) {
2293 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
2294 } else {
2295 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
2296 }
2297 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
2298 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002299 var float time_total := 20.0;
2300 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
2301 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01002302
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002303 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
2304 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01002305
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002306 timer T_itv := 0.0;
2307 T_itv.start;
2308 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01002309 alt {
2310 /* check for presence of CCCH LOAD IND (paging load) */
2311 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
2312 st.num_overload := st.num_overload + 1;
2313 repeat;
2314 }
2315 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002316 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01002317 }
2318 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
2319 log("Rx LOAD_IND");
2320 /* FIXME: analyze/verify interval + contents */
2321 repeat;
2322 }
2323 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02002324 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002325 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002326 [] T_itv.timeout {
2327 /* Send paging cmds based on elapsed time */
2328 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
2329 while (st.num_paging_sent < new_sent) {
2330 /* build mobile Identity */
2331 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2332 if (cfg.use_tmsi) {
2333 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2334 } else {
2335 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(st.num_paging_sent)));
2336 }
2337 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2338 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2339
2340 /* Send RSL PAGING COMMAND */
2341 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, st.num_paging_sent mod 4)));
2342
2343 st.num_paging_sent := st.num_paging_sent + 1;
2344 }
2345 if (st.num_paging_sent < pkt_total) {
2346 /* Wait for interval to next PAGING COMMAND */
2347 var float time_now := T_total.read;
2348 var float next_sched := int2float(st.num_paging_sent)*interval;
2349 if (next_sched > time_now) {
2350 T_itv.start(next_sched - time_now);
2351 } else {
2352 T_itv.start(0.0);
2353 }
2354 } else {
2355 /* We are done, no need to keep counting */
2356 T_total.stop;
2357 }
2358 }
2359 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01002360 [] as_rsl_res_ind();
2361 }
2362 }
2363
2364 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
2365 timer T_wait := 18.0;
2366 T_wait.start;
2367 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02002368 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002369 [] L1CTL.receive { repeat; }
2370 /* 65535 == empty paging queue, we can terminate*/
2371 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
2372 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
2373 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002374 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01002375 }
2376 [] as_rsl_res_ind();
2377 }
2378
2379 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
2380 " rcvd_ids=", st.num_paging_rcv_ids);
2381 return st;
2382}
2383
2384/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
2385 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2386 * - that CCCH LOAD IND (PCH) are being generated
2387 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2388testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002389 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002390 var PagingTestCfg cfg := {
2391 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002392 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002393 load_factor := 0.8,
2394 exp_load_ind := true,
2395 exp_overload := false,
2396 use_tmsi := false
2397 };
2398 var PagingTestState st := f_TC_paging(cfg);
2399 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002400 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2401 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002402 } else {
2403 setverdict(pass);
2404 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002405 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002406}
2407
2408/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
2409 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2410 * - that CCCH LOAD IND (PCH) are being generated
2411 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2412testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002413 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002414 var PagingTestCfg cfg := {
2415 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002416 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002417 load_factor := 0.8,
2418 exp_load_ind := true,
2419 exp_overload := false,
2420 use_tmsi := true
2421 };
2422 var PagingTestState st := f_TC_paging(cfg);
2423 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2425 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002426 } else {
2427 setverdict(pass);
2428 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002429 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002430}
2431
2432/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
2433 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2434 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2435 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2436testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002437 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002438 var PagingTestCfg cfg := {
2439 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002440 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002441 load_factor := 2.0,
2442 exp_load_ind := true,
2443 exp_overload := true,
2444 use_tmsi := false
2445 };
2446 var PagingTestState st := f_TC_paging(cfg);
2447 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
2448 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002449 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002450 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002451 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002452 } else {
2453 setverdict(pass);
2454 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002455 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002456}
2457
2458/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
2459 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2460 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2461 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2462testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002463 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002464 var PagingTestCfg cfg := {
2465 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002466 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002467 load_factor := 2.0,
2468 exp_load_ind := true,
2469 exp_overload := true,
2470 use_tmsi := true
2471 };
2472 var PagingTestState st := f_TC_paging(cfg);
2473 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
2474 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002475 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002476 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002477 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002478 } else {
2479 setverdict(pass);
2480 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002481 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002482}
2483
2484
Harald Welte93640c62018-02-25 16:59:33 +01002485/***********************************************************************
2486 * Immediate Assignment / AGCH
2487 ***********************************************************************/
Harald Weltee8d750e2018-06-10 21:41:35 +02002488const MobileAllocation c_MA_null := {
2489 len := 0,
2490 ma := ''B
2491}
Harald Welte93640c62018-02-25 16:59:33 +01002492
Harald Weltee8d750e2018-06-10 21:41:35 +02002493template (value) ChannelDescription ts_ChanDesc(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
2494 uint12_t arfcn := 871) := {
2495 chan_nr := chan_nr,
2496 tsc := tsc,
2497 h := false,
2498 arfcn := arfcn,
2499 maio_hsn := omit
2500}
2501
2502private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
2503 return int2str(num_tx) & " sent, "
2504 & int2str(num_rx) & " received, "
2505 & int2str(num_del) & " deleted";
2506}
2507
2508private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
2509 var L1ctlDlMessage l1_dl;
2510 timer T := 10.0;
2511 var integer num_tx := 0;
2512 var integer num_rx := 0;
2513 var integer num_del := 0;
2514 var charstring res_str;
2515 var float rx_ratio;
2516
Harald Welte10474062019-05-30 16:48:17 +02002517 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02002518 f_init_l1ctl();
2519 f_l1_tune(L1CTL);
2520
2521 for (var integer i := 0; i < num_total; i := i+1) {
2522 var ChannelDescription ch_desc := valueof(ts_ChanDesc(valueof(t_RslChanNr_SDCCH4(0, 0))));
2523 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
2524 var octetstring ia_enc := enc_GsmRrMessage(ia);
Harald Welte68e495b2018-02-25 00:05:57 +01002525 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02002526 num_tx := num_tx+1;
2527 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01002528 }
2529 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02002530 T.start;
2531 alt {
2532 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
2533 num_del := num_del+1;
2534 repeat;
2535 }
2536 [] RSL_CCHAN.receive {
2537 repeat;
2538 }
2539 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
2540 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2541 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
2542 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
2543 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002544 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02002545 } else {
2546 num_rx := num_rx+1;
2547 }
2548 repeat;
2549 }
2550 [] L1CTL.receive { repeat; }
2551 [] T.timeout { }
2552 }
2553 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
2554 log("AGCH test: " & res_str);
2555 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002556 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02002557 }
2558 rx_ratio := int2float(num_rx) / int2float(num_tx);
2559 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002560 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX ratio ("&float2str(rx_ratio)&") far from expected ("&float2str(exp_pass)&") " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02002561 } else {
2562 setverdict(pass);
2563 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002564 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002565}
2566
Harald Weltee8d750e2018-06-10 21:41:35 +02002567/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
2568testcase TC_imm_ass_1000_20ms() runs on test_CT {
2569 f_TC_imm_ass(1000, 0.02, 0.25);
2570}
2571
2572/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
2573testcase TC_imm_ass_200_0ms() runs on test_CT {
2574 f_TC_imm_ass(200, 0.0, 0.05);
2575}
2576
2577/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
2578testcase TC_imm_ass_200_76ms() runs on test_CT {
2579 f_TC_imm_ass(150, 0.076, 1.00);
2580}
2581
2582
2583
Harald Welte48494ca2018-02-25 16:59:50 +01002584/***********************************************************************
2585 * BCCH
2586 ***********************************************************************/
2587
2588/* tuple of Frame Number + decoded SI */
2589type record SystemInformationFn {
2590 GsmFrameNumber frame_number,
2591 SystemInformation si
2592}
2593
2594/* an arbitrary-length vector of decoded SI + gsmtap header */
2595type record of SystemInformationFn SystemInformationVector;
2596
2597/* an array of SI-vectors indexed by TC value */
2598type SystemInformationVector SystemInformationVectorPerTc[8];
2599
2600/* determine if a given SI vector contains given SI type at least once */
2601function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2602 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2603 var integer fn_mod51 := arr[i].frame_number mod 51;
2604 if (not bcch_ext and fn_mod51 == 2 or
2605 bcch_ext and fn_mod51 == 6) {
2606 if (arr[i].si.header.message_type == key) {
2607 return true;
2608 }
2609 }
2610 }
2611 return false;
2612}
2613
2614/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
2615function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2616 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002617 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002618 }
2619}
2620
2621/* check if a given SI vector contains given SI type at least once on any TC */
2622function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
2623 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
2624 if (f_si_vecslot_contains(arr[tc], key) or
2625 f_si_vecslot_contains(arr[tc], key, true)) {
2626 return true;
2627 }
2628 }
2629 return false;
2630}
2631
2632/* determine if a given SI vector contains given SI type at least N of M times */
2633function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
2634 var integer count := 0;
2635 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002636 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01002637 }
2638 for (var integer i:= 0; i < m; i := i + 1) {
2639 var integer fn_mod51 := arr[i].frame_number mod 51;
2640 if (not bcch_ext and fn_mod51 == 2 or
2641 bcch_ext and fn_mod51 == 6) {
2642 if (arr[i].si.header.message_type == key) {
2643 count := count + 1;
2644 }
2645 }
2646 }
2647 if (count >= n) {
2648 return true;
2649 } else {
2650 return false;
2651 }
2652}
2653
2654/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
2655function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
2656 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002657 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002658 }
2659}
2660
2661/* determine if a given SI vector contains given SI type at least once */
2662function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2663 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2664 var integer fn_mod51 := arr[i].frame_number mod 51;
2665 if (not bcch_ext and fn_mod51 == 2 or
2666 bcch_ext and fn_mod51 == 6) {
2667 if (arr[i].si.header.message_type != key) {
2668 return false;
2669 }
2670 }
2671 }
2672 return true;
2673}
2674
2675/* ensure a given TC slot of the SI vector contains only given SI type */
2676function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2677 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002678 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002679 }
2680}
2681
2682/* SI configuration of cell, against which we validate actual SI messages */
2683type set SystemInformationConfig {
2684 boolean bcch_extended,
2685 boolean si1_present,
2686 boolean si2bis_present,
2687 boolean si2ter_present,
2688 boolean si2quater_present,
2689 boolean si7_present,
2690 boolean si8_present,
2691 boolean si9_present,
2692 boolean si13_present,
2693 boolean si13alt_present,
2694 boolean si15_present,
2695 boolean si16_present,
2696 boolean si17_present,
2697 boolean si2n_present,
2698 boolean si21_present,
2699 boolean si22_present
2700}
2701
2702/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
2703function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
2704 var integer i;
2705 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
2706 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002707 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01002708 }
2709 }
2710 if (cfg.si1_present) {
2711 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
2712 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
2713 * when TC = 0, it can assume that System Information Type 1 is not in use. */
2714 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2715 /* make sure *ALL* contain SI1 */
2716 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2717 }
2718 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
2719 /* iii) A SI 2 message will be sent at least every time TC = 1 */
2720 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
2721 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
2722 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
2723 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
2724
2725 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
2726 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
2727 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
2728 * consecutive occurrences of TC = 4. */
2729 if (cfg.si2bis_present and not cfg.si2ter_present) {
2730 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2731 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
2732 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
2733 } else if (cfg.si2ter_present and cfg.si2bis_present) {
2734 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2735 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
2736 }
2737
2738 if (cfg.si7_present or cfg.si8_present) {
2739 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
2740 * if System Information type 4 does not contain all information needed for cell
2741 * selection and reselection. */
2742 if (not cfg.bcch_extended) {
2743 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
2744 }
2745 if (cfg.si7_present) {
2746 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
2747 }
2748 if (cfg.si8_present) {
2749 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
2750 }
2751 }
2752
2753 if (cfg.si2quater_present) {
2754 /* iii) System information type 2 quater is sent if needed, as determined by the system
2755 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
2756 * and 2ter are used, otherwise it shall be sent at least once within any of 4
2757 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
2758 * within any of 4 consecutive occurrences of TC = 5. */
2759 if (not (cfg.bcch_extended)) {
2760 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
2761 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
2762 } else {
2763 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
2764 }
2765 } else {
2766 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
2767 }
2768 }
2769 if (cfg.si9_present) {
2770 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
2771 * in system information type 3 as defined in 3GPP TS 44.018. */
2772 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
2773 }
2774 if (cfg.si13_present) {
2775 /* vii) System Information type 13 is only related to the GPRS service. System Information
2776 * Type 13 need only be sent if GPRS support is indicated in one or more of System
2777 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
2778 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
2779 * In the case that the message is sent on the BCCH Norm, it is sent at least once
2780 * within any of 4 consecutive occurrences of TC=4. */
2781 if (not cfg.bcch_extended) {
2782 log("not-bccch-extended");
2783 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
2784 } else {
2785 log("bccch-extended");
2786 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
2787 }
2788 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002789 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002790 }
2791 }
2792 if (cfg.si16_present or cfg.si17_present) {
2793 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
2794 * should not be sent in a cell where network sharing is used (see rule xv). */
2795 if (cfg.si22_present) {
2796 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2797 }
2798 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002799 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002800 }
2801 if (not cfg.bcch_extended) {
2802 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
2803 }
2804 if (cfg.si16_present) {
2805 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
2806 }
2807 if (cfg.si17_present) {
2808 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
2809 }
2810 }
2811
2812 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
2813 * broadcast information. The frequency with which they are sent is determined by the
2814 * system operator. System Information type 9 identifies the scheduling of System
2815 * Information type 18 and 20 messages. */
2816
2817 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
2818 * Information Type 19 is present, then its scheduling shall be indicated in System
2819 * Information Type 9. */
2820
2821 if (cfg.si15_present) {
2822 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
2823 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
2824 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
2825 * 4 consecutive occurrences of TC = 1. */
2826 if (not cfg.bcch_extended) {
2827 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
2828 } else {
2829 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
2830 }
2831 }
2832 if (cfg.si13alt_present) {
2833 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
2834 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
2835 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
2836 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
2837 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
2838 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
2839 * of TC = 4. */
2840 if (cfg.si13_present) {
2841 testcase.stop("Error: Cannot have SI13alt and SI13");
2842 }
2843 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002844 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002845 }
2846 if (not cfg.bcch_extended) {
2847 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
2848 } else {
2849 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
2850 }
2851 }
2852 if (cfg.si2n_present) {
2853 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
2854 * as determined by the system operator. In the case that the message is sent on the
2855 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
2856 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
2857 * consecutive occurrences of TC = 4. */
2858 if (not cfg.bcch_extended) {
2859 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
2860 } else {
2861 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
2862 }
2863 }
2864 if (cfg.si21_present) {
2865 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
2866 * determined by the system operator. If Extended Access Barring is in use in the cell
2867 * then this message is sent at least once within any of 4 consecutive occurrences of
2868 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
2869 * cell then this message shall only be sent on BCCH Ext. */
2870 if (not cfg.bcch_extended) {
2871 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
2872 } else {
2873 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
2874 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002875 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01002876 }
2877 }
2878 }
2879 if (cfg.si22_present) {
2880 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
2881 * should not be sent in a cell where SoLSA is used (see rule viii). System
2882 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
2883 * =2 and TC=6. */
2884 if (cfg.si16_present or cfg.si17_present) {
2885 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2886 }
2887 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
2888 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002889 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002890 }
2891 if (not cfg.bcch_extended) {
2892 testcase.stop("Error: SI22 requires BCCH Extd!");
2893 } else {
2894 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
2895 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
2896 }
2897 }
2898}
2899
2900/* sample Systme Information for specified duration via L1CTL */
2901function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
2902 timer T := duration;
2903 var SystemInformationVectorPerTc si_per_tc;
2904 var L1ctlDlMessage l1_dl;
2905
2906 /* initialize all per-TC vectors empty */
2907 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2908 si_per_tc[i] := {};
2909 }
2910
2911 /* flush all previous L1 queued msgs */
2912 pt.clear;
2913
2914 T.start;
2915 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002916 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01002917 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2918 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
2919 log("Ignoring non-RR SI ", l1_dl);
2920 repeat;
2921 }
2922 var SystemInformationFn sig := {
2923 frame_number := l1_dl.dl_info.frame_nr,
2924 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
2925 }
2926 var integer tc := f_gsm_compute_tc(sig.frame_number);
2927 log("SI received at TC=", tc, ": ", sig.si);
2928 /* append to the per-TC bucket */
2929 si_per_tc[tc] := si_per_tc[tc] & { sig };
2930 repeat;
2931 }
2932 [] pt.receive { repeat; }
2933 [] T.timeout { }
2934 }
2935
2936 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2937 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
2938 }
2939 log("si_per_tc=", si_per_tc);
2940 return si_per_tc;
2941}
2942
2943/* helper function: Set given SI via RSL + validate scheduling.
2944 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
2945function f_TC_si_sched() runs on test_CT {
2946 var SystemInformationVectorPerTc si_per_tc;
2947 f_init_l1ctl();
2948 f_l1_tune(L1CTL);
2949
2950 /* Sample + Validate Scheduling */
2951 si_per_tc := f_l1_sample_si(L1CTL);
2952 f_validate_si_scheduling(si_cfg, si_per_tc);
2953
2954 setverdict(pass);
2955}
2956
2957testcase TC_si_sched_default() runs on test_CT {
2958 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01002959 /* 2+3+4 are mandatory and set in f_init() */
2960 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002961 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01002962}
2963
2964testcase TC_si_sched_1() runs on test_CT {
2965 f_init();
2966 si_cfg.si1_present := true;
2967 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002968 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002969 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002970}
2971
2972testcase TC_si_sched_2bis() runs on test_CT {
2973 f_init();
2974 si_cfg.si2bis_present := true;
2975 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2976 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002977 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002978}
2979
2980testcase TC_si_sched_2ter() runs on test_CT {
2981 f_init();
2982 si_cfg.si2ter_present := true;
2983 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2984 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002985 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002986}
2987
2988testcase TC_si_sched_2ter_2bis() runs on test_CT {
2989 f_init();
2990 si_cfg.si2bis_present := true;
2991 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2992 si_cfg.si2ter_present := true;
2993 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2994 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002995 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002996}
2997
2998testcase TC_si_sched_2quater() runs on test_CT {
2999 f_init();
3000 si_cfg.si2quater_present := true;
3001 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3002 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003003 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003004}
3005
3006testcase TC_si_sched_13() runs on test_CT {
3007 f_init();
3008 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003009 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003010 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003011 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003012}
3013
3014testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
3015 f_init();
3016 si_cfg.si2bis_present := true;
3017 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3018 si_cfg.si2ter_present := true;
3019 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3020 si_cfg.si2quater_present := true;
3021 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3022 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003023 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003024 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003025 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003026}
3027
3028
Harald Welte68e495b2018-02-25 00:05:57 +01003029testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003030 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003031 /* FIXME: enable / disable individual BCCH info */
3032 //ts_RSL_BCCH_INFO(si_type, info);
3033 /* expect no ERROR REPORT after either of them *
3034 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003035 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003036}
3037
Harald Welte93640c62018-02-25 16:59:33 +01003038/***********************************************************************
3039 * Low-Level Protocol Errors / ERROR REPORT
3040 ***********************************************************************/
3041
Harald Welte01d982c2018-02-25 01:31:40 +01003042private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
3043 timer T := 5.0;
3044 T.start;
3045 alt {
3046 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
3047 setverdict(pass);
3048 }
3049 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003050 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003051 }
3052 [] RSL_CCHAN.receive {
3053 repeat;
3054 }
3055 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003056 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003057 }
3058 }
3059}
3060
3061/* Provoke a protocol error (message too short) and match on ERROR REPORT */
3062testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003063 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003064 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3065 rsl.ies := omit;
3066 RSL_CCHAN.send(ts_RSL_UD(rsl));
3067
3068 f_exp_err_rep(RSL_ERR_PROTO);
3069}
3070
3071/* Provoke a mandatory IE error and match on ERROR REPORT */
3072testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003073 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003074
3075 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3076 rsl.ies := { rsl.ies[0] };
3077 RSL_CCHAN.send(ts_RSL_UD(rsl));
3078
3079 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
3080}
3081
3082/* Provoke an IE content error and match on ERROR REPORT */
3083testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003084 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003085 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3086 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
3087 RSL_CCHAN.send(ts_RSL_UD(rsl));
3088
3089 f_exp_err_rep(RSL_ERR_IE_CONTENT);
3090}
3091
Harald Welteee25aae2019-05-19 14:32:37 +02003092/* attempt to activate channel with wrong RSL Message Discriminator IE */
3093function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
3094 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3095 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
3096 RSL.send(rsl);
3097 f_rslem_unregister(0, g_chan_nr);
3098}
3099testcase TC_err_rep_wrong_mdisc() runs on test_CT {
3100 var ConnHdlr vc_conn;
3101 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3102
Harald Welte10474062019-05-30 16:48:17 +02003103 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003104
3105 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
3106 vc_conn.done;
3107 f_exp_err_rep(RSL_ERR_MSG_DISCR);
3108
3109 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3110}
3111
3112/* Send messages with wrong message type */
3113function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
3114 var template (value) RSL_Message rsl_tx;
3115 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3116 rsl_tx.msg_type := RSL_MT_NOT_CMD;
3117 RSL.send(rsl_tx);
3118 f_rslem_unregister(0, g_chan_nr);
3119}
3120function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
3121 var template (value) RSL_Message rsl_tx;
3122 /* we first have to activate the dedicated channel */
3123 f_rsl_chan_act(g_pars.chan_mode);
3124 /* ... to then send an invalid RLL message */
3125 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
3126 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
3127 RSL.send(rsl_tx);
3128 f_rslem_unregister(0, g_chan_nr);
3129}
3130testcase TC_err_rep_wrong_msg_type() runs on test_CT {
3131 var ConnHdlr vc_conn;
3132 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3133 var template (value) RSL_Message rsl_tx;
3134
Harald Welte10474062019-05-30 16:48:17 +02003135 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003136
3137 /* Common Channel with wrong message type */
3138 RSL_CCHAN.clear;
3139 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3140 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
3141 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3142 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3143
3144 /* TRX Management */
3145 RSL_CCHAN.clear;
3146 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
3147 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
3148 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3149 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3150
3151 /* Dedicated Channel */
3152 RSL_CCHAN.clear;
3153 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
3154 vc_conn.done;
3155 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3156
3157 /* RLL */
3158 RSL_CCHAN.clear;
3159 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
3160 vc_conn.done;
3161 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3162}
3163
3164/* Send messages in wrong sequence (RLL to an inactive lchan) */
3165function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
3166 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
3167 f_rslem_unregister(0, g_chan_nr);
3168}
3169testcase TC_err_rep_wrong_sequence() runs on test_CT {
3170 var ConnHdlr vc_conn;
3171 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3172
Harald Welte10474062019-05-30 16:48:17 +02003173 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003174
3175 RSL_CCHAN.clear;
3176 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
3177 vc_conn.done;
3178 f_exp_err_rep(RSL_ERR_MSG_SEQ);
3179}
3180
Harald Welte93640c62018-02-25 16:59:33 +01003181/***********************************************************************
3182 * IPA CRCX/MDCX/DLCS media stream handling
3183 ***********************************************************************/
3184
Harald Weltea871a382018-02-25 02:03:14 +01003185/* Send IPA DLCX to inactive lchan */
3186function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01003187 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3188 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01003189}
3190testcase TC_ipa_dlcx_not_active() runs on test_CT {
3191 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003192 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01003193 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
3194 vc_conn.done;
3195}
Harald Welte68e495b2018-02-25 00:05:57 +01003196
Harald Weltea3f1df92018-02-25 12:49:55 +01003197/* Send IPA CRCX twice to inactive lchan */
3198function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
3199 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3200 "IPA CRCX ACK");
3201 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
3202 "IPA CRCX NACK");
3203}
3204testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
3205 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003206 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01003207 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
3208 vc_conn.done;
3209}
3210
3211/* Regular sequence of CRCX/MDCX/DLCX */
3212function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3213 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3214 "IPA CRCX ACK");
3215 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3216 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3217 var uint7_t rtp_pt2 := f_rnd_int(127);
3218 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3219 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3220 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3221 "IPA MDCX ACK");
3222 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3223 "IPA DLCX ACK");
3224}
3225testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
3226 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003227 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01003228 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
3229 vc_conn.done;
3230}
3231
Harald Welte3ae11da2018-02-25 13:36:06 +01003232/* Sequence of CRCX, 2x MDCX, DLCX */
3233function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3234 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3235 "IPA CRCX ACK");
3236 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3237 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3238 var uint7_t rtp_pt2 := f_rnd_int(127);
3239 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3240 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3241 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3242 "IPA MDCX ACK");
3243 /* Second MDCX */
3244 remote_ip := f_rnd_int(c_UINT32_MAX);
3245 remote_port := f_rnd_int(c_UINT16_MAX);
3246 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3247 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3248 "IPA MDCX ACK");
3249 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3250 "IPA DLCX ACK");
3251}
3252testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
3253 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003254 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01003255 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
3256 vc_conn.done;
3257}
3258
Harald Welte9912eb52018-02-25 13:30:15 +01003259/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
3260function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
3261 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
3262 "IPA CRCX NACK");
3263}
3264testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
3265 var ConnHdlrPars pars;
3266 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02003267 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01003268
3269 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
3270 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3271 vc_conn.done;
3272
3273 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
3274 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3275 vc_conn.done;
3276}
3277
Harald Weltea3f1df92018-02-25 12:49:55 +01003278
Harald Welte883340c2018-02-28 18:59:29 +01003279/***********************************************************************
3280 * PCU Socket related tests
3281 ***********************************************************************/
3282
Harald Welte07bd2d22019-05-25 11:03:30 +02003283/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003284friend function f_TC_pcu_act_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr, boolean exp_success)
Harald Welte883340c2018-02-28 18:59:29 +01003285runs on test_CT {
3286 timer T := 3.0;
3287
3288 /* we don't expect any RTS.req before PDCH are active */
3289 T.start;
3290 alt {
3291 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003292 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01003293 }
3294 [] PCU.receive { repeat; }
3295 [] T.timeout { }
3296 }
3297
3298 /* Send PDCH activate request for known PDCH timeslot */
3299 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
3300
3301 /* we now expect RTS.req for this timeslot (only) */
3302 T.start;
3303 alt {
3304 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
3305 setverdict(pass);
3306 }
3307 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3308 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003309 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01003310 }
3311 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003312 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01003313 }
3314 [] PCU.receive { repeat; }
3315 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003316 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003317 }
3318 [not exp_success] T.timeout {
3319 setverdict(pass);
3320 }
3321 }
3322}
3323
Harald Welte07bd2d22019-05-25 11:03:30 +02003324/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003325friend function f_TC_pcu_deact_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr)
Harald Welte883340c2018-02-28 18:59:29 +01003326runs on test_CT {
3327 timer T := 3.0;
3328
3329 /* Send PDCH activate request for known PDCH timeslot */
3330 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
3331
3332 PCU.clear;
3333 /* we now expect no RTS.req for this timeslot */
3334 T.start;
3335 alt {
3336 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003337 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003338 }
3339 [] PCU.receive { repeat; }
3340 [] T.timeout {
3341 setverdict(pass);
3342 }
3343 }
3344}
3345
Harald Weltead033dc2019-05-25 17:28:16 +02003346friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003347 f_init();
3348 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
3349}
3350
Harald Welte883340c2018-02-28 18:59:29 +01003351/* PDCH activation via PCU socket; check for presence of RTS.req */
3352testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003353 f_init_pcu_test();
3354
Harald Welte883340c2018-02-28 18:59:29 +01003355 f_TC_pcu_act_req(0, 0, 7, true);
3356}
3357
3358/* PDCH activation via PCU socket on non-PDCU timeslot */
3359testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003360 f_init_pcu_test();
3361
Harald Welte883340c2018-02-28 18:59:29 +01003362 f_TC_pcu_act_req(0, 0, 1, false);
3363}
3364
3365/* PDCH activation via PCU socket on wrong BTS */
3366testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003367 f_init_pcu_test();
3368
Harald Welte883340c2018-02-28 18:59:29 +01003369 f_TC_pcu_act_req(23, 0, 7, false);
3370}
3371
3372/* PDCH activation via PCU socket on wrong TRX */
3373testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003374 f_init_pcu_test();
3375
Harald Welte883340c2018-02-28 18:59:29 +01003376 f_TC_pcu_act_req(0, 23, 7, false);
3377}
3378
3379/* PDCH deactivation via PCU socket; check for absence of RTS.req */
3380testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003381 f_init_pcu_test();
3382
Harald Welte883340c2018-02-28 18:59:29 +01003383 /* Activate PDCH */
3384 f_TC_pcu_act_req(0, 0, 7, true);
3385 f_sleep(1.0);
3386 /* and De-Activate again */
3387 f_TC_pcu_deact_req(0, 0, 7);
3388}
3389
3390/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
3391testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003392 f_init_pcu_test();
3393
Harald Welte883340c2018-02-28 18:59:29 +01003394 f_TC_pcu_deact_req(0, 0, 1);
3395}
3396
3397/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
3398testcase TC_pcu_ver_si13() runs on test_CT {
3399 const octetstring si13 := '00010203040506070909'O;
3400 var PCUIF_send_data sd;
3401 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01003402 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003403
3404 /* Set SI13 via RSL */
3405 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01003406
Harald Welte883340c2018-02-28 18:59:29 +01003407 T.start;
3408 alt {
3409 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
3410 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
3411 setverdict(pass);
3412 } else {
3413 repeat;
3414 }
3415 }
3416 [] PCU.receive { repeat; }
3417 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003418 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01003419 }
3420 }
3421}
3422
3423private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
3424
3425/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02003426friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01003427 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
3428runs on test_CT
3429{
3430 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
3431 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
3432}
3433
3434/* helper function to wait for RTS.ind for given SAPI on given BTS/TRX/TS and then send */
Harald Weltead033dc2019-05-25 17:28:16 +02003435friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
3436 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01003437runs on test_CT
3438{
3439 var PCUIF_send_data sd;
3440
3441 timer T := 3.0;
3442 T.start;
3443 alt {
3444 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3445 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
3446 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
3447 sd.data.u.rts_req.fn, sapi, data);
3448 }
3449 [] PCU.receive { repeat; }
3450 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003451 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01003452 }
3453 }
3454}
3455
3456/* Send DATA.req on invalid BTS */
3457testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003458 var TfiUsfArr tua := f_TfiUsfArrInit();
3459 var octetstring data := '0000'O & f_rnd_octstring(21);
3460
3461 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003462
Harald Welte883340c2018-02-28 18:59:29 +01003463 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003464 f_TfiUsfArrSet(tua, 7, 0);
3465 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3466 f_sleep(1.0);
3467
3468 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003469}
3470
3471/* Send DATA.req on invalid TRX */
3472testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003473 var TfiUsfArr tua := f_TfiUsfArrInit();
3474 var octetstring data := '0000'O & f_rnd_octstring(21);
3475
3476 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003477
Harald Welte883340c2018-02-28 18:59:29 +01003478 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003479 f_TfiUsfArrSet(tua, 7, 0);
3480 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3481 f_sleep(1.0);
3482
3483 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003484}
3485
3486/* Send DATA.req on invalid timeslot */
3487testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003488 var TfiUsfArr tua := f_TfiUsfArrInit();
3489 var octetstring data := '0000'O & f_rnd_octstring(21);
3490
3491 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003492
Harald Welte883340c2018-02-28 18:59:29 +01003493 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003494 f_TfiUsfArrSet(tua, 7, 0);
3495 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3496 f_sleep(1.0);
3497
3498 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003499}
3500
3501/* Send DATA.req on timeslot that hasn't been activated */
3502testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003503 var TfiUsfArr tua := f_TfiUsfArrInit();
3504 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01003505
Harald Welte7162a612019-05-26 12:56:09 +02003506 f_virtphy_common();
3507
3508 f_TfiUsfArrSet(tua, 7, 0);
3509 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3510 f_sleep(1.0);
3511
3512 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003513}
3514
Harald Weltead033dc2019-05-25 17:28:16 +02003515private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02003516 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
3517 boolean wait_rts := true)
3518runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003519 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02003520 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02003521
3522 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02003523 if (wait_rts) {
3524 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
3525 } else {
3526 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
3527 }
Harald Weltead033dc2019-05-25 17:28:16 +02003528
3529 T.start;
3530 alt {
Harald Welte7162a612019-05-26 12:56:09 +02003531 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02003532 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
3533 setverdict(pass);
3534 }
Harald Welte7162a612019-05-26 12:56:09 +02003535 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
3536 setverdict(fail, "Received unexpected ", rx_dl);
3537 }
Harald Weltead033dc2019-05-25 17:28:16 +02003538 [] L1CTL.receive {
3539 repeat;
3540 }
Harald Welte7162a612019-05-26 12:56:09 +02003541 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02003542 setverdict(fail, "Timeout waiting for ", data);
3543 }
Harald Welte7162a612019-05-26 12:56:09 +02003544 [not expect_data] T.timeout {
3545 setverdict(pass);
3546 }
Harald Weltead033dc2019-05-25 17:28:16 +02003547 }
3548}
3549
3550private function f_disable_dynamic_ts() runs on test_CT
3551{
3552 f_init_vty_bsc();
3553 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
3554 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
3555 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
3556 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01003557 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02003558}
3559
3560private function f_virtphy_common() runs on test_CT {
3561 f_disable_dynamic_ts();
3562 f_init_l1ctl();
3563 f_l1_tune(L1CTL);
3564}
3565
3566testcase TC_pcu_data_req_pdtch() runs on test_CT {
3567 var TfiUsfArr tua := f_TfiUsfArrInit();
3568 var octetstring data := '0000'O & f_rnd_octstring(21);
3569
3570 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003571
Harald Welte883340c2018-02-28 18:59:29 +01003572 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003573 f_TfiUsfArrSet(tua, 7, 0);
3574 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3575 f_sleep(1.0);
3576
3577 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01003578}
3579
3580testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003581 var TfiUsfArr tua := f_TfiUsfArrInit();
3582 var octetstring data := '0000'O & f_rnd_octstring(21);
3583
3584 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003585
Harald Welte883340c2018-02-28 18:59:29 +01003586 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003587 f_TfiUsfArrSet(tua, 7, 0);
3588 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3589 f_sleep(1.0);
3590
3591 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01003592}
3593
3594/* Send AGCH from PCU; check it appears on Um side */
3595testcase TC_pcu_data_req_agch() runs on test_CT {
3596 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01003597 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003598 f_init_l1ctl();
3599 f_l1_tune(L1CTL);
3600
3601 f_TC_pcu_act_req(0, 0, 7, true);
3602 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
3603
3604 T.start;
3605 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003606 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01003607 setverdict(pass);
3608 }
3609 [] L1CTL.receive { repeat; }
3610 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003611 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003612 }
3613 }
3614}
3615
Harald Welte928622b2019-05-26 13:22:59 +02003616/* Send AGCH from PCU; check it appears on Um side */
3617testcase TC_pcu_data_req_pch() runs on test_CT {
3618 timer T := 3.0;
3619 f_init_pcu_test();
3620 f_init_l1ctl();
3621 f_l1_tune(L1CTL);
3622
3623 f_TC_pcu_act_req(0, 0, 7, true);
3624 /* three characters prefix: last 3 digits of IMSI as ASCII */
3625 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
3626
3627 T.start;
3628 alt {
3629 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
3630 setverdict(pass);
3631 }
3632 [] L1CTL.receive { repeat; }
3633 [] T.timeout {
3634 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
3635 }
3636 }
3637}
3638
Harald Welte883340c2018-02-28 18:59:29 +01003639/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
3640testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
3641 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01003642 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003643 f_init_l1ctl();
3644 f_l1_tune(L1CTL);
3645
3646 /* append 3 last imsi digits so BTS can compute pagng group */
3647 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
3648
3649 timer T := 0.5;
3650 T.start;
3651 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003652 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01003653 /* TODO: verify paging group */
3654 setverdict(pass);
3655 }
3656 [] L1CTL.receive { repeat; }
3657 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003658 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003659 }
3660 }
3661}
3662
3663/* Send RACH from Um side, expect it to show up on PCU socket */
3664testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003665 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003666 f_init_l1ctl();
3667 f_l1_tune(L1CTL);
3668
3669 var GsmFrameNumber fn_last := 0;
3670 for (var integer i := 0; i < 1000; i := i+1) {
3671 var OCT1 ra := f_rnd_ra_ps();
3672 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
3673 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003674 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01003675 }
3676 fn_last := fn;
3677
3678 timer T := 2.0;
3679 T.start;
3680 alt {
3681 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
3682 T.stop;
3683 }
3684 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003685 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003686 }
3687 [] PCU.receive { repeat; }
3688 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003689 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003690 }
3691 }
3692 }
3693 setverdict(pass);
3694}
3695
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07003696/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
3697 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
3698testcase TC_pcu_ext_rach_content() runs on test_CT {
3699 var template PCUIF_Message pcu_rach_ind;
3700 var GsmFrameNumber fn_last := 0;
3701 var L1ctlRachSynchSeq synch_seq;
3702 var PCUIF_BurstType pcu_bt;
3703 var GsmFrameNumber fn;
3704 var BIT11 ra11;
3705
3706 f_init_pcu_test();
3707 f_init_l1ctl();
3708 f_l1_tune(L1CTL);
3709
3710 for (var integer i := 0; i < 1000; i := i+1) {
3711 /* We need to test both TS1 & TS2 */
3712 if (i rem 2 == 0) {
3713 synch_seq := RACH_SYNCH_SEQ_TS1;
3714 pcu_bt := BURST_TYPE_1;
3715 } else {
3716 synch_seq := RACH_SYNCH_SEQ_TS2;
3717 pcu_bt := BURST_TYPE_2;
3718 }
3719
3720 ra11 := f_rnd_ra11_ps();
3721 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
3722 if (fn == fn_last) {
3723 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3724 "Two RACH in same FN?!?");
3725 }
3726 fn_last := fn;
3727
3728 /* Compose the expected message */
3729 pcu_rach_ind := tr_PCUIF_RACH_IND(
3730 bts_nr := 0,
3731 ra := bit2int(ra11),
3732 is_11bit := 1,
3733 burst_type := pcu_bt,
3734 fn := fn);
3735
3736 timer T := 2.0;
3737 T.start;
3738 alt {
3739 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
3740 T.stop;
3741 }
3742 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
3743 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
3744 }
3745 [] PCU.receive { repeat; }
3746 [] T.timeout {
3747 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
3748 }
3749 }
3750 }
3751 setverdict(pass);
3752}
3753
Harald Welte883340c2018-02-28 18:59:29 +01003754/* Send PAGING via RSL, expect it to shw up on PCU socket */
3755testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003756 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003757
3758 for (var integer i := 0; i < 100; i := i+1) {
3759 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
3760 timer T := 3.0;
3761 if (i < 50) {
3762 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
3763 } else {
3764 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
3765 }
3766 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
3767 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
3768 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
3769
3770 /* Send RSL PAGING COMMAND */
3771 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
3772 T.start;
3773 alt {
3774 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
3775 }
3776 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003777 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003778 }
3779 [] PCU.receive { repeat; }
3780 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003781 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003782 }
3783 }
3784 }
3785 setverdict(pass);
3786}
3787
Harald Welted66c9b82019-05-25 09:03:15 +02003788/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
3789testcase TC_pcu_time_ind() runs on test_CT {
3790 var PCUIF_send_data pcu_sd;
3791 var integer num_time_ind := 0;
3792 var integer first_fn, last_fn;
3793 var float test_duration := 5.0;
3794 timer T;
3795
3796 f_init_pcu_test();
3797 f_TC_pcu_act_req(0, 0, 7, true);
3798
3799 PCU.clear;
3800 T.start(test_duration);
3801 alt {
3802 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
3803 num_time_ind := num_time_ind + 1;
3804 if (not isbound(first_fn)) {
3805 first_fn := pcu_sd.data.u.time_ind.fn;
3806 }
3807 last_fn := pcu_sd.data.u.time_ind.fn;
3808 repeat;
3809 }
3810 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
3811 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
3812 repeat;
3813 }
3814 [] PCU.receive {
3815 repeat;
3816 }
3817 [] T.timeout {}
3818 }
3819 var integer fn_expired := last_fn - first_fn;
3820 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
3821
3822 /* verify the number of frames expired matches our expectation */
3823 const float c_GSM_FN_DURATION_MS := 4.61538;
3824 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02003825 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02003826 if (not match(fn_expired, t_fn_expected)) {
3827 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
3828 }
3829
3830 /* There are three TIME.ind in every fn MOD 13 */
3831 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
3832 /* Add some tolerance */
3833 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
3834 if (not match(num_time_ind, t_time_ind_exp)) {
3835 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
3836 }
3837
3838 setverdict(pass);
3839}
3840
Harald Welte4832c862019-05-25 14:57:18 +02003841/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
3842testcase TC_pcu_rts_req() runs on test_CT {
3843 var PCUIF_send_data pcu_sd;
3844 var integer first_fn, last_fn;
3845 var integer num_rts_pdtch := 0;
3846 var integer num_rts_ptcch := 0;
3847 var float test_duration := 5.0;
3848 timer T;
3849
3850 f_init_pcu_test();
3851 f_TC_pcu_act_req(0, 0, 7, true);
3852
3853 PCU.clear;
3854 T.start(test_duration);
3855 alt {
3856 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
3857 -> value pcu_sd {
3858 num_rts_pdtch := num_rts_pdtch + 1;
3859 if (not isbound(first_fn)) {
3860 first_fn := pcu_sd.data.u.rts_req.fn;
3861 }
3862 last_fn := pcu_sd.data.u.rts_req.fn;
3863 repeat;
3864 }
3865 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
3866 -> value pcu_sd {
3867 num_rts_ptcch := num_rts_ptcch + 1;
3868 if (not isbound(first_fn)) {
3869 first_fn := pcu_sd.data.u.rts_req.fn;
3870 }
3871 last_fn := pcu_sd.data.u.rts_req.fn;
3872 repeat;
3873 }
3874 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
3875 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
3876 repeat;
3877 }
3878 [] PCU.receive {
3879 repeat;
3880 }
3881 [] T.timeout {}
3882 }
3883 var integer fn_expired := last_fn - first_fn;
3884 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
3885 ", num_rts_ptcch=", num_rts_ptcch);
3886
3887 /* verify the number of frames expired matches our expectation */
3888 const float c_GSM_FN_DURATION_MS := 4.61538;
3889 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02003890 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02003891 if (not match(fn_expired, t_fn_expected)) {
3892 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
3893 }
3894
3895 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
3896 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
3897 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
3898 if (not match(num_rts_ptcch, t_ptcch_exp)) {
3899 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
3900 t_ptcch_exp);
3901 }
3902
3903 /* We have 12 PDTCH blocks every 52-multiframe */
3904 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
3905 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
3906 if (not match(num_rts_pdtch, t_pdtch_exp)) {
3907 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
3908 t_pdtch_exp);
3909 }
3910
3911 setverdict(pass);
3912}
3913
Harald Welte07bd2d22019-05-25 11:03:30 +02003914/* test for generating Abis side OML ALERT from the PCU */
3915testcase TC_pcu_oml_alert() runs on test_CT {
3916 var PCUIF_send_data pcu_sd;
3917 var integer num_time_ind := 0;
3918 var integer first_fn, last_fn;
3919 var float test_duration := 5.0;
3920 timer T;
3921
3922 f_init_pcu_test();
3923 f_TC_pcu_act_req(0, 0, 7, true);
3924
3925 /* re-connect CTRL port from BTS to BSC */
3926 f_ipa_ctrl_stop();
3927 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
3928
3929 /* Send that OML Alert */
3930 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
3931
3932 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
3933 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
3934 setverdict(pass);
3935}
3936
Harald Welteeaa9a862019-05-26 23:01:08 +02003937template (value) PDU_ML3_MS_NW ts_RRM_GprsSuspReq(template (value) OCT4 tlli,
3938 template (value) RoutingAreaIdentificationV rai,
3939 template (value) OCT1 cause) := {
3940 discriminator := '0000'B, /* overwritten */
3941 tiOrSkip := {
3942 skipIndicator := '0000'B
3943 },
3944 msgs := {
3945 rrm := {
3946 gPRS_suspensionRequest := {
3947 messageType := '00110100'B,
3948 tLLI := tlli,
3949 routingAreaIdentification := rai,
3950 suspensionCause := cause,
3951 service_Support := omit
3952 }
3953 }
3954 }
3955}
3956
3957/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
3958private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
3959 var PCUIF_Message first_info;
3960 var integer pcu_conn_id := -1;
3961 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3962 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
3963 var OCT4 tlli := '01020304'O;
3964 var OCT1 cause := '23'O;
3965 timer T := 5.0;
3966
3967 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3968
3969 f_l1_tune(L1CTL);
3970 RSL.clear;
3971
3972 f_est_dchan();
3973 L1CTL.clear;
3974
3975 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
3976
3977 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
3978 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
3979 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
3980
3981 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
3982 T.start;
3983 alt {
3984 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
3985 setverdict(pass);
3986 }
3987 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
3988 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
3989 }
3990 [] PCU.receive {
3991 repeat;
3992 }
3993 [] T.timeout {
3994 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
3995 }
3996 }
3997}
3998testcase TC_pcu_rr_suspend() runs on test_CT {
3999 var ConnHdlrPars pars;
4000 var ConnHdlr vc_conn;
4001
4002 f_init();
4003
4004 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
4005 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
4006 vc_conn.done;
4007}
Harald Welte07bd2d22019-05-25 11:03:30 +02004008
Harald Weltea2e0e942019-05-27 18:12:53 +02004009/* Ensure that PCUIF socket can accept only a single connection */
4010testcase TC_pcu_socket_connect_multi() runs on test_CT {
4011 timer T := 5.0;
4012
4013 /* this (among other things) establishes the first connection to the PCUIF socket */
4014 f_init();
4015
4016 /* try to establish a second connection, expect it to fail */
4017 PCU.send(UD_connect:{mp_pcu_socket, -1});
4018 T.start;
4019 alt {
4020 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
4021 setverdict(pass);
4022 }
4023 [] PCU.receive(UD_connect_result:?) {
4024 setverdict(fail, "Unexpected unix domain connect result");
4025 }
4026 [] T.timeout {
4027 setverdict(pass);
4028 }
4029 }
4030 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4031}
4032
Harald Weltec8effb72019-05-27 18:23:04 +02004033/* Ensure that PCUIF socket can disconnect + reconnect */
4034testcase TC_pcu_socket_reconnect() runs on test_CT {
4035 /* this (among other things) establishes the first connection to the PCUIF socket */
4036 f_init();
4037
4038 f_sleep(1.0);
4039
4040 f_pcuif_close(PCU, g_pcu_conn_id);
4041 g_pcu_conn_id := -1;
4042
4043 f_sleep(1.0);
4044
4045 /* re-connect */
4046 PCU.clear;
4047 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
4048 setverdict(pass);
4049
4050 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4051}
4052
Harald Weltebe030482019-05-27 22:29:35 +02004053/* Ensure that GPRS capability is not advertised before PCU socket conncet */
4054private function f_get_si3(L1CTL_PT pt) runs on test_CT return SystemInformationType3 {
4055 var L1ctlDlMessage l1_dl;
4056 var SystemInformation si;
4057 timer T := 5.0;
4058 T.start;
4059 alt {
4060 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
4061 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
4062 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
4063 log("Ignoring non-RR SI ", l1_dl);
4064 repeat;
4065 }
4066 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
4067 if (not ischosen(si.payload.si3)) {
4068 repeat;
4069 }
4070 }
4071 [] pt.receive {
4072 repeat;
4073 }
4074 [] T.timeout {
4075 setverdict(fail, "Timeout waiting for SI3");
4076 }
4077 }
4078 return si.payload.si3;
4079}
4080
4081/* CSN.1 L/H logic: is the bit at the current position using "inverted logic" (true) or not? */
4082private function f_bitpos_is_inv(integer idx) return boolean {
4083 select (idx mod 8) {
4084 case ((2, 4, 6, 7)) { return true; } /* 1-bits of 0x2B */
4085 case else { return false; } /* 0-bits of 0x2B */
4086 }
4087}
4088/* determine if the bit at position 'idx' in 'str' is a CSN.1 'H' (true) or 'L' (false) */
4089private function f_bit_is_high(bitstring str, integer idx) return boolean {
4090 var boolean invert := f_bitpos_is_inv(idx);
4091 if (invert) {
4092 if (str[idx] == '1'B) {
4093 return false;
4094 } else {
4095 return true;
4096 }
4097 } else {
4098 if (str[idx] == '1'B) {
4099 return true;
4100 } else {
4101 return false;
4102 }
4103 }
4104}
4105/* As the TITAN RAW codec cannot expres the CSN.1 L/H concept yet, we have to do this
4106 manually. Let's hope https://www.eclipse.org/forums/index.php/t/1099087/ takes off and
4107 we can replace this piece of code soon ... */
4108private function f_si3_has_gprs_indicator(OCT4 si3_restoctets) return boolean {
4109 var bitstring bits := oct2bit(si3_restoctets);
4110 var integer idx := 0;
4111
4112 if (f_bit_is_high(bits, idx)) {
4113 /* skip Optional selection parameters */
4114 idx := idx + 16;
4115 } else {
4116 idx := idx + 1;
4117 }
4118
4119 if (f_bit_is_high(bits, idx)) {
4120 /* skip Optional power offset */
4121 idx := idx + 3;
4122 } else {
4123 idx := idx + 1;
4124 }
4125
4126 /* skip SI2ter Indicator */
4127 idx := idx + 1;
4128
4129 /* skip Early CM Sending Control */
4130 idx := idx + 1;
4131
4132 /* skip Scheduling if and where */
4133 if (f_bit_is_high(bits, idx)) {
4134 idx := idx + 4;
4135 } else {
4136 idx := idx + 1;
4137 }
4138
4139 return f_bit_is_high(bits, idx);
4140}
4141
4142testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
4143 var SystemInformationType3 si3;
4144 timer T := 5.0;
4145
4146 /* don't call f_init() as this would connect PCU socket */
4147 f_init_rsl(testcasename());
4148 T.start;
4149 alt {
4150 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
4151 [] T.timeout {
4152 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
4153 }
4154 }
4155 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
4156
4157 f_init_l1ctl();
4158 f_l1_tune(L1CTL);
4159
4160 f_sleep(2.0);
4161 L1CTL.clear;
4162 si3 := f_get_si3(L1CTL);
4163 if (f_si3_has_gprs_indicator(si3.rest_octets)) {
4164 setverdict(fail, "SI3 indicates GPRS even before PCU socket connected");
4165 } else {
4166 setverdict(pass);
4167 }
4168 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4169}
4170
4171/* Ensure that GPRS capability is advertised after PCU socket connect */
4172testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
4173 var SystemInformationType3 si3;
4174
4175 /* this (among other things) establishes the first connection to the PCUIF socket */
4176 f_init();
4177 f_init_l1ctl();
4178 f_l1_tune(L1CTL);
4179
4180 f_sleep(2.0);
4181 L1CTL.clear;
4182 si3 := f_get_si3(L1CTL);
4183 if (not f_si3_has_gprs_indicator(si3.rest_octets)) {
4184 setverdict(fail, "SI3 indicates no GPRS despite PCU socket connected");
4185 } else {
4186 setverdict(pass);
4187 }
4188 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4189}
4190
4191/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
4192testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
4193 var SystemInformationType3 si3;
4194
4195 /* this (among other things) establishes the first connection to the PCUIF socket */
4196 f_init();
4197 f_init_l1ctl();
4198 f_l1_tune(L1CTL);
4199
4200 f_pcuif_close(PCU, g_pcu_conn_id);
4201 g_pcu_conn_id := -1;
4202
4203 f_sleep(1.0);
4204
4205 /* re-connect */
4206 PCU.clear;
4207 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
4208
4209 f_sleep(2.0);
4210 L1CTL.clear;
4211 si3 := f_get_si3(L1CTL);
4212 if (f_si3_has_gprs_indicator(si3.rest_octets)) {
4213 setverdict(fail, "SI3 indicates GPRS after PCU socket disconnected");
4214 } else {
4215 setverdict(pass);
4216 }
4217
4218 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4219}
4220
Harald Welted66c9b82019-05-25 09:03:15 +02004221
Harald Welte3d04ae62018-04-04 20:29:05 +02004222/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02004223 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02004224 ***********************************************************************/
4225
4226private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4227runs on ConnHdlr {
4228 var PCUIF_send_data sd;
4229 /* Expect BTS to immediately acknowledge activation as PDCH */
4230 PCU.clear;
4231 f_rsl_chan_act(g_pars.chan_mode);
4232 /* expect INFO_IND on PCU interface listing TS as PDCH */
4233 alt {
4234 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4235 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004236 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02004237 }
4238 }
4239 [] PCU.receive { repeat; }
4240 }
4241 /* try to activate this PDCH from the PCU point of view */
4242 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4243 /* FIXME: is there a response? */
4244}
4245
4246private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4247runs on ConnHdlr {
4248 var PCUIF_send_data sd;
4249 /* Send RSL CHAN REL (deactivate) */
4250 PCU.clear;
4251 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
4252 /* expect BTS to ask PCU to deactivate the channel */
4253 alt {
4254 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4255 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004256 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02004257 }
4258 }
4259 [] PCU.receive { repeat; }
4260 }
4261 /* Emulate PCU asking BTS to deactivate PDCH */
4262 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4263 alt {
4264 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
4265 setverdict(pass);
4266 }
4267 [] RSL.receive { repeat; }
4268 }
4269}
4270
4271/* Activate Osmocom-style dynamic PDCH from BSC side */
4272function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
4273 var PCUIF_Message first_info;
4274 var integer ts_nr := g_chan_nr.tn;
4275 var integer trx_nr := 0;
4276 var integer bts_nr := 0;
4277 var integer pcu_conn_id := -1;
4278
4279 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4280
4281 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4282 f_sleep(3.0);
4283 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4284 setverdict(pass);
4285}
4286testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
4287 var ConnHdlrPars pars;
4288 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004289 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02004290
4291 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4292 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
4293 vc_conn.done;
4294}
4295
4296/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
4297function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
4298 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02004299 var integer pcu_conn_id := -1;
4300
4301 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4302
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02004303 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
4304 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
4305 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02004306 setverdict(pass);
4307}
4308testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
4309 var ConnHdlrPars pars;
4310 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004311 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02004312
4313 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4314 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
4315 vc_conn.done;
4316}
4317
4318/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
4319function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
4320 var PCUIF_Message first_info;
4321 var integer ts_nr := g_chan_nr.tn;
4322 var integer trx_nr := 0;
4323 var integer bts_nr := 0;
4324 var integer pcu_conn_id := -1;
4325
4326 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4327
4328 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02004329 /* Send a second Chan Activ and expect it to be NACKed */
4330 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
4331 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02004332 setverdict(pass);
4333}
4334testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
4335 var ConnHdlrPars pars;
4336 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004337 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02004338
4339 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4340 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
4341 vc_conn.done;
4342}
4343
4344/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
4345function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
4346 var PCUIF_Message first_info;
4347 var integer ts_nr := g_chan_nr.tn;
4348 var integer trx_nr := 0;
4349 var integer bts_nr := 0;
4350 var integer pcu_conn_id := -1;
4351 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
4352
4353 /* register for the TCH/F channel number */
4354 f_rslem_register(0, chan_nr);
4355
4356 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4357
4358 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
4359 "RSL CHAN ACT");
4360 setverdict(pass);
4361}
4362testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
4363 var ConnHdlrPars pars;
4364 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004365 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02004366
4367 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4368 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
4369 vc_conn.done;
4370}
4371
4372/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
4373function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
4374 var PCUIF_Message first_info;
4375 var integer ts_nr := g_chan_nr.tn;
4376 var integer trx_nr := 0;
4377 var integer bts_nr := 0;
4378 var integer pcu_conn_id := -1;
4379 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
4380 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
4381
4382 /* register for the TCH/H channel numbers */
4383 f_rslem_register(0, chan_nr[0]);
4384 f_rslem_register(0, chan_nr[1]);
4385
4386 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4387
4388 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
4389 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
4390 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
4391 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
4392 setverdict(pass);
4393}
4394testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
4395 var ConnHdlrPars pars;
4396 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004397 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02004398
4399 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4400 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
4401 vc_conn.done;
4402}
4403
Harald Welte9bbbfb52018-04-05 09:33:19 +02004404/***********************************************************************
4405 * IPA Style Dynamic Timeslot Support
4406 ***********************************************************************/
4407
4408private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4409runs on ConnHdlr {
4410 var PCUIF_send_data sd;
4411 /* Expect BTS to immediately acknowledge activation as PDCH */
4412 PCU.clear;
4413 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
4414 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004415 timer T_wait := 2.0;
4416 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004417 alt {
4418 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4419 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004420 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
4421 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
4422 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004423 }
4424 }
4425 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004426 [] T_wait.timeout {
4427 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4428 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
4429 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02004430 }
4431 /* try to activate this PDCH from the PCU point of view */
4432 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4433 /* FIXME: is there a response? */
4434
4435 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
4436}
4437
4438private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4439runs on ConnHdlr {
4440 var PCUIF_send_data sd;
4441 /* Send RSL CHAN REL (deactivate) */
4442 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
4443 PCU.clear;
4444 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004445 timer T_wait := 2.0;
4446 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004447 alt {
4448 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4449 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004450 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
4451 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
4452 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004453 }
4454 }
4455 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004456 [] T_wait.timeout {
4457 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4458 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
4459 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02004460 }
4461 /* Emulate PCU asking BTS to deactivate PDCH */
4462 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4463 alt {
4464 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
4465 setverdict(pass);
4466 }
4467 [] RSL.receive { repeat; }
4468 }
4469}
4470
4471/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
4472function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
4473 var PCUIF_Message first_info;
4474 var integer ts_nr := g_chan_nr.tn;
4475 var integer trx_nr := 0;
4476 var integer bts_nr := 0;
4477 var integer pcu_conn_id := -1;
4478
4479 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4480
4481 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4482 f_sleep(3.0);
4483 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4484
4485 setverdict(pass);
4486
4487}
4488testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
4489 var ConnHdlrPars pars;
4490 var ConnHdlr vc_conn;
4491 f_init();
4492
4493 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4494 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
4495 vc_conn.done;
4496}
4497
4498/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
4499function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
4500 var PCUIF_Message first_info;
4501 var integer ts_nr := g_chan_nr.tn;
4502 var integer trx_nr := 0;
4503 var integer bts_nr := 0;
4504 var integer pcu_conn_id := -1;
4505
4506 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4507
4508 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4509 "RSL CHAN ACT");
4510 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4511 "RF CHAN REL", true);
4512 setverdict(pass);
4513}
4514testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
4515 var ConnHdlrPars pars;
4516 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004517 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02004518
4519 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4520 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
4521 vc_conn.done;
4522}
4523
4524/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
4525function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
4526 var PCUIF_Message first_info;
4527 var integer ts_nr := g_chan_nr.tn;
4528 var integer trx_nr := 0;
4529 var integer bts_nr := 0;
4530 var integer pcu_conn_id := -1;
4531
4532 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4533
4534 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4535 "RSL CHAN ACT");
4536
4537 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
4538 alt {
4539 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
4540 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004541 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02004542 }
4543 [] RSL.receive { repeat; }
4544 }
4545
4546 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4547 "RF CHAN REL", true);
4548 setverdict(pass);
4549}
4550testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
4551 var ConnHdlrPars pars;
4552 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004553 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02004554
4555 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4556 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
4557 vc_conn.done;
4558}
4559
4560/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
4561function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
4562 var PCUIF_Message first_info;
4563 var integer ts_nr := g_chan_nr.tn;
4564 var integer trx_nr := 0;
4565 var integer bts_nr := 0;
4566 var integer pcu_conn_id := -1;
4567
4568 /* register for the TCH/F channel number */
4569 f_rslem_register(0, g_chan_nr);
4570
4571 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4572
4573 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4574
4575 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
4576 "RSL CHAN ACT");
4577
4578 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4579
4580 setverdict(pass);
4581}
4582testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
4583 var ConnHdlrPars pars;
4584 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004585 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02004586
4587 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4588 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
4589 vc_conn.done;
4590}
4591
4592
Harald Welte0472ab42018-03-12 15:02:26 +01004593/***********************************************************************
4594 * LAPDm / RLL related
4595 ***********************************************************************/
4596
4597private function f_tx_lapdm(template (value) LapdmFrame l,
4598 template (value) RslLinkId link_id) runs on ConnHdlr {
4599 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07004600 var template (value) SacchL1Header l1h;
4601
4602 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01004603 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07004604 /* Compose dummy L1 header */
4605 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
4606 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, link_id, l1h, f_pad_oct(l2, 21, '2B'O)));
Pau Espin Pedrola0fb42a2018-10-10 15:56:39 +02004607 } else {
4608 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07004609 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, link_id, f_pad_oct(l2, 23, '2B'O)));
Harald Welte0472ab42018-03-12 15:02:26 +01004610 }
Harald Welte0472ab42018-03-12 15:02:26 +01004611}
4612
4613type record RllTestCase {
4614 uint3_t sapi,
4615 RslLinkId link_id,
4616 octetstring l3,
4617 boolean exp
4618}
4619type record of RllTestCase RllTestCases;
4620template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
4621 sapi := sapi,
4622 link_id := id,
4623 l3 := l3,
4624 exp := exp
4625}
4626
4627/* execute the same callback function with a set of different parameters (tcs) on a
4628 * variety of logical channels */
4629private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
4630 var ConnHdlrPars pars;
4631 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004632 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01004633
4634 /* test on each of the channels we have */
4635 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
4636 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
4637
4638 /* test each of the test cases on the current channel */
4639 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
4640 pars.spec.rll := tcs[j];
4641 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
4642 vc_conn := f_start_handler(fn, pars);
4643 vc_conn.done;
4644 }
4645 }
4646
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004647 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01004648}
4649
4650/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
4651private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
4652 var RllTestCase tc := g_pars.spec.rll;
4653 timer T := 3.0;
4654
4655 f_l1_tune(L1CTL);
4656 RSL.clear;
4657
4658 /* activate the logical channel */
4659 f_est_dchan();
4660 L1CTL.clear;
4661
4662 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
4663 T.start;
4664 alt {
4665 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
4666 if (tc.exp) {
4667 setverdict(pass);
4668 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004669 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01004670 }
4671 }
4672 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
4673 if (tc.exp) {
4674 setverdict(pass);
4675 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004676 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01004677 }
4678 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07004679 /* We also expect to receive the measurements */
4680 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01004681 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004682 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01004683 }
4684 [not tc.exp] T.timeout {
4685 setverdict(pass);
4686 }
4687 }
4688
4689 f_rsl_chan_deact();
4690 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4691 f_rslem_unregister(0, g_chan_nr);
4692}
4693testcase TC_rll_est_ind() runs on test_CT {
4694 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02004695 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01004696 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02004697 /* normal SAPI0 establishment */
4698 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01004699 /* SAPI 3 doesn't support contention resolution */
4700 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
4701 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
4702 /* normal SAPI3 establishment on main DCCH */
4703 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
4704 /* normal SAPI3 establishment on SACCH */
4705 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4706 };
4707 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
4708}
4709
4710/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
4711private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
4712 var RllTestCase tc := g_pars.spec.rll;
4713 var L1ctlDlMessage dl;
4714 timer T := 3.0;
4715
4716 f_l1_tune(L1CTL);
4717 RSL.clear;
4718
4719 /* activate the logical channel */
4720 f_est_dchan();
4721 L1CTL.clear;
4722
4723 /* Send a RSL EST REQ for SAPI3 on main DCCH */
4724 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
4725 T.start;
4726 alt {
4727 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4728 var LapdmFrame lapdm;
4729 var octetstring l2 := dl.payload.data_ind.payload;
4730 if (dl.dl_info.link_id.c == SACCH) {
4731 /* remove L1 header */
4732 l2 := substr(l2, 2, lengthof(l2)-2);
4733 }
4734 lapdm.ab := dec_LapdmFrameAB(l2);
4735 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
4736 setverdict(pass);
4737 } else {
4738 repeat;
4739 }
4740 }
4741 [] L1CTL.receive { repeat; }
4742 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004743 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01004744 }
4745 }
4746
4747 f_rsl_chan_deact();
4748 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4749 f_rslem_unregister(0, g_chan_nr);
4750}
4751testcase TC_rll_est_req_DCCH_3() runs on test_CT {
4752 var RllTestCases tcs := {
4753 /* normal SAPI3 establishment on main DCCH */
4754 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
4755 };
4756 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
4757}
4758testcase TC_rll_est_req_ACCH_3() runs on test_CT {
4759 var RllTestCases tcs := {
4760 /* normal SAPI3 establishment on SACCH */
4761 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4762 }
4763 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
4764}
4765
4766/* altstep to receive a LAPDm frame matching the given template */
4767private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
4768 var L1ctlDlMessage dl;
4769 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4770 var LapdmFrame lapdm;
4771 var octetstring l2 := dl.payload.data_ind.payload;
4772 if (dl.dl_info.link_id.c == SACCH) {
4773 /* remove L1 header */
4774 l2 := substr(l2, 2, lengthof(l2)-2);
4775 }
4776 if (ischosen(exp.ab)) {
4777 lapdm.ab := dec_LapdmFrameAB(l2);
4778 } else if (ischosen(exp.b4)) {
4779 lapdm.b4 := dec_LapdmFrameB4(l2);
4780 } else if (ischosen(exp.bbis)) {
4781 lapdm.bbis := dec_LapdmFrameBbis(l2);
4782 }
4783 log("Rx LAPDm ", lapdm);
4784 if (match(lapdm, exp)) {
4785 setverdict(pass);
4786 } else {
4787 repeat;
4788 }
4789 }
4790 [] L1CTL.receive { repeat; }
4791}
4792private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
4793 timer T := t;
4794 T.start;
4795 alt {
4796 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004797 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01004798 }
4799 [] as_l1_exp_lapdm(exp);
4800 }
4801}
4802
4803/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
4804private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
4805 /* send SABM from MS -> BTS */
4806 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
4807 /* expect RLL EST IND on Abis */
4808 alt {
4809 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
4810 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
4811 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004812 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01004813 }
4814 [] RSL.receive { repeat; }
4815 }
4816 /* expect UA from BTS -> MS */
4817 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
4818}
4819
4820/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
4821private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
4822 var RllTestCase tc := g_pars.spec.rll;
4823
4824 f_l1_tune(L1CTL);
4825 RSL.clear;
4826
4827 /* activate the logical channel */
4828 f_est_dchan();
4829 L1CTL.clear;
4830
4831 /* first establish the link-layer */
4832 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
4833
4834 /* then send the DISC */
4835 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
4836 /* ... and expect the REL IND on the RSL side */
4837 alt {
4838 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
4839 setverdict(pass);
4840 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07004841 /* We also expect to receive the measurements */
4842 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01004843 }
4844
4845 /* release the channel */
4846 f_rsl_chan_deact();
4847 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4848 f_rslem_unregister(0, g_chan_nr);
4849}
4850testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
4851 var RllTestCases tcs := {
4852 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
4853 };
4854 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4855}
4856
4857testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
4858 var RllTestCases tcs := {
4859 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
4860 };
4861 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4862}
4863testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
4864 var RllTestCases tcs := {
4865 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
4866 };
4867 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4868}
4869testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
4870 var RllTestCases tcs := {
4871 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4872 };
4873 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4874}
4875
4876/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
4877private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
4878 var RllTestCase tc := g_pars.spec.rll;
4879 f_l1_tune(L1CTL);
4880 RSL.clear;
4881
4882 /* activate the logical channel */
4883 f_est_dchan();
4884 L1CTL.clear;
4885
4886 /* first establish the link-layer */
4887 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
4888
4889 /* then send the REL REQ via RSL */
4890 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
4891 /* ... and expect the DISC on the Um side */
4892 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02004893 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01004894 /* FIXME: send a UA in resposne to the DISC */
4895 }
4896 }
4897
4898 /* release the channel */
4899 f_rsl_chan_deact();
4900 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4901 f_rslem_unregister(0, g_chan_nr);
4902}
4903testcase TC_rll_rel_req() runs on test_CT {
4904 var RllTestCases tcs := {
4905 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
4906 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
4907 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
4908 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4909 };
4910 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
4911}
4912
4913/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
4914testcase TC_rll_data_req() runs on test_CT {
4915}
4916
4917/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
4918testcase TC_rll_data_ind() runs on test_CT {
4919}
4920
4921/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
4922private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
4923 var RllTestCase tc := g_pars.spec.rll;
4924
4925 f_l1_tune(L1CTL);
4926 RSL.clear;
4927
4928 f_est_dchan();
4929 L1CTL.clear;
4930
4931 /* Send UNITDATA REQ on RSL side */
4932 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
4933 /* Expect it to arrive on the other side */
4934 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02004935 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01004936 } else {
Harald Weltee613f962018-04-18 22:38:16 +02004937 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01004938 }
4939
4940 /* release the channel */
4941 f_rsl_chan_deact();
4942 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4943 f_rslem_unregister(0, g_chan_nr);
4944}
4945testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
4946 var octetstring l3 := f_rnd_octstring(15);
4947 var RllTestCases tcs := {
4948 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
4949 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
4950 };
4951 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
4952}
4953testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
4954 var octetstring l3 := f_rnd_octstring(19);
4955 var RllTestCases tcs := {
4956 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
4957 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
4958 };
4959 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
4960}
4961
4962/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
4963private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
4964 var RllTestCase tc := g_pars.spec.rll;
4965
4966 f_l1_tune(L1CTL);
4967 RSL.clear;
4968
4969 f_est_dchan();
4970 L1CTL.clear;
4971
4972 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02004973 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01004974 /* Expdct RLL UNITDATA IND on RSL side */
4975 alt {
4976 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
4977 setverdict(pass);
4978 }
4979 [] RSL.receive { repeat; }
4980 }
4981
4982 /* release the channel */
4983 f_rsl_chan_deact();
4984 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4985 f_rslem_unregister(0, g_chan_nr);
4986}
4987testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02004988 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01004989 var RllTestCases tcs := {
4990 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
4991 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
4992 };
4993 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
4994}
4995testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
4996 var octetstring l3 := f_rnd_octstring(18);
4997 var RllTestCases tcs := {
4998 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
4999 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
5000 };
5001 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
5002}
5003
Harald Weltee613f962018-04-18 22:38:16 +02005004/***********************************************************************
5005 * Encryption Related
5006 ***********************************************************************/
5007
5008/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5009function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5010 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
5011 if (link_id.c == SACCH) {
5012 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
5013 } else {
5014 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
5015 }
5016}
5017
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005018/* Expect (or not expect) other kinds of messages */
5019private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
5020 [exp_any] RSL.receive { repeat; }
5021 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005022 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005023 }
5024}
5025
Harald Weltee613f962018-04-18 22:38:16 +02005026/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07005027private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07005028 RslLinkId link_id,
5029 octetstring l3,
5030 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07005031 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07005032) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02005033 timer T := 3.0;
5034 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
5035 T.start;
5036 /* Expect RLL UNITDATA IND on RSL side */
5037 alt {
5038 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
5039 setverdict(pass);
5040 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07005041 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005042 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02005043 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005044 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02005045 }
Harald Weltee613f962018-04-18 22:38:16 +02005046 }
5047}
5048
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005049/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
5050private function f_data_mo(
5051 RslLinkId link_id,
5052 boolean p, uint3_t nr, uint3_t ns,
5053 octetstring l3,
5054 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07005055 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005056) runs on ConnHdlr {
5057 timer T := 3.0;
5058 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
5059 T.start;
5060 /* Expect RLL DATA IND on RSL side */
5061 alt {
5062 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
5063 setverdict(pass);
5064 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07005065 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005066 [] as_rsl_any_ind(exp_any);
5067 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005068 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005069 }
5070 }
5071}
5072
Harald Weltee613f962018-04-18 22:38:16 +02005073/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
5074function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
5075 f_l1_tune(L1CTL);
5076 f_est_dchan(true);
5077
5078 /* now we actually need to transmit some data both ways to check if the encryption works */
5079 var L1ctlDlMessage dl;
5080
Stefan Sperling603d98e2018-07-25 16:47:28 +02005081 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02005082 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5083
5084 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5085 f_unitdata_mt(link_id, l3);
5086
5087 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
5088 f_unitdata_mo(link_id, l3);
5089
5090 /* release the channel */
5091 f_rsl_chan_deact();
5092 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5093 f_rslem_unregister(0, g_chan_nr);
5094}
5095testcase TC_chan_act_a51() runs on test_CT {
5096 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5097 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
5098 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5099}
5100testcase TC_chan_act_a52() runs on test_CT {
5101 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5102 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
5103 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5104}
5105testcase TC_chan_act_a53() runs on test_CT {
5106 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5107 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
5108 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5109}
5110
Eric Wildf1827a72019-05-28 17:37:35 +02005111/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
5112 which should break the en/decryption on purpose by supplying a new key that is unknown to the MS*/
5113function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
5114 f_l1_tune(L1CTL);
5115 f_est_dchan(true);
5116
5117 /* now we actually need to transmit some data both ways to check if the encryption works */
5118 var L1ctlDlMessage dl;
5119
5120 var octetstring l3 := f_rnd_octstring(20);
5121 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5122
5123 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5124 f_unitdata_mt(link_id, l3);
5125
5126 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
5127 f_unitdata_mo(link_id, l3);
5128
5129 var RSL_Message rsl;
5130 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
5131
5132 /* modify key to break proper encryption */
5133 g_pars.encr.key := f_rnd_octstring(8);
5134 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
5135 rsl.ies := rsl.ies & { ei };
5136 RSL.send(rsl);
5137
5138 timer T0 := 1.0;
5139 T0.start;
5140 /* Expect RSL MODIFY ACK */
5141 alt {
5142 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
5143 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
5144 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
5145 }
5146 [] T0.timeout {
5147 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
5148 }
5149 }
5150
5151 var octetstring l3msg := f_rnd_octstring(15);
5152 timer T1 := 3.0;
5153 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
5154 due to broken encryption */
5155 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
5156 T1.start;
5157 alt {
5158 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
5159 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
5160 }
5161 [] T1.timeout {
5162 setverdict(pass);
5163 }
5164 }
5165
5166 /* release the channel */
5167 f_rsl_chan_deact();
5168 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5169 f_rslem_unregister(0, g_chan_nr);
5170}
5171testcase TC_rsl_modify_encr() runs on test_CT {
5172 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5173 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
5174 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
5175}
Harald Weltee613f962018-04-18 22:38:16 +02005176
5177/* Test unencrypted channel activation followed by explicit ENCR CMD later */
5178function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
5179 /* L3 payload doesn't matter, as it is passed transparently */
5180 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
5181 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
5182 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5183
5184 f_l1_tune(L1CTL);
5185
5186 /* first establish a dedicated channel in the clear */
5187 f_est_dchan(false);
5188
5189 /* Establish ABM */
5190 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5191
5192 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
5193 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
5194 /* expect the L3 to arrive still unencrypted on the MS side */
5195 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
5196
5197 /* configure L1 to apply ciphering */
5198 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
5199 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
5200
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005201 /* send first ciphered I-frame in response and expect it on RSL */
5202 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02005203
5204 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
5205 * and hence enable encryption also on the downlink */
5206
5207 /* expect bi-directional communication work in encrypted mode */
5208 f_unitdata_mo(link_id, f_rnd_octstring(15));
5209 f_unitdata_mt(link_id, f_rnd_octstring(15));
5210
5211 /* release the channel */
5212 f_rsl_chan_deact();
5213 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5214 f_rslem_unregister(0, g_chan_nr);
5215}
5216testcase TC_encr_cmd_a51() runs on test_CT {
5217 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5218 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
5219 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
5220}
5221testcase TC_encr_cmd_a52() runs on test_CT {
5222 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5223 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
5224 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
5225}
5226testcase TC_encr_cmd_a53() runs on test_CT {
5227 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5228 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
5229 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
5230}
5231
5232private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
5233 var LapdmFrame lf;
5234 var octetstring reenc;
5235
5236 /* decode the LAPDm frame */
5237 if (ischosen(exp_match.ab)) {
5238 lf.ab := dec_LapdmFrameAB(enc);
5239 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005240 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02005241 }
5242
5243 /* check if decoder result matches expectation */
5244 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005245 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02005246 } else {
5247 log(name, ": matched");
5248 setverdict(pass);
5249 }
5250
5251 /* test if re-encoded frame equals original input */
5252 reenc := enc_LapdmFrame(lf);
5253 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005254 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02005255 } else {
5256 setverdict(pass);
5257 }
5258}
5259
5260testcase TC_lapdm_selftest() runs on test_CT {
5261 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
5262 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
5263 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
5264 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
5265 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
5266 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
5267 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
5268}
5269
Stefan Sperling4880be42018-08-07 18:12:59 +02005270/***********************************************************************
5271 * DTX Related (see GSM 05.08, section 8.3)
5272 ***********************************************************************/
5273
5274/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
5275function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
5276 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
5277 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
5278 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
5279 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
5280}
5281function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
5282 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
5283 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
5284}
5285function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
5286 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
5287 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
5288 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
5289 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
5290}
5291function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
5292 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
5293 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
5294 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
5295 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
5296 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
5297 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
5298 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
5299 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
5300}
5301
5302function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
5303 var L1ctlDlMessage dl;
5304 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
5305 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
5306 var GsmFrameNumber first_fn;
5307 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005308 var integer nfill_frames_sacch := 0;
5309 var integer nfill_frames_nonsacch := 0;
5310 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02005311 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
5312 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005313 const integer frame_dtx_tchf_mod := 104;
5314 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
5315 * which operates in terms of blocks rather than frames. */
5316 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
5317 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02005318 timer T := 5.0;
5319
5320 f_l1_tune(L1CTL);
5321 RSL.clear;
5322 L1CTL.clear;
5323
5324 /* activate TCHF signalling channel */
5325 f_est_dchan(false);
5326
5327 T.start;
5328 alt {
5329 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5330 var GsmFrameNumber fn := dl.dl_info.frame_nr;
5331 var octetstring l2 := dl.payload.data_ind.payload;
5332
5333 if (is_first_frame) {
5334 is_first_frame := false;
5335 first_fn := dl.dl_info.frame_nr;
5336 }
5337
5338 if (dl.dl_info.link_id.c == SACCH) {
5339 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
5340 if (not match(l2_fill_frame_sacch, l2)) {
5341 repeat;
5342 }
5343 } else if (not match(l2_fill_frame, l2)) {
5344 repeat;
5345 }
5346
5347 if (dtxd) {
5348 if (not f_g_chan_is_tchf()) {
5349 T.stop;
5350 f_rsl_chan_deact();
5351 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005352 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received fill frame on non-TCH/F channel; DTX is only allowed on TCH/F!");
Stefan Sperling4880be42018-08-07 18:12:59 +02005353 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005354 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005355 T.stop;
5356 f_rsl_chan_deact();
5357 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005358
5359 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
5360 * 2 SACCH, 1 TCH/F */
5361 expected_fill_frames := 3;
5362
5363 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
5364 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
5365 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005366 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02005367 } else {
5368 setverdict(pass);
5369 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005370 } else {
5371 if (dl.dl_info.link_id.c == SACCH) {
5372 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02005373 repeat;
5374 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005375 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
5376 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
5377 * we should only see the subset of frames numbers which correspond to a block boundary.
5378 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
5379 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
5380 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
5381 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
5382 repeat;
5383 }
5384 }
5385 log("Received DTX TCH fill frame with bad frame number: ", fn,
5386 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
5387 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
5388 f_rsl_chan_deact();
5389 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005390 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02005391 }
Stefan Sperling4880be42018-08-07 18:12:59 +02005392 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005393 if (dl.dl_info.link_id.c == SACCH) {
5394 nfill_frames_sacch := nfill_frames_sacch + 1;
5395 } else {
5396 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
5397 }
5398 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005399 T.stop;
5400 if (f_g_chan_is_tchf()) {
5401 /* Without DTX we can expect 25 fill frames for every 104 frames.
5402 * (24 FACCH + 1 SACCH filling) */
5403 expected_fill_frames := 25;
5404 } else if (f_g_chan_is_tchh()) {
5405 /* We can expect 2 fill frames for every 104 frames. */
5406 expected_fill_frames := 2;
5407 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
5408 /* We can expect 5 fill frames for every 104 frames. */
5409 expected_fill_frames := 5;
5410 } else {
5411 f_rsl_chan_deact();
5412 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005413 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02005414 }
5415
5416 f_rsl_chan_deact();
5417 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005418
5419 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005420 setverdict(pass);
5421 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005422 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
5423 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02005425 }
5426 } else {
5427 repeat;
5428 }
5429 }
5430 }
5431 [] L1CTL.receive { repeat; }
5432 [] T.timeout {
5433 f_rsl_chan_deact();
5434 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005435 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02005436 }
5437 }
5438}
5439
5440function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
5441 f_test_l2_fill_frames(false);
5442}
5443
5444function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
5445 f_test_l2_fill_frames(true);
5446}
5447
5448function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
5449 var ConnHdlr vc_conn;
5450 var ConnHdlrPars pars;
5451 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02005452 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02005453 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
5454 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
5455 if (dtxd) {
5456 if (i >= 4) { /* DTX is only allowed on TCH/F */
5457 break;
5458 }
5459 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
5460 } else {
5461 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
5462 }
5463 vc_conn.done;
5464 }
5465}
5466
5467/* Verify that L2 fill frames are sent on TCH in signaling mode if
5468 * there is nothing to transmit while DTX is disabled on downlink. */
5469testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
5470 f_tch_sign_l2_fill_frame(false);
5471}
5472
5473/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
5474 * there is nothing to transmit while DTX is enabled on downlink. */
5475testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
5476 f_tch_sign_l2_fill_frame(true);
5477}
Harald Welte0472ab42018-03-12 15:02:26 +01005478
Stefan Sperling0ec1c262018-10-15 15:12:52 +02005479testcase TC_chopped_ipa_ping() runs on test_CT {
5480 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
5481}
5482
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02005483testcase TC_chopped_ipa_payload() runs on test_CT {
5484 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
5485}
5486
Harald Welte0472ab42018-03-12 15:02:26 +01005487/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
5488/* protocol error as per 44.006 */
5489/* link layer failure (repetition of I-frame N200 times without ACK */
5490/* repetition of SABM or DISC N200 times without ACK */
5491/* receptiom of SABM in multi-frame established state */
5492
5493
Harald Welte68e495b2018-02-25 00:05:57 +01005494/* TODO Areas:
5495
5496* channel activation
5497** with BS_Power / MS_Power, bypassing power control loop
5498** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01005499** with timing advance from initial activation on
5500* mode modify
5501** encryption
5502** multirate
5503* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01005504** unsupported algorithm
5505* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01005506* BS Power Control
5507* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01005508* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01005509* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01005510** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01005511* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01005512** DATA_IND from BTS->PCU
5513** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01005514
5515*/
Harald Welte70767382018-02-21 12:16:40 +01005516
5517control {
5518 execute( TC_chan_act_stress() );
5519 execute( TC_chan_act_react() );
5520 execute( TC_chan_deact_not_active() );
5521 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01005522 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01005523 execute( TC_sacch_filling() );
5524 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01005525 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01005526 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02005527 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02005528 execute( TC_sacch_chan_act_ho_async() );
5529 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01005530 execute( TC_rach_content() );
5531 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01005532 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07005533 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02005534 execute( TC_rach_load_idle_thresh0() );
5535 execute( TC_rach_load_idle_below_thresh() );
5536 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01005537 execute( TC_meas_res_sign_tchf() );
5538 execute( TC_meas_res_sign_tchh() );
5539 execute( TC_meas_res_sign_sdcch4() );
5540 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01005541 execute( TC_meas_res_sign_tchh_toa256() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01005542 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wilde57e1a62019-05-28 13:30:55 +02005543 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02005544 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02005545 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01005546 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01005547 execute( TC_paging_imsi_80percent() );
5548 execute( TC_paging_tmsi_80percent() );
5549 execute( TC_paging_imsi_200percent() );
5550 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01005551 execute( TC_rsl_protocol_error() );
5552 execute( TC_rsl_mand_ie_error() );
5553 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01005554 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01005555 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01005556 execute( TC_si_sched_2bis() );
5557 execute( TC_si_sched_2ter() );
5558 execute( TC_si_sched_2ter_2bis() );
5559 execute( TC_si_sched_2quater() );
5560 execute( TC_si_sched_13() );
5561 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01005562 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01005563 execute( TC_ipa_crcx_twice_not_active() );
5564 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01005565 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01005566 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01005567
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005568 if (mp_pcu_socket != "") {
5569 execute( TC_pcu_act_req() );
5570 execute( TC_pcu_act_req_wrong_ts() );
5571 execute( TC_pcu_act_req_wrong_bts() );
5572 execute( TC_pcu_act_req_wrong_trx() );
5573 execute( TC_pcu_deact_req() );
5574 execute( TC_pcu_deact_req_wrong_ts() );
5575 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02005576 if (mp_l1_supports_gprs) {
5577 execute( TC_pcu_data_req_pdtch() );
5578 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02005579 execute( TC_pcu_data_req_wrong_bts() );
5580 execute( TC_pcu_data_req_wrong_trx() );
5581 execute( TC_pcu_data_req_wrong_ts() );
5582 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02005583 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005584 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02005585 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005586 execute( TC_pcu_data_req_imm_ass_pch() );
5587 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005588 execute( TC_pcu_ext_rach_content() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005589 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02005590 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02005591 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02005592 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02005593 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02005594 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02005595 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02005596 execute( TC_pcu_socket_noconnect_nosi3gprs() );
5597 execute( TC_pcu_socket_connect_si3gprs() );
5598 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005599 } else {
5600 log("PCU socket path not available, skipping PCU tests");
5601 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005602
5603 execute( TC_dyn_osmo_pdch_act_deact() );
5604 execute( TC_dyn_osmo_pdch_unsol_deact() );
5605 execute( TC_dyn_osmo_pdch_double_act() );
5606 execute( TC_dyn_osmo_pdch_tchf_act() );
5607 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02005608 execute( TC_dyn_ipa_pdch_act_deact() );
5609 execute( TC_dyn_ipa_pdch_tchf_act() );
5610 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
5611 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01005612
5613 execute( TC_rll_est_ind() );
5614 execute( TC_rll_est_req_DCCH_3() );
5615 execute( TC_rll_est_req_ACCH_3() );
5616 execute( TC_rll_rel_ind_DCCH_0() );
5617 execute( TC_rll_rel_ind_DCCH_3() );
5618 execute( TC_rll_rel_ind_ACCH_0() );
5619 execute( TC_rll_rel_ind_ACCH_3() );
5620 execute( TC_rll_rel_req() );
5621 execute( TC_rll_unit_data_req_DCCH() );
5622 execute( TC_rll_unit_data_req_ACCH() );
5623 execute( TC_rll_unit_data_ind_DCCH() );
5624 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02005625
5626 execute( TC_chan_act_a51() );
5627 execute( TC_chan_act_a52() );
5628 execute( TC_chan_act_a53() );
5629 execute( TC_encr_cmd_a51() );
5630 execute( TC_encr_cmd_a52() );
5631 execute( TC_encr_cmd_a53() );
5632
Harald Welteee25aae2019-05-19 14:32:37 +02005633 execute( TC_err_rep_wrong_mdisc() );
5634 execute( TC_err_rep_wrong_msg_type() );
5635 execute( TC_err_rep_wrong_sequence() );
5636
Harald Weltee613f962018-04-18 22:38:16 +02005637 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02005638
5639 execute( TC_tch_sign_l2_fill_frame() );
5640 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02005641
5642 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02005643 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01005644}
5645
5646
5647}