blob: 6786d6869122a0f0b16c4f966f49a6d5d0620aee [file] [log] [blame]
Harald Welte70767382018-02-21 12:16:40 +01001module BTS_Tests {
2
Harald Welte14906952019-05-27 09:19:49 +02003/* Integration Tests for OsmoBTS
Harald Welte34b5a952019-05-27 11:54:11 +02004 * (C) 2018-2019 by Harald Welte <laforge@gnumonks.org>
Harald Welte14906952019-05-27 09:19:49 +02005 * contributions by Vadim Yanitskiy and sysmocom - s.f.m.c. GmbH
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 *
Harald Welte34b5a952019-05-27 11:54:11 +020011 * SPDX-License-Identifier: GPL-2.0-or-later
12 *
Harald Welte14906952019-05-27 09:19:49 +020013 * This test suite tests OsmoBTS by attaching to the external interfaces
14 * such as Abis RSL, PCU, VTY as well as by attaching to a MS L1 implementation
15 * using the L1CTL protocol/interface.
16 *
17 * You can run the tests with
18 * a) osmo-bts-trx + trxcon + fake_trx (without any hardware)
19 * b) any osmo-bts-* + OsmocomBB layer1 + osmocon (with real BTS hardware)
20 * c) osmo-bts-virtual + virt_phy (without any hardware)
21 *
22 * Some of the tests will only run on a subset of those three configurations
23 * due to limitations in the respective L1.
24 */
25
Daniel Willmann0fcc4d32018-10-23 20:32:19 +020026import from Misc_Helpers all;
Harald Welte70767382018-02-21 12:16:40 +010027import from General_Types all;
28import from GSM_Types all;
29import from GSM_RR_Types all;
30import from Osmocom_Types all;
31import from GSM_Types all;
Harald Welte82ccef72018-02-25 16:17:33 +010032import from GSM_SystemInformation all;
Harald Welte70767382018-02-21 12:16:40 +010033import from L1CTL_PortType all;
34import from L1CTL_Types all;
35import from LAPDm_Types all;
Harald Weltead033dc2019-05-25 17:28:16 +020036import from LAPDm_RAW_PT all;
Harald Welte70767382018-02-21 12:16:40 +010037import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020038import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010039
40import from RSL_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010041import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010042import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020043import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010044import from RSL_Emulation all;
45
46import from IPL4asp_Types all;
47import from TRXC_Types all;
48import from TRXC_CodecPort all;
49import from TRXC_CodecPort_CtrlFunct all;
50
Harald Welte883340c2018-02-28 18:59:29 +010051import from PCUIF_Types all;
52import from PCUIF_CodecPort all;
Harald Weltea2e0e942019-05-27 18:12:53 +020053import from UD_Types all;
Harald Welte883340c2018-02-28 18:59:29 +010054
Harald Welte7484fc42018-02-24 14:09:45 +010055import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010056import from MobileL3_RRM_Types all;
57import from MobileL3_Types all;
58import from L3_Templates all;
Harald Welteeaa9a862019-05-26 23:01:08 +020059import from L3_Common all;
60import from MobileL3_GMM_SM_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010061
Harald Welte8da48242018-02-27 20:41:32 +010062import from Osmocom_VTY_Functions all;
63import from TELNETasp_PortType all;
64
Harald Welte505cf9b2018-09-15 17:47:23 +030065friend module BTS_Tests_SMSCB;
Harald Weltead033dc2019-05-25 17:28:16 +020066friend module BTS_Tests_virtphy;
Harald Welte505cf9b2018-09-15 17:47:23 +030067
Harald Welte70767382018-02-21 12:16:40 +010068/* The tests assume a BTS with the following timeslot configuration:
69 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020070 * TS1 : TCH/F
71 * TS2 : TCH/F
72 * TS3 : TCH/F_PDCH (IPA Style)
73 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010074 * TS5 : TCH/H
75 * TS6 : SDCCH/8
76 * TS7 : PDCH
77 */
78
79modulepar {
80 charstring mp_rsl_ip := "127.0.0.2";
81 integer mp_rsl_port := 3003;
82 integer mp_trx0_arfcn := 871;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070083 charstring mp_bts_trxc_ip := "127.0.0.1";
84 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010085 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020086 charstring mp_ctrl_ip := "127.0.0.1";
87 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020088 charstring mp_bsc_ctrl_ip := "127.0.0.1";
89 integer mp_bsc_ctrl_port := 4249;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020090 integer mp_tolerance_rxqual := 1;
91 integer mp_tolerance_rxlev := 3;
92 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +020093 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +020094 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +020095 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020096 integer mp_ms_actual_ta_exp := 0;
97 integer mp_timing_offset_256syms_exp := 512;
Pau Espin Pedrol315e4712018-11-01 16:27:07 +010098 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +020099 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200100 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200101 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
102 boolean mp_l1_supports_gprs := false;
Harald Welte70767382018-02-21 12:16:40 +0100103}
104
Harald Welte629cc6b2018-03-11 17:19:05 +0100105type record of RslChannelNr ChannelNrs;
106
Harald Welte70767382018-02-21 12:16:40 +0100107type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100108 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100109 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100110 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100111 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100112 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100113 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100114
115 /* L1CTL port (for classic tests) */
116 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100117
Harald Welte54a2a2d2018-02-26 09:14:05 +0100118 /* TRXC port (for classic tests) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700119 port TRXC_CODEC_PT BTS_TRXC;
120 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100121
Harald Weltef50e3ae2018-09-10 10:27:56 +0200122 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100123 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200124 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100125
Harald Welte883340c2018-02-28 18:59:29 +0100126 /* PCU Interface of BTS */
127 port PCUIF_CODEC_PT PCU;
128 var integer g_pcu_conn_id;
129 /* Last PCU INFO IND we received */
130 var PCUIF_Message g_pcu_last_info;
131
Harald Welte48494ca2018-02-25 16:59:50 +0100132 /* SI configuration */
133 var SystemInformationConfig si_cfg := {
134 bcch_extended := false,
135 si1_present := false,
136 si2bis_present := false,
137 si2ter_present := false,
138 si2quater_present := false,
139 si7_present := false,
140 si8_present := false,
141 si9_present := false,
142 si13_present := false,
143 si13alt_present := false,
144 si15_present := false,
145 si16_present := false,
146 si17_present := false,
147 si2n_present := false,
148 si21_present := false,
149 si22_present := false
150 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100151
152 /* all logical channels available on the BTS */
153 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100154 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100155}
156
157/* an individual call / channel */
158type component ConnHdlr extends RSL_DchanHdlr {
159 port L1CTL_PT L1CTL;
160
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700161 port TRXC_CODEC_PT BTS_TRXC;
162 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100163
164 timer g_Tguard;
165 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
166
167 var ConnHdlrPars g_pars;
168 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100169 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200170
171 /* PCU Interface of BTS */
172 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100173}
174
175function f_init_rsl(charstring id) runs on test_CT {
176 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
177 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
178
179 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
180 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
181 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
182
183 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
184 vc_RSL.start(RSL_Emulation.main(false));
185}
186
187type record ConnHdlrPars {
188 RslChannelNr chan_nr,
189 RSL_IE_ChannelMode chan_mode,
190 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100191 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200192 TestSpecUnion spec optional,
193 RSL_IE_EncryptionInfo encr optional
Harald Welte0472ab42018-03-12 15:02:26 +0100194}
195
196/* Test-specific parameters */
197type union TestSpecUnion {
198 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100199}
200
Harald Welte82ccef72018-02-25 16:17:33 +0100201template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100202 max_retrans := RACH_MAX_RETRANS_7,
203 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100204 cell_barr_access := false,
205 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100206 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100207};
208
Harald Weltef10153f2018-02-25 16:34:05 +0100209template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100210 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200211 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100212 acs := '0'B,
213 neci := true,
214 rxlev_access_min := 0
215}
216
217template (value) LocationAreaIdentification ts_LAI_default := {
218 mcc_mnc := '262F42'H,
219 lac := 42
220}
221
Harald Welte7484fc42018-02-24 14:09:45 +0100222/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100223template (value) SystemInformation ts_SI3_default := {
224 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100225 payload := {
226 si3 := {
227 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100228 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100229 ctrl_chan_desc := {
230 msc_r99 := true,
231 att := true,
232 bs_ag_blks_res := 1,
233 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100234 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100235 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
236 spare := '00'B,
237 bs_pa_mfrms := 0, /* 2 multiframes */
238 t3212 := 1 /* 6 minutes */
239 },
Harald Welte82ccef72018-02-25 16:17:33 +0100240 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100241 dn_ind := false,
242 pwrc := false,
243 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100244 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100245 },
Harald Weltef10153f2018-02-25 16:34:05 +0100246 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100247 rach_control := ts_RachCtrl_default,
Harald Welte3778acc2018-03-09 19:32:31 +0100248 rest_octets := '2B2B2B2B'O
Harald Welte7484fc42018-02-24 14:09:45 +0100249 }
250 }
251}
Harald Welte70767382018-02-21 12:16:40 +0100252
Harald Weltef8df4cb2018-03-10 15:15:08 +0100253template (value) SystemInformation ts_SI2_default := {
254 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100255 payload := {
256 si2 := {
257 bcch_freq_list := '00000000000000000000000000000000'O,
258 ncc_permitted := '11111111'B,
259 rach_control := ts_RachCtrl_default
260 }
261 }
262}
263
Harald Weltef8df4cb2018-03-10 15:15:08 +0100264template (value) SystemInformation ts_SI4_default := {
265 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100266 payload := {
267 si4 := {
268 lai := ts_LAI_default,
269 cell_sel_par := ts_CellSelPar_default,
270 rach_control := ts_RachCtrl_default,
271 cbch_chan_desc := omit,
272 cbch_mobile_alloc := omit,
273 rest_octets := ''O
274 }
275 }
276}
277
278function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
279runs on test_CT {
280 log("Setting ", rsl_si_type, ": ", si_enc);
281 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
282}
283
284function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
285runs on test_CT {
286 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
287 log("Setting ", rsl_si_type, ": ", si_dec);
288 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
289}
290
Harald Welte505cf9b2018-09-15 17:47:23 +0300291friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100292 map(self:BTSVTY, system:BTSVTY);
293 f_vty_set_prompts(BTSVTY);
294 f_vty_transceive(BTSVTY, "enable");
295}
296
Harald Welte505cf9b2018-09-15 17:47:23 +0300297friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200298 map(self:BSCVTY, system:BSCVTY);
299 f_vty_set_prompts(BSCVTY, "OsmoBSC");
300 f_vty_transceive(BSCVTY, "enable");
301}
302
Harald Welte883340c2018-02-28 18:59:29 +0100303/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200304private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
305 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100306 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200307 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
308 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100309 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200310 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200311 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100312 }
313}
314
Harald Weltef26de0b2018-04-04 20:28:05 +0200315private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
316 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100317 timer T := 2.0;
318 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100319 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200320 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100321 return;
322 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200323 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100324
325 T.start;
326 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200327 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100328 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200329 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100330 }
331 }
332}
333
Harald Welte70767382018-02-21 12:16:40 +0100334/* global init function */
Harald Welte68e495b2018-02-25 00:05:57 +0100335function f_init(charstring id := "BTS-Test") runs on test_CT {
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100336 timer T := mp_ipa_up_timeout;
Harald Welte629cc6b2018-03-11 17:19:05 +0100337 g_AllChannels := {
338 /* TS 1..4: TCH/F */
339 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
340 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
341 /* TS 5: TCH/H */
342 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
343 /* TS 0: SDCCH/4 */
344 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
345 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
346 /* TS 6: SDCCH/8 */
347 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
348 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
349 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
350 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
351 };
352
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200353 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700354 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200355 g_AllChanTypes := {
356 /* TS 1..4: TCH/F */
357 valueof(ts_RslChanNr_Bm(1)),
358 /* TS 5: TCH/H */
359 valueof(ts_RslChanNr_Lm(5,1)),
360 /* TS 0: SDCCH/4 */
361 valueof(ts_RslChanNr_SDCCH4(0,2)),
362 /* TS 6: SDCCH/8 */
363 valueof(ts_RslChanNr_SDCCH8(6,4))
364 };
365 } else {
366 g_AllChanTypes := {
367 /* TS 1..4: TCH/F */
368 valueof(ts_RslChanNr_Bm(1)),
369 /* TS 0: SDCCH/4 */
370 valueof(ts_RslChanNr_SDCCH4(0,2)),
371 /* TS 6: SDCCH/8 */
372 valueof(ts_RslChanNr_SDCCH8(6,4))
373 };
374 }
Harald Welte70767382018-02-21 12:16:40 +0100375 f_init_rsl(id);
Harald Welte83f6dbf2018-06-03 18:26:50 +0200376 T.start;
377 alt {
378 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
379 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200380 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
Harald Welte83f6dbf2018-06-03 18:26:50 +0200381 }
382 }
Harald Welte2d142592018-02-25 13:19:44 +0100383 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100384 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200385 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100386
387 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100388 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
389 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
390 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
391 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100392
Harald Weltef26de0b2018-04-04 20:28:05 +0200393 map(self:PCU, system:PCU);
394 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100395
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700396 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100397 var TrxcMessage ret;
398 /* start with a default moderate timing offset equalling TA=2 */
399 f_main_trxc_connect();
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700400 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 +0100401 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200402
403 /* Wait some extra time to make sure the BTS emits a stable carrier.
404 * (this is only relevant when running the tests with a physical BTS.) */
405 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100406}
407
Harald Welte68e495b2018-02-25 00:05:57 +0100408/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
409function f_init_l1ctl() runs on test_CT {
410 map(self:L1CTL, system:L1CTL);
411 f_connect_reset(L1CTL);
412}
413
Harald Welte70767382018-02-21 12:16:40 +0100414type function void_fn(charstring id) runs on ConnHdlr;
415
416/* create a new test component */
Harald Weltef26de0b2018-04-04 20:28:05 +0200417function f_start_handler(void_fn fn, ConnHdlrPars pars, boolean pcu_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100418runs on test_CT return ConnHdlr {
419 var charstring id := testcasename();
420 var ConnHdlr vc_conn;
421
422 vc_conn := ConnHdlr.create(id);
423 /* connect to RSL Emulation main component */
424 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
425 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Harald Weltef26de0b2018-04-04 20:28:05 +0200426 if (pcu_comp) {
427 /* the ConnHdlr component wants to talk directly to the PCU, so disconnect
428 * it from the test_CT and connect it to the component. This obviously only
429 * works for one component, i.e. no concurrency */
430 unmap(self:PCU, system:PCU);
431 map(vc_conn:PCU, system:PCU);
432 }
Harald Welte70767382018-02-21 12:16:40 +0100433
434 vc_conn.start(f_handler_init(fn, id, pars));
435 return vc_conn;
436}
437
Harald Welte7484fc42018-02-24 14:09:45 +0100438template ASP_RSL_Unitdata ts_RSL_UD(template RSL_Message rsl, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
439 streamId := sid,
440 rsl := rsl
441}
442
443template ASP_RSL_Unitdata tr_RSL_UD(template RSL_Message rsl,
444 template IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
445 streamId := sid,
446 rsl := rsl
447}
448
Harald Welte70767382018-02-21 12:16:40 +0100449private altstep as_Tguard() runs on ConnHdlr {
450 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200451 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100452 }
453}
454
Harald Welte990a3612019-05-27 14:02:13 +0200455friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
456 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100457}
458
459private function f_trxc_connect() runs on ConnHdlr {
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700460 map(self:BTS_TRXC, system:BTS_TRXC);
Harald Welte70767382018-02-21 12:16:40 +0100461 var Result res;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700462 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BTS_TRXC, mp_bts_trxc_ip, mp_bts_trxc_port,
Harald Weltea4d8f352018-03-01 15:47:20 +0100463 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +0200464 if (not ispresent(res.connId)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200465 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 +0200466 }
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700467 g_bts_trxc_conn_id := res.connId;
Harald Welte70767382018-02-21 12:16:40 +0100468}
469
470private function f_trxc_fake_rssi(uint8_t rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100471 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700472 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100473}
474
475private function f_trx_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100476 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700477 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100478}
479
480/* first function started in ConnHdlr component */
481private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
482runs on ConnHdlr {
483 g_pars := pars;
484 g_chan_nr := pars.chan_nr;
485
486 map(self:L1CTL, system:L1CTL);
487 f_connect_reset(L1CTL);
488
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700489 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100490 f_trxc_connect();
491 }
Harald Welte70767382018-02-21 12:16:40 +0100492
493 g_Tguard.start(pars.t_guard);
494 activate(as_Tguard());
495
496 f_rslem_register(0, pars.chan_nr);
497
498 /* call the user-supplied test case function */
499 fn.apply(id);
500}
501
Harald Welteb1726c92018-03-30 11:56:38 +0200502function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
503 boolean ignore_other := false)
504runs on ConnHdlr return RSL_Message {
505 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100506 timer T := 3.0;
507 RSL.send(tx);
508 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100509 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200510 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100511 T.stop;
512 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100513 }
Harald Welte1eba3742018-02-25 12:48:14 +0100514 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200515 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100516 }
Harald Welte21240e62018-03-11 21:43:35 +0100517 [not ignore_other] as_l1_sacch();
518 [not ignore_other] as_meas_res();
519 [not ignore_other] as_l1_dcch();
520 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200521 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100522 }
Harald Welte21240e62018-03-11 21:43:35 +0100523 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100524 }
Harald Welteb1726c92018-03-30 11:56:38 +0200525 return rx;
526}
527
528function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
529 boolean ignore_other := false)
530runs on ConnHdlr {
531 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100532}
533
Harald Welte8b01c792019-05-19 22:51:25 +0200534function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false, RSL_IE_List more_ies := {},
535 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA) runs on ConnHdlr {
536 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200537 if (encr_enable) {
538 /* append encryption related IEs, if requested */
539 var RSL_IE_EncryptionInfo encr_info;
540 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
541 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
542encr_info})) };
543 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200544 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200545 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100546}
547
Harald Welte70767382018-02-21 12:16:40 +0100548function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100549 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 +0100550 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100551}
552
Harald Welte70767382018-02-21 12:16:40 +0100553private template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
554 template RSL_IE_ChannelMode chan_mode,
555 float t_guard := 20.0) := {
556 chan_nr := valueof(chan_nr),
557 chan_mode := valueof(chan_mode),
558 t_guard := t_guard,
559 l1_pars := {
560 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100561 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100562 meas_ul := {
563 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200564 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100565 rxqual := 0
566 },
567 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200568 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100569 rxqual := 0
570 }
571 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200572 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100573 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200574 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200575 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100576 },
Harald Weltee613f962018-04-18 22:38:16 +0200577 spec := omit,
578 encr := omit
Harald Welte70767382018-02-21 12:16:40 +0100579}
580
Harald Welte93640c62018-02-25 16:59:33 +0100581/***********************************************************************
582 * Channel Activation / Deactivation
583 ***********************************************************************/
584
Harald Welte70767382018-02-21 12:16:40 +0100585/* Stress test: Do 500 channel activations/deactivations in rapid succession */
586function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
587 for (var integer i := 0; i < 500; i := i+1) {
588 f_rsl_chan_act(g_pars.chan_mode);
589 f_rsl_chan_deact();
590 }
591 setverdict(pass);
592}
593testcase TC_chan_act_stress() runs on test_CT {
594 var ConnHdlr vc_conn;
595 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
596 f_init(testcasename());
597 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
598 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200599 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100600}
601
602/* Test if re-activation of an already active channel fails as expected */
603function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
604 f_rsl_chan_act(g_pars.chan_mode);
605 /* attempt to activate the same lchan again -> expect reject */
606 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
607 alt {
608 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200609 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100610 }
611 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
612 setverdict(pass);
613 }
614 }
615 f_rsl_chan_deact();
616}
617testcase TC_chan_act_react() runs on test_CT {
618 var ConnHdlr vc_conn;
619 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100620 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100621 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
622 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200623 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100624}
625
626/* Attempt to de-activate a channel that's not active */
627function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
628 timer T := 3.0;
629 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
630 T.start;
631 alt {
632 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
633 setverdict(pass);
634 }
635 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200636 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100637 }
638 }
639}
640testcase TC_chan_deact_not_active() runs on test_CT {
641 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100642 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100643 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
644 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200645 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100646}
647
648/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
649function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
650 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
651 alt {
652 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200653 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100654 }
655 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
656 setverdict(pass);
657 }
658 }
659}
660private type record WrongChanNrCase {
661 RslChannelNr chan_nr,
662 charstring description
663}
664private type record of WrongChanNrCase WrongChanNrCases;
665private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
666 chan_nr := chan_nr,
667 description := desc
668}
669
670testcase TC_chan_act_wrong_nr() runs on test_CT {
671 var ConnHdlr vc_conn;
672 var ConnHdlrPars pars;
673
Harald Welte294b0a22018-03-10 23:26:48 +0100674 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100675
676 var WrongChanNrCases wrong := {
677 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
678 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
679 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
680 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
681 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
682 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
683 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
684 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
685 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
686 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
687 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
688 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
689 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
690 };
691
692 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
693 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
694 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
695 vc_conn.done;
696 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200697 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100698}
699
Harald Weltee613f962018-04-18 22:38:16 +0200700/* execute the same callback function on a variety of logical channels */
701private function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
702 var ConnHdlr vc_conn;
703 f_init(testcasename());
704
705 /* test on each of the channels we have */
706 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
707 pars.chan_nr := valueof(g_AllChanTypes[i]);
708
709 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
710 vc_conn := f_start_handler(fn, pars);
711 vc_conn.done;
712 }
713
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200714 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200715}
716
Harald Welte93640c62018-02-25 16:59:33 +0100717/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100718 * SACCH handling
719 ***********************************************************************/
720
721private function f_exp_sacch(boolean exp) runs on ConnHdlr {
722 timer T_sacch := 3.0;
723 T_sacch.start;
724 alt {
725 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200726 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100727 }
728 [not exp] T_sacch.timeout {
729 setverdict(pass);
730 }
731 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
732 setverdict(pass);
733 }
734 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200735 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100736 }
737 [] L1CTL.receive { repeat; }
738 [] RSL.receive { repeat; }
739 }
740}
741
742/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
743private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
744 f_l1_tune(L1CTL);
745 RSL.clear;
746
747 /* activate the logical channel */
748 f_est_dchan();
749 L1CTL.clear;
750
751 /* check that SACCH actually are received as expected */
752 f_exp_sacch(true);
753
754 /* deactivate SACCH on the logical channel */
755 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
756 f_sleep(1.0);
757 L1CTL.clear;
758
759 /* check that no SACCH are received anymore */
760 f_exp_sacch(false);
761
762 /* release the channel */
763 f_rsl_chan_deact();
764 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
765}
766testcase TC_deact_sacch() runs on test_CT {
767 var ConnHdlr vc_conn;
768 var ConnHdlrPars pars;
769 f_init();
770 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
771 //for (var integer i := 0; i < 1; i := i+1) {
772 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
773 log(testcasename(), ": Starting for ", g_AllChannels[i]);
774 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
775 vc_conn.done;
776 }
777 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200778 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100779}
780
Harald Welte55700662018-03-12 13:15:43 +0100781/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100782private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
783 var L1ctlDlMessage dl;
784 /* check that the specified SI5 value is actually sent */
785 timer T_sacch := 3.0;
786 L1CTL.clear;
787 T_sacch.start;
788 alt {
789 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
790 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
791 if (match(l3, l3_exp)) {
792 setverdict(pass);
793 } else {
794 repeat;
795 }
796 }
797 [] L1CTL.receive { repeat; }
798 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200799 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100800 }
801 }
802}
803
Harald Welte55700662018-03-12 13:15:43 +0100804/* verify that given SACCH payload is not present */
805private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
806 var L1ctlDlMessage dl;
807 /* check that the specified SI5 value is actually sent */
808 timer T_sacch := 3.0;
809 L1CTL.clear;
810 T_sacch.start;
811 alt {
812 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
813 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
814 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200815 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100816 } else {
817 repeat;
818 }
819 }
820 [] L1CTL.receive { repeat; }
821 [] T_sacch.timeout {
822 setverdict(pass);
823 }
824 }
825}
826
Harald Welte629cc6b2018-03-11 17:19:05 +0100827/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100828private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
829 /* Set a known default SACCH filling for SI5 */
830 var octetstring si5 := f_rnd_octstring(19);
831 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
832
833 f_l1_tune(L1CTL);
834 RSL.clear;
835
836 /* activate the logical channel */
837 f_est_dchan();
838
839 /* check that the specified SI5 value is actually sent */
840 f_sacch_present(si5);
841
842 /* release the channel */
843 RSL.clear;
844 f_rsl_chan_deact();
845 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
846}
847testcase TC_sacch_filling() runs on test_CT {
848 var ConnHdlr vc_conn;
849 var ConnHdlrPars pars;
850 f_init();
851 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
852 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
853 log(testcasename(), ": Starting for ", g_AllChannels[i]);
854 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
855 vc_conn.done;
856 }
857 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200858 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100859}
860
Harald Welte629cc6b2018-03-11 17:19:05 +0100861/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100862private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
863 /* Set a known default SACCH filling for SI5 */
864 var octetstring si5 := f_rnd_octstring(19);
865 var octetstring si5_diff := f_rnd_octstring(19);
866 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
867
868 f_l1_tune(L1CTL);
869 RSL.clear;
870
871 log("Activating channel, expecting standard SI5");
872 /* activate the logical channel */
873 f_est_dchan();
874 /* check that the specified SI5 value is actually sent */
875 f_sacch_present(si5);
876
877 /* set channel-specific different SI5 */
878 log("Setting channel specific SACCH INFO, expecting it");
879 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
880 /* check that the specified lchan-specific value is now used */
881 f_sacch_present(si5_diff);
882
883 /* deactivate the channel and re-activate it, this should result in default SI5 */
884 log("De-activating and re-activating channel, expecting standard SI5");
885 f_rsl_chan_deact();
886 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
887 /* Verify that the TRX-wide default SACCH filling is present again */
888 f_sacch_present(si5);
889
890 /* release the channel */
891 RSL.clear;
892 f_rsl_chan_deact();
893 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
894}
895testcase TC_sacch_info_mod() runs on test_CT {
896 var ConnHdlr vc_conn;
897 var ConnHdlrPars pars;
898 f_init();
899 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
900 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
901 log(testcasename(), ": Starting for ", g_AllChannels[i]);
902 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
903 vc_conn.done;
904 }
905 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200906 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100907}
908
Harald Welte075d84c2018-03-12 13:07:24 +0100909/* Test SACCH scheduling of multiple different SI message types */
910private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
911 var octetstring si5 := f_rnd_octstring(19);
912 var octetstring si5bis := f_rnd_octstring(19);
913 var octetstring si5ter := f_rnd_octstring(19);
914 var octetstring si6 := f_rnd_octstring(19);
915
916 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
917 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
918 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
919 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
920
921 f_l1_tune(L1CTL);
922 RSL.clear;
923
924 /* activate the logical channel */
925 f_est_dchan();
926 L1CTL.clear;
927
928 /* check that SACCH actually are received as expected */
929 f_sacch_present(si5);
930 f_sacch_present(si5bis);
931 f_sacch_present(si5ter);
932 f_sacch_present(si6);
933
934 /* release the channel */
935 f_rsl_chan_deact();
936 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
937}
938testcase TC_sacch_multi() runs on test_CT {
939 var ConnHdlr vc_conn;
940 var ConnHdlrPars pars;
941 f_init();
942 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
943 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
944 log(testcasename(), ": Starting for ", g_AllChannels[i]);
945 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
946 vc_conn.done;
947 }
948 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200949 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +0100950}
951
Harald Welte55700662018-03-12 13:15:43 +0100952/* Test if SACH information is modified as expected */
953private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
954 var octetstring si5 := f_rnd_octstring(19);
955 var octetstring si6 := f_rnd_octstring(19);
956
957 /* First, configure both SI5 and SI6 to be transmitted */
958 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
959 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
960
961 f_l1_tune(L1CTL);
962 RSL.clear;
963
964 /* activate the logical channel */
965 f_est_dchan();
966 L1CTL.clear;
967
968 /* check that SACCH actually are received as expected */
969 f_sacch_present(si5);
970 f_sacch_present(si6);
971
972 /* disable SI6 */
973 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
974
975 /* check that SI5 is still transmitted */
976 f_sacch_present(si5);
977 /* check if SI6 is now gone */
978 f_sacch_missing(si6);
979
980 /* release the channel */
981 f_rsl_chan_deact();
982 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
983}
984testcase TC_sacch_multi_chg() runs on test_CT {
985 var ConnHdlr vc_conn;
986 var ConnHdlrPars pars;
987 f_init();
988 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
989 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
990 log(testcasename(), ": Starting for ", g_AllChannels[i]);
991 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
992 vc_conn.done;
993 }
994 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200995 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +0100996}
997
Harald Weltec8d363c2019-05-19 20:36:48 +0200998/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
999private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1000 var octetstring si5 := f_rnd_octstring(19);
1001 var octetstring si6 := f_rnd_octstring(19);
1002 var octetstring si5_specific := f_rnd_octstring(19);
1003 var octetstring si6_specific := f_rnd_octstring(19);
1004
1005 /* First, configure both SI5 and SI6 to be transmitted */
1006 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1007 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1008
1009 f_l1_tune(L1CTL);
1010 RSL.clear;
1011
1012 /* activate channel with different SACCH filling */
1013 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1014 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1015 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1016 }));
1017 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1018 RSL_IE_Body:{sacch_info := sacch_info})) };
1019 f_est_dchan(more_ies := addl_ies);
1020
1021 /* check that SACCH actually are received as expected */
1022 f_sacch_present(si5_specific);
1023 f_sacch_present(si6_specific);
1024
1025 /* release the channel */
1026 f_rsl_chan_deact();
1027 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1028}
1029testcase TC_sacch_chan_act() runs on test_CT {
1030 var ConnHdlr vc_conn;
1031 var ConnHdlrPars pars;
1032 f_init();
1033
1034 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1035 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1036 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1037 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1038 vc_conn.done;
1039 }
1040 /* TODO: do the above in parallel, rather than sequentially? */
1041 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1042}
1043
Harald Welte8b01c792019-05-19 22:51:25 +02001044/* verify that SACCH DL transmission is started only if MS power IE present
1045 * see section 4.1.3 of 3GPP TS 48.058 */
1046private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1047 var octetstring si5 := f_rnd_octstring(19);
1048
1049 f_l1_tune(L1CTL);
1050 RSL.clear;
1051
1052 /* Step 1: Activate ASYNC HO channel without MS power IE */
1053
1054 /* Activate channel on BTS side */
1055 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1056 /* don't perform immediate assignment here, as we're testing non-IA case */
1057 /* enable dedicated mode */
1058 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1059
1060 /* Verify that no DL SACCH is being received */
1061 f_sacch_missing(?);
1062
1063 f_rsl_chan_deact();
1064 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1065
1066
1067 /* Step 2: Activate ASYNC HO channel with MS power IE */
1068
1069 /* Activate channel on BTS side */
1070 var RSL_IE_List addl_ies := {
1071 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1072 };
1073 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1074 /* don't perform immediate assignment here, as we're testing non-IA case */
1075 /* enable dedicated mode */
1076 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1077
1078 /* Verify that DL SACCH is being received */
1079 f_sacch_present(si5);
1080
1081 f_rsl_chan_deact();
1082 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1083}
1084testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1085 var ConnHdlr vc_conn;
1086 var ConnHdlrPars pars;
1087 f_init();
1088
1089 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1090 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1091 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1092 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1093 vc_conn.done;
1094 }
1095 /* TODO: do the above in parallel, rather than sequentially? */
1096 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1097}
1098
1099/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1100 * see section 4.1.4 of 3GPP TS 48.058 */
1101private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1102 var octetstring si5 := f_rnd_octstring(19);
1103 var RSL_IE_List addl_ies;
1104
1105 f_l1_tune(L1CTL);
1106 RSL.clear;
1107
1108 /* Step 1: Activate SYNC HO channel without MS power IE */
1109
1110 /* Activate channel on BTS side */
1111 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1112 /* don't perform immediate assignment here, as we're testing non-IA case */
1113 /* enable dedicated mode */
1114 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1115
1116 /* Verify that no DL SACCH is being received */
1117 f_sacch_missing(?);
1118
1119 f_rsl_chan_deact();
1120 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1121
1122
1123 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1124
1125 /* Activate channel on BTS side */
1126 addl_ies := {
1127 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1128 };
1129 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1130 /* don't perform immediate assignment here, as we're testing non-IA case */
1131 /* enable dedicated mode */
1132 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1133
1134 /* Verify that no DL SACCH is being received */
1135 f_sacch_missing(?);
1136
1137 f_rsl_chan_deact();
1138 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1139
1140
1141 /* Step 2b: Activate SYNC HO channel with TA IE */
1142
1143 /* Activate channel on BTS side */
1144 addl_ies := {
1145 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1146 };
1147 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1148 /* don't perform immediate assignment here, as we're testing non-IA case */
1149 /* enable dedicated mode */
1150 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1151
1152 /* Verify that no DL SACCH is being received */
1153 f_sacch_missing(?);
1154
1155 f_rsl_chan_deact();
1156 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1157
1158
1159 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1160
1161 /* Activate channel on BTS side */
1162 addl_ies := {
1163 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1164 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1165 };
1166 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1167 /* don't perform immediate assignment here, as we're testing non-IA case */
1168 /* enable dedicated mode */
1169 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1170
1171 /* Verify that DL SACCH is being received */
1172 f_sacch_present(si5);
1173
1174 f_rsl_chan_deact();
1175 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1176}
1177testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1178 var ConnHdlr vc_conn;
1179 var ConnHdlrPars pars;
1180 f_init();
1181
1182 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1183 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1184 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1185 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1186 vc_conn.done;
1187 }
1188 /* TODO: do the above in parallel, rather than sequentially? */
1189 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1190}
Harald Welte629cc6b2018-03-11 17:19:05 +01001191
1192
1193/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001194 * RACH Handling
1195 ***********************************************************************/
1196
Harald Welte8c24c2b2018-02-26 08:31:31 +01001197/* like L1SAP_IS_PACKET_RACH */
1198private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +01001199 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001200 return true;
1201 }
1202 return false;
1203}
1204
1205/* generate a random RACH for circuit-switched */
1206private function f_rnd_ra_cs() return OCT1 {
1207 var OCT1 ra;
1208 do {
1209 ra := f_rnd_octstring(1);
1210 } while (ra_is_ps(ra));
1211 return ra;
1212}
1213
Harald Welte883340c2018-02-28 18:59:29 +01001214/* generate a random RACH for packet-switched */
1215private function f_rnd_ra_ps() return OCT1 {
1216 var OCT1 ra;
1217 do {
1218 ra := f_rnd_octstring(1);
1219 } while (not ra_is_ps(ra));
1220 return ra;
1221}
1222
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07001223/* generate a random 11-bit RA (packet-switched only) */
1224private function f_rnd_ra11_ps() return BIT11 {
1225 var integer ra11 := f_rnd_int(bit2int('11111111111'B));
1226 return int2bit(ra11, 11);
1227}
1228
Harald Welte8c24c2b2018-02-26 08:31:31 +01001229/* Send 1000 RACH requests and check their RA+FN on the RSL side */
1230testcase TC_rach_content() runs on test_CT {
1231 f_init(testcasename());
1232 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001233 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001234
Harald Welte8c24c2b2018-02-26 08:31:31 +01001235 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001236 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001237 for (var integer i := 0; i < 1000; i := i+1) {
1238 var OCT1 ra := f_rnd_ra_cs();
1239 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1240 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001241 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001242 }
1243 fn_last := fn;
1244
1245 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001246 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001247 alt {
1248 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, ?))) {
1249 T.stop;
1250 }
1251 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001252 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001253 }
1254 [] RSL_CCHAN.receive { repeat; }
1255 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001256 test_failed := true;
1257 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001258 }
1259 }
1260 }
Maxba06feb2019-03-05 10:52:46 +01001261 if (test_failed) {
1262 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001263 }
Maxba06feb2019-03-05 10:52:46 +01001264 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001265 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001266}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001267
1268/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1269testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001270 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001271 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001272 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001273 f_l1_tune(L1CTL);
1274
1275 var GsmFrameNumber fn_last := 0;
1276 for (var integer i := 0; i < 1000; i := i+1) {
1277 var OCT1 ra := f_rnd_ra_cs();
1278 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1279 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001280 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001281 }
1282 fn_last := fn;
1283 }
1284 var integer rsl_chrqd := 0;
1285 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001286 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001287 alt {
1288 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
1289 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001290 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001291 repeat;
1292 }
1293 [] RSL_CCHAN.receive { repeat; }
1294 [] T.timeout { }
1295 }
1296 if (rsl_chrqd == 1000) {
1297 setverdict(pass);
1298 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001299 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001300 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001301 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001302}
1303
Harald Welte3453ab42019-05-24 21:19:58 +02001304private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1305 var charstring bts_str := "bts " & int2str(bts_nr);
1306 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1307}
1308
1309/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1310private template integer tr_rach_slots_per_interval := (90 .. 130);
1311
1312/* Expect 0 RACH load on an idle BTS that has just started up */
1313testcase TC_rach_load_idle_thresh0() runs on test_CT {
1314 var ASP_RSL_Unitdata rx_ud;
1315
1316 f_init_vty_bsc();
1317 /* send load indications even at 0% load */
1318 f_vty_load_ind_thresh(0);
1319 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1320 f_sleep(2.0);
1321
1322 f_init();
1323
1324 timer T := 5.0;
1325 T.start;
1326 alt {
1327 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, 0, 0))) {
1328 setverdict(pass);
1329 repeat;
1330 }
1331 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1332 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1333 repeat;
1334 }
1335 [] RSL_CCHAN.receive {
1336 repeat;
1337 }
1338 [] T.timeout { }
1339 }
1340
1341 f_vty_load_ind_thresh(10);
1342 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1343}
1344
1345/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1346testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1347 var ASP_RSL_Unitdata rx_ud;
1348
1349 f_init_vty_bsc();
1350 f_init();
1351
1352 timer T := 5.0;
1353 T.start;
1354 alt {
1355 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1356 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1357 repeat;
1358 }
1359 [] RSL_CCHAN.receive {
1360 repeat;
1361 }
1362 [] T.timeout {
1363 setverdict(pass);
1364 }
1365 }
1366
1367 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1368}
1369
1370/* Expect 0 RACH load on an idle BTS that has just started up */
1371testcase TC_rach_load_count() runs on test_CT {
1372 var ASP_RSL_Unitdata rx_ud;
1373 var integer load_access_count := 0;
1374
1375 f_init_vty_bsc();
1376 /* send load indications even at 0% load */
1377 f_vty_load_ind_thresh(0);
1378 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1379 f_sleep(2.0);
1380 f_init();
1381
1382 f_init_l1ctl();
1383 f_sleep(1.0);
1384 f_l1_tune(L1CTL);
1385
1386 var GsmFrameNumber fn_last := 0;
1387 for (var integer i := 0; i < 1000; i := i+1) {
1388 var OCT1 ra := f_rnd_ra_cs();
1389 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1390 if (fn == fn_last) {
1391 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1392 }
1393 fn_last := fn;
1394 }
1395
1396 timer T := 5.0;
1397 T.start;
1398 alt {
1399 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
1400 -> value rx_ud {
1401 var RSL_IE_Body ie;
1402 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1403 load_access_count := load_access_count + ie.rach_load.access_count;
1404 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1405 setverdict(fail, "Access count cannot be < Busy count");
1406 }
1407 repeat;
1408 }
1409 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1410 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1411 repeat;
1412 }
1413 [] RSL_CCHAN.receive {
1414 repeat;
1415 }
1416 [] T.timeout { }
1417 }
1418 if (load_access_count == 1000) {
1419 setverdict(pass);
1420 } else {
1421 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1422 }
1423
1424 f_vty_load_ind_thresh(10);
1425 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1426}
1427
1428
1429
Harald Welte54a2a2d2018-02-26 09:14:05 +01001430private function f_main_trxc_connect() runs on test_CT {
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001431 map(self:BTS_TRXC, system:BTS_TRXC);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001432 var Result res;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001433 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BTS_TRXC, mp_bts_trxc_ip, mp_bts_trxc_port,
Harald Welted3a88a62018-03-01 16:04:52 +01001434 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +02001435 if (not ispresent(res.connId)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001436 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 +02001437 }
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001438 g_bts_trxc_conn_id := res.connId;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001439}
1440
1441private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001442 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001443 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001444 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001445 f_sleep(0.5);
1446
1447 /* Transmit RACH request + wait for confirmation */
1448 var OCT1 ra := f_rnd_ra_cs();
1449 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1450
1451 /* Check for expected result */
1452 timer T := 1.5;
1453 T.start;
1454 alt {
1455 [expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
1456 setverdict(pass);
1457 }
1458 [not expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001459 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001460 }
1461 [] RSL_CCHAN.receive { repeat; }
1462 [not expect_pass] T.timeout {
1463 setverdict(pass);
1464 }
1465 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001466 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001467 }
1468 }
1469}
1470
1471/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1472testcase TC_rach_max_ta() runs on test_CT {
1473 f_init(testcasename());
1474 f_init_l1ctl();
1475 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001476 f_sleep(1.0);
1477
1478 /* default max-ta is 63 (full range of GSM timing advance */
1479
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001480 /* We allow early arrival up to 2 symbols */
1481 f_rach_toffs(-1*256, true);
1482 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001483 f_rach_toffs(-10*256, false);
1484
1485 /* 0 / 32 / 63 bits is legal / permitted */
1486 f_rach_toffs(0, true);
1487 f_rach_toffs(32*256, true);
1488 f_rach_toffs(63*256, true);
1489
1490 /* more than 63 bits is not legal / permitted */
1491 f_rach_toffs(64*256, false);
1492 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001493 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001494}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001495
Harald Welte93640c62018-02-25 16:59:33 +01001496/***********************************************************************
1497 * Measurement Processing / Reporting
1498 ***********************************************************************/
1499
Harald Welte70767382018-02-21 12:16:40 +01001500template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1501 spare := '0'B,
1502 lpd := 0,
1503 sapi := sapi,
1504 c_r := c_r,
1505 ea := true
1506}
1507
Harald Welted879bd92018-03-12 15:01:23 +01001508template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001509 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001510 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001511 len := 0, /* overwritten */
1512 m := false,
1513 el := 1,
1514 payload := pl
1515}
1516
1517/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1518altstep as_l1_sacch() runs on ConnHdlr {
1519 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001520 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001521 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001522 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 +01001523 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001524 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001525
1526 var L1ctlDataReq data_req := {
1527 l1header := valueof(ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta)),
1528 l2_payload := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O)
1529 }
1530 log("Sending Measurement Report: ", data_req);
1531 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), data_req));
Harald Welte70767382018-02-21 12:16:40 +01001532 repeat;
1533 }
1534}
1535
1536altstep as_l1_dcch() runs on ConnHdlr {
1537 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001538 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001539 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1540 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001541 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1542 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001543 repeat;
1544 }
1545}
1546
1547type record MeasElem {
1548 uint6_t rxlev,
1549 uint3_t rxqual
1550}
1551
1552type record MeasElemFS {
1553 MeasElem full,
1554 MeasElem sub
1555}
1556
1557type record ConnL1Pars {
1558 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001559 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001560 MeasElemFS meas_ul,
1561 int16_t timing_offset_256syms,
1562 uint5_t bs_power_level,
1563 uint5_t ms_power_level,
1564 uint8_t ms_actual_ta
1565}
1566
1567/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1568private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1569 return 63 + (toffs256s/256);
1570}
1571
Harald Welted5684392018-03-10 18:22:04 +01001572private function f_max(integer a, integer b) return integer {
1573 if (a > b) {
1574 return a;
1575 } else {
1576 return b;
1577 }
1578}
1579
1580private function f_min(integer a, integer b) return integer {
1581 if (a < b) {
1582 return a;
1583 } else {
1584 return b;
1585 }
1586}
1587
1588/* compute negative tolerance val-tolerance, ensure >= min */
1589private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1590 val := val - tolerance;
1591 return f_max(val, min);
1592}
1593
1594/* compute positive tolerance val+tolerance, ensure <= max */
1595private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1596 val := val + tolerance;
1597 return f_min(val, max);
1598}
1599
1600/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1601private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1602return template integer {
1603 var template integer ret;
1604 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1605 return ret;
1606}
1607
1608
Harald Welte70767382018-02-21 12:16:40 +01001609/* build a template for matching measurement results against */
1610private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1611 var ConnL1Pars l1p := g_pars.l1_pars;
1612 var template RSL_IE_UplinkMeas ul_meas := {
1613 len := 3,
1614 rfu := '0'B,
1615 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001616 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001617 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001618 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001619 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001620 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1621 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001622 supp_meas_info := omit
1623 };
Harald Welte685d5982018-02-27 20:42:05 +01001624 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001625 ul_meas.len := (3+8);
1626 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001627 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001628 toa256_min := ?,
1629 toa256_max := ?,
1630 toa256_std_dev := ?
1631 }
Harald Welte685d5982018-02-27 20:42:05 +01001632 }
Harald Welte70767382018-02-21 12:16:40 +01001633 var template RSL_IE_BS_Power bs_power := {
1634 reserved := 0,
1635 epc := false,
1636 fpc := false,
1637 power_level := l1p.bs_power_level
1638 };
1639 var template RSL_IE_L1Info l1_info := {
1640 ms_power_lvl := l1p.ms_power_level,
1641 fpc := false,
1642 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001643 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001644 };
1645 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001646 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001647 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1648 ?, t_toffs);
1649}
1650
1651/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001652altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001653 var RSL_Message rsl;
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001654 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Harald Welte70767382018-02-21 12:16:40 +01001655 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1656 /* increment counter of next to-be-expected meas rep */
1657 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1658 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001659 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001660 repeat;
1661 }
1662 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001663 /* increment counter of next to-be-expected meas rep */
1664 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1665 if (g_first_meas_res) {
1666 g_first_meas_res := false;
1667 repeat;
1668 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001669 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001670 }
Harald Welte70767382018-02-21 12:16:40 +01001671 }
1672 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001673 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001674 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001675 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001676 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001677 }
1678}
1679
Harald Weltee613f962018-04-18 22:38:16 +02001680private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1681 select (rsl_alg_id) {
1682 case (RSL_ALG_ID_A5_0) { return 0; }
1683 case (RSL_ALG_ID_A5_1) { return 1; }
1684 case (RSL_ALG_ID_A5_2) { return 2; }
1685 case (RSL_ALG_ID_A5_3) { return 3; }
1686 case (RSL_ALG_ID_A5_4) { return 4; }
1687 case (RSL_ALG_ID_A5_5) { return 5; }
1688 case (RSL_ALG_ID_A5_6) { return 6; }
1689 case (RSL_ALG_ID_A5_7) { return 7; }
1690 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001691 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1692 /* Make compiler happy by calling mtc.stop here. It is already
1693 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001694 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001695 }
1696 }
1697}
1698
1699private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1700 select (rsl_alg_id) {
1701 case (RSL_ALG_ID_A5_1) { return '000'B; }
1702 case (RSL_ALG_ID_A5_2) { return '001'B; }
1703 case (RSL_ALG_ID_A5_3) { return '010'B; }
1704 case (RSL_ALG_ID_A5_4) { return '011'B; }
1705 case (RSL_ALG_ID_A5_5) { return '100'B; }
1706 case (RSL_ALG_ID_A5_6) { return '101'B; }
1707 case (RSL_ALG_ID_A5_7) { return '110'B; }
1708 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001709 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1710 /* Make compiler happy by calling mtc.stop here. It is already
1711 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001712 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001713 }
1714 }
1715}
1716
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001717/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1718private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1719 var GsmFrameNumber fn;
1720 timer T := 8.0;
1721
1722 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1723 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1724
1725 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1726 /* Send the actual RACH */
1727 fn := f_L1CTL_RACH(L1CTL, ra);
1728
1729 T.start;
1730 alt {
1731 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1732 [] T.timeout {
1733 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1734 }
1735 }
1736 T.stop
1737 return fn;
1738}
Harald Weltee613f962018-04-18 22:38:16 +02001739
Harald Welte70767382018-02-21 12:16:40 +01001740/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001741private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001742 var GsmFrameNumber fn;
1743 var ImmediateAssignment imm_ass;
1744 var integer ra := 23;
1745
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001746 /* Send RACH request and wait for ChanReq */
1747 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001748
1749 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001750 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01001751
1752 /* Send IMM.ASS via CCHAN */
1753 var ChannelDescription ch_desc := {
1754 chan_nr := g_pars.chan_nr,
1755 tsc := 7,
1756 h := false,
1757 arfcn := mp_trx0_arfcn,
1758 maio_hsn := omit
1759 };
1760 var MobileAllocation ma := {
1761 len := 0,
1762 ma := ''B
1763 };
1764 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1765 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1766
1767 /* receive IMM.ASS on MS side */
1768 var ImmediateAssignment ia_um;
1769 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1770 /* enable dedicated mode */
1771 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltee613f962018-04-18 22:38:16 +02001772 /* enable encryption, if requested */
1773 if (encr_enable) {
1774 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1775 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1776 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001777
1778 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001779}
1780
1781/* establish DChan, verify existance + contents of measurement reports */
1782function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001783 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001784 RSL.clear;
1785
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001786 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001787 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001788 f_trx_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
1789 }
Harald Welte70767382018-02-21 12:16:40 +01001790
1791 f_est_dchan();
1792
1793 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1794 * RSL measurement reports on Abis side */
1795 timer T := 8.0;
1796 T.start;
1797 alt {
1798 [] as_l1_sacch();
1799 [] as_meas_res();
1800 [] as_l1_dcch();
1801 [] L1CTL.receive { repeat; }
1802 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001803 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01001804 * of any earlier errors, so if we reach this timeout, we're good */
1805 setverdict(pass);
1806 }
1807 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001808 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01001809 }
1810 }
1811 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001812 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001813}
Harald Welte0472ab42018-03-12 15:02:26 +01001814
Harald Welte70767382018-02-21 12:16:40 +01001815testcase TC_meas_res_sign_tchf() runs on test_CT {
1816 var ConnHdlr vc_conn;
1817 var ConnHdlrPars pars;
1818 f_init(testcasename());
1819 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1820 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1821 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1822 vc_conn.done;
1823 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001824 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001825}
1826testcase TC_meas_res_sign_tchh() runs on test_CT {
1827 var ConnHdlr vc_conn;
1828 var ConnHdlrPars pars;
1829 f_init(testcasename());
1830 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1831 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1832 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1833 vc_conn.done;
1834 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001835 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001836}
1837testcase TC_meas_res_sign_sdcch4() runs on test_CT {
1838 var ConnHdlr vc_conn;
1839 var ConnHdlrPars pars;
1840 f_init(testcasename());
1841 for (var integer ss := 0; ss <= 3; ss := ss+1) {
1842 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
1843 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1844 vc_conn.done;
1845 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001846 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001847}
1848testcase TC_meas_res_sign_sdcch8() runs on test_CT {
1849 var ConnHdlr vc_conn;
1850 var ConnHdlrPars pars;
1851 f_init(testcasename());
1852 for (var integer ss := 0; ss <= 7; ss := ss+1) {
1853 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
1854 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1855 vc_conn.done;
1856 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001857 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001858}
Harald Welte685d5982018-02-27 20:42:05 +01001859testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
1860 var ConnHdlr vc_conn;
1861 var ConnHdlrPars pars;
1862 f_init(testcasename());
1863 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
1864 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1865 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1866 pars.l1_pars.toa256_enabled := true;
1867 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1868 vc_conn.done;
1869 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001870 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01001871}
1872
Philipp Maier4d1e9c92018-12-20 11:11:56 +01001873/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
1874 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
1875function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
1876 var L1ctlDlMessage l1_dl;
1877 var RSL_IE_MS_Power ms_power;
1878 var RSL_Message rsl;
1879 var uint5_t power_level := 0;
1880
1881 f_l1_tune(L1CTL);
1882 RSL.clear;
1883
1884 f_est_dchan();
1885
1886 ms_power.reserved := 0;
1887 ms_power.fpc_epc := false;
1888
1889 /* Send the first power control command. This will disable any BTS/TRX
1890 * internal power control and switch the MS (which is not in scope of
1891 * this test) to a constant power level. We start with a power level
1892 * of 0 */
1893 ms_power.power_level := power_level;
1894 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1895 RSL.send(rsl);
1896
1897 alt {
1898
1899 /* Pick all SACCH blocks for checking */
1900 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1901
1902 /* The first byte of the L1 header contains the power level.
1903 * The reserved bits and the fpc bit is set to 0, so we may
1904 * compare directly. */
1905 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
1906 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
1907 }
1908
1909 /* Signal a new power level via RSL for the next turn. */
1910 if (power_level < 31) {
1911 power_level := power_level + 1;
1912 ms_power.power_level := power_level;
1913 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1914 RSL.send(rsl);
1915 repeat;
1916 }
1917
1918 }
1919
1920 /* Ignore all other blocks */
1921 [] L1CTL.receive { repeat; }
1922
1923 }
1924
1925 f_rsl_chan_deact();
1926 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1927
1928 setverdict(pass);
1929}
1930
1931testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
1932 var ConnHdlr vc_conn;
1933 var ConnHdlrPars pars;
1934 f_init(testcasename());
1935
1936 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1937 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1938 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
1939 vc_conn.done;
1940 }
1941 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1942}
Harald Welte70767382018-02-21 12:16:40 +01001943
Eric Wild6833cc92019-05-23 19:34:44 +02001944/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
1945TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
1946function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
1947 var L1ctlDlMessage l1_dl;
1948 var uint5_t ta_to_test := 16;
1949
1950
1951 f_l1_tune(L1CTL);
1952 RSL.clear;
1953
1954 /* tell fake_trx to use a given timing offset for all bursts */
1955 f_trx_fake_toffs256(ta_to_test*256);
1956
1957 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
1958
1959
1960 alt {
1961
1962 /* Pick all SACCH blocks for checking */
1963 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1964
1965 /* The second byte of the L1 header contains the TA. */
1966 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
1967 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
1968 }
1969
1970 }
1971
1972 /* Ignore all other blocks */
1973 [] L1CTL.receive { repeat; }
1974
1975 }
1976
1977 f_rsl_chan_deact();
1978 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1979
1980 setverdict(pass);
1981}
1982
1983testcase TC_rsl_chan_initial_ta() runs on test_CT {
1984 var ConnHdlr vc_conn;
1985 var ConnHdlrPars pars;
1986 f_init(testcasename());
1987 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
1988 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars);
1989 vc_conn.done;
1990 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1991}
1992
Harald Welte0472ab42018-03-12 15:02:26 +01001993/* 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 +01001994private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001995 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001996 RSL.clear;
1997
1998 f_est_dchan();
1999 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01002000 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01002001
2002 timer T := 40.0;
2003 T.start;
2004 alt {
2005 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
2006 setverdict(pass)
2007 }
2008 [] RSL.receive { repeat };
2009 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002010 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01002011 }
2012 }
2013 f_rsl_chan_deact();
2014}
2015testcase TC_conn_fail_crit() runs on test_CT {
2016 var ConnHdlr vc_conn;
2017 var ConnHdlrPars pars;
2018 f_init(testcasename());
2019 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
2020 pars.t_guard := 60.0;
2021 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
2022 vc_conn.done;
2023}
2024
Harald Welte93640c62018-02-25 16:59:33 +01002025/***********************************************************************
2026 * Paging
2027 ***********************************************************************/
2028
Harald Welte68e495b2018-02-25 00:05:57 +01002029function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
2030 if (tmsi == 'FFFFFFFF'O) {
2031 return true;
2032 } else {
2033 return false;
2034 }
2035}
Harald Welte70767382018-02-21 12:16:40 +01002036
Philipp Maier82cb0b12018-08-31 14:41:39 +02002037type record allowedFn { integer frame_nr }
2038template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
2039template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
2040template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
2041template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
2042template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
2043template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
2044template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
2045template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
2046function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
2047{
2048 var integer frame_nr_51;
2049 frame_nr_51 := frame_nr mod 51
2050
2051 var allowedFn fn_check;
2052 fn_check.frame_nr := frame_nr_51;
2053
2054 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002055 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002056 return;
2057 }
2058
2059 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
2060 return;
2061 }
2062 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
2063 return;
2064 }
2065 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
2066 return;
2067 }
2068 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
2069 return;
2070 }
2071 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
2072 return;
2073 }
2074 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
2075 return;
2076 }
2077 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
2078 return;
2079 }
2080 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
2081 return;
2082 }
2083
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002084 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002085 return;
2086}
2087
2088altstep 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 +01002089runs on test_CT {
2090 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002091 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002092 repeat;
2093 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01002094 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01002095 var octetstring without_plen :=
2096 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
2097 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02002098
2099 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
2100
Harald Welte68e495b2018-02-25 00:05:57 +01002101 if (match(rr, tr_PAGING_REQ1)) {
2102 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2103 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2104 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
2105 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2106 }
2107 } else if (match(rr, tr_PAGING_REQ2)) {
2108 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2109 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
2110 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2111 }
2112 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
2113 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2114 }
2115 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
2116 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2117 }
2118 } else if (match(rr, tr_PAGING_REQ3)) {
2119 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2120 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
2121 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2122 }
2123 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
2124 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2125 }
2126 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
2127 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2128 }
2129 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
2130 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2131 }
2132 }
2133 repeat;
2134 }
2135}
2136
2137type record PagingTestCfg {
2138 boolean combined_ccch,
2139 integer bs_ag_blks_res,
2140 float load_factor,
2141 boolean exp_load_ind,
2142 boolean exp_overload,
2143 boolean use_tmsi
2144}
2145
2146type record PagingTestState {
2147 integer num_paging_sent,
2148 integer num_paging_rcv_msgs,
2149 integer num_paging_rcv_ids,
2150 integer num_overload
2151}
2152
2153/* receive + ignore RSL RF RES IND */
2154altstep as_rsl_res_ind() runs on test_CT {
2155 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
2156 repeat;
2157 }
2158}
2159
2160/* Helper function for paging related testing */
2161private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
2162 f_init(testcasename());
2163 f_init_l1ctl();
2164 f_l1_tune(L1CTL);
2165
2166 var PagingTestState st := {
2167 num_paging_sent := 0,
2168 num_paging_rcv_msgs := 0,
2169 num_paging_rcv_ids := 0,
2170 num_overload := 0
2171 };
2172
2173 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
2174 var float max_pch_imsi_per_sec;
2175 if (cfg.use_tmsi) {
2176 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
2177 } else {
2178 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
2179 }
2180 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
2181 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002182 var float time_total := 20.0;
2183 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
2184 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01002185
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002186 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
2187 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01002188
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002189 timer T_itv := 0.0;
2190 T_itv.start;
2191 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01002192 alt {
2193 /* check for presence of CCCH LOAD IND (paging load) */
2194 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
2195 st.num_overload := st.num_overload + 1;
2196 repeat;
2197 }
2198 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002199 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01002200 }
2201 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
2202 log("Rx LOAD_IND");
2203 /* FIXME: analyze/verify interval + contents */
2204 repeat;
2205 }
2206 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02002207 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002208 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002209 [] T_itv.timeout {
2210 /* Send paging cmds based on elapsed time */
2211 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
2212 while (st.num_paging_sent < new_sent) {
2213 /* build mobile Identity */
2214 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2215 if (cfg.use_tmsi) {
2216 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2217 } else {
2218 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(st.num_paging_sent)));
2219 }
2220 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2221 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2222
2223 /* Send RSL PAGING COMMAND */
2224 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, st.num_paging_sent mod 4)));
2225
2226 st.num_paging_sent := st.num_paging_sent + 1;
2227 }
2228 if (st.num_paging_sent < pkt_total) {
2229 /* Wait for interval to next PAGING COMMAND */
2230 var float time_now := T_total.read;
2231 var float next_sched := int2float(st.num_paging_sent)*interval;
2232 if (next_sched > time_now) {
2233 T_itv.start(next_sched - time_now);
2234 } else {
2235 T_itv.start(0.0);
2236 }
2237 } else {
2238 /* We are done, no need to keep counting */
2239 T_total.stop;
2240 }
2241 }
2242 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01002243 [] as_rsl_res_ind();
2244 }
2245 }
2246
2247 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
2248 timer T_wait := 18.0;
2249 T_wait.start;
2250 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02002251 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002252 [] L1CTL.receive { repeat; }
2253 /* 65535 == empty paging queue, we can terminate*/
2254 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
2255 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
2256 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002257 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01002258 }
2259 [] as_rsl_res_ind();
2260 }
2261
2262 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
2263 " rcvd_ids=", st.num_paging_rcv_ids);
2264 return st;
2265}
2266
2267/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
2268 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2269 * - that CCCH LOAD IND (PCH) are being generated
2270 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2271testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002272 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002273 var PagingTestCfg cfg := {
2274 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002275 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002276 load_factor := 0.8,
2277 exp_load_ind := true,
2278 exp_overload := false,
2279 use_tmsi := false
2280 };
2281 var PagingTestState st := f_TC_paging(cfg);
2282 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002283 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2284 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002285 } else {
2286 setverdict(pass);
2287 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002288 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002289}
2290
2291/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
2292 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2293 * - that CCCH LOAD IND (PCH) are being generated
2294 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2295testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002296 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002297 var PagingTestCfg cfg := {
2298 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002299 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002300 load_factor := 0.8,
2301 exp_load_ind := true,
2302 exp_overload := false,
2303 use_tmsi := true
2304 };
2305 var PagingTestState st := f_TC_paging(cfg);
2306 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002307 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2308 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002309 } else {
2310 setverdict(pass);
2311 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002312 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002313}
2314
2315/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
2316 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2317 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2318 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2319testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002320 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002321 var PagingTestCfg cfg := {
2322 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002323 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002324 load_factor := 2.0,
2325 exp_load_ind := true,
2326 exp_overload := true,
2327 use_tmsi := false
2328 };
2329 var PagingTestState st := f_TC_paging(cfg);
2330 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
2331 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002332 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002333 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002334 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 +01002335 } else {
2336 setverdict(pass);
2337 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002338 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002339}
2340
2341/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
2342 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2343 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2344 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2345testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002346 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002347 var PagingTestCfg cfg := {
2348 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002349 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002350 load_factor := 2.0,
2351 exp_load_ind := true,
2352 exp_overload := true,
2353 use_tmsi := true
2354 };
2355 var PagingTestState st := f_TC_paging(cfg);
2356 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
2357 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002358 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002359 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002360 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 +01002361 } else {
2362 setverdict(pass);
2363 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002364 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002365}
2366
2367
Harald Welte93640c62018-02-25 16:59:33 +01002368/***********************************************************************
2369 * Immediate Assignment / AGCH
2370 ***********************************************************************/
Harald Weltee8d750e2018-06-10 21:41:35 +02002371const MobileAllocation c_MA_null := {
2372 len := 0,
2373 ma := ''B
2374}
Harald Welte93640c62018-02-25 16:59:33 +01002375
Harald Weltee8d750e2018-06-10 21:41:35 +02002376template (value) ChannelDescription ts_ChanDesc(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
2377 uint12_t arfcn := 871) := {
2378 chan_nr := chan_nr,
2379 tsc := tsc,
2380 h := false,
2381 arfcn := arfcn,
2382 maio_hsn := omit
2383}
2384
2385private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
2386 return int2str(num_tx) & " sent, "
2387 & int2str(num_rx) & " received, "
2388 & int2str(num_del) & " deleted";
2389}
2390
2391private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
2392 var L1ctlDlMessage l1_dl;
2393 timer T := 10.0;
2394 var integer num_tx := 0;
2395 var integer num_rx := 0;
2396 var integer num_del := 0;
2397 var charstring res_str;
2398 var float rx_ratio;
2399
Harald Welte68e495b2018-02-25 00:05:57 +01002400 f_init(testcasename());
Harald Weltee8d750e2018-06-10 21:41:35 +02002401 f_init_l1ctl();
2402 f_l1_tune(L1CTL);
2403
2404 for (var integer i := 0; i < num_total; i := i+1) {
2405 var ChannelDescription ch_desc := valueof(ts_ChanDesc(valueof(t_RslChanNr_SDCCH4(0, 0))));
2406 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
2407 var octetstring ia_enc := enc_GsmRrMessage(ia);
Harald Welte68e495b2018-02-25 00:05:57 +01002408 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02002409 num_tx := num_tx+1;
2410 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01002411 }
2412 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02002413 T.start;
2414 alt {
2415 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
2416 num_del := num_del+1;
2417 repeat;
2418 }
2419 [] RSL_CCHAN.receive {
2420 repeat;
2421 }
2422 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
2423 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2424 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
2425 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
2426 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002427 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02002428 } else {
2429 num_rx := num_rx+1;
2430 }
2431 repeat;
2432 }
2433 [] L1CTL.receive { repeat; }
2434 [] T.timeout { }
2435 }
2436 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
2437 log("AGCH test: " & res_str);
2438 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002439 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02002440 }
2441 rx_ratio := int2float(num_rx) / int2float(num_tx);
2442 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002443 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 +02002444 } else {
2445 setverdict(pass);
2446 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002447 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002448}
2449
Harald Weltee8d750e2018-06-10 21:41:35 +02002450/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
2451testcase TC_imm_ass_1000_20ms() runs on test_CT {
2452 f_TC_imm_ass(1000, 0.02, 0.25);
2453}
2454
2455/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
2456testcase TC_imm_ass_200_0ms() runs on test_CT {
2457 f_TC_imm_ass(200, 0.0, 0.05);
2458}
2459
2460/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
2461testcase TC_imm_ass_200_76ms() runs on test_CT {
2462 f_TC_imm_ass(150, 0.076, 1.00);
2463}
2464
2465
2466
Harald Welte48494ca2018-02-25 16:59:50 +01002467/***********************************************************************
2468 * BCCH
2469 ***********************************************************************/
2470
2471/* tuple of Frame Number + decoded SI */
2472type record SystemInformationFn {
2473 GsmFrameNumber frame_number,
2474 SystemInformation si
2475}
2476
2477/* an arbitrary-length vector of decoded SI + gsmtap header */
2478type record of SystemInformationFn SystemInformationVector;
2479
2480/* an array of SI-vectors indexed by TC value */
2481type SystemInformationVector SystemInformationVectorPerTc[8];
2482
2483/* determine if a given SI vector contains given SI type at least once */
2484function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2485 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2486 var integer fn_mod51 := arr[i].frame_number mod 51;
2487 if (not bcch_ext and fn_mod51 == 2 or
2488 bcch_ext and fn_mod51 == 6) {
2489 if (arr[i].si.header.message_type == key) {
2490 return true;
2491 }
2492 }
2493 }
2494 return false;
2495}
2496
2497/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
2498function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2499 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002500 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002501 }
2502}
2503
2504/* check if a given SI vector contains given SI type at least once on any TC */
2505function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
2506 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
2507 if (f_si_vecslot_contains(arr[tc], key) or
2508 f_si_vecslot_contains(arr[tc], key, true)) {
2509 return true;
2510 }
2511 }
2512 return false;
2513}
2514
2515/* determine if a given SI vector contains given SI type at least N of M times */
2516function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
2517 var integer count := 0;
2518 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002519 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01002520 }
2521 for (var integer i:= 0; i < m; i := i + 1) {
2522 var integer fn_mod51 := arr[i].frame_number mod 51;
2523 if (not bcch_ext and fn_mod51 == 2 or
2524 bcch_ext and fn_mod51 == 6) {
2525 if (arr[i].si.header.message_type == key) {
2526 count := count + 1;
2527 }
2528 }
2529 }
2530 if (count >= n) {
2531 return true;
2532 } else {
2533 return false;
2534 }
2535}
2536
2537/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
2538function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
2539 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002540 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002541 }
2542}
2543
2544/* determine if a given SI vector contains given SI type at least once */
2545function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2546 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2547 var integer fn_mod51 := arr[i].frame_number mod 51;
2548 if (not bcch_ext and fn_mod51 == 2 or
2549 bcch_ext and fn_mod51 == 6) {
2550 if (arr[i].si.header.message_type != key) {
2551 return false;
2552 }
2553 }
2554 }
2555 return true;
2556}
2557
2558/* ensure a given TC slot of the SI vector contains only given SI type */
2559function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2560 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002561 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002562 }
2563}
2564
2565/* SI configuration of cell, against which we validate actual SI messages */
2566type set SystemInformationConfig {
2567 boolean bcch_extended,
2568 boolean si1_present,
2569 boolean si2bis_present,
2570 boolean si2ter_present,
2571 boolean si2quater_present,
2572 boolean si7_present,
2573 boolean si8_present,
2574 boolean si9_present,
2575 boolean si13_present,
2576 boolean si13alt_present,
2577 boolean si15_present,
2578 boolean si16_present,
2579 boolean si17_present,
2580 boolean si2n_present,
2581 boolean si21_present,
2582 boolean si22_present
2583}
2584
2585/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
2586function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
2587 var integer i;
2588 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
2589 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002590 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01002591 }
2592 }
2593 if (cfg.si1_present) {
2594 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
2595 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
2596 * when TC = 0, it can assume that System Information Type 1 is not in use. */
2597 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2598 /* make sure *ALL* contain SI1 */
2599 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2600 }
2601 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
2602 /* iii) A SI 2 message will be sent at least every time TC = 1 */
2603 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
2604 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
2605 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
2606 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
2607
2608 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
2609 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
2610 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
2611 * consecutive occurrences of TC = 4. */
2612 if (cfg.si2bis_present and not cfg.si2ter_present) {
2613 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2614 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
2615 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
2616 } else if (cfg.si2ter_present and cfg.si2bis_present) {
2617 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2618 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
2619 }
2620
2621 if (cfg.si7_present or cfg.si8_present) {
2622 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
2623 * if System Information type 4 does not contain all information needed for cell
2624 * selection and reselection. */
2625 if (not cfg.bcch_extended) {
2626 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
2627 }
2628 if (cfg.si7_present) {
2629 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
2630 }
2631 if (cfg.si8_present) {
2632 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
2633 }
2634 }
2635
2636 if (cfg.si2quater_present) {
2637 /* iii) System information type 2 quater is sent if needed, as determined by the system
2638 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
2639 * and 2ter are used, otherwise it shall be sent at least once within any of 4
2640 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
2641 * within any of 4 consecutive occurrences of TC = 5. */
2642 if (not (cfg.bcch_extended)) {
2643 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
2644 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
2645 } else {
2646 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
2647 }
2648 } else {
2649 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
2650 }
2651 }
2652 if (cfg.si9_present) {
2653 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
2654 * in system information type 3 as defined in 3GPP TS 44.018. */
2655 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
2656 }
2657 if (cfg.si13_present) {
2658 /* vii) System Information type 13 is only related to the GPRS service. System Information
2659 * Type 13 need only be sent if GPRS support is indicated in one or more of System
2660 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
2661 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
2662 * In the case that the message is sent on the BCCH Norm, it is sent at least once
2663 * within any of 4 consecutive occurrences of TC=4. */
2664 if (not cfg.bcch_extended) {
2665 log("not-bccch-extended");
2666 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
2667 } else {
2668 log("bccch-extended");
2669 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
2670 }
2671 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002672 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002673 }
2674 }
2675 if (cfg.si16_present or cfg.si17_present) {
2676 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
2677 * should not be sent in a cell where network sharing is used (see rule xv). */
2678 if (cfg.si22_present) {
2679 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2680 }
2681 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002682 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002683 }
2684 if (not cfg.bcch_extended) {
2685 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
2686 }
2687 if (cfg.si16_present) {
2688 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
2689 }
2690 if (cfg.si17_present) {
2691 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
2692 }
2693 }
2694
2695 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
2696 * broadcast information. The frequency with which they are sent is determined by the
2697 * system operator. System Information type 9 identifies the scheduling of System
2698 * Information type 18 and 20 messages. */
2699
2700 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
2701 * Information Type 19 is present, then its scheduling shall be indicated in System
2702 * Information Type 9. */
2703
2704 if (cfg.si15_present) {
2705 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
2706 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
2707 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
2708 * 4 consecutive occurrences of TC = 1. */
2709 if (not cfg.bcch_extended) {
2710 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
2711 } else {
2712 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
2713 }
2714 }
2715 if (cfg.si13alt_present) {
2716 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
2717 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
2718 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
2719 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
2720 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
2721 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
2722 * of TC = 4. */
2723 if (cfg.si13_present) {
2724 testcase.stop("Error: Cannot have SI13alt and SI13");
2725 }
2726 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002727 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002728 }
2729 if (not cfg.bcch_extended) {
2730 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
2731 } else {
2732 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
2733 }
2734 }
2735 if (cfg.si2n_present) {
2736 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
2737 * as determined by the system operator. In the case that the message is sent on the
2738 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
2739 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
2740 * consecutive occurrences of TC = 4. */
2741 if (not cfg.bcch_extended) {
2742 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
2743 } else {
2744 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
2745 }
2746 }
2747 if (cfg.si21_present) {
2748 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
2749 * determined by the system operator. If Extended Access Barring is in use in the cell
2750 * then this message is sent at least once within any of 4 consecutive occurrences of
2751 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
2752 * cell then this message shall only be sent on BCCH Ext. */
2753 if (not cfg.bcch_extended) {
2754 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
2755 } else {
2756 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
2757 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002758 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01002759 }
2760 }
2761 }
2762 if (cfg.si22_present) {
2763 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
2764 * should not be sent in a cell where SoLSA is used (see rule viii). System
2765 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
2766 * =2 and TC=6. */
2767 if (cfg.si16_present or cfg.si17_present) {
2768 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2769 }
2770 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
2771 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002772 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002773 }
2774 if (not cfg.bcch_extended) {
2775 testcase.stop("Error: SI22 requires BCCH Extd!");
2776 } else {
2777 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
2778 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
2779 }
2780 }
2781}
2782
2783/* sample Systme Information for specified duration via L1CTL */
2784function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
2785 timer T := duration;
2786 var SystemInformationVectorPerTc si_per_tc;
2787 var L1ctlDlMessage l1_dl;
2788
2789 /* initialize all per-TC vectors empty */
2790 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2791 si_per_tc[i] := {};
2792 }
2793
2794 /* flush all previous L1 queued msgs */
2795 pt.clear;
2796
2797 T.start;
2798 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002799 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01002800 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2801 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
2802 log("Ignoring non-RR SI ", l1_dl);
2803 repeat;
2804 }
2805 var SystemInformationFn sig := {
2806 frame_number := l1_dl.dl_info.frame_nr,
2807 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
2808 }
2809 var integer tc := f_gsm_compute_tc(sig.frame_number);
2810 log("SI received at TC=", tc, ": ", sig.si);
2811 /* append to the per-TC bucket */
2812 si_per_tc[tc] := si_per_tc[tc] & { sig };
2813 repeat;
2814 }
2815 [] pt.receive { repeat; }
2816 [] T.timeout { }
2817 }
2818
2819 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2820 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
2821 }
2822 log("si_per_tc=", si_per_tc);
2823 return si_per_tc;
2824}
2825
2826/* helper function: Set given SI via RSL + validate scheduling.
2827 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
2828function f_TC_si_sched() runs on test_CT {
2829 var SystemInformationVectorPerTc si_per_tc;
2830 f_init_l1ctl();
2831 f_l1_tune(L1CTL);
2832
2833 /* Sample + Validate Scheduling */
2834 si_per_tc := f_l1_sample_si(L1CTL);
2835 f_validate_si_scheduling(si_cfg, si_per_tc);
2836
2837 setverdict(pass);
2838}
2839
2840testcase TC_si_sched_default() runs on test_CT {
2841 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01002842 /* 2+3+4 are mandatory and set in f_init() */
2843 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002844 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01002845}
2846
2847testcase TC_si_sched_1() runs on test_CT {
2848 f_init();
2849 si_cfg.si1_present := true;
2850 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002851 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002852 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002853}
2854
2855testcase TC_si_sched_2bis() runs on test_CT {
2856 f_init();
2857 si_cfg.si2bis_present := true;
2858 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2859 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002860 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002861}
2862
2863testcase TC_si_sched_2ter() runs on test_CT {
2864 f_init();
2865 si_cfg.si2ter_present := true;
2866 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2867 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002868 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002869}
2870
2871testcase TC_si_sched_2ter_2bis() runs on test_CT {
2872 f_init();
2873 si_cfg.si2bis_present := true;
2874 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2875 si_cfg.si2ter_present := true;
2876 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2877 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002878 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002879}
2880
2881testcase TC_si_sched_2quater() runs on test_CT {
2882 f_init();
2883 si_cfg.si2quater_present := true;
2884 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2885 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002886 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002887}
2888
2889testcase TC_si_sched_13() runs on test_CT {
2890 f_init();
2891 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002892 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002893 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002894 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002895}
2896
2897testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
2898 f_init();
2899 si_cfg.si2bis_present := true;
2900 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2901 si_cfg.si2ter_present := true;
2902 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2903 si_cfg.si2quater_present := true;
2904 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2905 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002906 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002907 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002908 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002909}
2910
2911
Harald Welte68e495b2018-02-25 00:05:57 +01002912testcase TC_bcch_info() runs on test_CT {
2913 f_init(testcasename());
2914 /* FIXME: enable / disable individual BCCH info */
2915 //ts_RSL_BCCH_INFO(si_type, info);
2916 /* expect no ERROR REPORT after either of them *
2917 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002918 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002919}
2920
Harald Welte93640c62018-02-25 16:59:33 +01002921/***********************************************************************
2922 * Low-Level Protocol Errors / ERROR REPORT
2923 ***********************************************************************/
2924
Harald Welte01d982c2018-02-25 01:31:40 +01002925private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
2926 timer T := 5.0;
2927 T.start;
2928 alt {
2929 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
2930 setverdict(pass);
2931 }
2932 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002933 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01002934 }
2935 [] RSL_CCHAN.receive {
2936 repeat;
2937 }
2938 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002939 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01002940 }
2941 }
2942}
2943
2944/* Provoke a protocol error (message too short) and match on ERROR REPORT */
2945testcase TC_rsl_protocol_error() runs on test_CT {
2946 f_init(testcasename());
2947 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2948 rsl.ies := omit;
2949 RSL_CCHAN.send(ts_RSL_UD(rsl));
2950
2951 f_exp_err_rep(RSL_ERR_PROTO);
2952}
2953
2954/* Provoke a mandatory IE error and match on ERROR REPORT */
2955testcase TC_rsl_mand_ie_error() runs on test_CT {
2956 f_init(testcasename());
2957
2958 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2959 rsl.ies := { rsl.ies[0] };
2960 RSL_CCHAN.send(ts_RSL_UD(rsl));
2961
2962 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
2963}
2964
2965/* Provoke an IE content error and match on ERROR REPORT */
2966testcase TC_rsl_ie_content_error() runs on test_CT {
2967 f_init(testcasename());
2968 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2969 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
2970 RSL_CCHAN.send(ts_RSL_UD(rsl));
2971
2972 f_exp_err_rep(RSL_ERR_IE_CONTENT);
2973}
2974
Harald Welteee25aae2019-05-19 14:32:37 +02002975/* attempt to activate channel with wrong RSL Message Discriminator IE */
2976function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
2977 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
2978 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
2979 RSL.send(rsl);
2980 f_rslem_unregister(0, g_chan_nr);
2981}
2982testcase TC_err_rep_wrong_mdisc() runs on test_CT {
2983 var ConnHdlr vc_conn;
2984 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
2985
2986 f_init(testcasename());
2987
2988 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
2989 vc_conn.done;
2990 f_exp_err_rep(RSL_ERR_MSG_DISCR);
2991
2992 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2993}
2994
2995/* Send messages with wrong message type */
2996function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
2997 var template (value) RSL_Message rsl_tx;
2998 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
2999 rsl_tx.msg_type := RSL_MT_NOT_CMD;
3000 RSL.send(rsl_tx);
3001 f_rslem_unregister(0, g_chan_nr);
3002}
3003function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
3004 var template (value) RSL_Message rsl_tx;
3005 /* we first have to activate the dedicated channel */
3006 f_rsl_chan_act(g_pars.chan_mode);
3007 /* ... to then send an invalid RLL message */
3008 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
3009 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
3010 RSL.send(rsl_tx);
3011 f_rslem_unregister(0, g_chan_nr);
3012}
3013testcase TC_err_rep_wrong_msg_type() runs on test_CT {
3014 var ConnHdlr vc_conn;
3015 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3016 var template (value) RSL_Message rsl_tx;
3017
3018 f_init(testcasename());
3019
3020 /* Common Channel with wrong message type */
3021 RSL_CCHAN.clear;
3022 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3023 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
3024 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3025 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3026
3027 /* TRX Management */
3028 RSL_CCHAN.clear;
3029 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
3030 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
3031 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3032 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3033
3034 /* Dedicated Channel */
3035 RSL_CCHAN.clear;
3036 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
3037 vc_conn.done;
3038 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3039
3040 /* RLL */
3041 RSL_CCHAN.clear;
3042 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
3043 vc_conn.done;
3044 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3045}
3046
3047/* Send messages in wrong sequence (RLL to an inactive lchan) */
3048function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
3049 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
3050 f_rslem_unregister(0, g_chan_nr);
3051}
3052testcase TC_err_rep_wrong_sequence() runs on test_CT {
3053 var ConnHdlr vc_conn;
3054 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3055
3056 f_init(testcasename());
3057
3058 RSL_CCHAN.clear;
3059 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
3060 vc_conn.done;
3061 f_exp_err_rep(RSL_ERR_MSG_SEQ);
3062}
3063
Harald Welte93640c62018-02-25 16:59:33 +01003064/***********************************************************************
3065 * IPA CRCX/MDCX/DLCS media stream handling
3066 ***********************************************************************/
3067
Harald Weltea871a382018-02-25 02:03:14 +01003068/* Send IPA DLCX to inactive lchan */
3069function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01003070 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3071 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01003072}
3073testcase TC_ipa_dlcx_not_active() runs on test_CT {
3074 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3075 f_init(testcasename());
3076 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
3077 vc_conn.done;
3078}
Harald Welte68e495b2018-02-25 00:05:57 +01003079
Harald Weltea3f1df92018-02-25 12:49:55 +01003080/* Send IPA CRCX twice to inactive lchan */
3081function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
3082 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3083 "IPA CRCX ACK");
3084 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
3085 "IPA CRCX NACK");
3086}
3087testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
3088 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3089 f_init(testcasename());
3090 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
3091 vc_conn.done;
3092}
3093
3094/* Regular sequence of CRCX/MDCX/DLCX */
3095function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3096 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3097 "IPA CRCX ACK");
3098 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3099 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3100 var uint7_t rtp_pt2 := f_rnd_int(127);
3101 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3102 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3103 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3104 "IPA MDCX ACK");
3105 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3106 "IPA DLCX ACK");
3107}
3108testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
3109 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3110 f_init(testcasename());
3111 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
3112 vc_conn.done;
3113}
3114
Harald Welte3ae11da2018-02-25 13:36:06 +01003115/* Sequence of CRCX, 2x MDCX, DLCX */
3116function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3117 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3118 "IPA CRCX ACK");
3119 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3120 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3121 var uint7_t rtp_pt2 := f_rnd_int(127);
3122 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3123 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3124 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3125 "IPA MDCX ACK");
3126 /* Second MDCX */
3127 remote_ip := f_rnd_int(c_UINT32_MAX);
3128 remote_port := f_rnd_int(c_UINT16_MAX);
3129 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3130 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3131 "IPA MDCX ACK");
3132 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3133 "IPA DLCX ACK");
3134}
3135testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
3136 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3137 f_init(testcasename());
3138 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
3139 vc_conn.done;
3140}
3141
Harald Welte9912eb52018-02-25 13:30:15 +01003142/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
3143function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
3144 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
3145 "IPA CRCX NACK");
3146}
3147testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
3148 var ConnHdlrPars pars;
3149 var ConnHdlr vc_conn;
3150 f_init(testcasename());
3151
3152 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
3153 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3154 vc_conn.done;
3155
3156 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
3157 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3158 vc_conn.done;
3159}
3160
Harald Weltea3f1df92018-02-25 12:49:55 +01003161
Harald Welte883340c2018-02-28 18:59:29 +01003162/***********************************************************************
3163 * PCU Socket related tests
3164 ***********************************************************************/
3165
Harald Welte07bd2d22019-05-25 11:03:30 +02003166/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003167friend 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 +01003168runs on test_CT {
3169 timer T := 3.0;
3170
3171 /* we don't expect any RTS.req before PDCH are active */
3172 T.start;
3173 alt {
3174 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003175 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01003176 }
3177 [] PCU.receive { repeat; }
3178 [] T.timeout { }
3179 }
3180
3181 /* Send PDCH activate request for known PDCH timeslot */
3182 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
3183
3184 /* we now expect RTS.req for this timeslot (only) */
3185 T.start;
3186 alt {
3187 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
3188 setverdict(pass);
3189 }
3190 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3191 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003192 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01003193 }
3194 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003195 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01003196 }
3197 [] PCU.receive { repeat; }
3198 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003199 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003200 }
3201 [not exp_success] T.timeout {
3202 setverdict(pass);
3203 }
3204 }
3205}
3206
Harald Welte07bd2d22019-05-25 11:03:30 +02003207/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003208friend 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 +01003209runs on test_CT {
3210 timer T := 3.0;
3211
3212 /* Send PDCH activate request for known PDCH timeslot */
3213 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
3214
3215 PCU.clear;
3216 /* we now expect no RTS.req for this timeslot */
3217 T.start;
3218 alt {
3219 [] 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 +02003220 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003221 }
3222 [] PCU.receive { repeat; }
3223 [] T.timeout {
3224 setverdict(pass);
3225 }
3226 }
3227}
3228
Harald Weltead033dc2019-05-25 17:28:16 +02003229friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003230 f_init();
3231 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
3232}
3233
Harald Welte883340c2018-02-28 18:59:29 +01003234/* PDCH activation via PCU socket; check for presence of RTS.req */
3235testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003236 f_init_pcu_test();
3237
Harald Welte883340c2018-02-28 18:59:29 +01003238 f_TC_pcu_act_req(0, 0, 7, true);
3239}
3240
3241/* PDCH activation via PCU socket on non-PDCU timeslot */
3242testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003243 f_init_pcu_test();
3244
Harald Welte883340c2018-02-28 18:59:29 +01003245 f_TC_pcu_act_req(0, 0, 1, false);
3246}
3247
3248/* PDCH activation via PCU socket on wrong BTS */
3249testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003250 f_init_pcu_test();
3251
Harald Welte883340c2018-02-28 18:59:29 +01003252 f_TC_pcu_act_req(23, 0, 7, false);
3253}
3254
3255/* PDCH activation via PCU socket on wrong TRX */
3256testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003257 f_init_pcu_test();
3258
Harald Welte883340c2018-02-28 18:59:29 +01003259 f_TC_pcu_act_req(0, 23, 7, false);
3260}
3261
3262/* PDCH deactivation via PCU socket; check for absence of RTS.req */
3263testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003264 f_init_pcu_test();
3265
Harald Welte883340c2018-02-28 18:59:29 +01003266 /* Activate PDCH */
3267 f_TC_pcu_act_req(0, 0, 7, true);
3268 f_sleep(1.0);
3269 /* and De-Activate again */
3270 f_TC_pcu_deact_req(0, 0, 7);
3271}
3272
3273/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
3274testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003275 f_init_pcu_test();
3276
Harald Welte883340c2018-02-28 18:59:29 +01003277 f_TC_pcu_deact_req(0, 0, 1);
3278}
3279
3280/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
3281testcase TC_pcu_ver_si13() runs on test_CT {
3282 const octetstring si13 := '00010203040506070909'O;
3283 var PCUIF_send_data sd;
3284 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01003285 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003286
3287 /* Set SI13 via RSL */
3288 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01003289
Harald Welte883340c2018-02-28 18:59:29 +01003290 T.start;
3291 alt {
3292 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
3293 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
3294 setverdict(pass);
3295 } else {
3296 repeat;
3297 }
3298 }
3299 [] PCU.receive { repeat; }
3300 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003301 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01003302 }
3303 }
3304}
3305
3306private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
3307
3308/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02003309friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01003310 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
3311runs on test_CT
3312{
3313 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
3314 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
3315}
3316
3317/* 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 +02003318friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
3319 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01003320runs on test_CT
3321{
3322 var PCUIF_send_data sd;
3323
3324 timer T := 3.0;
3325 T.start;
3326 alt {
3327 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3328 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
3329 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
3330 sd.data.u.rts_req.fn, sapi, data);
3331 }
3332 [] PCU.receive { repeat; }
3333 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003334 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01003335 }
3336 }
3337}
3338
3339/* Send DATA.req on invalid BTS */
3340testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003341 var TfiUsfArr tua := f_TfiUsfArrInit();
3342 var octetstring data := '0000'O & f_rnd_octstring(21);
3343
3344 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003345
Harald Welte883340c2018-02-28 18:59:29 +01003346 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003347 f_TfiUsfArrSet(tua, 7, 0);
3348 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3349 f_sleep(1.0);
3350
3351 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003352}
3353
3354/* Send DATA.req on invalid TRX */
3355testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003356 var TfiUsfArr tua := f_TfiUsfArrInit();
3357 var octetstring data := '0000'O & f_rnd_octstring(21);
3358
3359 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003360
Harald Welte883340c2018-02-28 18:59:29 +01003361 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003362 f_TfiUsfArrSet(tua, 7, 0);
3363 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3364 f_sleep(1.0);
3365
3366 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003367}
3368
3369/* Send DATA.req on invalid timeslot */
3370testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003371 var TfiUsfArr tua := f_TfiUsfArrInit();
3372 var octetstring data := '0000'O & f_rnd_octstring(21);
3373
3374 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003375
Harald Welte883340c2018-02-28 18:59:29 +01003376 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003377 f_TfiUsfArrSet(tua, 7, 0);
3378 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3379 f_sleep(1.0);
3380
3381 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003382}
3383
3384/* Send DATA.req on timeslot that hasn't been activated */
3385testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003386 var TfiUsfArr tua := f_TfiUsfArrInit();
3387 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01003388
Harald Welte7162a612019-05-26 12:56:09 +02003389 f_virtphy_common();
3390
3391 f_TfiUsfArrSet(tua, 7, 0);
3392 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3393 f_sleep(1.0);
3394
3395 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003396}
3397
Harald Weltead033dc2019-05-25 17:28:16 +02003398private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02003399 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
3400 boolean wait_rts := true)
3401runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003402 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02003403 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02003404
3405 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02003406 if (wait_rts) {
3407 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
3408 } else {
3409 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
3410 }
Harald Weltead033dc2019-05-25 17:28:16 +02003411
3412 T.start;
3413 alt {
Harald Welte7162a612019-05-26 12:56:09 +02003414 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02003415 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
3416 setverdict(pass);
3417 }
Harald Welte7162a612019-05-26 12:56:09 +02003418 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
3419 setverdict(fail, "Received unexpected ", rx_dl);
3420 }
Harald Weltead033dc2019-05-25 17:28:16 +02003421 [] L1CTL.receive {
3422 repeat;
3423 }
Harald Welte7162a612019-05-26 12:56:09 +02003424 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02003425 setverdict(fail, "Timeout waiting for ", data);
3426 }
Harald Welte7162a612019-05-26 12:56:09 +02003427 [not expect_data] T.timeout {
3428 setverdict(pass);
3429 }
Harald Weltead033dc2019-05-25 17:28:16 +02003430 }
3431}
3432
3433private function f_disable_dynamic_ts() runs on test_CT
3434{
3435 f_init_vty_bsc();
3436 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
3437 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
3438 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
3439 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01003440 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02003441}
3442
3443private function f_virtphy_common() runs on test_CT {
3444 f_disable_dynamic_ts();
3445 f_init_l1ctl();
3446 f_l1_tune(L1CTL);
3447}
3448
3449testcase TC_pcu_data_req_pdtch() runs on test_CT {
3450 var TfiUsfArr tua := f_TfiUsfArrInit();
3451 var octetstring data := '0000'O & f_rnd_octstring(21);
3452
3453 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003454
Harald Welte883340c2018-02-28 18:59:29 +01003455 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003456 f_TfiUsfArrSet(tua, 7, 0);
3457 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3458 f_sleep(1.0);
3459
3460 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01003461}
3462
3463testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003464 var TfiUsfArr tua := f_TfiUsfArrInit();
3465 var octetstring data := '0000'O & f_rnd_octstring(21);
3466
3467 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003468
Harald Welte883340c2018-02-28 18:59:29 +01003469 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003470 f_TfiUsfArrSet(tua, 7, 0);
3471 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3472 f_sleep(1.0);
3473
3474 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01003475}
3476
3477/* Send AGCH from PCU; check it appears on Um side */
3478testcase TC_pcu_data_req_agch() runs on test_CT {
3479 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01003480 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003481 f_init_l1ctl();
3482 f_l1_tune(L1CTL);
3483
3484 f_TC_pcu_act_req(0, 0, 7, true);
3485 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
3486
3487 T.start;
3488 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003489 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01003490 setverdict(pass);
3491 }
3492 [] L1CTL.receive { repeat; }
3493 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003494 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003495 }
3496 }
3497}
3498
Harald Welte928622b2019-05-26 13:22:59 +02003499/* Send AGCH from PCU; check it appears on Um side */
3500testcase TC_pcu_data_req_pch() runs on test_CT {
3501 timer T := 3.0;
3502 f_init_pcu_test();
3503 f_init_l1ctl();
3504 f_l1_tune(L1CTL);
3505
3506 f_TC_pcu_act_req(0, 0, 7, true);
3507 /* three characters prefix: last 3 digits of IMSI as ASCII */
3508 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
3509
3510 T.start;
3511 alt {
3512 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
3513 setverdict(pass);
3514 }
3515 [] L1CTL.receive { repeat; }
3516 [] T.timeout {
3517 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
3518 }
3519 }
3520}
3521
Harald Welte883340c2018-02-28 18:59:29 +01003522/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
3523testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
3524 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01003525 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003526 f_init_l1ctl();
3527 f_l1_tune(L1CTL);
3528
3529 /* append 3 last imsi digits so BTS can compute pagng group */
3530 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
3531
3532 timer T := 0.5;
3533 T.start;
3534 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003535 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01003536 /* TODO: verify paging group */
3537 setverdict(pass);
3538 }
3539 [] L1CTL.receive { repeat; }
3540 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003541 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003542 }
3543 }
3544}
3545
3546/* Send RACH from Um side, expect it to show up on PCU socket */
3547testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003548 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003549 f_init_l1ctl();
3550 f_l1_tune(L1CTL);
3551
3552 var GsmFrameNumber fn_last := 0;
3553 for (var integer i := 0; i < 1000; i := i+1) {
3554 var OCT1 ra := f_rnd_ra_ps();
3555 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
3556 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003557 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01003558 }
3559 fn_last := fn;
3560
3561 timer T := 2.0;
3562 T.start;
3563 alt {
3564 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
3565 T.stop;
3566 }
3567 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003568 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003569 }
3570 [] PCU.receive { repeat; }
3571 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003572 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003573 }
3574 }
3575 }
3576 setverdict(pass);
3577}
3578
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07003579/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
3580 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
3581testcase TC_pcu_ext_rach_content() runs on test_CT {
3582 var template PCUIF_Message pcu_rach_ind;
3583 var GsmFrameNumber fn_last := 0;
3584 var L1ctlRachSynchSeq synch_seq;
3585 var PCUIF_BurstType pcu_bt;
3586 var GsmFrameNumber fn;
3587 var BIT11 ra11;
3588
3589 f_init_pcu_test();
3590 f_init_l1ctl();
3591 f_l1_tune(L1CTL);
3592
3593 for (var integer i := 0; i < 1000; i := i+1) {
3594 /* We need to test both TS1 & TS2 */
3595 if (i rem 2 == 0) {
3596 synch_seq := RACH_SYNCH_SEQ_TS1;
3597 pcu_bt := BURST_TYPE_1;
3598 } else {
3599 synch_seq := RACH_SYNCH_SEQ_TS2;
3600 pcu_bt := BURST_TYPE_2;
3601 }
3602
3603 ra11 := f_rnd_ra11_ps();
3604 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
3605 if (fn == fn_last) {
3606 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3607 "Two RACH in same FN?!?");
3608 }
3609 fn_last := fn;
3610
3611 /* Compose the expected message */
3612 pcu_rach_ind := tr_PCUIF_RACH_IND(
3613 bts_nr := 0,
3614 ra := bit2int(ra11),
3615 is_11bit := 1,
3616 burst_type := pcu_bt,
3617 fn := fn);
3618
3619 timer T := 2.0;
3620 T.start;
3621 alt {
3622 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
3623 T.stop;
3624 }
3625 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
3626 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
3627 }
3628 [] PCU.receive { repeat; }
3629 [] T.timeout {
3630 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
3631 }
3632 }
3633 }
3634 setverdict(pass);
3635}
3636
Harald Welte883340c2018-02-28 18:59:29 +01003637private function f_pad_oct(octetstring str, integer len, OCT1 pad) return octetstring {
3638 var integer strlen := lengthof(str);
3639 for (var integer i := 0; i < len-strlen; i := i+1) {
3640 str := str & pad;
3641 }
3642 return str;
3643}
3644
3645/* Send PAGING via RSL, expect it to shw up on PCU socket */
3646testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003647 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003648
3649 for (var integer i := 0; i < 100; i := i+1) {
3650 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
3651 timer T := 3.0;
3652 if (i < 50) {
3653 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
3654 } else {
3655 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
3656 }
3657 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
3658 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
3659 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
3660
3661 /* Send RSL PAGING COMMAND */
3662 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
3663 T.start;
3664 alt {
3665 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
3666 }
3667 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003668 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003669 }
3670 [] PCU.receive { repeat; }
3671 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003672 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003673 }
3674 }
3675 }
3676 setverdict(pass);
3677}
3678
Harald Welted66c9b82019-05-25 09:03:15 +02003679/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
3680testcase TC_pcu_time_ind() runs on test_CT {
3681 var PCUIF_send_data pcu_sd;
3682 var integer num_time_ind := 0;
3683 var integer first_fn, last_fn;
3684 var float test_duration := 5.0;
3685 timer T;
3686
3687 f_init_pcu_test();
3688 f_TC_pcu_act_req(0, 0, 7, true);
3689
3690 PCU.clear;
3691 T.start(test_duration);
3692 alt {
3693 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
3694 num_time_ind := num_time_ind + 1;
3695 if (not isbound(first_fn)) {
3696 first_fn := pcu_sd.data.u.time_ind.fn;
3697 }
3698 last_fn := pcu_sd.data.u.time_ind.fn;
3699 repeat;
3700 }
3701 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
3702 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
3703 repeat;
3704 }
3705 [] PCU.receive {
3706 repeat;
3707 }
3708 [] T.timeout {}
3709 }
3710 var integer fn_expired := last_fn - first_fn;
3711 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
3712
3713 /* verify the number of frames expired matches our expectation */
3714 const float c_GSM_FN_DURATION_MS := 4.61538;
3715 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
3716 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 10);
3717 if (not match(fn_expired, t_fn_expected)) {
3718 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
3719 }
3720
3721 /* There are three TIME.ind in every fn MOD 13 */
3722 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
3723 /* Add some tolerance */
3724 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
3725 if (not match(num_time_ind, t_time_ind_exp)) {
3726 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
3727 }
3728
3729 setverdict(pass);
3730}
3731
Harald Welte4832c862019-05-25 14:57:18 +02003732/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
3733testcase TC_pcu_rts_req() runs on test_CT {
3734 var PCUIF_send_data pcu_sd;
3735 var integer first_fn, last_fn;
3736 var integer num_rts_pdtch := 0;
3737 var integer num_rts_ptcch := 0;
3738 var float test_duration := 5.0;
3739 timer T;
3740
3741 f_init_pcu_test();
3742 f_TC_pcu_act_req(0, 0, 7, true);
3743
3744 PCU.clear;
3745 T.start(test_duration);
3746 alt {
3747 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
3748 -> value pcu_sd {
3749 num_rts_pdtch := num_rts_pdtch + 1;
3750 if (not isbound(first_fn)) {
3751 first_fn := pcu_sd.data.u.rts_req.fn;
3752 }
3753 last_fn := pcu_sd.data.u.rts_req.fn;
3754 repeat;
3755 }
3756 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
3757 -> value pcu_sd {
3758 num_rts_ptcch := num_rts_ptcch + 1;
3759 if (not isbound(first_fn)) {
3760 first_fn := pcu_sd.data.u.rts_req.fn;
3761 }
3762 last_fn := pcu_sd.data.u.rts_req.fn;
3763 repeat;
3764 }
3765 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
3766 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
3767 repeat;
3768 }
3769 [] PCU.receive {
3770 repeat;
3771 }
3772 [] T.timeout {}
3773 }
3774 var integer fn_expired := last_fn - first_fn;
3775 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
3776 ", num_rts_ptcch=", num_rts_ptcch);
3777
3778 /* verify the number of frames expired matches our expectation */
3779 const float c_GSM_FN_DURATION_MS := 4.61538;
3780 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
3781 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 10);
3782 if (not match(fn_expired, t_fn_expected)) {
3783 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
3784 }
3785
3786 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
3787 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
3788 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
3789 if (not match(num_rts_ptcch, t_ptcch_exp)) {
3790 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
3791 t_ptcch_exp);
3792 }
3793
3794 /* We have 12 PDTCH blocks every 52-multiframe */
3795 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
3796 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
3797 if (not match(num_rts_pdtch, t_pdtch_exp)) {
3798 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
3799 t_pdtch_exp);
3800 }
3801
3802 setverdict(pass);
3803}
3804
Harald Welte07bd2d22019-05-25 11:03:30 +02003805/* test for generating Abis side OML ALERT from the PCU */
3806testcase TC_pcu_oml_alert() runs on test_CT {
3807 var PCUIF_send_data pcu_sd;
3808 var integer num_time_ind := 0;
3809 var integer first_fn, last_fn;
3810 var float test_duration := 5.0;
3811 timer T;
3812
3813 f_init_pcu_test();
3814 f_TC_pcu_act_req(0, 0, 7, true);
3815
3816 /* re-connect CTRL port from BTS to BSC */
3817 f_ipa_ctrl_stop();
3818 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
3819
3820 /* Send that OML Alert */
3821 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
3822
3823 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
3824 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
3825 setverdict(pass);
3826}
3827
Harald Welteeaa9a862019-05-26 23:01:08 +02003828template (value) PDU_ML3_MS_NW ts_RRM_GprsSuspReq(template (value) OCT4 tlli,
3829 template (value) RoutingAreaIdentificationV rai,
3830 template (value) OCT1 cause) := {
3831 discriminator := '0000'B, /* overwritten */
3832 tiOrSkip := {
3833 skipIndicator := '0000'B
3834 },
3835 msgs := {
3836 rrm := {
3837 gPRS_suspensionRequest := {
3838 messageType := '00110100'B,
3839 tLLI := tlli,
3840 routingAreaIdentification := rai,
3841 suspensionCause := cause,
3842 service_Support := omit
3843 }
3844 }
3845 }
3846}
3847
3848/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
3849private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
3850 var PCUIF_Message first_info;
3851 var integer pcu_conn_id := -1;
3852 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3853 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
3854 var OCT4 tlli := '01020304'O;
3855 var OCT1 cause := '23'O;
3856 timer T := 5.0;
3857
3858 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3859
3860 f_l1_tune(L1CTL);
3861 RSL.clear;
3862
3863 f_est_dchan();
3864 L1CTL.clear;
3865
3866 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
3867
3868 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
3869 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
3870 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
3871
3872 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
3873 T.start;
3874 alt {
3875 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
3876 setverdict(pass);
3877 }
3878 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
3879 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
3880 }
3881 [] PCU.receive {
3882 repeat;
3883 }
3884 [] T.timeout {
3885 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
3886 }
3887 }
3888}
3889testcase TC_pcu_rr_suspend() runs on test_CT {
3890 var ConnHdlrPars pars;
3891 var ConnHdlr vc_conn;
3892
3893 f_init();
3894
3895 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
3896 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
3897 vc_conn.done;
3898}
Harald Welte07bd2d22019-05-25 11:03:30 +02003899
Harald Weltea2e0e942019-05-27 18:12:53 +02003900/* Ensure that PCUIF socket can accept only a single connection */
3901testcase TC_pcu_socket_connect_multi() runs on test_CT {
3902 timer T := 5.0;
3903
3904 /* this (among other things) establishes the first connection to the PCUIF socket */
3905 f_init();
3906
3907 /* try to establish a second connection, expect it to fail */
3908 PCU.send(UD_connect:{mp_pcu_socket, -1});
3909 T.start;
3910 alt {
3911 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
3912 setverdict(pass);
3913 }
3914 [] PCU.receive(UD_connect_result:?) {
3915 setverdict(fail, "Unexpected unix domain connect result");
3916 }
3917 [] T.timeout {
3918 setverdict(pass);
3919 }
3920 }
3921 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3922}
3923
Harald Weltec8effb72019-05-27 18:23:04 +02003924/* Ensure that PCUIF socket can disconnect + reconnect */
3925testcase TC_pcu_socket_reconnect() runs on test_CT {
3926 /* this (among other things) establishes the first connection to the PCUIF socket */
3927 f_init();
3928
3929 f_sleep(1.0);
3930
3931 f_pcuif_close(PCU, g_pcu_conn_id);
3932 g_pcu_conn_id := -1;
3933
3934 f_sleep(1.0);
3935
3936 /* re-connect */
3937 PCU.clear;
3938 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
3939 setverdict(pass);
3940
3941 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3942}
3943
Harald Welted66c9b82019-05-25 09:03:15 +02003944
Harald Welte3d04ae62018-04-04 20:29:05 +02003945/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02003946 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02003947 ***********************************************************************/
3948
3949private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3950runs on ConnHdlr {
3951 var PCUIF_send_data sd;
3952 /* Expect BTS to immediately acknowledge activation as PDCH */
3953 PCU.clear;
3954 f_rsl_chan_act(g_pars.chan_mode);
3955 /* expect INFO_IND on PCU interface listing TS as PDCH */
3956 alt {
3957 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3958 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 +02003959 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02003960 }
3961 }
3962 [] PCU.receive { repeat; }
3963 }
3964 /* try to activate this PDCH from the PCU point of view */
3965 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3966 /* FIXME: is there a response? */
3967}
3968
3969private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3970runs on ConnHdlr {
3971 var PCUIF_send_data sd;
3972 /* Send RSL CHAN REL (deactivate) */
3973 PCU.clear;
3974 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
3975 /* expect BTS to ask PCU to deactivate the channel */
3976 alt {
3977 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3978 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 +02003979 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02003980 }
3981 }
3982 [] PCU.receive { repeat; }
3983 }
3984 /* Emulate PCU asking BTS to deactivate PDCH */
3985 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3986 alt {
3987 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
3988 setverdict(pass);
3989 }
3990 [] RSL.receive { repeat; }
3991 }
3992}
3993
3994/* Activate Osmocom-style dynamic PDCH from BSC side */
3995function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
3996 var PCUIF_Message first_info;
3997 var integer ts_nr := g_chan_nr.tn;
3998 var integer trx_nr := 0;
3999 var integer bts_nr := 0;
4000 var integer pcu_conn_id := -1;
4001
4002 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4003
4004 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4005 f_sleep(3.0);
4006 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4007 setverdict(pass);
4008}
4009testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
4010 var ConnHdlrPars pars;
4011 var ConnHdlr vc_conn;
4012 f_init(testcasename());
4013
4014 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4015 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
4016 vc_conn.done;
4017}
4018
4019/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
4020function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
4021 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02004022 var integer pcu_conn_id := -1;
4023
4024 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4025
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02004026 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
4027 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
4028 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02004029 setverdict(pass);
4030}
4031testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
4032 var ConnHdlrPars pars;
4033 var ConnHdlr vc_conn;
4034 f_init(testcasename());
4035
4036 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4037 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
4038 vc_conn.done;
4039}
4040
4041/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
4042function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
4043 var PCUIF_Message first_info;
4044 var integer ts_nr := g_chan_nr.tn;
4045 var integer trx_nr := 0;
4046 var integer bts_nr := 0;
4047 var integer pcu_conn_id := -1;
4048
4049 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4050
4051 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02004052 /* Send a second Chan Activ and expect it to be NACKed */
4053 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
4054 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02004055 setverdict(pass);
4056}
4057testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
4058 var ConnHdlrPars pars;
4059 var ConnHdlr vc_conn;
4060 f_init(testcasename());
4061
4062 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4063 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
4064 vc_conn.done;
4065}
4066
4067/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
4068function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
4069 var PCUIF_Message first_info;
4070 var integer ts_nr := g_chan_nr.tn;
4071 var integer trx_nr := 0;
4072 var integer bts_nr := 0;
4073 var integer pcu_conn_id := -1;
4074 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
4075
4076 /* register for the TCH/F channel number */
4077 f_rslem_register(0, chan_nr);
4078
4079 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4080
4081 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
4082 "RSL CHAN ACT");
4083 setverdict(pass);
4084}
4085testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
4086 var ConnHdlrPars pars;
4087 var ConnHdlr vc_conn;
4088 f_init(testcasename());
4089
4090 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4091 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
4092 vc_conn.done;
4093}
4094
4095/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
4096function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
4097 var PCUIF_Message first_info;
4098 var integer ts_nr := g_chan_nr.tn;
4099 var integer trx_nr := 0;
4100 var integer bts_nr := 0;
4101 var integer pcu_conn_id := -1;
4102 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
4103 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
4104
4105 /* register for the TCH/H channel numbers */
4106 f_rslem_register(0, chan_nr[0]);
4107 f_rslem_register(0, chan_nr[1]);
4108
4109 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4110
4111 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
4112 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
4113 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
4114 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
4115 setverdict(pass);
4116}
4117testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
4118 var ConnHdlrPars pars;
4119 var ConnHdlr vc_conn;
4120 f_init(testcasename());
4121
4122 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4123 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
4124 vc_conn.done;
4125}
4126
Harald Welte9bbbfb52018-04-05 09:33:19 +02004127/***********************************************************************
4128 * IPA Style Dynamic Timeslot Support
4129 ***********************************************************************/
4130
4131private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4132runs on ConnHdlr {
4133 var PCUIF_send_data sd;
4134 /* Expect BTS to immediately acknowledge activation as PDCH */
4135 PCU.clear;
4136 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
4137 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004138 timer T_wait := 2.0;
4139 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004140 alt {
4141 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4142 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 +01004143 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
4144 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
4145 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004146 }
4147 }
4148 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004149 [] T_wait.timeout {
4150 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4151 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
4152 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02004153 }
4154 /* try to activate this PDCH from the PCU point of view */
4155 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4156 /* FIXME: is there a response? */
4157
4158 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
4159}
4160
4161private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4162runs on ConnHdlr {
4163 var PCUIF_send_data sd;
4164 /* Send RSL CHAN REL (deactivate) */
4165 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
4166 PCU.clear;
4167 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004168 timer T_wait := 2.0;
4169 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004170 alt {
4171 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4172 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 +01004173 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
4174 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
4175 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004176 }
4177 }
4178 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004179 [] T_wait.timeout {
4180 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4181 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
4182 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02004183 }
4184 /* Emulate PCU asking BTS to deactivate PDCH */
4185 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4186 alt {
4187 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
4188 setverdict(pass);
4189 }
4190 [] RSL.receive { repeat; }
4191 }
4192}
4193
4194/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
4195function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
4196 var PCUIF_Message first_info;
4197 var integer ts_nr := g_chan_nr.tn;
4198 var integer trx_nr := 0;
4199 var integer bts_nr := 0;
4200 var integer pcu_conn_id := -1;
4201
4202 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4203
4204 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4205 f_sleep(3.0);
4206 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4207
4208 setverdict(pass);
4209
4210}
4211testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
4212 var ConnHdlrPars pars;
4213 var ConnHdlr vc_conn;
4214 f_init();
4215
4216 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4217 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
4218 vc_conn.done;
4219}
4220
4221/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
4222function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
4223 var PCUIF_Message first_info;
4224 var integer ts_nr := g_chan_nr.tn;
4225 var integer trx_nr := 0;
4226 var integer bts_nr := 0;
4227 var integer pcu_conn_id := -1;
4228
4229 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4230
4231 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4232 "RSL CHAN ACT");
4233 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4234 "RF CHAN REL", true);
4235 setverdict(pass);
4236}
4237testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
4238 var ConnHdlrPars pars;
4239 var ConnHdlr vc_conn;
4240 f_init(testcasename());
4241
4242 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4243 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
4244 vc_conn.done;
4245}
4246
4247/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
4248function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
4249 var PCUIF_Message first_info;
4250 var integer ts_nr := g_chan_nr.tn;
4251 var integer trx_nr := 0;
4252 var integer bts_nr := 0;
4253 var integer pcu_conn_id := -1;
4254
4255 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4256
4257 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4258 "RSL CHAN ACT");
4259
4260 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
4261 alt {
4262 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
4263 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004264 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02004265 }
4266 [] RSL.receive { repeat; }
4267 }
4268
4269 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4270 "RF CHAN REL", true);
4271 setverdict(pass);
4272}
4273testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
4274 var ConnHdlrPars pars;
4275 var ConnHdlr vc_conn;
4276 f_init(testcasename());
4277
4278 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4279 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
4280 vc_conn.done;
4281}
4282
4283/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
4284function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
4285 var PCUIF_Message first_info;
4286 var integer ts_nr := g_chan_nr.tn;
4287 var integer trx_nr := 0;
4288 var integer bts_nr := 0;
4289 var integer pcu_conn_id := -1;
4290
4291 /* register for the TCH/F channel number */
4292 f_rslem_register(0, g_chan_nr);
4293
4294 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4295
4296 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4297
4298 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
4299 "RSL CHAN ACT");
4300
4301 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4302
4303 setverdict(pass);
4304}
4305testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
4306 var ConnHdlrPars pars;
4307 var ConnHdlr vc_conn;
4308 f_init(testcasename());
4309
4310 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4311 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
4312 vc_conn.done;
4313}
4314
4315
Harald Welte0472ab42018-03-12 15:02:26 +01004316/***********************************************************************
4317 * LAPDm / RLL related
4318 ***********************************************************************/
4319
4320private function f_tx_lapdm(template (value) LapdmFrame l,
4321 template (value) RslLinkId link_id) runs on ConnHdlr {
4322 var octetstring l2 := enc_LapdmFrame(valueof(l));
4323 if (valueof(link_id.c) == SACCH) {
4324 /* prepend dummy L1 header */
Pau Espin Pedrola0fb42a2018-10-10 15:56:39 +02004325 var L1ctlDataReq l1hl2 := {
4326 l1header := valueof(ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta)),
4327 l2_payload := f_pad_oct(l2, 21, '2B'O)
4328 }
4329 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, link_id, l1hl2));
4330 } else {
4331 /* If required, pad L2 frame with constant 0x2b filling */
4332 l2 := f_pad_oct(l2, 23, '2B'O);
4333
4334 log("encoding ", l, " to ", l2);
4335 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, link_id, l2));
Harald Welte0472ab42018-03-12 15:02:26 +01004336 }
Harald Welte0472ab42018-03-12 15:02:26 +01004337}
4338
4339type record RllTestCase {
4340 uint3_t sapi,
4341 RslLinkId link_id,
4342 octetstring l3,
4343 boolean exp
4344}
4345type record of RllTestCase RllTestCases;
4346template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
4347 sapi := sapi,
4348 link_id := id,
4349 l3 := l3,
4350 exp := exp
4351}
4352
4353/* execute the same callback function with a set of different parameters (tcs) on a
4354 * variety of logical channels */
4355private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
4356 var ConnHdlrPars pars;
4357 var ConnHdlr vc_conn;
4358 f_init(testcasename());
4359
4360 /* test on each of the channels we have */
4361 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
4362 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
4363
4364 /* test each of the test cases on the current channel */
4365 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
4366 pars.spec.rll := tcs[j];
4367 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
4368 vc_conn := f_start_handler(fn, pars);
4369 vc_conn.done;
4370 }
4371 }
4372
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004373 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01004374}
4375
4376/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
4377private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
4378 var RllTestCase tc := g_pars.spec.rll;
4379 timer T := 3.0;
4380
4381 f_l1_tune(L1CTL);
4382 RSL.clear;
4383
4384 /* activate the logical channel */
4385 f_est_dchan();
4386 L1CTL.clear;
4387
4388 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
4389 T.start;
4390 alt {
4391 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
4392 if (tc.exp) {
4393 setverdict(pass);
4394 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004395 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01004396 }
4397 }
4398 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
4399 if (tc.exp) {
4400 setverdict(pass);
4401 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004402 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01004403 }
4404 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07004405 /* We also expect to receive the measurements */
4406 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01004407 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004408 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01004409 }
4410 [not tc.exp] T.timeout {
4411 setverdict(pass);
4412 }
4413 }
4414
4415 f_rsl_chan_deact();
4416 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4417 f_rslem_unregister(0, g_chan_nr);
4418}
4419testcase TC_rll_est_ind() runs on test_CT {
4420 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02004421 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01004422 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02004423 /* normal SAPI0 establishment */
4424 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01004425 /* SAPI 3 doesn't support contention resolution */
4426 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
4427 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
4428 /* normal SAPI3 establishment on main DCCH */
4429 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
4430 /* normal SAPI3 establishment on SACCH */
4431 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4432 };
4433 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
4434}
4435
4436/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
4437private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
4438 var RllTestCase tc := g_pars.spec.rll;
4439 var L1ctlDlMessage dl;
4440 timer T := 3.0;
4441
4442 f_l1_tune(L1CTL);
4443 RSL.clear;
4444
4445 /* activate the logical channel */
4446 f_est_dchan();
4447 L1CTL.clear;
4448
4449 /* Send a RSL EST REQ for SAPI3 on main DCCH */
4450 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
4451 T.start;
4452 alt {
4453 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4454 var LapdmFrame lapdm;
4455 var octetstring l2 := dl.payload.data_ind.payload;
4456 if (dl.dl_info.link_id.c == SACCH) {
4457 /* remove L1 header */
4458 l2 := substr(l2, 2, lengthof(l2)-2);
4459 }
4460 lapdm.ab := dec_LapdmFrameAB(l2);
4461 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
4462 setverdict(pass);
4463 } else {
4464 repeat;
4465 }
4466 }
4467 [] L1CTL.receive { repeat; }
4468 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004469 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01004470 }
4471 }
4472
4473 f_rsl_chan_deact();
4474 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4475 f_rslem_unregister(0, g_chan_nr);
4476}
4477testcase TC_rll_est_req_DCCH_3() runs on test_CT {
4478 var RllTestCases tcs := {
4479 /* normal SAPI3 establishment on main DCCH */
4480 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
4481 };
4482 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
4483}
4484testcase TC_rll_est_req_ACCH_3() runs on test_CT {
4485 var RllTestCases tcs := {
4486 /* normal SAPI3 establishment on SACCH */
4487 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4488 }
4489 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
4490}
4491
4492/* altstep to receive a LAPDm frame matching the given template */
4493private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
4494 var L1ctlDlMessage dl;
4495 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4496 var LapdmFrame lapdm;
4497 var octetstring l2 := dl.payload.data_ind.payload;
4498 if (dl.dl_info.link_id.c == SACCH) {
4499 /* remove L1 header */
4500 l2 := substr(l2, 2, lengthof(l2)-2);
4501 }
4502 if (ischosen(exp.ab)) {
4503 lapdm.ab := dec_LapdmFrameAB(l2);
4504 } else if (ischosen(exp.b4)) {
4505 lapdm.b4 := dec_LapdmFrameB4(l2);
4506 } else if (ischosen(exp.bbis)) {
4507 lapdm.bbis := dec_LapdmFrameBbis(l2);
4508 }
4509 log("Rx LAPDm ", lapdm);
4510 if (match(lapdm, exp)) {
4511 setverdict(pass);
4512 } else {
4513 repeat;
4514 }
4515 }
4516 [] L1CTL.receive { repeat; }
4517}
4518private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
4519 timer T := t;
4520 T.start;
4521 alt {
4522 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004523 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01004524 }
4525 [] as_l1_exp_lapdm(exp);
4526 }
4527}
4528
4529/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
4530private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
4531 /* send SABM from MS -> BTS */
4532 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
4533 /* expect RLL EST IND on Abis */
4534 alt {
4535 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
4536 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
4537 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004538 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01004539 }
4540 [] RSL.receive { repeat; }
4541 }
4542 /* expect UA from BTS -> MS */
4543 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
4544}
4545
4546/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
4547private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
4548 var RllTestCase tc := g_pars.spec.rll;
4549
4550 f_l1_tune(L1CTL);
4551 RSL.clear;
4552
4553 /* activate the logical channel */
4554 f_est_dchan();
4555 L1CTL.clear;
4556
4557 /* first establish the link-layer */
4558 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
4559
4560 /* then send the DISC */
4561 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
4562 /* ... and expect the REL IND on the RSL side */
4563 alt {
4564 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
4565 setverdict(pass);
4566 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07004567 /* We also expect to receive the measurements */
4568 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01004569 }
4570
4571 /* release the channel */
4572 f_rsl_chan_deact();
4573 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4574 f_rslem_unregister(0, g_chan_nr);
4575}
4576testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
4577 var RllTestCases tcs := {
4578 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
4579 };
4580 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4581}
4582
4583testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
4584 var RllTestCases tcs := {
4585 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
4586 };
4587 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4588}
4589testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
4590 var RllTestCases tcs := {
4591 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
4592 };
4593 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4594}
4595testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
4596 var RllTestCases tcs := {
4597 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4598 };
4599 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4600}
4601
4602/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
4603private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
4604 var RllTestCase tc := g_pars.spec.rll;
4605 f_l1_tune(L1CTL);
4606 RSL.clear;
4607
4608 /* activate the logical channel */
4609 f_est_dchan();
4610 L1CTL.clear;
4611
4612 /* first establish the link-layer */
4613 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
4614
4615 /* then send the REL REQ via RSL */
4616 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
4617 /* ... and expect the DISC on the Um side */
4618 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02004619 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01004620 /* FIXME: send a UA in resposne to the DISC */
4621 }
4622 }
4623
4624 /* release the channel */
4625 f_rsl_chan_deact();
4626 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4627 f_rslem_unregister(0, g_chan_nr);
4628}
4629testcase TC_rll_rel_req() runs on test_CT {
4630 var RllTestCases tcs := {
4631 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
4632 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
4633 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
4634 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4635 };
4636 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
4637}
4638
4639/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
4640testcase TC_rll_data_req() runs on test_CT {
4641}
4642
4643/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
4644testcase TC_rll_data_ind() runs on test_CT {
4645}
4646
4647/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
4648private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
4649 var RllTestCase tc := g_pars.spec.rll;
4650
4651 f_l1_tune(L1CTL);
4652 RSL.clear;
4653
4654 f_est_dchan();
4655 L1CTL.clear;
4656
4657 /* Send UNITDATA REQ on RSL side */
4658 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
4659 /* Expect it to arrive on the other side */
4660 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02004661 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01004662 } else {
Harald Weltee613f962018-04-18 22:38:16 +02004663 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01004664 }
4665
4666 /* release the channel */
4667 f_rsl_chan_deact();
4668 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4669 f_rslem_unregister(0, g_chan_nr);
4670}
4671testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
4672 var octetstring l3 := f_rnd_octstring(15);
4673 var RllTestCases tcs := {
4674 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
4675 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
4676 };
4677 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
4678}
4679testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
4680 var octetstring l3 := f_rnd_octstring(19);
4681 var RllTestCases tcs := {
4682 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
4683 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
4684 };
4685 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
4686}
4687
4688/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
4689private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
4690 var RllTestCase tc := g_pars.spec.rll;
4691
4692 f_l1_tune(L1CTL);
4693 RSL.clear;
4694
4695 f_est_dchan();
4696 L1CTL.clear;
4697
4698 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02004699 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01004700 /* Expdct RLL UNITDATA IND on RSL side */
4701 alt {
4702 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
4703 setverdict(pass);
4704 }
4705 [] RSL.receive { repeat; }
4706 }
4707
4708 /* release the channel */
4709 f_rsl_chan_deact();
4710 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4711 f_rslem_unregister(0, g_chan_nr);
4712}
4713testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02004714 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01004715 var RllTestCases tcs := {
4716 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
4717 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
4718 };
4719 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
4720}
4721testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
4722 var octetstring l3 := f_rnd_octstring(18);
4723 var RllTestCases tcs := {
4724 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
4725 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
4726 };
4727 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
4728}
4729
Harald Weltee613f962018-04-18 22:38:16 +02004730/***********************************************************************
4731 * Encryption Related
4732 ***********************************************************************/
4733
4734/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
4735function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
4736 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
4737 if (link_id.c == SACCH) {
4738 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
4739 } else {
4740 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
4741 }
4742}
4743
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07004744/* Expect (or not expect) other kinds of messages */
4745private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
4746 [exp_any] RSL.receive { repeat; }
4747 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004748 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07004749 }
4750}
4751
Harald Weltee613f962018-04-18 22:38:16 +02004752/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07004753private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07004754 RslLinkId link_id,
4755 octetstring l3,
4756 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07004757 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07004758) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02004759 timer T := 3.0;
4760 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
4761 T.start;
4762 /* Expect RLL UNITDATA IND on RSL side */
4763 alt {
4764 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
4765 setverdict(pass);
4766 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07004767 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07004768 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02004769 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004770 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02004771 }
Harald Weltee613f962018-04-18 22:38:16 +02004772 }
4773}
4774
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004775/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
4776private function f_data_mo(
4777 RslLinkId link_id,
4778 boolean p, uint3_t nr, uint3_t ns,
4779 octetstring l3,
4780 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07004781 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004782) runs on ConnHdlr {
4783 timer T := 3.0;
4784 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
4785 T.start;
4786 /* Expect RLL DATA IND on RSL side */
4787 alt {
4788 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
4789 setverdict(pass);
4790 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07004791 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004792 [] as_rsl_any_ind(exp_any);
4793 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004794 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004795 }
4796 }
4797}
4798
Harald Weltee613f962018-04-18 22:38:16 +02004799/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
4800function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
4801 f_l1_tune(L1CTL);
4802 f_est_dchan(true);
4803
4804 /* now we actually need to transmit some data both ways to check if the encryption works */
4805 var L1ctlDlMessage dl;
4806
Stefan Sperling603d98e2018-07-25 16:47:28 +02004807 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02004808 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
4809
4810 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
4811 f_unitdata_mt(link_id, l3);
4812
4813 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
4814 f_unitdata_mo(link_id, l3);
4815
4816 /* release the channel */
4817 f_rsl_chan_deact();
4818 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4819 f_rslem_unregister(0, g_chan_nr);
4820}
4821testcase TC_chan_act_a51() runs on test_CT {
4822 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4823 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
4824 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
4825}
4826testcase TC_chan_act_a52() runs on test_CT {
4827 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4828 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
4829 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
4830}
4831testcase TC_chan_act_a53() runs on test_CT {
4832 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4833 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
4834 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
4835}
4836
4837
4838/* Test unencrypted channel activation followed by explicit ENCR CMD later */
4839function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
4840 /* L3 payload doesn't matter, as it is passed transparently */
4841 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
4842 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
4843 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
4844
4845 f_l1_tune(L1CTL);
4846
4847 /* first establish a dedicated channel in the clear */
4848 f_est_dchan(false);
4849
4850 /* Establish ABM */
4851 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
4852
4853 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
4854 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
4855 /* expect the L3 to arrive still unencrypted on the MS side */
4856 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
4857
4858 /* configure L1 to apply ciphering */
4859 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
4860 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
4861
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004862 /* send first ciphered I-frame in response and expect it on RSL */
4863 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02004864
4865 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
4866 * and hence enable encryption also on the downlink */
4867
4868 /* expect bi-directional communication work in encrypted mode */
4869 f_unitdata_mo(link_id, f_rnd_octstring(15));
4870 f_unitdata_mt(link_id, f_rnd_octstring(15));
4871
4872 /* release the channel */
4873 f_rsl_chan_deact();
4874 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4875 f_rslem_unregister(0, g_chan_nr);
4876}
4877testcase TC_encr_cmd_a51() runs on test_CT {
4878 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4879 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
4880 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
4881}
4882testcase TC_encr_cmd_a52() runs on test_CT {
4883 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4884 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
4885 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
4886}
4887testcase TC_encr_cmd_a53() runs on test_CT {
4888 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4889 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
4890 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
4891}
4892
4893private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
4894 var LapdmFrame lf;
4895 var octetstring reenc;
4896
4897 /* decode the LAPDm frame */
4898 if (ischosen(exp_match.ab)) {
4899 lf.ab := dec_LapdmFrameAB(enc);
4900 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004901 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02004902 }
4903
4904 /* check if decoder result matches expectation */
4905 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004906 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02004907 } else {
4908 log(name, ": matched");
4909 setverdict(pass);
4910 }
4911
4912 /* test if re-encoded frame equals original input */
4913 reenc := enc_LapdmFrame(lf);
4914 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004915 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02004916 } else {
4917 setverdict(pass);
4918 }
4919}
4920
4921testcase TC_lapdm_selftest() runs on test_CT {
4922 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
4923 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
4924 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
4925 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
4926 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
4927 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
4928 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
4929}
4930
Stefan Sperling4880be42018-08-07 18:12:59 +02004931/***********************************************************************
4932 * DTX Related (see GSM 05.08, section 8.3)
4933 ***********************************************************************/
4934
4935/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
4936function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
4937 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
4938 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
4939 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
4940 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
4941}
4942function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
4943 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
4944 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
4945}
4946function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
4947 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
4948 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
4949 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
4950 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
4951}
4952function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
4953 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
4954 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
4955 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
4956 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
4957 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
4958 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
4959 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
4960 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
4961}
4962
4963function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
4964 var L1ctlDlMessage dl;
4965 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
4966 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
4967 var GsmFrameNumber first_fn;
4968 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004969 var integer nfill_frames_sacch := 0;
4970 var integer nfill_frames_nonsacch := 0;
4971 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02004972 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
4973 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004974 const integer frame_dtx_tchf_mod := 104;
4975 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
4976 * which operates in terms of blocks rather than frames. */
4977 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
4978 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02004979 timer T := 5.0;
4980
4981 f_l1_tune(L1CTL);
4982 RSL.clear;
4983 L1CTL.clear;
4984
4985 /* activate TCHF signalling channel */
4986 f_est_dchan(false);
4987
4988 T.start;
4989 alt {
4990 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4991 var GsmFrameNumber fn := dl.dl_info.frame_nr;
4992 var octetstring l2 := dl.payload.data_ind.payload;
4993
4994 if (is_first_frame) {
4995 is_first_frame := false;
4996 first_fn := dl.dl_info.frame_nr;
4997 }
4998
4999 if (dl.dl_info.link_id.c == SACCH) {
5000 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
5001 if (not match(l2_fill_frame_sacch, l2)) {
5002 repeat;
5003 }
5004 } else if (not match(l2_fill_frame, l2)) {
5005 repeat;
5006 }
5007
5008 if (dtxd) {
5009 if (not f_g_chan_is_tchf()) {
5010 T.stop;
5011 f_rsl_chan_deact();
5012 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005013 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 +02005014 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005015 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005016 T.stop;
5017 f_rsl_chan_deact();
5018 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005019
5020 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
5021 * 2 SACCH, 1 TCH/F */
5022 expected_fill_frames := 3;
5023
5024 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
5025 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
5026 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005027 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02005028 } else {
5029 setverdict(pass);
5030 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005031 } else {
5032 if (dl.dl_info.link_id.c == SACCH) {
5033 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02005034 repeat;
5035 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005036 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
5037 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
5038 * we should only see the subset of frames numbers which correspond to a block boundary.
5039 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
5040 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
5041 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
5042 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
5043 repeat;
5044 }
5045 }
5046 log("Received DTX TCH fill frame with bad frame number: ", fn,
5047 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
5048 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
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, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02005052 }
Stefan Sperling4880be42018-08-07 18:12:59 +02005053 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005054 if (dl.dl_info.link_id.c == SACCH) {
5055 nfill_frames_sacch := nfill_frames_sacch + 1;
5056 } else {
5057 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
5058 }
5059 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005060 T.stop;
5061 if (f_g_chan_is_tchf()) {
5062 /* Without DTX we can expect 25 fill frames for every 104 frames.
5063 * (24 FACCH + 1 SACCH filling) */
5064 expected_fill_frames := 25;
5065 } else if (f_g_chan_is_tchh()) {
5066 /* We can expect 2 fill frames for every 104 frames. */
5067 expected_fill_frames := 2;
5068 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
5069 /* We can expect 5 fill frames for every 104 frames. */
5070 expected_fill_frames := 5;
5071 } else {
5072 f_rsl_chan_deact();
5073 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005074 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02005075 }
5076
5077 f_rsl_chan_deact();
5078 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005079
5080 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005081 setverdict(pass);
5082 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005083 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
5084 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005085 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02005086 }
5087 } else {
5088 repeat;
5089 }
5090 }
5091 }
5092 [] L1CTL.receive { repeat; }
5093 [] T.timeout {
5094 f_rsl_chan_deact();
5095 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005096 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02005097 }
5098 }
5099}
5100
5101function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
5102 f_test_l2_fill_frames(false);
5103}
5104
5105function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
5106 f_test_l2_fill_frames(true);
5107}
5108
5109function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
5110 var ConnHdlr vc_conn;
5111 var ConnHdlrPars pars;
5112 pars.t_guard := 60.0;
5113 f_init(testcasename());
5114 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
5115 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
5116 if (dtxd) {
5117 if (i >= 4) { /* DTX is only allowed on TCH/F */
5118 break;
5119 }
5120 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
5121 } else {
5122 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
5123 }
5124 vc_conn.done;
5125 }
5126}
5127
5128/* Verify that L2 fill frames are sent on TCH in signaling mode if
5129 * there is nothing to transmit while DTX is disabled on downlink. */
5130testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
5131 f_tch_sign_l2_fill_frame(false);
5132}
5133
5134/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
5135 * there is nothing to transmit while DTX is enabled on downlink. */
5136testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
5137 f_tch_sign_l2_fill_frame(true);
5138}
Harald Welte0472ab42018-03-12 15:02:26 +01005139
Stefan Sperling0ec1c262018-10-15 15:12:52 +02005140testcase TC_chopped_ipa_ping() runs on test_CT {
5141 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
5142}
5143
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02005144testcase TC_chopped_ipa_payload() runs on test_CT {
5145 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
5146}
5147
Harald Welte0472ab42018-03-12 15:02:26 +01005148/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
5149/* protocol error as per 44.006 */
5150/* link layer failure (repetition of I-frame N200 times without ACK */
5151/* repetition of SABM or DISC N200 times without ACK */
5152/* receptiom of SABM in multi-frame established state */
5153
5154
Harald Welte68e495b2018-02-25 00:05:57 +01005155/* TODO Areas:
5156
5157* channel activation
5158** with BS_Power / MS_Power, bypassing power control loop
5159** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01005160** with timing advance from initial activation on
5161* mode modify
5162** encryption
5163** multirate
5164* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01005165** unsupported algorithm
5166* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01005167* BS Power Control
5168* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01005169* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01005170* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01005171** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01005172* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01005173** DATA_IND from BTS->PCU
5174** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01005175
5176*/
Harald Welte70767382018-02-21 12:16:40 +01005177
5178control {
5179 execute( TC_chan_act_stress() );
5180 execute( TC_chan_act_react() );
5181 execute( TC_chan_deact_not_active() );
5182 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01005183 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01005184 execute( TC_sacch_filling() );
5185 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01005186 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01005187 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02005188 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02005189 execute( TC_sacch_chan_act_ho_async() );
5190 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01005191 execute( TC_rach_content() );
5192 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01005193 execute( TC_rach_max_ta() );
Harald Welte3453ab42019-05-24 21:19:58 +02005194 execute( TC_rach_load_idle_thresh0() );
5195 execute( TC_rach_load_idle_below_thresh() );
5196 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01005197 execute( TC_meas_res_sign_tchf() );
5198 execute( TC_meas_res_sign_tchh() );
5199 execute( TC_meas_res_sign_sdcch4() );
5200 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01005201 execute( TC_meas_res_sign_tchh_toa256() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01005202 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild6833cc92019-05-23 19:34:44 +02005203 execute( TC_rsl_chan_initial_ta() );
Harald Welte70767382018-02-21 12:16:40 +01005204 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01005205 execute( TC_paging_imsi_80percent() );
5206 execute( TC_paging_tmsi_80percent() );
5207 execute( TC_paging_imsi_200percent() );
5208 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01005209 execute( TC_rsl_protocol_error() );
5210 execute( TC_rsl_mand_ie_error() );
5211 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01005212 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01005213 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01005214 execute( TC_si_sched_2bis() );
5215 execute( TC_si_sched_2ter() );
5216 execute( TC_si_sched_2ter_2bis() );
5217 execute( TC_si_sched_2quater() );
5218 execute( TC_si_sched_13() );
5219 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01005220 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01005221 execute( TC_ipa_crcx_twice_not_active() );
5222 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01005223 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01005224 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01005225
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005226 if (mp_pcu_socket != "") {
5227 execute( TC_pcu_act_req() );
5228 execute( TC_pcu_act_req_wrong_ts() );
5229 execute( TC_pcu_act_req_wrong_bts() );
5230 execute( TC_pcu_act_req_wrong_trx() );
5231 execute( TC_pcu_deact_req() );
5232 execute( TC_pcu_deact_req_wrong_ts() );
5233 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02005234 if (mp_l1_supports_gprs) {
5235 execute( TC_pcu_data_req_pdtch() );
5236 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02005237 execute( TC_pcu_data_req_wrong_bts() );
5238 execute( TC_pcu_data_req_wrong_trx() );
5239 execute( TC_pcu_data_req_wrong_ts() );
5240 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02005241 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005242 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02005243 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005244 execute( TC_pcu_data_req_imm_ass_pch() );
5245 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005246 execute( TC_pcu_ext_rach_content() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005247 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02005248 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02005249 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02005250 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02005251 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02005252 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02005253 execute( TC_pcu_socket_reconnect() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005254 } else {
5255 log("PCU socket path not available, skipping PCU tests");
5256 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005257
5258 execute( TC_dyn_osmo_pdch_act_deact() );
5259 execute( TC_dyn_osmo_pdch_unsol_deact() );
5260 execute( TC_dyn_osmo_pdch_double_act() );
5261 execute( TC_dyn_osmo_pdch_tchf_act() );
5262 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02005263 execute( TC_dyn_ipa_pdch_act_deact() );
5264 execute( TC_dyn_ipa_pdch_tchf_act() );
5265 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
5266 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01005267
5268 execute( TC_rll_est_ind() );
5269 execute( TC_rll_est_req_DCCH_3() );
5270 execute( TC_rll_est_req_ACCH_3() );
5271 execute( TC_rll_rel_ind_DCCH_0() );
5272 execute( TC_rll_rel_ind_DCCH_3() );
5273 execute( TC_rll_rel_ind_ACCH_0() );
5274 execute( TC_rll_rel_ind_ACCH_3() );
5275 execute( TC_rll_rel_req() );
5276 execute( TC_rll_unit_data_req_DCCH() );
5277 execute( TC_rll_unit_data_req_ACCH() );
5278 execute( TC_rll_unit_data_ind_DCCH() );
5279 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02005280
5281 execute( TC_chan_act_a51() );
5282 execute( TC_chan_act_a52() );
5283 execute( TC_chan_act_a53() );
5284 execute( TC_encr_cmd_a51() );
5285 execute( TC_encr_cmd_a52() );
5286 execute( TC_encr_cmd_a53() );
5287
Harald Welteee25aae2019-05-19 14:32:37 +02005288 execute( TC_err_rep_wrong_mdisc() );
5289 execute( TC_err_rep_wrong_msg_type() );
5290 execute( TC_err_rep_wrong_sequence() );
5291
Harald Weltee613f962018-04-18 22:38:16 +02005292 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02005293
5294 execute( TC_tch_sign_l2_fill_frame() );
5295 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02005296
5297 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02005298 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01005299}
5300
5301
5302}