blob: 5cde0afa620653de46946e1cbc20542c77acab71 [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
4 * (C) 2019-2019 by Harald Welte <laforge@gnumonks.org>
5 * 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 *
11 * This test suite tests OsmoBTS by attaching to the external interfaces
12 * such as Abis RSL, PCU, VTY as well as by attaching to a MS L1 implementation
13 * using the L1CTL protocol/interface.
14 *
15 * You can run the tests with
16 * a) osmo-bts-trx + trxcon + fake_trx (without any hardware)
17 * b) any osmo-bts-* + OsmocomBB layer1 + osmocon (with real BTS hardware)
18 * c) osmo-bts-virtual + virt_phy (without any hardware)
19 *
20 * Some of the tests will only run on a subset of those three configurations
21 * due to limitations in the respective L1.
22 */
23
Daniel Willmann0fcc4d32018-10-23 20:32:19 +020024import from Misc_Helpers all;
Harald Welte70767382018-02-21 12:16:40 +010025import from General_Types all;
26import from GSM_Types all;
27import from GSM_RR_Types all;
28import from Osmocom_Types all;
29import from GSM_Types all;
Harald Welte82ccef72018-02-25 16:17:33 +010030import from GSM_SystemInformation all;
Harald Welte70767382018-02-21 12:16:40 +010031import from L1CTL_PortType all;
32import from L1CTL_Types all;
33import from LAPDm_Types all;
Harald Weltead033dc2019-05-25 17:28:16 +020034import from LAPDm_RAW_PT all;
Harald Welte70767382018-02-21 12:16:40 +010035import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020036import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010037
38import from RSL_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010039import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010040import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020041import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010042import from RSL_Emulation all;
43
44import from IPL4asp_Types all;
45import from TRXC_Types all;
46import from TRXC_CodecPort all;
47import from TRXC_CodecPort_CtrlFunct all;
48
Harald Welte883340c2018-02-28 18:59:29 +010049import from PCUIF_Types all;
50import from PCUIF_CodecPort all;
51
Harald Welte7484fc42018-02-24 14:09:45 +010052import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010053import from MobileL3_RRM_Types all;
54import from MobileL3_Types all;
55import from L3_Templates all;
Harald Welteeaa9a862019-05-26 23:01:08 +020056import from L3_Common all;
57import from MobileL3_GMM_SM_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010058
Harald Welte8da48242018-02-27 20:41:32 +010059import from Osmocom_VTY_Functions all;
60import from TELNETasp_PortType all;
61
Harald Welte505cf9b2018-09-15 17:47:23 +030062friend module BTS_Tests_SMSCB;
Harald Weltead033dc2019-05-25 17:28:16 +020063friend module BTS_Tests_virtphy;
Harald Welte505cf9b2018-09-15 17:47:23 +030064
Harald Welte70767382018-02-21 12:16:40 +010065/* The tests assume a BTS with the following timeslot configuration:
66 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020067 * TS1 : TCH/F
68 * TS2 : TCH/F
69 * TS3 : TCH/F_PDCH (IPA Style)
70 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010071 * TS5 : TCH/H
72 * TS6 : SDCCH/8
73 * TS7 : PDCH
74 */
75
76modulepar {
77 charstring mp_rsl_ip := "127.0.0.2";
78 integer mp_rsl_port := 3003;
79 integer mp_trx0_arfcn := 871;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070080 charstring mp_bts_trxc_ip := "127.0.0.1";
81 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010082 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020083 charstring mp_ctrl_ip := "127.0.0.1";
84 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020085 charstring mp_bsc_ctrl_ip := "127.0.0.1";
86 integer mp_bsc_ctrl_port := 4249;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020087 integer mp_tolerance_rxqual := 1;
88 integer mp_tolerance_rxlev := 3;
89 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +020090 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +020091 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +020092 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020093 integer mp_ms_actual_ta_exp := 0;
94 integer mp_timing_offset_256syms_exp := 512;
Pau Espin Pedrol315e4712018-11-01 16:27:07 +010095 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +020096 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +020097 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +020098 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
99 boolean mp_l1_supports_gprs := false;
Harald Welte70767382018-02-21 12:16:40 +0100100}
101
Harald Welte629cc6b2018-03-11 17:19:05 +0100102type record of RslChannelNr ChannelNrs;
103
Harald Welte70767382018-02-21 12:16:40 +0100104type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100105 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100106 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100107 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100108 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100109 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100110 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100111
112 /* L1CTL port (for classic tests) */
113 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100114
Harald Welte54a2a2d2018-02-26 09:14:05 +0100115 /* TRXC port (for classic tests) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700116 port TRXC_CODEC_PT BTS_TRXC;
117 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100118
Harald Weltef50e3ae2018-09-10 10:27:56 +0200119 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100120 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200121 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100122
Harald Welte883340c2018-02-28 18:59:29 +0100123 /* PCU Interface of BTS */
124 port PCUIF_CODEC_PT PCU;
125 var integer g_pcu_conn_id;
126 /* Last PCU INFO IND we received */
127 var PCUIF_Message g_pcu_last_info;
128
Harald Welte48494ca2018-02-25 16:59:50 +0100129 /* SI configuration */
130 var SystemInformationConfig si_cfg := {
131 bcch_extended := false,
132 si1_present := false,
133 si2bis_present := false,
134 si2ter_present := false,
135 si2quater_present := false,
136 si7_present := false,
137 si8_present := false,
138 si9_present := false,
139 si13_present := false,
140 si13alt_present := false,
141 si15_present := false,
142 si16_present := false,
143 si17_present := false,
144 si2n_present := false,
145 si21_present := false,
146 si22_present := false
147 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100148
149 /* all logical channels available on the BTS */
150 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100151 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100152}
153
154/* an individual call / channel */
155type component ConnHdlr extends RSL_DchanHdlr {
156 port L1CTL_PT L1CTL;
157
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700158 port TRXC_CODEC_PT BTS_TRXC;
159 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100160
161 timer g_Tguard;
162 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
163
164 var ConnHdlrPars g_pars;
165 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100166 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200167
168 /* PCU Interface of BTS */
169 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100170}
171
172function f_init_rsl(charstring id) runs on test_CT {
173 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
174 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
175
176 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
177 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
178 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
179
180 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
181 vc_RSL.start(RSL_Emulation.main(false));
182}
183
184type record ConnHdlrPars {
185 RslChannelNr chan_nr,
186 RSL_IE_ChannelMode chan_mode,
187 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100188 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200189 TestSpecUnion spec optional,
190 RSL_IE_EncryptionInfo encr optional
Harald Welte0472ab42018-03-12 15:02:26 +0100191}
192
193/* Test-specific parameters */
194type union TestSpecUnion {
195 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100196}
197
Harald Welte82ccef72018-02-25 16:17:33 +0100198template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100199 max_retrans := RACH_MAX_RETRANS_7,
200 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100201 cell_barr_access := false,
202 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100203 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100204};
205
Harald Weltef10153f2018-02-25 16:34:05 +0100206template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100207 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200208 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100209 acs := '0'B,
210 neci := true,
211 rxlev_access_min := 0
212}
213
214template (value) LocationAreaIdentification ts_LAI_default := {
215 mcc_mnc := '262F42'H,
216 lac := 42
217}
218
Harald Welte7484fc42018-02-24 14:09:45 +0100219/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100220template (value) SystemInformation ts_SI3_default := {
221 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100222 payload := {
223 si3 := {
224 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100225 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100226 ctrl_chan_desc := {
227 msc_r99 := true,
228 att := true,
229 bs_ag_blks_res := 1,
230 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100231 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100232 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
233 spare := '00'B,
234 bs_pa_mfrms := 0, /* 2 multiframes */
235 t3212 := 1 /* 6 minutes */
236 },
Harald Welte82ccef72018-02-25 16:17:33 +0100237 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100238 dn_ind := false,
239 pwrc := false,
240 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100241 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100242 },
Harald Weltef10153f2018-02-25 16:34:05 +0100243 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100244 rach_control := ts_RachCtrl_default,
Harald Welte3778acc2018-03-09 19:32:31 +0100245 rest_octets := '2B2B2B2B'O
Harald Welte7484fc42018-02-24 14:09:45 +0100246 }
247 }
248}
Harald Welte70767382018-02-21 12:16:40 +0100249
Harald Weltef8df4cb2018-03-10 15:15:08 +0100250template (value) SystemInformation ts_SI2_default := {
251 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100252 payload := {
253 si2 := {
254 bcch_freq_list := '00000000000000000000000000000000'O,
255 ncc_permitted := '11111111'B,
256 rach_control := ts_RachCtrl_default
257 }
258 }
259}
260
Harald Weltef8df4cb2018-03-10 15:15:08 +0100261template (value) SystemInformation ts_SI4_default := {
262 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100263 payload := {
264 si4 := {
265 lai := ts_LAI_default,
266 cell_sel_par := ts_CellSelPar_default,
267 rach_control := ts_RachCtrl_default,
268 cbch_chan_desc := omit,
269 cbch_mobile_alloc := omit,
270 rest_octets := ''O
271 }
272 }
273}
274
275function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
276runs on test_CT {
277 log("Setting ", rsl_si_type, ": ", si_enc);
278 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
279}
280
281function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
282runs on test_CT {
283 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
284 log("Setting ", rsl_si_type, ": ", si_dec);
285 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
286}
287
Harald Welte505cf9b2018-09-15 17:47:23 +0300288friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100289 map(self:BTSVTY, system:BTSVTY);
290 f_vty_set_prompts(BTSVTY);
291 f_vty_transceive(BTSVTY, "enable");
292}
293
Harald Welte505cf9b2018-09-15 17:47:23 +0300294friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200295 map(self:BSCVTY, system:BSCVTY);
296 f_vty_set_prompts(BSCVTY, "OsmoBSC");
297 f_vty_transceive(BSCVTY, "enable");
298}
299
Harald Welte883340c2018-02-28 18:59:29 +0100300/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200301private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
302 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100303 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200304 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
305 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100306 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200307 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200308 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100309 }
310}
311
Harald Weltef26de0b2018-04-04 20:28:05 +0200312private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
313 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100314 timer T := 2.0;
315 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100316 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200317 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100318 return;
319 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200320 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100321
322 T.start;
323 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200324 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100325 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200326 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100327 }
328 }
329}
330
Harald Welte70767382018-02-21 12:16:40 +0100331/* global init function */
Harald Welte68e495b2018-02-25 00:05:57 +0100332function f_init(charstring id := "BTS-Test") runs on test_CT {
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100333 timer T := mp_ipa_up_timeout;
Harald Welte629cc6b2018-03-11 17:19:05 +0100334 g_AllChannels := {
335 /* TS 1..4: TCH/F */
336 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
337 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
338 /* TS 5: TCH/H */
339 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
340 /* TS 0: SDCCH/4 */
341 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
342 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
343 /* TS 6: SDCCH/8 */
344 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
345 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
346 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
347 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
348 };
349
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200350 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700351 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200352 g_AllChanTypes := {
353 /* TS 1..4: TCH/F */
354 valueof(ts_RslChanNr_Bm(1)),
355 /* TS 5: TCH/H */
356 valueof(ts_RslChanNr_Lm(5,1)),
357 /* TS 0: SDCCH/4 */
358 valueof(ts_RslChanNr_SDCCH4(0,2)),
359 /* TS 6: SDCCH/8 */
360 valueof(ts_RslChanNr_SDCCH8(6,4))
361 };
362 } else {
363 g_AllChanTypes := {
364 /* TS 1..4: TCH/F */
365 valueof(ts_RslChanNr_Bm(1)),
366 /* TS 0: SDCCH/4 */
367 valueof(ts_RslChanNr_SDCCH4(0,2)),
368 /* TS 6: SDCCH/8 */
369 valueof(ts_RslChanNr_SDCCH8(6,4))
370 };
371 }
Harald Welte70767382018-02-21 12:16:40 +0100372 f_init_rsl(id);
Harald Welte83f6dbf2018-06-03 18:26:50 +0200373 T.start;
374 alt {
375 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
376 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200377 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
Harald Welte83f6dbf2018-06-03 18:26:50 +0200378 }
379 }
Harald Welte2d142592018-02-25 13:19:44 +0100380 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100381 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200382 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100383
384 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100385 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
386 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
387 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
388 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100389
Harald Weltef26de0b2018-04-04 20:28:05 +0200390 map(self:PCU, system:PCU);
391 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100392
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700393 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100394 var TrxcMessage ret;
395 /* start with a default moderate timing offset equalling TA=2 */
396 f_main_trxc_connect();
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700397 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 +0100398 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200399
400 /* Wait some extra time to make sure the BTS emits a stable carrier.
401 * (this is only relevant when running the tests with a physical BTS.) */
402 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100403}
404
Harald Welte68e495b2018-02-25 00:05:57 +0100405/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
406function f_init_l1ctl() runs on test_CT {
407 map(self:L1CTL, system:L1CTL);
408 f_connect_reset(L1CTL);
409}
410
Harald Welte70767382018-02-21 12:16:40 +0100411type function void_fn(charstring id) runs on ConnHdlr;
412
413/* create a new test component */
Harald Weltef26de0b2018-04-04 20:28:05 +0200414function f_start_handler(void_fn fn, ConnHdlrPars pars, boolean pcu_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100415runs on test_CT return ConnHdlr {
416 var charstring id := testcasename();
417 var ConnHdlr vc_conn;
418
419 vc_conn := ConnHdlr.create(id);
420 /* connect to RSL Emulation main component */
421 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
422 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Harald Weltef26de0b2018-04-04 20:28:05 +0200423 if (pcu_comp) {
424 /* the ConnHdlr component wants to talk directly to the PCU, so disconnect
425 * it from the test_CT and connect it to the component. This obviously only
426 * works for one component, i.e. no concurrency */
427 unmap(self:PCU, system:PCU);
428 map(vc_conn:PCU, system:PCU);
429 }
Harald Welte70767382018-02-21 12:16:40 +0100430
431 vc_conn.start(f_handler_init(fn, id, pars));
432 return vc_conn;
433}
434
Harald Welte7484fc42018-02-24 14:09:45 +0100435template ASP_RSL_Unitdata ts_RSL_UD(template RSL_Message rsl, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
436 streamId := sid,
437 rsl := rsl
438}
439
440template ASP_RSL_Unitdata tr_RSL_UD(template RSL_Message rsl,
441 template IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
442 streamId := sid,
443 rsl := rsl
444}
445
Harald Welte70767382018-02-21 12:16:40 +0100446private altstep as_Tguard() runs on ConnHdlr {
447 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200448 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100449 }
450}
451
Harald Welte505cf9b2018-09-15 17:47:23 +0300452friend function f_l1_tune(L1CTL_PT L1CTL) {
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200453 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, CCCH_MODE_COMBINED, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100454}
455
456private function f_trxc_connect() runs on ConnHdlr {
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700457 map(self:BTS_TRXC, system:BTS_TRXC);
Harald Welte70767382018-02-21 12:16:40 +0100458 var Result res;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700459 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BTS_TRXC, mp_bts_trxc_ip, mp_bts_trxc_port,
Harald Weltea4d8f352018-03-01 15:47:20 +0100460 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +0200461 if (not ispresent(res.connId)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200462 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 +0200463 }
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700464 g_bts_trxc_conn_id := res.connId;
Harald Welte70767382018-02-21 12:16:40 +0100465}
466
467private function f_trxc_fake_rssi(uint8_t rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100468 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700469 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100470}
471
472private function f_trx_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100473 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700474 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100475}
476
477/* first function started in ConnHdlr component */
478private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
479runs on ConnHdlr {
480 g_pars := pars;
481 g_chan_nr := pars.chan_nr;
482
483 map(self:L1CTL, system:L1CTL);
484 f_connect_reset(L1CTL);
485
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700486 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100487 f_trxc_connect();
488 }
Harald Welte70767382018-02-21 12:16:40 +0100489
490 g_Tguard.start(pars.t_guard);
491 activate(as_Tguard());
492
493 f_rslem_register(0, pars.chan_nr);
494
495 /* call the user-supplied test case function */
496 fn.apply(id);
497}
498
Harald Welteb1726c92018-03-30 11:56:38 +0200499function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
500 boolean ignore_other := false)
501runs on ConnHdlr return RSL_Message {
502 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100503 timer T := 3.0;
504 RSL.send(tx);
505 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100506 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200507 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100508 T.stop;
509 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100510 }
Harald Welte1eba3742018-02-25 12:48:14 +0100511 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200512 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100513 }
Harald Welte21240e62018-03-11 21:43:35 +0100514 [not ignore_other] as_l1_sacch();
515 [not ignore_other] as_meas_res();
516 [not ignore_other] as_l1_dcch();
517 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200518 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100519 }
Harald Welte21240e62018-03-11 21:43:35 +0100520 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100521 }
Harald Welteb1726c92018-03-30 11:56:38 +0200522 return rx;
523}
524
525function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
526 boolean ignore_other := false)
527runs on ConnHdlr {
528 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100529}
530
Harald Welte8b01c792019-05-19 22:51:25 +0200531function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false, RSL_IE_List more_ies := {},
532 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA) runs on ConnHdlr {
533 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200534 if (encr_enable) {
535 /* append encryption related IEs, if requested */
536 var RSL_IE_EncryptionInfo encr_info;
537 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
538 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
539encr_info})) };
540 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200541 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200542 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100543}
544
Harald Welte70767382018-02-21 12:16:40 +0100545function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100546 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 +0100547 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100548}
549
Harald Welte70767382018-02-21 12:16:40 +0100550private template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
551 template RSL_IE_ChannelMode chan_mode,
552 float t_guard := 20.0) := {
553 chan_nr := valueof(chan_nr),
554 chan_mode := valueof(chan_mode),
555 t_guard := t_guard,
556 l1_pars := {
557 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100558 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100559 meas_ul := {
560 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200561 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100562 rxqual := 0
563 },
564 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200565 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100566 rxqual := 0
567 }
568 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200569 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100570 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200571 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200572 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100573 },
Harald Weltee613f962018-04-18 22:38:16 +0200574 spec := omit,
575 encr := omit
Harald Welte70767382018-02-21 12:16:40 +0100576}
577
Harald Welte93640c62018-02-25 16:59:33 +0100578/***********************************************************************
579 * Channel Activation / Deactivation
580 ***********************************************************************/
581
Harald Welte70767382018-02-21 12:16:40 +0100582/* Stress test: Do 500 channel activations/deactivations in rapid succession */
583function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
584 for (var integer i := 0; i < 500; i := i+1) {
585 f_rsl_chan_act(g_pars.chan_mode);
586 f_rsl_chan_deact();
587 }
588 setverdict(pass);
589}
590testcase TC_chan_act_stress() runs on test_CT {
591 var ConnHdlr vc_conn;
592 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
593 f_init(testcasename());
594 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
595 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200596 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100597}
598
599/* Test if re-activation of an already active channel fails as expected */
600function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
601 f_rsl_chan_act(g_pars.chan_mode);
602 /* attempt to activate the same lchan again -> expect reject */
603 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
604 alt {
605 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200606 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100607 }
608 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
609 setverdict(pass);
610 }
611 }
612 f_rsl_chan_deact();
613}
614testcase TC_chan_act_react() runs on test_CT {
615 var ConnHdlr vc_conn;
616 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100617 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100618 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
619 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200620 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100621}
622
623/* Attempt to de-activate a channel that's not active */
624function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
625 timer T := 3.0;
626 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
627 T.start;
628 alt {
629 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
630 setverdict(pass);
631 }
632 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200633 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100634 }
635 }
636}
637testcase TC_chan_deact_not_active() runs on test_CT {
638 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100639 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100640 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
641 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200642 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100643}
644
645/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
646function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
647 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
648 alt {
649 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200650 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100651 }
652 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
653 setverdict(pass);
654 }
655 }
656}
657private type record WrongChanNrCase {
658 RslChannelNr chan_nr,
659 charstring description
660}
661private type record of WrongChanNrCase WrongChanNrCases;
662private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
663 chan_nr := chan_nr,
664 description := desc
665}
666
667testcase TC_chan_act_wrong_nr() runs on test_CT {
668 var ConnHdlr vc_conn;
669 var ConnHdlrPars pars;
670
Harald Welte294b0a22018-03-10 23:26:48 +0100671 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100672
673 var WrongChanNrCases wrong := {
674 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
675 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
676 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
677 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
678 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
679 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
680 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
681 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
682 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
683 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
684 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
685 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
686 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
687 };
688
689 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
690 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
691 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
692 vc_conn.done;
693 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200694 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100695}
696
Harald Weltee613f962018-04-18 22:38:16 +0200697/* execute the same callback function on a variety of logical channels */
698private function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
699 var ConnHdlr vc_conn;
700 f_init(testcasename());
701
702 /* test on each of the channels we have */
703 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
704 pars.chan_nr := valueof(g_AllChanTypes[i]);
705
706 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
707 vc_conn := f_start_handler(fn, pars);
708 vc_conn.done;
709 }
710
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200711 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200712}
713
Harald Welte93640c62018-02-25 16:59:33 +0100714/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100715 * SACCH handling
716 ***********************************************************************/
717
718private function f_exp_sacch(boolean exp) runs on ConnHdlr {
719 timer T_sacch := 3.0;
720 T_sacch.start;
721 alt {
722 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200723 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100724 }
725 [not exp] T_sacch.timeout {
726 setverdict(pass);
727 }
728 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
729 setverdict(pass);
730 }
731 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200732 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100733 }
734 [] L1CTL.receive { repeat; }
735 [] RSL.receive { repeat; }
736 }
737}
738
739/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
740private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
741 f_l1_tune(L1CTL);
742 RSL.clear;
743
744 /* activate the logical channel */
745 f_est_dchan();
746 L1CTL.clear;
747
748 /* check that SACCH actually are received as expected */
749 f_exp_sacch(true);
750
751 /* deactivate SACCH on the logical channel */
752 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
753 f_sleep(1.0);
754 L1CTL.clear;
755
756 /* check that no SACCH are received anymore */
757 f_exp_sacch(false);
758
759 /* release the channel */
760 f_rsl_chan_deact();
761 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
762}
763testcase TC_deact_sacch() runs on test_CT {
764 var ConnHdlr vc_conn;
765 var ConnHdlrPars pars;
766 f_init();
767 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
768 //for (var integer i := 0; i < 1; i := i+1) {
769 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
770 log(testcasename(), ": Starting for ", g_AllChannels[i]);
771 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
772 vc_conn.done;
773 }
774 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200775 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100776}
777
Harald Welte55700662018-03-12 13:15:43 +0100778/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100779private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
780 var L1ctlDlMessage dl;
781 /* check that the specified SI5 value is actually sent */
782 timer T_sacch := 3.0;
783 L1CTL.clear;
784 T_sacch.start;
785 alt {
786 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
787 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
788 if (match(l3, l3_exp)) {
789 setverdict(pass);
790 } else {
791 repeat;
792 }
793 }
794 [] L1CTL.receive { repeat; }
795 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200796 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100797 }
798 }
799}
800
Harald Welte55700662018-03-12 13:15:43 +0100801/* verify that given SACCH payload is not present */
802private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
803 var L1ctlDlMessage dl;
804 /* check that the specified SI5 value is actually sent */
805 timer T_sacch := 3.0;
806 L1CTL.clear;
807 T_sacch.start;
808 alt {
809 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
810 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
811 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200812 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100813 } else {
814 repeat;
815 }
816 }
817 [] L1CTL.receive { repeat; }
818 [] T_sacch.timeout {
819 setverdict(pass);
820 }
821 }
822}
823
Harald Welte629cc6b2018-03-11 17:19:05 +0100824/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100825private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
826 /* Set a known default SACCH filling for SI5 */
827 var octetstring si5 := f_rnd_octstring(19);
828 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
829
830 f_l1_tune(L1CTL);
831 RSL.clear;
832
833 /* activate the logical channel */
834 f_est_dchan();
835
836 /* check that the specified SI5 value is actually sent */
837 f_sacch_present(si5);
838
839 /* release the channel */
840 RSL.clear;
841 f_rsl_chan_deact();
842 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
843}
844testcase TC_sacch_filling() runs on test_CT {
845 var ConnHdlr vc_conn;
846 var ConnHdlrPars pars;
847 f_init();
848 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
849 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
850 log(testcasename(), ": Starting for ", g_AllChannels[i]);
851 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
852 vc_conn.done;
853 }
854 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200855 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100856}
857
Harald Welte629cc6b2018-03-11 17:19:05 +0100858/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100859private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
860 /* Set a known default SACCH filling for SI5 */
861 var octetstring si5 := f_rnd_octstring(19);
862 var octetstring si5_diff := f_rnd_octstring(19);
863 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
864
865 f_l1_tune(L1CTL);
866 RSL.clear;
867
868 log("Activating channel, expecting standard SI5");
869 /* activate the logical channel */
870 f_est_dchan();
871 /* check that the specified SI5 value is actually sent */
872 f_sacch_present(si5);
873
874 /* set channel-specific different SI5 */
875 log("Setting channel specific SACCH INFO, expecting it");
876 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
877 /* check that the specified lchan-specific value is now used */
878 f_sacch_present(si5_diff);
879
880 /* deactivate the channel and re-activate it, this should result in default SI5 */
881 log("De-activating and re-activating channel, expecting standard SI5");
882 f_rsl_chan_deact();
883 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
884 /* Verify that the TRX-wide default SACCH filling is present again */
885 f_sacch_present(si5);
886
887 /* release the channel */
888 RSL.clear;
889 f_rsl_chan_deact();
890 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
891}
892testcase TC_sacch_info_mod() runs on test_CT {
893 var ConnHdlr vc_conn;
894 var ConnHdlrPars pars;
895 f_init();
896 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
897 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
898 log(testcasename(), ": Starting for ", g_AllChannels[i]);
899 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
900 vc_conn.done;
901 }
902 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200903 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100904}
905
Harald Welte075d84c2018-03-12 13:07:24 +0100906/* Test SACCH scheduling of multiple different SI message types */
907private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
908 var octetstring si5 := f_rnd_octstring(19);
909 var octetstring si5bis := f_rnd_octstring(19);
910 var octetstring si5ter := f_rnd_octstring(19);
911 var octetstring si6 := f_rnd_octstring(19);
912
913 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
914 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
915 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
916 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
917
918 f_l1_tune(L1CTL);
919 RSL.clear;
920
921 /* activate the logical channel */
922 f_est_dchan();
923 L1CTL.clear;
924
925 /* check that SACCH actually are received as expected */
926 f_sacch_present(si5);
927 f_sacch_present(si5bis);
928 f_sacch_present(si5ter);
929 f_sacch_present(si6);
930
931 /* release the channel */
932 f_rsl_chan_deact();
933 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
934}
935testcase TC_sacch_multi() runs on test_CT {
936 var ConnHdlr vc_conn;
937 var ConnHdlrPars pars;
938 f_init();
939 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
940 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
941 log(testcasename(), ": Starting for ", g_AllChannels[i]);
942 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
943 vc_conn.done;
944 }
945 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200946 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +0100947}
948
Harald Welte55700662018-03-12 13:15:43 +0100949/* Test if SACH information is modified as expected */
950private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
951 var octetstring si5 := f_rnd_octstring(19);
952 var octetstring si6 := f_rnd_octstring(19);
953
954 /* First, configure both SI5 and SI6 to be transmitted */
955 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
956 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
957
958 f_l1_tune(L1CTL);
959 RSL.clear;
960
961 /* activate the logical channel */
962 f_est_dchan();
963 L1CTL.clear;
964
965 /* check that SACCH actually are received as expected */
966 f_sacch_present(si5);
967 f_sacch_present(si6);
968
969 /* disable SI6 */
970 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
971
972 /* check that SI5 is still transmitted */
973 f_sacch_present(si5);
974 /* check if SI6 is now gone */
975 f_sacch_missing(si6);
976
977 /* release the channel */
978 f_rsl_chan_deact();
979 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
980}
981testcase TC_sacch_multi_chg() runs on test_CT {
982 var ConnHdlr vc_conn;
983 var ConnHdlrPars pars;
984 f_init();
985 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
986 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
987 log(testcasename(), ": Starting for ", g_AllChannels[i]);
988 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
989 vc_conn.done;
990 }
991 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200992 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +0100993}
994
Harald Weltec8d363c2019-05-19 20:36:48 +0200995/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
996private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
997 var octetstring si5 := f_rnd_octstring(19);
998 var octetstring si6 := f_rnd_octstring(19);
999 var octetstring si5_specific := f_rnd_octstring(19);
1000 var octetstring si6_specific := f_rnd_octstring(19);
1001
1002 /* First, configure both SI5 and SI6 to be transmitted */
1003 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1004 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1005
1006 f_l1_tune(L1CTL);
1007 RSL.clear;
1008
1009 /* activate channel with different SACCH filling */
1010 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1011 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1012 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1013 }));
1014 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1015 RSL_IE_Body:{sacch_info := sacch_info})) };
1016 f_est_dchan(more_ies := addl_ies);
1017
1018 /* check that SACCH actually are received as expected */
1019 f_sacch_present(si5_specific);
1020 f_sacch_present(si6_specific);
1021
1022 /* release the channel */
1023 f_rsl_chan_deact();
1024 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1025}
1026testcase TC_sacch_chan_act() runs on test_CT {
1027 var ConnHdlr vc_conn;
1028 var ConnHdlrPars pars;
1029 f_init();
1030
1031 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1032 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1033 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1034 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1035 vc_conn.done;
1036 }
1037 /* TODO: do the above in parallel, rather than sequentially? */
1038 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1039}
1040
Harald Welte8b01c792019-05-19 22:51:25 +02001041/* verify that SACCH DL transmission is started only if MS power IE present
1042 * see section 4.1.3 of 3GPP TS 48.058 */
1043private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1044 var octetstring si5 := f_rnd_octstring(19);
1045
1046 f_l1_tune(L1CTL);
1047 RSL.clear;
1048
1049 /* Step 1: Activate ASYNC HO channel without MS power IE */
1050
1051 /* Activate channel on BTS side */
1052 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1053 /* don't perform immediate assignment here, as we're testing non-IA case */
1054 /* enable dedicated mode */
1055 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1056
1057 /* Verify that no DL SACCH is being received */
1058 f_sacch_missing(?);
1059
1060 f_rsl_chan_deact();
1061 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1062
1063
1064 /* Step 2: Activate ASYNC HO channel with MS power IE */
1065
1066 /* Activate channel on BTS side */
1067 var RSL_IE_List addl_ies := {
1068 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1069 };
1070 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1071 /* don't perform immediate assignment here, as we're testing non-IA case */
1072 /* enable dedicated mode */
1073 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1074
1075 /* Verify that DL SACCH is being received */
1076 f_sacch_present(si5);
1077
1078 f_rsl_chan_deact();
1079 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1080}
1081testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1082 var ConnHdlr vc_conn;
1083 var ConnHdlrPars pars;
1084 f_init();
1085
1086 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1087 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1088 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1089 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1090 vc_conn.done;
1091 }
1092 /* TODO: do the above in parallel, rather than sequentially? */
1093 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1094}
1095
1096/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1097 * see section 4.1.4 of 3GPP TS 48.058 */
1098private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1099 var octetstring si5 := f_rnd_octstring(19);
1100 var RSL_IE_List addl_ies;
1101
1102 f_l1_tune(L1CTL);
1103 RSL.clear;
1104
1105 /* Step 1: Activate SYNC HO channel without MS power IE */
1106
1107 /* Activate channel on BTS side */
1108 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1109 /* don't perform immediate assignment here, as we're testing non-IA case */
1110 /* enable dedicated mode */
1111 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1112
1113 /* Verify that no DL SACCH is being received */
1114 f_sacch_missing(?);
1115
1116 f_rsl_chan_deact();
1117 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1118
1119
1120 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1121
1122 /* Activate channel on BTS side */
1123 addl_ies := {
1124 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1125 };
1126 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1127 /* don't perform immediate assignment here, as we're testing non-IA case */
1128 /* enable dedicated mode */
1129 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1130
1131 /* Verify that no DL SACCH is being received */
1132 f_sacch_missing(?);
1133
1134 f_rsl_chan_deact();
1135 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1136
1137
1138 /* Step 2b: Activate SYNC HO channel with TA IE */
1139
1140 /* Activate channel on BTS side */
1141 addl_ies := {
1142 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1143 };
1144 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1145 /* don't perform immediate assignment here, as we're testing non-IA case */
1146 /* enable dedicated mode */
1147 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1148
1149 /* Verify that no DL SACCH is being received */
1150 f_sacch_missing(?);
1151
1152 f_rsl_chan_deact();
1153 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1154
1155
1156 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1157
1158 /* Activate channel on BTS side */
1159 addl_ies := {
1160 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1161 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1162 };
1163 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1164 /* don't perform immediate assignment here, as we're testing non-IA case */
1165 /* enable dedicated mode */
1166 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1167
1168 /* Verify that DL SACCH is being received */
1169 f_sacch_present(si5);
1170
1171 f_rsl_chan_deact();
1172 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1173}
1174testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1175 var ConnHdlr vc_conn;
1176 var ConnHdlrPars pars;
1177 f_init();
1178
1179 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1180 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1181 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1182 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1183 vc_conn.done;
1184 }
1185 /* TODO: do the above in parallel, rather than sequentially? */
1186 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1187}
Harald Welte629cc6b2018-03-11 17:19:05 +01001188
1189
1190/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001191 * RACH Handling
1192 ***********************************************************************/
1193
Harald Welte8c24c2b2018-02-26 08:31:31 +01001194/* like L1SAP_IS_PACKET_RACH */
1195private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +01001196 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001197 return true;
1198 }
1199 return false;
1200}
1201
1202/* generate a random RACH for circuit-switched */
1203private function f_rnd_ra_cs() return OCT1 {
1204 var OCT1 ra;
1205 do {
1206 ra := f_rnd_octstring(1);
1207 } while (ra_is_ps(ra));
1208 return ra;
1209}
1210
Harald Welte883340c2018-02-28 18:59:29 +01001211/* generate a random RACH for packet-switched */
1212private function f_rnd_ra_ps() return OCT1 {
1213 var OCT1 ra;
1214 do {
1215 ra := f_rnd_octstring(1);
1216 } while (not ra_is_ps(ra));
1217 return ra;
1218}
1219
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07001220/* generate a random 11-bit RA (packet-switched only) */
1221private function f_rnd_ra11_ps() return BIT11 {
1222 var integer ra11 := f_rnd_int(bit2int('11111111111'B));
1223 return int2bit(ra11, 11);
1224}
1225
Harald Welte8c24c2b2018-02-26 08:31:31 +01001226/* Send 1000 RACH requests and check their RA+FN on the RSL side */
1227testcase TC_rach_content() runs on test_CT {
1228 f_init(testcasename());
1229 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001230 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001231
Harald Welte8c24c2b2018-02-26 08:31:31 +01001232 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001233 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001234 for (var integer i := 0; i < 1000; i := i+1) {
1235 var OCT1 ra := f_rnd_ra_cs();
1236 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1237 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001238 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001239 }
1240 fn_last := fn;
1241
1242 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001243 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001244 alt {
1245 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, ?))) {
1246 T.stop;
1247 }
1248 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001249 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001250 }
1251 [] RSL_CCHAN.receive { repeat; }
1252 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001253 test_failed := true;
1254 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001255 }
1256 }
1257 }
Maxba06feb2019-03-05 10:52:46 +01001258 if (test_failed) {
1259 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001260 }
Maxba06feb2019-03-05 10:52:46 +01001261 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001262 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001263}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001264
1265/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1266testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001267 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001268 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001269 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001270 f_l1_tune(L1CTL);
1271
1272 var GsmFrameNumber fn_last := 0;
1273 for (var integer i := 0; i < 1000; i := i+1) {
1274 var OCT1 ra := f_rnd_ra_cs();
1275 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1276 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001277 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001278 }
1279 fn_last := fn;
1280 }
1281 var integer rsl_chrqd := 0;
1282 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001283 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001284 alt {
1285 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
1286 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001287 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001288 repeat;
1289 }
1290 [] RSL_CCHAN.receive { repeat; }
1291 [] T.timeout { }
1292 }
1293 if (rsl_chrqd == 1000) {
1294 setverdict(pass);
1295 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001296 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001297 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001298 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001299}
1300
Harald Welte3453ab42019-05-24 21:19:58 +02001301private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1302 var charstring bts_str := "bts " & int2str(bts_nr);
1303 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1304}
1305
1306/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1307private template integer tr_rach_slots_per_interval := (90 .. 130);
1308
1309/* Expect 0 RACH load on an idle BTS that has just started up */
1310testcase TC_rach_load_idle_thresh0() runs on test_CT {
1311 var ASP_RSL_Unitdata rx_ud;
1312
1313 f_init_vty_bsc();
1314 /* send load indications even at 0% load */
1315 f_vty_load_ind_thresh(0);
1316 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1317 f_sleep(2.0);
1318
1319 f_init();
1320
1321 timer T := 5.0;
1322 T.start;
1323 alt {
1324 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, 0, 0))) {
1325 setverdict(pass);
1326 repeat;
1327 }
1328 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1329 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1330 repeat;
1331 }
1332 [] RSL_CCHAN.receive {
1333 repeat;
1334 }
1335 [] T.timeout { }
1336 }
1337
1338 f_vty_load_ind_thresh(10);
1339 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1340}
1341
1342/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1343testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1344 var ASP_RSL_Unitdata rx_ud;
1345
1346 f_init_vty_bsc();
1347 f_init();
1348
1349 timer T := 5.0;
1350 T.start;
1351 alt {
1352 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1353 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1354 repeat;
1355 }
1356 [] RSL_CCHAN.receive {
1357 repeat;
1358 }
1359 [] T.timeout {
1360 setverdict(pass);
1361 }
1362 }
1363
1364 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1365}
1366
1367/* Expect 0 RACH load on an idle BTS that has just started up */
1368testcase TC_rach_load_count() runs on test_CT {
1369 var ASP_RSL_Unitdata rx_ud;
1370 var integer load_access_count := 0;
1371
1372 f_init_vty_bsc();
1373 /* send load indications even at 0% load */
1374 f_vty_load_ind_thresh(0);
1375 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1376 f_sleep(2.0);
1377 f_init();
1378
1379 f_init_l1ctl();
1380 f_sleep(1.0);
1381 f_l1_tune(L1CTL);
1382
1383 var GsmFrameNumber fn_last := 0;
1384 for (var integer i := 0; i < 1000; i := i+1) {
1385 var OCT1 ra := f_rnd_ra_cs();
1386 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1387 if (fn == fn_last) {
1388 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1389 }
1390 fn_last := fn;
1391 }
1392
1393 timer T := 5.0;
1394 T.start;
1395 alt {
1396 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
1397 -> value rx_ud {
1398 var RSL_IE_Body ie;
1399 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1400 load_access_count := load_access_count + ie.rach_load.access_count;
1401 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1402 setverdict(fail, "Access count cannot be < Busy count");
1403 }
1404 repeat;
1405 }
1406 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1407 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1408 repeat;
1409 }
1410 [] RSL_CCHAN.receive {
1411 repeat;
1412 }
1413 [] T.timeout { }
1414 }
1415 if (load_access_count == 1000) {
1416 setverdict(pass);
1417 } else {
1418 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1419 }
1420
1421 f_vty_load_ind_thresh(10);
1422 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1423}
1424
1425
1426
Harald Welte54a2a2d2018-02-26 09:14:05 +01001427private function f_main_trxc_connect() runs on test_CT {
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001428 map(self:BTS_TRXC, system:BTS_TRXC);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001429 var Result res;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001430 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BTS_TRXC, mp_bts_trxc_ip, mp_bts_trxc_port,
Harald Welted3a88a62018-03-01 16:04:52 +01001431 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +02001432 if (not ispresent(res.connId)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001433 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 +02001434 }
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001435 g_bts_trxc_conn_id := res.connId;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001436}
1437
1438private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001439 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001440 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001441 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001442 f_sleep(0.5);
1443
1444 /* Transmit RACH request + wait for confirmation */
1445 var OCT1 ra := f_rnd_ra_cs();
1446 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1447
1448 /* Check for expected result */
1449 timer T := 1.5;
1450 T.start;
1451 alt {
1452 [expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
1453 setverdict(pass);
1454 }
1455 [not expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001456 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001457 }
1458 [] RSL_CCHAN.receive { repeat; }
1459 [not expect_pass] T.timeout {
1460 setverdict(pass);
1461 }
1462 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001463 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001464 }
1465 }
1466}
1467
1468/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1469testcase TC_rach_max_ta() runs on test_CT {
1470 f_init(testcasename());
1471 f_init_l1ctl();
1472 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001473 f_sleep(1.0);
1474
1475 /* default max-ta is 63 (full range of GSM timing advance */
1476
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001477 /* We allow early arrival up to 2 symbols */
1478 f_rach_toffs(-1*256, true);
1479 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001480 f_rach_toffs(-10*256, false);
1481
1482 /* 0 / 32 / 63 bits is legal / permitted */
1483 f_rach_toffs(0, true);
1484 f_rach_toffs(32*256, true);
1485 f_rach_toffs(63*256, true);
1486
1487 /* more than 63 bits is not legal / permitted */
1488 f_rach_toffs(64*256, false);
1489 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001490 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001491}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001492
Harald Welte93640c62018-02-25 16:59:33 +01001493/***********************************************************************
1494 * Measurement Processing / Reporting
1495 ***********************************************************************/
1496
Harald Welte70767382018-02-21 12:16:40 +01001497template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1498 spare := '0'B,
1499 lpd := 0,
1500 sapi := sapi,
1501 c_r := c_r,
1502 ea := true
1503}
1504
Harald Welted879bd92018-03-12 15:01:23 +01001505template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001506 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001507 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001508 len := 0, /* overwritten */
1509 m := false,
1510 el := 1,
1511 payload := pl
1512}
1513
1514/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1515altstep as_l1_sacch() runs on ConnHdlr {
1516 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001517 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001518 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001519 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 +01001520 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001521 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001522
1523 var L1ctlDataReq data_req := {
1524 l1header := valueof(ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta)),
1525 l2_payload := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O)
1526 }
1527 log("Sending Measurement Report: ", data_req);
1528 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), data_req));
Harald Welte70767382018-02-21 12:16:40 +01001529 repeat;
1530 }
1531}
1532
1533altstep as_l1_dcch() runs on ConnHdlr {
1534 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001535 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001536 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1537 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001538 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1539 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001540 repeat;
1541 }
1542}
1543
1544type record MeasElem {
1545 uint6_t rxlev,
1546 uint3_t rxqual
1547}
1548
1549type record MeasElemFS {
1550 MeasElem full,
1551 MeasElem sub
1552}
1553
1554type record ConnL1Pars {
1555 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001556 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001557 MeasElemFS meas_ul,
1558 int16_t timing_offset_256syms,
1559 uint5_t bs_power_level,
1560 uint5_t ms_power_level,
1561 uint8_t ms_actual_ta
1562}
1563
1564/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1565private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1566 return 63 + (toffs256s/256);
1567}
1568
Harald Welted5684392018-03-10 18:22:04 +01001569private function f_max(integer a, integer b) return integer {
1570 if (a > b) {
1571 return a;
1572 } else {
1573 return b;
1574 }
1575}
1576
1577private function f_min(integer a, integer b) return integer {
1578 if (a < b) {
1579 return a;
1580 } else {
1581 return b;
1582 }
1583}
1584
1585/* compute negative tolerance val-tolerance, ensure >= min */
1586private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1587 val := val - tolerance;
1588 return f_max(val, min);
1589}
1590
1591/* compute positive tolerance val+tolerance, ensure <= max */
1592private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1593 val := val + tolerance;
1594 return f_min(val, max);
1595}
1596
1597/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1598private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1599return template integer {
1600 var template integer ret;
1601 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1602 return ret;
1603}
1604
1605
Harald Welte70767382018-02-21 12:16:40 +01001606/* build a template for matching measurement results against */
1607private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1608 var ConnL1Pars l1p := g_pars.l1_pars;
1609 var template RSL_IE_UplinkMeas ul_meas := {
1610 len := 3,
1611 rfu := '0'B,
1612 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001613 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001614 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001615 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001616 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001617 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1618 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001619 supp_meas_info := omit
1620 };
Harald Welte685d5982018-02-27 20:42:05 +01001621 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001622 ul_meas.len := (3+8);
1623 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001624 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001625 toa256_min := ?,
1626 toa256_max := ?,
1627 toa256_std_dev := ?
1628 }
Harald Welte685d5982018-02-27 20:42:05 +01001629 }
Harald Welte70767382018-02-21 12:16:40 +01001630 var template RSL_IE_BS_Power bs_power := {
1631 reserved := 0,
1632 epc := false,
1633 fpc := false,
1634 power_level := l1p.bs_power_level
1635 };
1636 var template RSL_IE_L1Info l1_info := {
1637 ms_power_lvl := l1p.ms_power_level,
1638 fpc := false,
1639 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001640 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001641 };
1642 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001643 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001644 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1645 ?, t_toffs);
1646}
1647
1648/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001649altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001650 var RSL_Message rsl;
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001651 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Harald Welte70767382018-02-21 12:16:40 +01001652 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1653 /* increment counter of next to-be-expected meas rep */
1654 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1655 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001656 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001657 repeat;
1658 }
1659 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001660 /* increment counter of next to-be-expected meas rep */
1661 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1662 if (g_first_meas_res) {
1663 g_first_meas_res := false;
1664 repeat;
1665 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001666 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001667 }
Harald Welte70767382018-02-21 12:16:40 +01001668 }
1669 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001670 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001671 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001672 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001673 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001674 }
1675}
1676
Harald Weltee613f962018-04-18 22:38:16 +02001677private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1678 select (rsl_alg_id) {
1679 case (RSL_ALG_ID_A5_0) { return 0; }
1680 case (RSL_ALG_ID_A5_1) { return 1; }
1681 case (RSL_ALG_ID_A5_2) { return 2; }
1682 case (RSL_ALG_ID_A5_3) { return 3; }
1683 case (RSL_ALG_ID_A5_4) { return 4; }
1684 case (RSL_ALG_ID_A5_5) { return 5; }
1685 case (RSL_ALG_ID_A5_6) { return 6; }
1686 case (RSL_ALG_ID_A5_7) { return 7; }
1687 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001688 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1689 /* Make compiler happy by calling mtc.stop here. It is already
1690 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001691 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001692 }
1693 }
1694}
1695
1696private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1697 select (rsl_alg_id) {
1698 case (RSL_ALG_ID_A5_1) { return '000'B; }
1699 case (RSL_ALG_ID_A5_2) { return '001'B; }
1700 case (RSL_ALG_ID_A5_3) { return '010'B; }
1701 case (RSL_ALG_ID_A5_4) { return '011'B; }
1702 case (RSL_ALG_ID_A5_5) { return '100'B; }
1703 case (RSL_ALG_ID_A5_6) { return '101'B; }
1704 case (RSL_ALG_ID_A5_7) { return '110'B; }
1705 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001706 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1707 /* Make compiler happy by calling mtc.stop here. It is already
1708 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001709 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001710 }
1711 }
1712}
1713
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001714/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1715private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1716 var GsmFrameNumber fn;
1717 timer T := 8.0;
1718
1719 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1720 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1721
1722 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1723 /* Send the actual RACH */
1724 fn := f_L1CTL_RACH(L1CTL, ra);
1725
1726 T.start;
1727 alt {
1728 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1729 [] T.timeout {
1730 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1731 }
1732 }
1733 T.stop
1734 return fn;
1735}
Harald Weltee613f962018-04-18 22:38:16 +02001736
Harald Welte70767382018-02-21 12:16:40 +01001737/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001738private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001739 var GsmFrameNumber fn;
1740 var ImmediateAssignment imm_ass;
1741 var integer ra := 23;
1742
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001743 /* Send RACH request and wait for ChanReq */
1744 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001745
1746 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001747 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01001748
1749 /* Send IMM.ASS via CCHAN */
1750 var ChannelDescription ch_desc := {
1751 chan_nr := g_pars.chan_nr,
1752 tsc := 7,
1753 h := false,
1754 arfcn := mp_trx0_arfcn,
1755 maio_hsn := omit
1756 };
1757 var MobileAllocation ma := {
1758 len := 0,
1759 ma := ''B
1760 };
1761 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1762 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1763
1764 /* receive IMM.ASS on MS side */
1765 var ImmediateAssignment ia_um;
1766 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1767 /* enable dedicated mode */
1768 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltee613f962018-04-18 22:38:16 +02001769 /* enable encryption, if requested */
1770 if (encr_enable) {
1771 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1772 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1773 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001774
1775 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001776}
1777
1778/* establish DChan, verify existance + contents of measurement reports */
1779function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001780 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001781 RSL.clear;
1782
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001783 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001784 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001785 f_trx_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
1786 }
Harald Welte70767382018-02-21 12:16:40 +01001787
1788 f_est_dchan();
1789
1790 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1791 * RSL measurement reports on Abis side */
1792 timer T := 8.0;
1793 T.start;
1794 alt {
1795 [] as_l1_sacch();
1796 [] as_meas_res();
1797 [] as_l1_dcch();
1798 [] L1CTL.receive { repeat; }
1799 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001800 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01001801 * of any earlier errors, so if we reach this timeout, we're good */
1802 setverdict(pass);
1803 }
1804 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001805 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01001806 }
1807 }
1808 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001809 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001810}
Harald Welte0472ab42018-03-12 15:02:26 +01001811
Harald Welte70767382018-02-21 12:16:40 +01001812testcase TC_meas_res_sign_tchf() runs on test_CT {
1813 var ConnHdlr vc_conn;
1814 var ConnHdlrPars pars;
1815 f_init(testcasename());
1816 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1817 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1818 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1819 vc_conn.done;
1820 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001821 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001822}
1823testcase TC_meas_res_sign_tchh() runs on test_CT {
1824 var ConnHdlr vc_conn;
1825 var ConnHdlrPars pars;
1826 f_init(testcasename());
1827 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1828 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1829 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1830 vc_conn.done;
1831 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001832 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001833}
1834testcase TC_meas_res_sign_sdcch4() runs on test_CT {
1835 var ConnHdlr vc_conn;
1836 var ConnHdlrPars pars;
1837 f_init(testcasename());
1838 for (var integer ss := 0; ss <= 3; ss := ss+1) {
1839 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
1840 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1841 vc_conn.done;
1842 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001843 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001844}
1845testcase TC_meas_res_sign_sdcch8() runs on test_CT {
1846 var ConnHdlr vc_conn;
1847 var ConnHdlrPars pars;
1848 f_init(testcasename());
1849 for (var integer ss := 0; ss <= 7; ss := ss+1) {
1850 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
1851 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1852 vc_conn.done;
1853 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001854 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001855}
Harald Welte685d5982018-02-27 20:42:05 +01001856testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
1857 var ConnHdlr vc_conn;
1858 var ConnHdlrPars pars;
1859 f_init(testcasename());
1860 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
1861 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1862 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1863 pars.l1_pars.toa256_enabled := true;
1864 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1865 vc_conn.done;
1866 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001867 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01001868}
1869
Philipp Maier4d1e9c92018-12-20 11:11:56 +01001870/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
1871 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
1872function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
1873 var L1ctlDlMessage l1_dl;
1874 var RSL_IE_MS_Power ms_power;
1875 var RSL_Message rsl;
1876 var uint5_t power_level := 0;
1877
1878 f_l1_tune(L1CTL);
1879 RSL.clear;
1880
1881 f_est_dchan();
1882
1883 ms_power.reserved := 0;
1884 ms_power.fpc_epc := false;
1885
1886 /* Send the first power control command. This will disable any BTS/TRX
1887 * internal power control and switch the MS (which is not in scope of
1888 * this test) to a constant power level. We start with a power level
1889 * of 0 */
1890 ms_power.power_level := power_level;
1891 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1892 RSL.send(rsl);
1893
1894 alt {
1895
1896 /* Pick all SACCH blocks for checking */
1897 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1898
1899 /* The first byte of the L1 header contains the power level.
1900 * The reserved bits and the fpc bit is set to 0, so we may
1901 * compare directly. */
1902 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
1903 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
1904 }
1905
1906 /* Signal a new power level via RSL for the next turn. */
1907 if (power_level < 31) {
1908 power_level := power_level + 1;
1909 ms_power.power_level := power_level;
1910 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1911 RSL.send(rsl);
1912 repeat;
1913 }
1914
1915 }
1916
1917 /* Ignore all other blocks */
1918 [] L1CTL.receive { repeat; }
1919
1920 }
1921
1922 f_rsl_chan_deact();
1923 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1924
1925 setverdict(pass);
1926}
1927
1928testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
1929 var ConnHdlr vc_conn;
1930 var ConnHdlrPars pars;
1931 f_init(testcasename());
1932
1933 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1934 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1935 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
1936 vc_conn.done;
1937 }
1938 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1939}
Harald Welte70767382018-02-21 12:16:40 +01001940
Eric Wild6833cc92019-05-23 19:34:44 +02001941/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
1942TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
1943function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
1944 var L1ctlDlMessage l1_dl;
1945 var uint5_t ta_to_test := 16;
1946
1947
1948 f_l1_tune(L1CTL);
1949 RSL.clear;
1950
1951 /* tell fake_trx to use a given timing offset for all bursts */
1952 f_trx_fake_toffs256(ta_to_test*256);
1953
1954 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
1955
1956
1957 alt {
1958
1959 /* Pick all SACCH blocks for checking */
1960 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1961
1962 /* The second byte of the L1 header contains the TA. */
1963 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
1964 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
1965 }
1966
1967 }
1968
1969 /* Ignore all other blocks */
1970 [] L1CTL.receive { repeat; }
1971
1972 }
1973
1974 f_rsl_chan_deact();
1975 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1976
1977 setverdict(pass);
1978}
1979
1980testcase TC_rsl_chan_initial_ta() runs on test_CT {
1981 var ConnHdlr vc_conn;
1982 var ConnHdlrPars pars;
1983 f_init(testcasename());
1984 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
1985 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars);
1986 vc_conn.done;
1987 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1988}
1989
Harald Welte0472ab42018-03-12 15:02:26 +01001990/* 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 +01001991private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001992 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001993 RSL.clear;
1994
1995 f_est_dchan();
1996 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01001997 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01001998
1999 timer T := 40.0;
2000 T.start;
2001 alt {
2002 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
2003 setverdict(pass)
2004 }
2005 [] RSL.receive { repeat };
2006 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002007 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01002008 }
2009 }
2010 f_rsl_chan_deact();
2011}
2012testcase TC_conn_fail_crit() runs on test_CT {
2013 var ConnHdlr vc_conn;
2014 var ConnHdlrPars pars;
2015 f_init(testcasename());
2016 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
2017 pars.t_guard := 60.0;
2018 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
2019 vc_conn.done;
2020}
2021
Harald Welte93640c62018-02-25 16:59:33 +01002022/***********************************************************************
2023 * Paging
2024 ***********************************************************************/
2025
Harald Welte68e495b2018-02-25 00:05:57 +01002026function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
2027 if (tmsi == 'FFFFFFFF'O) {
2028 return true;
2029 } else {
2030 return false;
2031 }
2032}
Harald Welte70767382018-02-21 12:16:40 +01002033
Philipp Maier82cb0b12018-08-31 14:41:39 +02002034type record allowedFn { integer frame_nr }
2035template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
2036template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
2037template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
2038template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
2039template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
2040template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
2041template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
2042template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
2043function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
2044{
2045 var integer frame_nr_51;
2046 frame_nr_51 := frame_nr mod 51
2047
2048 var allowedFn fn_check;
2049 fn_check.frame_nr := frame_nr_51;
2050
2051 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002052 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002053 return;
2054 }
2055
2056 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
2057 return;
2058 }
2059 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
2060 return;
2061 }
2062 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
2063 return;
2064 }
2065 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
2066 return;
2067 }
2068 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
2069 return;
2070 }
2071 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
2072 return;
2073 }
2074 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
2075 return;
2076 }
2077 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
2078 return;
2079 }
2080
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002081 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002082 return;
2083}
2084
2085altstep 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 +01002086runs on test_CT {
2087 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002088 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002089 repeat;
2090 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01002091 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01002092 var octetstring without_plen :=
2093 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
2094 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02002095
2096 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
2097
Harald Welte68e495b2018-02-25 00:05:57 +01002098 if (match(rr, tr_PAGING_REQ1)) {
2099 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2100 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2101 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
2102 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2103 }
2104 } else if (match(rr, tr_PAGING_REQ2)) {
2105 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2106 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
2107 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2108 }
2109 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
2110 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2111 }
2112 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
2113 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2114 }
2115 } else if (match(rr, tr_PAGING_REQ3)) {
2116 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2117 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
2118 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2119 }
2120 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
2121 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2122 }
2123 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
2124 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2125 }
2126 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
2127 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2128 }
2129 }
2130 repeat;
2131 }
2132}
2133
2134type record PagingTestCfg {
2135 boolean combined_ccch,
2136 integer bs_ag_blks_res,
2137 float load_factor,
2138 boolean exp_load_ind,
2139 boolean exp_overload,
2140 boolean use_tmsi
2141}
2142
2143type record PagingTestState {
2144 integer num_paging_sent,
2145 integer num_paging_rcv_msgs,
2146 integer num_paging_rcv_ids,
2147 integer num_overload
2148}
2149
2150/* receive + ignore RSL RF RES IND */
2151altstep as_rsl_res_ind() runs on test_CT {
2152 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
2153 repeat;
2154 }
2155}
2156
2157/* Helper function for paging related testing */
2158private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
2159 f_init(testcasename());
2160 f_init_l1ctl();
2161 f_l1_tune(L1CTL);
2162
2163 var PagingTestState st := {
2164 num_paging_sent := 0,
2165 num_paging_rcv_msgs := 0,
2166 num_paging_rcv_ids := 0,
2167 num_overload := 0
2168 };
2169
2170 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
2171 var float max_pch_imsi_per_sec;
2172 if (cfg.use_tmsi) {
2173 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
2174 } else {
2175 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
2176 }
2177 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
2178 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002179 var float time_total := 20.0;
2180 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
2181 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01002182
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002183 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
2184 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01002185
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002186 timer T_itv := 0.0;
2187 T_itv.start;
2188 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01002189 alt {
2190 /* check for presence of CCCH LOAD IND (paging load) */
2191 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
2192 st.num_overload := st.num_overload + 1;
2193 repeat;
2194 }
2195 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002196 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01002197 }
2198 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
2199 log("Rx LOAD_IND");
2200 /* FIXME: analyze/verify interval + contents */
2201 repeat;
2202 }
2203 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02002204 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002205 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002206 [] T_itv.timeout {
2207 /* Send paging cmds based on elapsed time */
2208 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
2209 while (st.num_paging_sent < new_sent) {
2210 /* build mobile Identity */
2211 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2212 if (cfg.use_tmsi) {
2213 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2214 } else {
2215 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(st.num_paging_sent)));
2216 }
2217 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2218 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2219
2220 /* Send RSL PAGING COMMAND */
2221 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, st.num_paging_sent mod 4)));
2222
2223 st.num_paging_sent := st.num_paging_sent + 1;
2224 }
2225 if (st.num_paging_sent < pkt_total) {
2226 /* Wait for interval to next PAGING COMMAND */
2227 var float time_now := T_total.read;
2228 var float next_sched := int2float(st.num_paging_sent)*interval;
2229 if (next_sched > time_now) {
2230 T_itv.start(next_sched - time_now);
2231 } else {
2232 T_itv.start(0.0);
2233 }
2234 } else {
2235 /* We are done, no need to keep counting */
2236 T_total.stop;
2237 }
2238 }
2239 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01002240 [] as_rsl_res_ind();
2241 }
2242 }
2243
2244 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
2245 timer T_wait := 18.0;
2246 T_wait.start;
2247 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02002248 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002249 [] L1CTL.receive { repeat; }
2250 /* 65535 == empty paging queue, we can terminate*/
2251 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
2252 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
2253 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002254 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01002255 }
2256 [] as_rsl_res_ind();
2257 }
2258
2259 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
2260 " rcvd_ids=", st.num_paging_rcv_ids);
2261 return st;
2262}
2263
2264/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
2265 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2266 * - that CCCH LOAD IND (PCH) are being generated
2267 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2268testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002269 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002270 var PagingTestCfg cfg := {
2271 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002272 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002273 load_factor := 0.8,
2274 exp_load_ind := true,
2275 exp_overload := false,
2276 use_tmsi := false
2277 };
2278 var PagingTestState st := f_TC_paging(cfg);
2279 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002280 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2281 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002282 } else {
2283 setverdict(pass);
2284 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002285 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002286}
2287
2288/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
2289 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2290 * - that CCCH LOAD IND (PCH) are being generated
2291 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2292testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002293 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002294 var PagingTestCfg cfg := {
2295 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002296 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002297 load_factor := 0.8,
2298 exp_load_ind := true,
2299 exp_overload := false,
2300 use_tmsi := true
2301 };
2302 var PagingTestState st := f_TC_paging(cfg);
2303 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002304 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2305 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002306 } else {
2307 setverdict(pass);
2308 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002309 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002310}
2311
2312/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
2313 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2314 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2315 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2316testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002317 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002318 var PagingTestCfg cfg := {
2319 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002320 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002321 load_factor := 2.0,
2322 exp_load_ind := true,
2323 exp_overload := true,
2324 use_tmsi := false
2325 };
2326 var PagingTestState st := f_TC_paging(cfg);
2327 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
2328 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002329 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002330 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002331 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 +01002332 } else {
2333 setverdict(pass);
2334 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002335 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002336}
2337
2338/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
2339 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2340 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2341 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2342testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002343 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002344 var PagingTestCfg cfg := {
2345 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002346 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002347 load_factor := 2.0,
2348 exp_load_ind := true,
2349 exp_overload := true,
2350 use_tmsi := true
2351 };
2352 var PagingTestState st := f_TC_paging(cfg);
2353 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
2354 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002355 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002356 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002357 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 +01002358 } else {
2359 setverdict(pass);
2360 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002361 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002362}
2363
2364
Harald Welte93640c62018-02-25 16:59:33 +01002365/***********************************************************************
2366 * Immediate Assignment / AGCH
2367 ***********************************************************************/
Harald Weltee8d750e2018-06-10 21:41:35 +02002368const MobileAllocation c_MA_null := {
2369 len := 0,
2370 ma := ''B
2371}
Harald Welte93640c62018-02-25 16:59:33 +01002372
Harald Weltee8d750e2018-06-10 21:41:35 +02002373template (value) ChannelDescription ts_ChanDesc(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
2374 uint12_t arfcn := 871) := {
2375 chan_nr := chan_nr,
2376 tsc := tsc,
2377 h := false,
2378 arfcn := arfcn,
2379 maio_hsn := omit
2380}
2381
2382private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
2383 return int2str(num_tx) & " sent, "
2384 & int2str(num_rx) & " received, "
2385 & int2str(num_del) & " deleted";
2386}
2387
2388private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
2389 var L1ctlDlMessage l1_dl;
2390 timer T := 10.0;
2391 var integer num_tx := 0;
2392 var integer num_rx := 0;
2393 var integer num_del := 0;
2394 var charstring res_str;
2395 var float rx_ratio;
2396
Harald Welte68e495b2018-02-25 00:05:57 +01002397 f_init(testcasename());
Harald Weltee8d750e2018-06-10 21:41:35 +02002398 f_init_l1ctl();
2399 f_l1_tune(L1CTL);
2400
2401 for (var integer i := 0; i < num_total; i := i+1) {
2402 var ChannelDescription ch_desc := valueof(ts_ChanDesc(valueof(t_RslChanNr_SDCCH4(0, 0))));
2403 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
2404 var octetstring ia_enc := enc_GsmRrMessage(ia);
Harald Welte68e495b2018-02-25 00:05:57 +01002405 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02002406 num_tx := num_tx+1;
2407 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01002408 }
2409 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02002410 T.start;
2411 alt {
2412 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
2413 num_del := num_del+1;
2414 repeat;
2415 }
2416 [] RSL_CCHAN.receive {
2417 repeat;
2418 }
2419 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
2420 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2421 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
2422 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
2423 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002424 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02002425 } else {
2426 num_rx := num_rx+1;
2427 }
2428 repeat;
2429 }
2430 [] L1CTL.receive { repeat; }
2431 [] T.timeout { }
2432 }
2433 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
2434 log("AGCH test: " & res_str);
2435 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002436 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02002437 }
2438 rx_ratio := int2float(num_rx) / int2float(num_tx);
2439 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002440 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 +02002441 } else {
2442 setverdict(pass);
2443 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002444 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002445}
2446
Harald Weltee8d750e2018-06-10 21:41:35 +02002447/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
2448testcase TC_imm_ass_1000_20ms() runs on test_CT {
2449 f_TC_imm_ass(1000, 0.02, 0.25);
2450}
2451
2452/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
2453testcase TC_imm_ass_200_0ms() runs on test_CT {
2454 f_TC_imm_ass(200, 0.0, 0.05);
2455}
2456
2457/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
2458testcase TC_imm_ass_200_76ms() runs on test_CT {
2459 f_TC_imm_ass(150, 0.076, 1.00);
2460}
2461
2462
2463
Harald Welte48494ca2018-02-25 16:59:50 +01002464/***********************************************************************
2465 * BCCH
2466 ***********************************************************************/
2467
2468/* tuple of Frame Number + decoded SI */
2469type record SystemInformationFn {
2470 GsmFrameNumber frame_number,
2471 SystemInformation si
2472}
2473
2474/* an arbitrary-length vector of decoded SI + gsmtap header */
2475type record of SystemInformationFn SystemInformationVector;
2476
2477/* an array of SI-vectors indexed by TC value */
2478type SystemInformationVector SystemInformationVectorPerTc[8];
2479
2480/* determine if a given SI vector contains given SI type at least once */
2481function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2482 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2483 var integer fn_mod51 := arr[i].frame_number mod 51;
2484 if (not bcch_ext and fn_mod51 == 2 or
2485 bcch_ext and fn_mod51 == 6) {
2486 if (arr[i].si.header.message_type == key) {
2487 return true;
2488 }
2489 }
2490 }
2491 return false;
2492}
2493
2494/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
2495function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2496 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002497 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002498 }
2499}
2500
2501/* check if a given SI vector contains given SI type at least once on any TC */
2502function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
2503 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
2504 if (f_si_vecslot_contains(arr[tc], key) or
2505 f_si_vecslot_contains(arr[tc], key, true)) {
2506 return true;
2507 }
2508 }
2509 return false;
2510}
2511
2512/* determine if a given SI vector contains given SI type at least N of M times */
2513function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
2514 var integer count := 0;
2515 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002516 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01002517 }
2518 for (var integer i:= 0; i < m; i := i + 1) {
2519 var integer fn_mod51 := arr[i].frame_number mod 51;
2520 if (not bcch_ext and fn_mod51 == 2 or
2521 bcch_ext and fn_mod51 == 6) {
2522 if (arr[i].si.header.message_type == key) {
2523 count := count + 1;
2524 }
2525 }
2526 }
2527 if (count >= n) {
2528 return true;
2529 } else {
2530 return false;
2531 }
2532}
2533
2534/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
2535function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
2536 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002537 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002538 }
2539}
2540
2541/* determine if a given SI vector contains given SI type at least once */
2542function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2543 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2544 var integer fn_mod51 := arr[i].frame_number mod 51;
2545 if (not bcch_ext and fn_mod51 == 2 or
2546 bcch_ext and fn_mod51 == 6) {
2547 if (arr[i].si.header.message_type != key) {
2548 return false;
2549 }
2550 }
2551 }
2552 return true;
2553}
2554
2555/* ensure a given TC slot of the SI vector contains only given SI type */
2556function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2557 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002558 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002559 }
2560}
2561
2562/* SI configuration of cell, against which we validate actual SI messages */
2563type set SystemInformationConfig {
2564 boolean bcch_extended,
2565 boolean si1_present,
2566 boolean si2bis_present,
2567 boolean si2ter_present,
2568 boolean si2quater_present,
2569 boolean si7_present,
2570 boolean si8_present,
2571 boolean si9_present,
2572 boolean si13_present,
2573 boolean si13alt_present,
2574 boolean si15_present,
2575 boolean si16_present,
2576 boolean si17_present,
2577 boolean si2n_present,
2578 boolean si21_present,
2579 boolean si22_present
2580}
2581
2582/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
2583function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
2584 var integer i;
2585 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
2586 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002587 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01002588 }
2589 }
2590 if (cfg.si1_present) {
2591 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
2592 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
2593 * when TC = 0, it can assume that System Information Type 1 is not in use. */
2594 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2595 /* make sure *ALL* contain SI1 */
2596 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2597 }
2598 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
2599 /* iii) A SI 2 message will be sent at least every time TC = 1 */
2600 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
2601 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
2602 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
2603 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
2604
2605 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
2606 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
2607 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
2608 * consecutive occurrences of TC = 4. */
2609 if (cfg.si2bis_present and not cfg.si2ter_present) {
2610 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2611 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
2612 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
2613 } else if (cfg.si2ter_present and cfg.si2bis_present) {
2614 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2615 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
2616 }
2617
2618 if (cfg.si7_present or cfg.si8_present) {
2619 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
2620 * if System Information type 4 does not contain all information needed for cell
2621 * selection and reselection. */
2622 if (not cfg.bcch_extended) {
2623 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
2624 }
2625 if (cfg.si7_present) {
2626 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
2627 }
2628 if (cfg.si8_present) {
2629 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
2630 }
2631 }
2632
2633 if (cfg.si2quater_present) {
2634 /* iii) System information type 2 quater is sent if needed, as determined by the system
2635 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
2636 * and 2ter are used, otherwise it shall be sent at least once within any of 4
2637 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
2638 * within any of 4 consecutive occurrences of TC = 5. */
2639 if (not (cfg.bcch_extended)) {
2640 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
2641 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
2642 } else {
2643 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
2644 }
2645 } else {
2646 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
2647 }
2648 }
2649 if (cfg.si9_present) {
2650 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
2651 * in system information type 3 as defined in 3GPP TS 44.018. */
2652 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
2653 }
2654 if (cfg.si13_present) {
2655 /* vii) System Information type 13 is only related to the GPRS service. System Information
2656 * Type 13 need only be sent if GPRS support is indicated in one or more of System
2657 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
2658 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
2659 * In the case that the message is sent on the BCCH Norm, it is sent at least once
2660 * within any of 4 consecutive occurrences of TC=4. */
2661 if (not cfg.bcch_extended) {
2662 log("not-bccch-extended");
2663 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
2664 } else {
2665 log("bccch-extended");
2666 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
2667 }
2668 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002669 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002670 }
2671 }
2672 if (cfg.si16_present or cfg.si17_present) {
2673 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
2674 * should not be sent in a cell where network sharing is used (see rule xv). */
2675 if (cfg.si22_present) {
2676 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2677 }
2678 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002679 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002680 }
2681 if (not cfg.bcch_extended) {
2682 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
2683 }
2684 if (cfg.si16_present) {
2685 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
2686 }
2687 if (cfg.si17_present) {
2688 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
2689 }
2690 }
2691
2692 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
2693 * broadcast information. The frequency with which they are sent is determined by the
2694 * system operator. System Information type 9 identifies the scheduling of System
2695 * Information type 18 and 20 messages. */
2696
2697 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
2698 * Information Type 19 is present, then its scheduling shall be indicated in System
2699 * Information Type 9. */
2700
2701 if (cfg.si15_present) {
2702 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
2703 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
2704 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
2705 * 4 consecutive occurrences of TC = 1. */
2706 if (not cfg.bcch_extended) {
2707 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
2708 } else {
2709 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
2710 }
2711 }
2712 if (cfg.si13alt_present) {
2713 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
2714 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
2715 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
2716 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
2717 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
2718 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
2719 * of TC = 4. */
2720 if (cfg.si13_present) {
2721 testcase.stop("Error: Cannot have SI13alt and SI13");
2722 }
2723 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002724 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002725 }
2726 if (not cfg.bcch_extended) {
2727 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
2728 } else {
2729 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
2730 }
2731 }
2732 if (cfg.si2n_present) {
2733 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
2734 * as determined by the system operator. In the case that the message is sent on the
2735 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
2736 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
2737 * consecutive occurrences of TC = 4. */
2738 if (not cfg.bcch_extended) {
2739 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
2740 } else {
2741 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
2742 }
2743 }
2744 if (cfg.si21_present) {
2745 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
2746 * determined by the system operator. If Extended Access Barring is in use in the cell
2747 * then this message is sent at least once within any of 4 consecutive occurrences of
2748 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
2749 * cell then this message shall only be sent on BCCH Ext. */
2750 if (not cfg.bcch_extended) {
2751 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
2752 } else {
2753 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
2754 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002755 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01002756 }
2757 }
2758 }
2759 if (cfg.si22_present) {
2760 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
2761 * should not be sent in a cell where SoLSA is used (see rule viii). System
2762 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
2763 * =2 and TC=6. */
2764 if (cfg.si16_present or cfg.si17_present) {
2765 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2766 }
2767 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
2768 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002769 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002770 }
2771 if (not cfg.bcch_extended) {
2772 testcase.stop("Error: SI22 requires BCCH Extd!");
2773 } else {
2774 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
2775 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
2776 }
2777 }
2778}
2779
2780/* sample Systme Information for specified duration via L1CTL */
2781function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
2782 timer T := duration;
2783 var SystemInformationVectorPerTc si_per_tc;
2784 var L1ctlDlMessage l1_dl;
2785
2786 /* initialize all per-TC vectors empty */
2787 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2788 si_per_tc[i] := {};
2789 }
2790
2791 /* flush all previous L1 queued msgs */
2792 pt.clear;
2793
2794 T.start;
2795 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002796 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01002797 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2798 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
2799 log("Ignoring non-RR SI ", l1_dl);
2800 repeat;
2801 }
2802 var SystemInformationFn sig := {
2803 frame_number := l1_dl.dl_info.frame_nr,
2804 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
2805 }
2806 var integer tc := f_gsm_compute_tc(sig.frame_number);
2807 log("SI received at TC=", tc, ": ", sig.si);
2808 /* append to the per-TC bucket */
2809 si_per_tc[tc] := si_per_tc[tc] & { sig };
2810 repeat;
2811 }
2812 [] pt.receive { repeat; }
2813 [] T.timeout { }
2814 }
2815
2816 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2817 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
2818 }
2819 log("si_per_tc=", si_per_tc);
2820 return si_per_tc;
2821}
2822
2823/* helper function: Set given SI via RSL + validate scheduling.
2824 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
2825function f_TC_si_sched() runs on test_CT {
2826 var SystemInformationVectorPerTc si_per_tc;
2827 f_init_l1ctl();
2828 f_l1_tune(L1CTL);
2829
2830 /* Sample + Validate Scheduling */
2831 si_per_tc := f_l1_sample_si(L1CTL);
2832 f_validate_si_scheduling(si_cfg, si_per_tc);
2833
2834 setverdict(pass);
2835}
2836
2837testcase TC_si_sched_default() runs on test_CT {
2838 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01002839 /* 2+3+4 are mandatory and set in f_init() */
2840 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002841 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01002842}
2843
2844testcase TC_si_sched_1() runs on test_CT {
2845 f_init();
2846 si_cfg.si1_present := true;
2847 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002848 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002849 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002850}
2851
2852testcase TC_si_sched_2bis() runs on test_CT {
2853 f_init();
2854 si_cfg.si2bis_present := true;
2855 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2856 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002857 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002858}
2859
2860testcase TC_si_sched_2ter() runs on test_CT {
2861 f_init();
2862 si_cfg.si2ter_present := true;
2863 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2864 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002865 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002866}
2867
2868testcase TC_si_sched_2ter_2bis() runs on test_CT {
2869 f_init();
2870 si_cfg.si2bis_present := true;
2871 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2872 si_cfg.si2ter_present := true;
2873 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2874 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002875 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002876}
2877
2878testcase TC_si_sched_2quater() runs on test_CT {
2879 f_init();
2880 si_cfg.si2quater_present := true;
2881 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2882 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002883 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002884}
2885
2886testcase TC_si_sched_13() runs on test_CT {
2887 f_init();
2888 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002889 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002890 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002891 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002892}
2893
2894testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
2895 f_init();
2896 si_cfg.si2bis_present := true;
2897 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2898 si_cfg.si2ter_present := true;
2899 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2900 si_cfg.si2quater_present := true;
2901 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2902 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002903 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002904 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002905 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002906}
2907
2908
Harald Welte68e495b2018-02-25 00:05:57 +01002909testcase TC_bcch_info() runs on test_CT {
2910 f_init(testcasename());
2911 /* FIXME: enable / disable individual BCCH info */
2912 //ts_RSL_BCCH_INFO(si_type, info);
2913 /* expect no ERROR REPORT after either of them *
2914 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002915 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002916}
2917
Harald Welte93640c62018-02-25 16:59:33 +01002918/***********************************************************************
2919 * Low-Level Protocol Errors / ERROR REPORT
2920 ***********************************************************************/
2921
Harald Welte01d982c2018-02-25 01:31:40 +01002922private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
2923 timer T := 5.0;
2924 T.start;
2925 alt {
2926 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
2927 setverdict(pass);
2928 }
2929 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002930 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01002931 }
2932 [] RSL_CCHAN.receive {
2933 repeat;
2934 }
2935 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002936 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01002937 }
2938 }
2939}
2940
2941/* Provoke a protocol error (message too short) and match on ERROR REPORT */
2942testcase TC_rsl_protocol_error() runs on test_CT {
2943 f_init(testcasename());
2944 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2945 rsl.ies := omit;
2946 RSL_CCHAN.send(ts_RSL_UD(rsl));
2947
2948 f_exp_err_rep(RSL_ERR_PROTO);
2949}
2950
2951/* Provoke a mandatory IE error and match on ERROR REPORT */
2952testcase TC_rsl_mand_ie_error() runs on test_CT {
2953 f_init(testcasename());
2954
2955 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2956 rsl.ies := { rsl.ies[0] };
2957 RSL_CCHAN.send(ts_RSL_UD(rsl));
2958
2959 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
2960}
2961
2962/* Provoke an IE content error and match on ERROR REPORT */
2963testcase TC_rsl_ie_content_error() runs on test_CT {
2964 f_init(testcasename());
2965 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2966 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
2967 RSL_CCHAN.send(ts_RSL_UD(rsl));
2968
2969 f_exp_err_rep(RSL_ERR_IE_CONTENT);
2970}
2971
Harald Welteee25aae2019-05-19 14:32:37 +02002972/* attempt to activate channel with wrong RSL Message Discriminator IE */
2973function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
2974 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
2975 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
2976 RSL.send(rsl);
2977 f_rslem_unregister(0, g_chan_nr);
2978}
2979testcase TC_err_rep_wrong_mdisc() runs on test_CT {
2980 var ConnHdlr vc_conn;
2981 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
2982
2983 f_init(testcasename());
2984
2985 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
2986 vc_conn.done;
2987 f_exp_err_rep(RSL_ERR_MSG_DISCR);
2988
2989 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2990}
2991
2992/* Send messages with wrong message type */
2993function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
2994 var template (value) RSL_Message rsl_tx;
2995 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
2996 rsl_tx.msg_type := RSL_MT_NOT_CMD;
2997 RSL.send(rsl_tx);
2998 f_rslem_unregister(0, g_chan_nr);
2999}
3000function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
3001 var template (value) RSL_Message rsl_tx;
3002 /* we first have to activate the dedicated channel */
3003 f_rsl_chan_act(g_pars.chan_mode);
3004 /* ... to then send an invalid RLL message */
3005 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
3006 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
3007 RSL.send(rsl_tx);
3008 f_rslem_unregister(0, g_chan_nr);
3009}
3010testcase TC_err_rep_wrong_msg_type() runs on test_CT {
3011 var ConnHdlr vc_conn;
3012 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3013 var template (value) RSL_Message rsl_tx;
3014
3015 f_init(testcasename());
3016
3017 /* Common Channel with wrong message type */
3018 RSL_CCHAN.clear;
3019 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3020 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
3021 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3022 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3023
3024 /* TRX Management */
3025 RSL_CCHAN.clear;
3026 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
3027 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
3028 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3029 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3030
3031 /* Dedicated Channel */
3032 RSL_CCHAN.clear;
3033 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
3034 vc_conn.done;
3035 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3036
3037 /* RLL */
3038 RSL_CCHAN.clear;
3039 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
3040 vc_conn.done;
3041 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3042}
3043
3044/* Send messages in wrong sequence (RLL to an inactive lchan) */
3045function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
3046 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
3047 f_rslem_unregister(0, g_chan_nr);
3048}
3049testcase TC_err_rep_wrong_sequence() runs on test_CT {
3050 var ConnHdlr vc_conn;
3051 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3052
3053 f_init(testcasename());
3054
3055 RSL_CCHAN.clear;
3056 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
3057 vc_conn.done;
3058 f_exp_err_rep(RSL_ERR_MSG_SEQ);
3059}
3060
Harald Welte93640c62018-02-25 16:59:33 +01003061/***********************************************************************
3062 * IPA CRCX/MDCX/DLCS media stream handling
3063 ***********************************************************************/
3064
Harald Weltea871a382018-02-25 02:03:14 +01003065/* Send IPA DLCX to inactive lchan */
3066function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01003067 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3068 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01003069}
3070testcase TC_ipa_dlcx_not_active() runs on test_CT {
3071 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3072 f_init(testcasename());
3073 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
3074 vc_conn.done;
3075}
Harald Welte68e495b2018-02-25 00:05:57 +01003076
Harald Weltea3f1df92018-02-25 12:49:55 +01003077/* Send IPA CRCX twice to inactive lchan */
3078function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
3079 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3080 "IPA CRCX ACK");
3081 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
3082 "IPA CRCX NACK");
3083}
3084testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
3085 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3086 f_init(testcasename());
3087 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
3088 vc_conn.done;
3089}
3090
3091/* Regular sequence of CRCX/MDCX/DLCX */
3092function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3093 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3094 "IPA CRCX ACK");
3095 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3096 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3097 var uint7_t rtp_pt2 := f_rnd_int(127);
3098 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3099 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3100 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3101 "IPA MDCX ACK");
3102 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3103 "IPA DLCX ACK");
3104}
3105testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
3106 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3107 f_init(testcasename());
3108 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
3109 vc_conn.done;
3110}
3111
Harald Welte3ae11da2018-02-25 13:36:06 +01003112/* Sequence of CRCX, 2x MDCX, DLCX */
3113function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3114 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3115 "IPA CRCX ACK");
3116 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3117 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3118 var uint7_t rtp_pt2 := f_rnd_int(127);
3119 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3120 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3121 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3122 "IPA MDCX ACK");
3123 /* Second MDCX */
3124 remote_ip := f_rnd_int(c_UINT32_MAX);
3125 remote_port := f_rnd_int(c_UINT16_MAX);
3126 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3127 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3128 "IPA MDCX ACK");
3129 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3130 "IPA DLCX ACK");
3131}
3132testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
3133 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3134 f_init(testcasename());
3135 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
3136 vc_conn.done;
3137}
3138
Harald Welte9912eb52018-02-25 13:30:15 +01003139/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
3140function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
3141 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
3142 "IPA CRCX NACK");
3143}
3144testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
3145 var ConnHdlrPars pars;
3146 var ConnHdlr vc_conn;
3147 f_init(testcasename());
3148
3149 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
3150 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3151 vc_conn.done;
3152
3153 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
3154 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3155 vc_conn.done;
3156}
3157
Harald Weltea3f1df92018-02-25 12:49:55 +01003158
Harald Welte883340c2018-02-28 18:59:29 +01003159/***********************************************************************
3160 * PCU Socket related tests
3161 ***********************************************************************/
3162
Harald Welte07bd2d22019-05-25 11:03:30 +02003163/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003164friend 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 +01003165runs on test_CT {
3166 timer T := 3.0;
3167
3168 /* we don't expect any RTS.req before PDCH are active */
3169 T.start;
3170 alt {
3171 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003172 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01003173 }
3174 [] PCU.receive { repeat; }
3175 [] T.timeout { }
3176 }
3177
3178 /* Send PDCH activate request for known PDCH timeslot */
3179 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
3180
3181 /* we now expect RTS.req for this timeslot (only) */
3182 T.start;
3183 alt {
3184 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
3185 setverdict(pass);
3186 }
3187 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3188 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003189 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01003190 }
3191 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003192 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01003193 }
3194 [] PCU.receive { repeat; }
3195 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003196 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003197 }
3198 [not exp_success] T.timeout {
3199 setverdict(pass);
3200 }
3201 }
3202}
3203
Harald Welte07bd2d22019-05-25 11:03:30 +02003204/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003205friend 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 +01003206runs on test_CT {
3207 timer T := 3.0;
3208
3209 /* Send PDCH activate request for known PDCH timeslot */
3210 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
3211
3212 PCU.clear;
3213 /* we now expect no RTS.req for this timeslot */
3214 T.start;
3215 alt {
3216 [] 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 +02003217 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003218 }
3219 [] PCU.receive { repeat; }
3220 [] T.timeout {
3221 setverdict(pass);
3222 }
3223 }
3224}
3225
Harald Weltead033dc2019-05-25 17:28:16 +02003226friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003227 f_init();
3228 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
3229}
3230
Harald Welte883340c2018-02-28 18:59:29 +01003231/* PDCH activation via PCU socket; check for presence of RTS.req */
3232testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003233 f_init_pcu_test();
3234
Harald Welte883340c2018-02-28 18:59:29 +01003235 f_TC_pcu_act_req(0, 0, 7, true);
3236}
3237
3238/* PDCH activation via PCU socket on non-PDCU timeslot */
3239testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003240 f_init_pcu_test();
3241
Harald Welte883340c2018-02-28 18:59:29 +01003242 f_TC_pcu_act_req(0, 0, 1, false);
3243}
3244
3245/* PDCH activation via PCU socket on wrong BTS */
3246testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003247 f_init_pcu_test();
3248
Harald Welte883340c2018-02-28 18:59:29 +01003249 f_TC_pcu_act_req(23, 0, 7, false);
3250}
3251
3252/* PDCH activation via PCU socket on wrong TRX */
3253testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003254 f_init_pcu_test();
3255
Harald Welte883340c2018-02-28 18:59:29 +01003256 f_TC_pcu_act_req(0, 23, 7, false);
3257}
3258
3259/* PDCH deactivation via PCU socket; check for absence of RTS.req */
3260testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003261 f_init_pcu_test();
3262
Harald Welte883340c2018-02-28 18:59:29 +01003263 /* Activate PDCH */
3264 f_TC_pcu_act_req(0, 0, 7, true);
3265 f_sleep(1.0);
3266 /* and De-Activate again */
3267 f_TC_pcu_deact_req(0, 0, 7);
3268}
3269
3270/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
3271testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003272 f_init_pcu_test();
3273
Harald Welte883340c2018-02-28 18:59:29 +01003274 f_TC_pcu_deact_req(0, 0, 1);
3275}
3276
3277/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
3278testcase TC_pcu_ver_si13() runs on test_CT {
3279 const octetstring si13 := '00010203040506070909'O;
3280 var PCUIF_send_data sd;
3281 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01003282 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003283
3284 /* Set SI13 via RSL */
3285 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01003286
Harald Welte883340c2018-02-28 18:59:29 +01003287 T.start;
3288 alt {
3289 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
3290 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
3291 setverdict(pass);
3292 } else {
3293 repeat;
3294 }
3295 }
3296 [] PCU.receive { repeat; }
3297 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003298 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01003299 }
3300 }
3301}
3302
3303private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
3304
3305/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02003306friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01003307 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
3308runs on test_CT
3309{
3310 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
3311 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
3312}
3313
3314/* 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 +02003315friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
3316 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01003317runs on test_CT
3318{
3319 var PCUIF_send_data sd;
3320
3321 timer T := 3.0;
3322 T.start;
3323 alt {
3324 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3325 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
3326 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
3327 sd.data.u.rts_req.fn, sapi, data);
3328 }
3329 [] PCU.receive { repeat; }
3330 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003331 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01003332 }
3333 }
3334}
3335
3336/* Send DATA.req on invalid BTS */
3337testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003338 var TfiUsfArr tua := f_TfiUsfArrInit();
3339 var octetstring data := '0000'O & f_rnd_octstring(21);
3340
3341 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003342
Harald Welte883340c2018-02-28 18:59:29 +01003343 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003344 f_TfiUsfArrSet(tua, 7, 0);
3345 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3346 f_sleep(1.0);
3347
3348 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003349}
3350
3351/* Send DATA.req on invalid TRX */
3352testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003353 var TfiUsfArr tua := f_TfiUsfArrInit();
3354 var octetstring data := '0000'O & f_rnd_octstring(21);
3355
3356 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003357
Harald Welte883340c2018-02-28 18:59:29 +01003358 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003359 f_TfiUsfArrSet(tua, 7, 0);
3360 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3361 f_sleep(1.0);
3362
3363 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003364}
3365
3366/* Send DATA.req on invalid timeslot */
3367testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003368 var TfiUsfArr tua := f_TfiUsfArrInit();
3369 var octetstring data := '0000'O & f_rnd_octstring(21);
3370
3371 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003372
Harald Welte883340c2018-02-28 18:59:29 +01003373 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003374 f_TfiUsfArrSet(tua, 7, 0);
3375 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3376 f_sleep(1.0);
3377
3378 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003379}
3380
3381/* Send DATA.req on timeslot that hasn't been activated */
3382testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003383 var TfiUsfArr tua := f_TfiUsfArrInit();
3384 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01003385
Harald Welte7162a612019-05-26 12:56:09 +02003386 f_virtphy_common();
3387
3388 f_TfiUsfArrSet(tua, 7, 0);
3389 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3390 f_sleep(1.0);
3391
3392 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003393}
3394
Harald Weltead033dc2019-05-25 17:28:16 +02003395private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02003396 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
3397 boolean wait_rts := true)
3398runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003399 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02003400 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02003401
3402 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02003403 if (wait_rts) {
3404 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
3405 } else {
3406 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
3407 }
Harald Weltead033dc2019-05-25 17:28:16 +02003408
3409 T.start;
3410 alt {
Harald Welte7162a612019-05-26 12:56:09 +02003411 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02003412 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
3413 setverdict(pass);
3414 }
Harald Welte7162a612019-05-26 12:56:09 +02003415 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
3416 setverdict(fail, "Received unexpected ", rx_dl);
3417 }
Harald Weltead033dc2019-05-25 17:28:16 +02003418 [] L1CTL.receive {
3419 repeat;
3420 }
Harald Welte7162a612019-05-26 12:56:09 +02003421 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02003422 setverdict(fail, "Timeout waiting for ", data);
3423 }
Harald Welte7162a612019-05-26 12:56:09 +02003424 [not expect_data] T.timeout {
3425 setverdict(pass);
3426 }
Harald Weltead033dc2019-05-25 17:28:16 +02003427 }
3428}
3429
3430private function f_disable_dynamic_ts() runs on test_CT
3431{
3432 f_init_vty_bsc();
3433 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
3434 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
3435 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
3436 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01003437 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02003438}
3439
3440private function f_virtphy_common() runs on test_CT {
3441 f_disable_dynamic_ts();
3442 f_init_l1ctl();
3443 f_l1_tune(L1CTL);
3444}
3445
3446testcase TC_pcu_data_req_pdtch() runs on test_CT {
3447 var TfiUsfArr tua := f_TfiUsfArrInit();
3448 var octetstring data := '0000'O & f_rnd_octstring(21);
3449
3450 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003451
Harald Welte883340c2018-02-28 18:59:29 +01003452 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003453 f_TfiUsfArrSet(tua, 7, 0);
3454 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3455 f_sleep(1.0);
3456
3457 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01003458}
3459
3460testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003461 var TfiUsfArr tua := f_TfiUsfArrInit();
3462 var octetstring data := '0000'O & f_rnd_octstring(21);
3463
3464 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003465
Harald Welte883340c2018-02-28 18:59:29 +01003466 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003467 f_TfiUsfArrSet(tua, 7, 0);
3468 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3469 f_sleep(1.0);
3470
3471 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01003472}
3473
3474/* Send AGCH from PCU; check it appears on Um side */
3475testcase TC_pcu_data_req_agch() runs on test_CT {
3476 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01003477 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003478 f_init_l1ctl();
3479 f_l1_tune(L1CTL);
3480
3481 f_TC_pcu_act_req(0, 0, 7, true);
3482 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
3483
3484 T.start;
3485 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003486 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01003487 setverdict(pass);
3488 }
3489 [] L1CTL.receive { repeat; }
3490 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003491 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003492 }
3493 }
3494}
3495
Harald Welte928622b2019-05-26 13:22:59 +02003496/* Send AGCH from PCU; check it appears on Um side */
3497testcase TC_pcu_data_req_pch() runs on test_CT {
3498 timer T := 3.0;
3499 f_init_pcu_test();
3500 f_init_l1ctl();
3501 f_l1_tune(L1CTL);
3502
3503 f_TC_pcu_act_req(0, 0, 7, true);
3504 /* three characters prefix: last 3 digits of IMSI as ASCII */
3505 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
3506
3507 T.start;
3508 alt {
3509 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
3510 setverdict(pass);
3511 }
3512 [] L1CTL.receive { repeat; }
3513 [] T.timeout {
3514 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
3515 }
3516 }
3517}
3518
Harald Welte883340c2018-02-28 18:59:29 +01003519/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
3520testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
3521 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01003522 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003523 f_init_l1ctl();
3524 f_l1_tune(L1CTL);
3525
3526 /* append 3 last imsi digits so BTS can compute pagng group */
3527 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
3528
3529 timer T := 0.5;
3530 T.start;
3531 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003532 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01003533 /* TODO: verify paging group */
3534 setverdict(pass);
3535 }
3536 [] L1CTL.receive { repeat; }
3537 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003538 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003539 }
3540 }
3541}
3542
3543/* Send RACH from Um side, expect it to show up on PCU socket */
3544testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003545 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003546 f_init_l1ctl();
3547 f_l1_tune(L1CTL);
3548
3549 var GsmFrameNumber fn_last := 0;
3550 for (var integer i := 0; i < 1000; i := i+1) {
3551 var OCT1 ra := f_rnd_ra_ps();
3552 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
3553 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003554 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01003555 }
3556 fn_last := fn;
3557
3558 timer T := 2.0;
3559 T.start;
3560 alt {
3561 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
3562 T.stop;
3563 }
3564 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003565 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003566 }
3567 [] PCU.receive { repeat; }
3568 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003569 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003570 }
3571 }
3572 }
3573 setverdict(pass);
3574}
3575
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07003576/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
3577 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
3578testcase TC_pcu_ext_rach_content() runs on test_CT {
3579 var template PCUIF_Message pcu_rach_ind;
3580 var GsmFrameNumber fn_last := 0;
3581 var L1ctlRachSynchSeq synch_seq;
3582 var PCUIF_BurstType pcu_bt;
3583 var GsmFrameNumber fn;
3584 var BIT11 ra11;
3585
3586 f_init_pcu_test();
3587 f_init_l1ctl();
3588 f_l1_tune(L1CTL);
3589
3590 for (var integer i := 0; i < 1000; i := i+1) {
3591 /* We need to test both TS1 & TS2 */
3592 if (i rem 2 == 0) {
3593 synch_seq := RACH_SYNCH_SEQ_TS1;
3594 pcu_bt := BURST_TYPE_1;
3595 } else {
3596 synch_seq := RACH_SYNCH_SEQ_TS2;
3597 pcu_bt := BURST_TYPE_2;
3598 }
3599
3600 ra11 := f_rnd_ra11_ps();
3601 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
3602 if (fn == fn_last) {
3603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3604 "Two RACH in same FN?!?");
3605 }
3606 fn_last := fn;
3607
3608 /* Compose the expected message */
3609 pcu_rach_ind := tr_PCUIF_RACH_IND(
3610 bts_nr := 0,
3611 ra := bit2int(ra11),
3612 is_11bit := 1,
3613 burst_type := pcu_bt,
3614 fn := fn);
3615
3616 timer T := 2.0;
3617 T.start;
3618 alt {
3619 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
3620 T.stop;
3621 }
3622 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
3623 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
3624 }
3625 [] PCU.receive { repeat; }
3626 [] T.timeout {
3627 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
3628 }
3629 }
3630 }
3631 setverdict(pass);
3632}
3633
Harald Welte883340c2018-02-28 18:59:29 +01003634private function f_pad_oct(octetstring str, integer len, OCT1 pad) return octetstring {
3635 var integer strlen := lengthof(str);
3636 for (var integer i := 0; i < len-strlen; i := i+1) {
3637 str := str & pad;
3638 }
3639 return str;
3640}
3641
3642/* Send PAGING via RSL, expect it to shw up on PCU socket */
3643testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003644 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003645
3646 for (var integer i := 0; i < 100; i := i+1) {
3647 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
3648 timer T := 3.0;
3649 if (i < 50) {
3650 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
3651 } else {
3652 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
3653 }
3654 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
3655 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
3656 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
3657
3658 /* Send RSL PAGING COMMAND */
3659 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
3660 T.start;
3661 alt {
3662 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
3663 }
3664 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003665 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003666 }
3667 [] PCU.receive { repeat; }
3668 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003669 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003670 }
3671 }
3672 }
3673 setverdict(pass);
3674}
3675
Harald Welted66c9b82019-05-25 09:03:15 +02003676/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
3677testcase TC_pcu_time_ind() runs on test_CT {
3678 var PCUIF_send_data pcu_sd;
3679 var integer num_time_ind := 0;
3680 var integer first_fn, last_fn;
3681 var float test_duration := 5.0;
3682 timer T;
3683
3684 f_init_pcu_test();
3685 f_TC_pcu_act_req(0, 0, 7, true);
3686
3687 PCU.clear;
3688 T.start(test_duration);
3689 alt {
3690 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
3691 num_time_ind := num_time_ind + 1;
3692 if (not isbound(first_fn)) {
3693 first_fn := pcu_sd.data.u.time_ind.fn;
3694 }
3695 last_fn := pcu_sd.data.u.time_ind.fn;
3696 repeat;
3697 }
3698 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
3699 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
3700 repeat;
3701 }
3702 [] PCU.receive {
3703 repeat;
3704 }
3705 [] T.timeout {}
3706 }
3707 var integer fn_expired := last_fn - first_fn;
3708 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
3709
3710 /* verify the number of frames expired matches our expectation */
3711 const float c_GSM_FN_DURATION_MS := 4.61538;
3712 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
3713 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 10);
3714 if (not match(fn_expired, t_fn_expected)) {
3715 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
3716 }
3717
3718 /* There are three TIME.ind in every fn MOD 13 */
3719 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
3720 /* Add some tolerance */
3721 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
3722 if (not match(num_time_ind, t_time_ind_exp)) {
3723 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
3724 }
3725
3726 setverdict(pass);
3727}
3728
Harald Welte4832c862019-05-25 14:57:18 +02003729/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
3730testcase TC_pcu_rts_req() runs on test_CT {
3731 var PCUIF_send_data pcu_sd;
3732 var integer first_fn, last_fn;
3733 var integer num_rts_pdtch := 0;
3734 var integer num_rts_ptcch := 0;
3735 var float test_duration := 5.0;
3736 timer T;
3737
3738 f_init_pcu_test();
3739 f_TC_pcu_act_req(0, 0, 7, true);
3740
3741 PCU.clear;
3742 T.start(test_duration);
3743 alt {
3744 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
3745 -> value pcu_sd {
3746 num_rts_pdtch := num_rts_pdtch + 1;
3747 if (not isbound(first_fn)) {
3748 first_fn := pcu_sd.data.u.rts_req.fn;
3749 }
3750 last_fn := pcu_sd.data.u.rts_req.fn;
3751 repeat;
3752 }
3753 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
3754 -> value pcu_sd {
3755 num_rts_ptcch := num_rts_ptcch + 1;
3756 if (not isbound(first_fn)) {
3757 first_fn := pcu_sd.data.u.rts_req.fn;
3758 }
3759 last_fn := pcu_sd.data.u.rts_req.fn;
3760 repeat;
3761 }
3762 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
3763 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
3764 repeat;
3765 }
3766 [] PCU.receive {
3767 repeat;
3768 }
3769 [] T.timeout {}
3770 }
3771 var integer fn_expired := last_fn - first_fn;
3772 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
3773 ", num_rts_ptcch=", num_rts_ptcch);
3774
3775 /* verify the number of frames expired matches our expectation */
3776 const float c_GSM_FN_DURATION_MS := 4.61538;
3777 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
3778 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 10);
3779 if (not match(fn_expired, t_fn_expected)) {
3780 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
3781 }
3782
3783 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
3784 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
3785 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
3786 if (not match(num_rts_ptcch, t_ptcch_exp)) {
3787 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
3788 t_ptcch_exp);
3789 }
3790
3791 /* We have 12 PDTCH blocks every 52-multiframe */
3792 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
3793 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
3794 if (not match(num_rts_pdtch, t_pdtch_exp)) {
3795 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
3796 t_pdtch_exp);
3797 }
3798
3799 setverdict(pass);
3800}
3801
Harald Welte07bd2d22019-05-25 11:03:30 +02003802/* test for generating Abis side OML ALERT from the PCU */
3803testcase TC_pcu_oml_alert() runs on test_CT {
3804 var PCUIF_send_data pcu_sd;
3805 var integer num_time_ind := 0;
3806 var integer first_fn, last_fn;
3807 var float test_duration := 5.0;
3808 timer T;
3809
3810 f_init_pcu_test();
3811 f_TC_pcu_act_req(0, 0, 7, true);
3812
3813 /* re-connect CTRL port from BTS to BSC */
3814 f_ipa_ctrl_stop();
3815 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
3816
3817 /* Send that OML Alert */
3818 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
3819
3820 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
3821 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
3822 setverdict(pass);
3823}
3824
Harald Welteeaa9a862019-05-26 23:01:08 +02003825template (value) PDU_ML3_MS_NW ts_RRM_GprsSuspReq(template (value) OCT4 tlli,
3826 template (value) RoutingAreaIdentificationV rai,
3827 template (value) OCT1 cause) := {
3828 discriminator := '0000'B, /* overwritten */
3829 tiOrSkip := {
3830 skipIndicator := '0000'B
3831 },
3832 msgs := {
3833 rrm := {
3834 gPRS_suspensionRequest := {
3835 messageType := '00110100'B,
3836 tLLI := tlli,
3837 routingAreaIdentification := rai,
3838 suspensionCause := cause,
3839 service_Support := omit
3840 }
3841 }
3842 }
3843}
3844
3845/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
3846private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
3847 var PCUIF_Message first_info;
3848 var integer pcu_conn_id := -1;
3849 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3850 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
3851 var OCT4 tlli := '01020304'O;
3852 var OCT1 cause := '23'O;
3853 timer T := 5.0;
3854
3855 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3856
3857 f_l1_tune(L1CTL);
3858 RSL.clear;
3859
3860 f_est_dchan();
3861 L1CTL.clear;
3862
3863 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
3864
3865 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
3866 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
3867 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
3868
3869 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
3870 T.start;
3871 alt {
3872 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
3873 setverdict(pass);
3874 }
3875 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
3876 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
3877 }
3878 [] PCU.receive {
3879 repeat;
3880 }
3881 [] T.timeout {
3882 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
3883 }
3884 }
3885}
3886testcase TC_pcu_rr_suspend() runs on test_CT {
3887 var ConnHdlrPars pars;
3888 var ConnHdlr vc_conn;
3889
3890 f_init();
3891
3892 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
3893 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
3894 vc_conn.done;
3895}
Harald Welte07bd2d22019-05-25 11:03:30 +02003896
Harald Welted66c9b82019-05-25 09:03:15 +02003897
Harald Welte3d04ae62018-04-04 20:29:05 +02003898/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02003899 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02003900 ***********************************************************************/
3901
3902private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3903runs on ConnHdlr {
3904 var PCUIF_send_data sd;
3905 /* Expect BTS to immediately acknowledge activation as PDCH */
3906 PCU.clear;
3907 f_rsl_chan_act(g_pars.chan_mode);
3908 /* expect INFO_IND on PCU interface listing TS as PDCH */
3909 alt {
3910 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3911 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 +02003912 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02003913 }
3914 }
3915 [] PCU.receive { repeat; }
3916 }
3917 /* try to activate this PDCH from the PCU point of view */
3918 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3919 /* FIXME: is there a response? */
3920}
3921
3922private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3923runs on ConnHdlr {
3924 var PCUIF_send_data sd;
3925 /* Send RSL CHAN REL (deactivate) */
3926 PCU.clear;
3927 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
3928 /* expect BTS to ask PCU to deactivate the channel */
3929 alt {
3930 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3931 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 +02003932 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02003933 }
3934 }
3935 [] PCU.receive { repeat; }
3936 }
3937 /* Emulate PCU asking BTS to deactivate PDCH */
3938 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3939 alt {
3940 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
3941 setverdict(pass);
3942 }
3943 [] RSL.receive { repeat; }
3944 }
3945}
3946
3947/* Activate Osmocom-style dynamic PDCH from BSC side */
3948function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
3949 var PCUIF_Message first_info;
3950 var integer ts_nr := g_chan_nr.tn;
3951 var integer trx_nr := 0;
3952 var integer bts_nr := 0;
3953 var integer pcu_conn_id := -1;
3954
3955 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3956
3957 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3958 f_sleep(3.0);
3959 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3960 setverdict(pass);
3961}
3962testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
3963 var ConnHdlrPars pars;
3964 var ConnHdlr vc_conn;
3965 f_init(testcasename());
3966
3967 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3968 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
3969 vc_conn.done;
3970}
3971
3972/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
3973function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
3974 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02003975 var integer pcu_conn_id := -1;
3976
3977 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3978
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02003979 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
3980 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
3981 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02003982 setverdict(pass);
3983}
3984testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
3985 var ConnHdlrPars pars;
3986 var ConnHdlr vc_conn;
3987 f_init(testcasename());
3988
3989 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3990 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
3991 vc_conn.done;
3992}
3993
3994/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
3995function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
3996 var PCUIF_Message first_info;
3997 var integer ts_nr := g_chan_nr.tn;
3998 var integer trx_nr := 0;
3999 var integer bts_nr := 0;
4000 var integer pcu_conn_id := -1;
4001
4002 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4003
4004 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02004005 /* Send a second Chan Activ and expect it to be NACKed */
4006 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
4007 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02004008 setverdict(pass);
4009}
4010testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
4011 var ConnHdlrPars pars;
4012 var ConnHdlr vc_conn;
4013 f_init(testcasename());
4014
4015 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4016 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
4017 vc_conn.done;
4018}
4019
4020/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
4021function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
4022 var PCUIF_Message first_info;
4023 var integer ts_nr := g_chan_nr.tn;
4024 var integer trx_nr := 0;
4025 var integer bts_nr := 0;
4026 var integer pcu_conn_id := -1;
4027 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
4028
4029 /* register for the TCH/F channel number */
4030 f_rslem_register(0, chan_nr);
4031
4032 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4033
4034 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
4035 "RSL CHAN ACT");
4036 setverdict(pass);
4037}
4038testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
4039 var ConnHdlrPars pars;
4040 var ConnHdlr vc_conn;
4041 f_init(testcasename());
4042
4043 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4044 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
4045 vc_conn.done;
4046}
4047
4048/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
4049function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
4050 var PCUIF_Message first_info;
4051 var integer ts_nr := g_chan_nr.tn;
4052 var integer trx_nr := 0;
4053 var integer bts_nr := 0;
4054 var integer pcu_conn_id := -1;
4055 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
4056 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
4057
4058 /* register for the TCH/H channel numbers */
4059 f_rslem_register(0, chan_nr[0]);
4060 f_rslem_register(0, chan_nr[1]);
4061
4062 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4063
4064 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
4065 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
4066 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
4067 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
4068 setverdict(pass);
4069}
4070testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
4071 var ConnHdlrPars pars;
4072 var ConnHdlr vc_conn;
4073 f_init(testcasename());
4074
4075 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4076 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
4077 vc_conn.done;
4078}
4079
Harald Welte9bbbfb52018-04-05 09:33:19 +02004080/***********************************************************************
4081 * IPA Style Dynamic Timeslot Support
4082 ***********************************************************************/
4083
4084private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4085runs on ConnHdlr {
4086 var PCUIF_send_data sd;
4087 /* Expect BTS to immediately acknowledge activation as PDCH */
4088 PCU.clear;
4089 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
4090 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004091 timer T_wait := 2.0;
4092 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004093 alt {
4094 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4095 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 +01004096 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
4097 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
4098 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004099 }
4100 }
4101 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004102 [] T_wait.timeout {
4103 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4104 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
4105 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02004106 }
4107 /* try to activate this PDCH from the PCU point of view */
4108 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4109 /* FIXME: is there a response? */
4110
4111 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
4112}
4113
4114private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4115runs on ConnHdlr {
4116 var PCUIF_send_data sd;
4117 /* Send RSL CHAN REL (deactivate) */
4118 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
4119 PCU.clear;
4120 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004121 timer T_wait := 2.0;
4122 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004123 alt {
4124 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4125 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 +01004126 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
4127 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
4128 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004129 }
4130 }
4131 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004132 [] T_wait.timeout {
4133 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4134 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
4135 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02004136 }
4137 /* Emulate PCU asking BTS to deactivate PDCH */
4138 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4139 alt {
4140 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
4141 setverdict(pass);
4142 }
4143 [] RSL.receive { repeat; }
4144 }
4145}
4146
4147/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
4148function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
4149 var PCUIF_Message first_info;
4150 var integer ts_nr := g_chan_nr.tn;
4151 var integer trx_nr := 0;
4152 var integer bts_nr := 0;
4153 var integer pcu_conn_id := -1;
4154
4155 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4156
4157 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4158 f_sleep(3.0);
4159 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4160
4161 setverdict(pass);
4162
4163}
4164testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
4165 var ConnHdlrPars pars;
4166 var ConnHdlr vc_conn;
4167 f_init();
4168
4169 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4170 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
4171 vc_conn.done;
4172}
4173
4174/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
4175function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
4176 var PCUIF_Message first_info;
4177 var integer ts_nr := g_chan_nr.tn;
4178 var integer trx_nr := 0;
4179 var integer bts_nr := 0;
4180 var integer pcu_conn_id := -1;
4181
4182 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4183
4184 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4185 "RSL CHAN ACT");
4186 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4187 "RF CHAN REL", true);
4188 setverdict(pass);
4189}
4190testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
4191 var ConnHdlrPars pars;
4192 var ConnHdlr vc_conn;
4193 f_init(testcasename());
4194
4195 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4196 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
4197 vc_conn.done;
4198}
4199
4200/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
4201function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
4202 var PCUIF_Message first_info;
4203 var integer ts_nr := g_chan_nr.tn;
4204 var integer trx_nr := 0;
4205 var integer bts_nr := 0;
4206 var integer pcu_conn_id := -1;
4207
4208 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4209
4210 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4211 "RSL CHAN ACT");
4212
4213 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
4214 alt {
4215 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
4216 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004217 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02004218 }
4219 [] RSL.receive { repeat; }
4220 }
4221
4222 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4223 "RF CHAN REL", true);
4224 setverdict(pass);
4225}
4226testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
4227 var ConnHdlrPars pars;
4228 var ConnHdlr vc_conn;
4229 f_init(testcasename());
4230
4231 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4232 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
4233 vc_conn.done;
4234}
4235
4236/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
4237function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
4238 var PCUIF_Message first_info;
4239 var integer ts_nr := g_chan_nr.tn;
4240 var integer trx_nr := 0;
4241 var integer bts_nr := 0;
4242 var integer pcu_conn_id := -1;
4243
4244 /* register for the TCH/F channel number */
4245 f_rslem_register(0, g_chan_nr);
4246
4247 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4248
4249 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4250
4251 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
4252 "RSL CHAN ACT");
4253
4254 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4255
4256 setverdict(pass);
4257}
4258testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
4259 var ConnHdlrPars pars;
4260 var ConnHdlr vc_conn;
4261 f_init(testcasename());
4262
4263 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4264 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
4265 vc_conn.done;
4266}
4267
4268
Harald Welte0472ab42018-03-12 15:02:26 +01004269/***********************************************************************
4270 * LAPDm / RLL related
4271 ***********************************************************************/
4272
4273private function f_tx_lapdm(template (value) LapdmFrame l,
4274 template (value) RslLinkId link_id) runs on ConnHdlr {
4275 var octetstring l2 := enc_LapdmFrame(valueof(l));
4276 if (valueof(link_id.c) == SACCH) {
4277 /* prepend dummy L1 header */
Pau Espin Pedrola0fb42a2018-10-10 15:56:39 +02004278 var L1ctlDataReq l1hl2 := {
4279 l1header := valueof(ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta)),
4280 l2_payload := f_pad_oct(l2, 21, '2B'O)
4281 }
4282 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, link_id, l1hl2));
4283 } else {
4284 /* If required, pad L2 frame with constant 0x2b filling */
4285 l2 := f_pad_oct(l2, 23, '2B'O);
4286
4287 log("encoding ", l, " to ", l2);
4288 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, link_id, l2));
Harald Welte0472ab42018-03-12 15:02:26 +01004289 }
Harald Welte0472ab42018-03-12 15:02:26 +01004290}
4291
4292type record RllTestCase {
4293 uint3_t sapi,
4294 RslLinkId link_id,
4295 octetstring l3,
4296 boolean exp
4297}
4298type record of RllTestCase RllTestCases;
4299template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
4300 sapi := sapi,
4301 link_id := id,
4302 l3 := l3,
4303 exp := exp
4304}
4305
4306/* execute the same callback function with a set of different parameters (tcs) on a
4307 * variety of logical channels */
4308private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
4309 var ConnHdlrPars pars;
4310 var ConnHdlr vc_conn;
4311 f_init(testcasename());
4312
4313 /* test on each of the channels we have */
4314 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
4315 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
4316
4317 /* test each of the test cases on the current channel */
4318 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
4319 pars.spec.rll := tcs[j];
4320 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
4321 vc_conn := f_start_handler(fn, pars);
4322 vc_conn.done;
4323 }
4324 }
4325
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004326 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01004327}
4328
4329/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
4330private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
4331 var RllTestCase tc := g_pars.spec.rll;
4332 timer T := 3.0;
4333
4334 f_l1_tune(L1CTL);
4335 RSL.clear;
4336
4337 /* activate the logical channel */
4338 f_est_dchan();
4339 L1CTL.clear;
4340
4341 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
4342 T.start;
4343 alt {
4344 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
4345 if (tc.exp) {
4346 setverdict(pass);
4347 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004348 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01004349 }
4350 }
4351 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
4352 if (tc.exp) {
4353 setverdict(pass);
4354 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004355 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01004356 }
4357 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07004358 /* We also expect to receive the measurements */
4359 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01004360 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004361 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01004362 }
4363 [not tc.exp] T.timeout {
4364 setverdict(pass);
4365 }
4366 }
4367
4368 f_rsl_chan_deact();
4369 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4370 f_rslem_unregister(0, g_chan_nr);
4371}
4372testcase TC_rll_est_ind() runs on test_CT {
4373 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02004374 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01004375 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02004376 /* normal SAPI0 establishment */
4377 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01004378 /* SAPI 3 doesn't support contention resolution */
4379 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
4380 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
4381 /* normal SAPI3 establishment on main DCCH */
4382 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
4383 /* normal SAPI3 establishment on SACCH */
4384 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4385 };
4386 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
4387}
4388
4389/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
4390private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
4391 var RllTestCase tc := g_pars.spec.rll;
4392 var L1ctlDlMessage dl;
4393 timer T := 3.0;
4394
4395 f_l1_tune(L1CTL);
4396 RSL.clear;
4397
4398 /* activate the logical channel */
4399 f_est_dchan();
4400 L1CTL.clear;
4401
4402 /* Send a RSL EST REQ for SAPI3 on main DCCH */
4403 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
4404 T.start;
4405 alt {
4406 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4407 var LapdmFrame lapdm;
4408 var octetstring l2 := dl.payload.data_ind.payload;
4409 if (dl.dl_info.link_id.c == SACCH) {
4410 /* remove L1 header */
4411 l2 := substr(l2, 2, lengthof(l2)-2);
4412 }
4413 lapdm.ab := dec_LapdmFrameAB(l2);
4414 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
4415 setverdict(pass);
4416 } else {
4417 repeat;
4418 }
4419 }
4420 [] L1CTL.receive { repeat; }
4421 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004422 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01004423 }
4424 }
4425
4426 f_rsl_chan_deact();
4427 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4428 f_rslem_unregister(0, g_chan_nr);
4429}
4430testcase TC_rll_est_req_DCCH_3() runs on test_CT {
4431 var RllTestCases tcs := {
4432 /* normal SAPI3 establishment on main DCCH */
4433 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
4434 };
4435 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
4436}
4437testcase TC_rll_est_req_ACCH_3() runs on test_CT {
4438 var RllTestCases tcs := {
4439 /* normal SAPI3 establishment on SACCH */
4440 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4441 }
4442 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
4443}
4444
4445/* altstep to receive a LAPDm frame matching the given template */
4446private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
4447 var L1ctlDlMessage dl;
4448 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4449 var LapdmFrame lapdm;
4450 var octetstring l2 := dl.payload.data_ind.payload;
4451 if (dl.dl_info.link_id.c == SACCH) {
4452 /* remove L1 header */
4453 l2 := substr(l2, 2, lengthof(l2)-2);
4454 }
4455 if (ischosen(exp.ab)) {
4456 lapdm.ab := dec_LapdmFrameAB(l2);
4457 } else if (ischosen(exp.b4)) {
4458 lapdm.b4 := dec_LapdmFrameB4(l2);
4459 } else if (ischosen(exp.bbis)) {
4460 lapdm.bbis := dec_LapdmFrameBbis(l2);
4461 }
4462 log("Rx LAPDm ", lapdm);
4463 if (match(lapdm, exp)) {
4464 setverdict(pass);
4465 } else {
4466 repeat;
4467 }
4468 }
4469 [] L1CTL.receive { repeat; }
4470}
4471private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
4472 timer T := t;
4473 T.start;
4474 alt {
4475 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004476 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01004477 }
4478 [] as_l1_exp_lapdm(exp);
4479 }
4480}
4481
4482/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
4483private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
4484 /* send SABM from MS -> BTS */
4485 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
4486 /* expect RLL EST IND on Abis */
4487 alt {
4488 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
4489 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
4490 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004491 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01004492 }
4493 [] RSL.receive { repeat; }
4494 }
4495 /* expect UA from BTS -> MS */
4496 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
4497}
4498
4499/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
4500private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
4501 var RllTestCase tc := g_pars.spec.rll;
4502
4503 f_l1_tune(L1CTL);
4504 RSL.clear;
4505
4506 /* activate the logical channel */
4507 f_est_dchan();
4508 L1CTL.clear;
4509
4510 /* first establish the link-layer */
4511 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
4512
4513 /* then send the DISC */
4514 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
4515 /* ... and expect the REL IND on the RSL side */
4516 alt {
4517 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
4518 setverdict(pass);
4519 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07004520 /* We also expect to receive the measurements */
4521 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01004522 }
4523
4524 /* release the channel */
4525 f_rsl_chan_deact();
4526 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4527 f_rslem_unregister(0, g_chan_nr);
4528}
4529testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
4530 var RllTestCases tcs := {
4531 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
4532 };
4533 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4534}
4535
4536testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
4537 var RllTestCases tcs := {
4538 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
4539 };
4540 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4541}
4542testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
4543 var RllTestCases tcs := {
4544 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
4545 };
4546 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4547}
4548testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
4549 var RllTestCases tcs := {
4550 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4551 };
4552 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4553}
4554
4555/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
4556private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
4557 var RllTestCase tc := g_pars.spec.rll;
4558 f_l1_tune(L1CTL);
4559 RSL.clear;
4560
4561 /* activate the logical channel */
4562 f_est_dchan();
4563 L1CTL.clear;
4564
4565 /* first establish the link-layer */
4566 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
4567
4568 /* then send the REL REQ via RSL */
4569 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
4570 /* ... and expect the DISC on the Um side */
4571 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02004572 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01004573 /* FIXME: send a UA in resposne to the DISC */
4574 }
4575 }
4576
4577 /* release the channel */
4578 f_rsl_chan_deact();
4579 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4580 f_rslem_unregister(0, g_chan_nr);
4581}
4582testcase TC_rll_rel_req() runs on test_CT {
4583 var RllTestCases tcs := {
4584 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
4585 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
4586 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
4587 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4588 };
4589 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
4590}
4591
4592/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
4593testcase TC_rll_data_req() runs on test_CT {
4594}
4595
4596/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
4597testcase TC_rll_data_ind() runs on test_CT {
4598}
4599
4600/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
4601private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
4602 var RllTestCase tc := g_pars.spec.rll;
4603
4604 f_l1_tune(L1CTL);
4605 RSL.clear;
4606
4607 f_est_dchan();
4608 L1CTL.clear;
4609
4610 /* Send UNITDATA REQ on RSL side */
4611 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
4612 /* Expect it to arrive on the other side */
4613 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02004614 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01004615 } else {
Harald Weltee613f962018-04-18 22:38:16 +02004616 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01004617 }
4618
4619 /* release the channel */
4620 f_rsl_chan_deact();
4621 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4622 f_rslem_unregister(0, g_chan_nr);
4623}
4624testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
4625 var octetstring l3 := f_rnd_octstring(15);
4626 var RllTestCases tcs := {
4627 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
4628 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
4629 };
4630 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
4631}
4632testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
4633 var octetstring l3 := f_rnd_octstring(19);
4634 var RllTestCases tcs := {
4635 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
4636 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
4637 };
4638 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
4639}
4640
4641/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
4642private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
4643 var RllTestCase tc := g_pars.spec.rll;
4644
4645 f_l1_tune(L1CTL);
4646 RSL.clear;
4647
4648 f_est_dchan();
4649 L1CTL.clear;
4650
4651 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02004652 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01004653 /* Expdct RLL UNITDATA IND on RSL side */
4654 alt {
4655 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
4656 setverdict(pass);
4657 }
4658 [] RSL.receive { repeat; }
4659 }
4660
4661 /* release the channel */
4662 f_rsl_chan_deact();
4663 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4664 f_rslem_unregister(0, g_chan_nr);
4665}
4666testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02004667 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01004668 var RllTestCases tcs := {
4669 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
4670 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
4671 };
4672 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
4673}
4674testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
4675 var octetstring l3 := f_rnd_octstring(18);
4676 var RllTestCases tcs := {
4677 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
4678 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
4679 };
4680 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
4681}
4682
Harald Weltee613f962018-04-18 22:38:16 +02004683/***********************************************************************
4684 * Encryption Related
4685 ***********************************************************************/
4686
4687/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
4688function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
4689 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
4690 if (link_id.c == SACCH) {
4691 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
4692 } else {
4693 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
4694 }
4695}
4696
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07004697/* Expect (or not expect) other kinds of messages */
4698private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
4699 [exp_any] RSL.receive { repeat; }
4700 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004701 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07004702 }
4703}
4704
Harald Weltee613f962018-04-18 22:38:16 +02004705/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07004706private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07004707 RslLinkId link_id,
4708 octetstring l3,
4709 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07004710 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07004711) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02004712 timer T := 3.0;
4713 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
4714 T.start;
4715 /* Expect RLL UNITDATA IND on RSL side */
4716 alt {
4717 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
4718 setverdict(pass);
4719 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07004720 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07004721 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02004722 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004723 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02004724 }
Harald Weltee613f962018-04-18 22:38:16 +02004725 }
4726}
4727
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004728/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
4729private function f_data_mo(
4730 RslLinkId link_id,
4731 boolean p, uint3_t nr, uint3_t ns,
4732 octetstring l3,
4733 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07004734 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004735) runs on ConnHdlr {
4736 timer T := 3.0;
4737 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
4738 T.start;
4739 /* Expect RLL DATA IND on RSL side */
4740 alt {
4741 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
4742 setverdict(pass);
4743 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07004744 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004745 [] as_rsl_any_ind(exp_any);
4746 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004747 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004748 }
4749 }
4750}
4751
Harald Weltee613f962018-04-18 22:38:16 +02004752/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
4753function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
4754 f_l1_tune(L1CTL);
4755 f_est_dchan(true);
4756
4757 /* now we actually need to transmit some data both ways to check if the encryption works */
4758 var L1ctlDlMessage dl;
4759
Stefan Sperling603d98e2018-07-25 16:47:28 +02004760 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02004761 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
4762
4763 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
4764 f_unitdata_mt(link_id, l3);
4765
4766 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
4767 f_unitdata_mo(link_id, l3);
4768
4769 /* release the channel */
4770 f_rsl_chan_deact();
4771 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4772 f_rslem_unregister(0, g_chan_nr);
4773}
4774testcase TC_chan_act_a51() runs on test_CT {
4775 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4776 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
4777 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
4778}
4779testcase TC_chan_act_a52() runs on test_CT {
4780 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4781 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
4782 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
4783}
4784testcase TC_chan_act_a53() runs on test_CT {
4785 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4786 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
4787 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
4788}
4789
4790
4791/* Test unencrypted channel activation followed by explicit ENCR CMD later */
4792function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
4793 /* L3 payload doesn't matter, as it is passed transparently */
4794 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
4795 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
4796 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
4797
4798 f_l1_tune(L1CTL);
4799
4800 /* first establish a dedicated channel in the clear */
4801 f_est_dchan(false);
4802
4803 /* Establish ABM */
4804 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
4805
4806 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
4807 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
4808 /* expect the L3 to arrive still unencrypted on the MS side */
4809 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
4810
4811 /* configure L1 to apply ciphering */
4812 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
4813 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
4814
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004815 /* send first ciphered I-frame in response and expect it on RSL */
4816 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02004817
4818 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
4819 * and hence enable encryption also on the downlink */
4820
4821 /* expect bi-directional communication work in encrypted mode */
4822 f_unitdata_mo(link_id, f_rnd_octstring(15));
4823 f_unitdata_mt(link_id, f_rnd_octstring(15));
4824
4825 /* release the channel */
4826 f_rsl_chan_deact();
4827 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4828 f_rslem_unregister(0, g_chan_nr);
4829}
4830testcase TC_encr_cmd_a51() runs on test_CT {
4831 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4832 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
4833 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
4834}
4835testcase TC_encr_cmd_a52() runs on test_CT {
4836 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4837 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
4838 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
4839}
4840testcase TC_encr_cmd_a53() runs on test_CT {
4841 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4842 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
4843 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
4844}
4845
4846private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
4847 var LapdmFrame lf;
4848 var octetstring reenc;
4849
4850 /* decode the LAPDm frame */
4851 if (ischosen(exp_match.ab)) {
4852 lf.ab := dec_LapdmFrameAB(enc);
4853 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004854 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02004855 }
4856
4857 /* check if decoder result matches expectation */
4858 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004859 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02004860 } else {
4861 log(name, ": matched");
4862 setverdict(pass);
4863 }
4864
4865 /* test if re-encoded frame equals original input */
4866 reenc := enc_LapdmFrame(lf);
4867 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004868 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02004869 } else {
4870 setverdict(pass);
4871 }
4872}
4873
4874testcase TC_lapdm_selftest() runs on test_CT {
4875 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
4876 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
4877 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
4878 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
4879 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
4880 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
4881 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
4882}
4883
Stefan Sperling4880be42018-08-07 18:12:59 +02004884/***********************************************************************
4885 * DTX Related (see GSM 05.08, section 8.3)
4886 ***********************************************************************/
4887
4888/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
4889function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
4890 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
4891 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
4892 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
4893 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
4894}
4895function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
4896 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
4897 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
4898}
4899function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
4900 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
4901 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
4902 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
4903 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
4904}
4905function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
4906 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
4907 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
4908 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
4909 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
4910 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
4911 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
4912 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
4913 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
4914}
4915
4916function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
4917 var L1ctlDlMessage dl;
4918 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
4919 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
4920 var GsmFrameNumber first_fn;
4921 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004922 var integer nfill_frames_sacch := 0;
4923 var integer nfill_frames_nonsacch := 0;
4924 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02004925 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
4926 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004927 const integer frame_dtx_tchf_mod := 104;
4928 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
4929 * which operates in terms of blocks rather than frames. */
4930 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
4931 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02004932 timer T := 5.0;
4933
4934 f_l1_tune(L1CTL);
4935 RSL.clear;
4936 L1CTL.clear;
4937
4938 /* activate TCHF signalling channel */
4939 f_est_dchan(false);
4940
4941 T.start;
4942 alt {
4943 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4944 var GsmFrameNumber fn := dl.dl_info.frame_nr;
4945 var octetstring l2 := dl.payload.data_ind.payload;
4946
4947 if (is_first_frame) {
4948 is_first_frame := false;
4949 first_fn := dl.dl_info.frame_nr;
4950 }
4951
4952 if (dl.dl_info.link_id.c == SACCH) {
4953 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
4954 if (not match(l2_fill_frame_sacch, l2)) {
4955 repeat;
4956 }
4957 } else if (not match(l2_fill_frame, l2)) {
4958 repeat;
4959 }
4960
4961 if (dtxd) {
4962 if (not f_g_chan_is_tchf()) {
4963 T.stop;
4964 f_rsl_chan_deact();
4965 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004966 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 +02004967 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004968 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02004969 T.stop;
4970 f_rsl_chan_deact();
4971 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004972
4973 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
4974 * 2 SACCH, 1 TCH/F */
4975 expected_fill_frames := 3;
4976
4977 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
4978 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
4979 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004980 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02004981 } else {
4982 setverdict(pass);
4983 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004984 } else {
4985 if (dl.dl_info.link_id.c == SACCH) {
4986 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02004987 repeat;
4988 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004989 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
4990 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
4991 * we should only see the subset of frames numbers which correspond to a block boundary.
4992 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
4993 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
4994 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
4995 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
4996 repeat;
4997 }
4998 }
4999 log("Received DTX TCH fill frame with bad frame number: ", fn,
5000 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
5001 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
5002 f_rsl_chan_deact();
5003 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005004 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02005005 }
Stefan Sperling4880be42018-08-07 18:12:59 +02005006 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005007 if (dl.dl_info.link_id.c == SACCH) {
5008 nfill_frames_sacch := nfill_frames_sacch + 1;
5009 } else {
5010 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
5011 }
5012 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005013 T.stop;
5014 if (f_g_chan_is_tchf()) {
5015 /* Without DTX we can expect 25 fill frames for every 104 frames.
5016 * (24 FACCH + 1 SACCH filling) */
5017 expected_fill_frames := 25;
5018 } else if (f_g_chan_is_tchh()) {
5019 /* We can expect 2 fill frames for every 104 frames. */
5020 expected_fill_frames := 2;
5021 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
5022 /* We can expect 5 fill frames for every 104 frames. */
5023 expected_fill_frames := 5;
5024 } else {
5025 f_rsl_chan_deact();
5026 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005027 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02005028 }
5029
5030 f_rsl_chan_deact();
5031 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005032
5033 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005034 setverdict(pass);
5035 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005036 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
5037 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005038 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02005039 }
5040 } else {
5041 repeat;
5042 }
5043 }
5044 }
5045 [] L1CTL.receive { repeat; }
5046 [] T.timeout {
5047 f_rsl_chan_deact();
5048 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005049 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02005050 }
5051 }
5052}
5053
5054function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
5055 f_test_l2_fill_frames(false);
5056}
5057
5058function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
5059 f_test_l2_fill_frames(true);
5060}
5061
5062function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
5063 var ConnHdlr vc_conn;
5064 var ConnHdlrPars pars;
5065 pars.t_guard := 60.0;
5066 f_init(testcasename());
5067 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
5068 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
5069 if (dtxd) {
5070 if (i >= 4) { /* DTX is only allowed on TCH/F */
5071 break;
5072 }
5073 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
5074 } else {
5075 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
5076 }
5077 vc_conn.done;
5078 }
5079}
5080
5081/* Verify that L2 fill frames are sent on TCH in signaling mode if
5082 * there is nothing to transmit while DTX is disabled on downlink. */
5083testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
5084 f_tch_sign_l2_fill_frame(false);
5085}
5086
5087/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
5088 * there is nothing to transmit while DTX is enabled on downlink. */
5089testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
5090 f_tch_sign_l2_fill_frame(true);
5091}
Harald Welte0472ab42018-03-12 15:02:26 +01005092
Stefan Sperling0ec1c262018-10-15 15:12:52 +02005093testcase TC_chopped_ipa_ping() runs on test_CT {
5094 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
5095}
5096
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02005097testcase TC_chopped_ipa_payload() runs on test_CT {
5098 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
5099}
5100
Harald Welte0472ab42018-03-12 15:02:26 +01005101/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
5102/* protocol error as per 44.006 */
5103/* link layer failure (repetition of I-frame N200 times without ACK */
5104/* repetition of SABM or DISC N200 times without ACK */
5105/* receptiom of SABM in multi-frame established state */
5106
5107
Harald Welte68e495b2018-02-25 00:05:57 +01005108/* TODO Areas:
5109
5110* channel activation
5111** with BS_Power / MS_Power, bypassing power control loop
5112** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01005113** with timing advance from initial activation on
5114* mode modify
5115** encryption
5116** multirate
5117* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01005118** unsupported algorithm
5119* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01005120* BS Power Control
5121* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01005122* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01005123* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01005124** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01005125* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01005126** DATA_IND from BTS->PCU
5127** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01005128
5129*/
Harald Welte70767382018-02-21 12:16:40 +01005130
5131control {
5132 execute( TC_chan_act_stress() );
5133 execute( TC_chan_act_react() );
5134 execute( TC_chan_deact_not_active() );
5135 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01005136 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01005137 execute( TC_sacch_filling() );
5138 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01005139 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01005140 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02005141 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02005142 execute( TC_sacch_chan_act_ho_async() );
5143 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01005144 execute( TC_rach_content() );
5145 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01005146 execute( TC_rach_max_ta() );
Harald Welte3453ab42019-05-24 21:19:58 +02005147 execute( TC_rach_load_idle_thresh0() );
5148 execute( TC_rach_load_idle_below_thresh() );
5149 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01005150 execute( TC_meas_res_sign_tchf() );
5151 execute( TC_meas_res_sign_tchh() );
5152 execute( TC_meas_res_sign_sdcch4() );
5153 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01005154 execute( TC_meas_res_sign_tchh_toa256() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01005155 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild6833cc92019-05-23 19:34:44 +02005156 execute( TC_rsl_chan_initial_ta() );
Harald Welte70767382018-02-21 12:16:40 +01005157 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01005158 execute( TC_paging_imsi_80percent() );
5159 execute( TC_paging_tmsi_80percent() );
5160 execute( TC_paging_imsi_200percent() );
5161 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01005162 execute( TC_rsl_protocol_error() );
5163 execute( TC_rsl_mand_ie_error() );
5164 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01005165 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01005166 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01005167 execute( TC_si_sched_2bis() );
5168 execute( TC_si_sched_2ter() );
5169 execute( TC_si_sched_2ter_2bis() );
5170 execute( TC_si_sched_2quater() );
5171 execute( TC_si_sched_13() );
5172 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01005173 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01005174 execute( TC_ipa_crcx_twice_not_active() );
5175 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01005176 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01005177 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01005178
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005179 if (mp_pcu_socket != "") {
5180 execute( TC_pcu_act_req() );
5181 execute( TC_pcu_act_req_wrong_ts() );
5182 execute( TC_pcu_act_req_wrong_bts() );
5183 execute( TC_pcu_act_req_wrong_trx() );
5184 execute( TC_pcu_deact_req() );
5185 execute( TC_pcu_deact_req_wrong_ts() );
5186 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02005187 if (mp_l1_supports_gprs) {
5188 execute( TC_pcu_data_req_pdtch() );
5189 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02005190 execute( TC_pcu_data_req_wrong_bts() );
5191 execute( TC_pcu_data_req_wrong_trx() );
5192 execute( TC_pcu_data_req_wrong_ts() );
5193 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02005194 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005195 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02005196 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005197 execute( TC_pcu_data_req_imm_ass_pch() );
5198 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005199 execute( TC_pcu_ext_rach_content() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005200 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02005201 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02005202 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02005203 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02005204 execute( TC_pcu_rr_suspend() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005205 } else {
5206 log("PCU socket path not available, skipping PCU tests");
5207 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005208
5209 execute( TC_dyn_osmo_pdch_act_deact() );
5210 execute( TC_dyn_osmo_pdch_unsol_deact() );
5211 execute( TC_dyn_osmo_pdch_double_act() );
5212 execute( TC_dyn_osmo_pdch_tchf_act() );
5213 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02005214 execute( TC_dyn_ipa_pdch_act_deact() );
5215 execute( TC_dyn_ipa_pdch_tchf_act() );
5216 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
5217 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01005218
5219 execute( TC_rll_est_ind() );
5220 execute( TC_rll_est_req_DCCH_3() );
5221 execute( TC_rll_est_req_ACCH_3() );
5222 execute( TC_rll_rel_ind_DCCH_0() );
5223 execute( TC_rll_rel_ind_DCCH_3() );
5224 execute( TC_rll_rel_ind_ACCH_0() );
5225 execute( TC_rll_rel_ind_ACCH_3() );
5226 execute( TC_rll_rel_req() );
5227 execute( TC_rll_unit_data_req_DCCH() );
5228 execute( TC_rll_unit_data_req_ACCH() );
5229 execute( TC_rll_unit_data_ind_DCCH() );
5230 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02005231
5232 execute( TC_chan_act_a51() );
5233 execute( TC_chan_act_a52() );
5234 execute( TC_chan_act_a53() );
5235 execute( TC_encr_cmd_a51() );
5236 execute( TC_encr_cmd_a52() );
5237 execute( TC_encr_cmd_a53() );
5238
Harald Welteee25aae2019-05-19 14:32:37 +02005239 execute( TC_err_rep_wrong_mdisc() );
5240 execute( TC_err_rep_wrong_msg_type() );
5241 execute( TC_err_rep_wrong_sequence() );
5242
Harald Weltee613f962018-04-18 22:38:16 +02005243 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02005244
5245 execute( TC_tch_sign_l2_fill_frame() );
5246 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02005247
5248 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02005249 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01005250}
5251
5252
5253}