blob: 1c20657233feadc721a0cea4bfdaf0ecc19cdf79 [file] [log] [blame]
Harald Welte70767382018-02-21 12:16:40 +01001module BTS_Tests {
2
Harald Welte14906952019-05-27 09:19:49 +02003/* Integration Tests for OsmoBTS
Harald Welte34b5a952019-05-27 11:54:11 +02004 * (C) 2018-2019 by Harald Welte <laforge@gnumonks.org>
Harald Welte14906952019-05-27 09:19:49 +02005 * contributions by Vadim Yanitskiy and sysmocom - s.f.m.c. GmbH
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 *
Harald Welte34b5a952019-05-27 11:54:11 +020011 * SPDX-License-Identifier: GPL-2.0-or-later
12 *
Harald Welte14906952019-05-27 09:19:49 +020013 * This test suite tests OsmoBTS by attaching to the external interfaces
14 * such as Abis RSL, PCU, VTY as well as by attaching to a MS L1 implementation
15 * using the L1CTL protocol/interface.
16 *
17 * You can run the tests with
18 * a) osmo-bts-trx + trxcon + fake_trx (without any hardware)
19 * b) any osmo-bts-* + OsmocomBB layer1 + osmocon (with real BTS hardware)
20 * c) osmo-bts-virtual + virt_phy (without any hardware)
21 *
22 * Some of the tests will only run on a subset of those three configurations
23 * due to limitations in the respective L1.
24 */
25
Daniel Willmann0fcc4d32018-10-23 20:32:19 +020026import from Misc_Helpers all;
Harald Welte70767382018-02-21 12:16:40 +010027import from General_Types all;
28import from GSM_Types all;
29import from GSM_RR_Types all;
30import from Osmocom_Types all;
31import from GSM_Types all;
Harald Welte82ccef72018-02-25 16:17:33 +010032import from GSM_SystemInformation all;
Harald Welte70767382018-02-21 12:16:40 +010033import from L1CTL_PortType all;
34import from L1CTL_Types all;
35import from LAPDm_Types all;
Harald Weltead033dc2019-05-25 17:28:16 +020036import from LAPDm_RAW_PT all;
Harald Welte70767382018-02-21 12:16:40 +010037import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020038import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010039
40import from RSL_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010041import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010042import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020043import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010044import from RSL_Emulation all;
45
46import from IPL4asp_Types all;
47import from TRXC_Types all;
48import from TRXC_CodecPort all;
49import from TRXC_CodecPort_CtrlFunct all;
50
Harald Welte883340c2018-02-28 18:59:29 +010051import from PCUIF_Types all;
52import from PCUIF_CodecPort all;
53
Harald Welte7484fc42018-02-24 14:09:45 +010054import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010055import from MobileL3_RRM_Types all;
56import from MobileL3_Types all;
57import from L3_Templates all;
Harald Welteeaa9a862019-05-26 23:01:08 +020058import from L3_Common all;
59import from MobileL3_GMM_SM_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010060
Harald Welte8da48242018-02-27 20:41:32 +010061import from Osmocom_VTY_Functions all;
62import from TELNETasp_PortType all;
63
Harald Welte505cf9b2018-09-15 17:47:23 +030064friend module BTS_Tests_SMSCB;
Harald Weltead033dc2019-05-25 17:28:16 +020065friend module BTS_Tests_virtphy;
Harald Welte505cf9b2018-09-15 17:47:23 +030066
Harald Welte70767382018-02-21 12:16:40 +010067/* The tests assume a BTS with the following timeslot configuration:
68 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020069 * TS1 : TCH/F
70 * TS2 : TCH/F
71 * TS3 : TCH/F_PDCH (IPA Style)
72 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010073 * TS5 : TCH/H
74 * TS6 : SDCCH/8
75 * TS7 : PDCH
76 */
77
78modulepar {
79 charstring mp_rsl_ip := "127.0.0.2";
80 integer mp_rsl_port := 3003;
81 integer mp_trx0_arfcn := 871;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070082 charstring mp_bts_trxc_ip := "127.0.0.1";
83 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010084 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020085 charstring mp_ctrl_ip := "127.0.0.1";
86 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020087 charstring mp_bsc_ctrl_ip := "127.0.0.1";
88 integer mp_bsc_ctrl_port := 4249;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020089 integer mp_tolerance_rxqual := 1;
90 integer mp_tolerance_rxlev := 3;
91 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +020092 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +020093 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +020094 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020095 integer mp_ms_actual_ta_exp := 0;
96 integer mp_timing_offset_256syms_exp := 512;
Pau Espin Pedrol315e4712018-11-01 16:27:07 +010097 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +020098 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +020099 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200100 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
101 boolean mp_l1_supports_gprs := false;
Harald Welte70767382018-02-21 12:16:40 +0100102}
103
Harald Welte629cc6b2018-03-11 17:19:05 +0100104type record of RslChannelNr ChannelNrs;
105
Harald Welte70767382018-02-21 12:16:40 +0100106type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100107 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100108 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100109 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100110 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100111 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100112 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100113
114 /* L1CTL port (for classic tests) */
115 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100116
Harald Welte54a2a2d2018-02-26 09:14:05 +0100117 /* TRXC port (for classic tests) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700118 port TRXC_CODEC_PT BTS_TRXC;
119 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100120
Harald Weltef50e3ae2018-09-10 10:27:56 +0200121 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100122 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200123 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100124
Harald Welte883340c2018-02-28 18:59:29 +0100125 /* PCU Interface of BTS */
126 port PCUIF_CODEC_PT PCU;
127 var integer g_pcu_conn_id;
128 /* Last PCU INFO IND we received */
129 var PCUIF_Message g_pcu_last_info;
130
Harald Welte48494ca2018-02-25 16:59:50 +0100131 /* SI configuration */
132 var SystemInformationConfig si_cfg := {
133 bcch_extended := false,
134 si1_present := false,
135 si2bis_present := false,
136 si2ter_present := false,
137 si2quater_present := false,
138 si7_present := false,
139 si8_present := false,
140 si9_present := false,
141 si13_present := false,
142 si13alt_present := false,
143 si15_present := false,
144 si16_present := false,
145 si17_present := false,
146 si2n_present := false,
147 si21_present := false,
148 si22_present := false
149 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100150
151 /* all logical channels available on the BTS */
152 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100153 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100154}
155
156/* an individual call / channel */
157type component ConnHdlr extends RSL_DchanHdlr {
158 port L1CTL_PT L1CTL;
159
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700160 port TRXC_CODEC_PT BTS_TRXC;
161 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100162
163 timer g_Tguard;
164 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
165
166 var ConnHdlrPars g_pars;
167 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100168 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200169
170 /* PCU Interface of BTS */
171 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100172}
173
174function f_init_rsl(charstring id) runs on test_CT {
175 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
176 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
177
178 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
179 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
180 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
181
182 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
183 vc_RSL.start(RSL_Emulation.main(false));
184}
185
186type record ConnHdlrPars {
187 RslChannelNr chan_nr,
188 RSL_IE_ChannelMode chan_mode,
189 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100190 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200191 TestSpecUnion spec optional,
192 RSL_IE_EncryptionInfo encr optional
Harald Welte0472ab42018-03-12 15:02:26 +0100193}
194
195/* Test-specific parameters */
196type union TestSpecUnion {
197 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100198}
199
Harald Welte82ccef72018-02-25 16:17:33 +0100200template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100201 max_retrans := RACH_MAX_RETRANS_7,
202 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100203 cell_barr_access := false,
204 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100205 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100206};
207
Harald Weltef10153f2018-02-25 16:34:05 +0100208template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100209 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200210 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100211 acs := '0'B,
212 neci := true,
213 rxlev_access_min := 0
214}
215
216template (value) LocationAreaIdentification ts_LAI_default := {
217 mcc_mnc := '262F42'H,
218 lac := 42
219}
220
Harald Welte7484fc42018-02-24 14:09:45 +0100221/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100222template (value) SystemInformation ts_SI3_default := {
223 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100224 payload := {
225 si3 := {
226 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100227 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100228 ctrl_chan_desc := {
229 msc_r99 := true,
230 att := true,
231 bs_ag_blks_res := 1,
232 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100233 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100234 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
235 spare := '00'B,
236 bs_pa_mfrms := 0, /* 2 multiframes */
237 t3212 := 1 /* 6 minutes */
238 },
Harald Welte82ccef72018-02-25 16:17:33 +0100239 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100240 dn_ind := false,
241 pwrc := false,
242 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100243 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100244 },
Harald Weltef10153f2018-02-25 16:34:05 +0100245 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100246 rach_control := ts_RachCtrl_default,
Harald Welte3778acc2018-03-09 19:32:31 +0100247 rest_octets := '2B2B2B2B'O
Harald Welte7484fc42018-02-24 14:09:45 +0100248 }
249 }
250}
Harald Welte70767382018-02-21 12:16:40 +0100251
Harald Weltef8df4cb2018-03-10 15:15:08 +0100252template (value) SystemInformation ts_SI2_default := {
253 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100254 payload := {
255 si2 := {
256 bcch_freq_list := '00000000000000000000000000000000'O,
257 ncc_permitted := '11111111'B,
258 rach_control := ts_RachCtrl_default
259 }
260 }
261}
262
Harald Weltef8df4cb2018-03-10 15:15:08 +0100263template (value) SystemInformation ts_SI4_default := {
264 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100265 payload := {
266 si4 := {
267 lai := ts_LAI_default,
268 cell_sel_par := ts_CellSelPar_default,
269 rach_control := ts_RachCtrl_default,
270 cbch_chan_desc := omit,
271 cbch_mobile_alloc := omit,
272 rest_octets := ''O
273 }
274 }
275}
276
277function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
278runs on test_CT {
279 log("Setting ", rsl_si_type, ": ", si_enc);
280 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
281}
282
283function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
284runs on test_CT {
285 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
286 log("Setting ", rsl_si_type, ": ", si_dec);
287 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
288}
289
Harald Welte505cf9b2018-09-15 17:47:23 +0300290friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100291 map(self:BTSVTY, system:BTSVTY);
292 f_vty_set_prompts(BTSVTY);
293 f_vty_transceive(BTSVTY, "enable");
294}
295
Harald Welte505cf9b2018-09-15 17:47:23 +0300296friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200297 map(self:BSCVTY, system:BSCVTY);
298 f_vty_set_prompts(BSCVTY, "OsmoBSC");
299 f_vty_transceive(BSCVTY, "enable");
300}
301
Harald Welte883340c2018-02-28 18:59:29 +0100302/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200303private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
304 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100305 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200306 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
307 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100308 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200309 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200310 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100311 }
312}
313
Harald Weltef26de0b2018-04-04 20:28:05 +0200314private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
315 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100316 timer T := 2.0;
317 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100318 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200319 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100320 return;
321 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200322 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100323
324 T.start;
325 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200326 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100327 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200328 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100329 }
330 }
331}
332
Harald Welte70767382018-02-21 12:16:40 +0100333/* global init function */
Harald Welte68e495b2018-02-25 00:05:57 +0100334function f_init(charstring id := "BTS-Test") runs on test_CT {
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100335 timer T := mp_ipa_up_timeout;
Harald Welte629cc6b2018-03-11 17:19:05 +0100336 g_AllChannels := {
337 /* TS 1..4: TCH/F */
338 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
339 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
340 /* TS 5: TCH/H */
341 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
342 /* TS 0: SDCCH/4 */
343 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
344 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
345 /* TS 6: SDCCH/8 */
346 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
347 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
348 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
349 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
350 };
351
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200352 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700353 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200354 g_AllChanTypes := {
355 /* TS 1..4: TCH/F */
356 valueof(ts_RslChanNr_Bm(1)),
357 /* TS 5: TCH/H */
358 valueof(ts_RslChanNr_Lm(5,1)),
359 /* TS 0: SDCCH/4 */
360 valueof(ts_RslChanNr_SDCCH4(0,2)),
361 /* TS 6: SDCCH/8 */
362 valueof(ts_RslChanNr_SDCCH8(6,4))
363 };
364 } else {
365 g_AllChanTypes := {
366 /* TS 1..4: TCH/F */
367 valueof(ts_RslChanNr_Bm(1)),
368 /* TS 0: SDCCH/4 */
369 valueof(ts_RslChanNr_SDCCH4(0,2)),
370 /* TS 6: SDCCH/8 */
371 valueof(ts_RslChanNr_SDCCH8(6,4))
372 };
373 }
Harald Welte70767382018-02-21 12:16:40 +0100374 f_init_rsl(id);
Harald Welte83f6dbf2018-06-03 18:26:50 +0200375 T.start;
376 alt {
377 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
378 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200379 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
Harald Welte83f6dbf2018-06-03 18:26:50 +0200380 }
381 }
Harald Welte2d142592018-02-25 13:19:44 +0100382 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100383 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200384 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100385
386 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100387 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
388 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
389 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
390 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100391
Harald Weltef26de0b2018-04-04 20:28:05 +0200392 map(self:PCU, system:PCU);
393 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100394
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700395 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100396 var TrxcMessage ret;
397 /* start with a default moderate timing offset equalling TA=2 */
398 f_main_trxc_connect();
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700399 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 +0100400 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200401
402 /* Wait some extra time to make sure the BTS emits a stable carrier.
403 * (this is only relevant when running the tests with a physical BTS.) */
404 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100405}
406
Harald Welte68e495b2018-02-25 00:05:57 +0100407/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
408function f_init_l1ctl() runs on test_CT {
409 map(self:L1CTL, system:L1CTL);
410 f_connect_reset(L1CTL);
411}
412
Harald Welte70767382018-02-21 12:16:40 +0100413type function void_fn(charstring id) runs on ConnHdlr;
414
415/* create a new test component */
Harald Weltef26de0b2018-04-04 20:28:05 +0200416function f_start_handler(void_fn fn, ConnHdlrPars pars, boolean pcu_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100417runs on test_CT return ConnHdlr {
418 var charstring id := testcasename();
419 var ConnHdlr vc_conn;
420
421 vc_conn := ConnHdlr.create(id);
422 /* connect to RSL Emulation main component */
423 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
424 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Harald Weltef26de0b2018-04-04 20:28:05 +0200425 if (pcu_comp) {
426 /* the ConnHdlr component wants to talk directly to the PCU, so disconnect
427 * it from the test_CT and connect it to the component. This obviously only
428 * works for one component, i.e. no concurrency */
429 unmap(self:PCU, system:PCU);
430 map(vc_conn:PCU, system:PCU);
431 }
Harald Welte70767382018-02-21 12:16:40 +0100432
433 vc_conn.start(f_handler_init(fn, id, pars));
434 return vc_conn;
435}
436
Harald Welte7484fc42018-02-24 14:09:45 +0100437template ASP_RSL_Unitdata ts_RSL_UD(template RSL_Message rsl, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
438 streamId := sid,
439 rsl := rsl
440}
441
442template ASP_RSL_Unitdata tr_RSL_UD(template RSL_Message rsl,
443 template IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
444 streamId := sid,
445 rsl := rsl
446}
447
Harald Welte70767382018-02-21 12:16:40 +0100448private altstep as_Tguard() runs on ConnHdlr {
449 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200450 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100451 }
452}
453
Harald Welte505cf9b2018-09-15 17:47:23 +0300454friend function f_l1_tune(L1CTL_PT L1CTL) {
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200455 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, CCCH_MODE_COMBINED, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100456}
457
458private function f_trxc_connect() runs on ConnHdlr {
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700459 map(self:BTS_TRXC, system:BTS_TRXC);
Harald Welte70767382018-02-21 12:16:40 +0100460 var Result res;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700461 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BTS_TRXC, mp_bts_trxc_ip, mp_bts_trxc_port,
Harald Weltea4d8f352018-03-01 15:47:20 +0100462 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +0200463 if (not ispresent(res.connId)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200464 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 +0200465 }
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700466 g_bts_trxc_conn_id := res.connId;
Harald Welte70767382018-02-21 12:16:40 +0100467}
468
469private function f_trxc_fake_rssi(uint8_t rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100470 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700471 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100472}
473
474private function f_trx_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100475 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700476 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100477}
478
479/* first function started in ConnHdlr component */
480private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
481runs on ConnHdlr {
482 g_pars := pars;
483 g_chan_nr := pars.chan_nr;
484
485 map(self:L1CTL, system:L1CTL);
486 f_connect_reset(L1CTL);
487
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700488 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100489 f_trxc_connect();
490 }
Harald Welte70767382018-02-21 12:16:40 +0100491
492 g_Tguard.start(pars.t_guard);
493 activate(as_Tguard());
494
495 f_rslem_register(0, pars.chan_nr);
496
497 /* call the user-supplied test case function */
498 fn.apply(id);
499}
500
Harald Welteb1726c92018-03-30 11:56:38 +0200501function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
502 boolean ignore_other := false)
503runs on ConnHdlr return RSL_Message {
504 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100505 timer T := 3.0;
506 RSL.send(tx);
507 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100508 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200509 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100510 T.stop;
511 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100512 }
Harald Welte1eba3742018-02-25 12:48:14 +0100513 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200514 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100515 }
Harald Welte21240e62018-03-11 21:43:35 +0100516 [not ignore_other] as_l1_sacch();
517 [not ignore_other] as_meas_res();
518 [not ignore_other] as_l1_dcch();
519 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200520 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100521 }
Harald Welte21240e62018-03-11 21:43:35 +0100522 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100523 }
Harald Welteb1726c92018-03-30 11:56:38 +0200524 return rx;
525}
526
527function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
528 boolean ignore_other := false)
529runs on ConnHdlr {
530 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100531}
532
Harald Welte8b01c792019-05-19 22:51:25 +0200533function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false, RSL_IE_List more_ies := {},
534 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA) runs on ConnHdlr {
535 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200536 if (encr_enable) {
537 /* append encryption related IEs, if requested */
538 var RSL_IE_EncryptionInfo encr_info;
539 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
540 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
541encr_info})) };
542 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200543 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200544 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100545}
546
Harald Welte70767382018-02-21 12:16:40 +0100547function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100548 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 +0100549 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100550}
551
Harald Welte70767382018-02-21 12:16:40 +0100552private template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
553 template RSL_IE_ChannelMode chan_mode,
554 float t_guard := 20.0) := {
555 chan_nr := valueof(chan_nr),
556 chan_mode := valueof(chan_mode),
557 t_guard := t_guard,
558 l1_pars := {
559 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100560 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100561 meas_ul := {
562 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200563 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100564 rxqual := 0
565 },
566 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200567 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100568 rxqual := 0
569 }
570 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200571 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100572 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200573 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200574 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100575 },
Harald Weltee613f962018-04-18 22:38:16 +0200576 spec := omit,
577 encr := omit
Harald Welte70767382018-02-21 12:16:40 +0100578}
579
Harald Welte93640c62018-02-25 16:59:33 +0100580/***********************************************************************
581 * Channel Activation / Deactivation
582 ***********************************************************************/
583
Harald Welte70767382018-02-21 12:16:40 +0100584/* Stress test: Do 500 channel activations/deactivations in rapid succession */
585function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
586 for (var integer i := 0; i < 500; i := i+1) {
587 f_rsl_chan_act(g_pars.chan_mode);
588 f_rsl_chan_deact();
589 }
590 setverdict(pass);
591}
592testcase TC_chan_act_stress() runs on test_CT {
593 var ConnHdlr vc_conn;
594 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
595 f_init(testcasename());
596 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
597 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200598 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100599}
600
601/* Test if re-activation of an already active channel fails as expected */
602function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
603 f_rsl_chan_act(g_pars.chan_mode);
604 /* attempt to activate the same lchan again -> expect reject */
605 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
606 alt {
607 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200608 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100609 }
610 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
611 setverdict(pass);
612 }
613 }
614 f_rsl_chan_deact();
615}
616testcase TC_chan_act_react() runs on test_CT {
617 var ConnHdlr vc_conn;
618 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100619 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100620 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
621 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200622 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100623}
624
625/* Attempt to de-activate a channel that's not active */
626function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
627 timer T := 3.0;
628 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
629 T.start;
630 alt {
631 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
632 setverdict(pass);
633 }
634 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200635 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100636 }
637 }
638}
639testcase TC_chan_deact_not_active() runs on test_CT {
640 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100641 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100642 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
643 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200644 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100645}
646
647/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
648function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
649 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
650 alt {
651 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200652 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100653 }
654 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
655 setverdict(pass);
656 }
657 }
658}
659private type record WrongChanNrCase {
660 RslChannelNr chan_nr,
661 charstring description
662}
663private type record of WrongChanNrCase WrongChanNrCases;
664private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
665 chan_nr := chan_nr,
666 description := desc
667}
668
669testcase TC_chan_act_wrong_nr() runs on test_CT {
670 var ConnHdlr vc_conn;
671 var ConnHdlrPars pars;
672
Harald Welte294b0a22018-03-10 23:26:48 +0100673 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100674
675 var WrongChanNrCases wrong := {
676 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
677 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
678 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
679 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
680 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
681 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
682 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
683 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
684 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
685 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
686 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
687 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
688 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
689 };
690
691 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
692 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
693 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
694 vc_conn.done;
695 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200696 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100697}
698
Harald Weltee613f962018-04-18 22:38:16 +0200699/* execute the same callback function on a variety of logical channels */
700private function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
701 var ConnHdlr vc_conn;
702 f_init(testcasename());
703
704 /* test on each of the channels we have */
705 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
706 pars.chan_nr := valueof(g_AllChanTypes[i]);
707
708 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
709 vc_conn := f_start_handler(fn, pars);
710 vc_conn.done;
711 }
712
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200713 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200714}
715
Harald Welte93640c62018-02-25 16:59:33 +0100716/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100717 * SACCH handling
718 ***********************************************************************/
719
720private function f_exp_sacch(boolean exp) runs on ConnHdlr {
721 timer T_sacch := 3.0;
722 T_sacch.start;
723 alt {
724 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200725 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100726 }
727 [not exp] T_sacch.timeout {
728 setverdict(pass);
729 }
730 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
731 setverdict(pass);
732 }
733 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200734 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100735 }
736 [] L1CTL.receive { repeat; }
737 [] RSL.receive { repeat; }
738 }
739}
740
741/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
742private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
743 f_l1_tune(L1CTL);
744 RSL.clear;
745
746 /* activate the logical channel */
747 f_est_dchan();
748 L1CTL.clear;
749
750 /* check that SACCH actually are received as expected */
751 f_exp_sacch(true);
752
753 /* deactivate SACCH on the logical channel */
754 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
755 f_sleep(1.0);
756 L1CTL.clear;
757
758 /* check that no SACCH are received anymore */
759 f_exp_sacch(false);
760
761 /* release the channel */
762 f_rsl_chan_deact();
763 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
764}
765testcase TC_deact_sacch() runs on test_CT {
766 var ConnHdlr vc_conn;
767 var ConnHdlrPars pars;
768 f_init();
769 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
770 //for (var integer i := 0; i < 1; i := i+1) {
771 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
772 log(testcasename(), ": Starting for ", g_AllChannels[i]);
773 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
774 vc_conn.done;
775 }
776 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200777 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100778}
779
Harald Welte55700662018-03-12 13:15:43 +0100780/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100781private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
782 var L1ctlDlMessage dl;
783 /* check that the specified SI5 value is actually sent */
784 timer T_sacch := 3.0;
785 L1CTL.clear;
786 T_sacch.start;
787 alt {
788 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
789 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
790 if (match(l3, l3_exp)) {
791 setverdict(pass);
792 } else {
793 repeat;
794 }
795 }
796 [] L1CTL.receive { repeat; }
797 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200798 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100799 }
800 }
801}
802
Harald Welte55700662018-03-12 13:15:43 +0100803/* verify that given SACCH payload is not present */
804private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
805 var L1ctlDlMessage dl;
806 /* check that the specified SI5 value is actually sent */
807 timer T_sacch := 3.0;
808 L1CTL.clear;
809 T_sacch.start;
810 alt {
811 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
812 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
813 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200814 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100815 } else {
816 repeat;
817 }
818 }
819 [] L1CTL.receive { repeat; }
820 [] T_sacch.timeout {
821 setverdict(pass);
822 }
823 }
824}
825
Harald Welte629cc6b2018-03-11 17:19:05 +0100826/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100827private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
828 /* Set a known default SACCH filling for SI5 */
829 var octetstring si5 := f_rnd_octstring(19);
830 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
831
832 f_l1_tune(L1CTL);
833 RSL.clear;
834
835 /* activate the logical channel */
836 f_est_dchan();
837
838 /* check that the specified SI5 value is actually sent */
839 f_sacch_present(si5);
840
841 /* release the channel */
842 RSL.clear;
843 f_rsl_chan_deact();
844 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
845}
846testcase TC_sacch_filling() runs on test_CT {
847 var ConnHdlr vc_conn;
848 var ConnHdlrPars pars;
849 f_init();
850 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
851 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
852 log(testcasename(), ": Starting for ", g_AllChannels[i]);
853 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
854 vc_conn.done;
855 }
856 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200857 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100858}
859
Harald Welte629cc6b2018-03-11 17:19:05 +0100860/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100861private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
862 /* Set a known default SACCH filling for SI5 */
863 var octetstring si5 := f_rnd_octstring(19);
864 var octetstring si5_diff := f_rnd_octstring(19);
865 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
866
867 f_l1_tune(L1CTL);
868 RSL.clear;
869
870 log("Activating channel, expecting standard SI5");
871 /* activate the logical channel */
872 f_est_dchan();
873 /* check that the specified SI5 value is actually sent */
874 f_sacch_present(si5);
875
876 /* set channel-specific different SI5 */
877 log("Setting channel specific SACCH INFO, expecting it");
878 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
879 /* check that the specified lchan-specific value is now used */
880 f_sacch_present(si5_diff);
881
882 /* deactivate the channel and re-activate it, this should result in default SI5 */
883 log("De-activating and re-activating channel, expecting standard SI5");
884 f_rsl_chan_deact();
885 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
886 /* Verify that the TRX-wide default SACCH filling is present again */
887 f_sacch_present(si5);
888
889 /* release the channel */
890 RSL.clear;
891 f_rsl_chan_deact();
892 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
893}
894testcase TC_sacch_info_mod() runs on test_CT {
895 var ConnHdlr vc_conn;
896 var ConnHdlrPars pars;
897 f_init();
898 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
899 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
900 log(testcasename(), ": Starting for ", g_AllChannels[i]);
901 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
902 vc_conn.done;
903 }
904 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200905 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100906}
907
Harald Welte075d84c2018-03-12 13:07:24 +0100908/* Test SACCH scheduling of multiple different SI message types */
909private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
910 var octetstring si5 := f_rnd_octstring(19);
911 var octetstring si5bis := f_rnd_octstring(19);
912 var octetstring si5ter := f_rnd_octstring(19);
913 var octetstring si6 := f_rnd_octstring(19);
914
915 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
916 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
917 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
918 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
919
920 f_l1_tune(L1CTL);
921 RSL.clear;
922
923 /* activate the logical channel */
924 f_est_dchan();
925 L1CTL.clear;
926
927 /* check that SACCH actually are received as expected */
928 f_sacch_present(si5);
929 f_sacch_present(si5bis);
930 f_sacch_present(si5ter);
931 f_sacch_present(si6);
932
933 /* release the channel */
934 f_rsl_chan_deact();
935 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
936}
937testcase TC_sacch_multi() runs on test_CT {
938 var ConnHdlr vc_conn;
939 var ConnHdlrPars pars;
940 f_init();
941 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
942 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
943 log(testcasename(), ": Starting for ", g_AllChannels[i]);
944 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
945 vc_conn.done;
946 }
947 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200948 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +0100949}
950
Harald Welte55700662018-03-12 13:15:43 +0100951/* Test if SACH information is modified as expected */
952private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
953 var octetstring si5 := f_rnd_octstring(19);
954 var octetstring si6 := f_rnd_octstring(19);
955
956 /* First, configure both SI5 and SI6 to be transmitted */
957 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
958 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
959
960 f_l1_tune(L1CTL);
961 RSL.clear;
962
963 /* activate the logical channel */
964 f_est_dchan();
965 L1CTL.clear;
966
967 /* check that SACCH actually are received as expected */
968 f_sacch_present(si5);
969 f_sacch_present(si6);
970
971 /* disable SI6 */
972 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
973
974 /* check that SI5 is still transmitted */
975 f_sacch_present(si5);
976 /* check if SI6 is now gone */
977 f_sacch_missing(si6);
978
979 /* release the channel */
980 f_rsl_chan_deact();
981 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
982}
983testcase TC_sacch_multi_chg() runs on test_CT {
984 var ConnHdlr vc_conn;
985 var ConnHdlrPars pars;
986 f_init();
987 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
988 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
989 log(testcasename(), ": Starting for ", g_AllChannels[i]);
990 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
991 vc_conn.done;
992 }
993 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200994 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +0100995}
996
Harald Weltec8d363c2019-05-19 20:36:48 +0200997/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
998private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
999 var octetstring si5 := f_rnd_octstring(19);
1000 var octetstring si6 := f_rnd_octstring(19);
1001 var octetstring si5_specific := f_rnd_octstring(19);
1002 var octetstring si6_specific := f_rnd_octstring(19);
1003
1004 /* First, configure both SI5 and SI6 to be transmitted */
1005 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1006 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1007
1008 f_l1_tune(L1CTL);
1009 RSL.clear;
1010
1011 /* activate channel with different SACCH filling */
1012 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1013 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1014 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1015 }));
1016 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1017 RSL_IE_Body:{sacch_info := sacch_info})) };
1018 f_est_dchan(more_ies := addl_ies);
1019
1020 /* check that SACCH actually are received as expected */
1021 f_sacch_present(si5_specific);
1022 f_sacch_present(si6_specific);
1023
1024 /* release the channel */
1025 f_rsl_chan_deact();
1026 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1027}
1028testcase TC_sacch_chan_act() runs on test_CT {
1029 var ConnHdlr vc_conn;
1030 var ConnHdlrPars pars;
1031 f_init();
1032
1033 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1034 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1035 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1036 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1037 vc_conn.done;
1038 }
1039 /* TODO: do the above in parallel, rather than sequentially? */
1040 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1041}
1042
Harald Welte8b01c792019-05-19 22:51:25 +02001043/* verify that SACCH DL transmission is started only if MS power IE present
1044 * see section 4.1.3 of 3GPP TS 48.058 */
1045private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1046 var octetstring si5 := f_rnd_octstring(19);
1047
1048 f_l1_tune(L1CTL);
1049 RSL.clear;
1050
1051 /* Step 1: Activate ASYNC HO channel without MS power IE */
1052
1053 /* Activate channel on BTS side */
1054 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1055 /* don't perform immediate assignment here, as we're testing non-IA case */
1056 /* enable dedicated mode */
1057 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1058
1059 /* Verify that no DL SACCH is being received */
1060 f_sacch_missing(?);
1061
1062 f_rsl_chan_deact();
1063 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1064
1065
1066 /* Step 2: Activate ASYNC HO channel with MS power IE */
1067
1068 /* Activate channel on BTS side */
1069 var RSL_IE_List addl_ies := {
1070 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1071 };
1072 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1073 /* don't perform immediate assignment here, as we're testing non-IA case */
1074 /* enable dedicated mode */
1075 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1076
1077 /* Verify that DL SACCH is being received */
1078 f_sacch_present(si5);
1079
1080 f_rsl_chan_deact();
1081 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1082}
1083testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1084 var ConnHdlr vc_conn;
1085 var ConnHdlrPars pars;
1086 f_init();
1087
1088 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1089 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1090 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1091 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1092 vc_conn.done;
1093 }
1094 /* TODO: do the above in parallel, rather than sequentially? */
1095 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1096}
1097
1098/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1099 * see section 4.1.4 of 3GPP TS 48.058 */
1100private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1101 var octetstring si5 := f_rnd_octstring(19);
1102 var RSL_IE_List addl_ies;
1103
1104 f_l1_tune(L1CTL);
1105 RSL.clear;
1106
1107 /* Step 1: Activate SYNC HO channel without MS power IE */
1108
1109 /* Activate channel on BTS side */
1110 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1111 /* don't perform immediate assignment here, as we're testing non-IA case */
1112 /* enable dedicated mode */
1113 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1114
1115 /* Verify that no DL SACCH is being received */
1116 f_sacch_missing(?);
1117
1118 f_rsl_chan_deact();
1119 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1120
1121
1122 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1123
1124 /* Activate channel on BTS side */
1125 addl_ies := {
1126 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1127 };
1128 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1129 /* don't perform immediate assignment here, as we're testing non-IA case */
1130 /* enable dedicated mode */
1131 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1132
1133 /* Verify that no DL SACCH is being received */
1134 f_sacch_missing(?);
1135
1136 f_rsl_chan_deact();
1137 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1138
1139
1140 /* Step 2b: Activate SYNC HO channel with TA IE */
1141
1142 /* Activate channel on BTS side */
1143 addl_ies := {
1144 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1145 };
1146 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1147 /* don't perform immediate assignment here, as we're testing non-IA case */
1148 /* enable dedicated mode */
1149 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1150
1151 /* Verify that no DL SACCH is being received */
1152 f_sacch_missing(?);
1153
1154 f_rsl_chan_deact();
1155 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1156
1157
1158 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1159
1160 /* Activate channel on BTS side */
1161 addl_ies := {
1162 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1163 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1164 };
1165 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1166 /* don't perform immediate assignment here, as we're testing non-IA case */
1167 /* enable dedicated mode */
1168 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1169
1170 /* Verify that DL SACCH is being received */
1171 f_sacch_present(si5);
1172
1173 f_rsl_chan_deact();
1174 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1175}
1176testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1177 var ConnHdlr vc_conn;
1178 var ConnHdlrPars pars;
1179 f_init();
1180
1181 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1182 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1183 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1184 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1185 vc_conn.done;
1186 }
1187 /* TODO: do the above in parallel, rather than sequentially? */
1188 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1189}
Harald Welte629cc6b2018-03-11 17:19:05 +01001190
1191
1192/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001193 * RACH Handling
1194 ***********************************************************************/
1195
Harald Welte8c24c2b2018-02-26 08:31:31 +01001196/* like L1SAP_IS_PACKET_RACH */
1197private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +01001198 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001199 return true;
1200 }
1201 return false;
1202}
1203
1204/* generate a random RACH for circuit-switched */
1205private function f_rnd_ra_cs() return OCT1 {
1206 var OCT1 ra;
1207 do {
1208 ra := f_rnd_octstring(1);
1209 } while (ra_is_ps(ra));
1210 return ra;
1211}
1212
Harald Welte883340c2018-02-28 18:59:29 +01001213/* generate a random RACH for packet-switched */
1214private function f_rnd_ra_ps() return OCT1 {
1215 var OCT1 ra;
1216 do {
1217 ra := f_rnd_octstring(1);
1218 } while (not ra_is_ps(ra));
1219 return ra;
1220}
1221
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07001222/* generate a random 11-bit RA (packet-switched only) */
1223private function f_rnd_ra11_ps() return BIT11 {
1224 var integer ra11 := f_rnd_int(bit2int('11111111111'B));
1225 return int2bit(ra11, 11);
1226}
1227
Harald Welte8c24c2b2018-02-26 08:31:31 +01001228/* Send 1000 RACH requests and check their RA+FN on the RSL side */
1229testcase TC_rach_content() runs on test_CT {
1230 f_init(testcasename());
1231 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001232 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001233
Harald Welte8c24c2b2018-02-26 08:31:31 +01001234 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001235 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001236 for (var integer i := 0; i < 1000; i := i+1) {
1237 var OCT1 ra := f_rnd_ra_cs();
1238 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1239 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001240 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001241 }
1242 fn_last := fn;
1243
1244 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001245 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001246 alt {
1247 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, ?))) {
1248 T.stop;
1249 }
1250 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001251 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001252 }
1253 [] RSL_CCHAN.receive { repeat; }
1254 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001255 test_failed := true;
1256 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001257 }
1258 }
1259 }
Maxba06feb2019-03-05 10:52:46 +01001260 if (test_failed) {
1261 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001262 }
Maxba06feb2019-03-05 10:52:46 +01001263 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001264 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001265}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001266
1267/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1268testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001269 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001270 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001271 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001272 f_l1_tune(L1CTL);
1273
1274 var GsmFrameNumber fn_last := 0;
1275 for (var integer i := 0; i < 1000; i := i+1) {
1276 var OCT1 ra := f_rnd_ra_cs();
1277 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1278 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001279 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001280 }
1281 fn_last := fn;
1282 }
1283 var integer rsl_chrqd := 0;
1284 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001285 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001286 alt {
1287 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
1288 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001289 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001290 repeat;
1291 }
1292 [] RSL_CCHAN.receive { repeat; }
1293 [] T.timeout { }
1294 }
1295 if (rsl_chrqd == 1000) {
1296 setverdict(pass);
1297 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001298 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001299 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001300 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001301}
1302
Harald Welte3453ab42019-05-24 21:19:58 +02001303private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1304 var charstring bts_str := "bts " & int2str(bts_nr);
1305 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1306}
1307
1308/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1309private template integer tr_rach_slots_per_interval := (90 .. 130);
1310
1311/* Expect 0 RACH load on an idle BTS that has just started up */
1312testcase TC_rach_load_idle_thresh0() runs on test_CT {
1313 var ASP_RSL_Unitdata rx_ud;
1314
1315 f_init_vty_bsc();
1316 /* send load indications even at 0% load */
1317 f_vty_load_ind_thresh(0);
1318 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1319 f_sleep(2.0);
1320
1321 f_init();
1322
1323 timer T := 5.0;
1324 T.start;
1325 alt {
1326 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, 0, 0))) {
1327 setverdict(pass);
1328 repeat;
1329 }
1330 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1331 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1332 repeat;
1333 }
1334 [] RSL_CCHAN.receive {
1335 repeat;
1336 }
1337 [] T.timeout { }
1338 }
1339
1340 f_vty_load_ind_thresh(10);
1341 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1342}
1343
1344/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1345testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1346 var ASP_RSL_Unitdata rx_ud;
1347
1348 f_init_vty_bsc();
1349 f_init();
1350
1351 timer T := 5.0;
1352 T.start;
1353 alt {
1354 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1355 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1356 repeat;
1357 }
1358 [] RSL_CCHAN.receive {
1359 repeat;
1360 }
1361 [] T.timeout {
1362 setverdict(pass);
1363 }
1364 }
1365
1366 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1367}
1368
1369/* Expect 0 RACH load on an idle BTS that has just started up */
1370testcase TC_rach_load_count() runs on test_CT {
1371 var ASP_RSL_Unitdata rx_ud;
1372 var integer load_access_count := 0;
1373
1374 f_init_vty_bsc();
1375 /* send load indications even at 0% load */
1376 f_vty_load_ind_thresh(0);
1377 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1378 f_sleep(2.0);
1379 f_init();
1380
1381 f_init_l1ctl();
1382 f_sleep(1.0);
1383 f_l1_tune(L1CTL);
1384
1385 var GsmFrameNumber fn_last := 0;
1386 for (var integer i := 0; i < 1000; i := i+1) {
1387 var OCT1 ra := f_rnd_ra_cs();
1388 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1389 if (fn == fn_last) {
1390 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1391 }
1392 fn_last := fn;
1393 }
1394
1395 timer T := 5.0;
1396 T.start;
1397 alt {
1398 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
1399 -> value rx_ud {
1400 var RSL_IE_Body ie;
1401 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1402 load_access_count := load_access_count + ie.rach_load.access_count;
1403 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1404 setverdict(fail, "Access count cannot be < Busy count");
1405 }
1406 repeat;
1407 }
1408 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1409 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1410 repeat;
1411 }
1412 [] RSL_CCHAN.receive {
1413 repeat;
1414 }
1415 [] T.timeout { }
1416 }
1417 if (load_access_count == 1000) {
1418 setverdict(pass);
1419 } else {
1420 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1421 }
1422
1423 f_vty_load_ind_thresh(10);
1424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1425}
1426
1427
1428
Harald Welte54a2a2d2018-02-26 09:14:05 +01001429private function f_main_trxc_connect() runs on test_CT {
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001430 map(self:BTS_TRXC, system:BTS_TRXC);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001431 var Result res;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001432 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BTS_TRXC, mp_bts_trxc_ip, mp_bts_trxc_port,
Harald Welted3a88a62018-03-01 16:04:52 +01001433 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +02001434 if (not ispresent(res.connId)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001435 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 +02001436 }
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001437 g_bts_trxc_conn_id := res.connId;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001438}
1439
1440private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001441 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001442 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001443 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001444 f_sleep(0.5);
1445
1446 /* Transmit RACH request + wait for confirmation */
1447 var OCT1 ra := f_rnd_ra_cs();
1448 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1449
1450 /* Check for expected result */
1451 timer T := 1.5;
1452 T.start;
1453 alt {
1454 [expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
1455 setverdict(pass);
1456 }
1457 [not expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001458 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001459 }
1460 [] RSL_CCHAN.receive { repeat; }
1461 [not expect_pass] T.timeout {
1462 setverdict(pass);
1463 }
1464 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001465 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001466 }
1467 }
1468}
1469
1470/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1471testcase TC_rach_max_ta() runs on test_CT {
1472 f_init(testcasename());
1473 f_init_l1ctl();
1474 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001475 f_sleep(1.0);
1476
1477 /* default max-ta is 63 (full range of GSM timing advance */
1478
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001479 /* We allow early arrival up to 2 symbols */
1480 f_rach_toffs(-1*256, true);
1481 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001482 f_rach_toffs(-10*256, false);
1483
1484 /* 0 / 32 / 63 bits is legal / permitted */
1485 f_rach_toffs(0, true);
1486 f_rach_toffs(32*256, true);
1487 f_rach_toffs(63*256, true);
1488
1489 /* more than 63 bits is not legal / permitted */
1490 f_rach_toffs(64*256, false);
1491 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001492 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001493}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001494
Harald Welte93640c62018-02-25 16:59:33 +01001495/***********************************************************************
1496 * Measurement Processing / Reporting
1497 ***********************************************************************/
1498
Harald Welte70767382018-02-21 12:16:40 +01001499template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1500 spare := '0'B,
1501 lpd := 0,
1502 sapi := sapi,
1503 c_r := c_r,
1504 ea := true
1505}
1506
Harald Welted879bd92018-03-12 15:01:23 +01001507template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001508 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001509 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001510 len := 0, /* overwritten */
1511 m := false,
1512 el := 1,
1513 payload := pl
1514}
1515
1516/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1517altstep as_l1_sacch() runs on ConnHdlr {
1518 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001519 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001520 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001521 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 +01001522 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001523 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001524
1525 var L1ctlDataReq data_req := {
1526 l1header := valueof(ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta)),
1527 l2_payload := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O)
1528 }
1529 log("Sending Measurement Report: ", data_req);
1530 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), data_req));
Harald Welte70767382018-02-21 12:16:40 +01001531 repeat;
1532 }
1533}
1534
1535altstep as_l1_dcch() runs on ConnHdlr {
1536 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001537 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001538 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1539 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001540 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1541 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001542 repeat;
1543 }
1544}
1545
1546type record MeasElem {
1547 uint6_t rxlev,
1548 uint3_t rxqual
1549}
1550
1551type record MeasElemFS {
1552 MeasElem full,
1553 MeasElem sub
1554}
1555
1556type record ConnL1Pars {
1557 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001558 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001559 MeasElemFS meas_ul,
1560 int16_t timing_offset_256syms,
1561 uint5_t bs_power_level,
1562 uint5_t ms_power_level,
1563 uint8_t ms_actual_ta
1564}
1565
1566/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1567private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1568 return 63 + (toffs256s/256);
1569}
1570
Harald Welted5684392018-03-10 18:22:04 +01001571private function f_max(integer a, integer b) return integer {
1572 if (a > b) {
1573 return a;
1574 } else {
1575 return b;
1576 }
1577}
1578
1579private function f_min(integer a, integer b) return integer {
1580 if (a < b) {
1581 return a;
1582 } else {
1583 return b;
1584 }
1585}
1586
1587/* compute negative tolerance val-tolerance, ensure >= min */
1588private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1589 val := val - tolerance;
1590 return f_max(val, min);
1591}
1592
1593/* compute positive tolerance val+tolerance, ensure <= max */
1594private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1595 val := val + tolerance;
1596 return f_min(val, max);
1597}
1598
1599/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1600private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1601return template integer {
1602 var template integer ret;
1603 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1604 return ret;
1605}
1606
1607
Harald Welte70767382018-02-21 12:16:40 +01001608/* build a template for matching measurement results against */
1609private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1610 var ConnL1Pars l1p := g_pars.l1_pars;
1611 var template RSL_IE_UplinkMeas ul_meas := {
1612 len := 3,
1613 rfu := '0'B,
1614 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001615 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001616 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001617 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001618 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001619 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1620 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001621 supp_meas_info := omit
1622 };
Harald Welte685d5982018-02-27 20:42:05 +01001623 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001624 ul_meas.len := (3+8);
1625 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001626 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001627 toa256_min := ?,
1628 toa256_max := ?,
1629 toa256_std_dev := ?
1630 }
Harald Welte685d5982018-02-27 20:42:05 +01001631 }
Harald Welte70767382018-02-21 12:16:40 +01001632 var template RSL_IE_BS_Power bs_power := {
1633 reserved := 0,
1634 epc := false,
1635 fpc := false,
1636 power_level := l1p.bs_power_level
1637 };
1638 var template RSL_IE_L1Info l1_info := {
1639 ms_power_lvl := l1p.ms_power_level,
1640 fpc := false,
1641 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001642 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001643 };
1644 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001645 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001646 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1647 ?, t_toffs);
1648}
1649
1650/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001651altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001652 var RSL_Message rsl;
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001653 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Harald Welte70767382018-02-21 12:16:40 +01001654 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1655 /* increment counter of next to-be-expected meas rep */
1656 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1657 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001658 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001659 repeat;
1660 }
1661 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001662 /* increment counter of next to-be-expected meas rep */
1663 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1664 if (g_first_meas_res) {
1665 g_first_meas_res := false;
1666 repeat;
1667 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001668 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001669 }
Harald Welte70767382018-02-21 12:16:40 +01001670 }
1671 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001672 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001673 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001674 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001675 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001676 }
1677}
1678
Harald Weltee613f962018-04-18 22:38:16 +02001679private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1680 select (rsl_alg_id) {
1681 case (RSL_ALG_ID_A5_0) { return 0; }
1682 case (RSL_ALG_ID_A5_1) { return 1; }
1683 case (RSL_ALG_ID_A5_2) { return 2; }
1684 case (RSL_ALG_ID_A5_3) { return 3; }
1685 case (RSL_ALG_ID_A5_4) { return 4; }
1686 case (RSL_ALG_ID_A5_5) { return 5; }
1687 case (RSL_ALG_ID_A5_6) { return 6; }
1688 case (RSL_ALG_ID_A5_7) { return 7; }
1689 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001690 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1691 /* Make compiler happy by calling mtc.stop here. It is already
1692 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001693 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001694 }
1695 }
1696}
1697
1698private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1699 select (rsl_alg_id) {
1700 case (RSL_ALG_ID_A5_1) { return '000'B; }
1701 case (RSL_ALG_ID_A5_2) { return '001'B; }
1702 case (RSL_ALG_ID_A5_3) { return '010'B; }
1703 case (RSL_ALG_ID_A5_4) { return '011'B; }
1704 case (RSL_ALG_ID_A5_5) { return '100'B; }
1705 case (RSL_ALG_ID_A5_6) { return '101'B; }
1706 case (RSL_ALG_ID_A5_7) { return '110'B; }
1707 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001708 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1709 /* Make compiler happy by calling mtc.stop here. It is already
1710 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001711 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001712 }
1713 }
1714}
1715
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001716/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1717private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1718 var GsmFrameNumber fn;
1719 timer T := 8.0;
1720
1721 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1722 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1723
1724 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1725 /* Send the actual RACH */
1726 fn := f_L1CTL_RACH(L1CTL, ra);
1727
1728 T.start;
1729 alt {
1730 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1731 [] T.timeout {
1732 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1733 }
1734 }
1735 T.stop
1736 return fn;
1737}
Harald Weltee613f962018-04-18 22:38:16 +02001738
Harald Welte70767382018-02-21 12:16:40 +01001739/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001740private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001741 var GsmFrameNumber fn;
1742 var ImmediateAssignment imm_ass;
1743 var integer ra := 23;
1744
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001745 /* Send RACH request and wait for ChanReq */
1746 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001747
1748 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001749 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01001750
1751 /* Send IMM.ASS via CCHAN */
1752 var ChannelDescription ch_desc := {
1753 chan_nr := g_pars.chan_nr,
1754 tsc := 7,
1755 h := false,
1756 arfcn := mp_trx0_arfcn,
1757 maio_hsn := omit
1758 };
1759 var MobileAllocation ma := {
1760 len := 0,
1761 ma := ''B
1762 };
1763 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1764 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1765
1766 /* receive IMM.ASS on MS side */
1767 var ImmediateAssignment ia_um;
1768 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1769 /* enable dedicated mode */
1770 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltee613f962018-04-18 22:38:16 +02001771 /* enable encryption, if requested */
1772 if (encr_enable) {
1773 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1774 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1775 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001776
1777 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001778}
1779
1780/* establish DChan, verify existance + contents of measurement reports */
1781function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001782 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001783 RSL.clear;
1784
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001785 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001786 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001787 f_trx_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
1788 }
Harald Welte70767382018-02-21 12:16:40 +01001789
1790 f_est_dchan();
1791
1792 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1793 * RSL measurement reports on Abis side */
1794 timer T := 8.0;
1795 T.start;
1796 alt {
1797 [] as_l1_sacch();
1798 [] as_meas_res();
1799 [] as_l1_dcch();
1800 [] L1CTL.receive { repeat; }
1801 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001802 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01001803 * of any earlier errors, so if we reach this timeout, we're good */
1804 setverdict(pass);
1805 }
1806 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001807 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01001808 }
1809 }
1810 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001811 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001812}
Harald Welte0472ab42018-03-12 15:02:26 +01001813
Harald Welte70767382018-02-21 12:16:40 +01001814testcase TC_meas_res_sign_tchf() runs on test_CT {
1815 var ConnHdlr vc_conn;
1816 var ConnHdlrPars pars;
1817 f_init(testcasename());
1818 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1819 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1820 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1821 vc_conn.done;
1822 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001823 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001824}
1825testcase TC_meas_res_sign_tchh() runs on test_CT {
1826 var ConnHdlr vc_conn;
1827 var ConnHdlrPars pars;
1828 f_init(testcasename());
1829 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1830 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1831 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1832 vc_conn.done;
1833 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001834 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001835}
1836testcase TC_meas_res_sign_sdcch4() runs on test_CT {
1837 var ConnHdlr vc_conn;
1838 var ConnHdlrPars pars;
1839 f_init(testcasename());
1840 for (var integer ss := 0; ss <= 3; ss := ss+1) {
1841 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
1842 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1843 vc_conn.done;
1844 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001845 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001846}
1847testcase TC_meas_res_sign_sdcch8() runs on test_CT {
1848 var ConnHdlr vc_conn;
1849 var ConnHdlrPars pars;
1850 f_init(testcasename());
1851 for (var integer ss := 0; ss <= 7; ss := ss+1) {
1852 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
1853 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1854 vc_conn.done;
1855 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001856 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001857}
Harald Welte685d5982018-02-27 20:42:05 +01001858testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
1859 var ConnHdlr vc_conn;
1860 var ConnHdlrPars pars;
1861 f_init(testcasename());
1862 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
1863 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1864 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1865 pars.l1_pars.toa256_enabled := true;
1866 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1867 vc_conn.done;
1868 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001869 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01001870}
1871
Philipp Maier4d1e9c92018-12-20 11:11:56 +01001872/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
1873 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
1874function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
1875 var L1ctlDlMessage l1_dl;
1876 var RSL_IE_MS_Power ms_power;
1877 var RSL_Message rsl;
1878 var uint5_t power_level := 0;
1879
1880 f_l1_tune(L1CTL);
1881 RSL.clear;
1882
1883 f_est_dchan();
1884
1885 ms_power.reserved := 0;
1886 ms_power.fpc_epc := false;
1887
1888 /* Send the first power control command. This will disable any BTS/TRX
1889 * internal power control and switch the MS (which is not in scope of
1890 * this test) to a constant power level. We start with a power level
1891 * of 0 */
1892 ms_power.power_level := power_level;
1893 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1894 RSL.send(rsl);
1895
1896 alt {
1897
1898 /* Pick all SACCH blocks for checking */
1899 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1900
1901 /* The first byte of the L1 header contains the power level.
1902 * The reserved bits and the fpc bit is set to 0, so we may
1903 * compare directly. */
1904 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
1905 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
1906 }
1907
1908 /* Signal a new power level via RSL for the next turn. */
1909 if (power_level < 31) {
1910 power_level := power_level + 1;
1911 ms_power.power_level := power_level;
1912 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1913 RSL.send(rsl);
1914 repeat;
1915 }
1916
1917 }
1918
1919 /* Ignore all other blocks */
1920 [] L1CTL.receive { repeat; }
1921
1922 }
1923
1924 f_rsl_chan_deact();
1925 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1926
1927 setverdict(pass);
1928}
1929
1930testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
1931 var ConnHdlr vc_conn;
1932 var ConnHdlrPars pars;
1933 f_init(testcasename());
1934
1935 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1936 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1937 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
1938 vc_conn.done;
1939 }
1940 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1941}
Harald Welte70767382018-02-21 12:16:40 +01001942
Eric Wild6833cc92019-05-23 19:34:44 +02001943/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
1944TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
1945function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
1946 var L1ctlDlMessage l1_dl;
1947 var uint5_t ta_to_test := 16;
1948
1949
1950 f_l1_tune(L1CTL);
1951 RSL.clear;
1952
1953 /* tell fake_trx to use a given timing offset for all bursts */
1954 f_trx_fake_toffs256(ta_to_test*256);
1955
1956 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
1957
1958
1959 alt {
1960
1961 /* Pick all SACCH blocks for checking */
1962 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1963
1964 /* The second byte of the L1 header contains the TA. */
1965 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
1966 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
1967 }
1968
1969 }
1970
1971 /* Ignore all other blocks */
1972 [] L1CTL.receive { repeat; }
1973
1974 }
1975
1976 f_rsl_chan_deact();
1977 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1978
1979 setverdict(pass);
1980}
1981
1982testcase TC_rsl_chan_initial_ta() runs on test_CT {
1983 var ConnHdlr vc_conn;
1984 var ConnHdlrPars pars;
1985 f_init(testcasename());
1986 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
1987 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars);
1988 vc_conn.done;
1989 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1990}
1991
Harald Welte0472ab42018-03-12 15:02:26 +01001992/* 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 +01001993private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001994 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001995 RSL.clear;
1996
1997 f_est_dchan();
1998 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01001999 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01002000
2001 timer T := 40.0;
2002 T.start;
2003 alt {
2004 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
2005 setverdict(pass)
2006 }
2007 [] RSL.receive { repeat };
2008 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002009 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01002010 }
2011 }
2012 f_rsl_chan_deact();
2013}
2014testcase TC_conn_fail_crit() runs on test_CT {
2015 var ConnHdlr vc_conn;
2016 var ConnHdlrPars pars;
2017 f_init(testcasename());
2018 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
2019 pars.t_guard := 60.0;
2020 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
2021 vc_conn.done;
2022}
2023
Harald Welte93640c62018-02-25 16:59:33 +01002024/***********************************************************************
2025 * Paging
2026 ***********************************************************************/
2027
Harald Welte68e495b2018-02-25 00:05:57 +01002028function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
2029 if (tmsi == 'FFFFFFFF'O) {
2030 return true;
2031 } else {
2032 return false;
2033 }
2034}
Harald Welte70767382018-02-21 12:16:40 +01002035
Philipp Maier82cb0b12018-08-31 14:41:39 +02002036type record allowedFn { integer frame_nr }
2037template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
2038template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
2039template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
2040template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
2041template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
2042template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
2043template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
2044template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
2045function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
2046{
2047 var integer frame_nr_51;
2048 frame_nr_51 := frame_nr mod 51
2049
2050 var allowedFn fn_check;
2051 fn_check.frame_nr := frame_nr_51;
2052
2053 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002054 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002055 return;
2056 }
2057
2058 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
2059 return;
2060 }
2061 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
2062 return;
2063 }
2064 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
2065 return;
2066 }
2067 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
2068 return;
2069 }
2070 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
2071 return;
2072 }
2073 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
2074 return;
2075 }
2076 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
2077 return;
2078 }
2079 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
2080 return;
2081 }
2082
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002083 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002084 return;
2085}
2086
2087altstep 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 +01002088runs on test_CT {
2089 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002090 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002091 repeat;
2092 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01002093 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01002094 var octetstring without_plen :=
2095 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
2096 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02002097
2098 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
2099
Harald Welte68e495b2018-02-25 00:05:57 +01002100 if (match(rr, tr_PAGING_REQ1)) {
2101 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2102 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2103 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
2104 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2105 }
2106 } else if (match(rr, tr_PAGING_REQ2)) {
2107 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2108 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
2109 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2110 }
2111 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
2112 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2113 }
2114 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
2115 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2116 }
2117 } else if (match(rr, tr_PAGING_REQ3)) {
2118 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2119 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
2120 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2121 }
2122 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
2123 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2124 }
2125 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
2126 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2127 }
2128 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
2129 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2130 }
2131 }
2132 repeat;
2133 }
2134}
2135
2136type record PagingTestCfg {
2137 boolean combined_ccch,
2138 integer bs_ag_blks_res,
2139 float load_factor,
2140 boolean exp_load_ind,
2141 boolean exp_overload,
2142 boolean use_tmsi
2143}
2144
2145type record PagingTestState {
2146 integer num_paging_sent,
2147 integer num_paging_rcv_msgs,
2148 integer num_paging_rcv_ids,
2149 integer num_overload
2150}
2151
2152/* receive + ignore RSL RF RES IND */
2153altstep as_rsl_res_ind() runs on test_CT {
2154 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
2155 repeat;
2156 }
2157}
2158
2159/* Helper function for paging related testing */
2160private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
2161 f_init(testcasename());
2162 f_init_l1ctl();
2163 f_l1_tune(L1CTL);
2164
2165 var PagingTestState st := {
2166 num_paging_sent := 0,
2167 num_paging_rcv_msgs := 0,
2168 num_paging_rcv_ids := 0,
2169 num_overload := 0
2170 };
2171
2172 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
2173 var float max_pch_imsi_per_sec;
2174 if (cfg.use_tmsi) {
2175 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
2176 } else {
2177 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
2178 }
2179 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
2180 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002181 var float time_total := 20.0;
2182 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
2183 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01002184
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002185 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
2186 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01002187
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002188 timer T_itv := 0.0;
2189 T_itv.start;
2190 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01002191 alt {
2192 /* check for presence of CCCH LOAD IND (paging load) */
2193 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
2194 st.num_overload := st.num_overload + 1;
2195 repeat;
2196 }
2197 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002198 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01002199 }
2200 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
2201 log("Rx LOAD_IND");
2202 /* FIXME: analyze/verify interval + contents */
2203 repeat;
2204 }
2205 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02002206 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002207 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002208 [] T_itv.timeout {
2209 /* Send paging cmds based on elapsed time */
2210 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
2211 while (st.num_paging_sent < new_sent) {
2212 /* build mobile Identity */
2213 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2214 if (cfg.use_tmsi) {
2215 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2216 } else {
2217 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(st.num_paging_sent)));
2218 }
2219 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2220 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2221
2222 /* Send RSL PAGING COMMAND */
2223 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, st.num_paging_sent mod 4)));
2224
2225 st.num_paging_sent := st.num_paging_sent + 1;
2226 }
2227 if (st.num_paging_sent < pkt_total) {
2228 /* Wait for interval to next PAGING COMMAND */
2229 var float time_now := T_total.read;
2230 var float next_sched := int2float(st.num_paging_sent)*interval;
2231 if (next_sched > time_now) {
2232 T_itv.start(next_sched - time_now);
2233 } else {
2234 T_itv.start(0.0);
2235 }
2236 } else {
2237 /* We are done, no need to keep counting */
2238 T_total.stop;
2239 }
2240 }
2241 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01002242 [] as_rsl_res_ind();
2243 }
2244 }
2245
2246 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
2247 timer T_wait := 18.0;
2248 T_wait.start;
2249 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02002250 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002251 [] L1CTL.receive { repeat; }
2252 /* 65535 == empty paging queue, we can terminate*/
2253 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
2254 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
2255 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002256 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01002257 }
2258 [] as_rsl_res_ind();
2259 }
2260
2261 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
2262 " rcvd_ids=", st.num_paging_rcv_ids);
2263 return st;
2264}
2265
2266/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
2267 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2268 * - that CCCH LOAD IND (PCH) are being generated
2269 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2270testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002271 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002272 var PagingTestCfg cfg := {
2273 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002274 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002275 load_factor := 0.8,
2276 exp_load_ind := true,
2277 exp_overload := false,
2278 use_tmsi := false
2279 };
2280 var PagingTestState st := f_TC_paging(cfg);
2281 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002282 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2283 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002284 } else {
2285 setverdict(pass);
2286 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002287 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002288}
2289
2290/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
2291 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2292 * - that CCCH LOAD IND (PCH) are being generated
2293 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2294testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002295 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002296 var PagingTestCfg cfg := {
2297 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002298 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002299 load_factor := 0.8,
2300 exp_load_ind := true,
2301 exp_overload := false,
2302 use_tmsi := true
2303 };
2304 var PagingTestState st := f_TC_paging(cfg);
2305 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002306 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2307 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002308 } else {
2309 setverdict(pass);
2310 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002311 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002312}
2313
2314/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
2315 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2316 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2317 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2318testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002319 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002320 var PagingTestCfg cfg := {
2321 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002322 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002323 load_factor := 2.0,
2324 exp_load_ind := true,
2325 exp_overload := true,
2326 use_tmsi := false
2327 };
2328 var PagingTestState st := f_TC_paging(cfg);
2329 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
2330 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002331 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002332 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002333 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 +01002334 } else {
2335 setverdict(pass);
2336 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002337 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002338}
2339
2340/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
2341 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2342 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2343 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2344testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002345 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002346 var PagingTestCfg cfg := {
2347 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002348 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002349 load_factor := 2.0,
2350 exp_load_ind := true,
2351 exp_overload := true,
2352 use_tmsi := true
2353 };
2354 var PagingTestState st := f_TC_paging(cfg);
2355 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
2356 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002357 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002358 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002359 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 +01002360 } else {
2361 setverdict(pass);
2362 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002363 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002364}
2365
2366
Harald Welte93640c62018-02-25 16:59:33 +01002367/***********************************************************************
2368 * Immediate Assignment / AGCH
2369 ***********************************************************************/
Harald Weltee8d750e2018-06-10 21:41:35 +02002370const MobileAllocation c_MA_null := {
2371 len := 0,
2372 ma := ''B
2373}
Harald Welte93640c62018-02-25 16:59:33 +01002374
Harald Weltee8d750e2018-06-10 21:41:35 +02002375template (value) ChannelDescription ts_ChanDesc(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
2376 uint12_t arfcn := 871) := {
2377 chan_nr := chan_nr,
2378 tsc := tsc,
2379 h := false,
2380 arfcn := arfcn,
2381 maio_hsn := omit
2382}
2383
2384private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
2385 return int2str(num_tx) & " sent, "
2386 & int2str(num_rx) & " received, "
2387 & int2str(num_del) & " deleted";
2388}
2389
2390private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
2391 var L1ctlDlMessage l1_dl;
2392 timer T := 10.0;
2393 var integer num_tx := 0;
2394 var integer num_rx := 0;
2395 var integer num_del := 0;
2396 var charstring res_str;
2397 var float rx_ratio;
2398
Harald Welte68e495b2018-02-25 00:05:57 +01002399 f_init(testcasename());
Harald Weltee8d750e2018-06-10 21:41:35 +02002400 f_init_l1ctl();
2401 f_l1_tune(L1CTL);
2402
2403 for (var integer i := 0; i < num_total; i := i+1) {
2404 var ChannelDescription ch_desc := valueof(ts_ChanDesc(valueof(t_RslChanNr_SDCCH4(0, 0))));
2405 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
2406 var octetstring ia_enc := enc_GsmRrMessage(ia);
Harald Welte68e495b2018-02-25 00:05:57 +01002407 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02002408 num_tx := num_tx+1;
2409 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01002410 }
2411 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02002412 T.start;
2413 alt {
2414 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
2415 num_del := num_del+1;
2416 repeat;
2417 }
2418 [] RSL_CCHAN.receive {
2419 repeat;
2420 }
2421 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
2422 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2423 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
2424 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
2425 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002426 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02002427 } else {
2428 num_rx := num_rx+1;
2429 }
2430 repeat;
2431 }
2432 [] L1CTL.receive { repeat; }
2433 [] T.timeout { }
2434 }
2435 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
2436 log("AGCH test: " & res_str);
2437 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002438 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02002439 }
2440 rx_ratio := int2float(num_rx) / int2float(num_tx);
2441 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002442 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 +02002443 } else {
2444 setverdict(pass);
2445 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002446 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002447}
2448
Harald Weltee8d750e2018-06-10 21:41:35 +02002449/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
2450testcase TC_imm_ass_1000_20ms() runs on test_CT {
2451 f_TC_imm_ass(1000, 0.02, 0.25);
2452}
2453
2454/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
2455testcase TC_imm_ass_200_0ms() runs on test_CT {
2456 f_TC_imm_ass(200, 0.0, 0.05);
2457}
2458
2459/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
2460testcase TC_imm_ass_200_76ms() runs on test_CT {
2461 f_TC_imm_ass(150, 0.076, 1.00);
2462}
2463
2464
2465
Harald Welte48494ca2018-02-25 16:59:50 +01002466/***********************************************************************
2467 * BCCH
2468 ***********************************************************************/
2469
2470/* tuple of Frame Number + decoded SI */
2471type record SystemInformationFn {
2472 GsmFrameNumber frame_number,
2473 SystemInformation si
2474}
2475
2476/* an arbitrary-length vector of decoded SI + gsmtap header */
2477type record of SystemInformationFn SystemInformationVector;
2478
2479/* an array of SI-vectors indexed by TC value */
2480type SystemInformationVector SystemInformationVectorPerTc[8];
2481
2482/* determine if a given SI vector contains given SI type at least once */
2483function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2484 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2485 var integer fn_mod51 := arr[i].frame_number mod 51;
2486 if (not bcch_ext and fn_mod51 == 2 or
2487 bcch_ext and fn_mod51 == 6) {
2488 if (arr[i].si.header.message_type == key) {
2489 return true;
2490 }
2491 }
2492 }
2493 return false;
2494}
2495
2496/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
2497function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2498 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002499 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002500 }
2501}
2502
2503/* check if a given SI vector contains given SI type at least once on any TC */
2504function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
2505 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
2506 if (f_si_vecslot_contains(arr[tc], key) or
2507 f_si_vecslot_contains(arr[tc], key, true)) {
2508 return true;
2509 }
2510 }
2511 return false;
2512}
2513
2514/* determine if a given SI vector contains given SI type at least N of M times */
2515function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
2516 var integer count := 0;
2517 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002518 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01002519 }
2520 for (var integer i:= 0; i < m; i := i + 1) {
2521 var integer fn_mod51 := arr[i].frame_number mod 51;
2522 if (not bcch_ext and fn_mod51 == 2 or
2523 bcch_ext and fn_mod51 == 6) {
2524 if (arr[i].si.header.message_type == key) {
2525 count := count + 1;
2526 }
2527 }
2528 }
2529 if (count >= n) {
2530 return true;
2531 } else {
2532 return false;
2533 }
2534}
2535
2536/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
2537function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
2538 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002539 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002540 }
2541}
2542
2543/* determine if a given SI vector contains given SI type at least once */
2544function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2545 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2546 var integer fn_mod51 := arr[i].frame_number mod 51;
2547 if (not bcch_ext and fn_mod51 == 2 or
2548 bcch_ext and fn_mod51 == 6) {
2549 if (arr[i].si.header.message_type != key) {
2550 return false;
2551 }
2552 }
2553 }
2554 return true;
2555}
2556
2557/* ensure a given TC slot of the SI vector contains only given SI type */
2558function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2559 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002560 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002561 }
2562}
2563
2564/* SI configuration of cell, against which we validate actual SI messages */
2565type set SystemInformationConfig {
2566 boolean bcch_extended,
2567 boolean si1_present,
2568 boolean si2bis_present,
2569 boolean si2ter_present,
2570 boolean si2quater_present,
2571 boolean si7_present,
2572 boolean si8_present,
2573 boolean si9_present,
2574 boolean si13_present,
2575 boolean si13alt_present,
2576 boolean si15_present,
2577 boolean si16_present,
2578 boolean si17_present,
2579 boolean si2n_present,
2580 boolean si21_present,
2581 boolean si22_present
2582}
2583
2584/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
2585function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
2586 var integer i;
2587 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
2588 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002589 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01002590 }
2591 }
2592 if (cfg.si1_present) {
2593 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
2594 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
2595 * when TC = 0, it can assume that System Information Type 1 is not in use. */
2596 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2597 /* make sure *ALL* contain SI1 */
2598 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2599 }
2600 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
2601 /* iii) A SI 2 message will be sent at least every time TC = 1 */
2602 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
2603 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
2604 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
2605 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
2606
2607 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
2608 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
2609 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
2610 * consecutive occurrences of TC = 4. */
2611 if (cfg.si2bis_present and not cfg.si2ter_present) {
2612 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2613 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
2614 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
2615 } else if (cfg.si2ter_present and cfg.si2bis_present) {
2616 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2617 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
2618 }
2619
2620 if (cfg.si7_present or cfg.si8_present) {
2621 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
2622 * if System Information type 4 does not contain all information needed for cell
2623 * selection and reselection. */
2624 if (not cfg.bcch_extended) {
2625 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
2626 }
2627 if (cfg.si7_present) {
2628 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
2629 }
2630 if (cfg.si8_present) {
2631 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
2632 }
2633 }
2634
2635 if (cfg.si2quater_present) {
2636 /* iii) System information type 2 quater is sent if needed, as determined by the system
2637 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
2638 * and 2ter are used, otherwise it shall be sent at least once within any of 4
2639 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
2640 * within any of 4 consecutive occurrences of TC = 5. */
2641 if (not (cfg.bcch_extended)) {
2642 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
2643 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
2644 } else {
2645 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
2646 }
2647 } else {
2648 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
2649 }
2650 }
2651 if (cfg.si9_present) {
2652 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
2653 * in system information type 3 as defined in 3GPP TS 44.018. */
2654 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
2655 }
2656 if (cfg.si13_present) {
2657 /* vii) System Information type 13 is only related to the GPRS service. System Information
2658 * Type 13 need only be sent if GPRS support is indicated in one or more of System
2659 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
2660 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
2661 * In the case that the message is sent on the BCCH Norm, it is sent at least once
2662 * within any of 4 consecutive occurrences of TC=4. */
2663 if (not cfg.bcch_extended) {
2664 log("not-bccch-extended");
2665 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
2666 } else {
2667 log("bccch-extended");
2668 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
2669 }
2670 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002671 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002672 }
2673 }
2674 if (cfg.si16_present or cfg.si17_present) {
2675 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
2676 * should not be sent in a cell where network sharing is used (see rule xv). */
2677 if (cfg.si22_present) {
2678 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2679 }
2680 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002681 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002682 }
2683 if (not cfg.bcch_extended) {
2684 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
2685 }
2686 if (cfg.si16_present) {
2687 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
2688 }
2689 if (cfg.si17_present) {
2690 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
2691 }
2692 }
2693
2694 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
2695 * broadcast information. The frequency with which they are sent is determined by the
2696 * system operator. System Information type 9 identifies the scheduling of System
2697 * Information type 18 and 20 messages. */
2698
2699 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
2700 * Information Type 19 is present, then its scheduling shall be indicated in System
2701 * Information Type 9. */
2702
2703 if (cfg.si15_present) {
2704 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
2705 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
2706 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
2707 * 4 consecutive occurrences of TC = 1. */
2708 if (not cfg.bcch_extended) {
2709 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
2710 } else {
2711 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
2712 }
2713 }
2714 if (cfg.si13alt_present) {
2715 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
2716 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
2717 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
2718 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
2719 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
2720 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
2721 * of TC = 4. */
2722 if (cfg.si13_present) {
2723 testcase.stop("Error: Cannot have SI13alt and SI13");
2724 }
2725 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002726 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002727 }
2728 if (not cfg.bcch_extended) {
2729 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
2730 } else {
2731 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
2732 }
2733 }
2734 if (cfg.si2n_present) {
2735 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
2736 * as determined by the system operator. In the case that the message is sent on the
2737 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
2738 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
2739 * consecutive occurrences of TC = 4. */
2740 if (not cfg.bcch_extended) {
2741 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
2742 } else {
2743 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
2744 }
2745 }
2746 if (cfg.si21_present) {
2747 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
2748 * determined by the system operator. If Extended Access Barring is in use in the cell
2749 * then this message is sent at least once within any of 4 consecutive occurrences of
2750 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
2751 * cell then this message shall only be sent on BCCH Ext. */
2752 if (not cfg.bcch_extended) {
2753 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
2754 } else {
2755 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
2756 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002757 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01002758 }
2759 }
2760 }
2761 if (cfg.si22_present) {
2762 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
2763 * should not be sent in a cell where SoLSA is used (see rule viii). System
2764 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
2765 * =2 and TC=6. */
2766 if (cfg.si16_present or cfg.si17_present) {
2767 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2768 }
2769 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
2770 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002771 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002772 }
2773 if (not cfg.bcch_extended) {
2774 testcase.stop("Error: SI22 requires BCCH Extd!");
2775 } else {
2776 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
2777 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
2778 }
2779 }
2780}
2781
2782/* sample Systme Information for specified duration via L1CTL */
2783function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
2784 timer T := duration;
2785 var SystemInformationVectorPerTc si_per_tc;
2786 var L1ctlDlMessage l1_dl;
2787
2788 /* initialize all per-TC vectors empty */
2789 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2790 si_per_tc[i] := {};
2791 }
2792
2793 /* flush all previous L1 queued msgs */
2794 pt.clear;
2795
2796 T.start;
2797 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002798 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01002799 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2800 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
2801 log("Ignoring non-RR SI ", l1_dl);
2802 repeat;
2803 }
2804 var SystemInformationFn sig := {
2805 frame_number := l1_dl.dl_info.frame_nr,
2806 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
2807 }
2808 var integer tc := f_gsm_compute_tc(sig.frame_number);
2809 log("SI received at TC=", tc, ": ", sig.si);
2810 /* append to the per-TC bucket */
2811 si_per_tc[tc] := si_per_tc[tc] & { sig };
2812 repeat;
2813 }
2814 [] pt.receive { repeat; }
2815 [] T.timeout { }
2816 }
2817
2818 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2819 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
2820 }
2821 log("si_per_tc=", si_per_tc);
2822 return si_per_tc;
2823}
2824
2825/* helper function: Set given SI via RSL + validate scheduling.
2826 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
2827function f_TC_si_sched() runs on test_CT {
2828 var SystemInformationVectorPerTc si_per_tc;
2829 f_init_l1ctl();
2830 f_l1_tune(L1CTL);
2831
2832 /* Sample + Validate Scheduling */
2833 si_per_tc := f_l1_sample_si(L1CTL);
2834 f_validate_si_scheduling(si_cfg, si_per_tc);
2835
2836 setverdict(pass);
2837}
2838
2839testcase TC_si_sched_default() runs on test_CT {
2840 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01002841 /* 2+3+4 are mandatory and set in f_init() */
2842 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002843 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01002844}
2845
2846testcase TC_si_sched_1() runs on test_CT {
2847 f_init();
2848 si_cfg.si1_present := true;
2849 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002850 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002851 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002852}
2853
2854testcase TC_si_sched_2bis() runs on test_CT {
2855 f_init();
2856 si_cfg.si2bis_present := true;
2857 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2858 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002859 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002860}
2861
2862testcase TC_si_sched_2ter() runs on test_CT {
2863 f_init();
2864 si_cfg.si2ter_present := true;
2865 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2866 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002867 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002868}
2869
2870testcase TC_si_sched_2ter_2bis() runs on test_CT {
2871 f_init();
2872 si_cfg.si2bis_present := true;
2873 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2874 si_cfg.si2ter_present := true;
2875 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2876 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002877 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002878}
2879
2880testcase TC_si_sched_2quater() runs on test_CT {
2881 f_init();
2882 si_cfg.si2quater_present := true;
2883 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2884 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002885 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002886}
2887
2888testcase TC_si_sched_13() runs on test_CT {
2889 f_init();
2890 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002891 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002892 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002893 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002894}
2895
2896testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
2897 f_init();
2898 si_cfg.si2bis_present := true;
2899 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2900 si_cfg.si2ter_present := true;
2901 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2902 si_cfg.si2quater_present := true;
2903 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2904 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002905 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002906 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002907 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002908}
2909
2910
Harald Welte68e495b2018-02-25 00:05:57 +01002911testcase TC_bcch_info() runs on test_CT {
2912 f_init(testcasename());
2913 /* FIXME: enable / disable individual BCCH info */
2914 //ts_RSL_BCCH_INFO(si_type, info);
2915 /* expect no ERROR REPORT after either of them *
2916 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002917 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002918}
2919
Harald Welte93640c62018-02-25 16:59:33 +01002920/***********************************************************************
2921 * Low-Level Protocol Errors / ERROR REPORT
2922 ***********************************************************************/
2923
Harald Welte01d982c2018-02-25 01:31:40 +01002924private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
2925 timer T := 5.0;
2926 T.start;
2927 alt {
2928 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
2929 setverdict(pass);
2930 }
2931 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002932 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01002933 }
2934 [] RSL_CCHAN.receive {
2935 repeat;
2936 }
2937 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002938 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01002939 }
2940 }
2941}
2942
2943/* Provoke a protocol error (message too short) and match on ERROR REPORT */
2944testcase TC_rsl_protocol_error() runs on test_CT {
2945 f_init(testcasename());
2946 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2947 rsl.ies := omit;
2948 RSL_CCHAN.send(ts_RSL_UD(rsl));
2949
2950 f_exp_err_rep(RSL_ERR_PROTO);
2951}
2952
2953/* Provoke a mandatory IE error and match on ERROR REPORT */
2954testcase TC_rsl_mand_ie_error() runs on test_CT {
2955 f_init(testcasename());
2956
2957 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2958 rsl.ies := { rsl.ies[0] };
2959 RSL_CCHAN.send(ts_RSL_UD(rsl));
2960
2961 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
2962}
2963
2964/* Provoke an IE content error and match on ERROR REPORT */
2965testcase TC_rsl_ie_content_error() runs on test_CT {
2966 f_init(testcasename());
2967 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2968 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
2969 RSL_CCHAN.send(ts_RSL_UD(rsl));
2970
2971 f_exp_err_rep(RSL_ERR_IE_CONTENT);
2972}
2973
Harald Welteee25aae2019-05-19 14:32:37 +02002974/* attempt to activate channel with wrong RSL Message Discriminator IE */
2975function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
2976 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
2977 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
2978 RSL.send(rsl);
2979 f_rslem_unregister(0, g_chan_nr);
2980}
2981testcase TC_err_rep_wrong_mdisc() runs on test_CT {
2982 var ConnHdlr vc_conn;
2983 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
2984
2985 f_init(testcasename());
2986
2987 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
2988 vc_conn.done;
2989 f_exp_err_rep(RSL_ERR_MSG_DISCR);
2990
2991 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2992}
2993
2994/* Send messages with wrong message type */
2995function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
2996 var template (value) RSL_Message rsl_tx;
2997 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
2998 rsl_tx.msg_type := RSL_MT_NOT_CMD;
2999 RSL.send(rsl_tx);
3000 f_rslem_unregister(0, g_chan_nr);
3001}
3002function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
3003 var template (value) RSL_Message rsl_tx;
3004 /* we first have to activate the dedicated channel */
3005 f_rsl_chan_act(g_pars.chan_mode);
3006 /* ... to then send an invalid RLL message */
3007 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
3008 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
3009 RSL.send(rsl_tx);
3010 f_rslem_unregister(0, g_chan_nr);
3011}
3012testcase TC_err_rep_wrong_msg_type() runs on test_CT {
3013 var ConnHdlr vc_conn;
3014 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3015 var template (value) RSL_Message rsl_tx;
3016
3017 f_init(testcasename());
3018
3019 /* Common Channel with wrong message type */
3020 RSL_CCHAN.clear;
3021 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3022 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
3023 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3024 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3025
3026 /* TRX Management */
3027 RSL_CCHAN.clear;
3028 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
3029 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
3030 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3031 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3032
3033 /* Dedicated Channel */
3034 RSL_CCHAN.clear;
3035 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
3036 vc_conn.done;
3037 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3038
3039 /* RLL */
3040 RSL_CCHAN.clear;
3041 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
3042 vc_conn.done;
3043 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3044}
3045
3046/* Send messages in wrong sequence (RLL to an inactive lchan) */
3047function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
3048 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
3049 f_rslem_unregister(0, g_chan_nr);
3050}
3051testcase TC_err_rep_wrong_sequence() runs on test_CT {
3052 var ConnHdlr vc_conn;
3053 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3054
3055 f_init(testcasename());
3056
3057 RSL_CCHAN.clear;
3058 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
3059 vc_conn.done;
3060 f_exp_err_rep(RSL_ERR_MSG_SEQ);
3061}
3062
Harald Welte93640c62018-02-25 16:59:33 +01003063/***********************************************************************
3064 * IPA CRCX/MDCX/DLCS media stream handling
3065 ***********************************************************************/
3066
Harald Weltea871a382018-02-25 02:03:14 +01003067/* Send IPA DLCX to inactive lchan */
3068function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01003069 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3070 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01003071}
3072testcase TC_ipa_dlcx_not_active() runs on test_CT {
3073 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3074 f_init(testcasename());
3075 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
3076 vc_conn.done;
3077}
Harald Welte68e495b2018-02-25 00:05:57 +01003078
Harald Weltea3f1df92018-02-25 12:49:55 +01003079/* Send IPA CRCX twice to inactive lchan */
3080function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
3081 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3082 "IPA CRCX ACK");
3083 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
3084 "IPA CRCX NACK");
3085}
3086testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
3087 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3088 f_init(testcasename());
3089 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
3090 vc_conn.done;
3091}
3092
3093/* Regular sequence of CRCX/MDCX/DLCX */
3094function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3095 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3096 "IPA CRCX ACK");
3097 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3098 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3099 var uint7_t rtp_pt2 := f_rnd_int(127);
3100 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3101 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3102 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3103 "IPA MDCX ACK");
3104 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3105 "IPA DLCX ACK");
3106}
3107testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
3108 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3109 f_init(testcasename());
3110 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
3111 vc_conn.done;
3112}
3113
Harald Welte3ae11da2018-02-25 13:36:06 +01003114/* Sequence of CRCX, 2x MDCX, DLCX */
3115function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3116 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3117 "IPA CRCX ACK");
3118 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3119 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3120 var uint7_t rtp_pt2 := f_rnd_int(127);
3121 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3122 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3123 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3124 "IPA MDCX ACK");
3125 /* Second MDCX */
3126 remote_ip := f_rnd_int(c_UINT32_MAX);
3127 remote_port := f_rnd_int(c_UINT16_MAX);
3128 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3129 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3130 "IPA MDCX ACK");
3131 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3132 "IPA DLCX ACK");
3133}
3134testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
3135 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3136 f_init(testcasename());
3137 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
3138 vc_conn.done;
3139}
3140
Harald Welte9912eb52018-02-25 13:30:15 +01003141/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
3142function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
3143 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
3144 "IPA CRCX NACK");
3145}
3146testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
3147 var ConnHdlrPars pars;
3148 var ConnHdlr vc_conn;
3149 f_init(testcasename());
3150
3151 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
3152 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3153 vc_conn.done;
3154
3155 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
3156 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3157 vc_conn.done;
3158}
3159
Harald Weltea3f1df92018-02-25 12:49:55 +01003160
Harald Welte883340c2018-02-28 18:59:29 +01003161/***********************************************************************
3162 * PCU Socket related tests
3163 ***********************************************************************/
3164
Harald Welte07bd2d22019-05-25 11:03:30 +02003165/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003166friend 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 +01003167runs on test_CT {
3168 timer T := 3.0;
3169
3170 /* we don't expect any RTS.req before PDCH are active */
3171 T.start;
3172 alt {
3173 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003174 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01003175 }
3176 [] PCU.receive { repeat; }
3177 [] T.timeout { }
3178 }
3179
3180 /* Send PDCH activate request for known PDCH timeslot */
3181 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
3182
3183 /* we now expect RTS.req for this timeslot (only) */
3184 T.start;
3185 alt {
3186 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
3187 setverdict(pass);
3188 }
3189 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3190 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003191 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01003192 }
3193 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003194 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01003195 }
3196 [] PCU.receive { repeat; }
3197 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003198 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003199 }
3200 [not exp_success] T.timeout {
3201 setverdict(pass);
3202 }
3203 }
3204}
3205
Harald Welte07bd2d22019-05-25 11:03:30 +02003206/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003207friend 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 +01003208runs on test_CT {
3209 timer T := 3.0;
3210
3211 /* Send PDCH activate request for known PDCH timeslot */
3212 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
3213
3214 PCU.clear;
3215 /* we now expect no RTS.req for this timeslot */
3216 T.start;
3217 alt {
3218 [] 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 +02003219 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003220 }
3221 [] PCU.receive { repeat; }
3222 [] T.timeout {
3223 setverdict(pass);
3224 }
3225 }
3226}
3227
Harald Weltead033dc2019-05-25 17:28:16 +02003228friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003229 f_init();
3230 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
3231}
3232
Harald Welte883340c2018-02-28 18:59:29 +01003233/* PDCH activation via PCU socket; check for presence of RTS.req */
3234testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003235 f_init_pcu_test();
3236
Harald Welte883340c2018-02-28 18:59:29 +01003237 f_TC_pcu_act_req(0, 0, 7, true);
3238}
3239
3240/* PDCH activation via PCU socket on non-PDCU timeslot */
3241testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003242 f_init_pcu_test();
3243
Harald Welte883340c2018-02-28 18:59:29 +01003244 f_TC_pcu_act_req(0, 0, 1, false);
3245}
3246
3247/* PDCH activation via PCU socket on wrong BTS */
3248testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003249 f_init_pcu_test();
3250
Harald Welte883340c2018-02-28 18:59:29 +01003251 f_TC_pcu_act_req(23, 0, 7, false);
3252}
3253
3254/* PDCH activation via PCU socket on wrong TRX */
3255testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003256 f_init_pcu_test();
3257
Harald Welte883340c2018-02-28 18:59:29 +01003258 f_TC_pcu_act_req(0, 23, 7, false);
3259}
3260
3261/* PDCH deactivation via PCU socket; check for absence of RTS.req */
3262testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003263 f_init_pcu_test();
3264
Harald Welte883340c2018-02-28 18:59:29 +01003265 /* Activate PDCH */
3266 f_TC_pcu_act_req(0, 0, 7, true);
3267 f_sleep(1.0);
3268 /* and De-Activate again */
3269 f_TC_pcu_deact_req(0, 0, 7);
3270}
3271
3272/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
3273testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003274 f_init_pcu_test();
3275
Harald Welte883340c2018-02-28 18:59:29 +01003276 f_TC_pcu_deact_req(0, 0, 1);
3277}
3278
3279/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
3280testcase TC_pcu_ver_si13() runs on test_CT {
3281 const octetstring si13 := '00010203040506070909'O;
3282 var PCUIF_send_data sd;
3283 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01003284 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003285
3286 /* Set SI13 via RSL */
3287 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01003288
Harald Welte883340c2018-02-28 18:59:29 +01003289 T.start;
3290 alt {
3291 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
3292 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
3293 setverdict(pass);
3294 } else {
3295 repeat;
3296 }
3297 }
3298 [] PCU.receive { repeat; }
3299 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003300 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01003301 }
3302 }
3303}
3304
3305private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
3306
3307/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02003308friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01003309 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
3310runs on test_CT
3311{
3312 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
3313 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
3314}
3315
3316/* 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 +02003317friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
3318 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01003319runs on test_CT
3320{
3321 var PCUIF_send_data sd;
3322
3323 timer T := 3.0;
3324 T.start;
3325 alt {
3326 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3327 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
3328 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
3329 sd.data.u.rts_req.fn, sapi, data);
3330 }
3331 [] PCU.receive { repeat; }
3332 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003333 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01003334 }
3335 }
3336}
3337
3338/* Send DATA.req on invalid BTS */
3339testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003340 var TfiUsfArr tua := f_TfiUsfArrInit();
3341 var octetstring data := '0000'O & f_rnd_octstring(21);
3342
3343 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003344
Harald Welte883340c2018-02-28 18:59:29 +01003345 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003346 f_TfiUsfArrSet(tua, 7, 0);
3347 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3348 f_sleep(1.0);
3349
3350 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003351}
3352
3353/* Send DATA.req on invalid TRX */
3354testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003355 var TfiUsfArr tua := f_TfiUsfArrInit();
3356 var octetstring data := '0000'O & f_rnd_octstring(21);
3357
3358 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003359
Harald Welte883340c2018-02-28 18:59:29 +01003360 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003361 f_TfiUsfArrSet(tua, 7, 0);
3362 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3363 f_sleep(1.0);
3364
3365 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003366}
3367
3368/* Send DATA.req on invalid timeslot */
3369testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003370 var TfiUsfArr tua := f_TfiUsfArrInit();
3371 var octetstring data := '0000'O & f_rnd_octstring(21);
3372
3373 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003374
Harald Welte883340c2018-02-28 18:59:29 +01003375 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003376 f_TfiUsfArrSet(tua, 7, 0);
3377 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3378 f_sleep(1.0);
3379
3380 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003381}
3382
3383/* Send DATA.req on timeslot that hasn't been activated */
3384testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003385 var TfiUsfArr tua := f_TfiUsfArrInit();
3386 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01003387
Harald Welte7162a612019-05-26 12:56:09 +02003388 f_virtphy_common();
3389
3390 f_TfiUsfArrSet(tua, 7, 0);
3391 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3392 f_sleep(1.0);
3393
3394 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003395}
3396
Harald Weltead033dc2019-05-25 17:28:16 +02003397private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02003398 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
3399 boolean wait_rts := true)
3400runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003401 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02003402 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02003403
3404 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02003405 if (wait_rts) {
3406 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
3407 } else {
3408 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
3409 }
Harald Weltead033dc2019-05-25 17:28:16 +02003410
3411 T.start;
3412 alt {
Harald Welte7162a612019-05-26 12:56:09 +02003413 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02003414 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
3415 setverdict(pass);
3416 }
Harald Welte7162a612019-05-26 12:56:09 +02003417 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
3418 setverdict(fail, "Received unexpected ", rx_dl);
3419 }
Harald Weltead033dc2019-05-25 17:28:16 +02003420 [] L1CTL.receive {
3421 repeat;
3422 }
Harald Welte7162a612019-05-26 12:56:09 +02003423 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02003424 setverdict(fail, "Timeout waiting for ", data);
3425 }
Harald Welte7162a612019-05-26 12:56:09 +02003426 [not expect_data] T.timeout {
3427 setverdict(pass);
3428 }
Harald Weltead033dc2019-05-25 17:28:16 +02003429 }
3430}
3431
3432private function f_disable_dynamic_ts() runs on test_CT
3433{
3434 f_init_vty_bsc();
3435 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
3436 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
3437 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
3438 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01003439 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02003440}
3441
3442private function f_virtphy_common() runs on test_CT {
3443 f_disable_dynamic_ts();
3444 f_init_l1ctl();
3445 f_l1_tune(L1CTL);
3446}
3447
3448testcase TC_pcu_data_req_pdtch() runs on test_CT {
3449 var TfiUsfArr tua := f_TfiUsfArrInit();
3450 var octetstring data := '0000'O & f_rnd_octstring(21);
3451
3452 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003453
Harald Welte883340c2018-02-28 18:59:29 +01003454 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003455 f_TfiUsfArrSet(tua, 7, 0);
3456 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3457 f_sleep(1.0);
3458
3459 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01003460}
3461
3462testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003463 var TfiUsfArr tua := f_TfiUsfArrInit();
3464 var octetstring data := '0000'O & f_rnd_octstring(21);
3465
3466 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003467
Harald Welte883340c2018-02-28 18:59:29 +01003468 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003469 f_TfiUsfArrSet(tua, 7, 0);
3470 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3471 f_sleep(1.0);
3472
3473 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01003474}
3475
3476/* Send AGCH from PCU; check it appears on Um side */
3477testcase TC_pcu_data_req_agch() runs on test_CT {
3478 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01003479 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003480 f_init_l1ctl();
3481 f_l1_tune(L1CTL);
3482
3483 f_TC_pcu_act_req(0, 0, 7, true);
3484 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
3485
3486 T.start;
3487 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003488 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01003489 setverdict(pass);
3490 }
3491 [] L1CTL.receive { repeat; }
3492 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003493 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003494 }
3495 }
3496}
3497
Harald Welte928622b2019-05-26 13:22:59 +02003498/* Send AGCH from PCU; check it appears on Um side */
3499testcase TC_pcu_data_req_pch() runs on test_CT {
3500 timer T := 3.0;
3501 f_init_pcu_test();
3502 f_init_l1ctl();
3503 f_l1_tune(L1CTL);
3504
3505 f_TC_pcu_act_req(0, 0, 7, true);
3506 /* three characters prefix: last 3 digits of IMSI as ASCII */
3507 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
3508
3509 T.start;
3510 alt {
3511 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
3512 setverdict(pass);
3513 }
3514 [] L1CTL.receive { repeat; }
3515 [] T.timeout {
3516 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
3517 }
3518 }
3519}
3520
Harald Welte883340c2018-02-28 18:59:29 +01003521/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
3522testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
3523 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01003524 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003525 f_init_l1ctl();
3526 f_l1_tune(L1CTL);
3527
3528 /* append 3 last imsi digits so BTS can compute pagng group */
3529 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
3530
3531 timer T := 0.5;
3532 T.start;
3533 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003534 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01003535 /* TODO: verify paging group */
3536 setverdict(pass);
3537 }
3538 [] L1CTL.receive { repeat; }
3539 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003540 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003541 }
3542 }
3543}
3544
3545/* Send RACH from Um side, expect it to show up on PCU socket */
3546testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003547 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003548 f_init_l1ctl();
3549 f_l1_tune(L1CTL);
3550
3551 var GsmFrameNumber fn_last := 0;
3552 for (var integer i := 0; i < 1000; i := i+1) {
3553 var OCT1 ra := f_rnd_ra_ps();
3554 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
3555 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003556 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01003557 }
3558 fn_last := fn;
3559
3560 timer T := 2.0;
3561 T.start;
3562 alt {
3563 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
3564 T.stop;
3565 }
3566 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003567 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003568 }
3569 [] PCU.receive { repeat; }
3570 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003571 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003572 }
3573 }
3574 }
3575 setverdict(pass);
3576}
3577
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07003578/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
3579 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
3580testcase TC_pcu_ext_rach_content() runs on test_CT {
3581 var template PCUIF_Message pcu_rach_ind;
3582 var GsmFrameNumber fn_last := 0;
3583 var L1ctlRachSynchSeq synch_seq;
3584 var PCUIF_BurstType pcu_bt;
3585 var GsmFrameNumber fn;
3586 var BIT11 ra11;
3587
3588 f_init_pcu_test();
3589 f_init_l1ctl();
3590 f_l1_tune(L1CTL);
3591
3592 for (var integer i := 0; i < 1000; i := i+1) {
3593 /* We need to test both TS1 & TS2 */
3594 if (i rem 2 == 0) {
3595 synch_seq := RACH_SYNCH_SEQ_TS1;
3596 pcu_bt := BURST_TYPE_1;
3597 } else {
3598 synch_seq := RACH_SYNCH_SEQ_TS2;
3599 pcu_bt := BURST_TYPE_2;
3600 }
3601
3602 ra11 := f_rnd_ra11_ps();
3603 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
3604 if (fn == fn_last) {
3605 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3606 "Two RACH in same FN?!?");
3607 }
3608 fn_last := fn;
3609
3610 /* Compose the expected message */
3611 pcu_rach_ind := tr_PCUIF_RACH_IND(
3612 bts_nr := 0,
3613 ra := bit2int(ra11),
3614 is_11bit := 1,
3615 burst_type := pcu_bt,
3616 fn := fn);
3617
3618 timer T := 2.0;
3619 T.start;
3620 alt {
3621 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
3622 T.stop;
3623 }
3624 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
3625 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
3626 }
3627 [] PCU.receive { repeat; }
3628 [] T.timeout {
3629 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
3630 }
3631 }
3632 }
3633 setverdict(pass);
3634}
3635
Harald Welte883340c2018-02-28 18:59:29 +01003636private function f_pad_oct(octetstring str, integer len, OCT1 pad) return octetstring {
3637 var integer strlen := lengthof(str);
3638 for (var integer i := 0; i < len-strlen; i := i+1) {
3639 str := str & pad;
3640 }
3641 return str;
3642}
3643
3644/* Send PAGING via RSL, expect it to shw up on PCU socket */
3645testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003646 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003647
3648 for (var integer i := 0; i < 100; i := i+1) {
3649 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
3650 timer T := 3.0;
3651 if (i < 50) {
3652 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
3653 } else {
3654 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
3655 }
3656 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
3657 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
3658 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
3659
3660 /* Send RSL PAGING COMMAND */
3661 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
3662 T.start;
3663 alt {
3664 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
3665 }
3666 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003667 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003668 }
3669 [] PCU.receive { repeat; }
3670 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003671 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003672 }
3673 }
3674 }
3675 setverdict(pass);
3676}
3677
Harald Welted66c9b82019-05-25 09:03:15 +02003678/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
3679testcase TC_pcu_time_ind() runs on test_CT {
3680 var PCUIF_send_data pcu_sd;
3681 var integer num_time_ind := 0;
3682 var integer first_fn, last_fn;
3683 var float test_duration := 5.0;
3684 timer T;
3685
3686 f_init_pcu_test();
3687 f_TC_pcu_act_req(0, 0, 7, true);
3688
3689 PCU.clear;
3690 T.start(test_duration);
3691 alt {
3692 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
3693 num_time_ind := num_time_ind + 1;
3694 if (not isbound(first_fn)) {
3695 first_fn := pcu_sd.data.u.time_ind.fn;
3696 }
3697 last_fn := pcu_sd.data.u.time_ind.fn;
3698 repeat;
3699 }
3700 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
3701 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
3702 repeat;
3703 }
3704 [] PCU.receive {
3705 repeat;
3706 }
3707 [] T.timeout {}
3708 }
3709 var integer fn_expired := last_fn - first_fn;
3710 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
3711
3712 /* verify the number of frames expired matches our expectation */
3713 const float c_GSM_FN_DURATION_MS := 4.61538;
3714 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
3715 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 10);
3716 if (not match(fn_expired, t_fn_expected)) {
3717 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
3718 }
3719
3720 /* There are three TIME.ind in every fn MOD 13 */
3721 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
3722 /* Add some tolerance */
3723 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
3724 if (not match(num_time_ind, t_time_ind_exp)) {
3725 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
3726 }
3727
3728 setverdict(pass);
3729}
3730
Harald Welte4832c862019-05-25 14:57:18 +02003731/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
3732testcase TC_pcu_rts_req() runs on test_CT {
3733 var PCUIF_send_data pcu_sd;
3734 var integer first_fn, last_fn;
3735 var integer num_rts_pdtch := 0;
3736 var integer num_rts_ptcch := 0;
3737 var float test_duration := 5.0;
3738 timer T;
3739
3740 f_init_pcu_test();
3741 f_TC_pcu_act_req(0, 0, 7, true);
3742
3743 PCU.clear;
3744 T.start(test_duration);
3745 alt {
3746 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
3747 -> value pcu_sd {
3748 num_rts_pdtch := num_rts_pdtch + 1;
3749 if (not isbound(first_fn)) {
3750 first_fn := pcu_sd.data.u.rts_req.fn;
3751 }
3752 last_fn := pcu_sd.data.u.rts_req.fn;
3753 repeat;
3754 }
3755 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
3756 -> value pcu_sd {
3757 num_rts_ptcch := num_rts_ptcch + 1;
3758 if (not isbound(first_fn)) {
3759 first_fn := pcu_sd.data.u.rts_req.fn;
3760 }
3761 last_fn := pcu_sd.data.u.rts_req.fn;
3762 repeat;
3763 }
3764 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
3765 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
3766 repeat;
3767 }
3768 [] PCU.receive {
3769 repeat;
3770 }
3771 [] T.timeout {}
3772 }
3773 var integer fn_expired := last_fn - first_fn;
3774 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
3775 ", num_rts_ptcch=", num_rts_ptcch);
3776
3777 /* verify the number of frames expired matches our expectation */
3778 const float c_GSM_FN_DURATION_MS := 4.61538;
3779 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
3780 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 10);
3781 if (not match(fn_expired, t_fn_expected)) {
3782 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
3783 }
3784
3785 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
3786 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
3787 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
3788 if (not match(num_rts_ptcch, t_ptcch_exp)) {
3789 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
3790 t_ptcch_exp);
3791 }
3792
3793 /* We have 12 PDTCH blocks every 52-multiframe */
3794 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
3795 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
3796 if (not match(num_rts_pdtch, t_pdtch_exp)) {
3797 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
3798 t_pdtch_exp);
3799 }
3800
3801 setverdict(pass);
3802}
3803
Harald Welte07bd2d22019-05-25 11:03:30 +02003804/* test for generating Abis side OML ALERT from the PCU */
3805testcase TC_pcu_oml_alert() runs on test_CT {
3806 var PCUIF_send_data pcu_sd;
3807 var integer num_time_ind := 0;
3808 var integer first_fn, last_fn;
3809 var float test_duration := 5.0;
3810 timer T;
3811
3812 f_init_pcu_test();
3813 f_TC_pcu_act_req(0, 0, 7, true);
3814
3815 /* re-connect CTRL port from BTS to BSC */
3816 f_ipa_ctrl_stop();
3817 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
3818
3819 /* Send that OML Alert */
3820 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
3821
3822 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
3823 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
3824 setverdict(pass);
3825}
3826
Harald Welteeaa9a862019-05-26 23:01:08 +02003827template (value) PDU_ML3_MS_NW ts_RRM_GprsSuspReq(template (value) OCT4 tlli,
3828 template (value) RoutingAreaIdentificationV rai,
3829 template (value) OCT1 cause) := {
3830 discriminator := '0000'B, /* overwritten */
3831 tiOrSkip := {
3832 skipIndicator := '0000'B
3833 },
3834 msgs := {
3835 rrm := {
3836 gPRS_suspensionRequest := {
3837 messageType := '00110100'B,
3838 tLLI := tlli,
3839 routingAreaIdentification := rai,
3840 suspensionCause := cause,
3841 service_Support := omit
3842 }
3843 }
3844 }
3845}
3846
3847/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
3848private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
3849 var PCUIF_Message first_info;
3850 var integer pcu_conn_id := -1;
3851 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3852 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
3853 var OCT4 tlli := '01020304'O;
3854 var OCT1 cause := '23'O;
3855 timer T := 5.0;
3856
3857 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3858
3859 f_l1_tune(L1CTL);
3860 RSL.clear;
3861
3862 f_est_dchan();
3863 L1CTL.clear;
3864
3865 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
3866
3867 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
3868 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
3869 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
3870
3871 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
3872 T.start;
3873 alt {
3874 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
3875 setverdict(pass);
3876 }
3877 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
3878 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
3879 }
3880 [] PCU.receive {
3881 repeat;
3882 }
3883 [] T.timeout {
3884 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
3885 }
3886 }
3887}
3888testcase TC_pcu_rr_suspend() runs on test_CT {
3889 var ConnHdlrPars pars;
3890 var ConnHdlr vc_conn;
3891
3892 f_init();
3893
3894 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
3895 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
3896 vc_conn.done;
3897}
Harald Welte07bd2d22019-05-25 11:03:30 +02003898
Harald Welted66c9b82019-05-25 09:03:15 +02003899
Harald Welte3d04ae62018-04-04 20:29:05 +02003900/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02003901 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02003902 ***********************************************************************/
3903
3904private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3905runs on ConnHdlr {
3906 var PCUIF_send_data sd;
3907 /* Expect BTS to immediately acknowledge activation as PDCH */
3908 PCU.clear;
3909 f_rsl_chan_act(g_pars.chan_mode);
3910 /* expect INFO_IND on PCU interface listing TS as PDCH */
3911 alt {
3912 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3913 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 +02003914 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02003915 }
3916 }
3917 [] PCU.receive { repeat; }
3918 }
3919 /* try to activate this PDCH from the PCU point of view */
3920 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3921 /* FIXME: is there a response? */
3922}
3923
3924private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3925runs on ConnHdlr {
3926 var PCUIF_send_data sd;
3927 /* Send RSL CHAN REL (deactivate) */
3928 PCU.clear;
3929 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
3930 /* expect BTS to ask PCU to deactivate the channel */
3931 alt {
3932 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3933 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 +02003934 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02003935 }
3936 }
3937 [] PCU.receive { repeat; }
3938 }
3939 /* Emulate PCU asking BTS to deactivate PDCH */
3940 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3941 alt {
3942 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
3943 setverdict(pass);
3944 }
3945 [] RSL.receive { repeat; }
3946 }
3947}
3948
3949/* Activate Osmocom-style dynamic PDCH from BSC side */
3950function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
3951 var PCUIF_Message first_info;
3952 var integer ts_nr := g_chan_nr.tn;
3953 var integer trx_nr := 0;
3954 var integer bts_nr := 0;
3955 var integer pcu_conn_id := -1;
3956
3957 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3958
3959 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3960 f_sleep(3.0);
3961 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3962 setverdict(pass);
3963}
3964testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
3965 var ConnHdlrPars pars;
3966 var ConnHdlr vc_conn;
3967 f_init(testcasename());
3968
3969 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3970 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
3971 vc_conn.done;
3972}
3973
3974/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
3975function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
3976 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02003977 var integer pcu_conn_id := -1;
3978
3979 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3980
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02003981 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
3982 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
3983 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02003984 setverdict(pass);
3985}
3986testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
3987 var ConnHdlrPars pars;
3988 var ConnHdlr vc_conn;
3989 f_init(testcasename());
3990
3991 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3992 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
3993 vc_conn.done;
3994}
3995
3996/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
3997function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
3998 var PCUIF_Message first_info;
3999 var integer ts_nr := g_chan_nr.tn;
4000 var integer trx_nr := 0;
4001 var integer bts_nr := 0;
4002 var integer pcu_conn_id := -1;
4003
4004 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4005
4006 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02004007 /* Send a second Chan Activ and expect it to be NACKed */
4008 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
4009 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02004010 setverdict(pass);
4011}
4012testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
4013 var ConnHdlrPars pars;
4014 var ConnHdlr vc_conn;
4015 f_init(testcasename());
4016
4017 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4018 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
4019 vc_conn.done;
4020}
4021
4022/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
4023function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
4024 var PCUIF_Message first_info;
4025 var integer ts_nr := g_chan_nr.tn;
4026 var integer trx_nr := 0;
4027 var integer bts_nr := 0;
4028 var integer pcu_conn_id := -1;
4029 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
4030
4031 /* register for the TCH/F channel number */
4032 f_rslem_register(0, chan_nr);
4033
4034 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4035
4036 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
4037 "RSL CHAN ACT");
4038 setverdict(pass);
4039}
4040testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
4041 var ConnHdlrPars pars;
4042 var ConnHdlr vc_conn;
4043 f_init(testcasename());
4044
4045 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4046 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
4047 vc_conn.done;
4048}
4049
4050/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
4051function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
4052 var PCUIF_Message first_info;
4053 var integer ts_nr := g_chan_nr.tn;
4054 var integer trx_nr := 0;
4055 var integer bts_nr := 0;
4056 var integer pcu_conn_id := -1;
4057 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
4058 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
4059
4060 /* register for the TCH/H channel numbers */
4061 f_rslem_register(0, chan_nr[0]);
4062 f_rslem_register(0, chan_nr[1]);
4063
4064 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4065
4066 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
4067 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
4068 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
4069 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
4070 setverdict(pass);
4071}
4072testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
4073 var ConnHdlrPars pars;
4074 var ConnHdlr vc_conn;
4075 f_init(testcasename());
4076
4077 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4078 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
4079 vc_conn.done;
4080}
4081
Harald Welte9bbbfb52018-04-05 09:33:19 +02004082/***********************************************************************
4083 * IPA Style Dynamic Timeslot Support
4084 ***********************************************************************/
4085
4086private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4087runs on ConnHdlr {
4088 var PCUIF_send_data sd;
4089 /* Expect BTS to immediately acknowledge activation as PDCH */
4090 PCU.clear;
4091 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
4092 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004093 timer T_wait := 2.0;
4094 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004095 alt {
4096 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4097 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 +01004098 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
4099 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
4100 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004101 }
4102 }
4103 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004104 [] T_wait.timeout {
4105 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4106 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
4107 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02004108 }
4109 /* try to activate this PDCH from the PCU point of view */
4110 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4111 /* FIXME: is there a response? */
4112
4113 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
4114}
4115
4116private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4117runs on ConnHdlr {
4118 var PCUIF_send_data sd;
4119 /* Send RSL CHAN REL (deactivate) */
4120 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
4121 PCU.clear;
4122 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004123 timer T_wait := 2.0;
4124 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004125 alt {
4126 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4127 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 +01004128 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
4129 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
4130 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004131 }
4132 }
4133 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004134 [] T_wait.timeout {
4135 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4136 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
4137 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02004138 }
4139 /* Emulate PCU asking BTS to deactivate PDCH */
4140 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4141 alt {
4142 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
4143 setverdict(pass);
4144 }
4145 [] RSL.receive { repeat; }
4146 }
4147}
4148
4149/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
4150function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
4151 var PCUIF_Message first_info;
4152 var integer ts_nr := g_chan_nr.tn;
4153 var integer trx_nr := 0;
4154 var integer bts_nr := 0;
4155 var integer pcu_conn_id := -1;
4156
4157 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4158
4159 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4160 f_sleep(3.0);
4161 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4162
4163 setverdict(pass);
4164
4165}
4166testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
4167 var ConnHdlrPars pars;
4168 var ConnHdlr vc_conn;
4169 f_init();
4170
4171 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4172 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
4173 vc_conn.done;
4174}
4175
4176/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
4177function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
4178 var PCUIF_Message first_info;
4179 var integer ts_nr := g_chan_nr.tn;
4180 var integer trx_nr := 0;
4181 var integer bts_nr := 0;
4182 var integer pcu_conn_id := -1;
4183
4184 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4185
4186 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4187 "RSL CHAN ACT");
4188 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4189 "RF CHAN REL", true);
4190 setverdict(pass);
4191}
4192testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
4193 var ConnHdlrPars pars;
4194 var ConnHdlr vc_conn;
4195 f_init(testcasename());
4196
4197 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4198 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
4199 vc_conn.done;
4200}
4201
4202/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
4203function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
4204 var PCUIF_Message first_info;
4205 var integer ts_nr := g_chan_nr.tn;
4206 var integer trx_nr := 0;
4207 var integer bts_nr := 0;
4208 var integer pcu_conn_id := -1;
4209
4210 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4211
4212 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4213 "RSL CHAN ACT");
4214
4215 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
4216 alt {
4217 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
4218 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004219 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02004220 }
4221 [] RSL.receive { repeat; }
4222 }
4223
4224 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4225 "RF CHAN REL", true);
4226 setverdict(pass);
4227}
4228testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
4229 var ConnHdlrPars pars;
4230 var ConnHdlr vc_conn;
4231 f_init(testcasename());
4232
4233 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4234 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
4235 vc_conn.done;
4236}
4237
4238/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
4239function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
4240 var PCUIF_Message first_info;
4241 var integer ts_nr := g_chan_nr.tn;
4242 var integer trx_nr := 0;
4243 var integer bts_nr := 0;
4244 var integer pcu_conn_id := -1;
4245
4246 /* register for the TCH/F channel number */
4247 f_rslem_register(0, g_chan_nr);
4248
4249 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4250
4251 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4252
4253 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
4254 "RSL CHAN ACT");
4255
4256 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4257
4258 setverdict(pass);
4259}
4260testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
4261 var ConnHdlrPars pars;
4262 var ConnHdlr vc_conn;
4263 f_init(testcasename());
4264
4265 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4266 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
4267 vc_conn.done;
4268}
4269
4270
Harald Welte0472ab42018-03-12 15:02:26 +01004271/***********************************************************************
4272 * LAPDm / RLL related
4273 ***********************************************************************/
4274
4275private function f_tx_lapdm(template (value) LapdmFrame l,
4276 template (value) RslLinkId link_id) runs on ConnHdlr {
4277 var octetstring l2 := enc_LapdmFrame(valueof(l));
4278 if (valueof(link_id.c) == SACCH) {
4279 /* prepend dummy L1 header */
Pau Espin Pedrola0fb42a2018-10-10 15:56:39 +02004280 var L1ctlDataReq l1hl2 := {
4281 l1header := valueof(ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta)),
4282 l2_payload := f_pad_oct(l2, 21, '2B'O)
4283 }
4284 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, link_id, l1hl2));
4285 } else {
4286 /* If required, pad L2 frame with constant 0x2b filling */
4287 l2 := f_pad_oct(l2, 23, '2B'O);
4288
4289 log("encoding ", l, " to ", l2);
4290 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, link_id, l2));
Harald Welte0472ab42018-03-12 15:02:26 +01004291 }
Harald Welte0472ab42018-03-12 15:02:26 +01004292}
4293
4294type record RllTestCase {
4295 uint3_t sapi,
4296 RslLinkId link_id,
4297 octetstring l3,
4298 boolean exp
4299}
4300type record of RllTestCase RllTestCases;
4301template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
4302 sapi := sapi,
4303 link_id := id,
4304 l3 := l3,
4305 exp := exp
4306}
4307
4308/* execute the same callback function with a set of different parameters (tcs) on a
4309 * variety of logical channels */
4310private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
4311 var ConnHdlrPars pars;
4312 var ConnHdlr vc_conn;
4313 f_init(testcasename());
4314
4315 /* test on each of the channels we have */
4316 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
4317 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
4318
4319 /* test each of the test cases on the current channel */
4320 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
4321 pars.spec.rll := tcs[j];
4322 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
4323 vc_conn := f_start_handler(fn, pars);
4324 vc_conn.done;
4325 }
4326 }
4327
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004328 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01004329}
4330
4331/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
4332private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
4333 var RllTestCase tc := g_pars.spec.rll;
4334 timer T := 3.0;
4335
4336 f_l1_tune(L1CTL);
4337 RSL.clear;
4338
4339 /* activate the logical channel */
4340 f_est_dchan();
4341 L1CTL.clear;
4342
4343 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
4344 T.start;
4345 alt {
4346 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
4347 if (tc.exp) {
4348 setverdict(pass);
4349 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004350 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01004351 }
4352 }
4353 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
4354 if (tc.exp) {
4355 setverdict(pass);
4356 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004357 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01004358 }
4359 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07004360 /* We also expect to receive the measurements */
4361 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01004362 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004363 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01004364 }
4365 [not tc.exp] T.timeout {
4366 setverdict(pass);
4367 }
4368 }
4369
4370 f_rsl_chan_deact();
4371 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4372 f_rslem_unregister(0, g_chan_nr);
4373}
4374testcase TC_rll_est_ind() runs on test_CT {
4375 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02004376 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01004377 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02004378 /* normal SAPI0 establishment */
4379 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01004380 /* SAPI 3 doesn't support contention resolution */
4381 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
4382 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
4383 /* normal SAPI3 establishment on main DCCH */
4384 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
4385 /* normal SAPI3 establishment on SACCH */
4386 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4387 };
4388 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
4389}
4390
4391/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
4392private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
4393 var RllTestCase tc := g_pars.spec.rll;
4394 var L1ctlDlMessage dl;
4395 timer T := 3.0;
4396
4397 f_l1_tune(L1CTL);
4398 RSL.clear;
4399
4400 /* activate the logical channel */
4401 f_est_dchan();
4402 L1CTL.clear;
4403
4404 /* Send a RSL EST REQ for SAPI3 on main DCCH */
4405 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
4406 T.start;
4407 alt {
4408 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4409 var LapdmFrame lapdm;
4410 var octetstring l2 := dl.payload.data_ind.payload;
4411 if (dl.dl_info.link_id.c == SACCH) {
4412 /* remove L1 header */
4413 l2 := substr(l2, 2, lengthof(l2)-2);
4414 }
4415 lapdm.ab := dec_LapdmFrameAB(l2);
4416 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
4417 setverdict(pass);
4418 } else {
4419 repeat;
4420 }
4421 }
4422 [] L1CTL.receive { repeat; }
4423 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01004425 }
4426 }
4427
4428 f_rsl_chan_deact();
4429 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4430 f_rslem_unregister(0, g_chan_nr);
4431}
4432testcase TC_rll_est_req_DCCH_3() runs on test_CT {
4433 var RllTestCases tcs := {
4434 /* normal SAPI3 establishment on main DCCH */
4435 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
4436 };
4437 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
4438}
4439testcase TC_rll_est_req_ACCH_3() runs on test_CT {
4440 var RllTestCases tcs := {
4441 /* normal SAPI3 establishment on SACCH */
4442 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4443 }
4444 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
4445}
4446
4447/* altstep to receive a LAPDm frame matching the given template */
4448private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
4449 var L1ctlDlMessage dl;
4450 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4451 var LapdmFrame lapdm;
4452 var octetstring l2 := dl.payload.data_ind.payload;
4453 if (dl.dl_info.link_id.c == SACCH) {
4454 /* remove L1 header */
4455 l2 := substr(l2, 2, lengthof(l2)-2);
4456 }
4457 if (ischosen(exp.ab)) {
4458 lapdm.ab := dec_LapdmFrameAB(l2);
4459 } else if (ischosen(exp.b4)) {
4460 lapdm.b4 := dec_LapdmFrameB4(l2);
4461 } else if (ischosen(exp.bbis)) {
4462 lapdm.bbis := dec_LapdmFrameBbis(l2);
4463 }
4464 log("Rx LAPDm ", lapdm);
4465 if (match(lapdm, exp)) {
4466 setverdict(pass);
4467 } else {
4468 repeat;
4469 }
4470 }
4471 [] L1CTL.receive { repeat; }
4472}
4473private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
4474 timer T := t;
4475 T.start;
4476 alt {
4477 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004478 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01004479 }
4480 [] as_l1_exp_lapdm(exp);
4481 }
4482}
4483
4484/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
4485private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
4486 /* send SABM from MS -> BTS */
4487 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
4488 /* expect RLL EST IND on Abis */
4489 alt {
4490 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
4491 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
4492 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004493 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01004494 }
4495 [] RSL.receive { repeat; }
4496 }
4497 /* expect UA from BTS -> MS */
4498 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
4499}
4500
4501/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
4502private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
4503 var RllTestCase tc := g_pars.spec.rll;
4504
4505 f_l1_tune(L1CTL);
4506 RSL.clear;
4507
4508 /* activate the logical channel */
4509 f_est_dchan();
4510 L1CTL.clear;
4511
4512 /* first establish the link-layer */
4513 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
4514
4515 /* then send the DISC */
4516 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
4517 /* ... and expect the REL IND on the RSL side */
4518 alt {
4519 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
4520 setverdict(pass);
4521 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07004522 /* We also expect to receive the measurements */
4523 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01004524 }
4525
4526 /* release the channel */
4527 f_rsl_chan_deact();
4528 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4529 f_rslem_unregister(0, g_chan_nr);
4530}
4531testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
4532 var RllTestCases tcs := {
4533 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
4534 };
4535 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4536}
4537
4538testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
4539 var RllTestCases tcs := {
4540 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
4541 };
4542 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4543}
4544testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
4545 var RllTestCases tcs := {
4546 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
4547 };
4548 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4549}
4550testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
4551 var RllTestCases tcs := {
4552 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4553 };
4554 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4555}
4556
4557/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
4558private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
4559 var RllTestCase tc := g_pars.spec.rll;
4560 f_l1_tune(L1CTL);
4561 RSL.clear;
4562
4563 /* activate the logical channel */
4564 f_est_dchan();
4565 L1CTL.clear;
4566
4567 /* first establish the link-layer */
4568 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
4569
4570 /* then send the REL REQ via RSL */
4571 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
4572 /* ... and expect the DISC on the Um side */
4573 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02004574 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01004575 /* FIXME: send a UA in resposne to the DISC */
4576 }
4577 }
4578
4579 /* release the channel */
4580 f_rsl_chan_deact();
4581 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4582 f_rslem_unregister(0, g_chan_nr);
4583}
4584testcase TC_rll_rel_req() runs on test_CT {
4585 var RllTestCases tcs := {
4586 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
4587 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
4588 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
4589 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4590 };
4591 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
4592}
4593
4594/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
4595testcase TC_rll_data_req() runs on test_CT {
4596}
4597
4598/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
4599testcase TC_rll_data_ind() runs on test_CT {
4600}
4601
4602/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
4603private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
4604 var RllTestCase tc := g_pars.spec.rll;
4605
4606 f_l1_tune(L1CTL);
4607 RSL.clear;
4608
4609 f_est_dchan();
4610 L1CTL.clear;
4611
4612 /* Send UNITDATA REQ on RSL side */
4613 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
4614 /* Expect it to arrive on the other side */
4615 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02004616 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01004617 } else {
Harald Weltee613f962018-04-18 22:38:16 +02004618 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01004619 }
4620
4621 /* release the channel */
4622 f_rsl_chan_deact();
4623 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4624 f_rslem_unregister(0, g_chan_nr);
4625}
4626testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
4627 var octetstring l3 := f_rnd_octstring(15);
4628 var RllTestCases tcs := {
4629 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
4630 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
4631 };
4632 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
4633}
4634testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
4635 var octetstring l3 := f_rnd_octstring(19);
4636 var RllTestCases tcs := {
4637 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
4638 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
4639 };
4640 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
4641}
4642
4643/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
4644private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
4645 var RllTestCase tc := g_pars.spec.rll;
4646
4647 f_l1_tune(L1CTL);
4648 RSL.clear;
4649
4650 f_est_dchan();
4651 L1CTL.clear;
4652
4653 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02004654 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01004655 /* Expdct RLL UNITDATA IND on RSL side */
4656 alt {
4657 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
4658 setverdict(pass);
4659 }
4660 [] RSL.receive { repeat; }
4661 }
4662
4663 /* release the channel */
4664 f_rsl_chan_deact();
4665 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4666 f_rslem_unregister(0, g_chan_nr);
4667}
4668testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02004669 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01004670 var RllTestCases tcs := {
4671 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
4672 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
4673 };
4674 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
4675}
4676testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
4677 var octetstring l3 := f_rnd_octstring(18);
4678 var RllTestCases tcs := {
4679 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
4680 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
4681 };
4682 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
4683}
4684
Harald Weltee613f962018-04-18 22:38:16 +02004685/***********************************************************************
4686 * Encryption Related
4687 ***********************************************************************/
4688
4689/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
4690function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
4691 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
4692 if (link_id.c == SACCH) {
4693 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
4694 } else {
4695 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
4696 }
4697}
4698
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07004699/* Expect (or not expect) other kinds of messages */
4700private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
4701 [exp_any] RSL.receive { repeat; }
4702 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004703 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07004704 }
4705}
4706
Harald Weltee613f962018-04-18 22:38:16 +02004707/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07004708private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07004709 RslLinkId link_id,
4710 octetstring l3,
4711 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07004712 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07004713) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02004714 timer T := 3.0;
4715 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
4716 T.start;
4717 /* Expect RLL UNITDATA IND on RSL side */
4718 alt {
4719 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
4720 setverdict(pass);
4721 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07004722 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07004723 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02004724 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004725 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02004726 }
Harald Weltee613f962018-04-18 22:38:16 +02004727 }
4728}
4729
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004730/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
4731private function f_data_mo(
4732 RslLinkId link_id,
4733 boolean p, uint3_t nr, uint3_t ns,
4734 octetstring l3,
4735 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07004736 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004737) runs on ConnHdlr {
4738 timer T := 3.0;
4739 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
4740 T.start;
4741 /* Expect RLL DATA IND on RSL side */
4742 alt {
4743 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
4744 setverdict(pass);
4745 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07004746 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004747 [] as_rsl_any_ind(exp_any);
4748 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004749 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004750 }
4751 }
4752}
4753
Harald Weltee613f962018-04-18 22:38:16 +02004754/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
4755function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
4756 f_l1_tune(L1CTL);
4757 f_est_dchan(true);
4758
4759 /* now we actually need to transmit some data both ways to check if the encryption works */
4760 var L1ctlDlMessage dl;
4761
Stefan Sperling603d98e2018-07-25 16:47:28 +02004762 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02004763 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
4764
4765 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
4766 f_unitdata_mt(link_id, l3);
4767
4768 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
4769 f_unitdata_mo(link_id, l3);
4770
4771 /* release the channel */
4772 f_rsl_chan_deact();
4773 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4774 f_rslem_unregister(0, g_chan_nr);
4775}
4776testcase TC_chan_act_a51() runs on test_CT {
4777 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4778 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
4779 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
4780}
4781testcase TC_chan_act_a52() runs on test_CT {
4782 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4783 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
4784 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
4785}
4786testcase TC_chan_act_a53() runs on test_CT {
4787 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4788 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
4789 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
4790}
4791
4792
4793/* Test unencrypted channel activation followed by explicit ENCR CMD later */
4794function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
4795 /* L3 payload doesn't matter, as it is passed transparently */
4796 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
4797 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
4798 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
4799
4800 f_l1_tune(L1CTL);
4801
4802 /* first establish a dedicated channel in the clear */
4803 f_est_dchan(false);
4804
4805 /* Establish ABM */
4806 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
4807
4808 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
4809 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
4810 /* expect the L3 to arrive still unencrypted on the MS side */
4811 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
4812
4813 /* configure L1 to apply ciphering */
4814 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
4815 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
4816
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004817 /* send first ciphered I-frame in response and expect it on RSL */
4818 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02004819
4820 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
4821 * and hence enable encryption also on the downlink */
4822
4823 /* expect bi-directional communication work in encrypted mode */
4824 f_unitdata_mo(link_id, f_rnd_octstring(15));
4825 f_unitdata_mt(link_id, f_rnd_octstring(15));
4826
4827 /* release the channel */
4828 f_rsl_chan_deact();
4829 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4830 f_rslem_unregister(0, g_chan_nr);
4831}
4832testcase TC_encr_cmd_a51() runs on test_CT {
4833 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4834 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
4835 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
4836}
4837testcase TC_encr_cmd_a52() runs on test_CT {
4838 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4839 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
4840 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
4841}
4842testcase TC_encr_cmd_a53() runs on test_CT {
4843 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4844 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
4845 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
4846}
4847
4848private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
4849 var LapdmFrame lf;
4850 var octetstring reenc;
4851
4852 /* decode the LAPDm frame */
4853 if (ischosen(exp_match.ab)) {
4854 lf.ab := dec_LapdmFrameAB(enc);
4855 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004856 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02004857 }
4858
4859 /* check if decoder result matches expectation */
4860 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004861 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02004862 } else {
4863 log(name, ": matched");
4864 setverdict(pass);
4865 }
4866
4867 /* test if re-encoded frame equals original input */
4868 reenc := enc_LapdmFrame(lf);
4869 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004870 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02004871 } else {
4872 setverdict(pass);
4873 }
4874}
4875
4876testcase TC_lapdm_selftest() runs on test_CT {
4877 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
4878 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
4879 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
4880 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
4881 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
4882 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
4883 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
4884}
4885
Stefan Sperling4880be42018-08-07 18:12:59 +02004886/***********************************************************************
4887 * DTX Related (see GSM 05.08, section 8.3)
4888 ***********************************************************************/
4889
4890/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
4891function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
4892 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
4893 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
4894 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
4895 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
4896}
4897function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
4898 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
4899 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
4900}
4901function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
4902 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
4903 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
4904 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
4905 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
4906}
4907function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
4908 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
4909 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
4910 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
4911 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
4912 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
4913 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
4914 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
4915 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
4916}
4917
4918function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
4919 var L1ctlDlMessage dl;
4920 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
4921 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
4922 var GsmFrameNumber first_fn;
4923 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004924 var integer nfill_frames_sacch := 0;
4925 var integer nfill_frames_nonsacch := 0;
4926 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02004927 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
4928 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004929 const integer frame_dtx_tchf_mod := 104;
4930 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
4931 * which operates in terms of blocks rather than frames. */
4932 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
4933 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02004934 timer T := 5.0;
4935
4936 f_l1_tune(L1CTL);
4937 RSL.clear;
4938 L1CTL.clear;
4939
4940 /* activate TCHF signalling channel */
4941 f_est_dchan(false);
4942
4943 T.start;
4944 alt {
4945 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4946 var GsmFrameNumber fn := dl.dl_info.frame_nr;
4947 var octetstring l2 := dl.payload.data_ind.payload;
4948
4949 if (is_first_frame) {
4950 is_first_frame := false;
4951 first_fn := dl.dl_info.frame_nr;
4952 }
4953
4954 if (dl.dl_info.link_id.c == SACCH) {
4955 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
4956 if (not match(l2_fill_frame_sacch, l2)) {
4957 repeat;
4958 }
4959 } else if (not match(l2_fill_frame, l2)) {
4960 repeat;
4961 }
4962
4963 if (dtxd) {
4964 if (not f_g_chan_is_tchf()) {
4965 T.stop;
4966 f_rsl_chan_deact();
4967 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004968 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 +02004969 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004970 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02004971 T.stop;
4972 f_rsl_chan_deact();
4973 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004974
4975 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
4976 * 2 SACCH, 1 TCH/F */
4977 expected_fill_frames := 3;
4978
4979 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
4980 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
4981 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004982 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02004983 } else {
4984 setverdict(pass);
4985 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004986 } else {
4987 if (dl.dl_info.link_id.c == SACCH) {
4988 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02004989 repeat;
4990 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004991 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
4992 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
4993 * we should only see the subset of frames numbers which correspond to a block boundary.
4994 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
4995 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
4996 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
4997 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
4998 repeat;
4999 }
5000 }
5001 log("Received DTX TCH fill frame with bad frame number: ", fn,
5002 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
5003 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
5004 f_rsl_chan_deact();
5005 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005006 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02005007 }
Stefan Sperling4880be42018-08-07 18:12:59 +02005008 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005009 if (dl.dl_info.link_id.c == SACCH) {
5010 nfill_frames_sacch := nfill_frames_sacch + 1;
5011 } else {
5012 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
5013 }
5014 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005015 T.stop;
5016 if (f_g_chan_is_tchf()) {
5017 /* Without DTX we can expect 25 fill frames for every 104 frames.
5018 * (24 FACCH + 1 SACCH filling) */
5019 expected_fill_frames := 25;
5020 } else if (f_g_chan_is_tchh()) {
5021 /* We can expect 2 fill frames for every 104 frames. */
5022 expected_fill_frames := 2;
5023 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
5024 /* We can expect 5 fill frames for every 104 frames. */
5025 expected_fill_frames := 5;
5026 } else {
5027 f_rsl_chan_deact();
5028 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005029 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02005030 }
5031
5032 f_rsl_chan_deact();
5033 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005034
5035 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005036 setverdict(pass);
5037 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005038 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
5039 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005040 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02005041 }
5042 } else {
5043 repeat;
5044 }
5045 }
5046 }
5047 [] L1CTL.receive { repeat; }
5048 [] T.timeout {
5049 f_rsl_chan_deact();
5050 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005051 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02005052 }
5053 }
5054}
5055
5056function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
5057 f_test_l2_fill_frames(false);
5058}
5059
5060function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
5061 f_test_l2_fill_frames(true);
5062}
5063
5064function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
5065 var ConnHdlr vc_conn;
5066 var ConnHdlrPars pars;
5067 pars.t_guard := 60.0;
5068 f_init(testcasename());
5069 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
5070 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
5071 if (dtxd) {
5072 if (i >= 4) { /* DTX is only allowed on TCH/F */
5073 break;
5074 }
5075 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
5076 } else {
5077 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
5078 }
5079 vc_conn.done;
5080 }
5081}
5082
5083/* Verify that L2 fill frames are sent on TCH in signaling mode if
5084 * there is nothing to transmit while DTX is disabled on downlink. */
5085testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
5086 f_tch_sign_l2_fill_frame(false);
5087}
5088
5089/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
5090 * there is nothing to transmit while DTX is enabled on downlink. */
5091testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
5092 f_tch_sign_l2_fill_frame(true);
5093}
Harald Welte0472ab42018-03-12 15:02:26 +01005094
Stefan Sperling0ec1c262018-10-15 15:12:52 +02005095testcase TC_chopped_ipa_ping() runs on test_CT {
5096 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
5097}
5098
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02005099testcase TC_chopped_ipa_payload() runs on test_CT {
5100 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
5101}
5102
Harald Welte0472ab42018-03-12 15:02:26 +01005103/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
5104/* protocol error as per 44.006 */
5105/* link layer failure (repetition of I-frame N200 times without ACK */
5106/* repetition of SABM or DISC N200 times without ACK */
5107/* receptiom of SABM in multi-frame established state */
5108
5109
Harald Welte68e495b2018-02-25 00:05:57 +01005110/* TODO Areas:
5111
5112* channel activation
5113** with BS_Power / MS_Power, bypassing power control loop
5114** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01005115** with timing advance from initial activation on
5116* mode modify
5117** encryption
5118** multirate
5119* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01005120** unsupported algorithm
5121* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01005122* BS Power Control
5123* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01005124* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01005125* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01005126** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01005127* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01005128** DATA_IND from BTS->PCU
5129** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01005130
5131*/
Harald Welte70767382018-02-21 12:16:40 +01005132
5133control {
5134 execute( TC_chan_act_stress() );
5135 execute( TC_chan_act_react() );
5136 execute( TC_chan_deact_not_active() );
5137 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01005138 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01005139 execute( TC_sacch_filling() );
5140 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01005141 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01005142 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02005143 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02005144 execute( TC_sacch_chan_act_ho_async() );
5145 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01005146 execute( TC_rach_content() );
5147 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01005148 execute( TC_rach_max_ta() );
Harald Welte3453ab42019-05-24 21:19:58 +02005149 execute( TC_rach_load_idle_thresh0() );
5150 execute( TC_rach_load_idle_below_thresh() );
5151 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01005152 execute( TC_meas_res_sign_tchf() );
5153 execute( TC_meas_res_sign_tchh() );
5154 execute( TC_meas_res_sign_sdcch4() );
5155 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01005156 execute( TC_meas_res_sign_tchh_toa256() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01005157 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild6833cc92019-05-23 19:34:44 +02005158 execute( TC_rsl_chan_initial_ta() );
Harald Welte70767382018-02-21 12:16:40 +01005159 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01005160 execute( TC_paging_imsi_80percent() );
5161 execute( TC_paging_tmsi_80percent() );
5162 execute( TC_paging_imsi_200percent() );
5163 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01005164 execute( TC_rsl_protocol_error() );
5165 execute( TC_rsl_mand_ie_error() );
5166 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01005167 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01005168 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01005169 execute( TC_si_sched_2bis() );
5170 execute( TC_si_sched_2ter() );
5171 execute( TC_si_sched_2ter_2bis() );
5172 execute( TC_si_sched_2quater() );
5173 execute( TC_si_sched_13() );
5174 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01005175 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01005176 execute( TC_ipa_crcx_twice_not_active() );
5177 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01005178 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01005179 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01005180
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005181 if (mp_pcu_socket != "") {
5182 execute( TC_pcu_act_req() );
5183 execute( TC_pcu_act_req_wrong_ts() );
5184 execute( TC_pcu_act_req_wrong_bts() );
5185 execute( TC_pcu_act_req_wrong_trx() );
5186 execute( TC_pcu_deact_req() );
5187 execute( TC_pcu_deact_req_wrong_ts() );
5188 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02005189 if (mp_l1_supports_gprs) {
5190 execute( TC_pcu_data_req_pdtch() );
5191 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02005192 execute( TC_pcu_data_req_wrong_bts() );
5193 execute( TC_pcu_data_req_wrong_trx() );
5194 execute( TC_pcu_data_req_wrong_ts() );
5195 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02005196 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005197 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02005198 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005199 execute( TC_pcu_data_req_imm_ass_pch() );
5200 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005201 execute( TC_pcu_ext_rach_content() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005202 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02005203 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02005204 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02005205 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02005206 execute( TC_pcu_rr_suspend() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005207 } else {
5208 log("PCU socket path not available, skipping PCU tests");
5209 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005210
5211 execute( TC_dyn_osmo_pdch_act_deact() );
5212 execute( TC_dyn_osmo_pdch_unsol_deact() );
5213 execute( TC_dyn_osmo_pdch_double_act() );
5214 execute( TC_dyn_osmo_pdch_tchf_act() );
5215 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02005216 execute( TC_dyn_ipa_pdch_act_deact() );
5217 execute( TC_dyn_ipa_pdch_tchf_act() );
5218 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
5219 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01005220
5221 execute( TC_rll_est_ind() );
5222 execute( TC_rll_est_req_DCCH_3() );
5223 execute( TC_rll_est_req_ACCH_3() );
5224 execute( TC_rll_rel_ind_DCCH_0() );
5225 execute( TC_rll_rel_ind_DCCH_3() );
5226 execute( TC_rll_rel_ind_ACCH_0() );
5227 execute( TC_rll_rel_ind_ACCH_3() );
5228 execute( TC_rll_rel_req() );
5229 execute( TC_rll_unit_data_req_DCCH() );
5230 execute( TC_rll_unit_data_req_ACCH() );
5231 execute( TC_rll_unit_data_ind_DCCH() );
5232 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02005233
5234 execute( TC_chan_act_a51() );
5235 execute( TC_chan_act_a52() );
5236 execute( TC_chan_act_a53() );
5237 execute( TC_encr_cmd_a51() );
5238 execute( TC_encr_cmd_a52() );
5239 execute( TC_encr_cmd_a53() );
5240
Harald Welteee25aae2019-05-19 14:32:37 +02005241 execute( TC_err_rep_wrong_mdisc() );
5242 execute( TC_err_rep_wrong_msg_type() );
5243 execute( TC_err_rep_wrong_sequence() );
5244
Harald Weltee613f962018-04-18 22:38:16 +02005245 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02005246
5247 execute( TC_tch_sign_l2_fill_frame() );
5248 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02005249
5250 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02005251 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01005252}
5253
5254
5255}